Пример #1
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
Пример #2
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
Пример #3
0
 def create(self, cr, uid, values, context=None):
     if not values.get('message_id') and values.get('res_id') and values.get('model'):
         values['message_id'] = tools.generate_tracking_message_id('%(res_id)s-%(model)s' % values)
     newid = super(mail_message, self).create(cr, uid, values, context)
     self._notify(cr, SUPERUSER_ID, newid, context=context)
     return newid