Add mailnag-notify.py
This commit is contained in:
parent
638bf99508
commit
5f24a1e46b
34
mailnag-notify.py
Executable file
34
mailnag-notify.py
Executable file
@ -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")
|
Loading…
Reference in New Issue
Block a user