diff --git a/ChangeLog b/ChangeLog index 3965d4a..13feca3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,15 @@ +2018-06-16 Version 0.8.1 + - Correctly fold lines at or near the maximum line length (fix folding + zero length lines and adding a blank line and adding an exra cr/lf for + lines near max length (LP: #1717576) + - Thanks to Christian Jørgensen and John Levine for reporting the issue + 2018-05-18 Version 0.8.0 - Change from distutils to setuptools with entry points because it's the future - Use install_requires and extras_requires to document external dependencies for dkimpy (LP: #1227526) - - Fix typo in dknewky(1) for k= tag (Thanks to Andreas Schulze for + - Fix typo in dknewkey(1) for k= tag (Thanks to Andreas Schulze for reporting) - Detect incorrect version in DKIM public key record (LP: #1763815) - Detect unknown algorithm in k= tag and raise an appropriate error, vice diff --git a/dkim/__init__.py b/dkim/__init__.py index a526a6c..c1dee3e 100644 --- a/dkim/__init__.py +++ b/dkim/__init__.py @@ -352,7 +352,18 @@ def fold(header, namelen=0): ' foo' >>> len(fold(b'foo'*25).splitlines()[0]) 72 + >>> text(fold(b'x')) + 'x' + >>> text(fold(b'xyz'*24)) + 'xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz' """ + # 72 is the max line length we actually want, but the header field name + # has to fit in the first line too (See Debian Bug #863690). + maxleng = 72 - namelen + if len(header) <= maxleng: + return header + if len(header) - header.rfind(b"\r\n") == 2 and len(header) <= maxleng +2: + return header i = header.rfind(b"\r\n ") if i == -1: pre = b"" @@ -360,9 +371,6 @@ def fold(header, namelen=0): i += 3 pre = header[:i] header = header[i:] - # 72 is the max line length we actually want, but the header field name - # has to fit in the first line too (See Debian Bug #863690). - maxleng = 72 - namelen while len(header) > maxleng: i = header[:maxleng].rfind(b" ") if i == -1: @@ -372,7 +380,13 @@ def fold(header, namelen=0): pre += header[:j] + b"\r\n " header = header[j:] namelen = 0 - return pre + header + if len(header) > 2: + return pre + header + else: + if pre[0] == b' ': + return pre[:-1] + else: + return pre + header def load_pk_from_dns(name, dnsfunc=get_txt): s = dnsfunc(name) diff --git a/setup.py b/setup.py index d900ad0..07a1b67 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ from setuptools import setup import os -version = "0.8.0" +version = "0.8.1" kw = {} # Work-around for lack of 'or' requires in setuptools. try: