diff --git a/addons/mail/mail_mail.py b/addons/mail/mail_mail.py index 1a21bb17ad9..351ff0130e5 100644 --- a/addons/mail/mail_mail.py +++ b/addons/mail/mail_mail.py @@ -232,7 +232,19 @@ class mail_mail(osv.Model): 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 = ['%s <%s>' % (partner.name, partner.email)] if partner else tools.email_split(mail.email_to) + + # generate email_to, heuristic: + # 1. if 'partner' is specified and there is a related document: Followers of 'Doc' + # 2. if 'partner' is specified, but no related document: Partner Name + # 3; fallback on mail.email_to that we split to have an email addresses list + if partner and mail.record_name: + sanitized_record_name = re.sub(r'[^\w+.]+', '-', mail.record_name) + email_to = [_('"Followers of %s" <%s>') % (sanitized_record_name, partner.email)] + elif partner: + email_to = ['%s <%s>' % (partner.name, partner.email)] + else: + email_to = tools.email_split(mail.email_to) + return { 'body': body, 'body_alternative': body_alternative, diff --git a/addons/mail/tests/test_mail_features.py b/addons/mail/tests/test_mail_features.py index 2d0019c0b8a..7eea66b3b90 100644 --- a/addons/mail/tests/test_mail_features.py +++ b/addons/mail/tests/test_mail_features.py @@ -280,7 +280,8 @@ class test_mail(TestMailBase): 'message_post: mail.mail notifications should have been auto-deleted!') # Test: notifications emails: to a and b, c is email only, r is author - test_emailto = ['Administrator ', 'Bert Tartopoils '] + # test_emailto = ['Administrator ', 'Bert Tartopoils '] + test_emailto = ['"Followers of -Pigs-" ', '"Followers of -Pigs-" '] self.assertEqual(len(sent_emails), 2, 'message_post: notification emails wrong number of send emails') self.assertEqual(set([m['email_to'][0] for m in sent_emails]), set(test_emailto), @@ -353,7 +354,8 @@ class test_mail(TestMailBase): self.assertFalse(self.mail_mail.search(cr, uid, [('mail_message_id', '=', msg2_id)]), 'mail.mail notifications should have been auto-deleted!') # Test: emails send by server (to a, b, c, d) - test_emailto = [u'Administrator ', u'Bert Tartopoils ', u'Carine Poilvache ', u'D\xe9d\xe9 Grosbedon '] + # test_emailto = [u'Administrator ', u'Bert Tartopoils ', u'Carine Poilvache ', u'D\xe9d\xe9 Grosbedon '] + test_emailto = [u'"Followers of Pigs" ', u'"Followers of Pigs" ', u'"Followers of Pigs" ', u'"Followers of Pigs" '] # self.assertEqual(len(sent_emails), 3, 'sent_email number of sent emails incorrect') for sent_email in sent_emails: self.assertEqual(sent_email['email_from'], 'Raoul Grosbedon ',