From e9675ba178ea2142773b1bbd9c6e0c56523a60f0 Mon Sep 17 00:00:00 2001
From: Yusei Tahara <yusei@nexedi.com>
Date: Thu, 15 May 2008 17:35:46 +0000
Subject: [PATCH] Support attachment_list.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@20989 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Document/EmailDocument.py | 10 +++++++---
 product/ERP5/Document/Event.py         |  9 ++++++---
 product/ERP5/Tool/NotificationTool.py  |  9 ++++++++-
 3 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/product/ERP5/Document/EmailDocument.py b/product/ERP5/Document/EmailDocument.py
index 02361d560a..6cfd15934f 100644
--- a/product/ERP5/Document/EmailDocument.py
+++ b/product/ERP5/Document/EmailDocument.py
@@ -366,8 +366,7 @@ class EmailDocument(File, TextDocument):
 
   security.declareProtected(Permissions.UseMailhostServices, 'send')
   def send(self, from_url=None, to_url=None, reply_url=None, subject=None,
-                 body=None,
-                 attachment_format=None, download=False):
+           body=None, attachment_format=None, attachment_list=None, download=False):
     """
       Sends the current event content by email. If documents are
       attached through the aggregate category, enclose them.
@@ -391,6 +390,10 @@ class EmailDocument(File, TextDocument):
                  use the text representation of the event
                  as body (UTF-8)
 
+      attachment_list -- list of dictionary which contains raw data and
+                         name and mimetype for attachment.
+                         See NotificationTool.buildEmailMessage.
+
       attachment_format - defines an option format
                  to convet attachments to (ex. application/pdf)
 
@@ -449,7 +452,8 @@ class EmailDocument(File, TextDocument):
       to_url_list.append(to_url)
 
     # Attachments
-    attachment_list = []
+    if attachment_list is None:
+      attachment_list = []
     document_type_list = self.getPortalDocumentTypeList()
     for attachment in self.getAggregateValueList():
       mime_type = None
diff --git a/product/ERP5/Document/Event.py b/product/ERP5/Document/Event.py
index 03d28c84e1..77774e81c2 100644
--- a/product/ERP5/Document/Event.py
+++ b/product/ERP5/Document/Event.py
@@ -102,7 +102,8 @@ class Event(EmailDocument, Movement):
 
   security.declareProtected(Permissions.UseMailhostServices, 'send')
   def send(self, from_url=None, to_url=None, reply_url=None, subject=None,
-           body=None, attachment_format=None, download=False, **kw):
+           body=None, attachment_format=None, attachment_list=None,
+           download=False, **kw):
     """
       Make the send method overridable by typed based script
       so that special kinds of events can use a different gateway
@@ -115,8 +116,10 @@ class Event(EmailDocument, Movement):
     send_script = self._getTypeBasedMethod('send')
     if send_script is None:
       return Event.inheritedAttribute('send')(
-          self, from_url, to_url, reply_url, subject, body, attachment_format, download
+          self, from_url, to_url, reply_url, subject, body, attachment_format,
+          attachment_list, download
           )
     return send_script(
-        from_url, to_url, reply_url, subject, body, attachment_format, download, **kw
+        from_url, to_url, reply_url, subject, body, attachment_format, attachment_list,
+        download, **kw
         )
diff --git a/product/ERP5/Tool/NotificationTool.py b/product/ERP5/Tool/NotificationTool.py
index bee38b40dd..2d759fefed 100644
--- a/product/ERP5/Tool/NotificationTool.py
+++ b/product/ERP5/Tool/NotificationTool.py
@@ -221,7 +221,8 @@ class NotificationTool(BaseTool):
   # high-level interface
   security.declareProtected(Permissions.UseMailhostServices, 'sendMessage')
   def sendMessage(self, sender=None, recipient=None, subject=None,
-                  message=None, attachment_document_list=None,
+                  message=None,
+                  attachment_list=None, attachment_document_list=None,
                   notifier_list=None, priority_level=None,
                   store_as_event=False,
                   message_text_format='text/plain',
@@ -243,6 +244,10 @@ class NotificationTool(BaseTool):
 
       message -- the text of the message (already translated)
 
+      attachment_list -- list of dictionary which contains raw data and
+                         name and mimetype for attachment.
+                         See buildEmailMessage.
+
       attachment_document_list -- list of document (optional)
                                   which will be attachment.
 
@@ -302,6 +307,8 @@ class NotificationTool(BaseTool):
       low_level_kw['from_url'] = default_from_email
     if not to_person_list:
       low_level_kw['to_url'] = default_to_email
+    if attachment_list is not None:
+      low_level_kw['attachment_list'] = attachment_list
 
     # Make event
     available_notifier_list = self.getNotifierList()
-- 
2.30.9