feature/v2.7.5 (#23)

1、非管理员修改昵称报错修复
2、IOS“邮件”客户端展示错误修复。
This commit is contained in:
jinnrry 2024-11-03 01:48:40 +08:00
parent 223117283b
commit 4d464b0a3c
3 changed files with 64 additions and 7 deletions

View File

@ -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 == "" {

View File

@ -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)

View File

@ -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())
}