Commit 8f165c65 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

fixup! base: do not store a generated email message payload in a Mail Message document.

parent 6ba4a6b1
......@@ -64,8 +64,6 @@ elif sender is not None:\n
else:\n
from_url = portal.portal_preferences.getPreferredEventSenderEmail()\n
\n
attachment_list = kw.pop(\'attachment_list\', [])\n
\n
to_url = formataddr((context.getTitle(), context.getDefaultEmailText()))\n
\n
document_type_list = list(event.getPortalEmbeddedDocumentTypeList()) + list(event.getPortalDocumentTypeList())\n
......@@ -77,7 +75,6 @@ mail_message = portal.Base_createMailMessageAsString(from_url,\n
subject,\n
body,\n
content_type,\n
attachment_list=attachment_list,\n
embedded_file_list=embedded_file_list)\n
\n
event.sendMailHostMessage(mail_message)\n
......
......@@ -58,12 +58,28 @@ This script is also used by notification tool, that\'s why it is in erp5_base.\n
from email.utils import formataddr\n
portal = context.getPortalObject()\n
\n
if attachment_list is None:\n
attachment_list = []\n
use_activity = False\n
mail_message = None\n
to_url_list = []\n
\n
# Attachments\n
document_type_list = list(context.getPortalEmbeddedDocumentTypeList()) + list(context.getPortalDocumentTypeList())\n
embedded_file_list = context.getAggregateValueList(portal_type=document_type_list)\n
for attachment in attachment_list or []:\n
embedded_file = context.newContent(\n
portal_type=\'Embedded File\',\n
title=attachment[\'name\'],\n
filename=attachment[\'name\'],\n
content_type=attachment[\'mime_type\'],\n
data=attachment[\'content\'],\n
)\n
if embedded_file not in embedded_file_list:\n
embedded_file_list.append(embedded_file)\n
aggregate_list = context.getAggregateValueList()\n
context.setAggregateValueList(\n
aggregate_list + [x for x in embedded_file_list if x not in aggregate_list]\n
)\n
\n
if not context.isTempDocument() and to_url is None:\n
use_activity = True\n
\n
......@@ -79,10 +95,13 @@ if to_url is None:\n
else:\n
to_url_list.append(to_url)\n
\n
if not context.hasStartDate():\n
context.setStartDate(DateTime())\n
\n
if download or not use_activity:\n
for to_url in to_url_list:\n
body = body or context.getTextContent()\n
subject = subject or context.getTitle()\n
body = body or context.getTextContent() or \'\'\n
subject = subject or context.getTitle() or \'\'\n
\n
# From\n
if from_url is None:\n
......@@ -100,10 +119,6 @@ if download or not use_activity:\n
additional_headers = None\n
if reply_url:\n
additional_headers = {\'Return-Path\':reply_url}\n
\n
# Attachments\n
document_type_list = list(context.getPortalEmbeddedDocumentTypeList()) + list(context.getPortalDocumentTypeList())\n
embedded_file_list = context.getAggregateValueList(portal_type=document_type_list)\n
\n
content_type = context.getContentType()\n
\n
......@@ -112,7 +127,6 @@ if download or not use_activity:\n
subject,\n
body,\n
content_type,\n
attachment_list=attachment_list,\n
embedded_file_list=embedded_file_list)\n
\n
if not use_activity:\n
......@@ -120,8 +134,7 @@ if download or not use_activity:\n
\n
if use_activity:\n
method_kw = dict(event_relative_url=context.getRelativeUrl(),\n
from_url=from_url,\n
attachment_list=attachment_list)\n
from_url=from_url)\n
context.activate(\n
after_path_and_method_id=((context.getPath(),), \n
(\'immediateReindexObject\', \'recursiveImmediateReindexObject\'))).MailMessage_sendByActivity(\n
......
......@@ -18,6 +18,9 @@
<item>Visit</item>
<item>Web Message</item>
</portal_type>
<portal_type id="Mail Message">
<item>Embedded File</item>
</portal_type>
<portal_type id="Meeting">
<item>Event Path</item>
</portal_type>
......
......@@ -11,6 +11,7 @@ Event Module | Short Message
Event Module | Site Message
Event Module | Visit
Event Module | Web Message
Mail Message | Embedded File
Meeting Module | Meeting
Meeting | Event Path
Preference | Support Request
......
......@@ -160,9 +160,22 @@ class EmailDocument(TextDocument):
# Mail processing API
def _getMessage(self):
# Email Document is not a representation of SMTP payload, thus we no longer
# store it in 'data' property.
result = getattr(self, '_v_message', None)
if result is None:
result = message_from_string(str(self.getData()))
data = self.getData()
if not data:
# Generated a mail message temporarily to provide backward compatibility.
data = self.Base_createMailMessageAsString(
from_url='from@example.com',
to_url='to@example.com',
subject=self.getTitle() or '',
body=self.getTextContent() or '',
content_type=self.getContentType(),
embedded_file_list=self.getAggregateValueList(),
)
result = message_from_string(data)
self._v_message = result
return result
......
......@@ -525,8 +525,6 @@ class TestNotificationToolWithCRM(TestNotificationTool):
self.assertEqual(1, len(event_list))
event = event_list[0]
self.assertEqual(mail_dict['headers']['message-id'],
event.getSourceReference())
self.assertEqual('Mail Message', event.getPortalTypeName())
self.assertEqual('Subject', event.getTitle())
self.assertEqual('Message', event.getTextContent())
......
......@@ -71,7 +71,7 @@ if BaseMailTemplate is not None:
headers[header]=value
# check required values have been supplied
errors = []
for param in ('mfrom','mto','subject'):
for param in ('mfrom','mto'):
if not values.get(param):
errors.append(param)
if errors:
......
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