Your IP : 3.140.195.8


Current Path : /opt/alt/python35/lib64/python3.5/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/__pycache__/smtplib.cpython-35.opt-2.pyc



���]h��@sQddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Zddddddd	d
ddd
dgZdZdZdZdZdZejdej�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd	�d	e�Z Gdd
�d
e�Z!Gdd�de�Z"d d�Z#d!d"�Z$d#d
�Z%d$d%�Z&d&d'�Z'yddl(Z(Wne)k
r3d(Z*YnXd)Z*Gd*d�d�Z+e*rvGd+d,�d,e+�Z,ej-d,�d-Z.Gd.d/�d/e+�Z/e0d0krMd1d2�Z1e1d3�Z2e1d4�j3d5�Z4e5d6�d7Z6x%ej7j8�Z9e9r�Pe6e9Z6q�We5d8e:e6��e+d9�Z;e;j<d:�e;j=e2e4e6�e;j>�dS);�N)�body_encode�
SMTPException�SMTPServerDisconnected�SMTPResponseException�SMTPSenderRefused�SMTPRecipientsRefused�
SMTPDataError�SMTPConnectError�
SMTPHeloError�SMTPAuthenticationError�	quoteaddr�	quotedata�SMTP�i�z
s
i z	auth=(.*)c@seZdZdS)rN)�__name__�
__module__�__qualname__�rr�,/opt/alt/python35/lib64/python3.5/smtplib.pyrGsc@seZdZdS)�SMTPNotSupportedErrorN)rrrrrrrrJsrc@seZdZdS)rN)rrrrrrrrQsc@seZdZdd�ZdS)rcCs%||_||_||f|_dS)N)�	smtp_code�
smtp_error�args)�self�code�msgrrr�__init__bs		zSMTPResponseException.__init__N)rrrrrrrrrYs	c@seZdZdd�ZdS)rcCs1||_||_||_|||f|_dS)N)rr�senderr)rrrrrrrrns			zSMTPSenderRefused.__init__N)rrrrrrrrrgsc@seZdZdd�ZdS)rcCs||_|f|_dS)N)�
recipientsr)rrrrrr|s	zSMTPRecipientsRefused.__init__N)rrrrrrrrrtsc@seZdZdS)rN)rrrrrrrr�sc@seZdZdS)r	N)rrrrrrrr	�sc@seZdZdS)r
N)rrrrrrrr
�sc@seZdZdS)rN)rrrrrrrr�scCsStjj|�\}}||fdkrK|j�jd�rC|Sd|Sd|S)N��<z<%s>)rr)�email�utils�	parseaddr�strip�
startswith)�
addrstring�displayname�addrrrrr�scCs2tjj|�\}}||fdkr.|S|S)Nr)rr)r!r"r#)r&r'r(rrr�
_addr_only�sr)cCs"tjddtjdt|��S)Nz(?m)^\.z..z(?:\r\n|\n|\r(?!\n)))�re�sub�CRLF)�datarrrr
�scCstjdd|�S)Ns(?m)^\.s..)r*r+)Zbindatarrr�_quote_periods�sr.cCstjdt|�S)Nz(?:\r\n|\n|\r(?!\n)))r*r+r,)r-rrr�	_fix_eols�sr/FTc@s8eZdZdZdZdZdZdZdZe	Z
dddejddd�Z
dd�Zd	d
�Zdd�Zd
d�Zdd�Zddddd�Zdd�Zddd�Zdd�Zddd�Zddd�Zddd�Zd d!�Zdd"d#�Zd$d%�Zd&d'�Zd(d)�Zgd*d+�Zgd,d-�Z d.d/�Z!d0d1�Z"e"Z#d2d3�Z$d4d5�Z%d6d7d8d9�Z&dd:d;�Z'dd<d=�Z(dd>d?�Z)d6d7d@dA�Z*ddddBdC�Z+ggdDdE�Z,ddgidFdG�Z-dHdI�Z.dJdK�Z/dS)LrrN�ehlorc
Cs�||_||_i|_d|_||_|rp|j||�\}}|dkrp|j�t||��|dk	r�||_nht	j
�}d|kr�||_nDd}	yt	jt	j��}	Wnt	j
k
r�YnXd|	|_dS)N�ascii���.z	127.0.0.1z[%s])�_host�timeout�esmtp_features�command_encoding�source_address�connect�closer	�local_hostname�socket�getfqdn�
gethostbyname�gethostname�gaierror)
r�host�portr;r5r8rrZfqdnr(rrrr�s*					
z
SMTP.__init__cCs|S)Nr)rrrr�	__enter__szSMTP.__enter__cGs_zMy4|jd�\}}|dkr6t||��Wntk
rKYnXWd|j�XdS)NZQUIT��)�docmdrrr:)rrr�messagerrr�__exit__s
	z
SMTP.__exit__cCs
||_dS)N)�
debuglevel)rrHrrr�set_debuglevelszSMTP.set_debuglevelcGsN|jdkr7ttjj�j�|dtj�nt|dtj�dS)N��file)rH�print�datetimeZnow�time�sys�stderr)rrrrr�_print_debug's(zSMTP._print_debugcCsG|jdkr+|jd||f|j�tj||f||j�S)Nrzconnect: to)rHrQr8r<�create_connection)rrArBr5rrr�_get_socket-szSMTP._get_socket�	localhostcCs>|r||_|r�|jd�|jd�kr�|jd�}|dkr�|d|�||dd�}}yt|�}Wntk
r�td��YnX|s�|j}|jdkr�|jd||f�|j	|||j
�|_d|_|j
�\}}|jdkr4|jdt|��||fS)N�:rrJznonnumeric portzconnect:)r8�find�rfind�int�
ValueError�OSError�default_portrHrQrSr5�sockrK�getreply�repr)rrArBr8�irrrrrr95s(	%%
		zSMTP.connectcCs�|jdkr%|jdt|��t|d�r�|jr�t|t�r^|j|j�}y|jj	|�Wq�t
k
r�|j�td��Yq�Xntd��dS)Nrzsend:r\zServer not connectedzplease run connect() first)
rHrQr^�hasattrr\�
isinstance�str�encoder7�sendallrZr:r)r�srrr�sendWs

z	SMTP.sendcCsC|dkrd|tf}nd||tf}|j|�dS)Nrz%s%sz%s %s%s)r,rf)r�cmdrrbrrr�putcmdiszSMTP.putcmdcCs�g}|jdkr*|jjd�|_xEy|jjtd�}WnEtk
r�}z%|j�tdt|���WYdd}~XnX|s�|j�td��|j	dkr�|j
dt|��t|�tkr�|j�t
dd��|j|d	d�jd
��|dd�}yt|�}Wntk
rVd}PYnX|dd	�dkr-Pq-Wd
j|�}|j	dkr�|j
d||f�||fS)N�rbrJz Connection unexpectedly closed: zConnection unexpectedly closedrzreply:i�zLine too long.�s 	
��-s
zreply: retcode (%s); Msg: %a���)rKr\�makefile�readline�_MAXLINErZr:rrbrHrQr^�lenr�appendr$rXrY�join)r�resp�line�erZerrcode�errmsgrrrr]qs>

#

 
z
SMTP.getreplycCs|j||�|j�S)N)rhr])rrgrrrrrE�sz
SMTP.docmdcCs>|jd|p|j�|j�\}}||_||fS)N�helo)rhr;r]�	helo_resp)r�namerrrrrrx�s	z	SMTP.heloc
Cs�i|_|j|j|p!|j�|j�\}}|dkrkt|�dkrk|j�td��||_|dkr�||fSd|_	|jj
d�jd�}|d=x�|D]�}tj
|�}|r|jjdd�d	|jd�d|jd<q�tj
d
|�}|r�|jd�j�}|j|jd�d�j�}	|dkr�|jj|d�d	|	|j|<q�|	|j|<q�W||fS)
NrJrzServer not connected�zlatin-1�
�authr� z((?P<feature>[A-Za-z0-9][A-Za-z0-9\-]*) ?�featurerm)r6rh�ehlo_msgr;r]rqr:r�	ehlo_resp�
does_esmtp�decode�split�
OLDSTYLE_AUTH�match�get�groupsr*�group�lower�string�endr$)
rrzrrrt�eachZ
auth_match�mr�paramsrrrr0�s2	
	
	
1"'z	SMTP.ehlocCs|j�|jkS)N)r�r6)r�optrrr�has_extn�sz
SMTP.has_extncCs|jd|�|j�dS)N�helprJ)rhr])rrrrrr��sz	SMTP.helpcCsd|_|jd�S)Nr1�rset)r7rE)rrrrr��s	z	SMTP.rsetcCs'y|j�Wntk
r"YnXdS)N)r�r)rrrr�_rset�s
z
SMTP._rsetcCs
|jd�S)N�noop)rE)rrrrr�sz	SMTP.noopcCs�d}|rh|jrhtdd�|D��rU|jd�rId|_ntd��ddj|�}|jdd	t|�|f�|j�S)
Nrcss!|]}|j�dkVqdS)�smtputf8N)r�)�.0�xrrr�	<genexpr>szSMTP.mail.<locals>.<genexpr>r�zutf-8z SMTPUTF8 not supported by serverr~�mailz	FROM:%s%s)	r��anyr�r7rrsrhrr])rr�options�
optionlistrrrr�s		 z	SMTP.mailcCsRd}|r(|jr(ddj|�}|jddt|�|f�|j�S)Nrr~�rcptzTO:%s%s)r�rsrhrr])rZrecipr�r�rrrr�s
 z	SMTP.rcptcCs|jd�|j�\}}|jdkrD|jd||f�|dkrbt||��n�t|t�r�t|�jd�}t	|�}|dd�t
kr�|t
}|dt
}|j|�|j�\}}|jdkr|jd||f�||fSdS)	Nr-rzdata:ibr1��.���)rhr]rHrQrrarbr/rcr.�bCRLFrf)rrr�repl�qrrrr-!s"



z	SMTP.datacCs |jdt|��|j�S)N�vrfy)rhr)r])r�addressrrr�verify>szSMTP.verifycCs |jdt|��|j�S)N�expn)rhr)r])rr�rrrr�Esz	SMTP.expncCs�|jdkr�|jdkr�d|j�dko?dkns�|j�\}}d|komdkns�t||��dS)N��ri+)ryr�r0rxr
)rrrtrrr�ehlo_or_helo_if_neededLs
&zSMTP.ehlo_or_helo_if_needed�initial_response_okTc	Cs�|j�}|r|�nd}|dk	rkt|jd�dd�}|jd|d|�\}}n|jd|�\}}|dkr�tj|�}t||�jd�dd�}|j|�\}}|d	kr�||fSt||��dS)
Nr1ZeolrZAUTHr~iN���)r�r�)�upper�
encode_base64rcrE�base64Zdecodebytesr)	rZ	mechanismZ
authobjectr�Zinitial_response�responserrt�	challengerrrr}]s#
z	SMTP.authcCs@|dkrdS|jdtj|jjd�|d�j�S)Nr~r1�md5)�user�hmacZHMAC�passwordrc�	hexdigest)rr�rrr�
auth_cram_md5�szSMTP.auth_cram_md5cCsd|j|jfS)Nz%s%s)r�r�)rr�rrr�
auth_plain�szSMTP.auth_plaincCs|dkr|jS|jSdS)N)r�r�)rr�rrr�
auth_login�szSMTP.auth_logincs+|j�|jd�s%td��|jdj��dddg}�fdd�|D�}|srtd��|||_|_x�|D]�}d	|j�j	d
d�}yA|j
|t||�d|�\}}	|dkr�||	fSWq�tk
r}
z|
}WYdd}
~
Xq�Xq�W|�dS)Nr}z,SMTP AUTH extension not supported by server.zCRAM-MD5ZPLAINZLOGINcs"g|]}|�kr|�qSrr)r�r})�advertised_authlistrr�
<listcomp>�s	zSMTP.login.<locals>.<listcomp>z(No suitable authentication method found.Zauth_�-�_r�r��)r�r�)
r�r�rr6r�rr�r�r��replacer}�getattrr)rr�r�r�Zpreferred_authsZauthlistZ
authmethodZmethod_namerrtrvZlast_exceptionr)r�r�login�s*
	
z
SMTP.logincCs+|j�|jd�s%td��|jd�\}}|dkrtsXtd��|dk	r||dk	r|td��|dk	r�|dk	r�td��|dkr�tjd|d	|�}|j	|j
d
|j�|_
d|_d|_
d|_i|_d|_nt||��||fS)N�starttlsz+STARTTLS extension not supported by server.ZSTARTTLSr2z&No SSL support included in this Pythonz4context and keyfile arguments are mutually exclusivez5context and certfile arguments are mutually exclusive�certfile�keyfile�server_hostnamer)r�r�rrE�	_have_ssl�RuntimeErrorrY�ssl�_create_stdlib_context�wrap_socketr\r4rKryr�r6r�r)rr�r��contextrtZreplyrrrr��s0
						z
SMTP.starttlscCs�|j�g}t|t�r4t|�jd�}|jr�|jd�rc|jdt|��x|D]}|j|�qjW|j	||�\}}	|dkr�|dkr�|j
�n
|j�t||	|��i}
t|t�r�|g}xp|D]h}|j
||�\}}	|dkrE|dkrE||	f|
|<|dkr�|j
�t|
��q�Wt|
�t|�kr�|j�t|
��|j|�\}}	|dkr�|dkr�|j
�n
|j�t||	��|
S)Nr1�sizezsize=%dr{i��)r�rarbr/rcr�r�rrrqr�r:r�rr�rr-r)r�	from_addr�to_addrsr�mail_options�rcpt_optionsZ
esmtp_opts�optionrrtZsenderrsr�rrr�sendmailsF@
	


	




z
SMTP.sendmailcCs|j�|jd�}|dkr.d}n't|�dkrId}ntd��|dkr�|d|kr||dn||d}|dkr�dd	�||d
||d||dfD�}d
d	�tjj|�D�}tj|�}	|	d=|	d=d}
y#dj|f|��j	d�Wn3t
k
rg|jd�s]td��d}
YnXt
j��x}|
r�tjj|d|jjdd��}|ddg7}ntjj|�}|j|	dd�|j�}
WdQRX|j|||
||�S)NzResent-DaterrJzResent-z0message has more than one 'Resent-' header blockZSender�FromcSs"g|]}|dk	r|�qS)Nr)r��frrrr��s	z%SMTP.send_message.<locals>.<listcomp>�ToZBccZCccSsg|]}|d�qS)rJr)r��arrrr��s	z
Resent-BccFr1r�z�One or more source or delivery addresses require internationalized email support, but the server does not advertise the required SMTPUTF8 capabilityT�policy�utf8ZSMTPUTF8z
BODY=8BITMIME�linesepz
)r�Zget_allrqrYr!r"Zgetaddresses�copyrsrc�UnicodeEncodeErrorr�r�io�BytesIO�	generatorZBytesGeneratorr�ZcloneZflatten�getvaluer�)rrr�r�r�r�ZresentZ
header_prefixZaddr_fieldsZmsg_copy�
internationalZbytesmsg�gZflatmsgrrr�send_messagexsH
		#
		zSMTP.send_messagecCsPz&|j}d|_|r%|j�Wd|j}d|_|rK|j�XdS)N)rKr:r\)rrKr\rrrr:�s				z
SMTP.closecCs?|jd�}d|_|_i|_d|_|j�|S)N�quitF)rEr�ryr6r�r:)r�resrrrr��s		
z	SMTP.quit)0rrrrHrKryr�r�r��	SMTP_PORTr[r<�_GLOBAL_DEFAULT_TIMEOUTrrCrGrIrQrSr9rfrhr]rErxr0r�r�r�r�r�r�r�r-r�r�r�r�r}r�r�r�r�r�r�r�r:r�rrrrr�s\	-
	"1
3'	B4gK
c
@sIeZdZeZdddddejdddd�Zdd�ZdS)�SMTP_SSLrrNc		Cs�|dk	r$|dk	r$td��|dk	rH|dk	rHtd��||_||_|dkr~tjd|d|�}||_tj||||||�dS)Nz4context and keyfile arguments are mutually exclusivez5context and certfile arguments are mutually exclusiver�r�)rYr�r�r�r�r�rr)	rrArBr;r�r�r5r8r�rrrr�s				zSMTP_SSL.__init__cCsb|jdkr%|jd||f�tj||f||j�}|jj|d|j�}|S)Nrzconnect:r�)rHrQr<rRr8r�r�r4)rrArBr5Z
new_socketrrrrSszSMTP_SSL._get_socket)	rrr�
SMTP_SSL_PORTr[r<r�rrSrrrrr��s	r�i�c@sCeZdZdZdedddd�Zddddd	�ZdS)
�LMTPZlhlorNcCs#tj|||d|d|�dS)Nr;r8)rr)rrArBr;r8rrrr sz
LMTP.__init__rTrcCs�|ddkr)tj|||d|�Sy8tjtjtj�|_d|_|jj|�WnStk
r�|jdkr�|j	d|�|jr�|jj
�d|_�YnX|j�\}}|jdkr�|j	d|�||fS)Nr�/r8z
connect fail:zconnect:)rr9r<�AF_UNIX�SOCK_STREAMr\rKrZrHrQr:r])rrArBr8rrrrrr9&s"	
	
	zLMTP.connect)rrrr��	LMTP_PORTrr9rrrrr�s	r��__main__cCs4tjj|d�tjj�tjj�j�S)Nz: )rO�stdout�write�flush�stdinror$)�promptrrrr�@s
r�r�r��,zEnter message, end with ^D:rzMessage length is %drTrJ)?r<r�r*Zemail.utilsr!Z
email.messageZemail.generatorr�r�r�rMrOZemail.base64mimerr��__all__r�r�r,r�rp�compile�Ir�rZrrrrrrrr	r
rrr)r
r.r/r��ImportErrorr�rr�rrr�r�rr�Zfromaddrr�ZtoaddrsrLrr�rorurqZserverrIr�r�rrrr�<module>,s�			


	
���!,
/



?>