mail headers decoding function now returns completed array instead of single variable
This commit is contained in:
parent
9cb0d58312
commit
51c9221822
|
@ -283,13 +283,23 @@ class Mail():
|
||||||
typ, data = self.imap.fetch(num, '(RFC822)')
|
typ, data = self.imap.fetch(num, '(RFC822)')
|
||||||
raw_mail = data[0][1]
|
raw_mail = data[0][1]
|
||||||
mail=email.message_from_bytes(raw_mail)
|
mail=email.message_from_bytes(raw_mail)
|
||||||
subject = mail.get('Subject')
|
h=email.header.decode_header(mail.get('Subject'))
|
||||||
h=email.header.decode_header(subject)
|
|
||||||
if (h[0][1] != "unknown-8bit"):
|
if (h[0][1] != "unknown-8bit"):
|
||||||
msg = h[0][0].decode(h[0][1]) if h[0][1] else h[0][0]
|
SUBJ = h[0][0].decode(h[0][1]) if h[0][1] else h[0][0]
|
||||||
else:
|
else:
|
||||||
msg = "Unknown charset"
|
SUBJ = "Unknown charset"
|
||||||
print(msg)
|
h=email.header.decode_header(mail.get('From'))
|
||||||
|
if (h[0][1] != "unknown-8bit"):
|
||||||
|
FROM = h[0][0].decode(h[0][1]) if h[0][1] else h[0][0]
|
||||||
|
else:
|
||||||
|
FROM = "Unknown charset"
|
||||||
|
h=email.header.decode_header(mail.get('Date'))
|
||||||
|
if (h[0][1] != "unknown-8bit"):
|
||||||
|
DATE = h[0][0].decode(h[0][1]) if h[0][1] else h[0][0]
|
||||||
|
else:
|
||||||
|
DATE = "Unknown charset"
|
||||||
|
output = [FROM, SUBJ, DATE]
|
||||||
|
return output
|
||||||
except:
|
except:
|
||||||
print("Unable to get mail data")
|
print("Unable to get mail data")
|
||||||
return "ERROR"
|
return "ERROR"
|
||||||
|
@ -313,7 +323,7 @@ def mail_check():
|
||||||
mail_count = "ERROR"
|
mail_count = "ERROR"
|
||||||
else:
|
else:
|
||||||
mail_count += m.checkMail()
|
mail_count += m.checkMail()
|
||||||
m.parseMail()
|
print(m.parseMail())
|
||||||
else:
|
else:
|
||||||
mail_count = "CONNECTION_ERROR"
|
mail_count = "CONNECTION_ERROR"
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue