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..a65d339 --- /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()) +// +//}