[MERGE] Forward-port saas-3 up to e79a367
authorOlivier Dony <odo@openerp.com>
Fri, 1 Aug 2014 10:54:30 +0000 (12:54 +0200)
committerOlivier Dony <odo@openerp.com>
Fri, 1 Aug 2014 10:54:30 +0000 (12:54 +0200)
1  2 
addons/mail/mail_thread.py
openerp/osv/orm.py

@@@ -895,12 -859,14 +895,12 @@@ class mail_thread(osv.AbstractModel)
          thread_references = references or in_reply_to
  
          # 1. message is a reply to an existing message (exact match of message_id)
 +        ref_match = thread_references and tools.reference_re.search(thread_references)
-         msg_references = thread_references.split()
+         msg_references = mail_header_msgid_re.findall(thread_references)
          mail_message_ids = mail_msg_obj.search(cr, uid, [('message_id', 'in', msg_references)], context=context)
 -        if mail_message_ids:
 +        if ref_match and mail_message_ids:
              original_msg = mail_msg_obj.browse(cr, SUPERUSER_ID, mail_message_ids[0], context=context)
              model, thread_id = original_msg.model, original_msg.res_id
 -            _logger.info(
 -                'Routing mail from %s to %s with Message-Id %s: direct reply to msg: model: %s, thread_id: %s, custom_values: %s, uid: %s',
 -                email_from, email_to, message_id, model, thread_id, custom_values, uid)
              route = self.message_route_verify(
                  cr, uid, message, message_dict,
                  (model, thread_id, custom_values, uid, None),
                              cr, uid, message, message_dict,
                              (model, thread_id, custom_values, uid, None),
                              update_author=True, assert_model=True, create_fallback=True, context=context)
 -                        return route and [route] or []
 +                        if route:
 +                            _logger.info(
 +                                'Routing mail from %s to %s with Message-Id %s: direct thread reply (compat-mode) to model: %s, thread_id: %s, custom_values: %s, uid: %s',
 +                                email_from, email_to, message_id, model, thread_id, custom_values, uid)
 +                            return [route]
  
--        # 2. Reply to a private message
++        # 3. Reply to a private message
          if in_reply_to:
              mail_message_ids = mail_msg_obj.search(cr, uid, [
                                  ('message_id', '=', in_reply_to),
                  route = self.message_route_verify(cr, uid, message, message_dict,
                                  (mail_message.model, mail_message.res_id, custom_values, uid, None),
                                  update_author=True, assert_model=True, create_fallback=True, context=context)
 -                return route and [route] or []
 +                if route:
 +                    _logger.info(
 +                        'Routing mail from %s to %s with Message-Id %s: direct reply to a private message: %s, custom_values: %s, uid: %s',
 +                        email_from, email_to, message_id, mail_message.id, custom_values, uid)
 +                    return [route]
  
--        # 3. Look for a matching mail.alias entry
++        # 4. Look for a matching mail.alias entry
          # Delivered-To is a safe bet in most modern MTAs, but we have to fallback on To + Cc values
          # for all the odd MTAs out there, as there is no standard header for the envelope's `rcpt_to` value.
          rcpt_tos = \
                          routes.append(route)
                  return routes
  
--        # 4. Fallback to the provided parameters, if they work
++        # 5. Fallback to the provided parameters, if they work
          if not thread_id:
              # Legacy: fallback to matching [ID] in the Subject
              match = tools.res_re.search(decode_header(message, 'Subject'))
Simple merge