- 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)
This commit is contained in:
Scott Kitterman
2018-06-16 16:59:39 -04:00
parent ef80f037ca
commit 0566b9b4c1
3 changed files with 26 additions and 6 deletions
+7 -1
View File
@@ -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 2018-05-18 Version 0.8.0
- Change from distutils to setuptools with entry points because it's the - Change from distutils to setuptools with entry points because it's the
future future
- Use install_requires and extras_requires to document external - Use install_requires and extras_requires to document external
dependencies for dkimpy (LP: #1227526) 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) reporting)
- Detect incorrect version in DKIM public key record (LP: #1763815) - Detect incorrect version in DKIM public key record (LP: #1763815)
- Detect unknown algorithm in k= tag and raise an appropriate error, vice - Detect unknown algorithm in k= tag and raise an appropriate error, vice
+17 -3
View File
@@ -352,7 +352,18 @@ def fold(header, namelen=0):
' foo' ' foo'
>>> len(fold(b'foo'*25).splitlines()[0]) >>> len(fold(b'foo'*25).splitlines()[0])
72 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 ") i = header.rfind(b"\r\n ")
if i == -1: if i == -1:
pre = b"" pre = b""
@@ -360,9 +371,6 @@ def fold(header, namelen=0):
i += 3 i += 3
pre = header[:i] pre = header[:i]
header = 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: while len(header) > maxleng:
i = header[:maxleng].rfind(b" ") i = header[:maxleng].rfind(b" ")
if i == -1: if i == -1:
@@ -372,6 +380,12 @@ def fold(header, namelen=0):
pre += header[:j] + b"\r\n " pre += header[:j] + b"\r\n "
header = header[j:] header = header[j:]
namelen = 0 namelen = 0
if len(header) > 2:
return pre + header
else:
if pre[0] == b' ':
return pre[:-1]
else:
return pre + header return pre + header
def load_pk_from_dns(name, dnsfunc=get_txt): def load_pk_from_dns(name, dnsfunc=get_txt):
+1 -1
View File
@@ -24,7 +24,7 @@
from setuptools import setup from setuptools import setup
import os import os
version = "0.8.0" version = "0.8.1"
kw = {} # Work-around for lack of 'or' requires in setuptools. kw = {} # Work-around for lack of 'or' requires in setuptools.
try: try: