aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/notmuch/.local/bin/notmuch-notify
blob: f808c4db95d77fdafac331e2ac3e1805a886ec38 (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
#!/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,
        ]
    )


for message in (
    notmuch.Database(
        path="{}/mail".format(
            os.getenv("XDG_DATA_HOME", os.path.expanduser("~/.local/share"))
        ),
        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