#!/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)