notify-on-new-mail.py 396 B

123456789101112131415161718
  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. output = "Mail's here!\n\n"
  9. for message in new_mail_list:
  10. msg = message[0][0]
  11. dt = msg['headers']['Date']
  12. subj = msg['headers']['Subject']
  13. output += f"{dt}\n{subj}\n\n"
  14. subprocess.run(["dunstify", output])