aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--notmuch/.config/isyncrc8
-rwxr-xr-xnotmuch/.config/notmuch/default/hooks/post-new2
-rwxr-xr-xnotmuch/.local/lib/notmuch/notmuch-notify47
-rwxr-xr-xnotmuch/.local/lib/notmuch/notmuch-notify.py70
4 files changed, 75 insertions, 52 deletions
diff --git a/notmuch/.config/isyncrc b/notmuch/.config/isyncrc
index bfad9cd..0a69881 100644
--- a/notmuch/.config/isyncrc
+++ b/notmuch/.config/isyncrc
@@ -43,17 +43,17 @@ Patterns "INBOX"
Channel gmail-drafts
Far :gmail-remote:"[Gmail]/Drafts"
Near :gmail-local:Drafts
-Create Near
Channel gmail-sent
Far :gmail-remote:"[Gmail]/Sent Mail"
Near :gmail-local:Sent
-Create Near
Channel gmail-trash
Far :gmail-remote:"[Gmail]/Trash"
Near :gmail-local:Trash
-Create Near
Group gmail
-Channels gmail gmail-drafts gmail-sent gmail-trash
+Channel gmail
+Channel gmail-drafts
+Channel gmail-sent
+Channel gmail-trash
diff --git a/notmuch/.config/notmuch/default/hooks/post-new b/notmuch/.config/notmuch/default/hooks/post-new
index 798340f..a7810fc 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
-"$HOME"/.local/lib/notmuch/notmuch-notify
+"$HOME"/.local/lib/notmuch/notmuch-notify.py
diff --git a/notmuch/.local/lib/notmuch/notmuch-notify b/notmuch/.local/lib/notmuch/notmuch-notify
deleted file mode 100755
index b8a38b6..0000000
--- a/notmuch/.local/lib/notmuch/notmuch-notify
+++ /dev/null
@@ -1,47 +0,0 @@
-#!/bin/python
-
-import notmuch
-import subprocess
-import os
-
-
-def notify(title, message):
- subprocess.Popen(
- [
- "notify-send",
- "--app-name=notmuch-notify",
- "--category=email.arrived",
- "--icon=mail-unread",
- title,
- message,
- ]
- )
-
-
-def main():
- # Workaround for bug in the notmuch module's default config resolution
- if os.environ.get("NOTMUCH_CONFIG") is None:
- os.environ["NOTMUCH_CONFIG"] = os.path.join(
- os.environ.get(
- "XDG_CONFIG_HOME", os.path.join(os.path.expanduser("~"), ".config")
- ),
- "notmuch",
- os.environ.get("NOTMUCH_PROFILE", "default"),
- "config",
- )
-
- for message in (
- notmuch.Database(
- mode=notmuch.Database.MODE.READ_WRITE,
- )
- .create_query("tag:notify")
- .search_messages()
- ):
- print(message)
- message.remove_tag("notify")
- notify(message.get_header("From"), message.get_header("Subject"))
- del message
-
-
-if __name__ == "__main__":
- main()
diff --git a/notmuch/.local/lib/notmuch/notmuch-notify.py b/notmuch/.local/lib/notmuch/notmuch-notify.py
new file mode 100755
index 0000000..b39f29b
--- /dev/null
+++ b/notmuch/.local/lib/notmuch/notmuch-notify.py
@@ -0,0 +1,70 @@
+#!/usr/bin/env python3
+
+import notmuch
+import os
+from jeepney.io.blocking import open_dbus_connection
+from jeepney import DBusAddress, new_method_call
+
+
+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:
+ notifications = DBusAddress(
+ "/org/freedesktop/Notifications",
+ bus_name="org.freedesktop.Notifications",
+ interface="org.freedesktop.Notifications",
+ )
+
+ msg = new_method_call(
+ notifications,
+ "Notify",
+ "susssasa{sv}i",
+ (
+ "notmuch-notify",
+ 0,
+ "mail-unread",
+ summary,
+ body,
+ [],
+ {},
+ -1,
+ ),
+ )
+
+ return open_dbus_connection(bus="SESSION").send_and_get_reply(msg)
+
+
+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)
+ query = database.create_query("tag:notify")
+ count = query.count_messages()
+ messages = query.search_messages()
+
+ if count == 1:
+ message = next(messages)
+ print(message)
+ notify(message.get_header("From"), message.get_header("Subject"))
+ 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__":
+ main()