-
Notifications
You must be signed in to change notification settings - Fork 25
Description
When the value of the "From:" header (display name + email address) becomes too long (more than 72 characters) repoze.sendmail will generate a "From:" string which contains a newline (\n
).
("From: " is 6 characters long, default line length is 78 chars in Python's email module)
This seems to be ok when using the regular email.message.Message
class (Python 2+3). However I'm using Python 3's email.message.EmailMessage
class (as I like its API more). In that case I get the following error message (Python 3.4 and 3.6, no other versions tested):
Traceback (most recent call last):
File "repsendmail.py", line 26, in <module>
result = delivery.send('sender@site.example', 'recipient@site.example', msg)
File "…/repoze/sendmail/delivery.py", line 204, in send
encoding.cleanup_message(message)
File "…/repoze/sendmail/encoding.py", line 70, in cleanup_message
message.replace_header(key, value)
File "/usr/lib64/python3.6/email/message.py", line 555, in replace_header
self._headers[i] = self.policy.header_store_parse(k, _value)
File "/usr/lib64/python3.6/email/policy.py", line 145, in header_store_parse
raise ValueError("Header values may not contain linefeed "
ValueError: Header values may not contain linefeed or carriage return characters
It seems to me that calling Header.encode()
is not really correct when you want to put the resulting value back in the EmailMessage
instance.
Attached is a self-contained Python script which demonstrates the issue:
repsendmail.py.txt (with .txt
extension because github does not like .py
files).