소스 검색

fix DKIM fail on reply phase: the DKIM-signature should be added at the end of processing

Son NK 5 년 전
부모
커밋
569fda47a9
1개의 변경된 파일9개의 추가작업 그리고 4개의 파일을 삭제
  1. 9 4
      email_handler.py

+ 9 - 4
email_handler.py

@@ -234,10 +234,10 @@ class MailHandler:
 
             return "250 ignored"
 
-        # todo: add DKIM-Signature for custom domain
-        # add DKIM-Signature for non-custom-domain alias
-        if alias.endswith(EMAIL_DOMAIN):
-            add_dkim_signature(msg, EMAIL_DOMAIN)
+        # remove DKIM-Signature
+        if msg["DKIM-Signature"]:
+            LOG.d("Remove DKIM-Signature %s", msg["DKIM-Signature"])
+            del msg["DKIM-Signature"]
 
         # email seems to come from alias
         msg.replace_header("From", alias)
@@ -258,6 +258,11 @@ class MailHandler:
             envelope.rcpt_options,
         )
 
+        # todo: add DKIM-Signature for custom domain
+        # add DKIM-Signature for non-custom-domain alias
+        if alias.endswith(EMAIL_DOMAIN):
+            add_dkim_signature(msg, EMAIL_DOMAIN)
+
         msg_raw = msg.as_string().encode()
         smtp.sendmail(
             alias,