array works properly now

This commit is contained in:
Rinaldus 2016-07-25 15:16:45 +03:00
parent 52c76223a9
commit d5d41dcfef
Signed by: Rinaldus
GPG Key ID: C34E249005178E87
1 changed files with 8 additions and 5 deletions

View File

@ -275,21 +275,22 @@ class Mail():
except: except:
print("Unable to check mail") print("Unable to check mail")
return "ERROR" return "ERROR"
def parseMail(self): def parseMail(self,header):
try: try:
output=[]
self.imap.select(readonly=True) self.imap.select(readonly=True)
typ, data = self.imap.search(None, 'UNSEEN') typ, data = self.imap.search(None, 'UNSEEN')
for num in data[0].split(): for num in data[0].split():
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(header))
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] msg = h[0][0].decode(h[0][1]) if h[0][1] else h[0][0]
else: else:
msg = "Unknown charset" msg = "Unknown charset"
print(msg) output.append(msg)
return output
except: except:
print("Unable to get mail data") print("Unable to get mail data")
return "ERROR" return "ERROR"
@ -313,7 +314,9 @@ def mail_check():
mail_count = "ERROR" mail_count = "ERROR"
else: else:
mail_count += m.checkMail() mail_count += m.checkMail()
m.parseMail() print("FROM:",m.parseMail("From"))
print("SUBJECT:",m.parseMail("Subject"))
print("DATE:",m.parseMail("Date"))
else: else:
mail_count = "CONNECTION_ERROR" mail_count = "CONNECTION_ERROR"
else: else: