Переглянути джерело

[mail] don't notify if no email

Colin Powell 1 рік тому
батько
коміт
01da7bbadb
1 змінених файлів з 8 додано та 7 видалено
  1. 8 7
      bin/.bin/notify-on-new-mail.py

+ 8 - 7
bin/.bin/notify-on-new-mail.py

@@ -8,11 +8,12 @@ new_mail_list = json.loads(
 )
 
 
-output = "Mail's here!\n\n"
-for message in new_mail_list:
-    msg = message[0][0]
-    dt = msg['headers']['Date']
-    subj = msg['headers']['Subject']
-    output += f"{dt}\n{subj}\n\n"
+if new_mail_list:
+    output = "Mail's here!\n\n"
+    for message in new_mail_list:
+        msg = message[0][0]
+        dt = msg['headers']['Date']
+        subj = msg['headers']['Subject']
+        output += f"{dt}\n{subj}\n\n"
 
-subprocess.run(["dunstify", output])
+    subprocess.run(["dunstify", output])