summaryrefslogtreecommitdiffstats
path: root/.bin/get-mailbox-imap
diff options
context:
space:
mode:
Diffstat (limited to '.bin/get-mailbox-imap')
-rwxr-xr-x.bin/get-mailbox-imap34
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=' ')
remember that computers suck.