diff options
-rw-r--r-- | notmuch/.config/afew/SpamStatusFilter.py | 16 | ||||
-rw-r--r-- | notmuch/.config/afew/config | 19 | ||||
-rw-r--r-- | notmuch/.config/notmuch/default/config | 2 | ||||
-rwxr-xr-x | notmuch/.config/notmuch/default/hooks/post-new | 2 | ||||
-rwxr-xr-x | notmuch/.local/lib/notmuch/notmuch-notify.py | 40 |
5 files changed, 40 insertions, 39 deletions
diff --git a/notmuch/.config/afew/SpamStatusFilter.py b/notmuch/.config/afew/SpamStatusFilter.py new file mode 100644 index 0000000..e18c616 --- /dev/null +++ b/notmuch/.config/afew/SpamStatusFilter.py @@ -0,0 +1,16 @@ +from afew.FilterRegistry import register_filter +from afew.filters.HeaderMatchingFilter import HeaderMatchingFilter + + +@register_filter +class SpamStatusFilter(HeaderMatchingFilter): + message = "Tagging spam messages" + header = "X-Spam-Status" + pattern = "Yes" + + def __init__(self, database, tags="+spam", spam_tag=None, **kwargs): + if spam_tag is not None: + # this is for backward-compatibility + tags = "+" + spam_tag + kwargs["tags"] = [tags] + super().__init__(database, **kwargs) diff --git a/notmuch/.config/afew/config b/notmuch/.config/afew/config index b1cc796..52aad24 100644 --- a/notmuch/.config/afew/config +++ b/notmuch/.config/afew/config @@ -1,21 +1,12 @@ [SpamFilter] - +[SpamStatusFilter] [KillThreadsFilter] - [ArchiveSentMailsFilter] sent_tag = sent - -[Filter.0] -message = notify -query = tag:new -tags_blacklist = killed;spam -tags = +notify - [InboxFilter] - [MailMover] -folders = INBOX Archive Junk +folders = tobyvin.dev/tobyv/INBOX tobyvin.dev/tobyv/Archive tobyvin.dev/tobyv/Junk rename = True -INBOX = 'tag:spam':Junk 'NOT tag:inbox':Archive -Archive = 'tag:spam':Junk 'tag:inbox':INBOX -Junk = 'NOT tag:spam AND tag:inbox':INBOX 'NOT tag:spam':Archive +tobyvin.dev/tobyv/INBOX = 'tag:spam':tobyvin.dev/tobyv/Junk 'NOT tag:inbox':tobyvin.dev/tobyv/Archive +tobyvin.dev/tobyv/Archive = 'tag:spam':tobyvin.dev/tobyv/Junk 'tag:inbox':tobyvin.dev/tobyv/INBOX +tobyvin.dev/tobyv/Junk = 'NOT tag:spam AND tag:inbox':tobyvin.dev/tobyv/INBOX 'NOT tag:spam':tobyvin.dev/tobyv/Archive diff --git a/notmuch/.config/notmuch/default/config b/notmuch/.config/notmuch/default/config index 75f4f5f..530b1bb 100644 --- a/notmuch/.config/notmuch/default/config +++ b/notmuch/.config/notmuch/default/config @@ -5,7 +5,7 @@ name=Toby Vincent primary_email=tobyv@tobyvin.dev other_email=postmaster@tobyvin.dev;hostmaster@tobyvin.dev;webmaster@tobyvin.dev;tobyv13@gmail.com;tovince@siue.edu; [new] -tags=new +tags=new;notify ignore=.mbsyncstate;.uidvalidity;addressbook.tsv;mujmap.toml; [maildir] synchronize_flags=true diff --git a/notmuch/.config/notmuch/default/hooks/post-new b/notmuch/.config/notmuch/default/hooks/post-new index a7810fc..70c4dae 100755 --- a/notmuch/.config/notmuch/default/hooks/post-new +++ b/notmuch/.config/notmuch/default/hooks/post-new @@ -1,4 +1,4 @@ #!/bin/sh +~/.local/lib/notmuch/notmuch-notify.py afew -C "$XDG_CONFIG_HOME"/notmuch/default/config --tag --new -"$HOME"/.local/lib/notmuch/notmuch-notify.py diff --git a/notmuch/.local/lib/notmuch/notmuch-notify.py b/notmuch/.local/lib/notmuch/notmuch-notify.py index b39f29b..18c6c83 100755 --- a/notmuch/.local/lib/notmuch/notmuch-notify.py +++ b/notmuch/.local/lib/notmuch/notmuch-notify.py @@ -1,9 +1,17 @@ #!/usr/bin/env python3 -import notmuch import os -from jeepney.io.blocking import open_dbus_connection + +import notmuch from jeepney import DBusAddress, new_method_call +from jeepney.io.blocking import open_dbus_connection + + +DBUS_ADDRESS = DBusAddress( + "/org/freedesktop/Notifications", + bus_name="org.freedesktop.Notifications", + interface="org.freedesktop.Notifications", +) def default_config() -> str: @@ -17,15 +25,9 @@ def default_config() -> str: ) -def notify(summary: str, body: str) -> int: - notifications = DBusAddress( - "/org/freedesktop/Notifications", - bus_name="org.freedesktop.Notifications", - interface="org.freedesktop.Notifications", - ) - +def notify(summary: str, body: str) -> int | None: msg = new_method_call( - notifications, + DBUS_ADDRESS, "Notify", "susssasa{sv}i", ( @@ -40,7 +42,9 @@ def notify(summary: str, body: str) -> int: ), ) - return open_dbus_connection(bus="SESSION").send_and_get_reply(msg) + id = open_dbus_connection(bus="SESSION").send_and_get_reply(msg) + if isinstance(id, int): + return id def main(): @@ -48,22 +52,12 @@ def main(): os.environ["NOTMUCH_CONFIG"] = default_config() database = notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE) - query = database.create_query("tag:notify") - count = query.count_messages() - messages = query.search_messages() - if count == 1: - message = next(messages) - print(message) + for message in database.create_query("tag:notify").search_messages(): notify(message.get_header("From"), message.get_header("Subject")) + print(message) message.remove_tag("notify") del message - elif count > 1: - notify("You have new mail", f"{count} new messages...") - for message in query.search_messages(): - print(message) - message.remove_tag("notify") - del message if __name__ == "__main__": |