From 078b4b8bb590470e654640325262cbbab94fdec4 Mon Sep 17 00:00:00 2001 From: Roland Puntaier Date: Wed, 28 Aug 2019 21:30:43 +0200 Subject: [PATCH] folder-hook and account-hook --- bin/mw | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/bin/mw b/bin/mw index 25f9541..66bd928 100755 --- a/bin/mw +++ b/bin/mw @@ -131,6 +131,7 @@ set imap_user = \"$mwlogin\" set header_cache = $mwcachedir/$mwaccount/headers set message_cachedir = $mwcachedir/$mwaccount/bodies set imap_pass = \"\`pass $mwpass\`\" +account-hook \$folder 'set imap_user=\$imap_user imap_pass=\$imap_pass' set mbox_type = Maildir set ssl_starttls = yes @@ -204,14 +205,17 @@ EOF esac mkdir -p ${mwmbsyncrc%/*} echo "$mbsync_profile" >> "$mwmbsyncrc" - echo "$mutt_profile" > "$mwaccdir/$idnum-$mwaccount.muttrc" + mwaccrc=$mwaccdir/$idnum-$mwaccount.muttrc + echo "$mutt_profile" > "$mwaccrc" [ ! -f "$mwmuttrc" ] && echo "# vim: filetype=neomuttrc" > "$mwmuttrc" && echo "muttrc created." ! grep "source.*mutt-wizard.muttrc" "$mwmuttrc" >/dev/null && echo "source $mwconfig # mw-autogenerated" >> "$mwmuttrc" - ! grep "^source.*$idnum-$mwaccount.muttrc" "$mwmuttrc" >/dev/null && echo "source $mwaccdir/$idnum-$mwaccount.muttrc # mw-autogenerated" >> "$mwmuttrc" - ! grep "^macro .* i$idnum .*" "$mwmuttrc" >/dev/null && echo "macro index,pager i$idnum 'source $mwaccdir/$idnum-$mwaccount.muttrc!;' \"switch to $mwaddr\" # mw-autogenerated" >> "$mwmuttrc" if [ "$mwtype" = "offline" ]; then ! grep "^macro .* gM .*" "$mwmuttrc" >/dev/null && echo "macro index gM 'mailsync -Va' \"sync all mail\" # mw-autogenerated" >> "$mwmuttrc" fi + muttsync="source $mwaccrc\!;" + ! grep "^source.*$idnum-$mwaccount.muttrc" "$mwmuttrc" >/dev/null && echo "source $mwaccrc # mw-autogenerated" >> "$mwmuttrc" + ! grep "^folder-hook.*$idnum-$mwaccount.muttrc" "$mwmuttrc" >/dev/null && echo "folder-hook \$folder '$muttsync' # mw-autogenerated" >> "$mwmuttrc" + ! grep "^macro .* i$idnum .*" "$mwmuttrc" >/dev/null && echo "macro index,pager i$idnum '$muttsync' \"switch to $mwaddr\" # mw-autogenerated" >> "$mwmuttrc" return 0 } @@ -228,7 +232,7 @@ getpass() { formatShortcut() { while read -r data; do { echo "macro index,pager g$1 \"$data\" \"go to $2\" # mw-autogenerated" echo "macro index,pager M$1 \"$data\" \"move mail to $2\" # mw-autogenerated" - echo "macro index,pager C$1 \"$data\" \"copy mail to $2\" # mw-autogenerated"; } >> "$mwaccdir/$idnum-$mwaccount.muttrc" + echo "macro index,pager C$1 \"$data\" \"copy mail to $2\" # mw-autogenerated"; } >> "$mwaccrc" done } @@ -257,12 +261,12 @@ finalize() { record=$(echo "$boxes" | grep -i -m 1 sent | sed 's/=/+/g') postponed=$(echo "$boxes" | grep -i -m 1 draft | sed 's/=/+/g') trash=$(echo "$boxes" | grep -i -m 1 trash | sed 's/=/+/g') - sed -i "/^mailboxes\|^set record\|^set postponed\|^set trash\|^set spoolfile/d" "$mwaccdir/$idnum-$mwaccount.muttrc" - { echo "set spoolfile = \"$spoolfile\""; echo "set record = \"$record\""; echo "set postponed = \"$postponed\""; echo "set trash = \"$trash\""; } >> "$mwaccdir/$idnum-$mwaccount.muttrc" + sed -i "/^mailboxes\|^set record\|^set postponed\|^set trash\|^set spoolfile/d" "$mwaccrc" + { echo "set spoolfile = \"$spoolfile\""; echo "set record = \"$record\""; echo "set postponed = \"$postponed\""; echo "set trash = \"$trash\""; } >> "$mwaccrc" mwaccount_="${mwaccount//[.@]/_}" - echo "mailboxes =${mwaccount_%_*} ===================== $(echo "$boxes" | sed -e "s/^\|$/\"/g" | tr "\n" " ")" >> "$mwaccdir/$idnum-$mwaccount.muttrc" + echo "mailboxes =${mwaccount_%_*} ===================== $(echo "$boxes" | sed -e "s/^\|$/\"/g" | tr "\n" " ")" >> "$mwaccrc" printf "Setting up your keyboard shortcuts for jumping between mailboxes...\\n" - sed -i "/# mw-autogenerated/d" "$mwaccdir/$idnum-$mwaccount.muttrc" + sed -i "/# mw-autogenerated/d" "$mwaccrc" echo "$boxes" | grep -i inbox | head -n 1 | formatShortcut i inbox echo "$boxes" | grep -i sent | head -n 1 | formatShortcut s sent echo "$boxes" | grep -i draft | head -n 1 | formatShortcut d drafts