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 d28bff6 commit b1d3c14
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
7 changes: 4 additions & 3 deletions server/dto/parsemail/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package parsemail

import (
"bytes"
"fmt"
"github.com/emersion/go-message"
_ "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/config"
"pmail/utils/array"
"pmail/utils/context"
"regexp"
Expand Down Expand Up @@ -206,7 +207,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))
h.SetMessageID(fmt.Sprintf("%d@%s", e.MessageId, config.Instance.Domain))
if len(e.Cc) != 0 {
cc := []*mail.Address{}
for _, user := range e.Cc {
Expand Down Expand Up @@ -294,7 +295,7 @@ func (e *Email) BuildBytes(ctx *context.Context, dkim bool) []byte {
} else {
h.SetDate(time.Now())
}
h.SetMessageID(cast.ToString(e.MessageId))
h.SetMessageID(fmt.Sprintf("%d@%s", e.MessageId, config.Instance.Domain))
h.SetAddressList("From", from)
h.SetAddressList("To", to)
h.SetText("Subject", e.Subject)
Expand Down
35 changes: 35 additions & 0 deletions server/dto/parsemail/email_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,43 @@ import (
"bytes"
"fmt"
"github.com/emersion/go-message"
log "github.com/sirupsen/logrus"
"io"
"os"
"pmail/config"
"pmail/db"
"pmail/session"
"testing"
"time"
)

func testInit() {
// 设置日志格式为json格式
//log.SetFormatter(&log.JSONFormatter{})

log.SetReportCaller(true)
log.SetFormatter(&log.TextFormatter{
//以下设置只是为了使输出更美观
DisableColors: true,
TimestampFormat: "2006-01-02 15:03:04",
})

// 设置将日志输出到标准输出(默认的输出为stderr,标准错误)
// 日志消息输出可以是任意的io.writer类型
log.SetOutput(os.Stdout)

// 设置日志级别为warn以上
log.SetLevel(log.TraceLevel)

var cst, _ = time.LoadLocation("Asia/Shanghai")
time.Local = cst

config.Init()
Init()
db.Init()
session.Init()

}
func TestEmail_domainMatch(t *testing.T) {
//e := &Email{}
//dnsNames := []string{
Expand Down Expand Up @@ -77,6 +110,8 @@ func TestEmailBuidlers(t *testing.T) {
}

func TestEmail_builder(t *testing.T) {
testInit()

e := Email{
From: buildUser("i@test.com"),
To: buildUsers([]string{"to@test.com"}),
Expand Down

0 comments on commit b1d3c14

Please sign in to comment.