[IMP] improved code.
bzr revid: tpa@tinyerp.com-20120621090714-giqg7gynttquiztn
This commit is contained in:
parent
f64fa15ec0
commit
ca0509b340
|
@ -449,20 +449,21 @@ class mail_thread(osv.osv):
|
|||
|
||||
def _get_user(self, cr, uid, alias, context):
|
||||
"""
|
||||
return user_id based on alias
|
||||
else return id of admin
|
||||
param alias: browse record of alias.
|
||||
return: int user_id.
|
||||
"""
|
||||
|
||||
user_obj = self.pool.get('res.user')
|
||||
user_id = 1
|
||||
if alias.alias_user_id:
|
||||
user_id = alias_id.alias_user_id.id
|
||||
#if user_id not defined in the alias then search related user using name of Email sender
|
||||
else:
|
||||
frm = msg.get('from')
|
||||
user_ids = user_obj.search(cr, uid, [('name','=',frm)], context)
|
||||
from_email = msg.get('from')
|
||||
user_ids = user_obj.search(cr, uid, [('name','=',from_email)], context)
|
||||
if user_ids:
|
||||
user_id = user_obj.browse(cr, uid, user_ids[0], context).id
|
||||
return user_id or 1
|
||||
return user_id
|
||||
|
||||
def message_catchall(self, cr, uid, message, context=None):
|
||||
"""
|
||||
|
@ -492,14 +493,14 @@ class mail_thread(osv.osv):
|
|||
#if alias found then call message_process method.
|
||||
if alias_id:
|
||||
user_id = self._get_user(self, cr, uid, alias_id, context)
|
||||
self.message_process(self, cr, user_id, alias_id.alias_model_id.id, message, alias_id.alias_defaults or False , False, False, alias_id.alias_force_thread_id or False, context)
|
||||
self.message_process(self, cr, user_id, alias_id.alias_model_id.id, message, custom_values = alias_id.alias_defaults or {}, thread_id = alias_id.alias_force_thread_id or {}, context)
|
||||
#if alis not found give Exception
|
||||
else:
|
||||
_logger.warning("This mailbox does not exist so mail gate will reject this mail.")
|
||||
frm = user_obj.browse(cr, uid, uid, context).user_email
|
||||
#_logger.warning("This mailbox does not exist so mail gate will reject this mail.")
|
||||
from_email = user_obj.browse(cr, uid, uid, context).user_email
|
||||
sub = "Mail Rejection" + msg.get('subject')
|
||||
message = "Respective mailbox does not exist so your mail have been rejected" + msg
|
||||
mail_message.send_mail(cr, uid, {'email_from': frm,'email_to': msg.get('from'),'subject': sub, 'body_text': message}, context)
|
||||
mail_message.send_mail(cr, uid, {'email_from': from_email,'email_to': msg.get('from'),'subject': sub, 'body_text': message}, context)
|
||||
|
||||
return True
|
||||
|
||||
|
|
Loading…
Reference in New Issue