rc/config/neomutt/mailboxes.sh

30 lines
861 B
Bash
Raw Permalink Normal View History

#!/bin/sh
usage() {
2020-11-11 03:05:37 +00:00
>&2 echo "$0 <maildirs \$folder>"
>&2 echo " Generate neomutt mailboxes & named-mailboxes for every maildir in \$folder"
exit 1
}
if [ -z "$1" ]; then
usage
fi
maildir="$1"
2020-11-11 03:05:37 +00:00
mailboxes=$(find "$maildir" -mindepth 1 -maxdepth 1 -type d ! -name cur ! -name tmp ! -name new ! -name .notmuch | sort)
# Order of the keys to use for the account switch macro
chars="1234567890azertyuiopqsdfghjklmwxcvbn"
i=1
for m in $mailboxes; do
inbox="$(find "$m" -maxdepth 1 -iname "inbox" -type d -printf "%f" -quit)"
2020-11-11 03:05:37 +00:00
key="$(printf '%s' "$chars" | cut -c "$i")"
printf "named-mailboxes '[%s] %s' '%s'\n" "$key" "$(basename "$m")" "$m/$inbox"
printf "sidebar_whitelist '%s'\n" "$m/$inbox"
printf "mailboxes "
find "$m" -mindepth 1 -type d ! -name cur ! -name tmp ! -name new -printf '"%p"\0' | xargs -0
2020-11-11 03:05:37 +00:00
i=$((i+1))
done