From 45bbb20fc8b6fb81d489c9d71f38d5607bb242bd Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 7 Sep 2019 12:05:54 +0200 Subject: bin/mbsync2mutt_mailboxes: Adding helper script to write a mutt configuration snippet, defining the available mailboxes (per account). The script uses the output of mbsync -al to get a list of all mailboxes it has access to. --- bin/mbsync2mutt_mailboxes | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 bin/mbsync2mutt_mailboxes (limited to 'bin/mbsync2mutt_mailboxes') 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 -- cgit v1.2.3-70-g09d2