Browse Source

Merge pull request #494 from inkhey/fix/490/proper_header_for_mail

Damien Accorsi 7 years ago
parent
commit
8310436dd8
No account linked to committer's email
2 changed files with 7 additions and 8 deletions
  1. 4 3
      tracim/tracim/lib/email.py
  2. 3 5
      tracim/tracim/lib/notifications.py

+ 4 - 3
tracim/tracim/lib/email.py View File

4
 from email.message import Message
4
 from email.message import Message
5
 from email.mime.multipart import MIMEMultipart
5
 from email.mime.multipart import MIMEMultipart
6
 from email.mime.text import MIMEText
6
 from email.mime.text import MIMEText
7
+from email.utils import formataddr
7
 
8
 
8
 from mako.template import Template
9
 from mako.template import Template
9
 from tg.i18n import ugettext as _
10
 from tg.i18n import ugettext as _
156
             )
157
             )
157
         message = MIMEMultipart('alternative')
158
         message = MIMEMultipart('alternative')
158
         message['Subject'] = subject
159
         message['Subject'] = subject
159
-        message['From'] = '{0} <{1}>'.format(
160
+        message['From'] = formataddr((
160
             self._global_config.EMAIL_NOTIFICATION_FROM_DEFAULT_LABEL,
161
             self._global_config.EMAIL_NOTIFICATION_FROM_DEFAULT_LABEL,
161
             self._global_config.EMAIL_NOTIFICATION_FROM_EMAIL,
162
             self._global_config.EMAIL_NOTIFICATION_FROM_EMAIL,
162
-        )
163
-        message['To'] = user.email
163
+        ))
164
+        message['To'] = formataddr((user.get_display_name(), user.email))
164
 
165
 
165
         text_template_file_path = self._global_config.EMAIL_NOTIFICATION_CREATED_ACCOUNT_TEMPLATE_TEXT  # nopep8
166
         text_template_file_path = self._global_config.EMAIL_NOTIFICATION_CREATED_ACCOUNT_TEMPLATE_TEXT  # nopep8
166
         html_template_file_path = self._global_config.EMAIL_NOTIFICATION_CREATED_ACCOUNT_TEMPLATE_HTML  # nopep8
167
         html_template_file_path = self._global_config.EMAIL_NOTIFICATION_CREATED_ACCOUNT_TEMPLATE_HTML  # nopep8

+ 3 - 5
tracim/tracim/lib/notifications.py View File

5
 from email.header import Header
5
 from email.header import Header
6
 from email.mime.multipart import MIMEMultipart
6
 from email.mime.multipart import MIMEMultipart
7
 from email.mime.text import MIMEText
7
 from email.mime.text import MIMEText
8
+from email.utils import formataddr
8
 
9
 
9
 from lxml.html.diff import htmldiff
10
 from lxml.html.diff import htmldiff
10
 
11
 
207
         else:
208
         else:
208
             email_address = email_template.replace('{user_id}', '0')
209
             email_address = email_template.replace('{user_id}', '0')
209
 
210
 
210
-        return '{label} <{email_address}>'.format(
211
-            label = Header(mail_sender_name).encode(),
212
-            email_address = email_address
213
-        )
211
+        return formataddr((mail_sender_name, email_address))
214
 
212
 
215
     @staticmethod
213
     @staticmethod
216
     def log_notification(
214
     def log_notification(
269
 
267
 
270
         for role in notifiable_roles:
268
         for role in notifiable_roles:
271
             logger.info(self, 'Sending email to {}'.format(role.user.email))
269
             logger.info(self, 'Sending email to {}'.format(role.user.email))
272
-            to_addr = '{name} <{email}>'.format(name=role.user.display_name, email=role.user.email)
270
+            to_addr = formataddr((role.user.display_name, role.user.email))
273
 
271
 
274
             #
272
             #
275
             #  INFO - D.A. - 2014-11-06
273
             #  INFO - D.A. - 2014-11-06