aboutsummaryrefslogtreecommitdiff
path: root/tests/instrumentation/mbox-to-imap.py
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2024-01-06 21:42:08 +0100
committerQuentin Dufour <quentin@deuxfleurs.fr>2024-01-06 21:42:08 +0100
commit73fc5e77df9db756af64135aaa08bb0242b13371 (patch)
tree54c5b8d13f7ae7dccf5cf1b3d3441153929b2af7 /tests/instrumentation/mbox-to-imap.py
parentea1772df425cb7faa4628b1c6c398ae3f77fca34 (diff)
downloadaerogramme-73fc5e77df9db756af64135aaa08bb0242b13371.tar.gz
aerogramme-73fc5e77df9db756af64135aaa08bb0242b13371.zip
Quickly import lot of emails
Diffstat (limited to 'tests/instrumentation/mbox-to-imap.py')
-rw-r--r--tests/instrumentation/mbox-to-imap.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/instrumentation/mbox-to-imap.py b/tests/instrumentation/mbox-to-imap.py
new file mode 100644
index 0000000..63ff391
--- /dev/null
+++ b/tests/instrumentation/mbox-to-imap.py
@@ -0,0 +1,37 @@
+from imaplib import IMAP4_SSL, IMAP4
+from os import listdir
+from os.path import isfile, join
+import sys
+import argparse
+import mailbox
+
+parser = argparse.ArgumentParser(
+ prog='mbox-to-imap',
+ description='Send an mbox to an imap server',
+ epilog='Just a debug tool')
+parser.add_argument('mbox_path') # positional argument
+parser.add_argument('-H', '--host', default="localhost")
+parser.add_argument('-p', '--port', default="143")
+parser.add_argument('-u', '--user')
+parser.add_argument('-s', '--password')
+parser.add_argument('-m', '--mailbox', default="INBOX")
+parser.add_argument('-t', '--tls', action='store_true')
+args = parser.parse_args()
+
+mbox = mailbox.mbox(args.mbox_path)
+
+if args.tls:
+ imap = IMAP4_SSL
+else:
+ imap = IMAP4
+
+with imap(host=args.host, port=args.port) as M:
+ print(M.login(args.user, args.password))
+ print(M.select(args.mailbox))
+ for k in mbox.keys():
+ content = mbox.get(k).as_bytes()
+ M.append(args.mailbox, [], None, content)
+ print(f"{k}/{len(mbox)}")
+
+
+