Created
October 29, 2017 22:43
-
-
Save Nervengift/3262222875840d761f06784d9f8ba55e to your computer and use it in GitHub Desktop.
notification script for notmuch/afew
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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