added initial function for email subjects decoding
This commit is contained in:
parent
207dbbcdb8
commit
f73ca3e0b0
|
@ -7,6 +7,7 @@ from PyQt5.QtWidgets import (QAction, QApplication, QCheckBox, QComboBox,
|
||||||
QTextEdit, QVBoxLayout, QInputDialog)
|
QTextEdit, QVBoxLayout, QInputDialog)
|
||||||
from PyQt5.QtCore import (QThread, QTimer, QFile, QSettings)
|
from PyQt5.QtCore import (QThread, QTimer, QFile, QSettings)
|
||||||
import imaplib
|
import imaplib
|
||||||
|
import email
|
||||||
imaplib._MAXLINE = 400000
|
imaplib._MAXLINE = 400000
|
||||||
import subprocess
|
import subprocess
|
||||||
import resources_rc
|
import resources_rc
|
||||||
|
@ -274,6 +275,24 @@ class Mail():
|
||||||
except:
|
except:
|
||||||
print("Unable to check mail")
|
print("Unable to check mail")
|
||||||
return "ERROR"
|
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():
|
def mail_check():
|
||||||
mail_count = 0
|
mail_count = 0
|
||||||
|
@ -294,6 +313,7 @@ def mail_check():
|
||||||
mail_count = "ERROR"
|
mail_count = "ERROR"
|
||||||
else:
|
else:
|
||||||
mail_count += m.checkMail()
|
mail_count += m.checkMail()
|
||||||
|
m.parseMail()
|
||||||
else:
|
else:
|
||||||
mail_count = "CONNECTION_ERROR"
|
mail_count = "CONNECTION_ERROR"
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue