Canonicalisation of 'From ' quoting variations
This fixes #115
(Unit tests will be added shortly)
diff --git a/tools/plugins/dkim_id.py b/tools/plugins/dkim_id.py
index 27c6e79..8925c3e 100644
--- a/tools/plugins/dkim_id.py
+++ b/tools/plugins/dkim_id.py
@@ -21,6 +21,7 @@
import base64
import hmac
+import re
from typing import List, Optional, Set, Tuple
# Types
@@ -253,9 +254,27 @@
# Which makes this function polymorphic really
# This is not reflected in its type signature
headers, body = rfc6376_simple_holistic(headers, body)
-
+ body = _strip_gt_from(body)
return (headers, body)
+def _strip_gt_from(body: bytes) -> bytes:
+ r"""
+ Convert all escaped '>+From ' back to 'From '
+
+ >>> _strip_gt_from(b'> From ')
+ b'> From '
+ >>> _strip_gt_from(b' >From ')
+ b' >From '
+ >>> _strip_gt_from(b'>From_')
+ b'>From_'
+ >>> _strip_gt_from(b'>From ')
+ b'From '
+ >>> _strip_gt_from(b'>>>From ')
+ b'From '
+ >>> _strip_gt_from(b'\r\n>From x\r\n>From y')
+ b'\r\nFrom x\r\nFrom y'
+ """
+ return re.sub(b'^>+From ', b'From ', body, flags = re.MULTILINE)
def rfc6376_join(headers: Headers, body: Optional[bytes] = None) -> bytes:
r"""