mutt-wizard

fork of Luke Smiths mutt-wizard
git clone git://git.jakekoroman.com/mutt-wizard
Log | Files | Refs | README | LICENSE

commit 35ddd7d71b7a8676f74c2627f2aa3bb7455a7c95
parent 8a2a7821a207cffb6d7804df2263d0d5b107e250
Author: Luke Smith <luke@lukesmith.xyz>
Date:   Fri,  4 May 2018 13:10:21 -0700

update of mailsync script with dunst support

Diffstat:
M.gitignore | 1+
Aetc/email.gif | 0
Metc/mailsync.sh | 37+++++++++++++++----------------------
3 files changed, 16 insertions(+), 22 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -5,3 +5,4 @@ accounts/ personal.muttrc thunderbird/ autoconf/log +etc/mailsynclastrun diff --git a/etc/email.gif b/etc/email.gif Binary files differ. diff --git a/etc/mailsync.sh b/etc/mailsync.sh @@ -7,39 +7,32 @@ # # I have this run as a cronjob every 5 minutes. -# Check for internet connection. Exit script if none. (timeout in mac is `-t`) +export DISPLAY=:0.0 + +# Checks for internet connection and set notification script. +# Settings are different for MacOS (Darwin) systems. if [ "$(uname)" == "Darwin" ] then ping -q -t 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` >/dev/null || exit + notify() { osascript -e "display notification \"$2 in $1\" with title \"Youve got Mail\" subtitle \"Account: $account\"" && sleep 2 ;} else ping -q -w 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` >/dev/null || exit + notify() { pgrep -x dunst && notify-send -i ~/.config/mutt/etc/email.gif "$2 new mail(s) in \`$1\` account." ;} fi -# Get current number of new mail, then begin sync. -ori=$(find ~/.mail -wholename '*/new/*' | grep -vi "spam\|trash\|junk" | wc -l) +# Run offlineimap. You can feed this script different settings. offlineimap -o "$@" -# Recount new mail. -new=$(find ~/.mail -wholename '*/new/*' | grep -vi "spam\|trash\|junk" | wc -l) - -# If new mail has grown, play a notification. -if [ "$new" -gt "$ori" ]; then - mpv --quiet ~/.config/mutt/etc/notify.opus -fi - +# Check all accounts/mailboxes for new mail. Notify if there is new content. for account in $(ls ~/.mail) do - for mailbox in $(ls ~/.mail/$account/) - do - #List unread messages newer than last mailsync and count them - newcount=$(find ~/.mail/$account/$mailbox/new/ -type f -newer ~/.config/mutt/etc/mailsynclastrun 2> /dev/null | wc -l) - #Pop a Mac style notification with the count for that mailbox - if [ "$(uname)" == "Darwin" -a "$newcount" -gt "0" ] - then - osascript -e "display notification \"$newcount in $mailbox\" with title \"Youve got Mail\" subtitle \"Account: $account\"" - sleep 2 - fi - done + #List unread messages newer than last mailsync and count them + newcount=$(find ~/.mail/$account/INBOX/new/ -type f -newer ~/.config/mutt/etc/mailsynclastrun 2> /dev/null | wc -l) + if [ "$newcount" -gt "0" ] + then + notify "$account" "$newcount" & disown + mpv --quiet ~/.config/mutt/etc/notify.opus + fi done #Create a touch file that indicates the time of the last run of mailsync