Skip to content

Instantly share code, notes, and snippets.

@Nervengift
Created October 29, 2017 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nervengift/3262222875840d761f06784d9f8ba55e to your computer and use it in GitHub Desktop.
Save Nervengift/3262222875840d761f06784d9f8ba55e to your computer and use it in GitHub Desktop.
notification script for notmuch/afew
#!/usr/bin/env python3
# Send notifications for all mails with the "notify" tag via notify-send
#
# This is best used in combination with afew. To notify for all new messages just add
# the following filter to your ~/.config/afew/config just before [InboxFilter]:
#
# [Filter.0]
# message = notify
# query = tag:new AND NOT tag:killed AND NOT tag:spam
# tags = +notify
#
# Then run this script after each call to afew, e.g. in you notmuch post-new hook
import notmuch
import subprocess
def notify(title, message):
subprocess.Popen(['notify-send', "--app-name=notmuch-notify", title, message])
for message in notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE).create_query('tag:notify').search_messages():
print(message)
message.remove_tag('notify')
notify("New mail from {}".format(message.get_header('From')), message.get_header('Subject'))
del message # python's scoping is shit: message will survive the for loop and db will not be closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment