1、支持多域名 2、支持PostgreSQL数据库 3、更新全部依赖 4、支持垃圾箱邮件删除 Co-authored-by: jinnrry <i@jinnrry.com>
This commit is contained in:
1 parent
402e00150d
commit
9ffbdf41c3
34 files changed
+394
-222
No files matched your search
@@ -11,7 +11,8 @@ import (
|
||||
)
|
||||
|
||||
type emailDeleteRequest struct {
|
||||
IDs []int `json:"ids"`
|
||||
IDs []int64 `json:"ids"`
|
||||
ForcedDel bool `json:"forcedDel"`
|
||||
}
|
||||
|
||||
func EmailDelete(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
@@ -30,7 +31,7 @@ func EmailDelete(ctx *context.Context, w http.ResponseWriter, req *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
err = del_email.DelEmail(ctx, reqData.IDs)
|
||||
err = del_email.DelEmail(ctx, reqData.IDs, reqData.ForcedDel)
|
||||
if err != nil {
|
||||
response.NewErrorResponse(response.ServerError, err.Error(), "").FPrint(w)
|
||||
return
|
||||
|
||||
@@ -26,6 +26,7 @@ type emilItem struct {
|
||||
Datetime string `json:"datetime"`
|
||||
IsRead bool `json:"is_read"`
|
||||
Sender User `json:"sender"`
|
||||
To []User `json:"to"`
|
||||
Dangerous bool `json:"dangerous"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
@@ -76,6 +77,9 @@ func EmailList(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
var sender User
|
||||
_ = json.Unmarshal([]byte(email.Sender), &sender)
|
||||
|
||||
var tos []User
|
||||
_ = json.Unmarshal([]byte(email.To), &tos)
|
||||
|
||||
lst = append(lst, &emilItem{
|
||||
ID: email.Id,
|
||||
Title: email.Subject,
|
||||
@@ -83,6 +87,7 @@ func EmailList(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
Datetime: email.SendDate.Format("2006-01-02 15:04:05"),
|
||||
IsRead: email.IsRead == 1,
|
||||
Sender: sender,
|
||||
To: tos,
|
||||
Dangerous: email.SPFCheck == 0 && email.DKIMCheck == 0,
|
||||
Error: email.Error.String,
|
||||
})
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
"pmail/hooks/framework"
|
||||
"pmail/i18n"
|
||||
"pmail/models"
|
||||
"pmail/utils/array"
|
||||
"pmail/utils/async"
|
||||
"pmail/utils/context"
|
||||
"pmail/utils/send"
|
||||
@@ -69,6 +70,14 @@ func Send(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
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 reqData.From.Email == "" && reqData.From.Name != "" {
|
||||
reqData.From.Email = reqData.From.Name + "@" + config.Instance.Domain
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"pmail/dto"
|
||||
"pmail/dto/response"
|
||||
"pmail/i18n"
|
||||
"pmail/models"
|
||||
"pmail/services/group"
|
||||
"pmail/utils/array"
|
||||
"pmail/utils/context"
|
||||
@@ -66,17 +67,19 @@ func AddGroup(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
log.WithContext(ctx).Errorf("%+v", err)
|
||||
}
|
||||
|
||||
res, err := db.Instance.Exec(db.WithContext(ctx, "insert into `group` (name,parent_id,user_id) values (?,?,?)"), reqData.Name, reqData.ParentId, ctx.UserID)
|
||||
var newGroup models.Group = models.Group{
|
||||
Name: reqData.Name,
|
||||
ParentId: reqData.ParentId,
|
||||
UserId: ctx.UserID,
|
||||
}
|
||||
|
||||
_, err = db.Instance.Insert(&newGroup)
|
||||
if err != nil {
|
||||
response.NewErrorResponse(response.ServerError, "DBError", err.Error()).FPrint(w)
|
||||
return
|
||||
}
|
||||
id, err := res.LastInsertId()
|
||||
if err != nil {
|
||||
response.NewErrorResponse(response.ServerError, "DBError", err.Error()).FPrint(w)
|
||||
return
|
||||
}
|
||||
response.NewSuccessResponse(id).FPrint(w)
|
||||
|
||||
response.NewSuccessResponse(newGroup.ID).FPrint(w)
|
||||
}
|
||||
|
||||
type delGroupRequest struct {
|
||||
|
||||
@@ -6,11 +6,13 @@ import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
"io"
|
||||
"net/http"
|
||||
"pmail/config"
|
||||
"pmail/db"
|
||||
"pmail/dto/response"
|
||||
"pmail/i18n"
|
||||
"pmail/models"
|
||||
"pmail/session"
|
||||
"pmail/utils/array"
|
||||
"pmail/utils/context"
|
||||
"pmail/utils/errors"
|
||||
"pmail/utils/password"
|
||||
@@ -44,10 +46,16 @@ func Login(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
if user.ID != 0 {
|
||||
userStr, _ := json.Marshal(user)
|
||||
session.Instance.Put(req.Context(), "user", string(userStr))
|
||||
|
||||
domains := config.Instance.Domains
|
||||
domains = array.Difference(domains, []string{config.Instance.Domain})
|
||||
domains = append([]string{config.Instance.Domain}, domains...)
|
||||
|
||||
response.NewSuccessResponse(map[string]any{
|
||||
"account": user.Account,
|
||||
"name": user.Name,
|
||||
"is_admin": user.IsAdmin,
|
||||
"domains": domains,
|
||||
}).FPrint(w)
|
||||
} else {
|
||||
response.NewErrorResponse(response.ParamsError, i18n.GetText(ctx.Lang, "aperror"), "").FPrint(w)
|
||||
|
||||
+11
-10
@@ -3,6 +3,7 @@ package controllers
|
||||
import (
|
||||
"encoding/json"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cast"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -41,9 +42,8 @@ func Setup(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
|
||||
var reqData map[string]string
|
||||
err = json.Unmarshal(reqBytes, &reqData)
|
||||
|
||||
if err != nil {
|
||||
response.NewSuccessResponse("").FPrint(w)
|
||||
response.NewErrorResponse(response.ServerError, "", err.Error()).FPrint(w)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ func Setup(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
}
|
||||
|
||||
if reqData["step"] == "database" && reqData["action"] == "set" {
|
||||
err := setup.SetDatabaseSettings(ctx, reqData["db_type"], reqData["db_dsn"])
|
||||
err := setup.SetDatabaseSettings(ctx, cast.ToString(reqData["db_type"]), cast.ToString(reqData["db_dsn"]))
|
||||
if err != nil {
|
||||
response.NewErrorResponse(response.ServerError, err.Error(), "").FPrint(w)
|
||||
return
|
||||
@@ -83,7 +83,7 @@ func Setup(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
}
|
||||
|
||||
if reqData["step"] == "password" && reqData["action"] == "set" {
|
||||
err := setup.SetAdminPassword(ctx, reqData["account"], reqData["password"])
|
||||
err := setup.SetAdminPassword(ctx, cast.ToString(reqData["account"]), cast.ToString(reqData["password"]))
|
||||
if err != nil {
|
||||
response.NewErrorResponse(response.ServerError, err.Error(), "").FPrint(w)
|
||||
return
|
||||
@@ -93,20 +93,21 @@ func Setup(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
}
|
||||
|
||||
if reqData["step"] == "domain" && reqData["action"] == "get" {
|
||||
smtpDomain, webDomain, err := setup.GetDomainSettings()
|
||||
smtpDomain, webDomain, domains, err := setup.GetDomainSettings()
|
||||
if err != nil {
|
||||
response.NewErrorResponse(response.ServerError, err.Error(), "").FPrint(w)
|
||||
return
|
||||
}
|
||||
response.NewSuccessResponse(map[string]string{
|
||||
response.NewSuccessResponse(map[string]any{
|
||||
"smtp_domain": smtpDomain,
|
||||
"web_domain": webDomain,
|
||||
"domains": domains,
|
||||
}).FPrint(w)
|
||||
return
|
||||
}
|
||||
|
||||
if reqData["step"] == "domain" && reqData["action"] == "set" {
|
||||
err := setup.SetDomainSettings(reqData["smtp_domain"], reqData["web_domain"])
|
||||
err := setup.SetDomainSettings(cast.ToString(reqData["smtp_domain"]), cast.ToString(reqData["web_domain"]), reqData["multi_domain"])
|
||||
if err != nil {
|
||||
response.NewErrorResponse(response.ServerError, err.Error(), "").FPrint(w)
|
||||
return
|
||||
@@ -148,20 +149,20 @@ func Setup(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
keyPath := reqData["key_path"]
|
||||
crtPath := reqData["crt_path"]
|
||||
|
||||
_, err := os.Stat(keyPath)
|
||||
_, err := os.Stat(cast.ToString(keyPath))
|
||||
if err != nil {
|
||||
response.NewErrorResponse(response.ServerError, err.Error(), "").FPrint(w)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = os.Stat(crtPath)
|
||||
_, err = os.Stat(cast.ToString(crtPath))
|
||||
if err != nil {
|
||||
response.NewErrorResponse(response.ServerError, err.Error(), "").FPrint(w)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
err = ssl.SetSSL(reqData["ssl_type"], reqData["key_path"], reqData["crt_path"])
|
||||
err = ssl.SetSSL(cast.ToString(reqData["ssl_type"]), cast.ToString(reqData["key_path"]), cast.ToString(reqData["crt_path"]))
|
||||
if err != nil {
|
||||
response.NewErrorResponse(response.ServerError, err.Error(), "").FPrint(w)
|
||||
return
|
||||
|
||||
@@ -7,9 +7,11 @@ import (
|
||||
"io"
|
||||
"math"
|
||||
"net/http"
|
||||
"pmail/config"
|
||||
"pmail/db"
|
||||
"pmail/dto/response"
|
||||
"pmail/models"
|
||||
"pmail/utils/array"
|
||||
"pmail/utils/context"
|
||||
"pmail/utils/password"
|
||||
)
|
||||
@@ -104,10 +106,16 @@ func UserList(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
}
|
||||
|
||||
func Info(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
|
||||
domains := config.Instance.Domains
|
||||
domains = array.Difference(domains, []string{config.Instance.Domain})
|
||||
domains = append([]string{config.Instance.Domain}, domains...)
|
||||
|
||||
response.NewSuccessResponse(map[string]any{
|
||||
"account": ctx.UserAccount,
|
||||
"name": ctx.UserName,
|
||||
"is_admin": ctx.IsAdmin,
|
||||
"domains": domains,
|
||||
}).FPrint(w)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user