Browse Source

notification of new mail in all folders

sometimes new mail is not necessarily in the inbox e.g. if mail server applies filters.  This commit lists all folders and works through each one giving a notification of mail for each folder.
pull/455/head
rjl6789 4 years ago
parent
commit
38e4db15a8
1 changed files with 16 additions and 12 deletions
  1. +16
    -12
      bin/mailsync

+ 16
- 12
bin/mailsync View File

@@ -1,5 +1,6 @@
#!/bin/sh #!/bin/sh

MAILDIR="$HOME/.local/share/mail"
SYNCSTAT="$HOME/.config/mutt/.mailsynclastrun"
# Sync mail and give notification if there is new mail. # Sync mail and give notification if there is new mail.


# Run only if user logged in (prevent cron errors) # Run only if user logged in (prevent cron errors)
@@ -31,17 +32,20 @@ fi
syncandnotify() { syncandnotify() {
acc="$(echo "$account" | sed "s/.*\///")" acc="$(echo "$account" | sed "s/.*\///")"
if [ -z "$opts" ]; then mbsync "$acc"; else mbsync "$opts" "$acc"; fi if [ -z "$opts" ]; then mbsync "$acc"; else mbsync "$opts" "$acc"; fi
new=$(find "$HOME/.local/share/mail/$acc/INBOX/new/" "$HOME/.local/share/mail/$acc/Inbox/new/" "$HOME/.local/share/mail/$acc/inbox/new/" -type f -newer "$HOME/.config/mutt/.mailsynclastrun" 2> /dev/null)
newcount=$(echo "$new" | sed '/^\s*$/d' | wc -l)
if [ "$newcount" -gt "0" ]; then
notify "$acc" "$newcount" &
for file in $new; do
# Extract subject and sender from mail.
from=$(awk '/^From: / && ++n ==1,/^\<.*\>:/' "$file" | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)' | awk '{ $1=""; if (NF>=3)$NF=""; print $0 }' | sed 's/^[[:blank:]]*[\"'\''\<]*//;s/[\"'\''\>]*[[:blank:]]*$//')
subject=$(awk '/^Subject: / && ++n == 1,/^\<.*\>: / && ++i == 2' "$file" | head -n 1 | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)' | sed 's/^Subject: //' | sed 's/^{[[:blank:]]*[\"'\''\<]*//;s/[\"'\''\>]*[[:blank:]]*$//' | tr -d '\n')
messageinfo &
done
fi
folderlist="$(find "$MAILDIR"/"$acc"/*/new -type d 2>/dev/null | sed '/^\s*$/d')"
for folder in $folderlist; do
new="$(find "$folder" -type f -newer "$SYNCSTAT" 2> /dev/null)"
newcount=$(echo "$new" | sed '/^\s*$/d' | wc -l)
if [ "$newcount" -gt "0" ]; then
notify "$acc" "$newcount" &
for file in $new; do
# Extract subject and sender from mail.
from=$(awk '/^From: / && ++n ==1,/^\<.*\>:/' "$file" | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)' | awk '{ $1=""; if (NF>=3)$NF=""; print $0 }' | sed 's/^[[:blank:]]*[\"'\''\<]*//;s/[\"'\''\>]*[[:blank:]]*$//')
subject=$(awk '/^Subject: / && ++n == 1,/^\<.*\>: / && ++i == 2' "$file" | head -n 1 | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)' | sed 's/^Subject: //' | sed 's/^{[[:blank:]]*[\"'\''\<]*//;s/[\"'\''\>]*[[:blank:]]*$//' | tr -d '\n')
messageinfo &
done
fi
done
} }


# Sync accounts passed as argument or all. # Sync accounts passed as argument or all.


Loading…
Cancel
Save