diff --git a/.config/mutt/accounts/gil.portenseigne@nereide.fr.muttrc b/.config/mutt/accounts/gil.portenseigne@nereide.fr.muttrc index e1917cd..67cc8e2 100644 --- a/.config/mutt/accounts/gil.portenseigne@nereide.fr.muttrc +++ b/.config/mutt/accounts/gil.portenseigne@nereide.fr.muttrc @@ -62,8 +62,9 @@ subscribe support-pro20501@listes.nereide.fr subscribe support-pro20550@listes.nereide.fr -#mailboxes "=INBOX" "=LISTS" "=LISTS/PRIVATE OFBIZ" "=BULK" "=SERVICES" "=Drafts" "=Trash" "=Sent" "=Archives" -mailboxes =INBOX =BULK =LISTS =LISTS/APACHE =LISTS/NOTIFY\ OFBIZ =LISTS/NRD =LISTS/OFBIZ =LISTS/PRIVATE\ OFBIZ =SERVICES +setenv NEOMUTT_MAILDIR "$folder" +source "~/.local/bin/neomutt-mailboxes |" +macro index,pager ,m "setenv NEOMUTT_MAILDIR \"\$folder\"source \"~/.local/bin/neomutt-mailboxes |\"" "Rafraîchir les dossiers du compte actif" set status_format= "$from -%r-Mutt: %f [Msgs:%?M?%M/?%m%?n? New:%n?%?o? Old:%o?%?d? Del:%d?%?F? Flag:%F?%?t? Tag:%t?%?p? Post:%p?%?b? Inc:%b?%?l? %l?]---(%s/%S)-%>-(%P)---" diff --git a/.local/bin/neomutt-mailboxes b/.local/bin/neomutt-mailboxes new file mode 100755 index 0000000..9d61c09 --- /dev/null +++ b/.local/bin/neomutt-mailboxes @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 +import os +import sys +from pathlib import Path + + +def fail(error): + raise error + + +def quote(path): + value = str(path) + if "\n" in value or "\r" in value: + raise ValueError(f"Nom de dossier incompatible avec NeoMutt : {value!r}") + for character in ("\\", '"', "$", "`"): + value = value.replace(character, "\\" + character) + return f'"{value}"' + + +def main(): + if len(sys.argv) > 2: + raise ValueError("Utilisation : neomutt-mailboxes CHEMIN_DU_COMPTE") + + account = sys.argv[1] if len(sys.argv) == 2 else os.environ.get("NEOMUTT_MAILDIR") + if not account: + raise ValueError("Indiquez le chemin du compte ou définissez NEOMUTT_MAILDIR") + root = Path(account).expanduser() + if not root.is_dir(): + raise ValueError(f"Répertoire de courrier introuvable : {root}") + + mailboxes = [] + for current, directories, _ in os.walk(root, onerror=fail, followlinks=False): + names = set(directories) + if {"cur", "new", "tmp"} <= names: + mailboxes.append(Path(current)) + directories[:] = [name for name in directories if name not in {"cur", "new", "tmp"}] + + if not mailboxes: + raise ValueError(f"Aucun Maildir trouvé dans : {root}") + + commands = ["unmailboxes *"] + commands.extend(f"mailboxes {quote(path)}" for path in sorted(mailboxes)) + print("\n".join(commands)) + + +if __name__ == "__main__": + try: + main() + except (OSError, ValueError) as error: + print(f"neomutt-mailboxes : {error}", file=sys.stderr) + sys.exit(1)