aboutsummaryrefslogtreecommitdiff
path: root/local/sbin/newmail-notify
blob: 74aea66c688d0cf829b57b14a0f00044c36798b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/env python3
import json
import subprocess

subproc = subprocess.run(["notmuch", "show", "--format=json", "--", "tag:new"], check=True, capture_output=True)

mails = json.loads(subproc.stdout)
print(len(mails))

for mail in mails:
    headers = mail[0][0]["headers"]
    if 'To' in headers:
        summary = f"{headers['From']} -> {headers['To']}"
    else:
        summary = f"{headers['From']}"
    body = headers["Subject"]
    subprocess.run(["notify-send", summary, body], check=True)