From 395280a3639855b8294d8e96035edb52e37d6dcf Mon Sep 17 00:00:00 2001 From: xing Date: Tue, 11 Jul 2023 14:54:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 +++- bbclearn/bbc.go | 4 ++++ mail/mail.go | 16 +++++++++++----- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 604e828..b4a5f75 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ .gitignore rss.iml rss -fetchdapenti \ No newline at end of file +fetchdapenti +/run.sh +/sendmail \ No newline at end of file diff --git a/bbclearn/bbc.go b/bbclearn/bbc.go index 164a285..2cdae9c 100644 --- a/bbclearn/bbc.go +++ b/bbclearn/bbc.go @@ -88,6 +88,10 @@ func fetch(u string) (r rss2.Item) { var hadSend = safety.NewMap[string, struct{}]() func downAndSendMail(doc *goquery.Document, title string) { + if err := mail.CheckEnv(); err != nil { + log.Println("err", err) + return + } type m struct { tit string content string diff --git a/mail/mail.go b/mail/mail.go index 202ba50..cb27d32 100644 --- a/mail/mail.go +++ b/mail/mail.go @@ -7,23 +7,29 @@ import ( "os/exec" ) -func SendMail(subject string, content string, files ...string) error { - cm := os.Getenv("mail_cmd_path") +var cm, subjectParam, contentParam, fileParam string + +func CheckEnv() error { + cm = os.Getenv("mail_cmd_path") if cm == "" { return errors.New("cmd can't empty") } - subjectParam := os.Getenv("mail_cmd_subject_param_name") + subjectParam = os.Getenv("mail_cmd_subject_param_name") if subjectParam == "" { return errors.New("title param name empty") } - contentParam := os.Getenv("mail_cmd_content_param_name") + contentParam = os.Getenv("mail_cmd_content_param_name") if contentParam == "" { return errors.New("content param name emtpy") } - fileParam := os.Getenv("mail_cmd_file_param_name") + fileParam = os.Getenv("mail_cmd_file_param_name") if fileParam == "" { return errors.New("file empty") } + return nil +} + +func SendMail(subject string, content string, files ...string) error { v := []string{subjectParam, subject, contentParam, content} for _, f := range files { if f != "" {