mutt-wizard/bin/mw

347 lines
16 KiB
Plaintext
Raw Normal View History

2020-02-09 15:03:10 +01:00
#!/bin/sh
2019-05-04 15:50:15 +02:00
command -V gpg >/dev/null 2>&1 && GPG="gpg" || GPG="gpg2"
2019-06-02 04:13:06 +02:00
[ -z ${PASSWORD_STORE_DIR+x} ] && PASSWORD_STORE_DIR="$HOME/.password-store"
[ -r "$PASSWORD_STORE_DIR/.gpg-id" ] &&
"$GPG" --list-secret-keys $(cat "$PASSWORD_STORE_DIR/.gpg-id") >/dev/null 2>&1 || {
2020-02-29 12:01:54 +01:00
printf "\`pass\` must be installed and initialized to encrypt passwords.\\nBe sure it is installed and run \`pass init <yourgpgemail>\`.\\nIf you don't have a GPG public private key pair, run \`%s --full-gen-key\` first.\\n" "$GPG"
exit
}
! command -v mbsync >/dev/null && printf "\`mbsync (isync package)\` must be installed to run mutt-wizard.\\n" && exit
2019-05-04 22:47:01 +02:00
prefix="/usr/local"
2019-04-22 03:22:40 +02:00
muttdir="$HOME/.config/mutt" # Main mutt config location
2019-02-21 16:14:17 +01:00
accdir="$muttdir/accounts" # Directory for account settings
maildir="$HOME/.local/share/mail" # Location of mail storage
namere="^[a-z_][a-z0-9_-]*$" # Regex to ensure viable username
emailre=".+@.+\..+" # Regex to confirm valid email address
2019-05-04 22:47:01 +02:00
muttshare="$prefix/share/mutt-wizard"
2019-04-11 19:39:47 +02:00
mbsyncrc="$HOME/.mbsyncrc"
2019-04-26 02:27:49 +02:00
mwconfig="$muttshare/mutt-wizard.muttrc"
2019-04-22 21:12:03 +02:00
cachedir="$HOME/.cache/mutt-wizard"
2019-04-22 18:14:33 +02:00
muttrc="$muttdir/muttrc"
2019-05-02 03:02:17 +02:00
msmtprc="$HOME/.config/msmtp/config"
2019-04-26 15:42:16 +02:00
ssltype="IMAPS" # This is later changed to `None` later in the script if using Protonmail
2019-02-21 16:14:17 +01:00
for x in "/etc/ssl/certs/ca-certificates.crt" "/etc/pki/tls/certs/ca-bundle.crt" "/etc/ssl/ca-bundle.pem" "/etc/pki/tls/cacert.pem" "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem" "/etc/ssl/cert.pem" "/usr/local/share/ca-certificates/"
2019-04-25 21:35:48 +02:00
do
[ -f "$x" ] && sslcert="$x" && break
done || { echo "CA Certificate not found. Please install one or link it to /etc/ssl/certs/ca-certificates.crt" && exit 1 ;}
2019-04-23 05:47:41 +02:00
getaccounts() { accounts="$(find "$accdir" -type f | grep -o "[0-9]-.*.muttrc" | sed "s/-/: /;s/\..*//" | sort -n)" ;}
2019-04-22 19:11:27 +02:00
list() { getaccounts && [ -n "$accounts" ] && echo "$accounts" ;}
2019-04-22 18:43:42 +02:00
2019-02-21 16:14:17 +01:00
getprofiles() { \
2019-04-11 19:39:47 +02:00
unset msmtp_header msmtp_profile mutt_profile mbsync_profile
2019-02-22 18:25:37 +01:00
printf "Creating profiles for \`%s\`..." "$title"
2019-03-25 19:11:44 +01:00
msmtp_header="defaults
auth on
tls on
tls_trust_file $sslcert
logfile ~/.config/msmtp/msmtp.log
"
2019-04-26 15:42:16 +02:00
msmtp_profile="account $title
2019-03-25 19:11:44 +01:00
host $smtp
port $sport
2019-04-21 11:36:46 +02:00
from $fulladdr
user $login
2019-04-26 15:42:16 +02:00
passwordeval \"pass mutt-wizard-$title\"
2019-06-02 00:08:17 +02:00
$starttlsoff
2019-04-26 15:42:16 +02:00
"
2019-04-20 00:19:28 +02:00
mbsync_profile="IMAPStore $title-remote
2019-04-16 17:19:24 +02:00
Host $imap
Port $iport
User $login
2019-04-19 23:47:20 +02:00
PassCmd \"pass mutt-wizard-$title\"
AuthMechs LOGIN
2019-04-26 15:42:16 +02:00
SSLType $ssltype
2019-04-25 21:20:53 +02:00
CertificateFile $sslcert
2019-04-16 17:19:24 +02:00
MaildirStore $title-local
Subfolders Verbatim
Path ~/.local/share/mail/$title/
Inbox ~/.local/share/mail/$title/INBOX
2019-04-21 19:33:09 +02:00
Flatten .
2019-04-16 17:19:24 +02:00
Channel $title
2019-04-16 19:10:52 +02:00
Expunge Both
2019-04-16 17:19:24 +02:00
Master :$title-remote:
Slave :$title-local:
Patterns * !\"[Gmail]/All Mail\"
Create Both
SyncState *
2019-04-27 02:56:50 +02:00
MaxMessages $maxmes
2019-11-24 13:48:43 +01:00
ExpireUnread no
2019-04-20 00:59:09 +02:00
# End profile
"
2019-03-25 19:11:44 +01:00
if [ "$accounttype" = "offline" ]; then
mutt_profile="# vim: filetype=neomuttrc
# muttrc file for account $title
set realname = \"$realname\"
set from = \"$fulladdr\"
2019-04-26 03:43:41 +02:00
set sendmail = \"msmtp -a $title\"
2019-04-21 21:49:58 +02:00
alias me $realname <$fulladdr>
2019-03-25 19:11:44 +01:00
set folder = \"$maildir/$title\"
2019-04-22 22:21:21 +02:00
set header_cache = $cachedir/$title/headers
set message_cachedir = $cachedir/$title/bodies
2019-03-25 19:11:44 +01:00
set mbox_type = Maildir
2020-06-01 13:45:20 +02:00
2019-03-25 19:11:44 +01:00
bind index,pager gg noop
bind index,pager g noop
bind index,pager M noop
bind index,pager C noop
bind index gg first-entry
macro index o \"<shell-escape>mbsync -V $title<enter>\" \"run mbsync to sync $title\"
2019-03-25 19:11:44 +01:00
unmailboxes *
"
else
2019-02-21 16:14:17 +01:00
mutt_profile="# vim: filetype=neomuttrc
# muttrc file for account $title
set realname = \"$realname\"
set from = \"$fulladdr\"
set sendmail = \"msmtp -a $title\"
2019-04-21 21:49:58 +02:00
alias me $realname <$fulladdr>
set folder = \"imaps://$login@$imap:$iport\"
set imap_user = \"$login\"
2019-04-22 22:21:21 +02:00
set header_cache = $cachedir/$title/headers
set message_cachedir = $cachedir/$title/bodies
set imap_pass = \"\`pass mutt-wizard-$title\`\"
2019-02-21 16:14:17 +01:00
set mbox_type = Maildir
set ssl_starttls = yes
set ssl_force_tls = yes
bind index,pager gg noop
bind index,pager g noop
bind index,pager M noop
bind index,pager C noop
bind index gg first-entry
unmailboxes *
"
2019-03-25 19:11:44 +01:00
fi
2019-02-22 14:15:54 +01:00
printf "DONE.\\n"
2019-02-21 16:14:17 +01:00
}
2019-04-22 03:22:40 +02:00
askinfo() { \
2019-04-21 00:45:07 +02:00
printf "Insert the \033[31memail address\033[0m that you want to autoconfigure for mutt/mbsync\\n\tEmail: \033[36m"
2019-02-21 17:29:21 +01:00
read -r fulladdr
2019-02-22 19:14:38 +01:00
printf "\033[0m"
while ! echo "$fulladdr" | grep -E "$emailre" >/dev/null; do
2019-04-15 21:14:03 +02:00
printf "That is not a valid \033[31memail address\033[0m, please retype the desired email.\\n\\nEmail: \033[36m\t"
2019-02-21 17:29:21 +01:00
read -r fulladdr
2019-02-22 19:14:38 +01:00
printf "\033[0m"
2019-02-21 16:14:17 +01:00
done
domain="$(echo "$fulladdr" | sed "s/.*@//")"
search_query=$domain
case "$domain" in
protonmail.com|protonmail.ch|pm.me)
search_query='protonmail.com' ;;
*)
while : ; do
printf "\nIs your email hosted with Protonmail? [yes/no] "
read -r is_protonmail
case $is_protonmail in
[Yy][Ee][Ss]) search_query='protonmail.com' && break;;
[Nn][Oo]) break;;
*) printf 'Please answer Yes or No'
esac; done;
esac
2019-02-21 18:07:28 +01:00
printf "\\nSearching for \033[32m%s\033[0m in \033[34m\`domains.csv\`\033[0m..." "$domain"
serverinfo="$(grep "^$search_query" "$muttshare/domains.csv" 2>/dev/null)"
2020-08-27 22:46:36 +02:00
if [ -z "$serverinfo" ]; then
search_query=$(echo "$search_query" | sed "s/\.[^\.]*$/\.\\\*/")
serverinfo="$(grep "^$search_query" "$muttshare/domains.csv" 2>/dev/null)"
fi
2019-02-21 16:14:17 +01:00
if [ -z "$serverinfo" ]; then
2019-02-21 17:29:21 +01:00
printf "Your email domain is not in mutt-wizard's database yet.\\nmutt-wizard will still autoconfigure everything, but you will have to manually type in your service's IMAP and SMTP server information.\\nYou can usually quickly find this by internet searching for it.\\n"
2019-04-15 21:14:03 +02:00
printf "Insert the IMAP server for your email provider (excluding the port number)\\n\033[36m\t"
2019-02-21 17:29:21 +01:00
read -r imap
2019-04-15 21:14:03 +02:00
printf "\033[0mWhat is your server's IMAP port number? (Usually something like 993)\\n\033[36m\t"
2019-02-21 17:29:21 +01:00
read -r iport
2019-04-15 21:14:03 +02:00
printf "\033[0mInsert the SMTP server for your email provider (excluding the port number)\\n\033[36m\t"
2019-02-21 17:29:21 +01:00
read -r smtp
2019-04-15 21:14:03 +02:00
printf "\033[0mWhat is your server's SMTP port number? (Usually 587 or 465)\\n\033[36m\t"
2019-02-21 17:29:21 +01:00
read -r sport
2019-04-15 21:14:03 +02:00
printf "\033[0m\\nGreat! If you want to be helpful, copy the line below and you can add it to the \`domains.csv\` file on Github.\\nThis will make things easier for others who use your email provider.\\n\\n%s,%s,%s,%s,%s\\n\\nAlthough be sure to test to see if these settings work first! ;-)\\n" "$domain" "$imap" "$iport" "$smtp" "$sport"
2019-02-21 16:14:17 +01:00
else
2019-02-22 18:25:37 +01:00
IFS=, read -r service imap iport smtp sport <<EOF
2019-02-21 16:14:17 +01:00
$serverinfo
EOF
2019-04-27 01:26:57 +02:00
printf "\\n\033[3;33mCongrats!\033[0m Server info has automatically been found, so you won't have to look anything up!\\n\t\033[1mIMAP server\033[0m: %s\\n\t\033[1mIMAP port\033[0m: %s\\n\t\033[1mSMTP server\033[0m: %s\\n\t\033[1mSMTP port\033[0m: %s\\nThis data will be used by the wizard.\\n" "$imap" "$iport" "$smtp" "$sport"
case "$service" in
gmail.com) printf "\033[31mREMEMBER: Gmail users must enable \"less secure\" (third-party) applications first for the sync to work:\\nhttps://support.google.com/accounts/answer/6010255\\n\033[0m" ;;
2019-05-02 05:14:10 +02:00
protonmail.ch|protonmail.com|pm.me) printf "\033[31mREMEMBER: Protonmail users must install and configure Protonmail Bridge first for the sync to work:\\nhttps://protonmail.com/bridge/\\n\033[0m" && ssltype="None" ;;
esac
2019-06-02 00:08:17 +02:00
[ "$sport" = 465 ] && starttlsoff="tls_starttls off"
2019-02-21 16:14:17 +01:00
fi
2019-02-21 18:07:28 +01:00
printf "Enter the \033[35mfull name\033[0m you want to be identified by on this account.\\n\tReal name: "
2019-02-21 17:29:21 +01:00
read -r realname
2019-02-21 18:07:28 +01:00
printf "Enter a short, \033[36mone-word identifier\033[0m for this email account that will distinguish them from any other accounts you add.\\n\tAccount name: "
2019-02-21 17:29:21 +01:00
read -r title
2019-04-22 19:54:22 +02:00
while ! echo "$title" | grep "$namere" >/dev/null || ls "$accdir"/[0-9]"-$title.muttrc" >/dev/null 2>&1; do
printf "\033[31mTry again\033[0m. Pick a nickname that is one word only including lowercase letters and _ or - and that you have \033[1mnot\033[0m used before.\\n\tAccount name: \033[36m\t"
2019-02-21 17:29:21 +01:00
read -r title
2019-02-22 19:14:38 +01:00
printf "\033[0m"
2019-02-21 16:14:17 +01:00
done
2019-04-21 19:33:26 +02:00
printf "If your account has a special username different from your address, insert it now. Otherwise leave this prompt totally blank.\\n\033[34mMost accounts will not have a separate login, so you should probably leave this blank.\033[0m\\n\tLogin(?): \033[36m"
read -r login
printf "\033[0m"
[ -z "$login" ] && login="$fulladdr"
2019-04-27 02:56:50 +02:00
[ "$accounttype" = "offline" ] && printf "If you want to limit the number of messages kept offline to a number, enter that number below. If you do not want to limit your mail and would like \`mbsync\` to sync all mail, press enter without typing a number.\\n\t" && read -r maxmes
echo "$maxmes" | grep "[1-9]" >/dev/null || maxmes="0"
2019-02-22 19:14:38 +01:00
getpass
2019-02-21 16:14:17 +01:00
getprofiles
2019-04-23 13:05:38 +02:00
mkdir -p "$muttdir" "$accdir" "$cachedir/$title/bodies" "$HOME/.config/msmtp"
2019-04-22 21:36:56 +02:00
getaccounts
for x in $(seq 1 9); do echo "$accounts" | grep "$x" >/dev/null 2>&1 || { export idnum="$x"; break ;}; done
2019-05-02 03:02:17 +02:00
[ ! -f "$msmtprc" ] && echo "$msmtp_header" > "$msmtprc"
echo "$msmtp_profile" >> "$msmtprc"
2019-05-03 01:21:53 +02:00
command -V apt-get >/dev/null 2>&1 && ln -s "$msmtprc" "$HOME/.msmtprc" 2>/dev/null
2019-05-02 02:59:58 +02:00
case "$service" in
2019-05-02 05:14:10 +02:00
protonmail.ch|protonmail.com|pm.me) protonfinger || return 1 ;;
2019-05-02 02:59:58 +02:00
esac
2019-04-22 18:39:20 +02:00
echo "$mutt_profile" > "$accdir/$idnum-$title.muttrc"
echo "$mbsync_profile" >> "$mbsyncrc"
notmuchauto
2019-04-22 21:12:03 +02:00
[ ! -f "$muttrc" ] && echo "# vim: filetype=neomuttrc" > "$muttrc" && echo "muttrc created."
! grep "^source.*mutt-wizard.muttrc" "$muttrc" >/dev/null && echo "source $mwconfig # mw-autogenerated" >> "$muttrc"
2019-04-22 19:12:08 +02:00
! grep "^source.*.muttrc" "$muttrc" | grep -v "$mwconfig" >/dev/null && echo "source $accdir/$idnum-$title.muttrc # mw-autogenerated" >> "$muttrc"
2019-04-22 18:39:20 +02:00
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"
2019-02-21 16:14:17 +01:00
}
2019-05-02 02:59:58 +02:00
protonfinger() { printf "Getting Protonmail bridge fingerprint...\\n"
fingerprint="$(msmtp --serverinfo --host=127.0.0.1 --port=1025 --tls --tls-certcheck=off | grep SHA256: | sed 's/^.*: //')"
2019-05-04 15:50:22 +02:00
sed -ibu "s/account $title/&\ntls_trust_file\ntls_fingerprint $fingerprint/" "$msmtprc" ; rm -f "$msmtprc"bu
2019-05-02 02:59:58 +02:00
}
2019-04-21 20:30:34 +02:00
getpass() { while : ; do pass rm -f "mutt-wizard-$title" >/dev/null 2>&1
pass insert "mutt-wizard-$title" && break; done ;}
2019-02-21 16:14:17 +01:00
formatShortcut() { \
2019-04-22 18:14:33 +02:00
while read -r data; do { echo "macro index,pager g$1 \"<change-folder>$data<enter>\" \"go to $2\" # mw-autogenerated"
2019-12-01 16:14:31 +01:00
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"; } >> "$accdir/$idnum-$title.muttrc"
2019-02-21 16:14:17 +01:00
done ;}
2019-04-22 18:14:33 +02:00
tryconnect() { mkdir -p "$maildir/$title"
2019-04-24 14:48:08 +02:00
if mailboxes="$(mbsync -l "$title" | sed 's/\//./')" >/dev/null 2>&1 && [ -n "$mailboxes" ]; then
2019-04-26 18:12:03 +02:00
[ "$accounttype" = "online" ] && sed -ibu "/IMAPStore $title-remote$/,/# End profile/d" "$mbsyncrc" ; rm -f "$mbsyncrc"bu
2019-04-12 05:12:19 +02:00
printf "\033[32mMailboxes detected.\033[0m\\n"
echo "$mailboxes" | xargs -I {} mkdir -p "$maildir/$title/{}"
2019-04-23 05:59:43 +02:00
return 0
2019-02-21 18:41:48 +01:00
else
2019-04-26 15:29:49 +02:00
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"
2019-04-22 18:14:33 +02:00
return 1
2019-04-22 03:22:40 +02:00
fi ;}
2019-02-21 18:32:20 +01:00
2019-02-21 18:41:48 +01:00
finalize() { \
2020-02-09 13:49:12 +01:00
boxes="$(find "$maildir/$title/" -mindepth 1 -type d | sed "s/\ /\\\ /g;s/^.*\//=/;/=\(cur\|new\|tmp\)$/d")"
2019-04-11 19:39:47 +02:00
[ -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
2019-02-21 18:32:20 +01:00
printf "Setting default mailboxes for your Inbox, Sent, Drafts and Trash in mutt...\\n"
2019-04-22 19:12:17 +02:00
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')
2019-04-26 17:36:14 +02:00
sed -ibu "/^mailboxes\|^set record\|^set postponed\|^set trash\|^set spoolfile/d" "$accdir/$idnum-$title.muttrc" ; rm -f "$accdir/$idnum-$title.muttrcbu"
2019-04-22 19:12:08 +02:00
{ echo "set spoolfile = \"$spoolfile\""; echo "set record = \"$record\""; echo "set postponed = \"$postponed\""; echo "set trash = \"$trash\""; } >> "$accdir/$idnum-$title.muttrc"
2019-11-12 12:18:51 +01:00
echo "mailboxes $(echo "$boxes" | sed -e "s/^\|$/\"/g" | tr "\n" " ")" >> "$accdir/$idnum-$title.muttrc"
2019-02-21 18:32:20 +01:00
printf "Setting up your keyboard shortcuts for jumping between mailboxes...\\n"
2019-04-26 17:36:14 +02:00
sed -ibu "/# mw-autogenerated/d" "$accdir/$idnum-$title.muttrc" ; rm -f "$accdir/$idnum-$title.muttrcbu"
2019-04-26 17:20:26 +02:00
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
2019-04-20 04:52:31 +02:00
[ "$accounttype" = "offline" ] && printf "All done.\\n\033[33mYou should now be able to run \`\033[32mmbsync %s\033[33m\` to begin to download your mail.\033[0m\\n" "$title"
2019-05-03 01:04:54 +02:00
command -V urlview >/dev/null 2>&1 && [ ! -f "$HOME/.urlview" ] && echo "COMMAND \$BROWSER" > "$HOME/.urlview"
2019-04-23 05:59:43 +02:00
return 0
2019-02-21 16:14:17 +01:00
}
2020-02-09 14:18:32 +01:00
confirm() { printf "Do you want to %s? [yes/N]\\n\t" "$@" && read -r input && ! echo "$input" | grep -i "^yes$" >/dev/null && printf "That doesn't seem like a yes to me.\\n\\n" && return 1
printf "Are you really, really sure you want to %s?\\n\t" "$@" && read -r input && ! echo "$input" | grep -i "^yes$" >/dev/null && printf "That doesn't seem like a yes to me.\\n\\n" && return 1
2019-04-12 05:12:19 +02:00
return 0 ;}
2019-04-22 18:14:33 +02:00
pick() { printf "Select an accounts to %s:\\n" "$1"
list
2019-02-22 01:42:02 +01:00
read -r input
2019-02-22 18:25:37 +01:00
[ -z "$input" ] && return 1
2019-04-22 18:43:42 +02:00
title="$(echo "$accounts" | grep "$input" | awk '{print $2}')"
2019-02-22 13:40:43 +01:00
[ -z "$title" ] && printf "Invalid response." && return 1
2019-04-12 05:12:19 +02:00
return 0 ;}
2019-02-22 01:42:02 +01:00
2019-04-26 17:36:14 +02:00
delete() { sed -ibu "/IMAPStore $title-remote$/,/# End profile/d" "$mbsyncrc" ; rm -rf "$mbsyncrc"bu
2019-04-22 22:08:52 +02:00
rm -rf "${cachedir:?}/${title:?}" "$accdir/"[1-9]"-$title.muttrc"
2019-04-26 17:36:14 +02:00
sed -ibu "/[0-9]-$title.muttrc/d" "$muttrc" ; rm -f "$muttrc"bu
2019-05-02 03:02:17 +02:00
sed -ibu "/account $title/,/^\(\s*$\|account\)/d" "$msmtprc"; rm -f "$msmtprc"bu
2019-04-12 05:12:19 +02:00
}
2019-02-21 18:07:28 +01:00
2019-04-22 03:22:40 +02:00
asktype() { while : ; do
2019-04-21 00:45:07 +02:00
printf "Do you want to keep your mail for this account offline with mbsync? [yes/no]\\n\t"
2019-03-25 19:11:44 +01:00
read -r offnot
case "$offnot" in
2019-04-21 19:44:20 +02:00
[Yy][Ee][Ss]) accounttype="offline" && break ;;
[Nn][Oo]) accounttype="online" && break ;;
*) echo "Write out either yes or no completely. Try again or press ctrl-c to quit." ;;
2019-04-22 03:22:40 +02:00
esac; done ;}
2019-03-25 19:11:44 +01:00
2019-04-22 18:14:33 +02:00
purge() { confirm "delete all account data" || exit
2019-04-22 21:52:32 +02:00
rm -rf "$mbsyncrc" "$accdir" "$HOME/.config/msmtp" "$cachedir"
2019-04-22 18:14:33 +02:00
echo "All configs and account settings have been purged."
2019-04-26 17:36:14 +02:00
sed -ibu "/\# mw-autogenerated/d" "$muttrc" ; rm -f "$muttrc"bu
2019-04-22 03:22:40 +02:00
}
2019-03-25 19:11:44 +01:00
syncwrapper() { mbsync "${1:--a}" &
( kill -46 "$(pidof "${STATUSBAR:-dwmblocks}")" >/dev/null 2>&1 ) 2>/dev/null
wait
( kill -46 "$(pidof "${STATUSBAR:-dwmblocks}")" >/dev/null 2>&1 ) 2>/dev/null
notmuch new
}
notmuchauto() { \
[ -z "$NOTMUCH_CONFIG" ] && NOTMUCH_CONFIG="$HOME/.notmuch-config"
[ -f "$NOTMUCH_CONFIG" ] && return 0
nmbasic="[database]
path=$maildir
[user]
name=$realname
primary_email=$fulladdr
[new]
tags=unread;inbox;
ignore=.mbsyncstate;.uidvalidity
[search]
exclude_tags=deleted;spam;
[maildir]
synchronize_flags=true
[crypto]
2019-05-05 15:37:30 +02:00
gpg_path=$GPG"
echo "$nmbasic" > "$NOTMUCH_CONFIG" ;}
trap 'echo -e "\033[0m\n"; exit' INT ABRT
2019-04-22 03:22:40 +02:00
case "$1" in
2019-04-22 03:46:59 +02:00
ls) list ;;
2019-04-22 18:14:33 +02:00
add) asktype && askinfo && tryconnect && finalize || delete ;;
2019-04-22 03:46:59 +02:00
pass) pick "change the password of" && getpass ;;
2019-04-22 03:22:40 +02:00
delete) pick delete && confirm "delete the \`$title\` profile" && delete ;;
sync) syncwrapper $2 ;;
2019-04-22 18:14:33 +02:00
purge) purge ;;
2019-04-22 03:46:59 +02:00
*) cat << EOF
mw: mutt-wizard, auto-configure email accounts for mutt
2019-04-22 03:54:55 +02:00
including downloadable mail with \`isync\`.
2019-04-22 03:46:59 +02:00
Allowed options:
add Add and autoconfigure an email address (9 max.)
ls List configured accounts
delete Pick an account to delete
purge Delete all accounts and settings
sync Syncs mail and updates notmuch database
2019-04-22 03:46:59 +02:00
all else Print this message
2019-04-22 03:54:55 +02:00
NOTE: Once at least one account is added, you can run
\`mbsync -a\` to begin downloading mail.
2019-04-22 03:46:59 +02:00
EOF
2019-04-22 03:22:40 +02:00
esac