def python_message_to_string(msg):
    with closing(StringIO()) as fp:
        g = Generator(fp, mangle_from_=False)
        g.flatten(msg, unixfrom=False)
        return fp.getvalue()
Converts python message to string in a proper way
dataset/ETHPy150Open mailgun/flanker/flanker/mime/message/utils.py/python_message_to_string