[FIX] mail.thread: avoid wrongly matching model,id from a foreign OpenERP system

When emails transit from an OpenERP system to another
there is a chance of wrongly considering the foreign
model,id pair as local, possibly attaching a reply
to a wrong parent message.
This naive heuristic ignore the foreign identifiers
unless the hostname of the message-id mentioned in
the In-Reply-To header matches the local one.
This may fail after a change of local hostname but
is still better than the alternative.
In OpenERP v8 we should stop including the model,res_id
in outgoing Message-Id headers and only rely on the
stored, opaque, unique Message-Ids, preventing
any future mismatch.

bzr revid: odo@openerp.com-20140411101349-h3jmkdzvbr7lut26
This commit is contained in:
Olivier Dony 2014-04-11 12:13:49 +02:00
parent 63e9150cff
commit 4ed8413dc7
1 changed files with 6 additions and 1 deletions

View File

@ -26,6 +26,7 @@ import email
import logging import logging
import pytz import pytz
import re import re
import socket
import time import time
import xmlrpclib import xmlrpclib
from email.message import Message from email.message import Message
@ -539,8 +540,12 @@ class mail_thread(osv.AbstractModel):
if ref_match: if ref_match:
thread_id = int(ref_match.group(1)) thread_id = int(ref_match.group(1))
model = ref_match.group(2) or model model = ref_match.group(2) or model
our_hostname = socket.gethostname()
reply_to_hostname = ref_match.group(3)
# do not match forwarded emails from another OpenERP system (thread_id collision!)
is_reply_to_local = (our_hostname == reply_to_hostname)
model_pool = self.pool.get(model) model_pool = self.pool.get(model)
if thread_id and model and model_pool and model_pool.exists(cr, uid, thread_id) \ if thread_id and is_reply_to_local and model and model_pool and model_pool.exists(cr, uid, thread_id) \
and hasattr(model_pool, 'message_update'): and hasattr(model_pool, 'message_update'):
_logger.info('Routing mail from %s to %s with Message-Id %s: direct reply to model: %s, thread_id: %s, custom_values: %s, uid: %s', _logger.info('Routing mail from %s to %s with Message-Id %s: direct reply to model: %s, thread_id: %s, custom_values: %s, uid: %s',
email_from, email_to, message_id, model, thread_id, custom_values, uid) email_from, email_to, message_id, model, thread_id, custom_values, uid)