Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

proper UTF-8 encoding of email content #585

Merged
merged 1 commit into from Nov 30, 2018
Merged

Conversation

thorli
Copy link
Contributor

@thorli thorli commented Nov 30, 2018

Hello,

I just ran into issues with the Email.py script that postprocessing failed because of errors like this:

Wed Nov 28 2018 01:20:01 DETAIL EMail: Script successfully started
Wed Nov 28 2018 01:20:01 INFO EMail: Traceback (most recent call last):
Wed Nov 28 2018 01:20:01 INFO EMail: File "/downloads/scripts/EMail.py", line 245, in
Wed Nov 28 2018 01:20:01 INFO EMail: msg = MIMEText(text)
Wed Nov 28 2018 01:20:01 INFO EMail: File "/usr/lib/python2.7/email/mime/text.py", line 30, in init
Wed Nov 28 2018 01:20:01 INFO EMail: self.set_payload(_text, _charset)
Wed Nov 28 2018 01:20:01 INFO EMail: File "/usr/lib/python2.7/email/message.py", line 226, in set_payload
Wed Nov 28 2018 01:20:01 INFO EMail: self.set_charset(charset)
Wed Nov 28 2018 01:20:01 INFO EMail: File "/usr/lib/python2.7/email/message.py", line 262, in set_charset
Wed Nov 28 2018 01:20:01 INFO EMail: self._payload = self._payload.encode(charset.output_charset)
Wed Nov 28 2018 01:20:01 INFO EMail: UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 27060: ordinal not in range(128)

I identified german umlauts and some other non ascii characters beeing the cause of these errors. I did some research and found out to avoid errors like this it's best practice to perform a proper encoding of the email body.

In my own environment (nzbget is running in docker on Synology NAS with DSM 6.2) where python sys.getdefaultencoding() is "ascii", everything is working fine again.

Cheers,
Jürgen

Updated script so the email content is encoded properly in UTF-8 to avoid "UnicodeEncodeErrors" when non ascii characters are used like german Umlauts etc.
@hugbug hugbug merged commit da3425a into nzbget:develop Nov 30, 2018
@hugbug
Copy link
Member

hugbug commented Nov 30, 2018

Thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants