You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2021-12-12.16:35:16.824>created_at=<Date2016-06-07.19:52:43.623>labels= ['expert-email']
title='Exception in BytesGenerator.flatten'updated_at=<Date2021-12-12.16:35:16.823>user='https://bugs.python.org/frispete'
Attached mail, parsed with email.message_from_binary_file results in:
Traceback (most recent call last):
File "./mail_filter.py", line 616, in <module>
ret = main.run()
File "./mail_filter.py", line 605, in runself.process(fp)
File "./mail_filter.py", line 589, in processself.save_message(msg, self._fname +'.out')
File "./mail_filter.py", line 103, in save_message
ofd.write(msg.as_bytes())
File "/usr/lib64/python3.4/email/message.py", line 179, in as_bytes
g.flatten(self, unixfrom=unixfrom)
File "/usr/lib64/python3.4/email/generator.py", line 115, in flattenself._write(msg)
File "/usr/lib64/python3.4/email/generator.py", line 195, in _writeself._write_headers(msg)
File "/usr/lib64/python3.4/email/generator.py", line 422, in _write_headersself._fp.write(self.policy.fold_binary(h, v))
File "/usr/lib64/python3.4/email/policy.py", line 190, in fold_binary
folded =self._fold(name, value, refold_binary=self.cte_type=='7bit')
File "/usr/lib64/python3.4/email/policy.py", line 204, in _foldreturnself.header_factory(name, ''.join(lines)).fold(policy=self)
File "/usr/lib64/python3.4/email/headerregistry.py", line 255, in foldreturn header.fold(policy=policy)
File "/usr/lib64/python3.4/email/_header_value_parser.py", line 300, in foldself._fold(folded)
File "/usr/lib64/python3.4/email/_header_value_parser.py", line 1228, in _fold
rest._fold(folded)
File "/usr/lib64/python3.4/email/_header_value_parser.py", line 338, in _foldif folded.append_if_fits(part, tstr):
File "/usr/lib64/python3.4/email/_header_value_parser.py", line 149, in append_if_fits
token._fold(self)
File "/usr/lib64/python3.4/email/_header_value_parser.py", line 324, in _foldfor part inself.parts:
File "/usr/lib64/python3.4/email/_header_value_parser.py", line 254, in partsif token.startswith_fws():
File "/usr/lib64/python3.4/email/_header_value_parser.py", line 267, in startswith_fwsreturnself[0].startswith_fws()
File "/usr/lib64/python3.4/email/_header_value_parser.py", line 267, in startswith_fwsreturnself[0].startswith_fws()
File "/usr/lib64/python3.4/email/_header_value_parser.py", line 267, in startswith_fwsreturnself[0].startswith_fws()
File "/usr/lib64/python3.4/email/_header_value_parser.py", line 267, in startswith_fwsreturnself[0].startswith_fws()
File "/usr/lib64/python3.4/email/_header_value_parser.py", line 267, in startswith_fwsreturnself[0].startswith_fws()
IndexError: list index out of range
Thanks for helping to triage this, Pedro. I think there is a typo in your example: email.message_from_binary_file(fp) needs to be passed to bs.flatten().
With the following script I'm also unable to reproduce the issue in Python 3.4+:
Now the file is back! If any previous header has a newline before the value the error will not happen. But even with the output correct it isn't as expected.
pslacerda commented on Jun 18, 2016
pslacerdamannequin
Mannequin
More actions
Now the file is back! If any previous header has a newline before the value the error will not happen. But even with the output correct it isn't as expected.
Activity
frispete commentedon Jun 7, 2016
Attached mail, parsed with email.message_from_binary_file results in:
when flattened with BytesGenerator.
pslacerda commentedon Jun 16, 2016
I was unable to reproduce this bug using the following snippet
berkerpeksag commentedon Jun 16, 2016
Thanks for helping to triage this, Pedro. I think there is a typo in your example:
email.message_from_binary_file(fp)needs to be passed tobs.flatten().With the following script I'm also unable to reproduce the issue in Python 3.4+:
Hans-Peter, could you share a reproducer with us? Thanks!
frispete commentedon Jun 16, 2016
Sorry guys for not providing this earlier.
It turned out, that the sub optimal behaviour is related to a unfortunate policy choice: email.policy.SMTP.
pslacerda commentedon Jun 18, 2016
Seems that
token.has_fwsevaluates to True in the following conditioncausing
token._fold(self)where isn't needed and raising the exception. Hope it helps!By the way, why the _header_value_parser.py was removed from the repository?
https://github.com/python/cpython/blob/master/Lib/email/_header_value_parser.py#L144
pslacerda commentedon Jun 18, 2016
Now the file is back! If any previous header has a newline before the value the error will not happen. But even with the output correct it isn't as expected.
pslacerda commentedon Jun 18, 2016
Now the file is back! If any previous header has a newline before the value the error will not happen. But even with the output correct it isn't as expected.
iritkatriel commentedon Dec 12, 2021
I am also unable to reproduce the issue on 3.11 with the attached script and input.
Please create a new issue if this problem still exists in a current python version (>= 3.9).