scripts/tagmail.post

26 lines
664 B
Plaintext
Raw Normal View History

#!/usr/bin/env bash
notmuch new
folderlist=$(find ~/.mail/ -mindepth 1 -type d -printf '\n%P\n' | grep -v -E 'INBOX|Sent|Drafts|new|cur|tmp|notmuch' | sort)
folders="$(echo "$folderlist" | grep -v '\.') $(echo "$folderlist" | grep '\.')"
mailboxes="mailboxes"
# Tag by folder
for folder in INBOX Sent Drafts $folders
do
mailboxes="$mailboxes \"+$folder\""
tags=$(echo "${folder,,}" | tr -c '[[:alnum:]]' ' ' | sed -e 's/^ *//' -e 's/ *$//')
tagstring=+${tags// /" +"}
if [[ $folder != INBOX ]]; then
tagstring="$tagstring -inbox"
fi
#echo $tagstring
notmuch tag $tagstring folder:"$folder"
done
echo "$mailboxes" > ~/.mutt/mailboxes
exit 0