Plan 9 from Bell Labs’s /usr/web/sources/contrib/jas/root/sys/lib/python2.7/site-packages/mercurial/mail.pyc

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


��c@s�ddlmZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddl
ZddlZejjjZd�Zeejjjd<dejfd��YZejejd�rdejfd	��YZnddd
�Zd�Zd�Zd
�Zdd�Zdd�Zd�Zded�Z d�Z!d�Z"d�Z#ded�Z$dd�Z%ded�Z&ded�Z'ded�Z(dS(i�(t_NcOsd|d<t|||�dS(s�
    Python 2.7 introduces a backwards incompatible change
    (Python issue1974, r70772) in email.Generator.Generator code:
    pre-2.7 code passed "continuation_ws='	'" to the Header
    constructor, and 2.7 removed this parameter.

    Default argument is continuation_ws=' ', which means that the
    behaviour is different in <2.7 and 2.7

    We consider the 2.7 behaviour to be preferable, but need
    to have an unified behaviour for versions 2.4 to 2.7
    t tcontinuation_wsN(t_oldheaderinit(tselftargstkw((s2/sys/lib/python2.7/site-packages/mercurial/mail.pyt_unifiedheaderinits
t__init__tSTARTTLScBs&eZdZd�Zddd�ZRS(s�Derived class to verify the peer certificate for STARTTLS.

    This class allows to pass any keyword arguments to SSL socket creation.
    cKs tjj||�||_dS(N(tsmtplibtSMTPRt
_sslkwargs(Rt	sslkwargstkwargs((s2/sys/lib/python2.7/site-packages/mercurial/mail.pyR&scCs�|jd�s'd}tj|��n|jd�\}}|dkr�tj|j|||j�|_tj	|jd�s�|jj
|j_ntj|j�|_
d|_d|_i|_d|_n||fS(Ntstarttlss*STARTTLS extension not supported by serverR	i�treadi(thas_extnR
t
SMTPExceptiontdocmdtsslutiltssl_wrap_sockettsockRtutiltsafehasattrtrecvRtSSLFakeFiletfiletNonet	helo_respt	ehlo_resptesmtp_featurest
does_esmtp(Rtkeyfiletcertfiletmsgtresptreply((s2/sys/lib/python2.7/site-packages/mercurial/mail.pyR*s			N(t__name__t
__module__t__doc__RRR(((s2/sys/lib/python2.7/site-packages/mercurial/mail.pyR	!s	t_get_sockettSMTPScBs&eZdZddd�Zd�ZRS(s�Derived class to verify the peer certificate for SMTPS.

        This class allows to pass any keyword arguments to SSL socket creation.
        cKs>||_||_tjj||�tj|_||_dS(N(R!R"R
RRt
SMTP_SSL_PORTtdefault_portR(RR
R!R"R((s2/sys/lib/python2.7/site-packages/mercurial/mail.pyRBs
		cCsz|jdkr+tjdI||fIJntj||f|�}tj||j|j|j	�}t
j|�|_|S(Nisconnect:(
t
debugleveltsyststderrtsockettcreate_connectionRRR!R"RR
RR(Rthosttportttimeoutt
new_socket((s2/sys/lib/python2.7/site-packages/mercurial/mail.pyR)Is	N(R&R'R(RRR)(((s2/sys/lib/python2.7/site-packages/mercurial/mail.pyR*=scKstjtd���dS(Ns"SMTPS requires Python 2.6 or later(RtAbortR(R
R!R"R((s2/sys/lib/python2.7/site-packages/mercurial/mail.pyR*Sscs1|jdd�}|jddd�}|dkp?tj|�}|dk}|sZ|r�tjtd�r�tjtd���n|jdd	�}|s�tjtd
���n|jddd�}|dkr
tj|�tk	r
tjtd�|��q
n|s|r1|r1tj	||�}ni}|re|j
td��t|d|��n-|r�t|d|��nt
jd|��|r�d}nd}tj|jdd|��}	|j
td�||	f��jd	|d|	�|r2|j
td���j��j��j�n|s>|r||r||j
td��tj||��j|dk�n|jdd�}
|jdd�}|
r�|r�|j�}n|
r|r|j
td�|
�y�j|
|�Wqt
jk
r}tj|��qXn�fd�}
|
S(s;build an smtp connection and return a function to send mailtsmtptlocal_hostnamettlstnoneRtsmtpstssls/can't use TLS: Python SSL support not installedR2s+smtp.host not configured - cannot send mailt
verifycerttstricttlooses)invalid smtp.verifycert configuration: %ss(using smtps)
i�iR3s$sending mail: smtp host %s, port %s
s(using starttls)
s(verifying remote certificate)
tusernametpasswords&(authenticating to mail server as %s)
cs�y�j|||�SWn|tjk
rq}g|jj�D]}|d^q<}tjddj|���n%tjk
r�}tj|��nXdS(Nis
(	tsendmailR
tSMTPRecipientsRefusedt
recipientstvaluesRR6tjoinR(tsenderRDR#tinsttr(ts(s2/sys/lib/python2.7/site-packages/mercurial/mail.pytsend�s&(R>R?(tconfigRt	parseboolRR0R6RtFalseRR
tnoteR*R	R
RtgetporttconnecttehloRt	validatorRtgetpasstloginR(tuiR8R9RR;tmailhostR=R
tdefaultporttmailportR@RARHRK((RJs2/sys/lib/python2.7/site-packages/mercurial/mail.pyt_smtpVsf	


%
	cCs�|jdd�}d|tj|�djttj|��f}|jtd�|�tj|d�}|j|�|j	�}|r�tj
dtjj
|jd
d�d	�tj|�d	f��nd
S(ssend mail using sendmail.temailtmethods%s -f %s %sRssending mail: %s
tws%s %siiN(RLRR[RFtmapRORtpopentwritetcloseR6tostpathtbasenametsplitRtexplainexit(RVRGRDR#tprogramtcmdlinetfptret((s2/sys/lib/python2.7/site-packages/mercurial/mail.pyt	_sendmail�s
	cCsft|d�}tjdtj��}|jd||f�|j|�|jd�|j�dS(swrite mails to mboxsab+s%a %b %d %H:%M:%S %YsFrom %s %s
s

N(topenttimetstrftimet	localtimeR`Ra(tmboxRGRDR#Ritdate((s2/sys/lib/python2.7/site-packages/mercurial/mail.pyt_mbox�s

csX�r&t�d�j��fd�S�jddd�dkrKt��S�fd�S(snmake a mail connection. return a function to send mail.
    call as sendmail(sender, list-of-recipients, msg).twbcst�|||�S(N(Rr(RJRItm(Rp(s2/sys/lib/python2.7/site-packages/mercurial/mail.pyt<lambda>�sR[R\R7cst�|||�S(N(Rk(RJRIRt(RV(s2/sys/lib/python2.7/site-packages/mercurial/mail.pyRu�s(RlRaRLRZ(RVRp((RpRVs2/sys/lib/python2.7/site-packages/mercurial/mail.pyRQ�s

cCs"t|d|�}||||�S(NRp(RQ(RVRGRDR#RpRK((s2/sys/lib/python2.7/site-packages/mercurial/mail.pyRB�scCs}|jddd�}|dkrN|jdd�sytjtd���qyn+tj|�sytjtd�|��ndS(s=determine if we have enough config data to try sending email.R[R\R7R2s>smtp specified as email transport, but no smtp host configureds0%r specified as email transport, but not in PATHN(RLRR6Rtfindexe(RVR\((s2/sys/lib/python2.7/site-packages/mercurial/mail.pytvalidateconfig�stplaincCsod}|s_y|jd�Wq_tk
r[y|jd�d}Wq\tk
rWq\Xq_Xnt|||�S(s�Return MIME message suitable for a patch.
    Charset will be detected as utf-8 or (possibly fake) us-ascii.
    Transfer encodings will be used if necessary.sus-asciisutf-8(tdecodetUnicodeDecodeErrort
mimetextqp(RJtsubtypetdisplaytcs((s2/sys/lib/python2.7/site-packages/mercurial/mail.pyt
mimetextpatch�s



cCs~d}x?|j�D]1}t|�dkrtj|�}d}PqqWtjj|||�}|rz|d=||d<n|S(s[Return MIME message.
    Quoted-printable transfer encoding will be used if necessary.
    i�squoted-printablesContent-Transfer-EncodingN(Rt
splitlinestlentquopritencodestringR[tMIMEText(tbodyR|tcharsettenctlineR#((s2/sys/lib/python2.7/site-packages/mercurial/mail.pyR{�s
cCs�g|jdd�D]}|j�^q}tjj�tjj�dg}x*|D]"}||krS|j|�qSqSWg|D]}|jd�s�|^q�S(s;Obtains charsets to send mail parts not containing patches.R[tcharsetssutf-8tascii(t
configlisttlowertencodingtfallbackencodingtappendtendswith(RVR~R�t	fallbacks((s2/sys/lib/python2.7/site-packages/mercurial/mail.pyt	_charsets�s+
cCs�y|jd�Wn�tk
r�|p0t|�}x�tjtjfD]�}y|j|�}Wntk
ruqFnXx`|D]X}y|j|�|fSWq}tk
r�q}tk
r�|jt	d�|�q}Xq}WqFWnX|dfS(sReturns (converted) string, charset tuple.
    Finds out best charset by cycling through sendcharsets in descending
    order. Tries both encoding and fallbackencoding for input. Only as
    last resort send as is in fake ascii.
    Caveat: Do not use for mail parts containing patches!R�s!ignoring invalid sendcharset: %s
sus-ascii(
RyRzR�R�R�tencodetUnicodeEncodeErrortLookupErrortwarnR(RVRJR�tsendcharsetsticstutocs((s2/sys/lib/python2.7/site-packages/mercurial/mail.pyt_encode�s"




'cCs;|s7t|||�\}}ttjj||��S|S(s4Returns RFC-2047 compliant header from given string.(R�tstrR[tHeader(RVRJR�R}R~((s2/sys/lib/python2.7/site-packages/mercurial/mail.pyt
headencodescCs�t|||�}yS|jd�\}}|jd�}|jtj�jd�}d||f}Wnztk
r�tjtd�|��nQt	k
r�y|jd�}Wq�tk
r�tjtd�|��q�nXt
jj||f�S(Nt@R�tidnas%s@%ssinvalid email address: %ssinvalid local address: %s(
R�ReR�RyR�RzRR6Rt
ValueErrorR[tUtilst
formataddr(RVtnametaddrR�tacctdom((s2/sys/lib/python2.7/site-packages/mercurial/mail.pyt_addressencodes


!cCsB|s
|r|pdStjj|�\}}t||||�S(s-Turns address into RFC-2047 compliant header.t(R[R�t	parseaddrR�(RVtaddressR�R}R�R�((s2/sys/lib/python2.7/site-packages/mercurial/mail.pyt
addressencode,s

cCs�|r/g|D]}|j�r
|j�^q
Sg}xKtjj|�D]7\}}|s`|rH|jt||||��qHqHW|S(s�Turns a list of addresses into a list of RFC-2047 compliant headers.
    A single element of input list may contain multiple addresses, but output
    always has one address per item(tstripR[R�tgetaddressesR�R�(RVtaddrsR�R}tatresultR�R�((s2/sys/lib/python2.7/site-packages/mercurial/mail.pytaddrlistencode3s)#cCs7d}|s't|||�\}}nt|d|�S(sgcreates mime text object, encodes it if needed, and sets
    charset and transfer-encoding accordingly.sus-asciiRx(R�R{(RVRJR�R}R~((s2/sys/lib/python2.7/site-packages/mercurial/mail.pyt
mimeencode@s()ti18nRRR�RRbR
R0R�RmR.temail.HeaderR[temail.MIMETexttemail.UtilsR�RRRt__dict__RR	RR*RRZRkRrRQRBRwRNRR{R�R�R�R�R�R�R�(((s2/sys/lib/python2.7/site-packages/mercurial/mail.pyt<module>s2$H$		C		
			
	

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].