This is an automated email from the ASF dual-hosted git repository.
sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git
The following commit(s) were added to refs/heads/master by this push:
new c80e784 Canonicalisation of 'From ' quoting variations
c80e784 is described below
commit c80e7842ae274c22afefa817e18bd936c981ee8f
Author: Sebb <[email protected]>
AuthorDate: Fri Oct 8 20:26:33 2021 +0100
Canonicalisation of 'From ' quoting variations
This fixes #115
(Unit tests will be added shortly)
---
tools/plugins/dkim_id.py | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
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 @@ DKIM-ID Generator Code
import base64
import hmac
+import re
from typing import List, Optional, Set, Tuple
# Types
@@ -253,9 +254,27 @@ def rfc6376_split_canon(
# 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"""