Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mutalyzer
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirrors
mutalyzer
Commits
425fa7d1
Commit
425fa7d1
authored
9 years ago
by
Vermaat
Browse files
Options
Downloads
Patches
Plain Diff
Encode unicode email addresses before sending mail
parent
5b9c2c83
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mutalyzer/Scheduler.py
+22
-2
22 additions, 2 deletions
mutalyzer/Scheduler.py
with
22 additions
and
2 deletions
mutalyzer/Scheduler.py
+
22
−
2
View file @
425fa7d1
...
@@ -106,6 +106,25 @@ class Scheduler() :
...
@@ -106,6 +106,25 @@ class Scheduler() :
#TODO: Handle Connection errors in a try, except clause
#TODO: Handle Connection errors in a try, except clause
#Expected errors: socket.error
#Expected errors: socket.error
def
encode_address
(
address
):
"""
Unfortunately, smtplib can only handle ASCII email addresses.
The domain name part should be punycode-encoded. The part before
the
'
@
'
should be encoded as ASCII if possible or as UTF8 if the
first-hop mail server supports this.
This is way to complicated, so we just encode the entire address
as ASCII or punycode if that fails.
https://bugs.python.org/issue20084
https://bugs.python.org/issue20083
"""
try
:
return
address
.
encode
(
'
ascii
'
)
except
UnicodeEncodeError
:
return
address
.
encode
(
'
idna
'
)
from_address
=
'
Mutalyzer batch job <%s>
'
%
(
from_address
=
'
Mutalyzer batch job <%s>
'
%
(
settings
.
BATCH_NOTIFICATION_EMAIL
or
settings
.
EMAIL
)
settings
.
BATCH_NOTIFICATION_EMAIL
or
settings
.
EMAIL
)
download_url
=
website
.
url_for
(
'
batch_job_result
'
,
download_url
=
website
.
url_for
(
'
batch_job_result
'
,
...
@@ -126,7 +145,7 @@ Mutalyzer batch scheduler""" % download_url)
...
@@ -126,7 +145,7 @@ Mutalyzer batch scheduler""" % download_url)
message
[
"
Subject
"
]
=
"
Result of your Mutalyzer batch job
"
message
[
"
Subject
"
]
=
"
Result of your Mutalyzer batch job
"
message
[
"
From
"
]
=
from_address
message
[
"
From
"
]
=
from_address
message
[
"
To
"
]
=
mailTo
message
[
"
To
"
]
=
encode_address
(
mailTo
)
try
:
try
:
smtpInstance
=
smtplib
.
SMTP
(
'
localhost
'
)
smtpInstance
=
smtplib
.
SMTP
(
'
localhost
'
)
...
@@ -140,7 +159,8 @@ Mutalyzer batch scheduler""" % download_url)
...
@@ -140,7 +159,8 @@ Mutalyzer batch scheduler""" % download_url)
return
return
try
:
try
:
smtpInstance
.
sendmail
(
from_address
,
mailTo
,
message
.
as_string
())
smtpInstance
.
sendmail
(
from_address
,
encode_address
(
mailTo
),
message
.
as_string
())
except
smtplib
.
SMTPRecipientsRefused
as
e
:
except
smtplib
.
SMTPRecipientsRefused
as
e
:
for
address
,
(
code
,
error
)
in
e
.
recipients
.
items
():
for
address
,
(
code
,
error
)
in
e
.
recipients
.
items
():
print
'
Could not send email to %s: (%s) %s
'
%
(
address
,
print
'
Could not send email to %s: (%s) %s
'
%
(
address
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment