- Fixed problem with header folding that caused the first line to be
folded too long (Updated test test_add_body_length since l= tag is no
longer at the beginning of a line
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
UNRELEASED Version 0.6.2
|
||||
- Fixed problem with header folding that caused the first line to be
|
||||
folded too long (Updated test test_add_body_length since l= tag is no
|
||||
longer at the beginning of a line)
|
||||
- Fixed python3.4 string interpolation issue
|
||||
- Fix some byte casting issues & typos
|
||||
- Add test case for verification when should headers are signed
|
||||
|
||||
+10
-6
@@ -299,7 +299,7 @@ def text(s):
|
||||
if type(s) is str: return s
|
||||
return s.encode('ascii')
|
||||
|
||||
def fold(header):
|
||||
def fold(header, namelen=0):
|
||||
"""Fold a header line into multiple crlf-separated lines at column 72.
|
||||
|
||||
>>> text(fold(b'foo'))
|
||||
@@ -318,14 +318,18 @@ def fold(header):
|
||||
i += 3
|
||||
pre = header[:i]
|
||||
header = header[i:]
|
||||
while len(header) > 72:
|
||||
i = header[:72].rfind(b" ")
|
||||
# 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:
|
||||
j = 72
|
||||
j = maxleng
|
||||
else:
|
||||
j = i + 1
|
||||
pre += header[:j] + b"\r\n "
|
||||
header = header[j:]
|
||||
namelen = 0
|
||||
return pre + header
|
||||
|
||||
def load_pk_from_dns(name, dnsfunc=get_txt):
|
||||
@@ -485,7 +489,7 @@ class DomainSigner(object):
|
||||
|
||||
header_value = b"; ".join(b"=".join(x) for x in fields)
|
||||
if not standardize:
|
||||
header_value = fold(header_value)
|
||||
header_value = fold(header_value, namelen=len(header_name))
|
||||
header_value = RE_BTAG.sub(b'\\1',header_value)
|
||||
header = (header_name, b' ' + header_value)
|
||||
h = HashThrough(self.hasher())
|
||||
@@ -510,7 +514,7 @@ class DomainSigner(object):
|
||||
header_value = b"; ".join(b"=".join(x) for x in fields) + b"\r\n"
|
||||
|
||||
if not standardize:
|
||||
header_value = fold(header_value)
|
||||
header_value = fold(header_value, namelen=len(header_name))
|
||||
|
||||
return header_value
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ Y+vtSBczUiKERHv1yRbcaQtZFh5wtiRrN04BLUTD21MycBX5jYchHjPY/wIDAQAB"""
|
||||
sig = dkim.sign(
|
||||
self.message, b"test", b"example.com", self.key, length=True)
|
||||
msg = email.message_from_string(self.message.decode('utf-8'))
|
||||
self.assertIn('\n l=%s' % len(msg.get_payload() + '\n'), sig.decode('utf-8'))
|
||||
self.assertIn('; l=%s' % len(msg.get_payload() + '\n'), sig.decode('utf-8'))
|
||||
res = dkim.verify(sig + self.message, dnsfunc=self.dnsfunc)
|
||||
self.assertTrue(res)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user