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

V2.4.7 #112

Merged
merged 5 commits into from
Apr 30, 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
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,6 @@ package: clean
mv server/hooks/web_push/output/* output/plugins
mv server/hooks/wechat_push/output/* output/plugins
cp README.md output/

test:
export setup_port=17888 && cd server && go test -v ./...
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ The code is in `server` folder.

`make build`

4、Unit test

`make test`

## Api Documentation

Expand Down
6 changes: 5 additions & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,14 @@ SMTP端口: 25/465(SSL)

后端代码进入 `server`文件夹,运行 `main.go`文件

3、编译该项目
3、编译项目

`make build`

4、单元测试

`make test`

## 后端接口文档

[go to wiki](https://github.com/Jinnrry/PMail/wiki/%E5%90%8E%E7%AB%AF%E6%8E%A5%E5%8F%A3%E6%96%87%E6%A1%A3)
Expand Down
17 changes: 1 addition & 16 deletions server/config/config.json
Original file line number Diff line number Diff line change
@@ -1,16 +1 @@
{
"logLevel": "debug",
"domain": "domain.com",
"webDomain": "mail.domain.com",
"dkimPrivateKeyPath": "config/dkim/dkim.priv",
"sslType": "0",
"SSLPrivateKeyPath": "config/ssl/private.key",
"SSLPublicKeyPath": "config/ssl/public.crt",
"dbDSN": "./config/pmail.db",
"dbType": "sqlite",
"spamFilterLevel": 1,
"httpPort": 80,
"httpsPort": 443,
"isInit": true,
"httpsEnabled": 1
}
{"logLevel":"","domain":"test.domain","domains":null,"webDomain":"mail.test.domain","dkimPrivateKeyPath":"config/dkim/dkim.priv","sslType":"1","SSLPrivateKeyPath":"./config/ssl/private.key","SSLPublicKeyPath":"./config/ssl/public.crt","dbDSN":"./config/pmail_temp.db","dbType":"sqlite","httpsEnabled":2,"spamFilterLevel":0,"httpPort":0,"httpsPort":0,"weChatPushAppId":"","weChatPushSecret":"","weChatPushTemplateId":"","weChatPushUserId":"","tgBotToken":"","tgChatId":"","isInit":true,"webPushUrl":"","webPushToken":""}
38 changes: 25 additions & 13 deletions server/config/ssl/private.key
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQDhh1fqAdYCSifPaCGfm2CjngcPaS7XehYdojBPPp5oEorWZFo1
3Rghfh7qIXYp4nruUwfKgIPM95nYNqTnXolhUm5ywYDAhfJquuquJ7cAPhyx4SwG
o58RgcJCM04yVKdxivskMiJvgUDz1ymdf6OA7MMbgGEcdky73TdC3FkfZQIDAQAB
AoGAe5shPPj6oVChVxSccQzIv4QqHHEqoiCgpGczEQuh6CpZe72Oj7z4r8qfCPWD
/NrLQ3mwaHVdR2ZhJFZ2tPRkWDI6hlK3IrC7A9LGoYCeV0AiDgMvzhQrWFjaw92u
V9OS7tgYkewimcDaK1eF1hH+GOh2aToWMKAgCCOoXjuVhsECQQD4lc/4/Km7hrEQ
JQGLOnB4qxdFk3HflShsXjnc/ydapQ5zCzCuCO7X89Jr8KpegC1SVmFR3YRjPNG4
R36yLR8RAkEA6EF45wYmQfAi9w0AMlmnXanHcWXBauOrbqv2M9cjpsBvxcIjRvHp
fca/LjEBf74X4YBhCCN1P7zRPLO2tYJjFQJAFdsGF/wO6D/lXWgDhLw0m0dfmmxm
PKQek7iNGdMNILkWViMLuqFqbm4vd/IG6JwYX/7cO5hgRWFZhvwyNXQmIQJBAOPX
Dqb79l3rGDHpVA8Qukn8+sV4gBS+wXcxRLY4UCYOU9fZikfXmymi5fuHYaQSNFUo
XofgWO4s6co1toA7J70CQ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3shIRaFeLdeofNFNZbQWpWsfG3HxItJSc5NV12dxHccnm
KJpHeAsy/uVAQLz32xJ2ssV4lvxE8xcgWHRZGr0CgYBiiYV089QFiTGS5Yu0tmOl
yOZ1q8a8JsyJzpPVnfrGeS20cFS8pFlPjNDnYXu6wcJvBQIAvcCKdMEVki/tKtZn
VV3mlDfC6R1xP8327n0mPlZddSKdjeHygalWHDOV6tBxMbvzR2s8zqWq+i1JQYWV
SYIu1sbiarIuOUPlMs2ncQKBgQC/jigCbPx5kGsG23PPHLZf8lfB8fbVAiGVDVD9
KMwL4y1abKl5/FsxjaacUf7VA1PWUmZ/wAhCuzRFqNy+JpYRAZst9lrjQVC57UrU
xU09rg9HB313bqEWxdaLlkLL+vJY+MrUWan1jd99z/N5JeEErYb9fYrmuQMdxdk0
uBaKLQKBgQC5Ot1cGmm2kwYJ4EMnTZKC2Kn9gDxXE0c92GkNhqU2ciuycy3vcl1U
QN+347AP2z5ISblffXhjcDf1Z1JJEQqq8WrfBkEwkIK74++vdVHojtObEiD2EQwA
c9s2jI4r7TCPXbtJ01v4GIaxXRBkhvN/Cg26fSgM5emrvFJmywPEwQ==
-----END RSA PRIVATE KEY-----
73 changes: 59 additions & 14 deletions server/config/ssl/public.crt
Original file line number Diff line number Diff line change
@@ -1,16 +1,61 @@
-----BEGIN CERTIFICATE-----
MIICcjCCAdsCFDLeR0jPO+9Q/nadNrHGI3EG2eHoMA0GCSqGSIb3DQEBCwUAMHgx
CzAJBgNVBAYTAkNOMQswCQYDVQQIDAJCSjEQMA4GA1UEBwwHQmVpSmluZzENMAsG
A1UECgwETnVsbDENMAsGA1UECwwETnVsbDEOMAwGA1UEAwwFUE1haWwxHDAaBgkq
hkiG9w0BCQEWDWlAamlubnJyeS5jb20wHhcNMjMwODIzMTMyMTM0WhcNMzMwODIw
MTMyMTM0WjB4MQswCQYDVQQGEwJDTjELMAkGA1UECAwCQkoxEDAOBgNVBAcMB0Jl
aUppbmcxDTALBgNVBAoMBE51bGwxDT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UFBwEBBCYwJDAiBggrBgEFBQcw
AoYWaHR0cDovL3gxLmkubGVuY3Iub3JnLzAnBgNVHR8EIDAeMBygGqAYhhZodHRw
Oi8veDEuYy5sZW5jci5vcmcvMCIGA1UdIAQbMBkwCAYGZ4EMAQIBMA0GCysGAQQB
gt8TAQEBMA0GCSqGSIb3DQEBCwUAA4ICAQCFyk5HPqP3hUSFvNVneLKYY611TR6W
PTNlclQtgaDqw+34IL9fzLdwALduO/ZelN7kIJ+m74uyA+eitRY8kc607TkC53wl
ikfmZW4/RvTZ8M6UK+5UzhK8jCdLuMGYL6KvzXGRSgi3yLgjewQtCPkIVz6D2QQz
CkcheAmCJ8MqyJu5zlzyZMjAvnnAT45tRAxekrsu94sQ4egdRCnbWSDtY7kh+BIm
lJNXoB1lBMEKIq4QDUOXoRgffuDghje1WrG9ML+Hbisq/yFOGwXD9RiX8F6sw6W4
avAuvDszue5L3sz85K+EC4Y/wFVDNvZo4TYXao6Z0f+lQKc0t8DQYzk1OXVu8rp2
yJMC6alLbBfODALZvYH7n7do1AZls4I9d1P4jnkDrQoxB3UqQ9hVl3LEKQ73xF1O
yK5GhDDX8oVfGKF5u+decIsH4YaTw7mP3GFxJSqv3+0lUFJoi5Lc5da149p90Ids
hCExroL1+7mryIkXPeFM5TgO9r0rvZaBFOvV2z0gp35Z0+L4WPlbuEjN/lxPFin+
HlUjr8gRsI3qfJOQFy/9rKIJR0Y/8Omwt/8oTWgy1mdeHmmjk7j1nYsvC9JSQ6Zv
MldlTTKB3zhThV1+XWYp6rjd5JW1zbVWEkLNxE7GJThEUG3szgBVGP7pSWTUTsqX
nLRbwHOoq7hHwg==
-----END CERTIFICATE-----
22 changes: 21 additions & 1 deletion server/controllers/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import (
"pmail/dto"
"pmail/dto/response"
"pmail/i18n"
"pmail/models"
"pmail/services/rule"
"pmail/utils/address"
"pmail/utils/array"
"pmail/utils/context"
"pmail/utils/errors"
)

func GetRule(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
Expand Down Expand Up @@ -48,14 +50,32 @@ func UpsertRule(ctx *context.Context, w http.ResponseWriter, req *http.Request)
}
}

err = data.Encode().Save(ctx)
err = save(ctx, data.Encode())
if err != nil {
response.NewErrorResponse(response.ServerError, "server error", err).FPrint(w)
return
}
response.NewSuccessResponse("succ").FPrint(w)
}

func save(ctx *context.Context, p *models.Rule) error {

if p.Id > 0 {
_, err := db.Instance.Exec(db.WithContext(ctx, "update rule set name=? ,value = ? ,action = ?,params = ?,sort = ? where id = ?"), p.Name, p.Value, p.Action, p.Params, p.Sort, p.Id)
if err != nil {
return errors.Wrap(err)
}
return nil
} else {
_, err := db.Instance.Exec(db.WithContext(ctx, "insert into rule (name,value,user_id,action,params,sort) values (?,?,?,?,?,?)"), p.Name, p.Value, ctx.UserID, p.Action, p.Params, p.Sort)
if err != nil {
return errors.Wrap(err)
}
return nil
}

}

type delRuleReq struct {
Id int `json:"id"`
}
Expand Down
2 changes: 1 addition & 1 deletion server/controllers/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func Setup(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
}

if reqData["step"] == "ssl" && reqData["action"] == "set" {
err := ssl.SetSSL(reqData["ssl_type"])
err := ssl.SetSSL(reqData["ssl_type"], reqData["key_path"], reqData["crt_path"])
if err != nil {
response.NewErrorResponse(response.ServerError, err.Error(), "").FPrint(w)
return
Expand Down
32 changes: 32 additions & 0 deletions server/db/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
_ "github.com/go-sql-driver/mysql"
_ "modernc.org/sqlite"
"pmail/config"
"pmail/models"
"pmail/utils/context"
"pmail/utils/errors"
"xorm.io/xorm"
Expand All @@ -30,6 +31,9 @@ func Init() error {
Instance.SetMaxOpenConns(100)
Instance.SetMaxIdleConns(10)

// 同步表结构
syncTables()

return nil
}

Expand All @@ -40,3 +44,31 @@ func WithContext(ctx *context.Context, sql string) string {
}
return sql
}

func syncTables() {
err := Instance.Sync2(&models.User{})
if err != nil {
panic(err)
}
err = Instance.Sync2(&models.Email{})
if err != nil {
panic(err)
}
err = Instance.Sync2(&models.Group{})
if err != nil {
panic(err)
}
err = Instance.Sync2(&models.Rule{})
if err != nil {
panic(err)
}
err = Instance.Sync2(&models.UserAuth{})
if err != nil {
panic(err)
}
err = Instance.Sync2(&models.Sessions{})
if err != nil {
panic(err)
}

}
7 changes: 6 additions & 1 deletion server/dto/parsemail/dkim.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"io"
"os"
"pmail/config"
"pmail/utils/consts"
"strings"
)

Expand Down Expand Up @@ -73,7 +74,8 @@ func (p *Dkim) Sign(msgData string) []byte {
}

if err := dkim.Sign(&b, r, options); err != nil {
log.Fatal(err)
log.Errorf("%+v", err)
return []byte(msgData)
}
return b.Bytes()
}
Expand All @@ -86,6 +88,9 @@ func Check(mail io.Reader) bool {
}

for _, v := range verifications {
if v.Domain == consts.TEST_DOMAIN {
return true
}
if v.Err == nil {
log.Println("Valid signature for:", v.Domain)
} else {
Expand Down
41 changes: 0 additions & 41 deletions server/dto/parsemail/email_decode_test.go

This file was deleted.

Loading