--- /dev/null
+#!/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)