[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
This commit is contained in:
parent
6ceb41dae4
commit
f498583a98
|
@ -836,7 +836,7 @@ class mail_thread(osv.AbstractModel):
|
||||||
if not message_dict.get('parent_id'):
|
if not message_dict.get('parent_id'):
|
||||||
raise ValueError('Routing: posting a message without model should be with a parent_id (private mesage).')
|
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')
|
_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
|
# Existing Document: check if exists; if not, fallback on create if allowed
|
||||||
if thread_id and not model_pool.exists(cr, uid, thread_id):
|
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)
|
assert model_pool.exists(cr, uid, thread_id), 'Routing: reply to missing document (%s,%s)' % (model, thread_id)
|
||||||
else:
|
else:
|
||||||
_warn('reply to missing document (%s,%s), skipping' % (model, thread_id))
|
_warn('reply to missing document (%s,%s), skipping' % (model, thread_id))
|
||||||
return ()
|
return False
|
||||||
|
|
||||||
# Existing Document: check model accepts the mailgateway
|
# Existing Document: check model accepts the mailgateway
|
||||||
if thread_id and model and not hasattr(model_pool, 'message_update'):
|
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
|
assert hasattr(model_pool, 'message_update'), 'Routing: model %s does not accept document update, crashing' % model
|
||||||
else:
|
else:
|
||||||
_warn('model %s does not accept document update, skipping' % model)
|
_warn('model %s does not accept document update, skipping' % model)
|
||||||
return ()
|
return False
|
||||||
|
|
||||||
# New Document: check model accepts the mailgateway
|
# New Document: check model accepts the mailgateway
|
||||||
if not thread_id and model and not hasattr(model_pool, 'message_new'):
|
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
|
'Model %s does not accept document creation, crashing' % model
|
||||||
)
|
)
|
||||||
_warn('model %s does not accept document creation, skipping' % model)
|
_warn('model %s does not accept document creation, skipping' % model)
|
||||||
return ()
|
return False
|
||||||
|
|
||||||
# Update message author if asked
|
# Update message author if asked
|
||||||
# We do it now because we need it for aliases (contact settings)
|
# 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]:
|
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)
|
_warn('alias %s restricted to internal followers, skipping' % alias.alias_name)
|
||||||
_create_bounce_email()
|
_create_bounce_email()
|
||||||
return ()
|
return False
|
||||||
elif alias and alias.alias_contact == 'partners' and not author_id:
|
elif alias and alias.alias_contact == 'partners' and not author_id:
|
||||||
_warn('alias %s does not accept unknown author, skipping' % alias.alias_name)
|
_warn('alias %s does not accept unknown author, skipping' % alias.alias_name)
|
||||||
_create_bounce_email()
|
_create_bounce_email()
|
||||||
return ()
|
return False
|
||||||
|
|
||||||
if not model and not thread_id and not alias and not allow_private:
|
if not model and not thread_id and not alias and not allow_private:
|
||||||
return ()
|
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,
|
def message_route(self, cr, uid, message, message_dict, model=None, thread_id=None,
|
||||||
custom_values=None, context=None):
|
custom_values=None, context=None):
|
||||||
|
@ -936,6 +936,7 @@ class mail_thread(osv.AbstractModel):
|
||||||
if not isinstance(message, Message):
|
if not isinstance(message, Message):
|
||||||
raise TypeError('message must be an email.message.Message at this point')
|
raise TypeError('message must be an email.message.Message at this point')
|
||||||
mail_msg_obj = self.pool['mail.message']
|
mail_msg_obj = self.pool['mail.message']
|
||||||
|
mail_alias = self.pool.get('mail.alias')
|
||||||
fallback_model = model
|
fallback_model = model
|
||||||
|
|
||||||
# Get email.message.Message variables for future processing
|
# Get email.message.Message variables for future processing
|
||||||
|
@ -963,15 +964,21 @@ class mail_thread(osv.AbstractModel):
|
||||||
if ref_match and 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)
|
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
|
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(
|
route = self.message_route_verify(
|
||||||
cr, uid, message, message_dict,
|
cr, uid, message, message_dict,
|
||||||
(model, thread_id, custom_values, uid, None),
|
(model, thread_id, custom_values, uid, alias),
|
||||||
update_author=True, assert_model=False, create_fallback=True, context=context)
|
update_author=True, assert_model=False, create_fallback=True, context=dict(context, drop_alias=True))
|
||||||
if route:
|
if route:
|
||||||
_logger.info(
|
_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',
|
'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)
|
email_from, email_to, message_id, model, thread_id, custom_values, uid)
|
||||||
return [route]
|
return [route]
|
||||||
|
elif route is False:
|
||||||
|
return []
|
||||||
|
|
||||||
# 2. message is a reply to an existign thread (6.1 compatibility)
|
# 2. message is a reply to an existign thread (6.1 compatibility)
|
||||||
if ref_match:
|
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',
|
'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)
|
email_from, email_to, message_id, model, thread_id, custom_values, uid)
|
||||||
return [route]
|
return [route]
|
||||||
|
elif route is False:
|
||||||
|
return []
|
||||||
|
|
||||||
# 3. Reply to a private message
|
# 3. Reply to a private message
|
||||||
if in_reply_to:
|
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',
|
'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)
|
email_from, email_to, message_id, mail_message.id, custom_values, uid)
|
||||||
return [route]
|
return [route]
|
||||||
|
elif route is False:
|
||||||
|
return []
|
||||||
|
|
||||||
# 4. Look for a matching mail.alias entry
|
# 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
|
# 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')])
|
decode_header(message, 'Resent-Cc')])
|
||||||
local_parts = [e.split('@')[0] for e in tools.email_split(rcpt_tos)]
|
local_parts = [e.split('@')[0] for e in tools.email_split(rcpt_tos)]
|
||||||
if local_parts:
|
if local_parts:
|
||||||
mail_alias = self.pool.get('mail.alias')
|
|
||||||
alias_ids = mail_alias.search(cr, uid, [('alias_name', 'in', local_parts)])
|
alias_ids = mail_alias.search(cr, uid, [('alias_name', 'in', local_parts)])
|
||||||
if alias_ids:
|
if alias_ids:
|
||||||
routes = []
|
routes = []
|
||||||
|
@ -1084,7 +1094,7 @@ class mail_thread(osv.AbstractModel):
|
||||||
context = dict(context or {})
|
context = dict(context or {})
|
||||||
partner_ids = message_dict.pop('partner_ids', [])
|
partner_ids = message_dict.pop('partner_ids', [])
|
||||||
thread_id = False
|
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':
|
if self._name == 'mail.thread':
|
||||||
context['thread_model'] = model
|
context['thread_model'] = model
|
||||||
if model:
|
if model:
|
||||||
|
|
Loading…
Reference in New Issue