aboutsummaryrefslogtreecommitdiffstats
path: root/bin/mbsync2mutt_mailboxes
diff options
context:
space:
mode:
authorDavid Runge <dave@sleepmap.de>2019-09-07 12:05:54 +0200
committerDavid Runge <dave@sleepmap.de>2019-09-07 12:05:54 +0200
commit45bbb20fc8b6fb81d489c9d71f38d5607bb242bd (patch)
tree8d4c6973d8c219d5528826ecdfe54ff4c2327d83 /bin/mbsync2mutt_mailboxes
parent85cddc33b14fb68ef63133938bd0fae18a1b46ae (diff)
downloaddotfiles-45bbb20fc8b6fb81d489c9d71f38d5607bb242bd.tar.gz
dotfiles-45bbb20fc8b6fb81d489c9d71f38d5607bb242bd.tar.bz2
dotfiles-45bbb20fc8b6fb81d489c9d71f38d5607bb242bd.tar.xz
dotfiles-45bbb20fc8b6fb81d489c9d71f38d5607bb242bd.zip
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.
Diffstat (limited to 'bin/mbsync2mutt_mailboxes')
-rwxr-xr-xbin/mbsync2mutt_mailboxes45
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