diff options
-rw-r--r-- | README.md | 1 | ||||
-rwxr-xr-x | bin/mw | 126 | ||||
-rw-r--r-- | mw.1 | 3 | ||||
-rw-r--r-- | share/mutt-wizard.muttrc | 2 |
4 files changed, 54 insertions, 78 deletions
@@ -46,6 +46,7 @@ The mutt-wizard is run with the command `mw`. Once everything is setup, you'll u - `-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. +- `-x` -- Account password. You will be prompted for it otherwise. #### General Settings @@ -94,7 +94,7 @@ 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 $fulladdr<enter>\" \"run mbsync to sync $fulladdr\" +macro index o \"<shell-escape>mw -y $fulladdr<enter>\" \"run mbsync to sync $fulladdr\" unmailboxes * " else @@ -122,25 +122,20 @@ bind index gg first-entry unmailboxes * " fi - printf "DONE.\\n" } -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)" +parsedomains(){ serverinfo="$(grep "^${fulladdr#*@}" "$muttshare/domains.csv" 2>/dev/null)" - [ -z "$serverinfo" ] && - serverinfo="$(grep "$(echo "${fulladdr#*@}" | sed "s/\.[^\.]*$/\.\\\*/")" "$muttshare/domains.csv" 2>/dev/null)" + [ -z "$serverinfo" ] && serverinfo="$(grep "$(echo "${fulladdr#*@}" | sed "s/\.[^\.]*$/\.\\\*/")" "$muttshare/domains.csv" 2>/dev/null)" - IFS=, read -r service imapsugg iportsugg smtpsugg sportsugg <<EOF + IFS=, read -r service imapsugg iportsugg smtpsugg sportsugg <<EOF $serverinfo EOF - imap="${imap:-$imapsugg}" - smtp="${smtp:-$smtpsugg}" - sport="${sport:-$sportsugg}" - iport="${iport:-$iportsugg}" - } + imap="${imap:-$imapsugg}" + smtp="${smtp:-$smtpsugg}" + sport="${sport:-$sportsugg}" + iport="${iport:-$iportsugg}" +} delete() { if [ -z "${fulladdr+x}" ]; then echo "Select the account your would like to delete (by number):" @@ -160,7 +155,8 @@ delete() { if [ -z "${fulladdr+x}" ]; then 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 - } + pass rm -f "$pass_prefix$fulladdr" >/dev/null 2>&1 +} askinfo() { \ [ -z "$fulladdr" ] && echo "Give the full email address to add:" && @@ -178,46 +174,40 @@ askinfo() { \ [ -z "$realname" ] && echo "Give the name you would like to be identified by on the email account:" && read -r realname login="${login:-$fulladdr}" - getpass + if [ -n "${password+x}" ]; then + createpass + else + getpass + fi } +createpass() { echo "$password" > "$PASSWORD_STORE_DIR/$pass_prefix$fulladdr" + "$GPG" -qer "$(cat "$PASSWORD_STORE_DIR/.gpg-id")" "$PASSWORD_STORE_DIR/$pass_prefix$fulladdr" + rm -f "$PASSWORD_STORE_DIR/$pass_prefix$fulladdr" ;} -writeinfo() { - # Insert account information into variables. - getprofiles - - # Create required directories. - mkdir -p "$muttdir" "$accdir" "$cachedir/$fulladdr/bodies" "${XDG_CONFIG_HOME:-$HOME/.config}/msmtp" "$maildir/$fulladdr" +writeinfo() { 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). - getaccounts - for x in $(seq 1 9); do echo "$accounts" | grep -q "$x" || { export idnum="$x"; break ;}; done + getaccounts; for x in $(seq 1 9); do echo "$accounts" | grep -q "$x" || { export idnum="$x"; break ;}; done - # Create msmtprc file if not present. + # Configure msmtprc for sending mail. [ ! -f "$msmtprc" ] && echo "$msmtp_header" > "$msmtprc" - - # Add account msmtp settings. echo "$msmtp_profile" >> "$msmtprc" - # On Ubuntu/Debian, a link is needed since they use an older version. 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. - echo "$mutt_profile" > "$accdir/$idnum-$fulladdr.muttrc" - # Create the mbsync config file. mkdir -p "${mbsyncrc%/*}" echo "$mbsync_profile" >> "$mbsyncrc" - # Create a notmuch config file if not present already. - notmuchauto - - # Create a basic muttrc is not present and source the mutt-wizard files - # and add the shortcuts to the account. - [ ! -f "$muttrc" ] && echo "# vim: filetype=neomuttrc" > "$muttrc" && echo "muttrc created." + # Create a muttrc for viewing mail. + echo "$mutt_profile" > "$accdir/$idnum-$fulladdr.muttrc" + [ ! -f "$muttrc" ] && echo "# vim: filetype=neomuttrc" > "$muttrc" ! grep -q "^source.*mutt-wizard.muttrc" "$muttrc" && echo "source $mwconfig $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" + + notmuchauto # Create a notmuch config file if not present already. } protonfinger() { printf "Getting Protonmail bridge fingerprint...\\n" @@ -269,30 +259,12 @@ finalize() { echo "$mailboxes" | xargs -I {} mkdir -p "$maildir/$fulladdr/{}/cur command -V urlview >/dev/null 2>&1 && [ ! -f "$HOME/.urlview" ] && echo "COMMAND \$BROWSER" > "$HOME/.urlview" 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 - 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 ;} - -pick() { [ -n "${fulladdr+x}" ] && return 0 - echo "Select the account your would like to $1 (by number):" - list - read -r input - fulladdr="$(echo "$accounts" | grep "^$input:" | cut -f2 -d' ')" - [ -z "$fulladdr" ] && echo "Invalid response." && return 1 - return 0 ;} - 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 ;} -purge() { confirm "delete all account data" || exit - rm -rf "$mbsyncrc" "$accdir" "${XDG_CONFIG_HOME:-$HOME/.config}/msmtp" "$cachedir" - echo "All configs and account settings have been purged." - sed -ibu "/$MARKER/d" "$muttrc" ; rm -f "$muttrc"bu -} - notmuchauto() { \ [ -z "$NOTMUCH_CONFIG" ] && NOTMUCH_CONFIG="$HOME/.notmuch-config" [ -f "$NOTMUCH_CONFIG" ] && return 0 @@ -312,9 +284,7 @@ synchronize_flags=true gpg_path=$GPG" echo "$nmbasic" > "$NOTMUCH_CONFIG" ;} -trap 'echo -e "\033[0m\n"; exit' INT ABRT - -setaction() { if [ -n "${action+x}" ] && [ "$action" != "$1" ]; then +setact() { if [ -n "${action+x}" ] && [ "$action" != "$1" ]; then echo "Running $1 with $action..." echo "Incompatible options given. Only one action may be specified per run." return 1 @@ -322,22 +292,25 @@ setaction() { if [ -n "${action+x}" ] && [ "$action" != "$1" ]; then action="$1" fi; } -while getopts "fplhdYD:y:i:I:s:S:u:a:n:" o; do case "${o}" in - l) setaction list || exit 1 ;; - d) setaction delete || exit 1 ;; - D) setaction delete || exit 1 ; fulladdr="$OPTARG" ;; - y) setaction sync || exit 1 ; fulladdr="$OPTARG" ;; - Y) setaction sync || exit 1 ;; - a) setaction add || exit 1 ; fulladdr="$OPTARG" ;; - i) setaction add || exit 1 ; imap="$OPTARG" ;; - I) setaction add || exit 1 ; iport="$OPTARG" ;; - s) setaction add || exit 1 ; smtp="$OPTARG" ;; - S) setaction add || exit 1 ; sport="$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 ;; - f) setaction add || exit 1 ; force=True ;; +trap 'echo -e "\033[0m\n"; exit' INT ABRT + +while getopts "fplhdYD:y:i:I:s:S:u:a:n:x:" o; do case "${o}" in + l) setact list || exit 1 ;; + d) setact delete || exit 1 ;; + D) setact delete || exit 1 ; fulladdr="$OPTARG" ;; + y) setact sync || exit 1 ; fulladdr="$OPTARG" ;; + Y) setact sync || exit 1 ;; + a) setact add || exit 1 ; fulladdr="$OPTARG" ;; + i) setact add || exit 1 ; imap="$OPTARG" ;; + I) setact add || exit 1 ; iport="$OPTARG" ;; + s) setact add || exit 1 ; smtp="$OPTARG" ;; + S) setact add || exit 1 ; sport="$OPTARG" ;; + u) setact add || exit 1 ; login="$OPTARG" ;; + n) setact add || exit 1 ; realname="$OPTARG" ;; + m) setact add || exit 1 ; maxmes="$OPTARG" ;; + o) setact add || exit 1 ; online=True ;; + f) setact add || exit 1 ; force=True ;; + x) setact add || exit 1 ; password="$OPTARG" ;; p) echo "NOTE: Protonmail users must install and configure Protonmail Bridge first for the first sync to work." proton=True imap="127.0.0.1" @@ -346,7 +319,7 @@ while getopts "fplhdYD:y:i:I:s:S:u:a:n:" o; do case "${o}" in sport="1025" ssltype="None" protonfinger - setaction add || exit 1 + setact add || exit 1 ;; *) cat << EOF mw: mutt-wizard, auto-configure email accounts for mutt @@ -384,8 +357,7 @@ esac done case "$action" in list) list ;; - add) askinfo && writeinfo && getboxes && finalize || delete ;; + add) askinfo && getprofiles && writeinfo && getboxes && finalize || delete ;; delete) delete $fulladdr ;; sync) syncwrapper $fulladdr ;; - purge) purge ;; esac @@ -58,6 +58,9 @@ SMTP server address .TP .B -S SMTP server port (assumed to be 587 if not specified) +.TP +.B -x +Account password. You will be prompted for the password interactively if this option is not given. .SH OTHER OPTIONS .TP .B -f diff --git a/share/mutt-wizard.muttrc b/share/mutt-wizard.muttrc index 57df579..de169db 100644 --- a/share/mutt-wizard.muttrc +++ b/share/mutt-wizard.muttrc @@ -80,7 +80,7 @@ set sidebar_width = 20 set sidebar_short_path = yes set sidebar_next_new_wrap = yes set mail_check_stats -set sidebar_format = '%B%?F? [%F]?%* %?N?%N/? %?S?%S?' +set sidebar_format = '%D%?F? [%F]?%* %?N?%N/? %?S?%S?' bind index,pager \Ck sidebar-prev bind index,pager \Cj sidebar-next bind index,pager \Co sidebar-open |