[FIX] mail: fixed suggested recipients, not taking into account followers; when having multiple email addresses, this could lead to people being suggested based on email although they already are followers.
bzr revid: tde@openerp.com-20130326125311-xlt1lt1te28fcm1o
This commit is contained in:
@@ -848,7 +848,8 @@ class mail_thread(osv.AbstractModel):
|
||||
recipient in the result dictionary. The form is :
|
||||
partner_id, partner_name<partner_email> or partner_name, reason """
|
||||
if email and not partner:
|
||||
partner_info = self.message_get_partner_info_from_emails(cr, uid, [email], context=context)[0]
|
||||
# get partner info from email
|
||||
partner_info = self.message_get_partner_info_from_emails(cr, uid, [email], context=context, res_id=obj.id)[0]
|
||||
if partner_info.get('partner_id'):
|
||||
partner = self.pool.get('res.partner').browse(cr, SUPERUSER_ID, [partner_info.get('partner_id')], context=context)[0]
|
||||
if email and email in [val[1] for val in result[obj.id]]: # already existing email -> skip
|
||||
@@ -876,7 +877,11 @@ class mail_thread(osv.AbstractModel):
|
||||
self._message_add_suggested_recipient(cr, uid, result, obj, partner=obj.user_id.partner_id, reason=self._all_columns['user_id'].column.string, context=context)
|
||||
return result
|
||||
|
||||
def message_get_partner_info_from_emails(self, cr, uid, emails, link_mail=False, context=None):
|
||||
def message_get_partner_info_from_emails(self, cr, uid, emails, link_mail=False, context=None, res_id=None):
|
||||
""" Wrapper with weird order parameter because of 7.0 fix. """
|
||||
return self.message_find_partner_from_emails(cr, uid, res_id, emails, link_mail=link_mail, context=context)
|
||||
|
||||
def message_find_partner_from_emails(self, cr, uid, id, emails, link_mail=False, context=None):
|
||||
""" Convert a list of emails into a list partner_ids and a list
|
||||
new_partner_ids. The return value is non conventional because
|
||||
it is meant to be used by the mail widget.
|
||||
@@ -886,15 +891,26 @@ class mail_thread(osv.AbstractModel):
|
||||
mail_message_obj = self.pool.get('mail.message')
|
||||
partner_obj = self.pool.get('res.partner')
|
||||
result = list()
|
||||
if id:
|
||||
obj = self.browse(cr, SUPERUSER_ID, id, context=context)
|
||||
else:
|
||||
obj = None
|
||||
for email in emails:
|
||||
partner_info = {'full_name': email, 'partner_id': False}
|
||||
m = re.search(r"((.+?)\s*<)?([^<>]+@[^<>]+)>?", email, re.IGNORECASE | re.DOTALL)
|
||||
if not m:
|
||||
continue
|
||||
email_address = m.group(3)
|
||||
ids = partner_obj.search(cr, SUPERUSER_ID, [('email', '=', email_address)], context=context)
|
||||
if ids:
|
||||
partner_info['partner_id'] = ids[0]
|
||||
# first try: check in document's followers
|
||||
if obj:
|
||||
for follower in obj.message_follower_ids:
|
||||
if follower.email == email_address:
|
||||
partner_info['partner_id'] = follower.id
|
||||
# second try: check in partners
|
||||
if not partner_info.get('partner_id'):
|
||||
ids = partner_obj.search(cr, SUPERUSER_ID, [('email', '=', email_address)], context=context)
|
||||
if ids:
|
||||
partner_info['partner_id'] = ids[0]
|
||||
result.append(partner_info)
|
||||
|
||||
# link mail with this from mail to the new partner id
|
||||
|
||||
@@ -620,7 +620,11 @@ openerp.mail = function (session) {
|
||||
// have unknown names -> call message_get_partner_info_from_emails to try to find partner_id
|
||||
var find_done = $.Deferred();
|
||||
if (names_to_find.length > 0) {
|
||||
find_done = self.parent_thread.ds_thread._model.call('message_get_partner_info_from_emails', [names_to_find]);
|
||||
// find_done = self.parent_thread.ds_thread._model.call('message_get_partner_info_from_emails', [names_to_find]);
|
||||
var values = {
|
||||
'res_id': this.context.default_res_id,
|
||||
}
|
||||
find_done = self.parent_thread.ds_thread._model.call('message_get_partner_info_from_emails', [names_to_find], values);
|
||||
}
|
||||
else {
|
||||
find_done.resolve([]);
|
||||
@@ -666,7 +670,11 @@ openerp.mail = function (session) {
|
||||
var new_names_to_find = _.difference(names_to_find, names_to_remove);
|
||||
find_done = $.Deferred();
|
||||
if (new_names_to_find.length > 0) {
|
||||
find_done = self.parent_thread.ds_thread._model.call('message_get_partner_info_from_emails', [new_names_to_find, true]);
|
||||
var values = {
|
||||
'link_mail': true,
|
||||
'res_id': this.context.default_res_id,
|
||||
}
|
||||
find_done = self.parent_thread.ds_thread._model.call('message_get_partner_info_from_emails', [new_names_to_find], values);
|
||||
}
|
||||
else {
|
||||
find_done.resolve([]);
|
||||
|
||||
Reference in New Issue
Block a user