You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ponymail.apache.org by GitBox <gi...@apache.org> on 2022/06/15 22:55:41 UTC

[GitHub] [incubator-ponymail-foal] sebbASF commented on a diff in pull request #241: Allow automatic extraction of lid from List-Id header

sebbASF commented on code in PR #241:
URL: https://github.com/apache/incubator-ponymail-foal/pull/241#discussion_r898501019


##########
tools/plugins/dkim_id.py:
##########
@@ -302,6 +302,7 @@ def rfc6376_reformed_canon(
     head_canon: bool = False,
     body_canon: bool = False,
     lid: Optional[bytes] = None,
+    automatic: bool = False,

Review Comment:
   Needs documenting



##########
tools/plugins/dkim_id.py:
##########
@@ -324,15 +325,24 @@ def rfc6376_reformed_canon(
     # If any List-Id header is set to the LID, lid is empty
     for (k, v) in headers:
         if k == b"list-id":
-            if v == lid:
+            if automatic is True:
+                sv: bytes = v
+                if b"<" in sv:
+                    sv = sv.split(b"<", 1)[1]
+                sv = sv.lstrip(b" \t").rstrip(b"> \t\r\n")
+                lid = b"<" + sv + b">"
+                break
+            elif v == lid:
                 lid = None
                 break
     # Construct hashable bytes from the parsed message
     return (lid or b"", rfc6376_join(headers, body))
 
 
 def rfc6376_rascal(
-    data: bytes, lid: Optional[bytes] = None
+    data: bytes,
+    lid: Optional[bytes] = None,
+    automatic: bool = False,

Review Comment:
   Needs documenting



##########
tools/plugins/dkim_id.py:
##########
@@ -381,7 +392,9 @@ def unpibble32(text: str) -> bytes:
     return base64.b32decode(encoded.translate(table))
 
 
-def dkim_id(data: bytes, lid: Optional[bytes] = None) -> str:
+def dkim_id(
+    data: bytes, lid: Optional[bytes] = None, automatic: bool = False

Review Comment:
   automatic arg needs documenting



##########
tools/plugins/dkim_id.py:
##########
@@ -400,14 +415,18 @@ def main() -> None:
     from sys import argv
     from typing import BinaryIO
 
+    f: BinaryIO
     if len(argv) == 2:
-        f: BinaryIO
         with open(argv[1], "rb") as f:
             print(dkim_id(f.read()))
-    elif len(argv) == 3: # add lid
-        f: BinaryIO
+    elif len(argv) == 3:  # add lid
+        lid: Optional[bytes] = argv[2].encode("utf-8")
+        automatic: bool = False
+        if lid == b"-":

Review Comment:
   This special value needs documenting



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@ponymail.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org