summaryrefslogtreecommitdiff
path: root/bin/mw
diff options
context:
space:
mode:
authorLuke Smith <luke@lukesmith.xyz>2020-12-31 12:28:15 -0500
committerLuke Smith <luke@lukesmith.xyz>2020-12-31 12:28:15 -0500
commitf589cd4dfdd00f8521c09548b77cba6f995f89a5 (patch)
tree5e3b43faad468af8ce09e18e723d009d747fbd78 /bin/mw
parenta434ac50feb1f6e3142a18d5db0c22c8012cd05a (diff)
workable mailsync readded to enable autosync
the new script manually searches for environmental variables so that it can work from a cronjob and additionally searches for all Xorg displays on Linux so that the display notification should appear correctly no doubt there will be more bugs, but this is what the people want and it's worth working out
Diffstat (limited to 'bin/mw')
-rwxr-xr-xbin/mw46
1 files changed, 28 insertions, 18 deletions
diff --git a/bin/mw b/bin/mw
index a207d4e..f713761 100755
--- a/bin/mw
+++ b/bin/mw
@@ -21,7 +21,7 @@ cachedir="${XDG_CACHE_HOME:-$HOME/.cache}/mutt-wizard"
muttrc="$muttdir/muttrc"
msmtprc="${XDG_CONFIG_HOME:-$HOME/.config}/msmtp/config"
msmtplog="${XDG_CONFIG_HOME:-$HOME/.config}/msmtp/msmtp.log"
-MARKER="# mw-autogenerated"
+marker="# mw-autogenerated"
alias mbsync='mbsync -c "$mbsyncrc"'
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/"
@@ -151,7 +151,7 @@ delete() { if [ -z "${fulladdr+x}" ]; then
[ -z "$fulladdr" ] && echo "Invalid account name given." && return 1
- sed -ibu "/IMAPStore $fulladdr-remote$/,/# End profile/d" "$mbsyncrc" ; rm -rf "$mbsyncrc"bu
+ sed -ibu "/IMAPStore $fulladdr-remote$/,/# End profile/d" "$mbsyncrc" ; rm -f "$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
@@ -205,9 +205,9 @@ writeinfo() { mkdir -p "$muttdir" "$accdir" "$cachedir/$fulladdr/bodies" "${XDG_
# 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"
+ ! 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.
}
@@ -216,12 +216,12 @@ getpass() { while : ; do pass rm -f "$pass_prefix$fulladdr" >/dev/null 2>&1
pass insert "$pass_prefix$fulladdr" && break; done ;}
formatShortcut() { toappend="$toappend
-macro index,pager g$1 \"<change-folder>=$3<enter>\" \"go to $2\" $MARKER
-macro index,pager M$1 \";<save-message>=$3<enter>\" \"move mail to $2\" $MARKER
-macro index,pager C$1 \";<copy-message>=$3<enter>\" \"copy mail to $2\" $MARKER" >> "$accdir/$idnum-$fulladdr.muttrc" ;}
+macro index,pager g$1 \"<change-folder>=$3<enter>\" \"go to $2\" $marker
+macro index,pager M$1 \";<save-message>=$3<enter>\" \"move mail to $2\" $marker
+macro index,pager C$1 \";<copy-message>=$3<enter>\" \"copy mail to $2\" $marker" >> "$accdir/$idnum-$fulladdr.muttrc" ;}
setBox() { toappend="$toappend
-set $1 = \"+$2\" $MARKER" ;}
+set $1 = \"+$2\" $marker" ;}
getboxes() { [ -n "${force+x}" ] && mailboxes="INBOX
Drafts
@@ -239,7 +239,7 @@ Archive" && return 0
fi ;}
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"
+ sed -ibu "/$marker/d" "$accdir/$idnum-$fulladdr.muttrc" ; rm -f "$accdir/$idnum-$fulladdr.muttrcbu"
toappend="mailboxes $(echo "$mailboxes" | sed "s/^/\"=/;s/$/\"/" | paste -sd ' ' - )"
for x in $mailboxes; do
case "$x" in
@@ -257,12 +257,6 @@ 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 ;}
-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
@@ -282,6 +276,17 @@ synchronize_flags=true
gpg_path=$GPG"
echo "$nmbasic" > "$NOTMUCH_CONFIG" ;}
+togglecron() { cron="$(mktemp)"
+ crontab -l > "$cron"
+ if grep -q mailsync "$cron"; then
+ echo "Removing automatic mailsync..."
+ sed -ibu /mailsync/d "$cron"; rm -f "$cron"bu
+ else
+ echo "Adding automatic mailsync every ${cronmin:-10} minutes..."
+ echo "*/${cronmin-10} * * * * /usr/local/bin/mailsync" >> "$cron"
+ fi &&
+ crontab "$cron"; rm -f "$cron" ;}
+
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."
@@ -292,7 +297,7 @@ setact() { if [ -n "${action+x}" ] && [ "$action" != "$1" ]; then
trap 'echo -e "\033[0m\n"; exit' INT ABRT
-while getopts "fplhodYD:y:i:I:s:S:u:a:n:x:m:" o; do case "${o}" in
+while getopts "fplhodTYD:y:i:I:s:S:u:a:n:x:m:t:" o; do case "${o}" in
l) setact list || exit 1 ;;
d) setact delete || exit 1 ;;
D) setact delete || exit 1 ; fulladdr="$OPTARG" ;;
@@ -309,6 +314,8 @@ while getopts "fplhodYD:y:i:I:s:S:u:a:n:x:m:" o; do case "${o}" in
o) setact add || exit 1 ; online=True ;;
f) setact add || exit 1 ; force=True ;;
x) setact add || exit 1 ; password="$OPTARG" ;;
+ t) setact toggle || exit 1 ; cronmin="$OPTARG" ;;
+ T) setact toggle || exit 1 ;;
p) echo "NOTE: Protonmail users must install and configure Protonmail Bridge first for the first sync to work."
imap="127.0.0.1"
iport="1143"
@@ -329,6 +336,8 @@ Main actions:
-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
+ -t number Toggle automatic mailsync every <number> minutes
+ -T Toggle automatic mailsync
Options allowed with -a:
-u Account login name if not full address
@@ -357,5 +366,6 @@ case "$action" in
list) list ;;
add) askinfo && getprofiles && writeinfo && getboxes && finalize || { delete ; exit 1 ;} ;;
delete) delete $fulladdr ;;
- sync) syncwrapper $fulladdr ;;
+ sync) mailsync $fulladdr ;;
+ toggle) togglecron ;;
esac