示例#1
0
    def prepare_message(self, obj, message, data=None):
        '''Replace message References by query method data result.

        '''
        del message['References']
        message['References'] = encode_header(data['references'])
        return TransportRouteData(message, {})
示例#2
0
 def prepare_message(self, obj, message, data=None):
     thread_index = data['thread_index']
     address = data['replyto_address']
     self._set_replyto_address(obj, message, address)
     # The 'Thread-Index' is just to f**k some Microsoft Offices out there
     # that are not including the References.
     message['X-Odoo-Thread-Index'] = message['Thread-Index'] = thread_index
     return TransportRouteData(message, {})
示例#3
0
    def prepare_message(self, obj, message, data=None):
        '''Add the bounce address to the message.

        '''
        address = data['address']
        del message['Return-Path']  # Ensure a single Return-Path
        message['Return-Path'] = address
        if message['Disposition-Notification-To']:
            # Any disposition request will be invalid after the Return-Path is
            # changed.  See RFC 3798 section 2.1.
            del message['Disposition-Notification-To']
            message = address
        return TransportRouteData(message, {})
示例#4
0
    def prepare_message(self, obj, message, data=None):
        '''Remove new line character from message subject.

        '''
        # We need the safe_encode because we can get a email.header.Header
        # instance instead of text.  Also, safe_decode normalizes to unicode
        # so that we avoid any UnicodeError.
        subject = safe_decode(decode(safe_encode(message['subject'])))
        # Remove new line character
        subject = subject.replace(u'\n', u' ')
        del message['subject']  # Ensure a single subject
        message['subject'] = encode_header(subject)
        return TransportRouteData(message, {})
示例#5
0
 def prepare_message(self, obj, message, data=None):
     import email
     from xoutil.future.codecs import safe_encode
     _, refs = self.get_message_objects(obj, message)
     connection_data = {}
     if refs:
         # It seems OpenERP always uses the "original" message-id in the
         # references.  At least, for outgoing messages.
         parent = refs[0]
         mail = email.message_from_string(safe_encode(parent.raw_email))
         server = self.origin_server(obj, mail)
         originators = self.get_authors(mail, msg=parent)
         recipients = self.get_recipients(message)
         # Only use this server for messages going to the originators,
         # i.e the authors of the parent email.
         if server and (set(recipients) & set(originators)):
             _logger.info(
                 'SMTP outgoing server %s will send message %s',
                 server.name,
                 message['Message-Id'],
             )
             connection_data.update(mail_server_id=server.id)
             address = server.delivered_address
             # Ensure the Return-Path is used for the envelop and
             # matches the Sender (not necessarily the From).  The
             # Reply-To also changes, it is assumed you'll have a
             # matching POP/IMAP incoming fetchmail server for the same
             # account.
             del message['Reply-To'], message['Sender']
             message['Sender'] = address
             message['Reply-To'] = address
         else:
             _logger.info(
                 'Default SMTP server for message %s, going to %s',
                 message['Message-Id'],
                 recipients,
             )
     return TransportRouteData(message, connection_data)
示例#6
0
 def prepare_message(self, obj, message, data=None):
     address = data  # data is always a keyword argument.
     self._set_headers(obj, message, address)
     return TransportRouteData(message, {})