diff --git a/.github/workflows/docker_build.yml b/.github/workflows/docker_build.yml index 15b29d8d..5dce102c 100644 --- a/.github/workflows/docker_build.yml +++ b/.github/workflows/docker_build.yml @@ -39,7 +39,10 @@ jobs: - uses: actions/setup-node@v4 - name: Build FE - run: make build_fe + run: | + echo "$(git show -s --format=%H)" + echo "GITHASH=$(git show -s --format=%H)" >> ${GITHUB_ENV} + make build_fe - name: Log in to the Container registry uses: docker/login-action@v2.1.0 @@ -51,6 +54,9 @@ jobs: - name: Build and push Docker images uses: docker/build-push-action@v4 with: + build-args: | + VERSION=${{ env.VERSION }} + GITHASH=${{ env.GITHASH }} context: . file: ./DockerfileGithubAction platforms: | diff --git a/.github/workflows/docker_build_pre.yml b/.github/workflows/docker_build_pre.yml index 21799d59..a4ac05c5 100644 --- a/.github/workflows/docker_build_pre.yml +++ b/.github/workflows/docker_build_pre.yml @@ -39,7 +39,9 @@ jobs: - uses: actions/setup-node@v4 - name: Build FE - run: make build_fe + run: | + echo "GITHASH=$(git show -s --format=%H)" >> ${GITHUB_ENV} + make build_fe - name: Log in to the Container registry uses: docker/login-action@v2.1.0 @@ -51,7 +53,9 @@ jobs: - name: Build and push Docker images uses: docker/build-push-action@v4 with: - build-args: VERSION=${{ env.VERSION }} + build-args: | + VERSION=${{ env.VERSION }} + GITHASH=${{ env.GITHASH }} context: . file: ./DockerfileGithubAction platforms: | diff --git a/DockerfileGithubAction b/DockerfileGithubAction index 3150d014..ef08d699 100644 --- a/DockerfileGithubAction +++ b/DockerfileGithubAction @@ -1,11 +1,12 @@ FROM golang:alpine as serverbuild ARG VERSION +ARG GITHASH WORKDIR /work COPY server . RUN apk update && apk add git -RUN 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 pmail main.go +RUN go build -ldflags "-s -w -X 'main.version=${VERSION}' -X 'main.goVersion=$(go version)' -X 'main.gitHash=${GITHASH}' -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 telegram_push.go RUN cd /work/hooks/web_push && go build -ldflags "-s -w" -o output/web_push web_push.go RUN cd /work/hooks/wechat_push && go build -ldflags "-s -w" -o output/wechat_push wechat_push.go diff --git a/server/main.go b/server/main.go index a6ce37f4..ba74697b 100644 --- a/server/main.go +++ b/server/main.go @@ -50,8 +50,8 @@ func main() { // 日志消息输出可以是任意的io.writer类型 log.SetOutput(os.Stdout) - var cst, _ = time.LoadLocation("Asia/Shanghai") - time.Local = cst + var cstZone = time.FixedZone("CST", 8*3600) + time.Local = cstZone config.Init() @@ -75,15 +75,16 @@ func main() { } if version == "" { - version = time.Now().Format("2006-01-02 15:04:05") + version = "TestVersion" } - log.Infoln("***************************************************") - log.Infof("***\tServer Start Success Version:%s\n", version) + log.Infoln("*******************************************************************") + log.Infof("***\tServer Start Success \n") + log.Infof("***\tServer Version: %s \n", version) log.Infof("***\tGit Commit Hash: %s ", gitHash) - log.Infof("***\tBuild TimeStamp: %s ", buildTime) + log.Infof("***\tBuild Date: %s ", buildTime) log.Infof("***\tBuild GoLang Version: %s ", goVersion) - log.Infoln("***************************************************") + log.Infoln("*******************************************************************") // 定时任务启动 go cron_server.Start() diff --git a/server/smtp_server/read_content.go b/server/smtp_server/read_content.go index d87524c4..f86393de 100644 --- a/server/smtp_server/read_content.go +++ b/server/smtp_server/read_content.go @@ -64,6 +64,24 @@ func (s *Session) Data(r io.Reader) error { // 判断是收信还是转发,只要是登陆了,都当成转发处理 //account, domain := email.From.GetDomainAccount() if s.Ctx.UserID > 0 { + + log.WithContext(ctx).Debugf("开始执行插件SendBefore!") + as2 := async.New(ctx) + for _, hook := range hooks.HookList { + if hook == nil { + continue + } + as2.WaitProcess(func(hk any) { + hk.(framework.EmailHook).SendBefore(ctx, email) + }, hook) + } + as2.Wait() + log.WithContext(ctx).Debugf("开始执行插件SendBefore!End") + + if email == nil { + return nil + } + // 转发 err := saveEmail(ctx, email, 1, true, true) if err != nil { @@ -86,10 +104,7 @@ func (s *Session) Data(r io.Reader) error { SPFStatus = spfCheck(s.RemoteAddress.String(), email.Sender, email.Sender.EmailAddress) - saveEmail(ctx, email, 0, SPFStatus, dkimStatus) - log.WithContext(ctx).Debugf("开始执行插件ReceiveParseAfter!") - as2 := async.New(ctx) for _, hook := range hooks.HookList { if hook == nil { @@ -102,6 +117,12 @@ func (s *Session) Data(r io.Reader) error { as2.Wait() log.WithContext(ctx).Debugf("开始执行插件ReceiveParseAfter!End") + if email == nil { + return nil + } + + saveEmail(ctx, email, 0, SPFStatus, dkimStatus) + log.WithContext(ctx).Debugf("开始执行邮件规则!") // 执行邮件规则 rs := rule.GetAllRules(ctx)