Commit b3ff78f0 authored by Jérome Perrin's avatar Jérome Perrin

Move Event_send logic of sending email in MailMessage_send.

We only want to send an email for mail message portal type
parent f65e20ce
......@@ -50,102 +50,10 @@
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>from email.utils import formataddr\n
from email import message_from_string\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
if not context.isTempDocument() and to_url is None:\n
use_activity = True\n
\n
if to_url is None:\n
if use_activity:\n
recipient = context.getDestinationValue()\n
to_url_list.append(formataddr((recipient.getTitle(), recipient.getDefaultEmailText())))\n
else:\n
to_email_list = []\n
for recipient in context.getDestinationValueList():\n
email = recipient.getDefaultEmailText()\n
if email:\n
to_email_list.append(email)\n
to_url_list.append(formataddr((recipient.getTitle(), recipient.getDefaultEmailText())))\n
else:\n
raise ValueError("One email must be set to %s" % recipient.getRelativeUrl())\n
else:\n
to_url_list.append(to_url)\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
\n
# From\n
if from_url is None:\n
sender = context.getSourceValue()\n
from_url = formataddr((sender.getTitle(), sender.getDefaultEmailText()))\n
\n
# Return-Path\n
if reply_url is None:\n
reply_url = portal.portal_preferences.getPreferredEventSenderEmail()\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
mail_message = context.Base_createMailMessageAsString(from_url, \n
to_url,\n
subject,\n
body,\n
content_type,\n
attachment_list=attachment_list,\n
embedded_file_list=embedded_file_list)\n
\n
if len(embedded_file_list):\n
# do not store aggregated documents in Email document\n
# to avoid duplicate data\n
tmp_mail_message = context.Base_createMailMessageAsString(from_url,\n
to_url,\n
subject,\n
body,\n
content_type,\n
attachment_list=attachment_list)\n
context.setData(tmp_mail_message)\n
else:\n
context.setData(mail_message)\n
if not use_activity:\n
context.activate(activity=\'SQLQueue\').sendMailHostMessage(mail_message)\n
\n
if use_activity:\n
destination_list = context.getDestinationValueList()\n
path_list = [x.getPath() for x in destination_list]\n
uid_list = [x.getUid() for x in destination_list]\n
method_kw = dict(event_relative_url=context.getRelativeUrl(),\n
from_url=from_url,\n
attachment_list=attachment_list)\n
context.activate(\n
after_path_and_method_id=(path_list, \n
(\'immediateReindexObject\', \'recursiveImmediateReindexObject\'))).Event_sendByActivity(\n
uid_list=uid_list,\n
method_kw=method_kw, **kw)\n
\n
# Transit event workflow\n
if context.getTypeInfo() is not None:\n
for transition_id in \'plan\', \'order\', \'start\':\n
if portal.portal_workflow.isTransitionPossible(context, transition_id):\n
getattr(context, transition_id)()\n
\n
if download:\n
return mail_message\n
<value> <string>"""Event send does nothing by default, it has to be implemented for each kind\n
of event, look at MailMessage_send for example.\n
"""\n
pass\n
</string> </value>
</item>
<item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>"""Send a mail message.\n
\n
This script is used by notification tool, that\'s why it is in erp5_base.\n
"""\n
\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
if not context.isTempDocument() and to_url is None:\n
use_activity = True\n
\n
if to_url is None:\n
if use_activity:\n
recipient = context.getDestinationValue()\n
to_url_list.append(formataddr((recipient.getTitle(), recipient.getDefaultEmailText())))\n
else:\n
to_email_list = []\n
for recipient in context.getDestinationValueList():\n
email = recipient.getDefaultEmailText()\n
if email:\n
to_email_list.append(email)\n
to_url_list.append(formataddr((recipient.getTitle(), recipient.getDefaultEmailText())))\n
else:\n
raise ValueError("One email must be set to %s" % recipient.getRelativeUrl())\n
else:\n
to_url_list.append(to_url)\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
\n
# From\n
if from_url is None:\n
sender = context.getSourceValue()\n
from_url = formataddr((sender.getTitle(), sender.getDefaultEmailText()))\n
if not from_url:\n
from_url = portal.portal_preferences.getPreferredEventSenderEmail()\n
if not from_url:\n
raise ValueError(\'Preferred Event Sender Email not configured\')\n
\n
# Return-Path\n
if reply_url is None:\n
reply_url = portal.portal_preferences.getPreferredEventSenderEmail()\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
mail_message = context.Base_createMailMessageAsString(from_url, \n
to_url,\n
subject,\n
body,\n
content_type,\n
attachment_list=attachment_list,\n
embedded_file_list=embedded_file_list)\n
\n
if len(embedded_file_list):\n
# do not store aggregated documents in Email document\n
# to avoid duplicate data\n
tmp_mail_message = context.Base_createMailMessageAsString(from_url,\n
to_url,\n
subject,\n
body,\n
content_type,\n
attachment_list=attachment_list)\n
context.setData(tmp_mail_message)\n
else:\n
context.setData(mail_message)\n
if not use_activity:\n
context.activate(activity=\'SQLQueue\').sendMailHostMessage(mail_message)\n
\n
if use_activity:\n
destination_list = context.getDestinationValueList()\n
path_list = [x.getPath() for x in destination_list]\n
uid_list = [x.getUid() for x in destination_list]\n
method_kw = dict(event_relative_url=context.getRelativeUrl(),\n
from_url=from_url,\n
attachment_list=attachment_list)\n
context.activate(\n
after_path_and_method_id=(path_list, \n
# XXX Event_sendByActivity only applies to Mail Message at the moment.\n
# We should either renamted it to MailMessage_ or make this logic available to \n
# all kind of events.\n
(\'immediateReindexObject\', \'recursiveImmediateReindexObject\'))).Event_sendByActivity(\n
uid_list=uid_list,\n
method_kw=method_kw, **kw)\n
\n
if download:\n
return mail_message\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>from_url=None, to_url=None, reply_url=None, subject=None, body=None, attachment_format=None, attachment_list=None, download=None, **kw</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
<value>
<tuple>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>MailMessage_send</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
1054
\ No newline at end of file
1055
\ No newline at end of file
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