From f73ca3e0b001c2a0ebc4d7ef6ee51875c9a716c4 Mon Sep 17 00:00:00 2001 From: Rinaldus Date: Mon, 25 Jul 2016 11:51:04 +0300 Subject: [PATCH] added initial function for email subjects decoding --- mail-notifier.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/mail-notifier.py b/mail-notifier.py index 5f95bc0..df463b4 100755 --- a/mail-notifier.py +++ b/mail-notifier.py @@ -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(): 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(): mail_count = "ERROR" else: mail_count += m.checkMail() + m.parseMail() else: mail_count = "CONNECTION_ERROR" else: