diff --git a/app/config.py b/app/config.py index 16bdc1eb..47a9c5e9 100644 --- a/app/config.py +++ b/app/config.py @@ -415,3 +415,6 @@ TEMP_DIR = os.environ.get("TEMP_DIR") # enable the alias automation disable: an alias can be automatically disabled if it has too many bounces ALIAS_AUTOMATIC_DISABLE = "ALIAS_AUTOMATIC_DISABLE" in os.environ + +# whether the DKIM signing is handled by Rspamd +RSPAMD_SIGN_DKIM = "RSPAMD_SIGN_DKIM" in os.environ diff --git a/app/email/headers.py b/app/email/headers.py index aea6a713..0196a54e 100644 --- a/app/email/headers.py +++ b/app/email/headers.py @@ -31,6 +31,9 @@ SL_EMAIL_LOG_ID = "X-SimpleLogin-EmailLog-ID" SL_ENVELOPE_FROM = "X-SimpleLogin-Envelope-From" SL_ENVELOPE_TO = "X-SimpleLogin-Envelope-To" +# to let Rspamd know that the message should be signed +SL_WANT_SIGNING = "X-SimpleLogin-Want-Signing" + MIME_HEADERS = [ MIME_VERSION, CONTENT_TYPE, diff --git a/app/email_utils.py b/app/email_utils.py index 20fa5851..5d81baca 100644 --- a/app/email_utils.py +++ b/app/email_utils.py @@ -52,6 +52,7 @@ from app.config import ( POSTFIX_PORT_FORWARD, TEMP_DIR, ALIAS_AUTOMATIC_DISABLE, + RSPAMD_SIGN_DKIM, ) from app.db import Session from app.dns_utils import get_mx_domains @@ -408,6 +409,11 @@ def get_email_domain_part(address): def add_dkim_signature(msg: Message, email_domain: str): + if RSPAMD_SIGN_DKIM: + LOG.d("DKIM signature will be added by rspamd") + msg[headers.SL_WANT_SIGNING] = "yes" + return + for dkim_headers in headers.DKIM_HEADERS: try: add_dkim_signature_with_header(msg, email_domain, dkim_headers)