diff --git a/server/dto/parsemail/email.go b/server/dto/parsemail/email.go index 1179245..1dab338 100644 --- a/server/dto/parsemail/email.go +++ b/server/dto/parsemail/email.go @@ -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" @@ -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 { @@ -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) diff --git a/server/dto/parsemail/email_test.go b/server/dto/parsemail/email_test.go index bdf82cc..3c7c5e5 100644 --- a/server/dto/parsemail/email_test.go +++ b/server/dto/parsemail/email_test.go @@ -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{ @@ -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"}),