import.py: Add import script import
authorW. Trevor King <wking@tremily.us>
Sun, 21 Aug 2016 04:16:36 +0000 (21:16 -0700)
committerW. Trevor King <wking@tremily.us>
Sun, 21 Aug 2016 04:26:20 +0000 (21:26 -0700)
As posted in [1], with an additional ignored message since then.

I don't have ssoma-mda in an installable form at the moment, but you
can clone [2] and:

  $ ln -s ~/src/ssoma-mda/ssoma-mda ssoma_mda.py

in this directory before running import.py.

[1]: Subject: Mail archives in Git using ssoma
     To: notmuch@notmuchmail.org
     Date: Fri, 07 Nov 2014 11:03:21 -0800
     Message-ID: <20141107190321.GL23609@odin.tremily.us>
[2]: git://tremily.us/ssoma-mda.git

import.py [new file with mode: 0755]

diff --git a/import.py b/import.py
new file mode 100755 (executable)
index 0000000..497a73a
--- /dev/null
+++ b/import.py
@@ -0,0 +1,60 @@
+#!/usr/bin/env python3
+#
+# Copyright (C) 2014-2016 W. Trevor King <wking@tremily.us>
+# License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
+
+"""Import Notmuch archives into a ssoma format.
+
+More information in id:20141107190321.GL23609@odin.tremily.us.
+"""
+
+import email.utils
+import mailbox
+
+import ssoma_mda
+
+
+def import_mbox(path):
+    mbox = mailbox.mbox(path, factory=None, create=False)
+    messages = sorted(mbox, key=lambda m: email.utils.mktime_tz(email.utils.parsedate_tz(m['date'])))
+    for i, message in enumerate(messages):
+        print('{}: {}'.format(i, message['message-id']))
+        break
+        if ((message['message-id'] == '<m2k4gmyjer.fsf@ecocode.net>' and
+                message['X-List-Received-Date'] == 'Sat, 26 Feb 2011 14:23:34 -0000') or
+              (message['message-id'] == '<4EDF728E.3050204@gmail.com>' and
+                message['X-List-Received-Date'] == 'Wed, 07 Dec 2011 14:05:16 -0000') or
+              (message['message-id'] == '<4FE369F2.5080804@gmail.com>' and
+                message['X-List-Received-Date'] == 'Thu, 21 Jun 2012 18:38:07 -0000') or
+              (message['message-id'] == '<5122353D.4060601@gmail.com>' and
+                message['X-List-Received-Date'] == 'Mon, 18 Feb 2013 14:06:12 -0000') or
+              (message['message-id'] == '<CA+eQo_1hMsTD4+6ifqgEQXW0_qYXGOdfkO6tBuGQKV+W7OSaKA@mail.gmail.com>' and
+                message['X-List-Received-Date'] == 'Wed, 24 Apr 2013 18:09:55 -0000') or
+              (message['message-id'] == '<527B9E8C.5000001@krugs.de>' and
+                message['X-List-Received-Date'] == 'Thu, 07 Nov 2013 14:07:32 -0000') or
+              (message['message-id'] == '<1399645162-8653-1-git-send-email-wael.nasreddine@gmail.com>' and
+                message['X-List-Received-Date'] == 'Fri, 09 May 2014 14:19:36 -0000') or
+              (message['message-id'] == '<m2mw9xkyvg.fsf@krugs.de>' and
+                message['X-List-Received-Date'] == 'Thu, 18 Sep 2014 10:27:35 -0000') or
+              (message['message-id'] == '<cover.1411379395.git.jani@nikula.org>' and
+                message['X-List-Received-Date'] != 'Mon, 22 Sep 2014 09:54:16 -0000') or
+              (message['message-id'] == '<67EEA3E1-918F-47AE-8AD7-EF0A5923D800@m0g.net>' and
+                message['X-List-Received-Date'] == 'Wed, 06 Jan 2016 15:50:34 -0000')):
+            continue
+        try:
+            ssoma_mda.deliver(message=message, once=True)
+        except:
+            print(message['message-id'])
+            print(message['X-List-Received-Date'])
+            raise
+
+
+if __name__ == '__main__':
+    import argparse
+
+    parser = argparse.ArgumentParser(description=__doc__)
+    parser.add_argument('path', help='Path to Notmuch mbox.')
+
+    args = parser.parse_args()
+
+    import_mbox(args.path)