@@ -27,7 +27,7 @@ mwconfigdir=${XDG_CONFIG_HOME:-$HOME/.config}
# Main mutt config location
mwmuttdir="$mwconfigdir/mutt"
# Directory for account settings
mwaccrc dir="$mwmuttdir/accounts"
mwaccmutt dir="$mwmuttdir/accounts"
# Location of mail storage
mwmaildir="${MAILDIR:-${XDG_DATA_HOME:-$HOME/.local/share}/mail}"
# Regex to confirm valid email address
@@ -58,7 +58,7 @@ do
done || { echo "CA Certificate not found. Please install one or link it to /etc/ssl/certs/ca-certificates.crt" && exit 1 ;}
getaccounts() {
accounts="$(find "$mwaccrc dir" -type f | grep -o "[0-9]-.*.muttrc" | sed "s/-/: /;s/\.muttrc//" | sort -n)"
accounts="$(find "$mwaccmutt dir" -type f | grep -o "[0-9]-.*.muttrc" | sed "s/-/: /;s/\.muttrc//" | sort -n)"
}
mwlist() {
@@ -202,7 +202,7 @@ EOF
getpass
fi
getprofiles
mkdir -p "$mwmuttdir" "$mwaccrc dir" "$mwconfigdir/msmtp" "${mwmbsyncrc%/*}"
mkdir -p "$mwmuttdir" "$mwaccmutt dir" "$mwconfigdir/msmtp" "${mwmbsyncrc%/*}"
[ ! -f "$mwmsmtprc" ] && echo "$msmtp_header" > "$mwmsmtprc"
echo "$msmtp_profile" >> "$mwmsmtprc"
case "$mwservice" in
@@ -212,14 +212,14 @@ EOF
# new idnum = first one missing
getaccounts
for x in $(seq 1 9); do echo "$accounts" | grep "$x": >/dev/null 2>&1 || { export idnum="$x"; break ;}; done
mwaccrc="$mwaccrc dir/$idnum-$mwacc.muttrc"
echo "$mutt_profile" > "$mwaccrc"
mwaccmuttrc="$mwaccmutt dir/$idnum-$mwacc.muttrc"
echo "$mutt_profile" > "$mwaccmutt rc"
[ ! -f "$mwmuttrc" ] && echo "# vim: filetype=neomuttrc" > "$mwmuttrc" && echo "muttrc created."
! grep "source.*mutt-wizard.muttrc" "$mwmuttrc" >/dev/null && echo "source $mwsharerc # 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
! grep "^source.*$mwaccrc" "$mwmuttrc" >/dev/null && echo "source $mwaccrc # mw-autogenerated" >> "$mwmuttrc"
! grep "^source.*$mwaccmutt rc" "$mwmuttrc" >/dev/null && echo "source $mwaccmutt rc # mw-autogenerated" >> "$mwmuttrc"
return 0
}
@@ -233,12 +233,6 @@ getpass() {
while : ; do pass rm -f "$mwpass" >/dev/null 2>&1
pass insert "$mwpass" && break; done ;}
formatShortcut() {
while read -r data; do { echo "macro index,pager g$1 \"<change-folder>$data<enter>\" \"go to $2\" # mw-autogenerated"
echo "macro index,pager M$1 \"<save-message>$data<enter>\" \"move mail to $2\" # mw-autogenerated"
echo "macro index,pager C$1 \"<copy-message>$data<enter>\" \"copy mail to $2\" # mw-autogenerated"; } >> "$mwaccrc"
done
}
tryconnect() {
if [ -z "$mailboxes" ]; then
@@ -249,8 +243,19 @@ tryconnect() {
mailboxes="$($mbsyncbin -l $mwacc | sed 's/\//./')" >/dev/null 2>&1
fi
if [ -n "$mailboxes" ]; then
spoolfile=$(echo "$mailboxes" | grep -i -m 1 inbox | sed -ne 's/.*/+\0/p')
[ -z "$spoolfile" ] && return 1
#make directories
printf "\033[32mMailboxes detected.\033[0m\\n"
echo "$mailboxes" | xargs -I {} mkdir -p "$mwaccmaildir/{}"
echo "$mailboxes" | xargs -I {} mkdir -p "$mwaccmaildir/{}/"{cur,new,tmp}
record=$(echo "$mailboxes" | grep -i -m 1 sent | sed -ne 's/.*/+\0/p')
[ -z "$record" ] && mkdir -p "$mwaccmaildir/Sent/"{cur,new,tmp} && record="Sent"
postponed=$(echo "$mailboxes" | grep -i -m 1 draft | sed -ne 's/.*/+\0/p')
[ -z "$postponed" ] && mkdir -p "$mwaccmaildir/Drafts/"{cur,new,tmp} && postponed="Drafts"
trash=$(echo "$mailboxes" | grep -i -m 1 trash | sed -ne 's/.*/+\0/p')
[ -z "$trash" ] && mkdir -p "$mwaccmaildir/Trash/"{cur,new,tmp} && trash="Trash"
return 0
else
printf "\033[31m\033[31mLog-on not successful.\033[0m\\nIt seems that either you inputted the wrong password or server settings, or there are other requirements for your account out of the control of mutt-wizard.\\n"
@@ -258,41 +263,41 @@ tryconnect() {
fi
}
finalize() {
sed -i "/# mw-autogenerated/d" "$mwaccrc"
sed -i "/^mailboxes\|^set record\|^set postponed\|^set trash\|^set spoolfile/d" "$mwaccrc"
idnum=${mwaccrc%%-*}
idnum=${idnum##*/}
muttsync=$(printf '<sync-mailbox><enter-command>source %s<enter><change-folder>!<enter>;<check-stats>' $mwaccrc)
echo "macro index,pager i$idnum '$muttsync' \"switch to $mwaddr\" # mw-autogenerated" >> "$mwaccrc"
command -V urlview >/dev/null 2>&1 && [ ! -f "$HOME/.urlview" ] && echo "COMMAND \$BROWSER" > "$HOME/.urlview"
echo "folder-hook \$folder '$muttsync' # mw-autogenerated" >> "$mwaccrc"
boxes="$(find "$mwaccmaildir/" -mindepth 1 -maxdepth 1 | sed "s/\ /\\\ /g;s/^.*\//=/")"
if [ "$boxes" = "" ]; then
finalize() { # new mwaccmuttrc
idnum=${mwaccmuttrc%%-*}
idnum=${idnum##*/}
boxes="$(find "$mwaccmaildir/" -name cur | sed "s,$mwaccmaildir/,,g;s,/cur,,")"
if [[ "$boxes" =~ ^[[:space:]]*$ ]]; then
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" "$mwacc"
return
fi
printf "Setting default mailboxes for your Inbox, Sent, Drafts and Trash in mutt...\\n"
spoolfile=$(echo "$boxes" | grep -i -m 1 inbox | sed 's/=/+/g')
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')
cat >> "$mwaccrc" <<EOF
mwaccmutt="${email//[.@]/_}"
muttsync=$(printf '<sync-mailbox><enter-command>source %s<enter><change-folder>!<enter>;<check-stats>' $mwaccmuttrc)
cat >> "$mwaccmuttrc" <<EOF
set spoolfile = "$spoolfile"
set record = "$record"
set postponed = "$postponed"
set trash = "$trash"
folder-hook \$folder '$muttsync'
macro index,pager i$idnum '$muttsync' "switch to $email"
mailboxes =$mwaccmutt ===================== $(echo "$boxes" | sed -e "s/ //g;s/.*/\"=\0\"/g" | tr "\n" " ")
EOF
echo "mailboxes =$mwaccmutt ===================== $(echo "$boxes" | sed -e "s/^\|$/\"/g" | tr "\n" " ")" >> "$mwaccrc"
printf "Setting up your keyboard shortcuts for jumping between mailboxes...\\n"
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
echo "$boxes" | grep -i trash | head -n 1 | formatShortcut t trash
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
for eqbox in $boxes; do
box=${eqbox##*/}
box=${box##*.}
boxi=${box::2}
boxi=${boxi,,}
cat >> $mwaccmuttrc <<EOF
macro index,pager i$boxi "<change-folder>=$eqbox<enter>" "go to $box"
macro index,pager M$boxi "<save-message>=$eqbox<enter>" "move mail to $box"
macro index,pager C$boxi "<copy-message>=$eqbox<enter>" "copy mail to $box"
EOF
done
if [ "$mwtype" = "offline" ]; then
notmuchauto
printf "All done.\\n\033[33mYou can now run \`\033[32mmailsync [%s]\033[33m\` to sync your mail.\033[0m\\n" "$mwacc"
@@ -323,7 +328,7 @@ mwpick() {
mwdelete() {
sed -i "/IMAPStore $mwacc-remote$/,/# End profile/d" "$mwmbsyncrc"
rm -rf "$mwacccachedir"
rm -rf "$mwaccrc dir/"[1-9]"-$mwacc.muttrc"
rm -rf "$mwaccmutt dir/"[1-9]"-$mwacc.muttrc"
sed -i "/[0-9]-$mwacc.muttrc/d" "$mwmuttrc"
sed -i "/account $mwacc/,/^\(\s*$\|account\)/d" "$mwmsmtprc"
}
@@ -367,7 +372,7 @@ asktype() {
mwpurge() {
confirm "delete all account data" || exit
rm -rf "$mwmbsyncrc" "$mwaccrc dir" "$mwconfigdir/msmtp" "${mwmbsyncrc%/*}" "$mwcachedir"
rm -rf "$mwmbsyncrc" "$mwaccmutt dir" "$mwconfigdir/msmtp" "${mwmbsyncrc%/*}" "$mwcachedir"
pgrep cron >/dev/null && crontab -l | sed '/mailsync/d' | crontab - >/dev/null
sed -i "/\# mw-autogenerated/d" "$mwmuttrc"
echo "All configs and account settings have been purged."