From d76fa2c71ece026e6d00d532b53bd2ecc269e6b5 Mon Sep 17 00:00:00 2001 From: Pawel M Date: Thu, 8 Dec 2016 09:32:04 +0100 Subject: [PATCH 1/3] PY3 support and msgNum error solved in process_queue method --- helpdesk/management/commands/get_email.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/helpdesk/management/commands/get_email.py b/helpdesk/management/commands/get_email.py index e5b40c41..d2f3d70a 100644 --- a/helpdesk/management/commands/get_email.py +++ b/helpdesk/management/commands/get_email.py @@ -214,9 +214,9 @@ def process_queue(q, logger): ticket = ticket_from_message(message=data[0][1], queue=q, logger=logger) if ticket: server.store(num, '+FLAGS', '\\Deleted') - logger.info("Successfully processed message %s, deleted from IMAP server" % str(msgNum)) + logger.info("Successfully processed message %s, deleted from IMAP server" % str(num)) else: - logger.warn("Message %s was not successfully processed, and will be left on IMAP server" % str(msgNum)) + logger.warn("Message %s was not successfully processed, and will be left on IMAP server" % str(num)) server.expunge() server.close() @@ -271,7 +271,10 @@ def decode_mail_headers(string): def ticket_from_message(message, queue, logger): # 'message' must be an RFC822 formatted message. msg = message - message = email.message_from_string(msg) + if six.PY2: + message = email.message_from_string(msg) + elif six.PY3: + message = email.message_from_bytes(msg) subject = message.get('subject', _('Created from e-mail')) subject = decode_mail_headers(decodeUnknown(message.get_charset(), subject)) for affix in STRIPPED_SUBJECT_STRINGS: From 4c97ecd0aebe6b6989dec018236f812c9b3a00d6 Mon Sep 17 00:00:00 2001 From: Pawel M Date: Thu, 8 Dec 2016 15:14:11 +0100 Subject: [PATCH 2/3] PY3 get_email support in method ticket_from_message (if message isinstance bytes use email.email_from_bytes(msg) else ..from_string(msg)) --- helpdesk/management/commands/get_email.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/helpdesk/management/commands/get_email.py b/helpdesk/management/commands/get_email.py index d2f3d70a..3c85a8ae 100644 --- a/helpdesk/management/commands/get_email.py +++ b/helpdesk/management/commands/get_email.py @@ -274,7 +274,13 @@ def ticket_from_message(message, queue, logger): if six.PY2: message = email.message_from_string(msg) elif six.PY3: - message = email.message_from_bytes(msg) + print(type(msg)) + print(msg) + print(isinstance(msg, bytes)) + if isinstance(msg, bytes): + message = email.message_from_bytes(msg) + else: + message = email.message_from_string(msg) subject = message.get('subject', _('Created from e-mail')) subject = decode_mail_headers(decodeUnknown(message.get_charset(), subject)) for affix in STRIPPED_SUBJECT_STRINGS: From 5998faa6a59c9c1f9b3ed00969fa68adc80f4976 Mon Sep 17 00:00:00 2001 From: Pawel M Date: Thu, 8 Dec 2016 15:17:14 +0100 Subject: [PATCH 3/3] PY3 get_email support in method ticket_from_message (if message isinstance bytes use email.email_from_bytes(msg) else ..from_string(msg)) ... clear --- helpdesk/management/commands/get_email.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/helpdesk/management/commands/get_email.py b/helpdesk/management/commands/get_email.py index 3c85a8ae..48b765b0 100644 --- a/helpdesk/management/commands/get_email.py +++ b/helpdesk/management/commands/get_email.py @@ -274,9 +274,6 @@ def ticket_from_message(message, queue, logger): if six.PY2: message = email.message_from_string(msg) elif six.PY3: - print(type(msg)) - print(msg) - print(isinstance(msg, bytes)) if isinstance(msg, bytes): message = email.message_from_bytes(msg) else: