summaryrefslogtreecommitdiffstats
path: root/.bin/get-mailbox-imap
diff options
context:
space:
mode:
authorRomain Gonçalves <me@rgoncalves.se>2022-10-08 12:40:19 +0200
committerRomain Gonçalves <me@rgoncalves.se>2022-10-08 12:40:19 +0200
commitce6be946d024aa55a15d576388d05f90be671cf2 (patch)
treefa1053446a3fb06daee8438c1ff664cb36c0abcb /.bin/get-mailbox-imap
parent703ed1915c69911a95cab6e1fb6524629c976800 (diff)
downloaddots-ce6be946d024aa55a15d576388d05f90be671cf2.tar.gz
Sat Oct 8 12:40:19 PM CEST 2022
Diffstat (limited to '.bin/get-mailbox-imap')
-rwxr-xr-x.bin/get-mailbox-imap69
1 files changed, 0 insertions, 69 deletions
diff --git a/.bin/get-mailbox-imap b/.bin/get-mailbox-imap
deleted file mode 100755
index b78752d..0000000
--- a/.bin/get-mailbox-imap
+++ /dev/null
@@ -1,69 +0,0 @@
-#!/usr/bin/env python3
-
-import imaplib
-import sys
-
-
-def get_boxes(list):
- """ Retrieve and decode all mailboxes. """
- return [box.decode('utf-8').rsplit(' ')[-1] for box in list]
-
-
-def flatten_output(list):
- """ Print all boxes with a flattened output. """
- return ''.join([f"+'{box}' " for box in list])
-
-
-def sort_mailboxes(mailboxes):
- """ Sort boxes list according to a predefined order. """
-
- order = [
- "INBOX",
- "Unread",
- "Drafts",
- "Sent",
- "Spam",
- "Trash",
- "Junk",
- "Archive"
- ]
-
- mailboxes = sorted(mailboxes)
-
- # sort based on predefined order
- output = []
- for exp in order:
- matching = [s for s in mailboxes if exp in s]
- output.extend(matching)
-
- # ensure all retrieved boxes are present
- for box in mailboxes:
- if box not in output:
- output.append(box)
-
- return output
-
-
-def main():
- """
- Retrieve, sort, and pretty print for neomutt
- """
-
- # user information
- remote = sys.argv[1]
- username = sys.argv[2]
- password = sys.argv[3]
-
- # connection
- mail = imaplib.IMAP4_SSL(remote)
- mail.login(username, password)
-
- # parse folders output
- bxs = sort_mailboxes(get_boxes(mail.list()[1]))
-
- # oneline pretty-print for neomutt
- print(flatten_output(bxs), end=' ')
-
-
-if __name__ == "__main__":
- main()
remember that computers suck.