aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/notmuch/.local/bin/notmuch-notify
blob: bc93f090313d9e027ea5b2fac321c5387f38c289 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/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,
        ]
    )


# 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