summaryrefslogtreecommitdiff
path: root/addons/mail/mail_thread.py
diff options
context:
space:
mode:
authorAnael Closson <acl@odoo.com>2014-06-18 14:33:35 +0200
committerDenis Ledoux <dle@odoo.com>2014-09-01 13:51:08 +0200
commit0bee015dd67cb809fd235215b43d331074824e42 (patch)
tree634ea8f4c8caa56bfa0e548cea6b837e50c3a312 /addons/mail/mail_thread.py
parent18d365ce05494f0d7c5b353dcad19ee6dec5b4a9 (diff)
[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.
Diffstat (limited to 'addons/mail/mail_thread.py')
-rw-r--r--addons/mail/mail_thread.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py
index 5691cb9ac73..7ff1af038f0 100644
--- a/addons/mail/mail_thread.py
+++ b/addons/mail/mail_thread.py
@@ -29,6 +29,7 @@ import re
import socket
import time
import xmlrpclib
+import re
from email.message import Message
from openerp import tools
@@ -42,6 +43,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, []))))
@@ -916,13 +919,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]