空指针异常修复

This commit is contained in:
jinnrry
2024-01-29 19:38:33 +08:00
parent 2467061431
commit dbc125d1c2
3 changed files with 98 additions and 0 deletions

View File

@@ -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))

View File

@@ -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: <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) {
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)))

View File

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