Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/v2.7.5 (#23) #221

Merged
merged 2 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
//
//}