| @@ -148,19 +148,17 @@ EOF | |||||
| read -r login | read -r login | ||||
| printf "\033[0m" | printf "\033[0m" | ||||
| [ -z "$login" ] && login="$fulladdr" | [ -z "$login" ] && login="$fulladdr" | ||||
| tmpdir="$(mktemp -d)" | |||||
| grep "i[0-9]" "$muttrc" 2>/dev/null | awk '{print $3}' | sed -e 's/i//g' > "$tmpdir/mutt_used" | |||||
| seq 1 9 > "$tmpdir/mutt_all" | |||||
| idnum=$(diff "$tmpdir/mutt_all" "$tmpdir/mutt_used" | sed -n 2p | awk '{print $2}') | |||||
| accounts="$(find "$accdir" -type f | grep -o "[0-9]-.*.muttrc" | sed "s/-/: /g;s/\..*//" | sort -n)" | |||||
| for x in $(seq 1 9); do echo "$accounts" | grep "$x" || { export idnum="$x"; break ;}; done | |||||
| getpass | getpass | ||||
| getprofiles | getprofiles | ||||
| mkdir -p "$accdir/$title/cache/bodies" "$HOME/.config/msmtp" | mkdir -p "$accdir/$title/cache/bodies" "$HOME/.config/msmtp" | ||||
| [ ! -f "$HOME/.config/msmtp/config" ] && echo "$msmtp_header" > "$HOME/.config/msmtp/config" | [ ! -f "$HOME/.config/msmtp/config" ] && echo "$msmtp_header" > "$HOME/.config/msmtp/config" | ||||
| echo "$msmtp_profile" >> "$HOME/.config/msmtp/config" | echo "$msmtp_profile" >> "$HOME/.config/msmtp/config" | ||||
| echo "$mutt_profile" > "$accdir/$title.muttrc" | |||||
| echo "$mutt_profile" > "$accdir/$idnum-$title.muttrc" | |||||
| echo "$mbsync_profile" >> "$mbsyncrc" | echo "$mbsync_profile" >> "$mbsyncrc" | ||||
| ! grep "^source.*.muttrc" "$muttrc" | grep -v "$mwconfig" >/dev/null && echo "source $accdir/$title.muttrc # mw-autogenerated" >> "$muttrc" | ! grep "^source.*.muttrc" "$muttrc" | grep -v "$mwconfig" >/dev/null && echo "source $accdir/$title.muttrc # mw-autogenerated" >> "$muttrc" | ||||
| echo "macro index,pager i$idnum '<sync-mailbox><enter-command>source $accdir/$title.muttrc<enter><change-folder>!<enter>;<check-stats>' \"switch to $fulladdr\" # mw-autogenerated" >> "$muttrc" | |||||
| echo "macro index,pager i$idnum '<sync-mailbox><enter-command>source $accdir/$idnum-$title.muttrc<enter><change-folder>!<enter>;<check-stats>' \"switch to $fulladdr\" # mw-autogenerated" >> "$muttrc" | |||||
| } | } | ||||
| getpass() { while : ; do pass rm -f "mutt-wizard-$title" >/dev/null 2>&1 | getpass() { while : ; do pass rm -f "mutt-wizard-$title" >/dev/null 2>&1 | ||||
| @@ -185,6 +183,7 @@ tryconnect() { mkdir -p "$maildir/$title" | |||||
| finalize() { \ | finalize() { \ | ||||
| boxes="$(du -a "$maildir/$title/"* -d 0 | sed "s/^.*\//=/")" | boxes="$(du -a "$maildir/$title/"* -d 0 | sed "s/^.*\//=/")" | ||||
| [ -z "$boxes" ] && printf "\033[31mNo local mailboxes have been detected for %s.\033[0m\\nThis means that mbsync has not been successfully run.\\nRun mbsync, and if it has an error, be sure to check your password and server settings manually if needbe.\\n" "$title" && return | [ -z "$boxes" ] && printf "\033[31mNo local mailboxes have been detected for %s.\033[0m\\nThis means that mbsync has not been successfully run.\\nRun mbsync, and if it has an error, be sure to check your password and server settings manually if needbe.\\n" "$title" && return | ||||
| tmpdir="$(mktemp -d)" | |||||
| echo "$boxes" > "$tmpdir/title_boxes" | echo "$boxes" > "$tmpdir/title_boxes" | ||||
| printf "Setting up the mutt sidebar...\\n" | printf "Setting up the mutt sidebar...\\n" | ||||
| sidebar_width="$(sed -n -e '/^set sidebar_width/p' "$muttdir/muttrc" | awk -F'=' '{print $2}')" | sidebar_width="$(sed -n -e '/^set sidebar_width/p' "$muttdir/muttrc" | awk -F'=' '{print $2}')" | ||||
| @@ -231,7 +230,7 @@ pick() { printf "Select an accounts to %s:\\n" "$1" | |||||
| return 0 ;} | return 0 ;} | ||||
| delete() { sed -i "/IMAPStore $title-remote$/,/# End profile/d" "$mbsyncrc" | delete() { sed -i "/IMAPStore $title-remote$/,/# End profile/d" "$mbsyncrc" | ||||
| rm -rf "${accdir:?}/${title:?}" "$accdir/$title.muttrc" | |||||
| rm -rf "${accdir:?}/${title:?}" "$accdir/[1-9]-$title.muttrc" | |||||
| sed -i "/$title.muttrc/d" "$muttrc" | sed -i "/$title.muttrc/d" "$muttrc" | ||||
| sed -i "/account $title/,/^\(\s*$\|account\)/d" "$HOME/.config/msmtp/config" | sed -i "/account $title/,/^\(\s*$\|account\)/d" "$HOME/.config/msmtp/config" | ||||
| } | } | ||||