Skip to content

Commit 5ae1f50

Browse files
authored
Merge pull request #3218 from fettuccinae/sanitize_username
LB-1442: Fix sending emails if username contains a special character
2 parents 99b401a + 8c436d0 commit 5ae1f50

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

listenbrainz/db/year_in_music.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ def send_mail(subject, to_name, to_email, content, html, logo, logo_cid):
178178
current_app.logger.info("Email sent to %s", to_name)
179179

180180

181+
def sanitize_username(username):
182+
username.replace('\\','\\\\')
183+
username.replace('"','\\"')
184+
return f'"{username}"'
185+
186+
181187
def notify_yim_users(db_conn, ts_conn, year):
182188
logo_cid = make_msgid()
183189
with open("/static/img/year-in-music-24/yim24-header-all-email.png", "rb") as img:
@@ -198,7 +204,7 @@ def notify_yim_users(db_conn, ts_conn, year):
198204
rows = result.fetchall()
199205

200206
for row in rows:
201-
user_name = row.musicbrainz_id
207+
user_name = sanitize_username(row.musicbrainz_id)
202208

203209
# cannot use url_for because we do not set SERVER_NAME and
204210
# a request_context will not be available in this script.

0 commit comments

Comments
 (0)