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 2020/08/22 09:41:58 UTC
[incubator-ponymail-foal] branch master updated: Does not need to
be Archiver method
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 70af824 Does not need to be Archiver method
70af824 is described below
commit 70af8241ffe4cbbea83736ea8f3c9eee68318323
Author: Sebb <se...@apache.org>
AuthorDate: Sat Aug 22 10:41:39 2020 +0100
Does not need to be Archiver method
---
tools/archiver.py | 23 ++++++++++++-----------
tools/import-mbox.py | 2 +-
2 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/tools/archiver.py b/tools/archiver.py
index 39b236f..4101024 100755
--- a/tools/archiver.py
+++ b/tools/archiver.py
@@ -87,6 +87,16 @@ def encode_base64(buff: bytes) -> str:
""" Convert bytes to base64 as text string (no newlines) """
return base64.standard_b64encode(buff).decode("ascii", "ignore")
+def mbox_source(b: bytes) -> str:
+ # Common method shared with import-mbox
+ try:
+ # Can we store as ASCII?
+ return b.decode("ascii", errors="strict")
+ except UnicodeError:
+ # No, so must use base64 to avoid corruption on re-encoding
+ return encode_base64(b)
+
+
def parse_attachment(
part: email.message.Message,
@@ -499,7 +509,7 @@ class Archiver(object): # N.B. Also used by import-mbox.py
body={
"message-id": msg_metadata["message-id"],
"permalink": ojson["mid"],
- "source": self.mbox_source(raw_message),
+ "source": mbox_source(raw_message),
},
)
# If we have a dump dir and ES failed, push to dump dir instead as a JSON object
@@ -521,7 +531,7 @@ class Archiver(object): # N.B. Also used by import-mbox.py
"id": sha3,
"permalink": ojson["mid"],
"message-id": msg_metadata["message-id"],
- "source": self.mbox_source(raw_message),
+ "source": mbox_source(raw_message),
},
"attachments": contents,
},
@@ -630,15 +640,6 @@ class Archiver(object): # N.B. Also used by import-mbox.py
logger.info("Notification sent to %s for %s", cid, mid)
return lid, ojson["mid"]
- def mbox_source(self, b: bytes) -> str:
- # Common method shared with import-mbox
- try:
- # Can we store as ASCII?
- return b.decode("ascii", errors="strict")
- except UnicodeError:
- # No, so must use base64 to avoid corruption on re-encoding
- return encode_base64(b)
-
def list_url(self, _mlist):
""" Required by MM3 plugin API
"""
diff --git a/tools/import-mbox.py b/tools/import-mbox.py
index 54fee71..1e31c32 100755
--- a/tools/import-mbox.py
+++ b/tools/import-mbox.py
@@ -327,7 +327,7 @@ class SlurpThread(Thread):
"mid"
], # needed for bulk-insert only, not needed in database
"message-id": json["message-id"],
- "source": archie.mbox_source(raw_msg),
+ "source": archiver.mbox_source(raw_msg),
}
except Exception as e:
self.printid(