[New-bugs-announce] [issue34881] unnecessary encoded-words usage breaks DKIM signatures

Bryce Drennan report at bugs.python.org
Wed Oct 3 03:06:28 EDT 2018


New submission from Bryce Drennan <python at accounts.brycedrennan.com>:

Since Python 3.6.4 folding of unstructured headers uses the encoded words syntax even if there are no special characters.  

This makes DKIM-Signature headers that are unreadable to google's gmail servers. It may be that encoded-words are not valid in this header.  I don't see them mentioned here: https://tools.ietf.org/html/rfc6376#page-8

Here is the smallest test case I could create to demonstrate the issue.

One solution would be to add DKIM-Signature to the HeaderRegistry but I'm not yet expert enough to execute this. I went down that path for a few hours. Didn't see a straight-forward way to disable encoded words.

Setting EmailPolicy(max_line_length=None) does output without encoded words but I worry that will cause different incompatibility issues.


from email.headerregistry import HeaderRegistry
from email.policy import SMTP

def test_unstructured_encoded_word_folding():
    header = HeaderRegistry()('DKIM-Signature', 'a' * 85)
    folded = header.fold(policy=SMTP.clone(refold_source=None))
    print(f'\nDKIM-Signature: {header}')
    print(folded)
    assert '=?utf-8?q?' not in folded


Output:

DKIM-Signature: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
DKIM-Signature: =?utf-8?q?aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa?=
 =?utf-8?q?aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa?=

AssertionError()!

----------
components: email
messages: 326943
nosy: barry, bryced, r.david.murray
priority: normal
severity: normal
status: open
title: unnecessary encoded-words usage breaks DKIM signatures
versions: Python 3.6, Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34881>
_______________________________________


More information about the New-bugs-announce mailing list