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/30 10:38:13 UTC

[incubator-ponymail-unit-tests] branch master updated: Oops, cannot use key with multiple input files

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


The following commit(s) were added to refs/heads/master by this push:
     new 76b942f  Oops, cannot use key with multiple input files
76b942f is described below

commit 76b942fcc7ee0f637648b6bff2151f134a1211f0
Author: Sebb <se...@apache.org>
AuthorDate: Sun Aug 30 11:37:57 2020 +0100

    Oops, cannot use key with multiple input files
---
 tools/collate-mboxes.py | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/tools/collate-mboxes.py b/tools/collate-mboxes.py
index eed73ef..3bb02d5 100755
--- a/tools/collate-mboxes.py
+++ b/tools/collate-mboxes.py
@@ -13,6 +13,7 @@ msgfiles = sys.argv[2:] # multiple input files allowed
 
 allmessages = {}
 noid = 0
+crlf = None # assume that all emails have the same EOL
 for msgfile in msgfiles:
     messages = mailbox.mbox(
         msgfile, None, create=False
@@ -22,27 +23,27 @@ for msgfile in msgfiles:
         msgid = message.get('message-id')
         if msgid:
             msgid = msgid.strip()
-            allmessages[msgid] = key
+            file = messages.get_file(key, True)
+            message_raw = b''
+            if crlf is None:
+                message_raw = file.readline()
+                crlf = (message_raw.endswith(b'\r\n'))
+            message_raw += file.read()
+            file.close()
+            allmessages[msgid] = message_raw
         else:
             print("No message id: ", message.get_from())
             noid += 1
 
 
 nw = 0
-crlf = None # assume that all emails have the same EOL
 with open(outmbox, "wb") as f:
     for key in sorted(allmessages.keys()):
-        file=messages.get_file(allmessages[key], True)
-        if crlf is None:
-            from_ = file.readline()
-            f.write(from_)
-            crlf = (from_.endswith(b'\r\n'))
-        f.write(file.read())
+        f.write(allmessages[key])
         if crlf:
             f.write(b'\r\n')
         else:
             f.write(b'\n')
-        file.close()
         nw += 1
 
 print("Wrote %u emails to %s with CRLF %s (%u skipped)" % (nw, outmbox, crlf, noid))