diff --git a/bin/mw b/bin/mw index cb65be3..4a9970d 100755 --- a/bin/mw +++ b/bin/mw @@ -125,22 +125,18 @@ 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 < "$msmtprc" @@ -205,8 +200,7 @@ writeinfo() { mkdir -p "$muttdir" "$accdir" "$cachedir/$fulladdr/bodies" "${XDG_ ! grep "^source.*.muttrc" "$muttrc" | grep -qv "$mwconfig" && echo "source $accdir/$idnum-$fulladdr.muttrc $MARKER" >> "$muttrc" echo "macro index,pager i$idnum 'source $accdir/$idnum-$fulladdr.muttrc!;' \"switch to $fulladdr\" $MARKER" >> "$muttrc" - # Create a notmuch config file if not present already. - notmuchauto + notmuchauto # Create a notmuch config file if not present already. } protonfinger() { printf "Getting Protonmail bridge fingerprint...\\n" @@ -283,9 +277,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 @@ -293,22 +285,24 @@ setaction() { if [ -n "${action+x}" ] && [ "$action" != "$1" ]; then action="$1" fi; } +trap 'echo -e "\033[0m\n"; exit' INT ABRT + 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 ;; + 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 ;; 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" @@ -317,7 +311,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