[FIX] mass_mailing: fixes:
- fixed keeping the original message for routing, only when choosing to reply in the original thread (notification=True) - auto delete sent emails explicitely - mail_thread: routing: fixed replies always choosen even when replying to emails with a specified reply_to (using ref_match in the algorithm) - mail_thread: routing: instead of exclusive routing heuristics, use each case as a fallback of the previous.
This commit is contained in:
parent
c319dc40e7
commit
cbdf7830b1
|
@ -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.' %
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue