diff options
author | Romain Gonçalves <me@rgoncalves.se> | 2022-01-04 18:16:12 +0100 |
---|---|---|
committer | Romain Gonçalves <me@rgoncalves.se> | 2022-01-04 18:16:12 +0100 |
commit | e7b2188fe8dd715603dbd509fc62de6e872933a2 (patch) | |
tree | 8f31b14f0958d2b7acc9c41f940156e0822f22c4 /.bin/get-mailbox-imap | |
parent | f7ba6813339a00e45959c10c96b249326419c10b (diff) | |
download | dots-e7b2188fe8dd715603dbd509fc62de6e872933a2.tar.gz |
Tue Jan 4 06:16:12 PM CET 2022
Diffstat (limited to '.bin/get-mailbox-imap')
-rwxr-xr-x | .bin/get-mailbox-imap | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/.bin/get-mailbox-imap b/.bin/get-mailbox-imap index 713873e..b78752d 100755 --- a/.bin/get-mailbox-imap +++ b/.bin/get-mailbox-imap @@ -5,25 +5,17 @@ import sys def get_boxes(list): - """ - Retrieve and decode all mailboxes. - """ + """ 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, - primarily for neomutt usage. - """ + """ Print all boxes with a flattened output. """ return ''.join([f"+'{box}' " for box in list]) -def sort_boxes(bxs): - """ - Sort boxes list, - according to a predefined order - """ +def sort_mailboxes(mailboxes): + """ Sort boxes list according to a predefined order. """ order = [ "INBOX", @@ -36,20 +28,20 @@ def sort_boxes(bxs): "Archive" ] - bxs_orig = sorted(bxs) + mailboxes = sorted(mailboxes) # sort based on predefined order - bxs = [] + output = [] for exp in order: - matching = [s for s in bxs_orig if exp in s] - bxs.extend(matching) + matching = [s for s in mailboxes if exp in s] + output.extend(matching) # ensure all retrieved boxes are present - for bx in bxs_orig: - if bx not in bxs: - bxs.append(bx) + for box in mailboxes: + if box not in output: + output.append(box) - return bxs + return output def main(): @@ -67,7 +59,7 @@ def main(): mail.login(username, password) # parse folders output - bxs = sort_boxes(get_boxes(mail.list()[1])) + bxs = sort_mailboxes(get_boxes(mail.list()[1])) # oneline pretty-print for neomutt print(flatten_output(bxs), end=' ') |