Skip to main content

SafeMIMEText

This class provides a secure implementation of MIMEText that prevents header injection by forbidding multi-line headers. It automatically manages payload encoding, specifically handling long lines in UTF-8 content by applying Quoted-Printable encoding to ensure compliance with RFC 5322 line length limits.

Attributes

AttributeTypeDescription
encodingstring or CharsetThe character set used to encode the email content and headers, typically passed during initialization.

Constructor

Signature

def SafeMIMEText(
_text: string,
_subtype: string = plain,
_charset: string = null
) - > null

Parameters

NameTypeDescription
_textstringThe text content of the message.
_subtypestring = plainThe minor type of the MIME message.
_charsetstring = nullThe character set of the message.

Methods


set_payload()

@classmethod
def set_payload(
payload: string,
charset: string = null
) - > null

Sets the content of the email message and automatically selects an appropriate transfer encoding to handle long lines if UTF-8 is used.

Parameters

NameTypeDescription
payloadstringThe actual text content or body to be stored in the email message.
charsetstring = nullThe character set of the payload; if set to 'utf-8', the method may force Quoted-Printable encoding to ensure RFC 5322 compliance for long lines.

Returns

TypeDescription
nullNo value is returned.