Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repoze.sendmail adds "\n" to "From:" header when used with EmailMessage in Python 3 #42

Open
FelixSchwarz opened this issue Jul 13, 2018 · 0 comments

Comments

@FelixSchwarz
Copy link

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('[email protected]', '[email protected]', 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).

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

No branches or pull requests

1 participant