[IMP] mail: htmlEntities for the author email, select list of new partner by real email

bzr revid: chm@openerp.com-20130104111004-9l0hb6zu33o5b2v6
This commit is contained in:
Christophe Matthieu 2013-01-04 12:10:04 +01:00
parent 8758afd045
commit e40b49a838
3 changed files with 33 additions and 20 deletions

View File

@ -914,7 +914,7 @@ class mail_thread(osv.AbstractModel):
for email in extra_emails:
partner_id = partner_obj.find_or_create(cr, uid, email, context=context)
# link mail with this from mail to the new partner id
partner_msg_ids = mail_message_obj.search(cr, SUPERUSER_ID, [('email_from', '=', email), ('author_id', '=', False)], context=context)
partner_msg_ids = mail_message_obj.search(cr, SUPERUSER_ID, ['|', ('email_from', '=', email), ('email_from', 'ilike', '<%s>' % email), ('author_id', '=', False)], context=context)
if partner_id and partner_msg_ids:
mail_message_obj.write(cr, SUPERUSER_ID, partner_msg_ids, {'email_from': None, 'author_id': partner_id}, context=context)
partner_ids.add((4, partner_id))

View File

@ -253,7 +253,14 @@ openerp.mail = function (session) {
} else {
this.avatar = mail.ChatterUtils.get_image(this.session, 'res.users', 'image_small', this.session.uid);
}
if (this.author_id) {
var email = this.author_id[1].match(/(.*)<(.*@.*)>/);
if (!email) {
this.author_id.push(_.str.escapeHTML(this.author_id[1]), '', this.author_id[1]);
} else {
this.author_id.push(_.str.escapeHTML(email[0]), _.str.trim(email[1]), email[2]);
}
}
},
@ -505,8 +512,7 @@ openerp.mail = function (session) {
}
// create list of new partners
var extra_email = _.map(_.filter(this.emails_from, function (f) {return f[1]}), function (f) {return f[0]});
this.check_recipient_partners(extra_email).done(function () {
this.check_recipient_partners().done(function () {
var context = {
'default_model': default_composition_mode == 'reply' ? undefined : self.context.default_model,
'default_res_id': default_composition_mode == 'reply' ? undefined : self.context.default_res_id,
@ -561,22 +567,31 @@ openerp.mail = function (session) {
}
},
check_recipient_partners: function (emails) {
check_recipient_partners: function () {
var self = this;
self.partners_from = [];
var emails = [];
_.each(this.emails_from, function (email_from) {
if (email_from[1]) {
if (!_.find(emails, function (email) {return email[4] == email_from[0][4];})) {
emails.push(email_from[0]);
}
}
});
var deferreds = [];
var ds_partner = new session.web.DataSetSearch(this, 'res.partner');
this.partners_from = [];
_.each(emails, function (email) {
var deferred = $.Deferred();
deferreds.push(deferred);
ds_partner.call('search', [[['email', 'like', email]]]).then(function (partner_ids) {
ds_partner.call('search', [[['email', 'like', email[4]]]]).then(function (partner_ids) {
if (!partner_ids.length) {
var pop = new session.web.form.FormOpenPopup(this);
pop.show_element(
'res.partner',
0,
{
'default_email': email,
'default_email': email[4],
'default_name': email[3],
'force_email': true,
'ref': "compound_context",
},
@ -606,8 +621,7 @@ openerp.mail = function (session) {
var self = this;
if (this.do_check_attachment_upload() && (this.attachment_ids.length || this.$('textarea').val().match(/\S+/))) {
// create list of new partners
var extra_email = _.map(_.filter(this.emails_from, function (f) {return f[1]}), function (f) {return f[0]});
this.check_recipient_partners(extra_email).done(function () {
this.check_recipient_partners().done(function () {
self.do_send_message_post();
});
}
@ -621,7 +635,7 @@ openerp.mail = function (session) {
'subject': false,
'parent_id': this.context.default_parent_id,
'attachment_ids': _.map(this.attachment_ids, function (file) {return file.id;}),
'extra_emails': _.map(_.filter(this.emails_from, function (f) {return f[1]}), function (f) {return f[0]}),
'extra_emails': _.map(_.filter(this.emails_from, function (f) {return f[1]}), function (f) {return f[0][4]}),
'context': this.parent_thread.context,
}).done(function (message_id) {
var thread = self.parent_thread;
@ -683,19 +697,18 @@ openerp.mail = function (session) {
_.each(messages, function (thread) {
if (thread.author_id && !thread.author_id[0] &&
!_.find(self.emails_from, function (from) {return from[0] == thread.author_id[1];})) {
self.emails_from.push([thread.author_id[1], true]);
!_.find(self.emails_from, function (from) {return from[0][4] == thread.author_id[4];})) {
self.emails_from.push([thread.author_id, true]);
}
});
return self.emails_from;
},
on_checked_email_from: function (event) {
var $input = $(event.target);
var email = $input.attr("data");
_.each(this.emails_from, function (email_from) {
if (email_from[0] == email) {
if (email_from[0][4] == email) {
email_from[1] = $input.is(":checked");
}
});

View File

@ -132,8 +132,8 @@
<div class="oe_emails_from">
<t t-foreach='widget.emails_from' t-as='email_from'>
<label title="Add them into recipients and followers">
<input type="checkbox" t-att-checked="email_from[1] ? 'checked' : undefind" t-att-data="email_from[0]"/>
<t t-raw="email_from[0]"/>
<input type="checkbox" t-att-checked="email_from[1] ? 'checked' : undefind" t-att-data="email_from[0][4]"/>
<t t-raw="email_from[0][2]"/>
</label>
</t>
</div>
@ -243,8 +243,8 @@
<t t-if="widget.attachment_ids.length > 0">
<div class="oe_msg_attachment_list"></div>
</t>
<a t-if="widget.author_id and widget.options.show_link and widget.author_id[0]" t-attf-href="#model=res.partner&amp;id=#{widget.author_id[0]}"><t t-raw="widget.author_id[1]"/></a>
<span t-if="widget.author_id and (!widget.options.show_link or !widget.author_id[0])"><t t-raw="widget.author_id[1]"/></span>
<a t-if="widget.author_id and widget.options.show_link and widget.author_id[0]" t-attf-href="#model=res.partner&amp;id=#{widget.author_id[0]}"><t t-raw="widget.author_id[2]"/></a>
<span t-if="widget.author_id and (!widget.options.show_link or !widget.author_id[0])"><t t-raw="widget.author_id[2]"/></span>
<span class='oe_subtle'></span>
<span t-att-title="widget.date"><t t-raw="widget.timerelative"/></span>
<span t-if="!widget.options.readonly" class='oe_subtle'></span>