MIMEMixin
This class provides specialized serialization methods for MIME messages, allowing them to be converted into string or byte formats. It specifically overrides default behavior to ensure that lines beginning with 'From ' are not mangled during the flattening process. The class supports optional inclusion of Unix envelope headers and customizable line separators.
Methods
as_string()
@classmethod
def as_string(
unixfrom: boolean = False,
linesep: string = "\n"
) - > string
Return the entire formatted message as a string. Optional `unixfrom' when True, means include the Unix From_ envelope header. This overrides the default as_string() implementation to not mangle lines that begin with 'From '. See bug #13433 for details.
Parameters
| Name | Type | Description |
|---|---|---|
| unixfrom | boolean = False | A flag indicating whether to include the Unix From_ envelope header at the start of the output. |
| linesep | string = "\n" | The character sequence used to terminate lines in the generated string. |
Returns
| Type | Description |
|---|---|
string | The complete message content formatted as a string, including headers and body. |
as_bytes()
@classmethod
def as_bytes(
unixfrom: boolean = False,
linesep: string = "\n"
) - > bytes
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.
Parameters
| Name | Type | Description |
|---|---|---|
| unixfrom | boolean = False | A flag indicating whether to include the Unix From_ envelope header at the start of the output. |
| linesep | string = "\n" | The character sequence used to terminate lines in the generated byte stream. |
Returns
| Type | Description |
|---|---|
bytes | The complete message content formatted as a byte string, suitable for binary transmission or storage. |