Skip to content

Commit

Permalink
feature/v2.7.5 (#23)
Browse files Browse the repository at this point in the history
1、非管理员修改昵称报错修复
2、IOS“邮件”客户端展示错误修复。
  • Loading branch information
Jinnrry committed Nov 2, 2024
1 parent 2231172 commit 4d464b0
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 7 deletions.
14 changes: 7 additions & 7 deletions server/controllers/email/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand Down
2 changes: 2 additions & 0 deletions server/dto/parsemail/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
})
Expand All @@ -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)
Expand Down
55 changes: 55 additions & 0 deletions server/pop3_server/action_test.go
Original file line number Diff line number Diff line change
@@ -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())

}

0 comments on commit 4d464b0

Please sign in to comment.