Opened 4 hours ago
Last modified 6 minutes ago
#36119 new Bug
Attaching email file to email fails if the attachment is using 8bit Content-Transfer-Encoding
Reported by: | Trenton H | Owned by: | |
---|---|---|---|
Component: | Core (Mail) | Version: | 5.1 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If the attached email file is attached to an email, such as the code snipped below, the sending will fail due to the presence of non-ASCII content in the attachment.
email = EmailMessage( subject="subject", body="body", to="someone@somewhere.com", ) email.attach_file(original_file) n_messages = email.send()
Traceback (most recent call last): File "/usr/src/paperless/src/documents/signals/handlers.py", line 989, in email_action n_messages = email.send() ^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/django/core/mail/message.py", line 301, in send return self.get_connection(fail_silently).send_messages([self]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/django/core/mail/backends/smtp.py", line 136, in send_messages sent = self._send(message) ^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/django/core/mail/backends/smtp.py", line 156, in _send from_email, recipients, message.as_bytes(linesep="\r\n") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/django/core/mail/message.py", line 148, in as_bytes g.flatten(self, unixfrom=unixfrom, linesep=linesep) File "/usr/local/lib/python3.12/email/generator.py", line 117, in flatten self._write(msg) File "/usr/local/lib/python3.12/email/generator.py", line 182, in _write self._dispatch(msg) File "/usr/local/lib/python3.12/email/generator.py", line 219, in _dispatch meth(msg) File "/usr/local/lib/python3.12/email/generator.py", line 286, in _handle_multipart g.flatten(part, unixfrom=False, linesep=self._NL) File "/usr/local/lib/python3.12/email/generator.py", line 117, in flatten self._write(msg) File "/usr/local/lib/python3.12/email/generator.py", line 182, in _write self._dispatch(msg) File "/usr/local/lib/python3.12/email/generator.py", line 219, in _dispatch meth(msg) File "/usr/local/lib/python3.12/email/generator.py", line 372, in _handle_message g.flatten(msg.get_payload(0), unixfrom=False, linesep=self._NL) File "/usr/local/lib/python3.12/email/generator.py", line 117, in flatten self._write(msg) File "/usr/local/lib/python3.12/email/generator.py", line 182, in _write self._dispatch(msg) File "/usr/local/lib/python3.12/email/generator.py", line 219, in _dispatch meth(msg) File "/usr/local/lib/python3.12/email/generator.py", line 446, in _handle_text super(BytesGenerator,self)._handle_text(msg) File "/usr/local/lib/python3.12/email/generator.py", line 263, in _handle_text self._write_lines(payload) File "/usr/local/lib/python3.12/email/generator.py", line 156, in _write_lines self.write(line) File "/usr/local/lib/python3.12/email/generator.py", line 420, in write self._fp.write(s.encode('ascii', 'surrogateescape')) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnicodeEncodeError: 'ascii' codec can't encode characters in position 10-15: ordinal not in range(128)
Attachments (1)
Note:
See TracTickets
for help on using tickets.
Trenton, It would be helpful if you could provide some more information about this because I'm not sure we have any triagers who are experts in this area. Where is Django at fault and how can we fix it?