HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/django/core/mail/__pycache__/message.cpython-310.pyc
o

3�a�B�@s�ddlZddlmZmZmZmZddlm	Z	ddl
mZddlm
Z
mZddlmZddlmZddlmZdd	lmZdd
lmZddlmZmZmZmZddlmZm Z dd
l!m"Z"ddl#m$Z$ddl%m&Z&ddl'm(Z(m)Z)e�d�Z*de*_+e�d�Z,ej-e,_+dZ.dZ/Gdd�de0�Z1hd�Z2dd�Z3dd�Z4Gdd�d�Z5Gdd�de5e�Z6Gdd �d e5e�Z7Gd!d"�d"e5e�Z8Gd#d$�d$�Z9Gd%d&�d&e9�Z:dS)'�N)�charset�encoders�	generator�message_from_string)�HeaderParseError)�Header)�Address�parser)�Message)�MIMEBase)�MIMEMessage)�
MIMEMultipart)�MIMEText)�
formataddr�
formatdate�getaddresses�
make_msgid)�BytesIO�StringIO)�Path)�settings)�DNS_NAME)�	force_str�punycode�utf-8zapplication/octet-streami�c@seZdZdS)�BadHeaderErrorN)�__name__�
__module__�__qualname__�rr�:/usr/lib/python3/dist-packages/django/core/mail/message.pyr#sr>�reply-to�	resent-cc�	resent-to�
resent-bcc�resent-from�
resent-sender�cc�to�bcc�from�sendercs��ptj�t|�}d|vsd|vrtd||f��z|�d�Wn.tyN|��tvr=d��fdd�t	|f�D��}nt
|����}Y||fSY||fSw|��dkr[t
|���}||fS)	z6Forbid multi-line headers to prevent header injection.�
�
z;Header values can't contain newlines (got %r for header %r)�ascii�, c3s�|]}t|��VqdS�N)�sanitize_address)�.0�addr��encodingrr �	<genexpr>As�z,forbid_multi_line_headers.<locals>.<genexpr>�subject)r�DEFAULT_CHARSET�strr�encode�UnicodeEncodeError�lower�ADDRESS_HEADERS�joinrr)�name�valr5rr4r �forbid_multi_line_headers7s"
 ��rAc

CsDd}t|t�s=t|�}z	t�|�\}}Wntttfy$td|��w|r/td||f��|jp3d}|j	}|j
p;d}n|\}}|�dd�\}}|||}d|vsWd|vr[td	��z
|�d
�t
|���}Wntyxt
||���}Ynwz|�d
�Wnty�t
||���}Ynwt|�}t||d�}	t||	jf�S)zF
    Format a pair of (name, address) or an email address string.
    NzInvalid address "%s"z2Invalid address; only %s could be parsed from "%s"��@�r,r-z7Invalid address; address parts cannot contain newlines.r.)�username�domain)�
isinstance�tuplerr	�get_mailboxr�
ValueError�
IndexError�display_name�
local_partrF�rsplitr:rr;rrr�	addr_spec)
r3r5�address�token�rest�nm�	localpartrF�
address_parts�parsed_addressrrr r1JsH
���

��r1c@s eZdZddd�Zddd�ZdS)	�	MIMEMixinFr,cC�,t�}tj|dd�}|j|||d�|��S)a&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.
        F��mangle_from_��unixfrom�linesep)rr�	Generator�flatten�getvalue��selfr\r]�fp�grrr �	as_stringx�zMIMEMixin.as_stringcCrX)a"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.
        FrYr[)rr�BytesGeneratorr_r`rarrr �as_bytes�rfzMIMEMixin.as_bytesN)Fr,)rrrrerhrrrr rWws

rWc@seZdZdd�ZdS)�SafeMIMEMessagecCs"t||d�\}}t�|||�dS)Nr.)rAr�__setitem__�rbr?r@rrr rj�szSafeMIMEMessage.__setitem__N)rrrrjrrrr ri�sric@s(eZdZd	dd�Zdd�Zd
dd�ZdS)�SafeMIMEText�plainNcCs||_tj||||d�dS)N)�_subtype�_charset)r5r�__init__)rb�_textrnrorrr rp�szSafeMIMEText.__init__cC�$t|||j�\}}t�|||�dSr0)rAr5rrjrkrrr rj��zSafeMIMEText.__setitem__cCsJ|dkrt|tj�stdd�|��D��}|rtnt}tj|||d�dS)Nrcss �|]}t|���tkVqdSr0)�lenr:�RFC5322_EMAIL_LINE_LENGTH_LIMIT)r2�linerrr r6�s
��
�z+SafeMIMEText.set_payload.<locals>.<genexpr>)r)rG�Charset�any�
splitlines�utf8_charset_qp�utf8_charsetr�set_payload)rb�payloadr�has_long_linesrrr r|�s�zSafeMIMEText.set_payload)rmNr0)rrrrprjr|rrrr rl�s
rlc@seZdZddd�Zdd�ZdS)�SafeMIMEMultipart�mixedNcKs"||_tj||||fi|��dSr0)r5r
rp)rbrn�boundary�	_subpartsr5�_paramsrrr rp�szSafeMIMEMultipart.__init__cCrrr0)rAr5r
rjrkrrr rj�rszSafeMIMEMultipart.__setitem__)r�NNN)rrrrprjrrrr r�s
rc@s�eZdZdZdZdZdZ			ddd�Zd d	d
�Zdd�Z	d
d�Z
d dd�Zd!dd�Zd"dd�Z
dd�Zdd�Zdd�Zd"dd�Zdd�ZdS)#�EmailMessagez"A container for email information.rmr�NrBcCs|rt|t�rtd��t|�|_ng|_|	r%t|	t�rtd��t|	�|_ng|_|r9t|t�r3td��t|�|_ng|_|
rMt|
t�rGtd��t|
�|_ng|_|pTtj	|_
||_|p\d|_g|_
|rx|D]}t|t�rr|�|�qe|j|�qe|p{i|_||_dS)�g
        Initialize a single email message (which can be sent to multiple
        recipients).
        z%"to" argument must be a list or tuplez%"cc" argument must be a list or tuplez&"bcc" argument must be a list or tuplez+"reply_to" argument must be a list or tuplerBN)rGr9�	TypeError�listr(r'r)�reply_tor�DEFAULT_FROM_EMAIL�
from_emailr7�body�attachmentsr�attach�
extra_headers�
connection)rbr7r�r�r(r)r�r��headersr'r��
attachmentrrr rp�s>







zEmailMessage.__init__FcCs$ddlm}|js||d�|_|jS)Nr)�get_connection)�
fail_silently)�django.core.mailr�r�)rbr�r�rrr r��szEmailMessage.get_connectioncCs�|jptj}t|j|j|�}|�|�}|j|d<|j�	d|j
�|d<|�|d|j�|�|d|j
�|�|d|j�dd�|jD�}d|vrNttjd	�|d
<d|vrYttd�|d
<|j��D]\}}|��dkrl|||<q^|S)N�Subject�From�To�CczReply-TocSsg|]}|���qSr)r<)r2�keyrrr �
<listcomp>�z(EmailMessage.message.<locals>.<listcomp>�date)�	localtime�Datez
message-id)rFz
Message-IDr*)r5rr8rlr��content_subtype�_create_messager7r��getr��_set_list_header_if_not_emptyr(r'r�r�EMAIL_USE_LOCALTIMErr�itemsr<)rbr5�msg�header_namesr?�valuerrr �message�s$

�zEmailMessage.messagecCsdd�|j|j|jD�S)z�
        Return a list of all recipients of the email (includes direct
        addressees as well as Cc and Bcc entries).
        cSsg|]}|r|�qSrr)r2�emailrrr r�r�z+EmailMessage.recipients.<locals>.<listcomp>)r(r'r))rbrrr �
recipientsszEmailMessage.recipientscCs|��sdS|�|��|g�S)zSend the email message.r)r�r��
send_messages)rbr�rrr �sendszEmailMessage.sendcCs�t|t�r|dusJ�|dusJ�|j�|�dS|dusJ�|p)t�|�dp)t}|�dd�\}}|dkrMt|t�rMz|�	�}Wnt
yLt}Ynw|j�|||f�dS)a�
        Attach a file with the given filename and content. The filename can
        be omitted and the mimetype is guessed, if not provided.

        If the first parameter is a MIMEBase subclass, insert it directly
        into the resulting message attachments.

        For a text/* mimetype (guessed or specified), when a bytes object is
        specified as content, decode it as UTF-8. If that fails, set the
        mimetype to DEFAULT_ATTACHMENT_MIME_TYPE and don't decode the content.
        Nr�/rD�text)rGrr��append�	mimetypes�
guess_type�DEFAULT_ATTACHMENT_MIME_TYPE�split�bytes�decode�UnicodeDecodeError)rb�filename�content�mimetype�basetype�subtyperrr r�s

�zEmailMessage.attachcCsPt|�}|�d��}|��}|�|j||�Wd�dS1s!wYdS)al
        Attach a file from the filesystem.

        Set the mimetype to DEFAULT_ATTACHMENT_MIME_TYPE if it isn't specified
        and cannot be guessed.

        For a text/* mimetype (guessed or specified), decode the file's content
        as UTF-8. If that fails, set the mimetype to
        DEFAULT_ATTACHMENT_MIME_TYPE and don't decode the content.
        �rbN)r�open�readr�r?)rb�pathr��filer�rrr �attach_file>s
"�zEmailMessage.attach_filecCs
|�|�Sr0)�_create_attachments�rbr�rrr r�Ns
zEmailMessage._create_messagecCsr|jr7|jptj}|}t|j|d�}|js|��r|�|�|jD]}t	|t
�r.|�|�q!|�|j|��q!|S�N)rnr5)r�r5rr8r�
mixed_subtyper��is_multipartr�rGr�_create_attachment)rbr�r5�body_msgr�rrr r�Qs


z EmailMessage._create_attachmentscCs�|�dd�\}}|dkr|jptj}t|||�}|S|dkr>|dkr>t|t�r,|��}nt|t�s7t	t
|��}t||�}|St||�}|�
|�t�|�|S)z�
        Convert the content, mimetype pair into a MIME attachment object.

        If the mimetype is message/rfc822, content may be an
        email.Message or EmailMessage object, as well as a str.
        r�rDr�r��rfc822)r�r5rr8rlrGr�r�r
rrrirr|�Encoders�
encode_base64)rbr�r�r�r�r5r�rrr �_create_mime_attachment_s �




�

z$EmailMessage._create_mime_attachmentcCsP|�||�}|r&z|�d�Wntydd|f}Ynw|jdd|d�|S)zg
        Convert the filename, content, mimetype triple into a MIME attachment
        object.
        r.rrBzContent-Dispositionr�)r�)r�r:r;�
add_header)rbr�r�r�r�rrr r�}s�zEmailMessage._create_attachmentcCsJ|r#z|j|}Wntyd�dd�|D��}Ynw|||<dSdS)zt
        Set msg's header, either from self.extra_headers, if present, or from
        the values argument.
        r/css�|]}t|�VqdSr0)r9)r2�vrrr r6�s�z=EmailMessage._set_list_header_if_not_empty.<locals>.<genexpr>N)r��KeyErrorr>)rbr��header�valuesr�rrr r��s��z*EmailMessage._set_list_header_if_not_empty)
rBrBNNNNNNNN)F)NNNr0)rrr�__doc__r�r�r5rpr�r�r�r�r�r�r�r�r�r�r�rrrr r��s(
�
,


 
r�csDeZdZdZdZ			d
�fdd�	Zdd�Zd	d
�Zdd�Z�Z	S)�EmailMultiAlternativesz�
    A version of EmailMessage that makes it easy to send multipart/alternative
    messages. For example, including text and HTML versions of the text is
    made easier.
    �alternativerBNcs,t��|||||||||
|�
|	pg|_dS)r�N)�superrp�alternatives)rbr7r�r�r(r)r�r�r�r�r'r���	__class__rr rp�s
�zEmailMultiAlternatives.__init__cCs,|dusJ�|dusJ�|j�||f�dS)z-Attach an alternative content representation.N)r�r�)rbr�r�rrr �attach_alternative�sz)EmailMultiAlternatives.attach_alternativecCs|�|�|��Sr0)r��_create_alternativesr�rrr r��sz&EmailMultiAlternatives._create_messagecCsT|jptj}|jr(|}t|j|d�}|jr|�|�|jD]
}|�|j|��q|Sr�)	r5rr8r�r�alternative_subtyper�r�r�)rbr�r5r�r�rrr r��s

z+EmailMultiAlternatives._create_alternatives)rBrBNNNNNNNNN)
rrrr�r�rpr�r�r��
__classcell__rrr�r r��s�
r�);r�r�rrwrr�rr�email.errorsr�email.headerr�email.headerregistryrr	�
email.messager
�email.mime.baser�email.mime.messager�email.mime.multipartr
�email.mime.textr�email.utilsrrrr�iorr�pathlibr�django.confr�django.core.mail.utilsr�django.utils.encodingrrr{�
body_encodingrz�QPr�rurJrr=rAr1rWrirlrr�r�rrrr �<module>sB

-]