Skip to content

Commit

Permalink
V2.4.0 (#89)
Browse files Browse the repository at this point in the history
* 插件架构改造

* v2.4.0
  • Loading branch information
Jinnrry authored Mar 1, 2024
1 parent d358812 commit 20f3590
Show file tree
Hide file tree
Showing 26 changed files with 628 additions and 127 deletions.
30 changes: 24 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,46 @@ jobs:
- name: Setup Go environment
uses: actions/[email protected]
with:
go-version: '1.21'
check-latest: true
- name: Gen output name
run: echo "FILENAME=pmail_${{ matrix.goos }}_${{ matrix.goarch }}" >> ${GITHUB_ENV}
run: |
echo "FILENAME=pmail_${{ matrix.goos }}_${{ matrix.goarch }}" >> ${GITHUB_ENV}
echo "TGFILENAME=telegram_push_${{ matrix.goos }}_${{ matrix.goarch }}" >> ${GITHUB_ENV}
echo "WCFILENAME=wechat_push_${{ matrix.goos }}_${{ matrix.goarch }}" >> ${GITHUB_ENV}
echo "WEBFILENAME=web_push_${{ matrix.goos }}_${{ matrix.goarch }}" >> ${GITHUB_ENV}
- name: Rename Windows File
if: matrix.goos == 'windows'
run: echo "FILENAME=pmail_${{ matrix.goos }}_${{ matrix.goarch }}.exe" >> ${GITHUB_ENV}
run: |
echo "FILENAME=pmail_${{ matrix.goos }}_${{ matrix.goarch }}.exe" >> ${GITHUB_ENV}
echo "TGFILENAME=telegram_push_${{ matrix.goos }}_${{ matrix.goarch }}.exe" >> ${GITHUB_ENV}
echo "WCFILENAME=wechat_push_${{ matrix.goos }}_${{ matrix.goarch }}.exe" >> ${GITHUB_ENV}
echo "WEBFILENAME=web_push_${{ matrix.goos }}_${{ matrix.goarch }}.exe" >> ${GITHUB_ENV}
- name: FE Build
run: cd fe && yarn && yarn build
- name: BE Build
run: |
cd server && cp -rf ../fe/dist http_server
go build -ldflags "-s -w -X 'main.goVersion=$(go version)' -X 'main.gitHash=$(git show -s --format=%H)' -X 'main.buildTime=$(TZ=UTC-8 date +%Y-%m-%d" "%H:%M:%S)'" -o ${{ env.FILENAME }} main.go
go build -ldflags "-s -w -X 'main.version=${{ VERSION }}' -X 'main.goVersion=$(go version)' -X 'main.gitHash=$(git show -s --format=%H)' -X 'main.buildTime=$(TZ=UTC-8 date +%Y-%m-%d" "%H:%M:%S)'" -o ${{ env.FILENAME }} main.go
go build -ldflags "-s -w" -o ${{ env.TGFILENAME }} hooks/telegram_push/telegram_push.go
go build -ldflags "-s -w" -o ${{ env.WEBFILENAME }} hooks/web_push/web_push.go
go build -ldflags "-s -w" -o ${{ env.WCFILENAME }} hooks/wechat_push/wechat_push.go
- name: Upload files to Artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ env.FILENAME }}
path: ./server/${{ env.FILENAME }}
path: |
./server/${{ env.FILENAME }}
./server/${{ env.TGFILENAME }}
./server/${{ env.WEBFILENAME }}
./server/${{ env.WCFILENAME }}
- name: Upload binaries to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ./server/${{ env.FILENAME }}
file: |
./server/${{ env.FILENAME }}
./server/${{ env.TGFILENAME }}
./server/${{ env.WEBFILENAME }}
./server/${{ env.WCFILENAME }}
tag: ${{ github.ref }}
file_glob: true
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
.DS_Store
dist
output
pmail.db
pmail.db
server/plugins
config
7 changes: 6 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ COPY --from=febuild /work/dist /work/http_server/dist

RUN apk update && apk add git
RUN go build -ldflags "-X 'main.goVersion=$(go version)' -X 'main.gitHash=$(git show -s --format=%H)' -X 'main.buildTime=$(TZ=UTC-8 date +%Y-%m-%d" "%H:%M:%S)'" -o pmail main.go
RUN cd /work/hooks/telegram_push && go build -ldflags "-s -W" -o output/telegram_push main.go
RUN cd /work/hooks/web_push && go build -ldflags "-s -W" -o output/web_push main.go
RUN cd /work/hooks/wechat_push && go build -ldflags "-s -W" -o output/wechat_push main.go


FROM alpine
Expand All @@ -30,6 +33,8 @@ RUN apk add --no-cache tzdata \


COPY --from=serverbuild /work/pmail .

COPY --from=serverbuild /work/hooks/telegram_push/output/* ./plugin/
COPY --from=serverbuild /work/hooks/web_push/output/* ./plugin/
COPY --from=serverbuild /work/hooks/wechat_push/output/* ./plugin/

CMD /work/pmail
9 changes: 7 additions & 2 deletions DockerfileGithubAction
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ WORKDIR /work
COPY server .

RUN apk update && apk add git
RUN go build -ldflags "-X 'main.goVersion=$(go version)' -X 'main.gitHash=$(git show -s --format=%H)' -X 'main.buildTime=$(TZ=UTC-8 date +%Y-%m-%d" "%H:%M:%S)'" -o pmail main.go
RUN go build -ldflags "-s -w -X 'main.goVersion=$(go version)' -X 'main.gitHash=$(git show -s --format=%H)' -X 'main.buildTime=$(TZ=UTC-8 date +%Y-%m-%d" "%H:%M:%S)'" -o pmail main.go
RUN cd /work/hooks/telegram_push && go build -ldflags "-s -W" -o output/telegram_push main.go
RUN cd /work/hooks/web_push && go build -ldflags "-s -W" -o output/web_push main.go
RUN cd /work/hooks/wechat_push && go build -ldflags "-s -W" -o output/wechat_push main.go


FROM alpine
Expand All @@ -21,6 +24,8 @@ RUN apk add --no-cache tzdata \


COPY --from=serverbuild /work/pmail .

COPY --from=serverbuild /work/hooks/telegram_push/output/* ./plugin/
COPY --from=serverbuild /work/hooks/web_push/output/* ./plugin/
COPY --from=serverbuild /work/hooks/wechat_push/output/* ./plugin/

CMD /work/pmail
30 changes: 28 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
build: build_fe build_server package
build: build_fe build_server telegram_push web_push wechat_push package

clean:
rm -rf output


build_fe:
cd fe && yarn && yarn build
cd server && cp -rf ../fe/dist http_server
Expand All @@ -13,11 +14,36 @@ build_server:
cd server && CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w -X 'main.goVersion=$(go version)' -X 'main.gitHash=$(git show -s --format=%H)' -X 'main.buildTime=$(TZ=UTC-8 date +%Y-%m-%d" "%H:%M:%S)'" -o pmail_mac_amd64 main.go
cd server && CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w -X 'main.goVersion=$(go version)' -X 'main.gitHash=$(git show -s --format=%H)' -X 'main.buildTime=$(TZ=UTC-8 date +%Y-%m-%d" "%H:%M:%S)'" -o pmail_mac_arm64 main.go

telegram_push:
cd server/hooks/telegram_push && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o output/telegram_push_linux_amd64 telegram_push.go
cd server/hooks/telegram_push && CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-s -w" -o output/telegram_push_windows_amd64.exe telegram_push.go
cd server/hooks/telegram_push && CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w" -o output/telegram_push_mac_amd64 telegram_push.go
cd server/hooks/telegram_push && CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w" -o output/telegram_push_mac_arm64 telegram_push.go

web_push:
cd server/hooks/web_push && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o output/web_push_linux_amd64 web_push.go
cd server/hooks/web_push && CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-s -w" -o output/web_push_windows_amd64.exe web_push.go
cd server/hooks/web_push && CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w" -o output/web_push_mac_amd64 web_push.go
cd server/hooks/web_push && CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w" -o output/web_push_mac_arm64 web_push.go

wechat_push:
cd server/hooks/wechat_push && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o output/wechat_push_linux_amd64 wechat_push.go
cd server/hooks/wechat_push && CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-s -w" -o output/wechat_push_windows_amd64.exe wechat_push.go
cd server/hooks/wechat_push && CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w" -o output/wechat_push_mac_amd64 wechat_push.go
cd server/hooks/wechat_push && CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w" -o output/wechat_push_mac_arm64 wechat_push.go

plugin: telegram_push wechat_push web_push


package: clean
mkdir output
mv server/pmail* output/
mkdir config
mkdir output/config
mkdir output/plugins
cp -r server/config/dkim output/config/
cp -r server/config/ssl output/config/
cp -r server/config/config.json output/config/
mv server/hooks/telegram_push/output/* output/plugins
mv server/hooks/web_push/output/* output/plugins
mv server/hooks/wechat_push/output/* output/plugins
cp README.md output/
32 changes: 11 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,6 @@ configure.
Check if your mailbox has completed all the security configuration. It is recommended to
use [https://www.mail-tester.com/](https://www.mail-tester.com/) for checking.

## 5、 WeChat Message Push

Open the `config/config.json` file in the run directory, edit a few configuration items at the beginning of `weChatPush`
and restart the service.

## 6、Telegram Message Push

Create bot and get token from [BotFather](https://t.me/BotFather)
Open the `config/config.json` file in the run directory, edit a few configuration items at the beginning of `tg`and restart the service.

## 7、WebHook Push

Open the `config/config.json` file in the running directory, edit the webPushUrl and webPushToken (optional). After receiving an email, the email information will be posted to the hook address, and the token will also be placed in the body for easy verification. After configuring, restart the service.

# Configuration file format description

Expand All @@ -102,14 +89,6 @@ Open the `config/config.json` file in the running directory, edit the webPushUrl
"httpPort": 80, // http port . default 80
"httpsPort": 443, // https port . default 443
"spamFilterLevel": 0,// Spam filter level, 0: no filter, 1: filtering when `spf` and `dkim` don't pass, 2: filtering when `spf` don't pass
"weChatPushAppId": "", // wechat appid
"weChatPushSecret": "", // weChat Secret
"weChatPushTemplateId": "", // weChat TemplateId
"weChatPushUserId": "", // weChat UserId
"tgChatId": "", // telegram chatid
"tgBotToken": "", // telegram token
"webPushUrl": "", // webhook push URL
"webPushToken": "", // webhook push token
"isInit": true // If false, it will enter the bootstrap process.
}
```
Expand All @@ -124,6 +103,16 @@ SMTP Server Address : smtp.[Your Domain]

SMTP Port: 25/465(SSL)

# Plugin

[WeChat Push](server/hooks/wechat_push/README.md)

[Telegram Push](server/hooks/wechat_push/README.md)

[Web Push](server/hooks/wechat_push/README.md)



# For Developer

## Project Framework
Expand All @@ -143,3 +132,4 @@ The code is in `server` folder.
## Plugin Development

Reference this file. `server/hooks/wechat_push/wechat_push.go`

29 changes: 9 additions & 20 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,6 @@ PMail是一个追求极简部署流程、极致资源占用的个人域名邮箱

建议找一下邮箱测试服务(比如[https://www.mail-tester.com/](https://www.mail-tester.com/))进行邮件得分检测,避免自己某些步骤漏配,导致发件进对方垃圾箱。

## 5、微信推送

打开运行目录下的 `config/config.json`文件,编辑 `weChatPush` 开头的几个配置项,重启服务即可。

## 6、Telegram推送

[BotFather](https://t.me/BotFather) 创建并获取令牌机器人。 打开运行目录下的 config/config.json 文件,编辑 `tg` 开头的几个配置项,重启服务即可。

## 7、WebHook推送

打开运行目录下的 `config/config.json`文件,编辑 webPushUrl 跟webPushToken (可选),接收到邮件后会往hook地址post发送邮件信息,token也会放在body中,方便需要的进行校验,配置完重启服务即可。

# 配置文件说明

```json
Expand All @@ -106,14 +94,6 @@ PMail是一个追求极简部署流程、极致资源占用的个人域名邮箱
"spamFilterLevel": 0,// 垃圾邮件过滤级别,0不过滤、1 spf dkim 校验均失败时过滤,2 spf校验不通过时过滤
"httpPort": 80, // http 端口 . 默认 80
"httpsPort": 443, // https 端口 . 默认 443
"weChatPushAppId": "", // 微信推送appid
"weChatPushSecret": "", // 微信推送秘钥
"weChatPushTemplateId": "", // 微信推送模板id
"weChatPushUserId": "", // 微信推送用户id
"tgChatId": "", // telegram 推送chatid
"tgBotToken": "", // telegram 推送 token
"webPushUrl": "", // webhook 推送地址
"webPushToken": "", // webhook 推送 token
"isInit": true // 为false的时候会进入安装引导流程
}
```
Expand All @@ -128,6 +108,15 @@ SMTP地址: smtp.[你的域名]

SMTP端口: 25/465(SSL)


# 插件

[微信推送](server/hooks/wechat_push/README.md)

[Telegram推送](server/hooks/wechat_push/README.md)

[WebHook推送](server/hooks/wechat_push/README.md)

# 参与开发

## 项目架构
Expand Down
2 changes: 1 addition & 1 deletion server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type Config struct {
//go:embed tables/*
var tableConfig embed.FS

const Version = "2.3.8"
const Version = "2.4.0"

const DBTypeMySQL = "mysql"
const DBTypeSQLite = "sqlite"
Expand Down
8 changes: 0 additions & 8 deletions server/config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@
"spamFilterLevel": 2,
"httpPort": 80,
"httpsPort": 443,
"weChatPushAppId": "",
"weChatPushSecret": "",
"weChatPushTemplateId": "",
"weChatPushUserId": "",
"tgChatId": "",
"tgBotToken": "",
"webPushUrl": "",
"webPushToken": "",
"isInit": true,
"httpsEnabled": 1
}
5 changes: 3 additions & 2 deletions server/controllers/email/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"pmail/dto/parsemail"
"pmail/dto/response"
"pmail/hooks"
"pmail/hooks/framework"
"pmail/i18n"
"pmail/utils/async"
"pmail/utils/context"
Expand Down Expand Up @@ -134,7 +135,7 @@ func Send(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
continue
}
as.WaitProcess(func(hk any) {
hk.(hooks.EmailHook).SendBefore(ctx, e)
hk.(framework.EmailHook).SendBefore(ctx, e)
}, hook)
}
as.Wait()
Expand Down Expand Up @@ -180,7 +181,7 @@ func Send(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
continue
}
as2.WaitProcess(func(hk any) {
hk.(hooks.EmailHook).SendAfter(ctx, e, sendErr)
hk.(framework.EmailHook).SendAfter(ctx, e, sendErr)
}, hook)
}
as2.Wait()
Expand Down
Loading

0 comments on commit 20f3590

Please sign in to comment.