Commit 1e949fd8 authored by Jérome Perrin's avatar Jérome Perrin

interface_post: py3

parent 6f03f9ff
...@@ -43,7 +43,7 @@ class InternetMessagePost(Item, MailMessageMixin): ...@@ -43,7 +43,7 @@ class InternetMessagePost(Item, MailMessageMixin):
def _getMessage(self): def _getMessage(self):
return email.message_from_string(self.getData()) return email.message_from_string(self.getData().decode())
security.declareProtected(Permissions.AccessContentsInformation, 'stripMessageId') security.declareProtected(Permissions.AccessContentsInformation, 'stripMessageId')
def stripMessageId(self, message_id): def stripMessageId(self, message_id):
......
import six
portal = context.getPortalObject() portal = context.getPortalObject()
post_message_post_module = portal.getDefaultModuleValue(post_portal_type, None) post_message_post_module = portal.getDefaultModuleValue(post_portal_type, None)
if isinstance(post_message_data, six.text_type):
post_message_data = post_message_data.encode()
message_post = post_message_post_module.newContent( message_post = post_message_post_module.newContent(
portal_type=post_portal_type, portal_type=post_portal_type,
title="Post Message for %s" % context.getTitle(), title="Post Message for %s" % context.getTitle(),
......
...@@ -5,13 +5,16 @@ multipart message). As for users don't want an accurate representation of ...@@ -5,13 +5,16 @@ multipart message). As for users don't want an accurate representation of
the message, but a preview, we assume that rendering the first part the message, but a preview, we assume that rendering the first part
of the multipart message is enough. of the multipart message is enough.
""" """
import six
import email import email
message = email.message_from_string(context.getData()) message = email.message_from_string(context.getData().decode())
payload = message.get_payload() payload = message.get_payload()
while isinstance(payload, list): while isinstance(payload, list):
payload = payload[0].get_payload(decode=True) payload = payload[0].get_payload(decode=True)
if six.PY3:
payload = payload.decode()
return payload return payload
...@@ -5,10 +5,16 @@ in ERP5. ...@@ -5,10 +5,16 @@ in ERP5.
from Products.ZSQLCatalog.SQLCatalog import SimpleQuery from Products.ZSQLCatalog.SQLCatalog import SimpleQuery
import email import email
import six
portal = context.getPortalObject() portal = context.getPortalObject()
email_object = email.message_from_string(context.getData()) if six.PY2:
message_from_bytes = email.message_from_string
else:
message_from_bytes = email.message_from_bytes
email_object = message_from_bytes(bytes(context.getData()))
mail_message = portal.portal_contributions.newContent( mail_message = portal.portal_contributions.newContent(
container_path='event_module', container_path='event_module',
......
...@@ -5,5 +5,4 @@ ...@@ -5,5 +5,4 @@
# spawned with parameters : # spawned with parameters :
# conflict_retry=False, # conflict_retry=False,
# max_retry=0, # max_retry=0,
context.getPortalObject().MailHost.send(context.getData().decode())
context.getPortalObject().MailHost.send(context.getData())
...@@ -231,7 +231,7 @@ class TestInterfacePost(ERP5TypeTestCase): ...@@ -231,7 +231,7 @@ class TestInterfacePost(ERP5TypeTestCase):
for internet_message_post in internet_message_post_list: for internet_message_post in internet_message_post_list:
self.assertEqual(internet_message_post.getSimulationState(), 'exported') self.assertEqual(internet_message_post.getSimulationState(), 'exported')
mail_object = email.message_from_string(internet_message_post.getData()) mail_object = email.message_from_string(internet_message_post.getData().decode())
self.assertEqual( self.assertEqual(
internet_message_post.getReference(), mail_object['message-id'].strip('<>') internet_message_post.getReference(), mail_object['message-id'].strip('<>')
) )
...@@ -263,7 +263,7 @@ class TestInterfacePost(ERP5TypeTestCase): ...@@ -263,7 +263,7 @@ class TestInterfacePost(ERP5TypeTestCase):
message_list = self.portal.MailHost._message_list message_list = self.portal.MailHost._message_list
self.assertEqual(len(message_list), len(self.recipient_list)) self.assertEqual(len(message_list), len(self.recipient_list))
for post in sequence['internet_message_post_list']: for post in sequence['internet_message_post_list']:
post_recipient = email.message_from_string(post.getData())['to'] post_recipient = email.message_from_string(post.getData().decode())['to']
message_list = self._getMailHostMessageForRecipient(post_recipient) message_list = self._getMailHostMessageForRecipient(post_recipient)
self.assertEqual(len(message_list), 1) self.assertEqual(len(message_list), 1)
message = message_list[0] message = message_list[0]
...@@ -282,7 +282,7 @@ class TestInterfacePost(ERP5TypeTestCase): ...@@ -282,7 +282,7 @@ class TestInterfacePost(ERP5TypeTestCase):
post = sequence['internet_message_post'] post = sequence['internet_message_post']
# Create a response mail object # Create a response mail object
mail_object = email.message_from_string(post.getData()) mail_object = email.message_from_string(post.getData().decode())
sender = mail_object['from'] sender = mail_object['from']
recipient = mail_object['to'] recipient = mail_object['to']
...@@ -297,7 +297,7 @@ class TestInterfacePost(ERP5TypeTestCase): ...@@ -297,7 +297,7 @@ class TestInterfacePost(ERP5TypeTestCase):
# Ingest it # Ingest it
response_post = self.portal.internet_message_post_module.newContent( response_post = self.portal.internet_message_post_module.newContent(
portal_type='Internet Message Post', portal_type='Internet Message Post',
data=mail_object.as_string(), data=mail_object.as_string().encode(),
) )
response_post.prepareImport() response_post.prepareImport()
sequence['internet_message_post_response'] = response_post sequence['internet_message_post_response'] = response_post
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment