On 9/15/22 20:39, Mark Sapiro wrote:
What I think is happening is the original message is parsed into a multipart/alternative Message object with payload of the text/plain and text/html subparts. Then something deletes the top level Content-Type: header which makes the message appear to be text/plain, yet get_payload() still returns the list of two subparts.
As an experiment, I did the following
$ /opt/mailman/mm/bin/mailman shell
Welcome to the GNU Mailman shell
Use commit() to commit changes.
Use abort() to discard changes since the last commit.
Exit with ctrl+D does an implicit commit() but exit() does not.
>>> import pickle
>>> with open('path/to/shunted/pickle', 'rb') as fp:
... msg = pickle.load(fp)
... msgdata = pickle.load(fp)
...
>>> msg
Traceback (most recent call last):
<snip>
File "/usr/local/lib/python3.9/email/generator.py", line 239, in
_handle_text
raise TypeError('string payload expected: %s' % type(payload))
TypeError: string payload expected: <class 'list'>
>>> msg['MIME-Version'] = '1.0'
>>> msg['Content-Type'] = 'multipart/alternative; boundary="aaaabbbb"'
>>> msg
<displays the message as a string with no exception>
>>>
I.e., restoring the missing headers allows the message to be properly flattened. I don't think we can blame email.generator:_handle_text for this as we have corrupted the message object by removing the Content-Type: header.
-- Mark Sapiro <mark@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan