Browse Source

added initial function for email subjects decoding

master
Rinaldus 6 years ago
parent
commit
f73ca3e0b0
Signed by: Rinaldus
GPG Key ID: C34E249005178E87
  1. 20
      mail-notifier.py

20
mail-notifier.py

@ -7,6 +7,7 @@ from PyQt5.QtWidgets import (QAction, QApplication, QCheckBox, QComboBox, @@ -7,6 +7,7 @@ from PyQt5.QtWidgets import (QAction, QApplication, QCheckBox, QComboBox,
QTextEdit, QVBoxLayout, QInputDialog)
from PyQt5.QtCore import (QThread, QTimer, QFile, QSettings)
import imaplib
import email
imaplib._MAXLINE = 400000
import subprocess
import resources_rc
@ -274,6 +275,24 @@ class Mail(): @@ -274,6 +275,24 @@ class Mail():
except:
print("Unable to check mail")
return "ERROR"
def parseMail(self):
try:
self.imap.select()
typ, data = self.imap.search(None, 'ALL')
for num in data[0].split():
typ, data = self.imap.fetch(num, '(RFC822)')
raw_mail = data[0][1]
mail=email.message_from_bytes(raw_mail)
subject = mail.get('Subject')
h=email.header.decode_header(subject)
if (h[0][1] != "unknown-8bit"):
msg = h[0][0].decode(h[0][1]) if h[0][1] else h[0][0]
else:
msg = "Unknown charset"
print(msg)
except:
print("Unable to get mail data")
return "ERROR"
def mail_check():
mail_count = 0
@ -294,6 +313,7 @@ def mail_check(): @@ -294,6 +313,7 @@ def mail_check():
mail_count = "ERROR"
else:
mail_count += m.checkMail()
m.parseMail()
else:
mail_count = "CONNECTION_ERROR"
else:

Loading…
Cancel
Save