summaryrefslogtreecommitdiff
path: root/detect_mailboxes.sh
blob: 7a015e15346924ceaf3a26eb32f143fc8e2be2d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/sh
muttdir="$HOME/.config/mutt/"

find ~/.mail/$1 -maxdepth 1 -mindepth 1 -type d | sed -e "s/.*\///g;s/^/=/g" > /tmp/$1_boxes
oneline=$(cat /tmp/$1_boxes | tr "\n" " ")
sed -i "/^mailboxes/d" "$muttdir"accounts/$1.muttrc
echo mailboxes $oneline >> "$muttdir"accounts/$1.muttrc

formatShortcut() { \
	while read data; do
	echo "macro index,pager g$1 \"<change-folder>$data<enter>\" \"Go to $2.\"" >> "$muttdir"accounts/$3.muttrc
	done ;}

sed -i "/^macro index,pager g/d" "$muttdir"accounts/$1.muttrc

grep -vi /tmp/$1_boxes -e "trash\|drafts\|sent\|trash\|spam\|junk\|archive" | sort -n | sed 1q | formatShortcut i inbox $1
grep -i /tmp/$1_boxes -e sent | formatShortcut s sent $1
grep -i /tmp/$1_boxes -e trash | formatShortcut t trash $1
grep -i /tmp/$1_boxes -e spam | formatShortcut S spam $1
grep -i /tmp/$1_boxes -e draft | formatShortcut d drafts $1
grep -i /tmp/$1_boxes -e archive | formatShortcut a archive $1