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