'Dump message contents to target file.'

def _dump_message(self, message, target, mangle_from_=False):

    if isinstance(message, email.message.Message):
        buffer = StringIO.StringIO()
        gen = email.generator.Generator(buffer, mangle_from_, 0)
        gen.flatten(message)
        buffer.seek(0)
        data = buffer.read().replace('\n', os.linesep)
        target.write(data)
        if (self._append_newline and (not data.endswith(os.linesep))):
            target.write(os.linesep)
    elif isinstance(message, str):
        if mangle_from_:
            message = message.replace('\nFrom    ', '\n>From    ')
        message = message.replace('\n', os.linesep)
        target.write(message)
        if (self._append_newline and (not message.endswith(os.linesep))):
            target.write(os.linesep)
    elif hasattr(message, 'read'):
        lastline = None
        while True:
            line = message.readline()
            if (line == ''):
                break
            if (mangle_from_ and line.startswith('From    ')):
                line = ('>From    ' + line[5:])
            line = line.replace('\n', os.linesep)
            target.write(line)
            lastline = line
        if (self._append_newline and lastline and (not lastline.endswith(os.linesep))):
            target.write(os.linesep)
    else:
        raise TypeError(('Invalid    message    type:    %s' % type(message)))
