Просмотр исходного кода

Merge pull request 'v2.4.2' (#4) from v2.4.2 into master

Reviewed-on: http://192.168.123.5/jinnrry/PMail_Github/pulls/4
jinnrry 2 лет назад
Родитель
Сommit
e95930cc1a

+ 7 - 1
.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: |

+ 6 - 2
.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: |

+ 2 - 1
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

+ 8 - 7
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()

+ 24 - 3
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)