summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/mailsync67
-rwxr-xr-xbin/mw17
-rw-r--r--mailsync.118
-rw-r--r--share/mailcap1
4 files changed, 48 insertions, 55 deletions
diff --git a/bin/mailsync b/bin/mailsync
index 4fb79b6..daa4ecf 100755
--- a/bin/mailsync
+++ b/bin/mailsync
@@ -43,10 +43,10 @@ case "$(uname)" in
# remember if a display server is running since `ps` doesn't always contain a display
pgrepoutput="$(pgrep -ax X\(\|org\|wayland\))"
displays="$(echo "$pgrepoutput" | grep -wo "[0-9]*:[0-9]\+" | sort -u)"
- [ -z $displays ] && [ -d /tmp/.X11-unix ] && displays=$(cd /tmp/.X11-unix && for x in X*; do echo ":${x#X}"; done)
+ [ -z "$displays" ] && [ -d /tmp/.X11-unix ] && displays=$(cd /tmp/.X11-unix && for x in X*; do echo ":${x#X}"; done)
notify() { [ -n "$pgrepoutput" ] && for x in ${displays:-0:}; do
- export DISPLAY=$x
+ export DISPLAY="$x"
notify-send --app-name="mutt-wizard" "New mail!" "📬 $2 new mail(s) in \`$1\` account."
done ;}
;;
@@ -54,55 +54,42 @@ esac
# Check account for new mail. Notify if there is new content.
syncandnotify() {
- acc="$(echo "$account" | sed "s/.*\///")"
- if [ "$1" = "pop" ]; then
- # Handle POP
- mpop "$acc"
- else
- # Handle IMAP
- if [ -z "$opts" ]; then mbsync "$acc"; else mbsync "$opts" "$acc"; fi
- fi
+ case "$1" in
+ imap) mbsync -q "$2" ;;
+ pop) mpop -q "$2" ;;
+ esac
new=$(find\
- "$HOME/.local/share/mail/$acc/"[Ii][Nn][Bb][Oo][Xx]/new/ \
- "$HOME/.local/share/mail/$acc/"[Ii][Nn][Bb][Oo][Xx]/cur/ \
+ "$HOME/.local/share/mail/$2/"[Ii][Nn][Bb][Oo][Xx]/new/ \
+ "$HOME/.local/share/mail/$2/"[Ii][Nn][Bb][Oo][Xx]/cur/ \
-type f -newer "$lastrun" 2> /dev/null)
newcount=$(echo "$new" | sed '/^\s*$/d' | wc -l)
[ -z "$MAILSYNC_MUTE" ] && case 1 in
- $((newcount > 0)) ) notify "$acc" "$newcount" ;;
+ $((newcount > 0)) ) notify "$2" "$newcount" ;;
esac
}
-# Sync accounts passed as argument or all.
-if [ "$#" -gt "0" ]; then
- for arg in "$@"; do
- [ "${arg%${arg#?}}" = '-' ] && opts="${opts:+${opts} }${arg}" && shift 1
- done
- accounts=$*
+allaccounts="$(grep -hs "^\(Channel\|account\)" "$MBSYNCRC" "$MPOPRC")"
+
+# Get accounts to sync. All if no argument. Prefix with `error` if non-existent.
+IFS='
+'
+if [ -z "$1" ]; then
+ tosync="$allaccounts"
+else
+ tosync="$(for arg in "$@"; do for availacc in $allaccounts; do
+ [ "$arg" = "${availacc##* }" ] && echo "$availacc" && break
+ done || echo "error $arg"; done)"
fi
-[ -z "$imap_accounts" ] && [ -r "$MBSYNCRC" ] && imap_accounts="$(awk '/^Channel/ {print $2}' "$MBSYNCRC" 2>/dev/null)"
-[ -z "$pop_accounts" ] && [ -r "$MPOPRC" ] && pop_accounts="$(awk '/^account/ {print $2}' "$MPOPRC" 2>/dev/null)"
-
-# Parallelize multiple accounts
-for account in $imap_accounts; do
- if [ -n "$accounts" ]; then
- for tmp_ac in $accounts; do
- [ "$tmp_ac" = "$account" ] && syncandnotify "imap" &
- done
- continue
- fi
- syncandnotify "imap" &
-done
-for account in $pop_accounts; do
- if [ -n "$accounts" ]; then
- for tmp_ac in $accounts; do
- [ "$tmp_ac" = "$account" ] && syncandnotify "pop" &
- done
- continue
- fi
- syncandnotify "pop" &
+for account in $tosync; do
+ case $account in
+ Channel*) syncandnotify imap "${account##* }" & ;;
+ account*) syncandnotify pop "${account##* }" & ;;
+ error*) echo "ERROR: Account ${account##* } not found." ;;
+ esac
done
+
wait
notmuch new --quiet
diff --git a/bin/mw b/bin/mw
index 2ab0a68..96cf327 100755
--- a/bin/mw
+++ b/bin/mw
@@ -214,6 +214,21 @@ createpass() { echo "$password" > "$PASSWORD_STORE_DIR/$passprefix$fulladdr"
"$GPG" -qe $(printf -- " -r %s" $(cat "$PASSWORD_STORE_DIR/.gpg-id")) "$PASSWORD_STORE_DIR/$passprefix$fulladdr"
rm -f "$PASSWORD_STORE_DIR/$passprefix$fulladdr" ;}
+errorexit() {
+ echo "Log-on not successful."
+ case "$imap" in
+ imap.gmail.com)
+ echo "This account with $service is using Google's Gmail servers, which disable all third-party applications without an application-specific password.
+Please be sure you are using OAUTH with your Gmail account, or better yet, stop using Gmail."
+ ;;
+ imap.mail.me.com)
+ echo "This account with $service is using Apple's iCloud servers, which disable all non-Apple applications by default.
+Please be sure you either enable third-party applications, or create an app-specific password, or best of all, stop using Apple."
+ ;;
+ esac
+ exit 1
+ }
+
getpass() { while : ; do pass rm -f "$passprefix$fulladdr" >/dev/null 2>&1
pass insert -f "$passprefix$fulladdr" && break; done ;}
@@ -221,7 +236,7 @@ getboxes() { if [ -n "${force+x}" ] ; then
mailboxes="$(printf "INBOX\\nDrafts\\nJunk\\nTrash\\nSent\\nArchive")"
else
info="$(curl --location-trusted -s -m 5 --user "$login:$(pass "$passprefix$fulladdr")" --url "${protocol:-imaps}://$imap:${iport:-993}")"
- [ -z "$info" ] && echo "Log-on not successful." && return 1
+ [ -z "$info" ] && errorexit
mailboxes="$(echo "$info" | grep -v HasChildren | sed "s/.*\" //;s/\"//g" | tr -d '\r')"
fi
[ "$type" = "pop" ] && mailboxes="INBOX"
diff --git a/mailsync.1 b/mailsync.1
index a4aa50f..236a418 100644
--- a/mailsync.1
+++ b/mailsync.1
@@ -18,14 +18,11 @@ or if account names are given, syncs only those accounts.
.B
mailsync
-can also pass on options to
-.B
-mbsync,
-which it uses to sync mail.
-.B
-mailsync
is a wrapper for
-.B mbsync,
+.B mbsync
+and
+.B
+mpop,
but also automatically reindexes new mail with
.B notmuch,
gives notifications if new mail is found and can also be set as a cronjob to sync and index mail quietly in the background.
@@ -38,13 +35,6 @@ sync all mail accounts and notify user if there is new mail
only sync the
.B account@example.org
account.
-.TP
-.B
--*
-See the
-.B
-mbsync
-manual for additional options that can be used.
.SH AUTHORS
Written by Luke Smith <luke@lukesmith.xyz> originally in 2018.
.SH LICENSE
diff --git a/share/mailcap b/share/mailcap
index 0829b3b..601419c 100644
--- a/share/mailcap
+++ b/share/mailcap
@@ -7,3 +7,4 @@ audio/*; mpv %s ;
application/pdf; /usr/local/lib/mutt-wizard/openfile %s ;
application/pgp-encrypted; gpg -d '%s'; copiousoutput;
application/pgp-keys; gpg --import '%s'; copiousoutput;
+application/x-subrip; $EDITOR %s ;