예제 #1
0
    def message_partner_by_email(self, cr, uid, email, context=None):
        """Attempts to return the id of a partner address matching
           the given ``email``, and the corresponding partner id.
           Can be used by classes using the ``mail.thread`` mixin
           to lookup the partner and use it in their implementation
           of ``message_new`` to link the new record with a
           corresponding partner.
           The keys used in the returned dict are meant to map
           to usual names for relationships towards a partner
           and one of its addresses.
           
           :param email: email address for which a partner
                         should be searched for.
           :rtype: dict
           :return: a map of the following form::

                      { 'partner_address_id': id or False,
                        'partner_id': pid or False }
        """
        address_pool = self.pool.get('res.partner.address')
        res = {'partner_address_id': False, 'partner_id': False}
        if email:
            email = to_email(email) and to_email(email)[0]
        if email:
            address_ids = address_pool.search(cr, uid, [('email', '=', email)])
            if address_ids:
                address = address_pool.browse(cr, uid, address_ids[0])
                res['partner_address_id'] = address_ids[0]
                res['partner_id'] = address.partner_id.id
        return res
예제 #2
0
    def message_partner_by_email(self, cr, uid, email, context=None):
        """Attempts to return the id of a partner address matching
           the given ``email``, and the corresponding partner id.
           Can be used by classes using the ``mail.thread`` mixin
           to lookup the partner and use it in their implementation
           of ``message_new`` to link the new record with a
           corresponding partner.
           The keys used in the returned dict are meant to map
           to usual names for relationships towards a partner
           and one of its addresses.
           
           :param email: email address for which a partner
                         should be searched for.
           :rtype: dict
           :return: a map of the following form::

                      { 'partner_address_id': id or False,
                        'partner_id': pid or False }
        """
        address_pool = self.pool.get('res.partner.address')
        res = {
            'partner_address_id': False,
            'partner_id': False
        }
        if email:
            email = to_email(email) and to_email(email)[0]
        if email:
            address_ids = address_pool.search(cr, uid, [('email', '=', email)])
            if address_ids:
                address = address_pool.browse(cr, uid, address_ids[0])
                res['partner_address_id'] = address_ids[0]
                res['partner_id'] = address.partner_id.id
        return res
예제 #3
0
    def message_forward(self,
                        cr,
                        uid,
                        model,
                        thread_ids,
                        msg,
                        email_error=False,
                        context=None):
        """Sends an email to all people following the given threads.
           The emails are forwarded immediately, not queued for sending,
           and not archived.

        :param str model: thread model
        :param list thread_ids: ids of the thread records
        :param msg: email.message.Message object to forward
        :param email_error: optional email address to notify in case
                            of any delivery error during the forward.
        :return: True
        """
        model_pool = self.pool.get(model)
        smtp_server_obj = self.pool.get('ir.mail_server')
        for res in model_pool.browse(cr, uid, thread_ids, context=context):
            if hasattr(model_pool, 'message_thread_followers'):
                followers = model_pool.message_thread_followers(
                    cr, uid, [res.id])[res.id]
            else:
                followers = self.message_thread_followers(cr, uid,
                                                          [res.id])[res.id]
            message_followers_emails = to_email(','.join(
                filter(None, followers)))
            message_recipients = to_email(','.join(
                filter(None, [
                    decode(msg['From']),
                    decode(msg['To']),
                    decode(msg['Cc'])
                ])))
            forward_to = [
                i for i in message_followers_emails
                if (i and (i not in message_recipients))
            ]
            if forward_to:
                # TODO: we need an interface for this for all types of objects, not just leads
                if hasattr(res, 'section_id'):
                    del msg['Reply-To']
                    msg['Reply-To'] = res.section_id.reply_to

                smtp_from, = to_email(msg['From'])
                del msg['From'], msg['To'], msg['Cc'], msg['Message-Id']
                msg['From'] = smtp_from
                msg['To'] = ", ".join(forward_to)
                msg['Message-Id'] = tools.generate_tracking_message_id(res.id)
                if not smtp_server_obj.send_email(cr, uid,
                                                  msg) and email_error:
                    subj = msg['Subject']
                    del msg['Subject'], msg['To'], msg['Cc']
                    msg['Subject'] = _('[OpenERP-Forward-Failed] %s') % subj
                    msg['To'] = email_error
                    smtp_server_obj.send_email(cr, uid, msg)
        return True
예제 #4
0
    def message_forward(self, cr, uid, model, thread_ids, msg, email_error=False, context=None):
        """Sends an email to all people following the given threads.
           The emails are forwarded immediately, not queued for sending,
           and not archived.

        :param str model: thread model
        :param list thread_ids: ids of the thread records
        :param msg: email.message.Message object to forward
        :param email_error: optional email address to notify in case
                            of any delivery error during the forward.
        :return: True
        """
        model_pool = self.pool.get(model)
        smtp_server_obj = self.pool.get('ir.mail_server')
        for res in model_pool.browse(cr, uid, thread_ids, context=context):
            if hasattr(model_pool, 'message_thread_followers'):
                followers = model_pool.message_thread_followers(cr, uid, [res.id])[res.id]
            else:
                followers = self.message_thread_followers(cr, uid, [res.id])[res.id]
            message_followers_emails = to_email(','.join(filter(None, followers)))
            message_recipients = to_email(','.join(filter(None,
                                                                       [decode(msg['From']),
                                                                        decode(msg['To']),
                                                                        decode(msg['Cc'])])))
            forward_to = [i for i in message_followers_emails if (i and (i not in message_recipients))]
            if forward_to:
                # TODO: we need an interface for this for all types of objects, not just leads
                if hasattr(res, 'section_id'):
                    del msg['Reply-To']
                    msg['Reply-To'] = res.section_id.reply_to

                smtp_from, = to_email(msg['From'])
                del msg['From'], msg['To'], msg['Cc'], msg['Message-Id']
                msg['From'] = smtp_from
                msg['To'] =  ", ".join(forward_to)
                msg['Message-Id'] = tools.generate_tracking_message_id(res.id)
                if not smtp_server_obj.send_email(cr, uid, msg) and email_error:
                    subj = msg['Subject']
                    del msg['Subject'], msg['To'], msg['Cc']
                    msg['Subject'] = _('[OpenERP-Forward-Failed] %s') % subj
                    msg['To'] = email_error
                    smtp_server_obj.send_email(cr, uid, msg)
        return True