diff --git a/ChangeLog b/ChangeLog index ac2a7d7..e3bf701 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ - Add testing extras option to setup.py (Daniel Hahler) - Fix deprecation warnings in test asserts (Daniel Hahler) - Correctly limit try/except for imports to import errors (Daniel Hahler) + - Don't error out in Python 3 if include headers is string (LP: #1776775) 2018-05-18 Version 0.8.0 - Change from distutils to setuptools with entry points because it's the diff --git a/dkim/__init__.py b/dkim/__init__.py index eeb9fd1..8293c6c 100644 --- a/dkim/__init__.py +++ b/dkim/__init__.py @@ -724,6 +724,12 @@ class DKIM(DomainSigner): if include_headers is None: include_headers = self.default_sign_headers() + try: + include_headers = [bytes(x, 'utf-8') for x in include_headers] + except TypeError: + # TypeError means it's already bytes and we're good or we're in + # Python 2 and we don't care. See LP: #1776775. + pass include_headers = tuple([x.lower() for x in include_headers]) # record what verify should extract diff --git a/dkim/tests/test_dkim.py b/dkim/tests/test_dkim.py index 93e2b87..8f4e347 100644 --- a/dkim/tests/test_dkim.py +++ b/dkim/tests/test_dkim.py @@ -244,6 +244,17 @@ p=11qYAYKxCrfVS/7TyWQHOg7hcvPapiMlrwIaaPcHURo=""" res = dkim.verify(sig + self.message, dnsfunc=self.dnsfunc) self.assertTrue(res) + def test_string_include(self): + # A message can be signed when the include_headers is string + for header_algo in (b"simple", b"relaxed"): + for body_algo in (b"simple", b"relaxed"): + sig = dkim.sign( + self.message, b"test", b"example.com", self.key, + canonicalize=(header_algo, body_algo), + include_headers=('from',) ) + res = dkim.verify(sig + self.message, dnsfunc=self.dnsfunc) + self.assertTrue(res) + def test_add_body_length(self): sig = dkim.sign( self.message, b"test", b"example.com", self.key, length=True)