This is an automated email from the ASF dual-hosted git repository.

humbedooh 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 6889ed8  Add in email parsing policy
6889ed8 is described below

commit 6889ed80253f0d3a3bd5a2a809feeb08982ac32d
Author: Daniel Gruno <[email protected]>
AuthorDate: Mon Nov 15 17:35:14 2021 +0100

    Add in email parsing policy
---
 tools/archiver.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/tools/archiver.py b/tools/archiver.py
index 79e11d1..3ef6a49 100755
--- a/tools/archiver.py
+++ b/tools/archiver.py
@@ -964,8 +964,16 @@ def main():
 
     try:
         raw_message = input_stream.read()
+        
+        # Get/Set email parsing policy (primarily ascii/7bit vs native utf8)
+        policy = email.policy.default        # Default (8bit) lines in Python 
>=3.3
+        policy_choice = config.get("archiver", "policy", fallback="default")
+        if policy_choice == "strict":
+            policy = email.policy.compat32   # 7bit lines
+        elif policy_choice == "smtputf8":
+            policy = email.policy.SMTPUTF8   # 8bit/unicode lines
         try:
-            msg = email.message_from_bytes(raw_message, 
policy=email.policy.default)
+            msg = email.message_from_bytes(raw_message, policy=policy)
         except Exception as err:
             print("STDIN parser exception: %s" % err)
             sys.exit(-1)

Reply via email to