Skip to content

Commit

Permalink
Merge pull request #494 from inkhey/fix/490/proper_header_for_mail
Browse files Browse the repository at this point in the history
Better escaping for mail header with formataddr method
  • Loading branch information
Damien Accorsi committed Nov 17, 2017
2 parents 5c30aac + 4707561 commit 8310436
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
7 changes: 4 additions & 3 deletions tracim/tracim/lib/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from email.message import Message
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.utils import formataddr

from mako.template import Template
from tg.i18n import ugettext as _
Expand Down Expand Up @@ -156,11 +157,11 @@ def notify_created_account(
)
message = MIMEMultipart('alternative')
message['Subject'] = subject
message['From'] = '{0} <{1}>'.format(
message['From'] = formataddr((
self._global_config.EMAIL_NOTIFICATION_FROM_DEFAULT_LABEL,
self._global_config.EMAIL_NOTIFICATION_FROM_EMAIL,
)
message['To'] = user.email
))
message['To'] = formataddr((user.get_display_name(), user.email))

text_template_file_path = self._global_config.EMAIL_NOTIFICATION_CREATED_ACCOUNT_TEMPLATE_TEXT # nopep8
html_template_file_path = self._global_config.EMAIL_NOTIFICATION_CREATED_ACCOUNT_TEMPLATE_HTML # nopep8
Expand Down
8 changes: 3 additions & 5 deletions tracim/tracim/lib/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from email.header import Header
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.utils import formataddr

from lxml.html.diff import htmldiff

Expand Down Expand Up @@ -207,10 +208,7 @@ def _get_sender(self, user: User=None) -> str:
else:
email_address = email_template.replace('{user_id}', '0')

return '{label} <{email_address}>'.format(
label = Header(mail_sender_name).encode(),
email_address = email_address
)
return formataddr((mail_sender_name, email_address))

@staticmethod
def log_notification(
Expand Down Expand Up @@ -269,7 +267,7 @@ def notify_content_update(self, event_actor_id: int, event_content_id: int):

for role in notifiable_roles:
logger.info(self, 'Sending email to {}'.format(role.user.email))
to_addr = '{name} <{email}>'.format(name=role.user.display_name, email=role.user.email)
to_addr = formataddr((role.user.display_name, role.user.email))

#
# INFO - D.A. - 2014-11-06
Expand Down

0 comments on commit 8310436

Please sign in to comment.