From 4d464b0a3c1a58bfdcca47fded580b2b3179f11c Mon Sep 17 00:00:00 2001 From: jinnrry Date: Sun, 3 Nov 2024 01:48:40 +0800 Subject: [PATCH] feature/v2.7.5 (#23) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1、非管理员修改昵称报错修复 2、IOS“邮件”客户端展示错误修复。 --- server/controllers/email/send.go | 14 ++++---- server/dto/parsemail/email.go | 2 ++ server/pop3_server/action_test.go | 55 +++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 server/pop3_server/action_test.go diff --git a/server/controllers/email/send.go b/server/controllers/email/send.go index 03c9221..ebfc4ae 100644 --- a/server/controllers/email/send.go +++ b/server/controllers/email/send.go @@ -65,21 +65,21 @@ func Send(ctx *context.Context, w http.ResponseWriter, req *http.Request) { return } - if !ctx.IsAdmin && reqData.From.Name != ctx.UserAccount { - response.NewErrorResponse(response.ParamsError, "params error", "").FPrint(w) - return - } - if reqData.From.Email != "" { infos := strings.Split(reqData.From.Email, "@") if len(infos) != 2 || !array.InArray(infos[1], config.Instance.Domains) { response.NewErrorResponse(response.ParamsError, "params error", "").FPrint(w) return } + if !ctx.IsAdmin && infos[0] != ctx.UserAccount { + response.NewErrorResponse(response.ParamsError, "params error", "").FPrint(w) + return + } + } - if reqData.From.Email == "" && reqData.From.Name != "" { - reqData.From.Email = reqData.From.Name + "@" + config.Instance.Domain + if reqData.From.Email == "" { + reqData.From.Email = ctx.UserAccount + "@" + config.Instance.Domain } if reqData.From.Email == "" { diff --git a/server/dto/parsemail/email.go b/server/dto/parsemail/email.go index 1b5c819..1f65c93 100644 --- a/server/dto/parsemail/email.go +++ b/server/dto/parsemail/email.go @@ -383,6 +383,7 @@ func (e *Email) BuildBytes(ctx *context.Context, dkim bool) []byte { log.WithContext(ctx).Fatal(err) } var th mail.InlineHeader + th.Header.Set("Content-Transfer-Encoding", "base64") th.SetContentType("text/plain", map[string]string{ "charset": "UTF-8", }) @@ -397,6 +398,7 @@ func (e *Email) BuildBytes(ctx *context.Context, dkim bool) []byte { html.SetContentType("text/html", map[string]string{ "charset": "UTF-8", }) + html.Header.Set("Content-Transfer-Encoding", "base64") w, err = tw.CreatePart(html) if err != nil { log.Fatal(err) diff --git a/server/pop3_server/action_test.go b/server/pop3_server/action_test.go new file mode 100644 index 0000000..581cdc4 --- /dev/null +++ b/server/pop3_server/action_test.go @@ -0,0 +1,55 @@ +package pop3_server + +import ( + "bytes" + "fmt" + "github.com/Jinnrry/gopop" + "github.com/Jinnrry/pmail/config" + "github.com/Jinnrry/pmail/db" + "github.com/Jinnrry/pmail/utils/context" + "github.com/emersion/go-message/mail" + "io" + "testing" +) + +func Test_action_Retr(t *testing.T) { + config.Init() + db.Init("") + + a := action{} + session := &gopop.Session{ + Ctx: &context.Context{ + UserID: 1, + }, + } + got, got1, err := a.Retr(session, 301) + + _, _, _ = got, got1, err +} + +func Test_email(t *testing.T) { + var b bytes.Buffer + + // Create our mail header + var h mail.Header + + // Create a new mail writer + mw, _ := mail.CreateWriter(&b, h) + + // Create a text part + tw, _ := mw.CreateInline() + + var html mail.InlineHeader + + html.Header.Set("Content-Transfer-Encoding", "base64") + w, _ := tw.CreatePart(html) + + io.WriteString(w, "=") + + w.Close() + + tw.Close() + + fmt.Printf("%s", b.String()) + +}