Hi !
I am implementing DKIM validation for my emails.
I noticed than some emails do not pass DKIM validation due to different body hashes.
Such emails can be generated by Sentry, by my own apps, etc..
Now about Django:
When using EmailMessage, the charset is utf-8, and the Content-Transfer-Encoding is either 7bit or 8bit (automatically changes between them when the body contains non-ASCII characters).
Quick validation with:
>>> from django.core.mail import EmailMessage
>>> print EmailMessage('subject', 'body', 'fro...@example.net', ['to....@example.net']).message().as_string()
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Subject: subject
From: fro...@example.net
To: to....@example.net
Date: Wed, 30 Apr 2014 11:01:44 -0000
Message-ID: <20140430110144.1564.85693@localhost>
body
So at the moment, because Django says not to use base64 for utf-8 emails in its code, Django does no longer make sure that the lines are not too long, despite the RFC.
I see 3 ways to make sure that the lines are not too long :
- automatically split lines in a way that can be recognized by email readers (no idea how to do that properly..) (in Django/in the apps)
- go back to base64 (but it seems to increase spam scores)
- switch to quoted-printable (functioning code below, no idea of the potentially negative impact)
from django.core.mail.message import utf8_charset
from email import Charset
utf8_charset.body_encoding = Charset.QP
What do you think ?
Is Django code / app code the correct place to fix this ?
Should Django respect the RFC ?
Any other ideas ?
Thanks !