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 ...@@ -64,8 +64,6 @@ elif sender is not None:\n
else:\n else:\n
from_url = portal.portal_preferences.getPreferredEventSenderEmail()\n from_url = portal.portal_preferences.getPreferredEventSenderEmail()\n
\n \n
attachment_list = kw.pop(\'attachment_list\', [])\n
\n
to_url = formataddr((context.getTitle(), context.getDefaultEmailText()))\n to_url = formataddr((context.getTitle(), context.getDefaultEmailText()))\n
\n \n
document_type_list = list(event.getPortalEmbeddedDocumentTypeList()) + list(event.getPortalDocumentTypeList())\n document_type_list = list(event.getPortalEmbeddedDocumentTypeList()) + list(event.getPortalDocumentTypeList())\n
...@@ -77,7 +75,6 @@ mail_message = portal.Base_createMailMessageAsString(from_url,\n ...@@ -77,7 +75,6 @@ mail_message = portal.Base_createMailMessageAsString(from_url,\n
subject,\n subject,\n
body,\n body,\n
content_type,\n content_type,\n
attachment_list=attachment_list,\n
embedded_file_list=embedded_file_list)\n embedded_file_list=embedded_file_list)\n
\n \n
event.sendMailHostMessage(mail_message)\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 ...@@ -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 from email.utils import formataddr\n
portal = context.getPortalObject()\n portal = context.getPortalObject()\n
\n \n
if attachment_list is None:\n
attachment_list = []\n
use_activity = False\n use_activity = False\n
mail_message = None\n mail_message = None\n
to_url_list = []\n to_url_list = []\n
\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 if not context.isTempDocument() and to_url is None:\n
use_activity = True\n use_activity = True\n
\n \n
...@@ -79,10 +95,13 @@ if to_url is None:\n ...@@ -79,10 +95,13 @@ if to_url is None:\n
else:\n else:\n
to_url_list.append(to_url)\n to_url_list.append(to_url)\n
\n \n
if not context.hasStartDate():\n
context.setStartDate(DateTime())\n
\n
if download or not use_activity:\n if download or not use_activity:\n
for to_url in to_url_list:\n for to_url in to_url_list:\n
body = body or context.getTextContent()\n body = body or context.getTextContent() or \'\'\n
subject = subject or context.getTitle()\n subject = subject or context.getTitle() or \'\'\n
\n \n
# From\n # From\n
if from_url is None:\n if from_url is None:\n
...@@ -100,10 +119,6 @@ if download or not use_activity:\n ...@@ -100,10 +119,6 @@ if download or not use_activity:\n
additional_headers = None\n additional_headers = None\n
if reply_url:\n if reply_url:\n
additional_headers = {\'Return-Path\':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 \n
content_type = context.getContentType()\n content_type = context.getContentType()\n
\n \n
...@@ -112,7 +127,6 @@ if download or not use_activity:\n ...@@ -112,7 +127,6 @@ if download or not use_activity:\n
subject,\n subject,\n
body,\n body,\n
content_type,\n content_type,\n
attachment_list=attachment_list,\n
embedded_file_list=embedded_file_list)\n embedded_file_list=embedded_file_list)\n
\n \n
if not use_activity:\n if not use_activity:\n
...@@ -120,8 +134,7 @@ if download or not use_activity:\n ...@@ -120,8 +134,7 @@ if download or not use_activity:\n
\n \n
if use_activity:\n if use_activity:\n
method_kw = dict(event_relative_url=context.getRelativeUrl(),\n method_kw = dict(event_relative_url=context.getRelativeUrl(),\n
from_url=from_url,\n from_url=from_url)\n
attachment_list=attachment_list)\n
context.activate(\n context.activate(\n
after_path_and_method_id=((context.getPath(),), \n after_path_and_method_id=((context.getPath(),), \n
(\'immediateReindexObject\', \'recursiveImmediateReindexObject\'))).MailMessage_sendByActivity(\n (\'immediateReindexObject\', \'recursiveImmediateReindexObject\'))).MailMessage_sendByActivity(\n
......
...@@ -18,6 +18,9 @@ ...@@ -18,6 +18,9 @@
<item>Visit</item> <item>Visit</item>
<item>Web Message</item> <item>Web Message</item>
</portal_type> </portal_type>
<portal_type id="Mail Message">
<item>Embedded File</item>
</portal_type>
<portal_type id="Meeting"> <portal_type id="Meeting">
<item>Event Path</item> <item>Event Path</item>
</portal_type> </portal_type>
......
...@@ -11,6 +11,7 @@ Event Module | Short Message ...@@ -11,6 +11,7 @@ Event Module | Short Message
Event Module | Site Message Event Module | Site Message
Event Module | Visit Event Module | Visit
Event Module | Web Message Event Module | Web Message
Mail Message | Embedded File
Meeting Module | Meeting Meeting Module | Meeting
Meeting | Event Path Meeting | Event Path
Preference | Support Request Preference | Support Request
......
...@@ -160,9 +160,22 @@ class EmailDocument(TextDocument): ...@@ -160,9 +160,22 @@ class EmailDocument(TextDocument):
# Mail processing API # Mail processing API
def _getMessage(self): 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) result = getattr(self, '_v_message', None)
if result is 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 self._v_message = result
return result return result
......
...@@ -525,8 +525,6 @@ class TestNotificationToolWithCRM(TestNotificationTool): ...@@ -525,8 +525,6 @@ class TestNotificationToolWithCRM(TestNotificationTool):
self.assertEqual(1, len(event_list)) self.assertEqual(1, len(event_list))
event = event_list[0] event = event_list[0]
self.assertEqual(mail_dict['headers']['message-id'],
event.getSourceReference())
self.assertEqual('Mail Message', event.getPortalTypeName()) self.assertEqual('Mail Message', event.getPortalTypeName())
self.assertEqual('Subject', event.getTitle()) self.assertEqual('Subject', event.getTitle())
self.assertEqual('Message', event.getTextContent()) self.assertEqual('Message', event.getTextContent())
......
...@@ -71,7 +71,7 @@ if BaseMailTemplate is not None: ...@@ -71,7 +71,7 @@ if BaseMailTemplate is not None:
headers[header]=value headers[header]=value
# check required values have been supplied # check required values have been supplied
errors = [] errors = []
for param in ('mfrom','mto','subject'): for param in ('mfrom','mto'):
if not values.get(param): if not values.get(param):
errors.append(param) errors.append(param)
if errors: 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