From 562d8129f2b4342b54e83fe6e5f5f724deb8ddb0 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Thu, 17 Jul 2014 00:16:12 +0200 Subject: [PATCH] [FIX] mail: less confusing To: header for mailing-list posts Many mail clients will replace the name in the To: header with Me if the To: email matches the email of the user. These users will see To: Me instead of "Followers of ..." and usually believe this was a private email from the sender to them. But when replying they would reply to the whole list. Fix this by explicitly forcing the To: to be the mailing list address. --- addons/mail/mail_group.py | 15 ++++++++------- openerp/addons/base/ir/ir_mail_server.py | 7 +++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/addons/mail/mail_group.py b/addons/mail/mail_group.py index ef4e02b9fc3..6c40e618342 100644 --- a/addons/mail/mail_group.py +++ b/addons/mail/mail_group.py @@ -221,12 +221,13 @@ class mail_group(osv.Model): def message_get_email_values(self, cr, uid, id, notif_mail=None, context=None): res = super(mail_group, self).message_get_email_values(cr, uid, id, notif_mail=notif_mail, context=context) group = self.browse(cr, uid, id, context=context) - res.update({ - 'headers': { - 'Precedence': 'list', - } - }) + headers = res.setdefault('headers', {}) + headers['Precedence'] = 'list' if group.alias_domain: - res['headers']['List-Id'] = '%s.%s' % (group.alias_name, group.alias_domain) - res['headers']['List-Post'] = '' % (group.alias_name, group.alias_domain) + headers['List-Id'] = '%s.%s' % (group.alias_name, group.alias_domain) + headers['List-Post'] = '' % (group.alias_name, group.alias_domain) + # Avoid users thinking it was a personal message + # X-Forge-To: will replace To: after SMTP envelope is determined by ir.mail.server + list_to = '"%s" <%s@%s>' % (group.name, group.alias_name, group.alias_domain) + headers['X-Forge-To'] = list_to return res diff --git a/openerp/addons/base/ir/ir_mail_server.py b/openerp/addons/base/ir/ir_mail_server.py index 4af52bdea41..56a51640da7 100644 --- a/openerp/addons/base/ir/ir_mail_server.py +++ b/openerp/addons/base/ir/ir_mail_server.py @@ -415,6 +415,13 @@ class ir_mail_server(osv.osv): smtp_to_list = filter(None, tools.flatten(map(extract_rfc2822_addresses,[email_to, email_cc, email_bcc]))) assert smtp_to_list, "At least one valid recipient address should be specified for outgoing emails (To/Cc/Bcc)" + x_forge_to = message['X-Forge-To'] + if x_forge_to: + # `To:` header forged, e.g. for posting on mail.groups, to avoid confusion + del message['X-Forge-To'] + del message['To'] # avoid multiple To: headers! + message['To'] = x_forge_to + # Do not actually send emails in testing mode! if getattr(threading.currentThread(), 'testing', False): _test_logger.info("skip sending email in test mode")