Browse Source

place iX macro inside the account rc

pull/276/head
Roland Puntaier 5 years ago
parent
commit
c05076903d
4 changed files with 17 additions and 16 deletions
  1. +0
    -1
      README.md
  2. +2
    -1
      bin/mailsync
  3. +12
    -11
      bin/mw
  4. +3
    -3
      test/dotests

+ 0
- 1
README.md View File

@@ -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`

+ 2
- 1
bin/mailsync View File

@@ -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


+ 12
- 11
bin/mw View File

@@ -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 '<shell-escape>mailsync -Va<enter>' \"sync all mail\" # mw-autogenerated" >> "$mwmuttrc"
fi
muttsync="<sync-mailbox><enter-command>source $mwaccrc<enter><change-folder>\!<enter>;<check-stats>"
! 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="<sync-mailbox><enter-command>source $mwaccrc<enter><change-folder>\!<enter>;<check-stats>"
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"


+ 3
- 3
test/dotests View File

@@ -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 ="


Loading…
Cancel
Save