HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib64/python3.10/site-packages/__pycache__/flask_mail.cpython-310.pyc
o

4�(TF�@s�dZddlmZdZddlZddlZddlZddlZddlZddl	Z	ddl
mZddlm
Z
ddlmZddlmZdd	lmZdd
lmZddlmZmZmZmZddlmZdd
lmZejddkZ e omejddkZ!e re"fZ#e"Z$ddl
m%Z%e%j&Z'ne(fZ#e)Z$dZ'e�*dej+dd�Gdd�de,�Z-d1dd�Z.d2dd�Z/d2dd�Z0d2dd�Z1dd�Z2Gd d!�d!e3�Z4Gd"d#�d#e5�Z6Gd$d%�d%e3�Z7Gd&d'�d'e3�Z8Gd(d)�d)e3�Z9Gd*d+�d+e9�Z:Gd,d-�d-e9�Z;e�<�Z=e=j>d.d/d0�Z?dS)3z�
    flaskext.mail
    ~~~~~~~~~~~~~

    Flask extension for sending email.

    :copyright: (c) 2010 by Dan Jacob.
    :license: BSD, see LICENSE for more details.
�)�with_statementz0.9.1N)�charset)�
encode_base64)�MIMEBase)�
MIMEMultipart)�MIMEText)�Header)�
formatdate�
formataddr�
make_msgid�	parseaddr)�contextmanager)�current_app���)�policy�utf-8c@seZdZdd�Zdd�ZdS)�FlaskMailUnicodeDecodeErrorcGs||_tj|g|�R�dS�N)�obj�UnicodeDecodeError�__init__)�selfr�args�r�C/home/arjun/projects/env/lib/python3.10/site-packages/flask_mail.pyr4sz$FlaskMailUnicodeDecodeError.__init__cCs t�|�}d||jt|j�fS)Nz%s. You passed in %r (%s))r�__str__r�type)r�originalrrrr8s
z#FlaskMailUnicodeDecodeError.__str__N)�__name__�
__module__�__qualname__rrrrrrr3sr�strictc
s�t|t�r|Sz<t|t�s;tr$t|t�rt|���}W|St|�}W|St|d�r0|��}W|Stt|����}W|S|����}W|Styq}z"t|t	�sYt
|g|j�R��d���fdd�|D��}WYd}~|Sd}~ww)z�
    Similar to smart_text, except that lazy instances are resolved to
    strings, rather than kept as lazy objects.

    If strings_only is True, don't convert (some) non-string-like objects.
    �__unicode__� csg|]	}t|�t���qSr)�
force_text�strings_only)�.0�arg��encoding�errorsrr�
<listcomp>Xs
��zforce_text.<locals>.<listcomp>N)
�
isinstance�	text_type�string_types�PY3�bytes�hasattrr$�decoder�	Exceptionrr�join)�sr+r,�err*rr&=s4



�
�
�	��
���r&cCs\z|�d�W|Sty-zt||���}WY|Sty,t|d���}YY|Sww)N�asciir)�encode�UnicodeEncodeErrorr)�subjectr+rrr�sanitize_subject\s����r=cCs�t|t�rtt|��}|\}}z	t||���}Wnty(t|d���}Ynwz|�d�Wn3tycd|vrZ|�dd�\}}tt||��}|�d��	d�}d�
||g�}nt||���}Ynwt||f�S)Nrr9�@r�idna)r.r0rr&rr:r;�split�strr4r6r
)�addrr+�nm�	localpart�domainrrr�sanitize_addressfs(
���rFcst�fdd�|�S)Ncs
t|��Sr)rF)r8�r+rr�<lambda>}s
z$sanitize_addresses.<locals>.<lambda>)�map)�	addressesr+rrGr�sanitize_addresses|srKcCs|rd|vs
d|vrdSdS)z,Used by has_bad_header to check for \r or \n�
�
TFr)�linerrr�_has_newline�srOc@sBeZdZdZdd�Zdd�Zdd�Zdd	�Zddd�Zd
d�Z	d
S)�
ConnectionzHandles connection to host.cCs
||_dSr)�mail)rrQrrrr�s
zConnection.__init__cCs$|jjrd|_n|��|_d|_|S)Nr)rQ�suppress�host�configure_host�
num_emails�rrrr�	__enter__�s

zConnection.__enter__cCs|jr
|j��dSdSr)rS�quit)r�exc_type�	exc_value�tbrrr�__exit__�s�zConnection.__exit__cCs||jjrt�|jj|jj�}n
t�|jj|jj�}|�t|jj	��|jj
r*|��|jjr<|jj
r<|�|jj|jj
�|Sr)rQ�use_ssl�smtplib�SMTP_SSL�server�port�SMTP�set_debuglevel�int�debug�use_tls�starttls�username�password�login)rrSrrrrT�szConnection.configure_hostNcCs�|jsJd��|jsJd��|��rt�|jdurt��|_|jr?|j�t|p)|j�t	t
|j��tr6|��n|�
�|j|j�tj|t��d�|jd7_|j|jjkrhd|_|jrj|j��|��|_dSdSdS)z�Verifies and sends message.

        :param message: Message instance.
        :param envelope_from: Email address to be used in MAIL FROM command.
        zNo recipients have been addedzRThe message does not specify a sender and a default sender has not been configuredN)�apprr)�send_to�sender�has_bad_headers�BadHeaderError�date�timerS�sendmailrF�listrKr1�as_bytes�	as_string�mail_options�rcpt_options�email_dispatched�sendr�_get_current_objectrUrQ�
max_emailsrXrT)r�message�
envelope_fromrrrry�s0�

�
�zConnection.sendcO�|�t|i|���dS�ztShortcut for send(msg).

        Takes same arguments as Message constructor.

        :versionadded: 0.3.5
        N�ry�Message�rr�kwargsrrr�send_message��zConnection.send_messager)
r r!r"�__doc__rrWr\rTryr�rrrrrP�s

#rPc@seZdZdS)roN)r r!r"rrrrro�sroc@seZdZdZ		ddd�ZdS)�
Attachmentz�Encapsulates file attachment information.

    :versionadded: 0.3.5

    :param filename: filename of attachment
    :param content_type: file mimetype
    :param data: the raw file data
    :param disposition: content-disposition (if any)
    NcCs*||_||_||_|pd|_|pi|_dS)N�
attachment)�filename�content_type�data�disposition�headers�rr�r�r�r�r�rrrr�s

zAttachment.__init__�NNNNN)r r!r"r�rrrrrr��s

�r�c@s�eZdZdZ														ddd�Zedd��Zd d	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Z					d!dd�ZdS)"r�a�Encapsulates an email message.

    :param subject: email subject header
    :param recipients: list of email addresses
    :param body: plain text message
    :param html: HTML message
    :param sender: email sender address, or **MAIL_DEFAULT_SENDER** by default
    :param cc: CC list
    :param bcc: BCC list
    :param attachments: list of Attachment instances
    :param reply_to: reply-to address
    :param date: send date
    :param charset: message character set
    :param extra_headers: A dictionary of additional headers for the message
    :param mail_options: A list of ESMTP options to be used in MAIL FROM command
    :param rcpt_options:  A list of ESMTP options to be used in RCPT commands
    �NcCs�|ptjdj}t|t�rd|}|pg|_||_||_|	|_|p"g|_	|p'g|_
||_||_|
|_
t�|_||_||_|
p?g|_|pDg|_|pIg|_dS)NrQz%s <%s>)r�
extensions�default_senderr.�tuple�
recipientsr<rm�reply_to�cc�bcc�body�htmlrpr�msgIdr�
extra_headersrvrw�attachments)rr<r�r�r�rmr�r�r�r�rprr�rvrwrrrrs$





zMessage.__init__cCs&t|j�t|jp	d�Bt|jpd�BS)Nr)�setr�r�r�rVrrrrl&s&zMessage.send_to�plaincCs|jpd}t|||d�S)z�Creates a MIMEText object with the given subtype (default: 'plain')
        If the text is unicode, the utf-8 charset is used.
        r)�_subtype�_charset)rr)r�text�subtyperrrr�	_mimetext*s
zMessage._mimetextc	Csptjdj}|jp
d}|jpg}t|�dkr |js |�|j�}n6t|�dkr6|js6t	�}|�
|�|j��n t	�}t	d�}|�
|�|jd��|�
|�|jd��|�
|�|jrctt
|j�|�|d<t|j|�|d<d	�ttt|j|����|d
<t|jdd�|d
<|j|d<|jr�d	�ttt|j|����|d<|jr�t|j|�|d<|jr�|j��D]\}}|||<q�t�dtj�}|D]p}	t|	j �!d��}
|
�"|	j#�t$|
�|	j%}|r�|r�t&�'d|�}|�(dd��)d�}|�*d|��+�}z	|o�|�(d�Wnt,�yt-�s
|�(d�}dd|f}Ynw|
j.d|	j/|d�|	j0D]\}}
|
�.||
��q|�
|
�q�t1�r6t1|_2|S)zCreates the emailrQrr�alternativer�r��Subject�Fromz, �ToT)�	localtime�Datez
Message-ID�CczReply-Toz[\s]+�/�NFKDr9�ignorer%�utf8�UTF8r�zContent-Disposition)r�)3rr��ascii_attachmentsrr��lenr�r�r�r�attachr<r=r&rFrmr6rsr�rKr�r	rpr�r�r�r��items�re�compile�UNICODErr�r@�set_payloadr�rr��unicodedata�	normalizer:r4�sub�stripr;r1�
add_headerr�r��message_policyr)rr�r+r��msgr��k�v�SPACESr��fr��key�valuerrr�_message1sl




�
��zMessage._messagecCs|����Sr)r�rurVrrrru|szMessage.as_stringcCs(tr|����S|�����|jpd�S)Nr)�PY34r�rtrur:rrVrrrrtszMessage.as_bytescC�|��Sr)rurVrrrr��zMessage.__str__cCr�r)rtrVrrr�	__bytes__�r�zMessage.__bytes__cCs�|j|jg|j}|D]	}t|�rdSq|jrNt|j�rNt|j�d��D](\}}|s.dS|dkr;|ddvr;dSt|�rBdSt|���dkrMdSq%dS)z�Checks for bad headers i.e. newlines in subject, sender or recipients.
        RFC5322: Allows multiline CRLF with trailing whitespace (FWS) in headers
        Tz
rz	 F)	rmr�r�rOr<�	enumerater@r�r�)rr��header�linenumrNrrrrn�s$�
�zMessage.has_bad_headerscCs(ddlm}d}|t|�dd�|��S)Nr)�warnzIis_bad_headers is deprecated, use the new has_bad_headers method instead.r)�
stacklevel)�warningsr��DeprecationWarningrn)rr�r�rrr�is_bad_headers�szMessage.is_bad_headerscCs|�|�dS)zVerifies and sends the message.N)ry)r�
connectionrrrry�szMessage.sendcCs|j�|�dS)zfAdds another recipient to the message.

        :param recipient: email address of recipient.
        N)r��append)r�	recipientrrr�
add_recipient�szMessage.add_recipientcCs|j�t|||||��dS)z�Adds an attachment to the message.

        :param filename: filename of attachment
        :param content_type: file mimetype
        :param data: the raw file data
        :param disposition: content-disposition (if any)
        N)r�r�r�r�rrrr��s
�zMessage.attach)r�NNNNNNNNNNNNN)r�r�)r r!r"r�r�propertyrlr�r�rurtrr�rnr�ryr�r�rrrrr��sF
�$

K	�r�c@s0eZdZedd��Zdd�Zdd�Zdd�Zd	S)
�
_MailMixinc	#sL�tstd��g��fdd�}t�|�z�VWt�|�dSt�|�w)ayRecords all messages. Use in unit tests for example::

            with mail.record_messages() as outbox:
                response = app.test_client.get("/email-sending-view/")
                assert len(outbox) == 1
                assert outbox[0].subject == "testing"

        You must have blinker installed in order to use this feature.
        :versionadded: 0.4
        zblinker must be installedcs��|�dSr)r�)r|rk��outboxrr�_record��z+_MailMixin.record_messages.<locals>._recordN)rx�RuntimeError�connect�
disconnect)rr�rr�r�record_messages�s�

z_MailMixin.record_messagescCs8|���}|�|�Wd�dS1swYdS)z�Sends a single message instance. If TESTING is True the message will
        not actually be sent.

        :param message: a Message instance.
        N)r�ry)rr|r�rrrry�s
"�z_MailMixin.sendcOr~rr�r�rrrr��r�z_MailMixin.send_messagecCs8t|dd�pt}zt|jd�WStytd��w)z$Opens a connection to the mail host.rkNrQz9The curent application was not configured with Flask-Mail)�getattrrrPr��KeyErrorr��rrkrrrr��s�z_MailMixin.connectN)r r!r"r
r�ryr�r�rrrrr��s


r�c@seZdZ	ddd�ZdS)�_MailFcCsF||_||_||_||_||_||_||_||_|	|_|
|_	||_
dSr)r`rhrirarfr]r�rer{rRr�)rr`rhrirarfr]r�rer{rRr�rrrrs
z_Mail.__init__N)F)r r!r"rrrrrr�s�r�c@s4eZdZdZddd�Zd
dd�Zdd	�Zd
d�ZdS)�Mailz<Manages email messaging

    :param app: Flask instance
    NcCs(||_|dur|�|�|_dSd|_dSr)rk�init_app�stater�rrrrs
z
Mail.__init__FcCspt|�dd�|�d�|�d�|�dd�|�dd�|�d	d�|�d
�t|�d|��|�d�|�d
|�|�dd��S)N�MAIL_SERVERz	127.0.0.1�
MAIL_USERNAME�
MAIL_PASSWORD�	MAIL_PORT��MAIL_USE_TLSF�MAIL_USE_SSL�MAIL_DEFAULT_SENDER�
MAIL_DEBUG�MAIL_MAX_EMAILS�MAIL_SUPPRESS_SEND�MAIL_ASCII_ATTACHMENTS)r��getrd)r�configre�testingrrr�	init_mails





�zMail.init_mailcCs0|�|j|j|j�}t|di�|_||jd<|S)z�Initializes your mail settings from the application settings.

        You can use this if you want to set up your Mail instance
        at configuration time.

        :param app: Flask application instance
        r�rQ)r�r�rer�r�r�)rrkr�rrrr�.s
z
Mail.init_appcCst|j|d�Sr)r�r�)r�namerrr�__getattr__=r�zMail.__getattr__r)FF)r r!r"r�rr�r�r�rrrrr�s

r�zemail-dispatchedz�
Signal sent when an email is dispatched. This signal will also be sent
in testing mode, even though the email will not actually be sent.
)�doc)rr#)r)@r��
__future__r�__version__r��blinkerr^�sysrqr��emailr�email.encodersr�email.mime.baser�email.mime.multipartr�email.mime.textr�email.headerr�email.utilsr	r
rr�
contextlibr
�flaskr�version_infor1r�rAr0r/rrbr��
basestring�unicode�add_charset�SHORTESTrrr&r=rFrKrO�objectrPr5ror�r�r�r�r��	Namespace�signals�signalrxrrrr�<module>sZ






QX;/