rj1
log | files | refs

email-check (1150B) - raw


#!/bin/zsh
# source env vars for cronjob
source ~/.config/zsh/.zprofile

# get list of emails
source ~/.config/lieer/config.sh

for gmail in "${gmails[@]}"
do
  cd ~/mail/$gmail
  echo "checking ${gmail}"
  /usr/bin/gmi sync
done

# sync smtp mail if there's a parameter
/usr/bin/mbsync -c /home/rj1/.config/mbsync/config -aV

# add mail to notmuch db
/usr/bin/notmuch new

# do some filtering
# source ~/.config/email/filter.sh

# do some tagging
/usr/bin/notmuch tag +inbox -- tag:new
/usr/bin/notmuch tag +notify -- tag:new
/usr/bin/notmuch tag -new -- tag:new

# notify if there are new mails and notifications aren't muted
if [ -z "$MUTE_NOTIFICATIONS" ] || [ "$MUTE_NOTIFICATIONS" -eq 0 ]; then

  SEARCH="tag:notify"

  NOTIFY_COUNT=$(/usr/bin/notmuch count "$SEARCH")

  if [ "$NOTIFY_COUNT" -gt 0 ]; then
    RESULTS=$(/usr/bin/notmuch search --format=json --output=summary --limit=3 --sort="newest-first" "$SEARCH" | jq -r '.[] | "\(.authors): \(.subject)"')
    /usr/bin/notify-send "$NOTIFY_COUNT new mails:" "$RESULTS"
  fi

  /usr/bin/notmuch tag -notify -- tag:notify
fi

# refresh alot buffer if it's open
pkill --signal SIGUSR1 alot