Browse Source

3.0 release

tags/v3.1
Luke Smith 4 years ago
parent
commit
601d496fdf
No known key found for this signature in database GPG Key ID: 4C50B54A911F6252
3 changed files with 178 additions and 155 deletions
  1. +25
    -6
      README.md
  2. +100
    -132
      bin/mw
  3. +53
    -17
      mw.1

+ 25
- 6
README.md View File

@@ -27,12 +27,31 @@ User of Arch-based distros can also install mutt-wizard from the AUR as [mutt-wi


The mutt-wizard is run with the command `mw`. Once everything is setup, you'll use `neomutt` to access your mail. The mutt-wizard is run with the command `mw`. Once everything is setup, you'll use `neomutt` to access your mail.


- `mw add` -- add a new email account
- `mw ls` -- list existing accounts
- `mw pass` -- revise an account's password
- `mw delete` -- delete an added account
- `mw sync` -- sync all mail accounts and update notmuch database
- `mw purge` -- delete all accounts and settings
- `mw -a you@email.com` -- add a new email account
- `mw -l` -- list existing accounts
- `mw -y your@email.com` -- sync an email account
- `my -Y` -- sync all configured email accounts
- `mw -d` -- choose an account to delete
- `mw -D your@email.com` -- delete account settings without confirmation
- `pass edit mw-your@email.com` -- revise an account's password

### Options usable when adding an account

#### Providing arguments

- `-u` -- Give an account username if different from the email address. If you use my [emailwiz](https://github.com/lukesmithxyz/emailwiz), give your username with this option. Not necessary for other accounts.
- `-n` -- A real name to be used by the account. Put in quotations if multiple words
- `-i` -- IMAP server address
- `-I` -- IMAP server port (otherwise assumed to be 993)
- `-s` -- SMTP server address
- `-S` -- SMTP server port (otherwise assumed to be 587)
- `-m` -- Maximum number of emails to be kept offline. No maximum is default functionality.

#### General Settings

- `-p` -- Add a Protonmail account
- `-f` -- Assume mailbox names and force account configuration without connecting online at all.
- `-o` -- Configure mutt for an account, but do not keep mail offline.


## Dependencies ## Dependencies




+ 100
- 132
bin/mw View File

@@ -1,20 +1,5 @@
#!/bin/sh #!/bin/sh


debug() {
echo "fulladdr: $fulladdr"
echo "login: $login"
echo "title: $title"
echo "imap: $imap"
echo "iport: $iport"
echo "smtp: $smtp"
echo "sport: $sport"
echo "proton: $proton"
echo "tls: $tls"
echo "force: $force"
echo "online: $online"
echo "action: $action"
}

command -V gpg >/dev/null 2>&1 && GPG="gpg" || GPG="gpg2" command -V gpg >/dev/null 2>&1 && GPG="gpg" || GPG="gpg2"
[ -z ${PASSWORD_STORE_DIR+x} ] && PASSWORD_STORE_DIR="$HOME/.password-store" [ -z ${PASSWORD_STORE_DIR+x} ] && PASSWORD_STORE_DIR="$HOME/.password-store"
[ -r "$PASSWORD_STORE_DIR/.gpg-id" ] && [ -r "$PASSWORD_STORE_DIR/.gpg-id" ] &&
@@ -22,7 +7,6 @@ command -V gpg >/dev/null 2>&1 && GPG="gpg" || GPG="gpg2"
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" 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 exit
} }
! command -v mbsync >/dev/null && printf "\`mbsync (isync package)\` must be installed to run mutt-wizard.\\n" && exit


prefix="/usr/local" prefix="/usr/local"
pass_prefix="mw-" pass_prefix="mw-"
@@ -38,7 +22,6 @@ cachedir="${XDG_CACHE_HOME:-$HOME/.cache}/mutt-wizard"
muttrc="$muttdir/muttrc" muttrc="$muttdir/muttrc"
msmtprc="${XDG_CONFIG_HOME:-$HOME/.config}/msmtp/config" msmtprc="${XDG_CONFIG_HOME:-$HOME/.config}/msmtp/config"
msmtplog="${XDG_CONFIG_HOME:-$HOME/.config}/msmtp/msmtp.log" msmtplog="${XDG_CONFIG_HOME:-$HOME/.config}/msmtp/msmtp.log"
ssltype="IMAPS" # This is later changed to `None` later in the script if using Protonmail
MARKER="# mw-autogenerated" MARKER="# mw-autogenerated"
alias mbsync='mbsync -c "$mbsyncrc"' alias mbsync='mbsync -c "$mbsyncrc"'


@@ -47,63 +30,63 @@ do
[ -f "$x" ] && sslcert="$x" && break [ -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 ;} done || { echo "CA Certificate not found. Please install one or link it to /etc/ssl/certs/ca-certificates.crt" && exit 1 ;}


getaccounts() { accounts="$(find "$accdir" -type f | grep -o "[0-9]-.*.muttrc" | sed "s/-/: /;s/\..*//" | sort -n)" ;}
getaccounts() { accounts="$(find "$accdir" -type f | grep -o "[0-9]-.*.muttrc" | sed "s/-/: /;s/\.muttrc$//" | sort -n)" ;}

list() { getaccounts && [ -n "$accounts" ] && echo "$accounts" ;} list() { getaccounts && [ -n "$accounts" ] && echo "$accounts" ;}


getprofiles() { \ getprofiles() { \
unset msmtp_header msmtp_profile mutt_profile mbsync_profile unset msmtp_header msmtp_profile mutt_profile mbsync_profile
printf "Creating profiles for \`%s\`..." "$title"
msmtp_header="defaults msmtp_header="defaults
auth on auth on
tls on tls on
tls_trust_file $sslcert tls_trust_file $sslcert
logfile $msmtplog logfile $msmtplog
" "
msmtp_profile="account $title
msmtp_profile="account $fulladdr
host $smtp host $smtp
port ${sport:-587} port ${sport:-587}
from $fulladdr from $fulladdr
user $login user $login
passwordeval \"pass $pass_prefix$title\"
passwordeval \"pass $pass_prefix$fulladdr\"
$starttlsoff $starttlsoff
" "
mbsync_profile="IMAPStore $title-remote
mbsync_profile="IMAPStore $fulladdr-remote
Host $imap Host $imap
Port ${iport:-993} Port ${iport:-993}
User $login User $login
PassCmd \"pass $pass_prefix$title\"
PassCmd \"pass $pass_prefix$fulladdr\"
AuthMechs LOGIN AuthMechs LOGIN
SSLType $ssltype
SSLType ${ssltype:-IMAPS}
CertificateFile $sslcert CertificateFile $sslcert


MaildirStore $title-local
MaildirStore $fulladdr-local
Subfolders Verbatim Subfolders Verbatim
Path ${XDG_DATA_HOME:-$HOME/.local/share}/mail/$title/
Inbox ${XDG_DATA_HOME:-$HOME/.local/share}/mail/$title/INBOX
Path ${XDG_DATA_HOME:-$HOME/.local/share}/mail/$fulladdr/
Inbox ${XDG_DATA_HOME:-$HOME/.local/share}/mail/$fulladdr/INBOX
Flatten . Flatten .


Channel $title
Channel $fulladdr
Expunge Both Expunge Both
Master :$title-remote:
Slave :$title-local:
Master :$fulladdr-remote:
Slave :$fulladdr-local:
Patterns * !\"[Gmail]/All Mail\" Patterns * !\"[Gmail]/All Mail\"
Create Both Create Both
SyncState * SyncState *
MaxMessages $maxmes
MaxMessages ${maxmes:-0}
ExpireUnread no ExpireUnread no
# End profile # End profile
" "


if [ -z "${online+x}" ]; then if [ -z "${online+x}" ]; then
mutt_profile="# vim: filetype=neomuttrc mutt_profile="# vim: filetype=neomuttrc
# muttrc file for account $title
# muttrc file for account $fulladdr
set realname = \"$realname\" set realname = \"$realname\"
set from = \"$fulladdr\" set from = \"$fulladdr\"
set sendmail = \"msmtp -a $title\"
set sendmail = \"msmtp -a $fulladdr\"
alias me $realname <$fulladdr> alias me $realname <$fulladdr>
set folder = \"$maildir/$title\"
set header_cache = $cachedir/$title/headers
set message_cachedir = $cachedir/$title/bodies
set folder = \"$maildir/$fulladdr\"
set header_cache = $cachedir/$fulladdr/headers
set message_cachedir = $cachedir/$fulladdr/bodies
set mbox_type = Maildir set mbox_type = Maildir


bind index,pager gg noop bind index,pager gg noop
@@ -111,21 +94,21 @@ bind index,pager g noop
bind index,pager M noop bind index,pager M noop
bind index,pager C noop bind index,pager C noop
bind index gg first-entry bind index gg first-entry
macro index o \"<shell-escape>mbsync -V $title<enter>\" \"run mbsync to sync $title\"
macro index o \"<shell-escape>mbsync -V $fulladdr<enter>\" \"run mbsync to sync $fulladdr\"
unmailboxes * unmailboxes *
" "
else else
mutt_profile="# vim: filetype=neomuttrc mutt_profile="# vim: filetype=neomuttrc
# muttrc file for account $title
# muttrc file for account $fulladdr
set realname = \"$realname\" set realname = \"$realname\"
set from = \"$fulladdr\" set from = \"$fulladdr\"
set sendmail = \"msmtp -a $title\"
set sendmail = \"msmtp -a $fulladdr\"
alias me $realname <$fulladdr> alias me $realname <$fulladdr>
set folder = \"imaps://$login@$imap:${iport:-993}\" set folder = \"imaps://$login@$imap:${iport:-993}\"
set imap_user = \"$login\" set imap_user = \"$login\"
set header_cache = $cachedir/$title/headers
set message_cachedir = $cachedir/$title/bodies
set imap_pass = \"\`pass $pass_prefix$title\`\"
set header_cache = $cachedir/$fulladdr/headers
set message_cachedir = $cachedir/$fulladdr/bodies
set imap_pass = \"\`pass $pass_prefix$fulladdr\`\"


set mbox_type = Maildir set mbox_type = Maildir
set ssl_starttls = yes set ssl_starttls = yes
@@ -142,7 +125,10 @@ fi
printf "DONE.\\n" printf "DONE.\\n"
} }


parsedomains(){ serverinfo="$(grep "^${fulladdr#*@}" "$muttshare/domains.csv" 2>/dev/null)"
parsedomains(){ \
# Parses the domains.csv file for server information and sets
# the required variables unless overridden by the user.
serverinfo="$(grep "^${fulladdr#*@}" "$muttshare/domains.csv" 2>/dev/null)"


[ -z "$serverinfo" ] && [ -z "$serverinfo" ] &&
serverinfo="$(grep "$(echo "${fulladdr#*@}" | sed "s/\.[^\.]*$/\.\\\*/")" "$muttshare/domains.csv" 2>/dev/null)" serverinfo="$(grep "$(echo "${fulladdr#*@}" | sed "s/\.[^\.]*$/\.\\\*/")" "$muttshare/domains.csv" 2>/dev/null)"
@@ -156,39 +142,42 @@ EOF
iport="${iport:-$iportsugg}" iport="${iport:-$iportsugg}"
} }


delete() { if [ -z "${fulladdr+x}" ]; then
echo "Select the account your would like to delete (by number):"
list
read -r input
match="^$input:"
else
match=" $fulladdr$"
getaccounts
fi

fulladdr="$(echo "$accounts" | grep "$match" | cut -f2 -d' ')"

[ -z "$fulladdr" ] && echo "Invalid account name given." && return 1

sed -ibu "/IMAPStore $fulladdr-remote$/,/# End profile/d" "$mbsyncrc" ; rm -rf "$mbsyncrc"bu
rm -rf "${cachedir:?}/${fulladdr:?}" "$accdir/"[1-9]"-$fulladdr.muttrc"
sed -ibu "/[0-9]-$fulladdr.muttrc/d" "$muttrc" ; rm -f "$muttrc"bu
sed -ibu "/account $fulladdr/,/^\(\s*$\|account\)/d" "$msmtprc"; rm -f "$msmtprc"bu
}

askinfo() { \ askinfo() { \
[ -z "$fulladdr" ] && echo "Give the full email address to add:" && [ -z "$fulladdr" ] && echo "Give the full email address to add:" &&
read -r fulladdr read -r fulladdr

while ! echo "$fulladdr" | grep -qE "$emailre"; do while ! echo "$fulladdr" | grep -qE "$emailre"; do
echo "\`$fulladdr\` is not a valid email address. Please retype the address:" echo "\`$fulladdr\` is not a valid email address. Please retype the address:"
read -r fulladdr read -r fulladdr
done done

# If we don't have either the IMAP or SMTP servers, look for them and ports.
{ [ -z "$imap" ] || [ -z "$smtp" ] ;} && parsedomains { [ -z "$imap" ] || [ -z "$smtp" ] ;} && parsedomains
[ -z "$imap" ] && echo "Give your email server's IMAP address (excluding the port number):" &&
read -r imap
[ -z "$smtp" ] && echo "Give your email server's SMTP address (excluding the port number):" &&
read -r smtp
[ "$sport" = 465 ] && starttlsoff="tls_starttls off" [ "$sport" = 465 ] && starttlsoff="tls_starttls off"

[ -z "$realname" ] && echo "Give the name you would like to be identified by on the email account:" && [ -z "$realname" ] && echo "Give the name you would like to be identified by on the email account:" &&
read -r realname read -r realname

title="$fulladdr"
#while ! echo "$title" | grep -q "$namere" || 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"
#read -r title
#printf "\033[0m"
#done

[ -z "$login" ] && echo "Give the account log-on/username for this address:" && read -r login
login="${login:-$fulladdr}" login="${login:-$fulladdr}"



#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" ;;
#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

getpass getpass
} }


@@ -198,7 +187,7 @@ writeinfo() {
getprofiles getprofiles


# Create required directories. # Create required directories.
mkdir -p "$muttdir" "$accdir" "$cachedir/$title/bodies" "${XDG_CONFIG_HOME:-$HOME/.config}/msmtp" "$maildir/$title"
mkdir -p "$muttdir" "$accdir" "$cachedir/$fulladdr/bodies" "${XDG_CONFIG_HOME:-$HOME/.config}/msmtp" "$maildir/$fulladdr"


# Get accounts and find the first missing account number (max. 9). # Get accounts and find the first missing account number (max. 9).
getaccounts getaccounts
@@ -214,7 +203,7 @@ writeinfo() {
command -V apt-get >/dev/null 2>&1 && ln -s "$msmtprc" "$HOME/.msmtprc" 2>/dev/null command -V apt-get >/dev/null 2>&1 && ln -s "$msmtprc" "$HOME/.msmtprc" 2>/dev/null


# Create the individual mutt config file for the account. # Create the individual mutt config file for the account.
echo "$mutt_profile" > "$accdir/$idnum-$title.muttrc"
echo "$mutt_profile" > "$accdir/$idnum-$fulladdr.muttrc"


# Create the mbsync config file. # Create the mbsync config file.
mkdir -p "${mbsyncrc%/*}" mkdir -p "${mbsyncrc%/*}"
@@ -227,26 +216,21 @@ writeinfo() {
# and add the shortcuts to the account. # and add the shortcuts to the account.
[ ! -f "$muttrc" ] && echo "# vim: filetype=neomuttrc" > "$muttrc" && echo "muttrc created." [ ! -f "$muttrc" ] && echo "# vim: filetype=neomuttrc" > "$muttrc" && echo "muttrc created."
! grep -q "^source.*mutt-wizard.muttrc" "$muttrc" && echo "source $mwconfig $MARKER" >> "$muttrc" ! grep -q "^source.*mutt-wizard.muttrc" "$muttrc" && echo "source $mwconfig $MARKER" >> "$muttrc"
! grep "^source.*.muttrc" "$muttrc" | grep -qv "$mwconfig" && echo "source $accdir/$idnum-$title.muttrc $MARKER" >> "$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\" $MARKER" >> "$muttrc"

! grep "^source.*.muttrc" "$muttrc" | grep -qv "$mwconfig" && echo "source $accdir/$idnum-$fulladdr.muttrc $MARKER" >> "$muttrc"
echo "macro index,pager i$idnum '<sync-mailbox><enter-command>source $accdir/$idnum-$fulladdr.muttrc<enter><change-folder>!<enter>;<check-stats>' \"switch to $fulladdr\" $MARKER" >> "$muttrc"
} }


protonfinger() { printf "Getting Protonmail bridge fingerprint...\\n" 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/^.*: //')"
sed -ibu "s/account $title/&\ntls_trust_file\ntls_fingerprint $fingerprint/" "$msmtprc" ; rm -f "$msmtprc"bu
}
fingerprint="$(msmtp --serverinfo --host=$smtp --port=$sport --tls --tls-certcheck=off | grep SHA256: | sed 's/^.*: //')"
sed -ibu "s/account $fulladdr/&\ntls_trust_file\ntls_fingerprint $fingerprint/" "$msmtprc" ; rm -f "$msmtprc"bu ;}


getpass() { while : ; do pass rm -f "$pass_prefix$title" >/dev/null 2>&1
pass insert "$pass_prefix$title" && break; done ;}
getpass() { while : ; do pass rm -f "$pass_prefix$fulladdr" >/dev/null 2>&1
pass insert "$pass_prefix$fulladdr" && break; done ;}


formatShortcut() { toappend="$toappend formatShortcut() { toappend="$toappend
macro index,pager g$1 \"<change-folder>=$3<enter>\" \"go to $2\" $MARKER macro index,pager g$1 \"<change-folder>=$3<enter>\" \"go to $2\" $MARKER
getpass
macro index,pager M$1 \";<save-message>=$3<enter>\" \"move mail to $2\" $MARKER macro index,pager M$1 \";<save-message>=$3<enter>\" \"move mail to $2\" $MARKER
getpass
macro index,pager C$1 \";<copy-message>=$3<enter>\" \"copy mail to $2\" $MARKER" >> "$accdir/$idnum-$title.muttrc"
}
macro index,pager C$1 \";<copy-message>=$3<enter>\" \"copy mail to $2\" $MARKER" >> "$accdir/$idnum-$fulladdr.muttrc" ;}


setBox() { toappend="$toappend setBox() { toappend="$toappend
set $1 = \"+$2\" $MARKER" ;} set $1 = \"+$2\" $MARKER" ;}
@@ -254,73 +238,54 @@ set $1 = \"+$2\" $MARKER" ;}
getboxes() { [ -n "${force+x}" ] && mailboxes="INBOX getboxes() { [ -n "${force+x}" ] && mailboxes="INBOX
Drafts Drafts
Junk Junk
Trash
Sent Sent
Archive" && return 0 Archive" && return 0
if mailboxes="$(mbsync -l "$title" | sed 's/\//./')" >/dev/null 2>&1 && [ -n "$mailboxes" ]; then
[ "$accounttype" = "online" ] && sed -ibu "/IMAPStore $title-remote$/,/# End profile/d" "$mbsyncrc" ; rm -f "$mbsyncrc"bu
printf "\033[32mMailboxes detected.\033[0m\\n"
if mailboxes="$(mbsync -l "$fulladdr" | sed 's/\//./')" >/dev/null 2>&1 && [ -n "$mailboxes" ]; then
[ "$accounttype" = "online" ] && sed -ibu "/IMAPStore $fulladdr-remote$/,/# End profile/d" "$mbsyncrc" ; rm -f "$mbsyncrc"bu
return 0 return 0
else else
echo "$mailboxes"
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" 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"
return 1 return 1
fi ;} fi ;}


finalize() { \

# Create the required mailbox structure.
echo "$mailboxes" | xargs -I {} mkdir -p "$maildir/$title/{}"

printf "Setting default mailboxes for your Inbox, Sent, Drafts and Trash in mutt...\\n"

sed -ibu "/$MARKER/d" "$accdir/$idnum-$title.muttrc" ; rm -f "$accdir/$idnum-$title.muttrcbu"

finalize() { echo "$mailboxes" | xargs -I {} mkdir -p "$maildir/$fulladdr/{}/cur" "$maildir/$fulladdr/{}/tmp" "$maildir/$fulladdr/{}/new"
sed -ibu "/$MARKER/d" "$accdir/$idnum-$fulladdr.muttrc" ; rm -f "$accdir/$idnum-$fulladdr.muttrcbu"
toappend="mailboxes $(echo "$mailboxes" | sed "s/^/\"=/;s/$/\"/" | paste -sd ' ' )" toappend="mailboxes $(echo "$mailboxes" | sed "s/^/\"=/;s/$/\"/" | paste -sd ' ' )"

for x in $mailboxes; do for x in $mailboxes; do
case $x in case $x in
*[Ii][Nn][Bb][Oo][Xx]*) formatShortcut i inbox "$x"; setBox spoolfile "$x" ;; *[Ii][Nn][Bb][Oo][Xx]*) formatShortcut i inbox "$x"; setBox spoolfile "$x" ;;
*[Ss][Ee][Nn][Tt]*) setBox record "$x"; formatShortcut s sent "$x" ;; *[Ss][Ee][Nn][Tt]*) setBox record "$x"; formatShortcut s sent "$x" ;;
*[Dd][Rr][Aa][Ff][Tt][Ss]*) setBox postponed "$x"; formatShortcut d drafts "$x" ;; *[Dd][Rr][Aa][Ff][Tt][Ss]*) setBox postponed "$x"; formatShortcut d drafts "$x" ;;
*[Tt][Rr][Aa][Ss][Hh]*|*[Jj][Uu][Nn][Kk]*) formatShortcut t trash "$x"; setBox trash "$x" ;;
*[Tt][Rr][Aa][Ss][Hh]*) formatShortcut t trash "$x"; setBox trash "$x" ;;
*[Jj][Uu][Nn][Kk]*) formatShortcut j junk "$x" ;;
*[Aa][Rr][Cc][Hh][Ii][Vv][Ee]*) formatShortcut a archive "$x" ;; *[Aa][Rr][Cc][Hh][Ii][Vv][Ee]*) formatShortcut a archive "$x" ;;
*[Ss][Pp][Aa][Mm]*) formatShortcut S spam "$x" ;; *[Ss][Pp][Aa][Mm]*) formatShortcut S spam "$x" ;;
esac esac
done done

echo "$toappend" >> "$accdir/$idnum-$title.muttrc"

[ -z "${online+x}" ] && 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"

# Create a urlview config file if non-existent.
echo "$toappend" >> "$accdir/$idnum-$fulladdr.muttrc"
[ -z "${online+x}" ] && printf "\033[33mYou should now be able to run \`\033[32mw -y %s\033[33m\` to begin to download your mail.\033[0m\\n" "$fulladdr"
command -V urlview >/dev/null 2>&1 && [ ! -f "$HOME/.urlview" ] && echo "COMMAND \$BROWSER" > "$HOME/.urlview" command -V urlview >/dev/null 2>&1 && [ ! -f "$HOME/.urlview" ] && echo "COMMAND \$BROWSER" > "$HOME/.urlview"

return 0
}
return 0 ;}


confirm() { printf "Do you want to %s? [yes/N]\\n\t" "$@" && read -r input && ! echo "$input" | grep -qi "^yes$" && printf "That doesn't seem like a yes to me.\\n\\n" && return 1 confirm() { printf "Do you want to %s? [yes/N]\\n\t" "$@" && read -r input && ! echo "$input" | grep -qi "^yes$" && 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 -qi "^yes$" && 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 -qi "^yes$" && printf "That doesn't seem like a yes to me.\\n\\n" && return 1
return 0 ;} return 0 ;}


pick() { printf "Select an accounts to %s:\\n" "$1"
pick() { [ -n "${fulladdr+x}" ] && return 0
echo "Select the account your would like to $1 (by number):"
list list
read -r input read -r input
[ -z "$input" ] && return 1
title="$(echo "$accounts" | grep "$input" | awk '{print $2}')"
[ -z "$title" ] && printf "Invalid response." && return 1
fulladdr="$(echo "$accounts" | grep "^$input:" | cut -f2 -d' ')"
[ -z "$fulladdr" ] && echo "Invalid response." && return 1
return 0 ;} return 0 ;}


delete() { sed -ibu "/IMAPStore $title-remote$/,/# End profile/d" "$mbsyncrc" ; rm -rf "$mbsyncrc"bu
rm -rf "${cachedir:?}/${title:?}" "$accdir/"[1-9]"-$title.muttrc"
sed -ibu "/[0-9]-$title.muttrc/d" "$muttrc" ; rm -f "$muttrc"bu
sed -ibu "/account $title/,/^\(\s*$\|account\)/d" "$msmtprc"; rm -f "$msmtprc"bu
}

syncwrapper() { mbsync "${1:--a}" & syncwrapper() { mbsync "${1:--a}" &
( kill -46 "$(pidof "${STATUSBAR:-dwmblocks}")" >/dev/null 2>&1 ) 2>/dev/null ( kill -46 "$(pidof "${STATUSBAR:-dwmblocks}")" >/dev/null 2>&1 ) 2>/dev/null
wait wait
( kill -46 "$(pidof "${STATUSBAR:-dwmblocks}")" >/dev/null 2>&1 ) 2>/dev/null ( kill -46 "$(pidof "${STATUSBAR:-dwmblocks}")" >/dev/null 2>&1 ) 2>/dev/null
notmuch new
}
notmuch new ;}


purge() { confirm "delete all account data" || exit purge() { confirm "delete all account data" || exit
rm -rf "$mbsyncrc" "$accdir" "${XDG_CONFIG_HOME:-$HOME/.config}/msmtp" "$cachedir" rm -rf "$mbsyncrc" "$accdir" "${XDG_CONFIG_HOME:-$HOME/.config}/msmtp" "$cachedir"
@@ -357,48 +322,47 @@ setaction() { if [ -n "${action+x}" ] && [ "$action" != "$1" ]; then
action="$1" action="$1"
fi; } fi; }


while getopts "gbpPlhdYD:y:i:I:s:S:u:a:" o; do case "${o}" in
while getopts "fplhdYD:y:i:I:s:S:u:a:n:" o; do case "${o}" in
l) setaction list || exit 1 ;; l) setaction list || exit 1 ;;
p) setaction pass || exit 1 ;;
d) setaction delete || exit 1 ;; d) setaction delete || exit 1 ;;
D) setaction delete || exit 1 ; title="$OPTARG" ;;
y) setaction sync || exit 1 ; title="$OPTARG" ;;
D) setaction delete || exit 1 ; fulladdr="$OPTARG" ;;
y) setaction sync || exit 1 ; fulladdr="$OPTARG" ;;
Y) setaction sync || exit 1 ;; Y) setaction sync || exit 1 ;;

a) setaction add || exit 1 ; fulladdr="$OPTARG" ;; a) setaction add || exit 1 ; fulladdr="$OPTARG" ;;
i) setaction add || exit 1 ; imap="$OPTARG" ;; i) setaction add || exit 1 ; imap="$OPTARG" ;;
I) setaction add || exit 1 ; iport="$OPTARG" ;; I) setaction add || exit 1 ; iport="$OPTARG" ;;
s) setaction add || exit 1 ; smtp="$OPTARG" ;; s) setaction add || exit 1 ; smtp="$OPTARG" ;;
S) setaction add || exit 1 ; sport="$OPTARG" ;; S) setaction add || exit 1 ; sport="$OPTARG" ;;
u) setaction add || exit 1 ; login="$OPTARG" ;; u) setaction add || exit 1 ; login="$OPTARG" ;;

n) setaction add || exit 1 ; realname="$OPTARG" ;;
m) setaction add || exit 1 ; maxmes="$OPTARG" ;;
o) setaction add || exit 1 ; online=True ;; o) setaction add || exit 1 ; online=True ;;
b) setaction add || exit 1 ; force=True ;;
P) echo "NOTE: Protonmail users must install and configure Protonmail Bridge first for the first sync to work."
f) setaction add || exit 1 ; force=True ;;
p) echo "NOTE: Protonmail users must install and configure Protonmail Bridge first for the first sync to work."
proton=True proton=True
imap="127.0.0.1" imap="127.0.0.1"
iport=1143
iport="1143"
smtp="127.0.0.1" smtp="127.0.0.1"
sport=1025
sport="1025"
ssltype="None"
protonfinger
setaction add || exit 1 setaction add || exit 1
;; ;;

g) debug ;;

*) cat << EOF *) cat << EOF
mw: mutt-wizard, auto-configure email accounts for mutt mw: mutt-wizard, auto-configure email accounts for mutt
including downloadable mail with \`isync\`. including downloadable mail with \`isync\`.


Main actions: Main actions:
-a your@email.com Add an email address -a your@email.com Add an email address
-d Remove an already added address
-D nameofaccount Force remove account without confirmation
-l List email addresses configured -l List email addresses configured
-y nameofaccount Sync mail for account by name
-d Remove an already added address
-D your@email.com Force remove account without confirmation
-y your@email.com Sync mail for account by name
-Y Sync mail for all accounts -Y Sync mail for all accounts


Options allowed with -a: Options allowed with -a:
-u Account login name if not full address. -u Account login name if not full address.
-n "Real name" to be on the email account.
-i IMAP server address -i IMAP server address
-I IMAP server port -I IMAP server port
-s SMTP server address -s SMTP server address
@@ -409,15 +373,19 @@ Options allowed with -a:


NOTE: Once at least one account is added, you can run NOTE: Once at least one account is added, you can run
\`mbsync -a\` to begin downloading mail. \`mbsync -a\` to begin downloading mail.

To chane an account's password, run \`pass edit ${pass_prefix}your@email.com\`.
EOF EOF
exit 1
;; ;;
esac done esac done


! command -v mbsync >/dev/null && [ -z "${force+x}" ] && printf "\`mbsync (isync package)\` must be installed to run mutt-wizard.\\n" && exit

case "$action" in case "$action" in
list) list ;; list) list ;;
add) askinfo && writeinfo && getboxes && finalize || delete ;; add) askinfo && writeinfo && getboxes && finalize || delete ;;
pass) pick "change the password of" && getpass ;;
delete) pick delete && confirm "delete the \`$title\` profile" && delete ;;
sync) syncwrapper $title ;;
delete) delete $fulladdr ;;
sync) syncwrapper $fulladdr ;;
purge) purge ;; purge) purge ;;
esac esac

+ 53
- 17
mw.1 View File

@@ -3,7 +3,9 @@
mw \- mutt-wizard \- autoconfigure email accounts for neomutt and isync mw \- mutt-wizard \- autoconfigure email accounts for neomutt and isync
.SH SYNOPSIS .SH SYNOPSIS
.B mw .B mw
<command>
[
.I OPTIONS
]
.SH DESCRIPTION .SH DESCRIPTION
.B mw .B mw
takes a user email account and sets up a terminal-based email interface for it with takes a user email account and sets up a terminal-based email interface for it with
@@ -16,22 +18,58 @@ for sending mail, and also passwords automatically encrypted and stored with
.B pass. .B pass.
.SH COMMANDS .SH COMMANDS
.TP .TP
.B add
configure an email account
.B -a your@email.com
add an email address
.TP .TP
.B ls
.B -l
list all email accounts configured by mutt-wizard list all email accounts configured by mutt-wizard
.TP .TP
.B delete
delete the configuration files for an already configured email account
.B -d
pick an already configured account and remove its configuration
.TP .TP
.B purge
totally purge all local mutt-wizard accounts
.B -D your@email.com
remove a configured account without confirmation
.TP .TP
.B sync
sync mail accounts then update notmuch database
.B mailsync
as often as you wish
.B -y your@email.com
download and upload mail for an email account
.TP
.B -Y
sync all email accounts
.SH OPTIONS FOR ADDING ACCOUNTS
These can be specified on the command line, otherwise, you will be prompted for what is necessary. mutt-wizard knows the IMAP/SMTP server information for most email providers, so specifying them is usually redundant.
.TP
.B -u billy
Account logon/username if required and different from email address.
.TP
.B -n Billy
Real name which will appear in emails. Should be put in quotes if multiple words.
.TP
.B -m number
Set a maximum number of messages to be stored offline.
.TP
.B -i
IMAP server address
.TP
.B -I
IMAP server port (assumed to be 993 if not specified)
.TP
.B -s
SMTP server address
.TP
.B -S
SMTP server port (assumed to be 587 if not specified)
.SH OTHER OPTIONS
.TP
.B -f
Force account creation and guess mailboxes without attempting to connect to server. Otherwise if connection cannot be made, the configured account settings will not be persistent.
.TP
.B -o
Create settings for an account to be used online only without mail syncing abilities. Without
.B -f
connection will still be attempted in setup to discover mailboxes.
.TP
.B -p
Add a Protonmail account. Protonmail Bridge must be installed and set up.
.SH DETAILS .SH DETAILS
.TP .TP
.B Mail location .B Mail location
@@ -52,11 +90,9 @@ and can be edited by the user if needbe. Note that the mutt-wizard will also sou
file. file.
.TP .TP
.B Mail deletion .B Mail deletion
Neither
.B delete
or
.B purge
will delete downloaded mail for safety (and time)'s sake. If you want to delete downloaded mail, do so manually by removing it from the directory above.
mutt-wizard's delete action will delete configuration files and
.I not
downloaded mail for safety (and time)'s sake. If you want to delete downloaded mail, do so manually by removing it from the directory above.
.TP .TP
.B Default settings .B Default settings
The mutt-wizard has many default settings that focus on making it aesthetically pleasing and supplying more vim-like bindings. These can be found in The mutt-wizard has many default settings that focus on making it aesthetically pleasing and supplying more vim-like bindings. These can be found in


Loading…
Cancel
Save