--- header-orig.py 2011-06-02 16:59:56.937459791 +0200 +++ header.py 2011-06-02 17:06:47.604116656 +0200 @@ -313,16 +313,17 @@ formatter = _ValueFormatter(self._headerlen, maxlinelen, self._continuation_ws, splitchars) for string, charset in self._chunks: - lines = string.splitlines() - formatter.feed(lines[0], charset) - for line in lines[1:]: - formatter.newline() - if charset.header_encoding is not None: - formatter.feed(self._continuation_ws, USASCII) - line = ' ' + line.lstrip() - formatter.feed(line, charset) - if len(lines) > 1: - formatter.newline() + if string: + lines = string.splitlines() + formatter.feed(lines[0], charset) + for line in lines[1:]: + formatter.newline() + if charset.header_encoding is not None: + formatter.feed(self._continuation_ws, USASCII) + line = ' ' + line.lstrip() + formatter.feed(line, charset) + if len(lines) > 1: + formatter.newline() formatter.add_transition() value = formatter._str(linesep) if _embeded_header.search(value):