Skip to content

Commit

Permalink
RFC 5322 添加MessageId
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinnrry committed Nov 22, 2023
1 parent f00aa08 commit b78bf61
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions server/controllers/email/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ func Send(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
return
}

e.MessageId = emailId

async.New(ctx).Process(func(p any) {
errMsg := ""
err, sendErr := send.Send(ctx, e)
Expand Down
5 changes: 4 additions & 1 deletion server/dto/parsemail/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
_ "github.com/emersion/go-message/charset"
"github.com/emersion/go-message/mail"
log "github.com/sirupsen/logrus"
"github.com/spf13/cast"
"io"
"net/textproto"
"pmail/utils/array"
Expand Down Expand Up @@ -54,6 +55,7 @@ type Email struct {
IsRead int
Status int // 0未发送,1已发送,2发送失败,3删除
GroupId int // 分组id
MessageId int64
}

func NewEmailFromReader(to []string, r io.Reader) *Email {
Expand Down Expand Up @@ -204,6 +206,7 @@ func (e *Email) ForwardBuildBytes(ctx *context.Context, forwardAddress string) [
h.SetAddressList("From", from)
h.SetAddressList("To", to)
h.SetText("Subject", e.Subject)
h.SetMessageID(cast.ToString(e.MessageId))
if len(e.Cc) != 0 {
cc := []*mail.Address{}
for _, user := range e.Cc {
Expand Down Expand Up @@ -291,7 +294,7 @@ func (e *Email) BuildBytes(ctx *context.Context, dkim bool) []byte {
} else {
h.SetDate(time.Now())
}

h.SetMessageID(cast.ToString(e.MessageId))
h.SetAddressList("From", from)
h.SetAddressList("To", to)
h.SetText("Subject", e.Subject)
Expand Down
6 changes: 5 additions & 1 deletion server/smtp_server/read_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func saveEmail(ctx *context.Context, email *parsemail.Email, emailType int, SPFS
}

sql := "INSERT INTO email (type, send_date, subject, reply_to, from_name, from_address, `to`, bcc, cc, text, html, sender, attachments,spf_check, dkim_check, create_time,is_read,status,group_id) VALUES (?,?,?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
_, err := db.Instance.Exec(sql,
res, err := db.Instance.Exec(sql,
emailType,
email.Date,
email.Subject,
Expand All @@ -165,6 +165,10 @@ func saveEmail(ctx *context.Context, email *parsemail.Email, emailType int, SPFS
if err != nil {
log.WithContext(ctx).Println("mysql insert error:", err.Error())
}
insertId, _ := res.LastInsertId()
if insertId > 0 {
email.MessageId = insertId
}

return nil
}
Expand Down

0 comments on commit b78bf61

Please sign in to comment.