Browse Source

more

tags/v3.1
Luke Smith 4 years ago
parent
commit
c08cfd5365
No known key found for this signature in database GPG Key ID: 4C50B54A911F6252
2 changed files with 11 additions and 41 deletions
  1. +10
    -40
      bin/mw
  2. +1
    -1
      share/mutt-wizard.muttrc

+ 10
- 40
bin/mw View File

@@ -94,7 +94,7 @@ 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 $fulladdr<enter>\" \"run mbsync to sync $fulladdr\"
macro index o \"<shell-escape>mw -y $fulladdr<enter>\" \"run mbsync to sync $fulladdr\"
unmailboxes * unmailboxes *
" "
else else
@@ -182,42 +182,31 @@ askinfo() { \
} }




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). # Get accounts and find the first missing account number (max. 9).
getaccounts getaccounts
for x in $(seq 1 9); do echo "$accounts" | grep -q "$x" || { export idnum="$x"; break ;}; done 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" [ ! -f "$msmtprc" ] && echo "$msmtp_header" > "$msmtprc"

# Add account msmtp settings.
echo "$msmtp_profile" >> "$msmtprc" echo "$msmtp_profile" >> "$msmtprc"

# On Ubuntu/Debian, a link is needed since they use an older version. # 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 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. # Create the mbsync config file.
mkdir -p "${mbsyncrc%/*}" mkdir -p "${mbsyncrc%/*}"
echo "$mbsync_profile" >> "$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 -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" ! 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" 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"

# Create a notmuch config file if not present already.
notmuchauto
} }


protonfinger() { printf "Getting Protonmail bridge fingerprint...\\n" protonfinger() { printf "Getting Protonmail bridge fingerprint...\\n"
@@ -269,30 +258,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" 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
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}" & 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
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() { \ notmuchauto() { \
[ -z "$NOTMUCH_CONFIG" ] && NOTMUCH_CONFIG="$HOME/.notmuch-config" [ -z "$NOTMUCH_CONFIG" ] && NOTMUCH_CONFIG="$HOME/.notmuch-config"
[ -f "$NOTMUCH_CONFIG" ] && return 0 [ -f "$NOTMUCH_CONFIG" ] && return 0
@@ -384,8 +355,7 @@ esac done


case "$action" in case "$action" in
list) list ;; list) list ;;
add) askinfo && writeinfo && getboxes && finalize || delete ;;
add) askinfo && getprofiles && writeinfo && getboxes && finalize || delete ;;
delete) delete $fulladdr ;; delete) delete $fulladdr ;;
sync) syncwrapper $fulladdr ;; sync) syncwrapper $fulladdr ;;
purge) purge ;;
esac esac

+ 1
- 1
share/mutt-wizard.muttrc View File

@@ -80,7 +80,7 @@ set sidebar_width = 20
set sidebar_short_path = yes set sidebar_short_path = yes
set sidebar_next_new_wrap = yes set sidebar_next_new_wrap = yes
set mail_check_stats 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 \Ck sidebar-prev
bind index,pager \Cj sidebar-next bind index,pager \Cj sidebar-next
bind index,pager \Co sidebar-open bind index,pager \Co sidebar-open


Loading…
Cancel
Save