[issue34220] Serialization of email message without header line length limit and a non-ASCII subject fails with TypeError

Karthikeyan Singaravelan report at bugs.python.org
Wed Jul 25 10:22:17 EDT 2018


Karthikeyan Singaravelan <tir.karthi at gmail.com> added the comment:

I took all the commits made to Lib/email from 3.5 to latest of 3.6 branch with `git log --oneline --format="%h" upstream/3.5..upstream/3.6 Lib/email > commits.txt`

I could see the test fails with a87ba60 and passes with d94ef8f. Probably something to do with a87ba60fe56ae2ebe80ab9ada6d280a6a1f3d552 that had a rewrite the email header folding algorithm as I can see from the issue https://bugs.python.org/issue27240

cpython git:(master) ✗ ./python
Python 3.8.0a0 (heads/bpo34193-dirty:bfdde5a, Jul 25 2018, 07:51:50)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

# commit a87ba60

cpython git:(master) $ git checkout a87ba60 Lib/email && ./python -m unittest bpo34220.py && git reset --quiet HEAD . && git checkout .
.E
======================================================================
ERROR: test_non_ascii_message_no_len_limit (bpo34220.TestEmailMessage)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/cpython/bpo34220.py", line 35, in test_non_ascii_message_no_len_limit
    self.assertTrue(str(msg))
  File "/home/cpython/Lib/email/message.py", line 135, in __str__
    return self.as_string()
  File "/home/cpython/Lib/email/message.py", line 158, in as_string
    g.flatten(self, unixfrom=unixfrom)
  File "/home/cpython/Lib/email/generator.py", line 116, in flatten
    self._write(msg)
  File "/home/cpython/Lib/email/generator.py", line 195, in _write
    self._write_headers(msg)
  File "/home/cpython/Lib/email/generator.py", line 222, in _write_headers
    self.write(self.policy.fold(h, v))
  File "/home/cpython/Lib/email/policy.py", line 183, in fold
    return self._fold(name, value, refold_binary=True)
  File "/home/cpython/Lib/email/policy.py", line 205, in _fold
    return value.fold(policy=self)
  File "/home/cpython/Lib/email/headerregistry.py", line 258, in fold
    return header.fold(policy=policy)
  File "/home/cpython/Lib/email/_header_value_parser.py", line 144, in fold
    return _refold_parse_tree(self, policy=policy)
  File "/home/cpython/Lib/email/_header_value_parser.py", line 2645, in _refold_parse_tree
    part.ew_combine_allowed, charset)
  File "/home/cpython/Lib/email/_header_value_parser.py", line 2722, in _fold_as_ew
    first_part = to_encode[:text_space]
TypeError: slice indices must be integers or None or have an __index__ method

----------------------------------------------------------------------
Ran 2 tests in 0.022s

FAILED (errors=1)

# commit d94ef8f
  
cpython git:(master) $ git checkout d94ef8f Lib/email && ./python -m unittest bpo34220.py && git reset --quiet HEAD . && git checkout .
..
----------------------------------------------------------------------
Ran 2 tests in 0.017s

OK


Hope I am correct on the above approach and there are no C code related changes that need to be made to recompile Python.

Thanks

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34220>
_______________________________________


More information about the Python-bugs-list mailing list