[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.
This commit is contained in:
parent
18d365ce05
commit
0bee015dd6
|
@ -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]
|
||||
|
||||
|
|
Loading…
Reference in New Issue