dgy
/
hexagons
Archived
1
0
Fork 0
This repository has been archived on 2021-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
hexagons/.local/bin/cartero

41 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env sh
pgrep -x mbsync > /dev/null && exit
ping -q -c 1 1.1.1.1 > /dev/null || exit
ICON="$XDG_DATA_HOME/icons/Haiku/scalable/apps/claws-mail.svg"
syncandnotify() {
acc="$(echo "$account" | sed "s/.*\///")"
mbsync -c "$XDG_CONFIG_HOME"/isync/mbsyncrc "$acc"
new=$(find "$XDG_DATA_HOME/mail/$acc/INBOX/new/" "$XDG_DATA_HOME/mail/$acc/Inbox/new/" "$XDG_DATA_HOME/mail/$acc/inbox/new/" -type f -newer "$XDG_CONFIG_HOME/neomutt/.mailsynclastrun" 2> /dev/null)
newcount=$(echo "$new" | sed '/^\s*$/d' | wc -l)
if [ "$newcount" -gt "0" ]; then
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')
[ -n $DISPLAY ] && notify-send --app-name="neomutt" -i "$ICON" "Mensaje nuevo para $acc" "$from: $subject" &
done
fi
}
if [ "$#" -eq "0" ]; then
accounts="$(awk '/^Channel/ {print $2}' "$XDG_CONFIG_HOME/isync/mbsyncrc")"
else
for arg in "$@"; do
[ "${arg%${arg#?}}" = '-' ] && opts="${opts:+${opts} }${arg}" && shift 1
done
accounts=$*
fi
for account in $accounts; do
syncandnotify &
done
wait
notmuch new 2> /dev/null
touch "$XDG_CONFIG_HOME/neomutt/.mailsynclastrun"