From 5f24a1e46bb3c5aaee1aa36031997d3177283ee9 Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Sun, 25 Dec 2022 16:48:14 -0800 Subject: [PATCH] Add mailnag-notify.py --- mailnag-notify.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 mailnag-notify.py diff --git a/mailnag-notify.py b/mailnag-notify.py new file mode 100755 index 0000000..210c699 --- /dev/null +++ b/mailnag-notify.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 +import sys +import subprocess + + +def notify_send(subj, data): + result = subprocess.run(["notify-send", subj, data]) + if result.returncode == -127: + print("error: notify-send program not found in PATH", file=sys.stderr) + exit(1) + elif result.returncode != 0: + print("error: notify-send failed", file=sys.stderr) + exit(1) + + +senders = {} + +for i in range(2, len(sys.argv), 3): + sender = sys.argv[i + 1] + subj = sys.argv[i + 2] + print(sender) + print(subj) + if sender not in senders: + senders[sender] = subj + elif isinstance(subj, str): + senders[sender] = 2 + else: + senders[sender] += 1 + +for sender, data in senders.items(): + if isinstance(data, str): + notify_send("New mail from " + sender, data) + else: + notify_send("New mail from " + sender, str(data) + " unread messages")