From c05076903dba730c0e81013ffebace4fed5703cb Mon Sep 17 00:00:00 2001 From: Roland Puntaier Date: Thu, 29 Aug 2019 10:14:00 +0200 Subject: [PATCH] place iX macro inside the account rc --- README.md | 1 - bin/mailsync | 3 ++- bin/mw | 23 ++++++++++++----------- test/dotests | 6 +++--- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 2182371..e7d873e 100644 --- a/README.md +++ b/README.md @@ -157,4 +157,3 @@ mutt-wizard is free/libre software, licensed under the GPLv3. - Add ~~Mac OS~~/BSD compatibility (the script should work for Mac OS now) - ~~Out-of-the-box compatibility with Protonmail Bridge~~ (I believe this is done, but more bug-testing is welcome since I don't have PM) - Option to keep configuration for accounts that failed to connect (maybe) -- Add automatic tagging and mail moving via `afew` diff --git a/bin/mailsync b/bin/mailsync index ac7380e..d9188e8 100755 --- a/bin/mailsync +++ b/bin/mailsync @@ -57,7 +57,8 @@ syncandnotify() { # Sync accounts passed as argument or all. if [ "$#" -eq "0" ]; then - accounts="$(awk '/^Channel/ {print $2}' "$mbsyncrc")" + accounts="$(awk '/^Group .*@.*/ {print $2}' "$mbsyncrc")" + accounts+=" $(awk '/^Channel .*@.*/ {print $2}' "$mbsyncrc")" else accounts=$* fi diff --git a/bin/mw b/bin/mw index 66bd928..5184fbe 100755 --- a/bin/mw +++ b/bin/mw @@ -127,11 +127,11 @@ set from = \"$mwaddr\" set sendmail = \"$msmtpbin -a $mwaccount\" alias me $mwname <$mwaddr> set folder = \"imaps://$mwaddr@$mwimap:$mwiport\" +set header_cache = $mwcachedir/$mwaccount +set message_cachedir = $mwcachedir/$mwaccount 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' +account-hook \$folder 'set imap_user=\"$mwlogin\" imap_pass=\"\`pass $mwpass\`\"' set mbox_type = Maildir set ssl_starttls = yes @@ -195,9 +195,7 @@ EOF getpass fi getprofiles - mkdir -p "$mwmuttdir" "$mwaccdir" "$mwcachedir/$mwaccount/bodies" "$mwconfigdir/msmtp" - getaccounts - for x in $(seq 1 9); do echo "$accounts" | grep "$x": >/dev/null 2>&1 || { export idnum="$x"; break ;}; done + mkdir -p "$mwmuttdir" "$mwaccdir" "$mwcachedir/$mwaccount" "$mwconfigdir/msmtp" [ ! -f "$mwmsmtprc" ] && echo "$msmtp_header" > "$mwmsmtprc" echo "$msmtp_profile" >> "$mwmsmtprc" case "$mwservice" in @@ -205,17 +203,16 @@ EOF esac mkdir -p ${mwmbsyncrc%/*} echo "$mbsync_profile" >> "$mwmbsyncrc" - mwaccrc=$mwaccdir/$idnum-$mwaccount.muttrc + getaccounts + for x in $(seq 1 9); do echo "$accounts" | grep "$x": >/dev/null 2>&1 || { export idnum="$x"; break ;}; done + 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" 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 } @@ -274,6 +271,10 @@ finalize() { echo "$boxes" | grep -i spam | head -n 1 | formatShortcut S spam echo "$boxes" | grep -i junk | head -n 1 | formatShortcut j junk echo "$boxes" | grep -i archive | head -n 1 | formatShortcut a archive + idnum=${mwaccrc%%-*} + muttsync="source $mwaccrc\!;" + echo "folder-hook \$folder '$muttsync' # mw-autogenerated" >> "$mwaccrc" + echo "macro index,pager i$idnum $muttsync \"switch to $mwaddr\" # mw-autogenerated" >> "$mwaccrc" [ "$mwtype" = "offline" ] && printf "All done.\\n\033[33mYou can now run \`\033[32mmailsync [%s]\033[33m\` to sync your mail.\033[0m\\n" "$mwaccount" command -V urlview >/dev/null 2>&1 && [ ! -f "$HOME/.urlview" ] && echo "COMMAND \$BROWSER" > "$HOME/.urlview" return 0 @@ -297,7 +298,7 @@ mwpick() { mwdelete() { sed -i "/IMAPStore $mwaccount-remote$/,/# End profile/d" "$mwmbsyncrc" - rm -rf "${mwcachedir:?}/${mwaccount:?}" + rm -rf "$mwcachedir/$mwaccount" rm -rf "$mwaccdir/"[1-9]"-$mwaccount.muttrc" sed -i "/[0-9]-$mwaccount.muttrc/d" "$mwmuttrc" sed -i "/account $mwaccount/,/^\(\s*$\|account\)/d" "$mwmsmtprc" diff --git a/test/dotests b/test/dotests index a2bd649..28b46c9 100755 --- a/test/dotests +++ b/test/dotests @@ -6,7 +6,7 @@ echo bats --tap test_mw.bats echo -echo Integration Tests: +echo Integration tests with a working email: echo #modify @@ -20,10 +20,10 @@ fi cd .. && sudo make install rm -rf $mwmaildir/$mwaddr -export mwmaildir=\$MAILDIR +export mwmaildir=$MAILDIR export mwname='r n' export mwlogin=$mwaddr -export mwpass=mutt-wizard-$mwaddr +export mwpass="${mwpass:-mutt-wizard-$mwaddr} [ -f ~/.password-store/$mwpass.gpg ] || pass insert $mwpass echo "= manual test 1 ="