config

Personal configuration.
git clone git://code.dwrz.net/config
Log | Files | Refs

sync-email (631B)


      1 #!/usr/bin/env bash
      2 
      3 err() {
      4   echo "[$(date -u +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
      5 }
      6 
      7 main() {
      8   # Sync email.
      9   if ! mbsync -c "${XDG_CONFIG_HOME}/isync/mbsyncrc" -qqa ; then
     10     notify-send --urgency=low "sync-email" "failed to sync email"
     11   fi
     12 
     13   # Delete emails tagged as deleted or spam.
     14   notmuch search --output=files --format=text0 tag:deleted tag:spam | \
     15     xargs -r0 rm
     16 
     17   # Import new email into notmuch.
     18   notmuch new
     19 
     20   # Tag emails.
     21   tag-email
     22 
     23   # Notify unread count.
     24   unread="$(notmuch count tag:unread)"
     25   if [[ "${unread}" -gt 0 ]]; then
     26     notify-send "Email" "${unread} unread email(s)."
     27   fi
     28 }
     29 
     30 main "$@"