Opened 8 years ago

Closed 8 years ago

#27848 closed Bug (fixed)

EmailMessage.attach_file() with .eml file crashes

Reported by: RAMAGE Sébastien Owned by: Claude Paroz <claude@…>
Component: Core (Mail) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by RAMAGE Sébastien)

.eml file could not be attached to EmailMessage using .attach_file() because it raise the following error :
initial_value must be str or None, not bytes

maybe related to mimetype message/rfc822

File "/usr/local/lib/python3.5/dist-packages/django/core/mail/message.py", line 292, in send return self.get_connection(fail_silently).send_messages([self]) 
File "/usr/local/lib/python3.5/dist-packages/django/core/mail/backends/smtp.py", line 107, in send_messages sent = self._send(message) 
File "/usr/local/lib/python3.5/dist-packages/django/core/mail/backends/smtp.py", line 121, in _send message = email_message.message() 
File "/usr/local/lib/python3.5/dist-packages/django/core/mail/message.py", line 256, in message msg = self._create_message(msg) 
File "/usr/local/lib/python3.5/dist-packages/django/core/mail/message.py", line 344, in _create_message return self._create_attachments(msg) 
File "/usr/local/lib/python3.5/dist-packages/django/core/mail/message.py", line 357, in _create_attachments msg.attach(self._create_attachment(*attachment)) 
File "/usr/local/lib/python3.5/dist-packages/django/core/mail/message.py", line 399, in _create_attachment attachment = self._create_mime_attachment(content, mimetype) 
File "/usr/local/lib/python3.5/dist-packages/django/core/mail/message.py", line 380, in _create_mime_attachment content = message_from_string(content) 
File "/usr/lib/python3.5/email/__init__.py", line 38, in message_from_string return Parser(*args, **kws).parsestr(s) 
File "/usr/lib/python3.5/email/parser.py", line 68, in parsestr return self.parse(StringIO(text), headersonly=headersonly) 
TypeError: initial_value must be str or None, not bytes

Attachments (1)

27848-test.diff (572 bytes ) - added by Tim Graham 8 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 by RAMAGE Sébastien, 8 years ago

Description: modified (diff)

comment:2 by RAMAGE Sébastien, 8 years ago

Description: modified (diff)

comment:3 by Tim Graham, 8 years ago

Summary: .eml could not be attached to EmailMessageEmailMessage.attach_file() with .eml file crashes
Triage Stage: UnreviewedAccepted

Reproduced with the attached test.

by Tim Graham, 8 years ago

Attachment: 27848-test.diff added

comment:4 by Dariush Azimi, 8 years ago

Owner: changed from nobody to Dariush Azimi
Status: newassigned

in reply to:  description comment:5 by Darius Azimi, 8 years ago

Hi Ramage,

Trying to reproduce the error. Can you provide the steps to reproduce the error? I see the test case but that is all there is.

Thanks
Dariush

Replying to RAMAGE Sébastien:

.eml file could not be attached to EmailMessage using .attach_file() because it raise the following error :
initial_value must be str or None, not bytes

maybe related to mimetype message/rfc822

File "/usr/local/lib/python3.5/dist-packages/django/core/mail/message.py", line 292, in send return self.get_connection(fail_silently).send_messages([self]) 
File "/usr/local/lib/python3.5/dist-packages/django/core/mail/backends/smtp.py", line 107, in send_messages sent = self._send(message) 
File "/usr/local/lib/python3.5/dist-packages/django/core/mail/backends/smtp.py", line 121, in _send message = email_message.message() 
File "/usr/local/lib/python3.5/dist-packages/django/core/mail/message.py", line 256, in message msg = self._create_message(msg) 
File "/usr/local/lib/python3.5/dist-packages/django/core/mail/message.py", line 344, in _create_message return self._create_attachments(msg) 
File "/usr/local/lib/python3.5/dist-packages/django/core/mail/message.py", line 357, in _create_attachments msg.attach(self._create_attachment(*attachment)) 
File "/usr/local/lib/python3.5/dist-packages/django/core/mail/message.py", line 399, in _create_attachment attachment = self._create_mime_attachment(content, mimetype) 
File "/usr/local/lib/python3.5/dist-packages/django/core/mail/message.py", line 380, in _create_mime_attachment content = message_from_string(content) 
File "/usr/lib/python3.5/email/__init__.py", line 38, in message_from_string return Parser(*args, **kws).parsestr(s) 
File "/usr/lib/python3.5/email/parser.py", line 68, in parsestr return self.parse(StringIO(text), headersonly=headersonly) 
TypeError: initial_value must be str or None, not bytes
Version 0, edited 8 years ago by Darius Azimi (next)

comment:6 by Tim Graham, 8 years ago

To reproduce, apply the patch I provided and run that test from the Django test suite.

comment:7 by Claude Paroz, 8 years ago

Has patch: set
Owner: Dariush Azimi removed
Status: assignednew
Version: 1.9master

comment:8 by Tim Graham, 8 years ago

Triage Stage: AcceptedReady for checkin

comment:9 by Claude Paroz <claude@…>, 8 years ago

Owner: set to Claude Paroz <claude@…>
Resolution: fixed
Status: newclosed

In 9a9e2283:

Fixed #27848 -- Prevented crash when attaching a .eml file to a message

Thanks Sébastien Ramage for the report.

Note: See TracTickets for help on using tickets.
Back to Top