def messageToFile(message):
    """
    Flattens a message into a file-like object.
    """
    outFile = StringIO()
    messageGenerator = generator.Generator(outFile, False)
    messageGenerator.flatten(message)
    outFile.seek(0, 0)
    return outFile
Flattens a message into a file-like object.