summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Martinelli <nim@odoo.com>2015-06-23 16:34:53 +0200
committerNicolas Martinelli <nim@odoo.com>2015-06-30 12:39:03 +0200
commitf498583a988f055f49ce14d2669b32b1073d6800 (patch)
treec9813c51e93533d9c2978e36ab9a35f2fcb5368b
parent6ceb41dae44df50511e6e6c167408e6b329f9656 (diff)
[FIX] mail: make sure to send bouncing email even if the mail is a direct reply
This could happen if a partner is removed from the list of followers. opw-633988
-rw-r--r--addons/mail/mail_thread.py32
1 files changed, 21 insertions, 11 deletions
diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py
index 8217b18f5ff..a2c5ae39772 100644
--- a/addons/mail/mail_thread.py
+++ b/addons/mail/mail_thread.py
@@ -836,7 +836,7 @@ class mail_thread(osv.AbstractModel):
if not message_dict.get('parent_id'):
raise ValueError('Routing: posting a message without model should be with a parent_id (private mesage).')
_warn('posting a message without model should be with a parent_id (private mesage), skipping')
- return ()
+ return False
# Existing Document: check if exists; if not, fallback on create if allowed
if thread_id and not model_pool.exists(cr, uid, thread_id):
@@ -847,7 +847,7 @@ class mail_thread(osv.AbstractModel):
assert model_pool.exists(cr, uid, thread_id), 'Routing: reply to missing document (%s,%s)' % (model, thread_id)
else:
_warn('reply to missing document (%s,%s), skipping' % (model, thread_id))
- return ()
+ return False
# Existing Document: check model accepts the mailgateway
if thread_id and model and not hasattr(model_pool, 'message_update'):
@@ -858,7 +858,7 @@ class mail_thread(osv.AbstractModel):
assert hasattr(model_pool, 'message_update'), 'Routing: model %s does not accept document update, crashing' % model
else:
_warn('model %s does not accept document update, skipping' % model)
- return ()
+ return False
# New Document: check model accepts the mailgateway
if not thread_id and model and not hasattr(model_pool, 'message_new'):
@@ -868,7 +868,7 @@ class mail_thread(osv.AbstractModel):
'Model %s does not accept document creation, crashing' % model
)
_warn('model %s does not accept document creation, skipping' % model)
- return ()
+ return False
# Update message author if asked
# We do it now because we need it for aliases (contact settings)
@@ -887,16 +887,16 @@ class mail_thread(osv.AbstractModel):
if not author_id or not author_id in [fol.id for fol in obj.message_follower_ids]:
_warn('alias %s restricted to internal followers, skipping' % alias.alias_name)
_create_bounce_email()
- return ()
+ return False
elif alias and alias.alias_contact == 'partners' and not author_id:
_warn('alias %s does not accept unknown author, skipping' % alias.alias_name)
_create_bounce_email()
- return ()
+ return False
if not model and not thread_id and not alias and not allow_private:
return ()
- return (model, thread_id, route[2], route[3], route[4])
+ return (model, thread_id, route[2], route[3], None if context.get('drop_alias', False) else route[4])
def message_route(self, cr, uid, message, message_dict, model=None, thread_id=None,
custom_values=None, context=None):
@@ -936,6 +936,7 @@ class mail_thread(osv.AbstractModel):
if not isinstance(message, Message):
raise TypeError('message must be an email.message.Message at this point')
mail_msg_obj = self.pool['mail.message']
+ mail_alias = self.pool.get('mail.alias')
fallback_model = model
# Get email.message.Message variables for future processing
@@ -963,15 +964,21 @@ class mail_thread(osv.AbstractModel):
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
+ alias_ids = mail_alias.search(cr, uid, [('alias_name', '=', (tools.email_split(email_to) or [''])[0].split('@', 1)[0].lower())])
+ alias = None
+ if alias_ids:
+ alias = mail_alias.browse(cr, uid, [alias_ids[0]], context=context)
route = self.message_route_verify(
cr, uid, message, message_dict,
- (model, thread_id, custom_values, uid, None),
- update_author=True, assert_model=False, create_fallback=True, context=context)
+ (model, thread_id, custom_values, uid, alias),
+ update_author=True, assert_model=False, create_fallback=True, context=dict(context, drop_alias=True))
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]
+ elif route is False:
+ return []
# 2. message is a reply to an existign thread (6.1 compatibility)
if ref_match:
@@ -1000,6 +1007,8 @@ class mail_thread(osv.AbstractModel):
'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]
+ elif route is False:
+ return []
# 3. Reply to a private message
if in_reply_to:
@@ -1017,6 +1026,8 @@ class mail_thread(osv.AbstractModel):
'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]
+ elif route is False:
+ return []
# 4. 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
@@ -1029,7 +1040,6 @@ class mail_thread(osv.AbstractModel):
decode_header(message, 'Resent-Cc')])
local_parts = [e.split('@')[0] for e in tools.email_split(rcpt_tos)]
if local_parts:
- mail_alias = self.pool.get('mail.alias')
alias_ids = mail_alias.search(cr, uid, [('alias_name', 'in', local_parts)])
if alias_ids:
routes = []
@@ -1084,7 +1094,7 @@ class mail_thread(osv.AbstractModel):
context = dict(context or {})
partner_ids = message_dict.pop('partner_ids', [])
thread_id = False
- for model, thread_id, custom_values, user_id, alias in routes:
+ for model, thread_id, custom_values, user_id, alias in routes or ():
if self._name == 'mail.thread':
context['thread_model'] = model
if model: