sendable.py 5.46 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2009 Nexedi SA and Contributors. All Rights Reserved.
#                    Jean-Paul Smets-Solanes <jp@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
##############################################################################
29 30 31
"""
Products.ERP5.interfaces.sendable
"""
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129

from zope.interface import Interface

class ISendable(Interface):
  """
    Common Interface for all documents which can be sent.
    The notion of sending a document is independent of the 
    kind of transport. A document can be sent by email, 
    by fax, by chat, by printing it out, etc. The recipients are
    defined by the 'send' method, which can usually be overloaded
    through type based methods in order to implement all
    kinds of policies (ex. cc any sent invoice to a given 
    mailing list, selected based on some predicate information
    stored on email addresses of the Person or Organisation).

    Sent messages all use a common format: MIMEMultipart. Tools
    are invoked to send content. Tools must thus support MIMEMultipart
    and implement the IMIMESender interface.

    Sent messages can be recorded in the form of Event instances.
  """

  def send(from_url=None, to_url=None, cc_url=None, bcc_url=None,
           reply_url=None, subject=None, body=None, body_encoding=None,
           attachment_format=None, attachment_list=None, mime_sender=None,
           download=False, **kw):
    """
      High-level interface. The purpose of this method is to implement
      the sending logic ie. select recipients, select the tool to send
      the message, etc. Content of the message can either derive from
      document properties or can be provided through the 'body' a parameter.
      This method is not supposed to generate the actual message envelope.
      This is the role of asMIMEMultipart (bellow).

      from_url -- the sender of this email. If not provided
                  we will use source to find a valid
                  email address

      to_url   -- the recipients of this email. If not provided
                 we will use destination category to 
                 find a list of valid email addresses

      cc_url   -- the Cc recipients of this email (optional)

      bcc_url  -- the Bcc recipients of this email (optional)

      reply_url -- the email address to reply to. If nothing
                   is provided, use the email defined in 
                   preferences. (XXX)

      subject  -- a custom title. If not provided, we will use
                  getTitle XXX (getTranslatedTitle)

      body     -- a body message. If not provided, we will
                  use the text representation of the event
                  as body (UTF-8)

      body_encoding   -- the text encoding for the message body. 
                         this is required to send emails in countries
                         such as Japan where UTF-8 is not favoured

      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 convert attachments to (ex. application/pdf)

      download -- if set to True returns, the message online
                 rather than sending it.

      language -- selects the language to use for message generation
                  (ex. printout language, mail template language, content, etc.)
                   etc

      mime_sender -- the sender tool to use to send the message (optional)

      **kw -- optional parameters
    """
    pass

  def asMIMEMultipart(from_url, to_url,
                      cc_url=None, bcc_url=None,
                      reply_url=None, subject=None,
                      body=None, body_encoding=None, 
                      attachment_list=None,
                      attachment_format=None,
                      extra_header_dict=None, 
                      additional_header_dict=None,
                      **kw):
    """
      Low-level interface. Build a MIMEMultipart instance based on 
      the parameters and on the document content. Recipients
      must be provided explicitely. Actual MIMEMultipart generation
      uses mailtemplates.
    """
    pass

Sebastien Robin's avatar
Sebastien Robin committed
130
  def getMIMEMultipartLogList(mime_sender=None):
131 132 133
    """
      Retrieve the list of messages sent based on the current document
    """
Sebastien Robin's avatar
Sebastien Robin committed
134
    pass