diff options
Diffstat (limited to 'bin/mbsync2mutt_mailboxes')
-rwxr-xr-x | bin/mbsync2mutt_mailboxes | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/bin/mbsync2mutt_mailboxes b/bin/mbsync2mutt_mailboxes new file mode 100755 index 0000000..c98e219 --- /dev/null +++ b/bin/mbsync2mutt_mailboxes @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +# +# This script writes account specific output of mbsync -l to a configuration +# file, that can be used by mutt, to define its mailboxes. +# It requires isync (provides mbsync) to be installed. +# +# Creates an output file (defined by the first arguments to this script), which +# adds a 'mailboxes' entry (see `man 5 muttrc`) of all mailboxes in a specific +# account, that mbsync is setup to sync (see `man 1 mbsync`). + +set -eou pipefail +IFS=$'\n' + +declare -A mailboxes +output_file="" + +get_mailboxes_by_account() { + local account="" + for entry in $(mbsync -al); do + if [[ "$entry" == *':' ]]; then + account="${entry/:/}" + mailboxes["$account"]="" + else + mailboxes["$account"]="${mailboxes[$account]} '+${account}/${entry}'" + fi + done +} + +output_mailboxes_to_file() { + tmpfile="$(mktemp)" + for account in "${!mailboxes[@]}"; do + echo -e "mailboxes ${mailboxes[$account]}\n" >> "$tmpfile" + done + mv "$tmpfile" "$output_file" +} + +if [ $# -ne 1 ]; then + echo "Requires an output file name as first argument." + exit 1 +else + output_file="$1" +fi + +get_mailboxes_by_account +output_mailboxes_to_file |