notify-on-new-mail.py 442 B

12345678910111213141516171819
  1. import json
  2. import subprocess
  3. new_mail_list = json.loads(
  4. subprocess.check_output(
  5. ["notmuch", "show", "--format=json", "tag:inbox"],
  6. ).decode('utf-8')
  7. )
  8. if new_mail_list:
  9. output = "Mail's here!\n\n"
  10. for message in new_mail_list:
  11. msg = message[0][0]
  12. dt = msg['headers']['Date']
  13. subj = msg['headers']['Subject']
  14. output += f"{dt}\n{subj}\n\n"
  15. subprocess.run(["dunstify", output])