diff options
author | David Runge <dave@sleepmap.de> | 2022-12-09 22:59:46 +0100 |
---|---|---|
committer | David Runge <dave@sleepmap.de> | 2022-12-09 22:59:46 +0100 |
commit | efd80c4e49f786329163289724ba23b2fdc5fa58 (patch) | |
tree | 8388d09a2af61caa19351b7ebee4b15a396f4490 /bin | |
parent | fbd00a8e8c5edf108d726dc25d83afd9aa881c0f (diff) | |
download | dotfiles-efd80c4e49f786329163289724ba23b2fdc5fa58.tar.gz dotfiles-efd80c4e49f786329163289724ba23b2fdc5fa58.tar.bz2 dotfiles-efd80c4e49f786329163289724ba23b2fdc5fa58.tar.xz dotfiles-efd80c4e49f786329163289724ba23b2fdc5fa58.zip |
Add script to export mutt mailboxes
bin/mutt_mailboxes:
Add script to export mutt mailboxes.
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/mutt_mailboxes | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/bin/mutt_mailboxes b/bin/mutt_mailboxes new file mode 100755 index 0000000..71547c9 --- /dev/null +++ b/bin/mutt_mailboxes @@ -0,0 +1,68 @@ +#!/usr/bin/python + +from argparse import ArgumentParser +from pathlib import Path +from sys import exit + +MAILBOX_SUBDIRS = {"cur", "new", "tmp"} + + +def get_mailbox_from_dir(path: Path, mailboxes: list[Path]) -> None: + for current_path in path.iterdir(): + if current_path.is_dir() and current_path.name not in MAILBOX_SUBDIRS: + subdirs = list(current_path.iterdir()) + if MAILBOX_SUBDIRS & set(subdir.name for subdir in subdirs) and current_path not in mailboxes: + mailboxes.append(current_path) + + for subdir in subdirs: + if subdir.name not in MAILBOX_SUBDIRS: + get_mailbox_from_dir(path=current_path, mailboxes=mailboxes) + + +def main(output: Path, paths: list[Path]) -> None: + file_string = "" + + if len(paths) == 0: + exit(1) + + for path in paths: + mailboxes: list[Path] = [] + mailboxes_string = "mailboxes " + + if not path.exists(): + exit(1) + + get_mailbox_from_dir(path=path, mailboxes=mailboxes) + + for mailbox in mailboxes: + mailboxes_string += f" '+{(str(mailbox).replace(str(path.parent) + '/', ''))}'" + file_string += mailboxes_string + "\n" + + with open(output, "w") as f: + print(file_string, file=f) + + +if __name__ == "__main__": + parser = ArgumentParser( + description=""" + Create 'mailboxes' entries for one or more directories. + Each provided directory is + """ + ) + parser.add_argument( + "-o", + "--output", + default=Path("mailboxes.rc"), + help="a file to write the mailboxes to (mailboxes.rc by default)", + type=Path, + ) + parser.add_argument( + "paths", + help="a directory to search in for mailbox directories", + nargs="+", + type=Path, + ) + + namespace = parser.parse_args() + + main(output=namespace.output, paths=namespace.paths) |