aboutsummaryrefslogtreecommitdiff
path: root/offlineimap/postsynchook.sh
diff options
context:
space:
mode:
authorgxlin <[email protected]>2021-06-26 10:49:25 +0800
committergxlin <[email protected]>2021-06-26 10:49:25 +0800
commitd79b3e6c9a904d8fc4f28f85ea60cb6ab040164b (patch)
treefa385565b9964c28db1384e047b393b3050ae4fd /offlineimap/postsynchook.sh
parent2aa3bd3b351aa99bee9e8bc905975744bf24a4bf (diff)
downloaddotfiles-d79b3e6c9a904d8fc4f28f85ea60cb6ab040164b.tar.gz
dotfiles-d79b3e6c9a904d8fc4f28f85ea60cb6ab040164b.tar.bz2
dotfiles-d79b3e6c9a904d8fc4f28f85ea60cb6ab040164b.zip
Notification of offlineimap
Diffstat (limited to 'offlineimap/postsynchook.sh')
-rwxr-xr-xofflineimap/postsynchook.sh46
1 files changed, 46 insertions, 0 deletions
diff --git a/offlineimap/postsynchook.sh b/offlineimap/postsynchook.sh
new file mode 100755
index 0000000..7262a50
--- /dev/null
+++ b/offlineimap/postsynchook.sh
@@ -0,0 +1,46 @@
+#!/usr/bin/env bash
+
+clean () {
+ sed "s/^\[/\\\[/g" | sed "s/\"/'/g" | sed 's/\!/❕/g'
+}
+
+get_sender () {
+ grep -o '^From: \(.*\)$' $1 | sed "s/^From: //g" | clean
+}
+
+get_subject () {
+ grep -o '^Subject: \(.*\)$' $1 | sed "s/^Subject: //g" | perl -pe 'use MIME::Words(decode_mimewords); $_=decode_mimewords($_);' | clean
+}
+
+notify () {
+ account=$1
+ previous_messages=/tmp/offlineimap-$account-messages
+ maildir="$HOME/.mail/$account/inbox/new"
+
+ if [ ! -e $previous_messages ]; then
+ touch $previous_messages
+ fi
+
+ for file in $maildir/*; do
+ if [ ! -f $file ]; then
+ continue
+ fi
+
+ filename=$(basename $file)
+ if grep -Fxq $filename $previous_messages; then
+ : echo "seen"
+ else
+ echo $filename >> $previous_messages
+ sender="`get_sender $file`"
+ subject=`get_subject $file`
+ message="New message for $account"
+
+ if [ -e /usr/local/bin/terminal-notifier ]; then
+ terminal-notifier -title $subject -subtitle $sender -message $message -sender 'org.gnu.Emacs' -activate 'org.gnu.Emacs'
+ fi
+ fi
+ done
+}
+
+mu index
+notify $1