From fa436774b049dd09ce2af5daa777e6c28fb14405 Mon Sep 17 00:00:00 2001 From: rjl6789 Date: Mon, 8 Jun 2020 14:21:28 +0100 Subject: [PATCH] exclude folders that we do not want notifactions for exclude drafts, sent, trash etc from search for new mail. I still believe it's usefull to have a notification for all the folders except these. --- bin/mailsync | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bin/mailsync b/bin/mailsync index 489b47e..e04f025 100755 --- a/bin/mailsync +++ b/bin/mailsync @@ -1,7 +1,10 @@ #!/bin/sh + +# Sync mail and give notification if there is new mail. + MAILDIR="$HOME/.local/share/mail" SYNCSTAT="$HOME/.config/mutt/.mailsynclastrun" -# Sync mail and give notification if there is new mail. +FOLDEREXCLUDES='sent|drafts|bin|trash|spam|junk' # Run only if user logged in (prevent cron errors) pgrep -u "${USER:=$LOGNAME}" >/dev/null || { echo "$USER not logged in; sync will not run."; exit ;} @@ -32,7 +35,7 @@ fi syncandnotify() { acc="$(echo "$account" | sed "s/.*\///")" if [ -z "$opts" ]; then mbsync "$acc"; else mbsync "$opts" "$acc"; fi - folderlist="$(find "$MAILDIR"/"$acc"/*/new -type d 2>/dev/null | sed '/^\s*$/d')" + folderlist="$(find "$MAILDIR"/"$acc"/*/new -type d 2>/dev/null | sed '/^\s*$/d' | awk -v exclude=$FOLDEREXCLUDES 'BEGIN {IGNORECASE = 1} $0 !~ exclude')" for folder in $folderlist; do new="$(find "$folder" -type f -newer "$SYNCSTAT" 2> /dev/null)" newcount=$(echo "$new" | sed '/^\s*$/d' | wc -l)