From 338e6dd84046ad31f114e1d13e89dd646c35a707 Mon Sep 17 00:00:00 2001 From: Toby Vincent Date: Wed, 18 Sep 2024 18:08:39 -0500 Subject: fix(notmuch): move notify script to bin --- notmuch/.config/notmuch/default/hooks/post-new | 2 +- notmuch/.local/bin/notmuch-notify | 64 ++++++++++++++++++++++++++ notmuch/.local/lib/notmuch/notmuch-notify.py | 64 -------------------------- 3 files changed, 65 insertions(+), 65 deletions(-) create mode 100755 notmuch/.local/bin/notmuch-notify delete mode 100755 notmuch/.local/lib/notmuch/notmuch-notify.py diff --git a/notmuch/.config/notmuch/default/hooks/post-new b/notmuch/.config/notmuch/default/hooks/post-new index 6f4c03f..912d8bc 100755 --- a/notmuch/.config/notmuch/default/hooks/post-new +++ b/notmuch/.config/notmuch/default/hooks/post-new @@ -1,4 +1,4 @@ #!/bin/sh afew -C "$XDG_CONFIG_HOME"/notmuch/default/config --tag --new -~/.local/lib/notmuch/notmuch-notify.py +"$HOME"/.local/bin/notmuch-notify diff --git a/notmuch/.local/bin/notmuch-notify b/notmuch/.local/bin/notmuch-notify new file mode 100755 index 0000000..18c6c83 --- /dev/null +++ b/notmuch/.local/bin/notmuch-notify @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 + +import os + +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: + return os.path.join( + os.environ.get( + "XDG_CONFIG_HOME", os.path.join(os.path.expanduser("~"), ".config") + ), + "notmuch", + os.environ.get("NOTMUCH_PROFILE", "default"), + "config", + ) + + +def notify(summary: str, body: str) -> int | None: + msg = new_method_call( + DBUS_ADDRESS, + "Notify", + "susssasa{sv}i", + ( + "notmuch-notify", + 0, + "mail-unread", + summary, + body, + [], + {}, + -1, + ), + ) + + id = open_dbus_connection(bus="SESSION").send_and_get_reply(msg) + if isinstance(id, int): + return id + + +def main(): + if os.environ.get("NOTMUCH_CONFIG") is None: + os.environ["NOTMUCH_CONFIG"] = default_config() + + database = notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE) + + 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 + + +if __name__ == "__main__": + main() diff --git a/notmuch/.local/lib/notmuch/notmuch-notify.py b/notmuch/.local/lib/notmuch/notmuch-notify.py deleted file mode 100755 index 18c6c83..0000000 --- a/notmuch/.local/lib/notmuch/notmuch-notify.py +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/env python3 - -import os - -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: - return os.path.join( - os.environ.get( - "XDG_CONFIG_HOME", os.path.join(os.path.expanduser("~"), ".config") - ), - "notmuch", - os.environ.get("NOTMUCH_PROFILE", "default"), - "config", - ) - - -def notify(summary: str, body: str) -> int | None: - msg = new_method_call( - DBUS_ADDRESS, - "Notify", - "susssasa{sv}i", - ( - "notmuch-notify", - 0, - "mail-unread", - summary, - body, - [], - {}, - -1, - ), - ) - - id = open_dbus_connection(bus="SESSION").send_and_get_reply(msg) - if isinstance(id, int): - return id - - -def main(): - if os.environ.get("NOTMUCH_CONFIG") is None: - os.environ["NOTMUCH_CONFIG"] = default_config() - - database = notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE) - - 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 - - -if __name__ == "__main__": - main() -- cgit v1.2.3-70-g09d2