You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by se...@apache.org on 2019/08/12 14:56:54 UTC

[incubator-ponymail] branch master updated: Bug: generator.py does not include original medium generator

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.git


The following commit(s) were added to refs/heads/master by this push:
     new 0c61956  Bug: generator.py does not include original medium generator
0c61956 is described below

commit 0c619565b8fe4888c85f6e5f9eced542b892278f
Author: Sebb <se...@apache.org>
AuthorDate: Mon Aug 12 15:56:50 2019 +0100

    Bug: generator.py does not include original medium generator
    
    This fixes #505
---
 CHANGELOG.md        |  1 +
 tools/generators.py | 39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9b32835..f75216a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,5 @@
 ## Changes in 0.12:
+- Bug: generator.py does not include original medium generator (#505)
 - Enh: move generator selection to generator.py (#504)
 - Bug: Bug: parser fails to extract inline attachments (#501)
 - Bug: Google OAuth used with wrong response_type (#500)
diff --git a/tools/generators.py b/tools/generators.py
index d561dfe..0de3309 100644
--- a/tools/generators.py
+++ b/tools/generators.py
@@ -50,6 +50,7 @@ def medium(msg, body, lid, _attachments):
     """
     Standard 0.9 generator - Not recommended for future installations.
     (does not generate sufficiently unique ids)
+    Also the lid is included in the hash; this causes problems if the listname needs to be changed.
 
     The following message fields are concatenated to form the hash input:
     - body: if bytes as is else encoded ascii, ignoring invalid characters; if the body is null an Exception is thrown
@@ -91,6 +92,43 @@ def medium(msg, body, lid, _attachments):
     mid = "%s@%s" % (hashlib.sha224(xbody).hexdigest(), lid)
     return mid
 
+# Original medium generator used for a while in June 2016
+# Committed: https://gitbox.apache.org/repos/asf?p=incubator-ponymail.git;a=commitdiff;h=aa989610
+# Replaced:  https://gitbox.apache.org/repos/asf?p=incubator-ponymail.git;a=commitdiff;h=4732d25f
+def medium_original(msg, body, lid, _attachments):
+    """
+    NOT RECOMMENDED - does not generate sufficiently unique ids
+    Also the lid is included in the hash; this causes problems if the listname needs to be changed.
+
+    The following message fields are concatenated to form the hash input:
+    - body: if bytes as is else encoded ascii, ignoring invalid characters; if the body is null an Exception is thrown
+    - lid
+    - Date header if it exists and parses OK; converted to UTC seconds since the epoch; else 0
+
+    Parameters:
+    msg - the parsed message (used to get the date)
+    body - the parsed text content (may be null)
+    lid - list id
+    _attachments - list of attachments (not used)
+
+    Returns: "<hash>@<lid>" where hash is sha224 of the message items noted above
+    """
+
+    # Use text body
+    xbody = body if type(body) is bytes else body.encode('ascii', 'ignore')
+    # Use List ID
+    xbody += bytes(lid)
+
+    uid_mdate = 0 # mdate for UID generation
+    try:
+        mdate = email.utils.parsedate_tz(msg_metadata.get('date'))
+        uid_mdate = email.utils.mktime_tz(mdate) # Only set if Date header is valid
+    except:
+       pass
+    xbody += bytes(uid_mdate)
+    mid = "%s@%s" % (hashlib.sha224(xbody).hexdigest(), lid)
+    return mid
+
 # cluster: Use data that is guaranteed to be the same across cluster setups
 # This is the recommended generator for cluster setups.
 # Unlike 'medium', this only makes use of the Date: header and not the archived-at,
@@ -195,6 +233,7 @@ def legacy(msg, body, lid, _attachments):
 __GENERATORS={
     'full': full,
     'medium': medium,
+    'medium_original': medium_original,
     'cluster': cluster,
     'legacy': legacy,
 }