[Email-SIG] Non-string headers

Oleg Broytmann phd at phd.pp.ru
Tue Apr 20 07:18:30 EDT 2004


Hello!

from email import MIMEText
msg = MIMEText.MIMEText("This is a simple message", _charset="latin-1")

msg["Subject"] = "Text"
msg["X-Test"] = 1

print str(msg)

Traceback (most recent call last):
  File "./text.py", line 10, in ?
    print str(msg)
  File "/usr/local/lib/python2.3/email/Message.py", line 116, in __str__
    return self.as_string(unixfrom=True)
  File "/usr/local/lib/python2.3/email/Message.py", line 130, in as_string
    g.flatten(self, unixfrom=unixfrom)
  File "/usr/local/lib/python2.3/email/Generator.py", line 103, in flatten
    self._write(msg)
  File "/usr/local/lib/python2.3/email/Generator.py", line 138, in _write
    self._write_headers(msg)
  File "/usr/local/lib/python2.3/email/Generator.py", line 184, in _write_headers
    header_name=h, continuation_ws='\t').encode()
  File "/usr/local/lib/python2.3/email/Header.py", line 412, in encode
    newchunks += self._split(s, charset, targetlen, splitchars)
  File "/usr/local/lib/python2.3/email/Header.py", line 297, in _split
    elen = charset.encoded_header_len(encoded)
  File "/usr/local/lib/python2.3/email/Charset.py", line 341, in encoded_header_len
    return len(s)
TypeError: len() of unsized object

   Is it a bug or a feature? I personnaly thing it is a feature, but a
colleague of mine initiated a discussion trying to convince me this is a bug in
email and shoud be fixed by calling str() on every header's name (yes, name)
and value.

Oleg.
-- 
     Oleg Broytmann            http://phd.pp.ru/            phd at phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.



More information about the Email-SIG mailing list