From: Anael Closson Date: Wed, 18 Jun 2014 12:33:35 +0000 (+0200) Subject: [FIX] mail: more robust parsing of In-Reply-To/References (OPW 608919) X-Git-Tag: 8.0.0~25^2~24^2~112 X-Git-Url: http://git.inspyration.org/?a=commitdiff_plain;h=4bad513d29596abf2c614834a7592758186f0851;p=odoo%2Fodoo.git [FIX] mail: more robust parsing of In-Reply-To/References (OPW 608919) When parsing incoming messages, ignore white-space around In-Reply-To headers, and extract message-id items inside the References header using a regex. This actually serves as a workaround for broken MTAs mangling References (such as outlook.com nesting past ones with commas, violating RFC2822). Closes #516 as a manual rebase. --- diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index a264d58..8324b60 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -33,6 +33,7 @@ import pytz import socket import time import xmlrpclib +import re from email.message import Message from openerp import tools @@ -46,6 +47,8 @@ from openerp.tools.translate import _ _logger = logging.getLogger(__name__) +mail_header_msgid_re = re.compile('<[^<>]+>') + def decode_header(message, header, separator=' '): return separator.join(map(decode, filter(None, message.get_all(header, [])))) @@ -1259,13 +1262,13 @@ class mail_thread(osv.AbstractModel): msg_dict['date'] = stored_date.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT) if message.get('In-Reply-To'): - parent_ids = self.pool.get('mail.message').search(cr, uid, [('message_id', '=', decode(message['In-Reply-To']))]) + parent_ids = self.pool.get('mail.message').search(cr, uid, [('message_id', '=', decode(message['In-Reply-To'].strip()))]) if parent_ids: msg_dict['parent_id'] = parent_ids[0] if message.get('References') and 'parent_id' not in msg_dict: - parent_ids = self.pool.get('mail.message').search(cr, uid, [('message_id', 'in', - [x.strip() for x in decode(message['References']).split()])]) + msg_list = mail_header_msgid_re.findall(decode(message['References'])) + parent_ids = self.pool.get('mail.message').search(cr, uid, [('message_id', 'in', [x.strip() for x in msg_list])]) if parent_ids: msg_dict['parent_id'] = parent_ids[0]