Explorar el Código

空指针异常修复

jinnrry hace 2 años
padre
commit
dbc125d1c2

+ 4 - 0
server/dto/parsemail/email.go

@@ -182,6 +182,10 @@ func buildUser(str string) *User {
 func buildUsers(str []string) []*User {
 func buildUsers(str []string) []*User {
 	var ret []*User
 	var ret []*User
 	for _, s1 := range str {
 	for _, s1 := range str {
+		if s1 == "" {
+			continue
+		}
+
 		for _, s := range strings.Split(s1, ",") {
 		for _, s := range strings.Split(s1, ",") {
 			s = strings.TrimSpace(s)
 			s = strings.TrimSpace(s)
 			ret = append(ret, buildUser(s))
 			ret = append(ret, buildUser(s))

+ 77 - 0
server/smtp_server/read_content_test.go

@@ -12,6 +12,7 @@ import (
 	"pmail/db"
 	"pmail/db"
 	parsemail2 "pmail/dto/parsemail"
 	parsemail2 "pmail/dto/parsemail"
 	"pmail/session"
 	"pmail/session"
+	"pmail/utils/context"
 	"testing"
 	"testing"
 	"time"
 	"time"
 )
 )
@@ -49,6 +50,11 @@ func TestNuisanace(t *testing.T) {
 
 
 	s := Session{
 	s := Session{
 		RemoteAddress: net.TCPAddrFromAddrPort(netip.AddrPortFrom(netip.AddrFrom4([4]byte{}), 25)),
 		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")
 	data, _ := os.ReadFile("../docs/nuisance/demo.txt")
@@ -122,6 +128,11 @@ Content-Type: text/html
 `
 `
 	s := Session{
 	s := Session{
 		RemoteAddress: net.TCPAddrFromAddrPort(netip.AddrPortFrom(netip.AddrFrom4([4]byte{}), 25)),
 		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)))
 	s.Data(bytes.NewReader([]byte(emailData)))
@@ -281,6 +292,11 @@ Content-Type: text/html
 
 
 	s := Session{
 	s := Session{
 		RemoteAddress: net.TCPAddrFromAddrPort(netip.AddrPortFrom(netip.AddrFrom4([4]byte{}), 25)),
 		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)))
 	s.Data(bytes.NewReader([]byte(deleteEmail)))
@@ -331,6 +347,11 @@ Content-Type: text/html
 
 
 	s := Session{
 	s := Session{
 		RemoteAddress: net.TCPAddrFromAddrPort(netip.AddrPortFrom(netip.AddrFrom4([4]byte{}), 25)),
 		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)))
 	s.Data(bytes.NewReader([]byte(readEmail)))
@@ -379,12 +400,63 @@ Content-Type: text/html
 
 
 	s := Session{
 	s := Session{
 		RemoteAddress: net.TCPAddrFromAddrPort(netip.AddrPortFrom(netip.AddrFrom4([4]byte{}), 25)),
 		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)))
 	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: <cf43cc780b72dad392d4f90dfced88a8@1231@111.com>
+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) {
 func TestRuleMove(t *testing.T) {
 	testInit()
 	testInit()
 
 
@@ -427,6 +499,11 @@ Content-Type: text/html
 
 
 	s := Session{
 	s := Session{
 		RemoteAddress: net.TCPAddrFromAddrPort(netip.AddrPortFrom(netip.AddrFrom4([4]byte{}), 25)),
 		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)))
 	s.Data(bytes.NewReader([]byte(moveEmail)))

+ 17 - 0
server/utils/send/send_test.go

@@ -68,6 +68,23 @@ func TestSendSohu(t *testing.T) {
 	Send(nil, e)
 	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("<div>这是Html</div>"),
+	}
+	Send(nil, e)
+}
+
 func Test_domainMatch(t *testing.T) {
 func Test_domainMatch(t *testing.T) {
 	domain := domainMatch("qq.com", nil)
 	domain := domainMatch("qq.com", nil)