From bdee80efc618b957ca412e085e8c0ccb35b75325 Mon Sep 17 00:00:00 2001 From: jinnrry Date: Sun, 14 Jan 2024 19:21:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=94=B6=E5=8F=91=E4=BB=B6?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E9=80=BB=E8=BE=91=EF=BC=8C=E4=BC=98=E5=8C=96?= =?UTF-8?q?SMTP=E9=82=AE=E4=BB=B6=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/config/config.go | 2 +- server/pop3_server/action.go | 13 +++++++++++-- server/smtp_server/read_content.go | 7 +++---- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/server/config/config.go b/server/config/config.go index 3930dc9..d2e8d54 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -39,7 +39,7 @@ type Config struct { //go:embed tables/* var tableConfig embed.FS -const Version = "2.3.4" +const Version = "2.3.6" const DBTypeMySQL = "mysql" const DBTypeSQLite = "sqlite" diff --git a/server/pop3_server/action.go b/server/pop3_server/action.go index edd86c0..d0818e1 100644 --- a/server/pop3_server/action.go +++ b/server/pop3_server/action.go @@ -19,6 +19,7 @@ import ( type action struct { } +// Custom 非标准命令 func (a action) Custom(session *gopop.Session, cmd string, args []string) ([]string, error) { if session.Ctx == nil { tc := &context.Context{} @@ -30,6 +31,7 @@ func (a action) Custom(session *gopop.Session, cmd string, args []string) ([]str return nil, nil } +// Capa 说明服务端支持的命令列表 func (a action) Capa(session *gopop.Session) ([]string, error) { if session.Ctx == nil { tc := &context.Context{} @@ -64,6 +66,7 @@ func (a action) Capa(session *gopop.Session) ([]string, error) { return ret, nil } +// User 提交登陆的用户名 func (a action) User(session *gopop.Session, username string) error { if session.Ctx == nil { tc := &context.Context{} @@ -83,6 +86,7 @@ func (a action) User(session *gopop.Session, username string) error { return nil } +// Pass 提交密码验证 func (a action) Pass(session *gopop.Session, pwd string) error { if session.Ctx == nil { tc := &context.Context{} @@ -114,6 +118,7 @@ func (a action) Pass(session *gopop.Session, pwd string) error { return errors.New("password error") } +// Apop APOP登陆命令 func (a action) Apop(session *gopop.Session, username, digest string) error { if session.Ctx == nil { tc := &context.Context{} @@ -156,11 +161,12 @@ type statInfo struct { Size int64 `json:"size"` } +// Stat 查询邮件数量 func (a action) Stat(session *gopop.Session) (msgNum, msgSize int64, err error) { log.WithContext(session.Ctx).Debugf("POP3 CMD: STAT") var si statInfo - err = db.Instance.Get(&si, db.WithContext(session.Ctx.(*context.Context), "select count(1) as `num`, sum(length(text)+length(html)) as `size` from email")) + err = db.Instance.Get(&si, db.WithContext(session.Ctx.(*context.Context), "select count(1) as `num`, sum(length(text)+length(html)) as `size` from email where type = 0")) if err != nil && !errors.Is(err, sql.ErrNoRows) { log.WithContext(session.Ctx.(*context.Context)).Errorf("%+v", err) err = nil @@ -213,6 +219,7 @@ type listItem struct { Size int64 `json:"size"` } +// List 邮件列表 func (a action) List(session *gopop.Session, msg string) ([]gopop.MailInfo, error) { log.WithContext(session.Ctx).Debugf("POP3 CMD: LIST ,Args:%s", msg) var res []listItem @@ -230,7 +237,7 @@ func (a action) List(session *gopop.Session, msg string) ([]gopop.MailInfo, erro ssql = db.WithContext(session.Ctx.(*context.Context), "SELECT id, ifnull(LENGTH(TEXT) , 0) + ifnull(LENGTH(html) , 0) AS `size` FROM email where id =?") err = db.Instance.Select(&res, ssql, listId) } else { - ssql = db.WithContext(session.Ctx.(*context.Context), "SELECT id, ifnull(LENGTH(TEXT) , 0) + ifnull(LENGTH(html) , 0) AS `size` FROM email") + ssql = db.WithContext(session.Ctx.(*context.Context), "SELECT id, ifnull(LENGTH(TEXT) , 0) + ifnull(LENGTH(html) , 0) AS `size` FROM email where type = 0") err = db.Instance.Select(&res, ssql) } @@ -249,6 +256,7 @@ func (a action) List(session *gopop.Session, msg string) ([]gopop.MailInfo, erro return ret, nil } +// Retr 获取邮件详情 func (a action) Retr(session *gopop.Session, id int64) (string, int64, error) { log.WithContext(session.Ctx).Debugf("POP3 CMD: RETR ,Args:%d", id) email, err := detail.GetEmailDetail(session.Ctx.(*context.Context), cast.ToInt(id), false) @@ -262,6 +270,7 @@ func (a action) Retr(session *gopop.Session, id int64) (string, int64, error) { } +// Delete 删除邮件 func (a action) Delete(session *gopop.Session, id int64) error { log.WithContext(session.Ctx).Debugf("POP3 CMD: DELE ,Args:%d", id) diff --git a/server/smtp_server/read_content.go b/server/smtp_server/read_content.go index ed6cc43..592a801 100644 --- a/server/smtp_server/read_content.go +++ b/server/smtp_server/read_content.go @@ -13,7 +13,6 @@ import ( "pmail/dto/parsemail" "pmail/hooks" "pmail/services/rule" - "pmail/utils/array" "pmail/utils/async" "pmail/utils/context" "pmail/utils/send" @@ -60,9 +59,9 @@ func (s *Session) Data(r io.Reader) error { } } - // 判断是收信还是转发 - account, domain := email.From.GetDomainAccount() - if array.InArray(domain, config.Instance.Domains) && s.Ctx.UserName == account { + // 判断是收信还是转发,只要是登陆了,都当成转发处理 + //account, domain := email.From.GetDomainAccount() + if s.Ctx.UserID > 0 { // 转发 err := saveEmail(ctx, email, 1, true, true) if err != nil {