def mime_to_bytes(msg, header_len): fp = BytesIO() g = email_generator.BytesGenerator(fp, mangle_from_=False, maxheaderlen=header_len) g.flatten(msg) return fp.getvalue()
def as_bytes(self, unixfrom=False, linesep='\n'): """Return the entire formatted message as bytes. Optional `unixfrom' when True, means include the Unix From_ envelope header. This overrides the default as_bytes() implementation to not mangle lines that begin with 'From '. See bug #13433 for details. """ fp = BytesIO() g = generator.BytesGenerator(fp, mangle_from_=False) g.flatten(self, unixfrom=unixfrom, linesep=linesep) return fp.getvalue()
def as_bytes(message, unixfrom=False, linesep='\n'): fp = BytesIO() g = generator.BytesGenerator(fp, mangle_from_=False) g.flatten(message, unixfrom=unixfrom, linesep=linesep) return fp.getvalue()