diff --git a/server/dto/parsemail/email.go b/server/dto/parsemail/email.go index 1dab338..2cac13e 100644 --- a/server/dto/parsemail/email.go +++ b/server/dto/parsemail/email.go @@ -182,6 +182,10 @@ func buildUser(str string) *User { func buildUsers(str []string) []*User { var ret []*User for _, s1 := range str { + if s1 == "" { + continue + } + for _, s := range strings.Split(s1, ",") { s = strings.TrimSpace(s) ret = append(ret, buildUser(s)) diff --git a/server/smtp_server/read_content_test.go b/server/smtp_server/read_content_test.go index 52a1f99..69e9fcc 100644 --- a/server/smtp_server/read_content_test.go +++ b/server/smtp_server/read_content_test.go @@ -12,6 +12,7 @@ import ( "pmail/db" parsemail2 "pmail/dto/parsemail" "pmail/session" + "pmail/utils/context" "testing" "time" ) @@ -49,6 +50,11 @@ func TestNuisanace(t *testing.T) { s := Session{ RemoteAddress: net.TCPAddrFromAddrPort(netip.AddrPortFrom(netip.AddrFrom4([4]byte{}), 25)), + Ctx: &context.Context{ + UserID: 1, + UserName: "a", + UserAccount: "a", + }, } data, _ := os.ReadFile("../docs/nuisance/demo.txt") @@ -122,6 +128,11 @@ Content-Type: text/html ` s := Session{ RemoteAddress: net.TCPAddrFromAddrPort(netip.AddrPortFrom(netip.AddrFrom4([4]byte{}), 25)), + Ctx: &context.Context{ + UserID: 1, + UserName: "a", + UserAccount: "a", + }, } s.Data(bytes.NewReader([]byte(emailData))) @@ -281,6 +292,11 @@ Content-Type: text/html s := Session{ RemoteAddress: net.TCPAddrFromAddrPort(netip.AddrPortFrom(netip.AddrFrom4([4]byte{}), 25)), + Ctx: &context.Context{ + UserID: 1, + UserName: "a", + UserAccount: "a", + }, } s.Data(bytes.NewReader([]byte(deleteEmail))) @@ -331,6 +347,11 @@ Content-Type: text/html s := Session{ RemoteAddress: net.TCPAddrFromAddrPort(netip.AddrPortFrom(netip.AddrFrom4([4]byte{}), 25)), + Ctx: &context.Context{ + UserID: 1, + UserName: "a", + UserAccount: "a", + }, } s.Data(bytes.NewReader([]byte(readEmail))) @@ -379,12 +400,63 @@ Content-Type: text/html s := Session{ RemoteAddress: net.TCPAddrFromAddrPort(netip.AddrPortFrom(netip.AddrFrom4([4]byte{}), 25)), + Ctx: &context.Context{ + UserID: 1, + UserName: "a", + UserAccount: "a", + }, } s.Data(bytes.NewReader([]byte(deleteEmail))) } +func TestNullCC(t *testing.T) { + testInit() + + emailData := `Date: Mon, 29 Jan 2024 16:54:30 +0800 +Return-Path: 1231@111.com +From: =?utf-8?B?b2VhdHY=?= 1231@111.com +To: =?utf-8?B?ODQ2ODAzOTY=?= 123213@qq.com +Cc: +Bcc: +Reply-To: <> +Subject: =?utf-8?B?6L+Z5piv5LiA5bCB5p2l6IeqUmVsYXhEcmFtYeeahOmCruS7tg==?= +Message-ID: +X-Priority: 3 +X-Mailer: Mailer (https://github.com/txthinking/Mailer) +MIME-Version: 1.0 +Content-Type: multipart/alternative; boundary="6edc2ef285d93010a080caccc858c67b" + +--6edc2ef285d93010a080caccc858c67b +Content-Type: text/plain; charset="UTF-8" +Content-Transfer-Encoding: base64 + +PGRpdiBzdHlsZT0ibWluLWhlaWdodDo1NTBweDsgcGFkZGluZzogMTAwcHggNTVweCAyMDBweDsi +Pui/meaYr+S4gOWwgeadpeiHqlJlbGF4RHJhbWHnmoTmoKHpqozpgq7ku7Ys55So5LqO5qCh6aqM +6YKu5Lu26YWN572u5piv5ZCm5q2j5bi4ITwvZGl2Pg== + +--6edc2ef285d93010a080caccc858c67b +Content-Type: text/html; charset="UTF-8" +Content-Transfer-Encoding: base64 + +PGRpdiBzdHlsZT0ibWluLWhlaWdodDo1NTBweDsgcGFkZGluZzogMTAwcHggNTVweCAyMDBweDsi +Pui/meaYr+S4gOWwgeadpeiHqlJlbGF4RHJhbWHnmoTmoKHpqozpgq7ku7Ys55So5LqO5qCh6aqM +6YKu5Lu26YWN572u5piv5ZCm5q2j5bi4ITwvZGl2Pg== + +--6edc2ef285d93010a080caccc858c67b--` + s := Session{ + RemoteAddress: net.TCPAddrFromAddrPort(netip.AddrPortFrom(netip.AddrFrom4([4]byte{}), 25)), + Ctx: &context.Context{ + UserID: 1, + UserName: "a", + UserAccount: "a", + }, + } + + s.Data(bytes.NewReader([]byte(emailData))) +} + func TestRuleMove(t *testing.T) { testInit() @@ -427,6 +499,11 @@ Content-Type: text/html s := Session{ RemoteAddress: net.TCPAddrFromAddrPort(netip.AddrPortFrom(netip.AddrFrom4([4]byte{}), 25)), + Ctx: &context.Context{ + UserID: 1, + UserName: "a", + UserAccount: "a", + }, } s.Data(bytes.NewReader([]byte(moveEmail))) diff --git a/server/utils/send/send_test.go b/server/utils/send/send_test.go index 269cbc1..6088dde 100644 --- a/server/utils/send/send_test.go +++ b/server/utils/send/send_test.go @@ -68,6 +68,23 @@ func TestSendSohu(t *testing.T) { Send(nil, e) } +func TestSendTom(t *testing.T) { + testInit() + e := &parsemail.Email{ + From: &parsemail.User{ + Name: "发送人", + EmailAddress: "j@jinnrry.com", + }, + To: []*parsemail.User{ + {"tom@tom.com", "名"}, + }, + Subject: "插件测试", + Text: []byte("这是Text"), + HTML: []byte("
这是Html
"), + } + Send(nil, e) +} + func Test_domainMatch(t *testing.T) { domain := domainMatch("qq.com", nil)