From d5c97e78d80177119421f9dade324b04f2b00126 Mon Sep 17 00:00:00 2001 From: Yaroslav Date: Thu, 9 Apr 2020 01:30:04 +0300 Subject: mail scripts for aerc+mbsync; goodbye neomutt --- dotfiles/.local/bin/mailsync | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 dotfiles/.local/bin/mailsync (limited to 'dotfiles/.local/bin/mailsync') diff --git a/dotfiles/.local/bin/mailsync b/dotfiles/.local/bin/mailsync new file mode 100755 index 0000000..9da6270 --- /dev/null +++ b/dotfiles/.local/bin/mailsync @@ -0,0 +1,43 @@ +#!/bin/sh +# Sync mail and give notification if there is new mail. + +# Run only if user logged in (prevent cron errors) +w | grep "^$USER\W" >/dev/null || exit + +# Check several times before giving up, useful when just waking up from sleep +# since internet is usually not available right away +wget -q --tries=5 --timeout=20 --spider 1.1.1.1 > /dev/null || exit + +# Source the needed env variables so that it can function properly from cron +. ~/.cache/sessionenv + +thereis=0 + +# Run mbsync. You can feed this script different settings. +if [ $# -eq 0 ]; then + mbsync -a +else + mbsync "$@" +fi + +# Check all accounts/mailboxes for new mail. Notify if there is new content. +for mailbox in "$HOME/.local/share/mail/"* +do + account="$(echo "$mailbox" | sed "s/.*\///")" + newcount=$(find "$HOME/.local/share/mail/$account/INBOX/new/" "$HOME/.local/share/mail/$account/Inbox/new/" "$HOME/.local/share/mail/$account/inbox/new/" -type f -newer "$HOME/.cache/lastmailsync" 2> /dev/null | wc -l) + if [ "$newcount" -gt "0" ]; then + notify-send "📬 Email" "$newcount new mail(s) in \`$account\` mailbox." + thereis=1 + fi +done + +if [ $thereis = 1 ]; then + mpv "$HOME/.local/share/soundalerts/mail.mp3" > /dev/null + killall -42 waybar +fi + +notmuch new 2>/dev/null + +# Create a touch file that indicates the time of the last run of mailsync +touch "$HOME/.cache/lastmailsync" + -- cgit v1.2.3