Skip to content

Commit

Permalink
空指针异常修复
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinnrry committed Jan 29, 2024
1 parent 2467061 commit dbc125d
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
4 changes: 4 additions & 0 deletions server/dto/parsemail/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
77 changes: 77 additions & 0 deletions server/smtp_server/read_content_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"pmail/db"
parsemail2 "pmail/dto/parsemail"
"pmail/session"
"pmail/utils/context"
"testing"
"time"
)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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)))
Expand Down
17 changes: 17 additions & 0 deletions server/utils/send/send_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit dbc125d

Please sign in to comment.