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")