mimetools.Message() to python 3 email.message.Message

python, python-2.x, python-3.x

Solution

Alex's own solution from his comment:

import email
stream = io.StringIO() 
rxString = data.decode("utf-8").split('\r\n', 1)[1]
stream.write(rxString) 
headers = email.message_from_string(rxString)

Problem

I try to port a python 2.x code to python 3. The line im struggeling with is ``` from mimetools import Message ... headers = Message(StringIO(data.split('\r\n', 1)[1])) ``` i have figured out that mimetools are no longer present in python 3 and that the replacement is the email class. I tried out to replace it like this: ``` headers = email.message_from_file(io.StringIO(data.split('\r\n', 1)[1])) ``` but with that i get this error: ``` headers = email.message_from_file(io.StringIO(data.split('\r\n', 1)[1])) TypeError: Type str doesn't support the buffer API ``` i am searching for an hint to do this porting from mimetools to email correct. The original code is not from me. It can be found here : https://gist.github.com/jkp/3136208

Original source