summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibault Delavallée <tde@openerp.com>2014-06-03 12:03:42 +0200
committerThibault Delavallée <tde@openerp.com>2014-06-03 12:03:42 +0200
commitc1b2b657fa653bfe30b818afcf1fc17fd58c0116 (patch)
tree14d681de5a43a815fdb1f18a787bb06c47ef4dec
parentaa1165441c880f248cb4c7df23e5590a7e8a43ca (diff)
parentcbdf7830b1cc75a57f3a473f6199032cd4123378 (diff)
Merge pull request #288 from odoo-dev/saas-4-mass_mailing_fixes-tde
[FIX] mass_mailing: fixes - backport (+ cleaning) of eb22d202e48068a82ddcfa3878dbe0cbb845cc9c (saas-5): mail_thread: routing: instead of exclusive routing heuristics, use each case as a fallback of the previous. - better fix for dd36a0e5093df90bd92667d26f529a3a79fe0397 (saas-5): mail_thread: routing: fixed replies always choosen even when replying to emails with a specified reply_to (using ref_match in the algorithm) - backport of d6a2ae642b1a48ce6cb227c3cde2deca847a0a33 (saas-5): avoid evaluating a False / None domain - fixed keeping the original message for routing, only when choosing to reply in the original thread (notification=True) - mail_thread: routing: fixed replies always chosen even when replying to emails with a specified reply_to (using ref_match in the algorithm)
-rw-r--r--addons/mail/mail_thread.py44
-rw-r--r--addons/mass_mailing/models/mass_mailing.py9
-rw-r--r--addons/mass_mailing/wizard/mail_compose_message.py17
3 files changed, 43 insertions, 27 deletions
diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py
index 3cc2f60ed69..9acfb07c13b 100644
--- a/addons/mail/mail_thread.py
+++ b/addons/mail/mail_thread.py
@@ -879,22 +879,23 @@ 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()
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),
- update_author=True, assert_model=True, create_fallback=True, context=context)
- return route and [route] or []
+ update_author=True, assert_model=False, create_fallback=True, context=context)
+ if route:
+ _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)
+ return [route]
# 2. message is a reply to an existign thread (6.1 compatibility)
- ref_match = thread_references and tools.reference_re.search(thread_references)
if ref_match:
reply_thread_id = int(ref_match.group(1))
reply_model = ref_match.group(2) or fallback_model
@@ -912,14 +913,15 @@ class mail_thread(osv.AbstractModel):
('res_id', '=', thread_id),
], context=context)
if compat_mail_msg_ids and model_obj.exists(cr, uid, thread_id) and hasattr(model_obj, 'message_update'):
- _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)
route = self.message_route_verify(
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
if in_reply_to:
@@ -929,12 +931,14 @@ class mail_thread(osv.AbstractModel):
], limit=1, context=context)
if mail_message_ids:
mail_message = mail_msg_obj.browse(cr, uid, mail_message_ids[0], context=context)
- _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)
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
# Delivered-To is a safe bet in most modern MTAs, but we have to fallback on To + Cc values
@@ -962,11 +966,12 @@ class mail_thread(osv.AbstractModel):
user_id = uid
_logger.info('No matching user_id for the alias %s', alias.alias_name)
route = (alias.alias_model_id.model, alias.alias_force_thread_id, eval(alias.alias_defaults), user_id, alias)
- _logger.info('Routing mail from %s to %s with Message-Id %s: direct alias match: %r',
- email_from, email_to, message_id, route)
route = self.message_route_verify(cr, uid, message, message_dict, route,
update_author=True, assert_model=True, create_fallback=True, context=context)
if route:
+ _logger.info(
+ 'Routing mail from %s to %s with Message-Id %s: direct alias match: %r',
+ email_from, email_to, message_id, route)
routes.append(route)
return routes
@@ -980,15 +985,16 @@ class mail_thread(osv.AbstractModel):
thread_id = int(thread_id)
except:
thread_id = False
- _logger.info('Routing mail from %s to %s with Message-Id %s: fallback to model:%s, thread_id:%s, custom_values:%s, uid:%s',
- email_from, email_to, message_id, fallback_model, thread_id, custom_values, uid)
route = self.message_route_verify(cr, uid, message, message_dict,
(fallback_model, thread_id, custom_values, uid, None),
update_author=True, assert_model=True, context=context)
if route:
+ _logger.info(
+ 'Routing mail from %s to %s with Message-Id %s: fallback to model:%s, thread_id:%s, custom_values:%s, uid:%s',
+ email_from, email_to, message_id, fallback_model, thread_id, custom_values, uid)
return [route]
- # AssertionError if no routes found and if no bounce occured
+ # ValueError if no routes found and if no bounce occured
raise ValueError(
'No possible route found for incoming message from %s to %s (Message-Id %s:). '
'Create an appropriate mail.alias or force the destination model.' %
diff --git a/addons/mass_mailing/models/mass_mailing.py b/addons/mass_mailing/models/mass_mailing.py
index f721ed2f385..bfeb3aeeafe 100644
--- a/addons/mass_mailing/models/mass_mailing.py
+++ b/addons/mass_mailing/models/mass_mailing.py
@@ -532,8 +532,12 @@ class MassMailing(osv.Model):
#------------------------------------------------------
def get_recipients(self, cr, uid, mailing, context=None):
- domain = eval(mailing.mailing_domain)
- res_ids = self.pool[mailing.mailing_model].search(cr, uid, domain, context=context)
+ if mailing.mailing_domain:
+ domain = eval(mailing.mailing_domain)
+ res_ids = self.pool[mailing.mailing_model].search(cr, uid, domain, context=context)
+ else:
+ res_ids = []
+ domain = [('id', 'in', res_ids)]
# randomly choose a fragment
if mailing.contact_ab_pc < 100:
@@ -567,6 +571,7 @@ class MassMailing(osv.Model):
'composition_mode': 'mass_mail',
'mass_mailing_id': mailing.id,
'mailing_list_ids': [(4, l.id) for l in mailing.contact_list_ids],
+ 'same_thread': mailing.reply_to_mode == 'thread',
}
if mailing.reply_to_mode == 'email':
composer_values['reply_to'] = mailing.reply_to
diff --git a/addons/mass_mailing/wizard/mail_compose_message.py b/addons/mass_mailing/wizard/mail_compose_message.py
index 4aebff2d04d..ede3fe37803 100644
--- a/addons/mass_mailing/wizard/mail_compose_message.py
+++ b/addons/mass_mailing/wizard/mail_compose_message.py
@@ -43,10 +43,15 @@ class MailComposeMessage(osv.TransientModel):
}, context=context)
mass_mailing = self.pool['mail.mass_mailing'].browse(cr, uid, mass_mailing_id, context=context)
for res_id in res_ids:
- res[res_id]['mailing_id'] = mass_mailing.id
- res[res_id]['statistics_ids'] = [(0, 0, {
- 'model': wizard.model,
- 'res_id': res_id,
- 'mass_mailing_id': mass_mailing.id,
- })]
+ res[res_id].update({
+ 'mailing_id': mass_mailing.id,
+ 'statistics_ids': [(0, 0, {
+ 'model': wizard.model,
+ 'res_id': res_id,
+ 'mass_mailing_id': mass_mailing.id,
+ })],
+ # email-mode: keep original message for routing
+ 'notification': mass_mailing.reply_to_mode == 'thread',
+ 'auto_delete': True,
+ })
return res