From 5e83a094476f28eb77508c8b470efe3dfd56de83 Mon Sep 17 00:00:00 2001 From: Mohammad Reza Karimi Date: Fri, 9 Jan 2026 17:34:31 -0500 Subject: some big changes --- scripts/dot-local/bin/mailsync | 54 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 scripts/dot-local/bin/mailsync (limited to 'scripts/dot-local/bin/mailsync') diff --git a/scripts/dot-local/bin/mailsync b/scripts/dot-local/bin/mailsync new file mode 100755 index 0000000..8029444 --- /dev/null +++ b/scripts/dot-local/bin/mailsync @@ -0,0 +1,54 @@ +#!/usr/bin/env sh + +# Run only if not already running in other instance +pgrep mbsync >/dev/null && { + echo "mbsync is already running." + exit +} + +notify() +{ + notify-send --app-name="Mail" -- "$1" "$2" +} + +# export GPG_TTY="$(tty)" +# export DISPLAY=":0" +# export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/"$(id -u)"/bus +export MAILDIR="$XDG_DATA_HOME/mail" +lastrun="$XDG_CACHE_HOME/.mailsynclastrun" +# export PYTHONWARNINGS="ignore::UserWarning" + +# afew --move-mails --all +mbsync -q mit + +new=$(find "$MAILDIR/mit/INBOX/new/" "$MAILDIR/mit/INBOX/cur/" -type f -newer "$lastrun" 2>/dev/null) +newcount=$(echo "$new" | sed '/^\s*$/d' | wc -l) + +case 1 in + $((newcount > 5))) + echo "$newcount new mail for mit." + notify "New Mail!" "$newcount new mail(s)." + ;; + $((newcount > 0))) + echo "$newcount new mail for mit." + for file in $new; do + # Extract and decode subject and sender from mail. + subject=$(awk '/^Subject: / && ++n == 1,/^.*: / && ++i == 2' "$file" | head -n-1 | + perl -CS -MEncode -ne 'print decode("MIME-Header", $_)' | + sed 's/^Subject: //' | tr -d '\n\t') + from="$(sed -n "/^From:/ s|From: *|| p" "$file" | + perl -CS -MEncode -ne 'print decode("MIME-Header", $_)')" + from="${from% *}" + from="${from%\"}" + from="${from#\"}" + notify "$from:" "$subject" + done + ;; + *) echo "No new mail for mit." ;; +esac + +# notmuch new +# afew --tag --new + +#Create a touch file that indicates the time of the last run of mailsync +touch "$lastrun" -- cgit v1.2.3-71-gdd5e