Fix e-mail segment UTF-8 issues

Closes #178.
This commit is contained in:
Kim Silkebækken 2013-02-06 09:09:18 +01:00
parent c8d4e58a93
commit 9a95d738d5
1 changed files with 5 additions and 4 deletions

View File

@ -242,10 +242,11 @@ def email_imap_alert(username, password, server='imap.gmail.com', port=993, fold
try: try:
mail = imaplib.IMAP4_SSL(server, port) mail = imaplib.IMAP4_SSL(server, port)
mail.login(username, password) mail.login(username, password)
rc, message = mail.status(folder, '(UNSEEN)').decode('utf-8') rc, message = mail.status(folder, '(UNSEEN)')
unread_count = int(re.search('UNSEEN (\d+)', message[0]).group(1)) unread_str = message[0].decode('utf-8')
except (imaplib.IMAP4.error, AttributeError): unread_count = int(re.search('UNSEEN (\d+)', unread_str).group(1))
return None except imaplib.IMAP4.error as e:
unread_count = str(e)
if not unread_count: if not unread_count:
return None return None
return [{ return [{