From 3537fa335e4185288b58cac493f5c02be621b5fe Mon Sep 17 00:00:00 2001 From: jinnrry Date: Sat, 28 Sep 2024 11:05:27 +0800 Subject: [PATCH] feature/v2.7.3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pop协议数据中增加messageId字段 --- server/models/email.go | 2 ++ server/pop3_server/action.go | 28 +++++++++++++++++++++++----- server/utils/send/send.go | 2 +- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/server/models/email.go b/server/models/email.go index f38294f..6e4b0bf 100644 --- a/server/models/email.go +++ b/server/models/email.go @@ -4,6 +4,7 @@ import ( "database/sql" "encoding/json" "github.com/Jinnrry/pmail/dto/parsemail" + "github.com/spf13/cast" "time" ) @@ -122,6 +123,7 @@ func (d *Email) MarshalJSON() ([]byte, error) { func (d *Email) ToTransObj() *parsemail.Email { return &parsemail.Email{ + MessageId: cast.ToInt64(d.Id), From: &parsemail.User{ Name: d.FromName, EmailAddress: d.FromAddress, diff --git a/server/pop3_server/action.go b/server/pop3_server/action.go index 9617cbc..03f5c85 100644 --- a/server/pop3_server/action.go +++ b/server/pop3_server/action.go @@ -67,6 +67,8 @@ func (a action) Capa(session *gopop.Session) ([]string, error) { ret = append(ret, "STLS") } + log.WithContext(session.Ctx).Debugf("CAPA \n %+v", ret) + return ret, nil } @@ -175,6 +177,7 @@ func (a action) Uidl(session *gopop.Session, msg string) ([]gopop.UidlItem, erro reqId := cast.ToInt64(msg) if reqId > 0 { + log.WithContext(session.Ctx).Debugf("Uidl \n %+v", reqId) return []gopop.UidlItem{ { Id: reqId, @@ -199,6 +202,8 @@ func (a action) Uidl(session *gopop.Session, msg string) ([]gopop.UidlItem, erro UnionId: cast.ToString(re.Id), }) } + + log.WithContext(session.Ctx).Debugf("Uidl \n %+v", ret) return ret, nil } @@ -224,17 +229,25 @@ func (a action) List(session *gopop.Session, msg string) ([]gopop.MailInfo, erro if err != nil { return nil, err } - res = append(res, listItem{ + item := listItem{ Id: cast.ToInt64(info.Id), Size: cast.ToInt64(info.Size), - }) + } + if item.Size == 0 { + item.Size = 9999 + } + res = append(res, item) } else { emailList, _ := list.GetEmailList(session.Ctx.(*context.Context), dto.SearchTag{Type: consts.EmailTypeReceive, Status: -1, GroupId: -1}, "", true, 0, 99999) for _, info := range emailList { - res = append(res, listItem{ + item := listItem{ Id: cast.ToInt64(info.Id), Size: cast.ToInt64(info.Size), - }) + } + if item.Size == 0 { + item.Size = 9999 + } + res = append(res, item) } } ret := []gopop.MailInfo{} @@ -244,6 +257,8 @@ func (a action) List(session *gopop.Session, msg string) ([]gopop.MailInfo, erro Size: re.Size, }) } + + log.WithContext(session.Ctx).Debugf("List \n %+v", ret) return ret, nil } @@ -257,6 +272,7 @@ func (a action) Retr(session *gopop.Session, id int64) (string, int64, error) { } ret := email.ToTransObj().BuildBytes(session.Ctx.(*context.Context), false) + log.WithContext(session.Ctx).Debugf("Retr \n %+v", string(ret)) return string(ret), cast.ToInt64(len(ret)), nil } @@ -297,7 +313,9 @@ func (a action) Top(session *gopop.Session, id int64, n int) (string, error) { return string(ret), nil } - return array.Join(res[0:headerEndLine+n+1], "\n"), nil + lines := array.Join(res[0:headerEndLine+n+1], "\n") + log.WithContext(session.Ctx).Debugf("Top \n %+v", lines) + return lines, nil } diff --git a/server/utils/send/send.go b/server/utils/send/send.go index 06e077b..4785cc0 100644 --- a/server/utils/send/send.go +++ b/server/utils/send/send.go @@ -149,7 +149,7 @@ func Send(ctx *context.Context, e *parsemail.Email) (error, map[string]error) { mxHost: "smtp." + args[1], } if err != nil { - log.WithContext(ctx).Errorf(s.EmailAddress, "域名mx记录查询失败") + log.WithContext(ctx).Errorf(s.EmailAddress, "域名mx记录查询失败,检查邮箱是否存在!") } if len(mxInfo) > 0 { address = mxDomain{