From c33dff10f16d40776f716aa1102f483ad7cbab98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Wed, 2 Jan 2013 14:00:25 +0100 Subject: [PATCH] [IMP] mail: send emails now have a reply_to based on aliases, if defined, and if not reply_to already defined in the mail.mail object. bzr revid: tde@openerp.com-20130102130025-5wa2k8wzv1vgg2xx --- addons/mail/mail_mail.py | 20 +++++++++++++++++++- addons/mail/mail_thread.py | 12 ++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/addons/mail/mail_mail.py b/addons/mail/mail_mail.py index d6cb2a2cf7e..bb33c75758d 100644 --- a/addons/mail/mail_mail.py +++ b/addons/mail/mail_mail.py @@ -160,6 +160,22 @@ class mail_mail(osv.Model): """ return mail.body_html + def send_get_mail_reply_to(self, cr, uid, mail, partner=None, context=None): + """ Return a specific ir_email body. The main purpose of this method + is to be inherited by Portal, to add a link for signing in, in + each notification email a partner receives. + + :param browse_record mail: mail.mail browse_record + :param browse_record partner: specific recipient partner + """ + if mail.reply_to: + return mail.reply_to + if not mail.model or not mail.res_id: + return False + if not hasattr(self.pool.get(mail.model), 'message_get_reply_to'): + return False + return self.pool.get(mail.model).message_get_reply_to(cr, uid, [mail.res_id], context=context)[0] + def send_get_email_dict(self, cr, uid, mail, partner=None, context=None): """ Return a dictionary for specific email values, depending on a partner, or generic to the whole recipients given by mail.email_to. @@ -169,6 +185,7 @@ class mail_mail(osv.Model): """ body = self.send_get_mail_body(cr, uid, mail, partner=partner, context=context) subject = self.send_get_mail_subject(cr, uid, mail, partner=partner, context=context) + reply_to = self.send_get_mail_reply_to(cr, uid, mail, partner=partner, context=context) body_alternative = tools.html2plaintext(body) email_to = [partner.email] if partner else tools.email_split(mail.email_to) return { @@ -176,6 +193,7 @@ class mail_mail(osv.Model): 'body_alternative': body_alternative, 'subject': subject, 'email_to': email_to, + 'reply_to': reply_to, } def send(self, cr, uid, ids, auto_commit=False, recipient_ids=None, context=None): @@ -219,7 +237,7 @@ class mail_mail(osv.Model): body = email.get('body'), body_alternative = email.get('body_alternative'), email_cc = tools.email_split(mail.email_cc), - reply_to = mail.reply_to, + reply_to = email.get('reply_to'), attachments = attachments, message_id = mail.message_id, references = mail.references, diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 5054bf89b8c..59628d73c0a 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -387,6 +387,18 @@ class mail_thread(osv.AbstractModel): return [('message_unread', '=', True)] return [] + #------------------------------------------------------ + # Email specific + #------------------------------------------------------ + + def message_get_reply_to(self, cr, uid, ids, context=None): + if not self._inherits.get('mail.alias'): + return False + return ["%s@%s" % (record['alias_name'], record['alias_domain']) + if record.get('alias_domain') and record.get('alias_name') + else False + for record in self.read(cr, uid, ids, ['alias_name', 'alias_domain'], context=context)] + #------------------------------------------------------ # Mail gateway #------------------------------------------------------