dotfiles/conf.d/notmuch/post-new

69 lines
1.4 KiB
Plaintext
Raw Normal View History

2021-02-27 00:30:26 +00:00
#!/bin/bash
# File : post-new
# Author : Jeff LANCE <email@jefflance.me>
# Date : 10.02.2015
2021-03-01 21:41:37 +00:00
# Last Modified Date: 01.03.2021
2021-02-27 00:30:26 +00:00
# Last Modified By : Jeff LANCE <email@jefflance.me>
2021-03-01 21:41:37 +00:00
#
2021-02-27 00:30:26 +00:00
ASTROID_BIN=$(which astroid)
2021-03-01 21:41:37 +00:00
NOTMUCH_BIN=$(which notmuch)
NOTIFY_BIN=$(which notify-send)
function notify() {
# count new mails and display a message
newcount=$(${NOTMUCH_BIN} count tag:new)
summary="Tu as reçu ${newcount} new message"
# come on, who here doesn't actually hate "you have 1 new message(s)"?
if [ $newcount -gt 1 ]; then
summary="${summary}s"
fi
if [ $newcount -gt 0 ]; then
detail="$(${NOTMUCH_BIN} search --output=summary --format=json tag:new \
| sed -e 's/.*authors": "//;s/|[^"]*"/"/;s/", "subject": "/ : /;s/".*//')"
fi
if [ ${newcount} -gt 0 ]; then
${NOTIFY_BIN} \
-i /usr/share/notify-osd/icons/hicolor/scalable/status/notification-message-email.svg \
-c Mail "${summary}." "${detail}" -t 10000
fi
}
2021-02-27 00:30:26 +00:00
2021-03-01 21:41:37 +00:00
function refresh_ui() {
# refresh astroid ui
${ASTROID_BIN} --refresh 0
}
2021-02-27 00:30:26 +00:00
2021-03-01 21:41:37 +00:00
# some additional tags
${NOTMUCH_BIN} tag --input=${HOME}/Mail/.notmuch/tagupdate
if [ "x${DISPLAY}" != "x" ]; then
logger -t notmuch "post-new: notify"
notify
fi
# run afew on mew mails and make moves
2021-02-27 00:30:26 +00:00
afew --tag --new
afew --move-mails
if [ "x${DISPLAY}" != "x" ]; then
2021-03-01 21:41:37 +00:00
logger -t notmuch "post-new: refresh_ui"
refresh_ui
2021-02-27 00:30:26 +00:00
fi
2021-03-01 21:41:37 +00:00
exit 0
2021-02-27 00:30:26 +00:00
# vim:ft=sh