Vcics( ddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m ZgdZdZdZdZdZdZd Zejd ejZGd d eZGd deZGddeZGddeZGddeZGddeZGddeZ GddeZ!GddeZ"GddeZ#dZ$d Z%d!Z&d"Z'd#Z( ddl)Z)d$Z*n #e+$rd%Z*YnwxYwGd&d'Z,e*r#Gd(d)e,Z-e.d)d*Z/Gd+d,e,Z0e1d-krd.Z2e2d/Z3e2d04d1Z5e6d2d3Z7 e j89Z:e:sne7e:zZ7"e6d5e;e7ze,d6Ze3e5e7e>rrcr)rNrrrrrrKrrcr)rNrrrrrrRsrrceZdZ dZdS)rcs4||_||_||f|_dSN) smtp_code smtp_errorargs)selfcodemsg r__init__zSMTPResponseException.__init__cs3K rNrrrr"rrrrrZs(     rrcr)rcsD||_||_||_|||f|_dSr)rrsenderr)rrr r$ rr"zSMTPSenderRefused.__init__os) 3' rNr#rrrrrhs( (((((rrcr)rcs$||_|f|_dSr) recipientsr)rr& rr"zSMTPRecipientsRefused.__init__}s$M rNr#rrrrrus("""""rrcr)rNrrrrrrs11rrcr)r Nrrrrr r s00rr cr)r Nrrrrr r s,,rr cr)r Nrrrrr r rrr cs tj|\}}||fdkr.|dr|Sd|zSd|zS)Nr)z)emailutils parseaddrstripZ startswithZ addrstringZ displaynameaddrr!rr r sr --j99KTh&#      ( ( - -   "" D=rcs^tj|\}}||fdkr|S|S)Nr()r*r+r,r.r!r _addr_onlyr0s9 --j99KTh& Krc sb tjddtjdt|S)Nz(?m)^\.z..(?:\r\n|\n|\r(?!\n))resubCRLFdata rr r s3 6*d &d33 5 55rcs.tjdd|S)Ns(?m)^\.s..)r3r4)Zbindatar8r_quote_periodsr9s 6+ug . ..rcs8tjdt|S)Nr1r2r6r8r _fix_eolsr:s F*D$ 7 77rTFcsFeZdZ dZdZdZdZdZdZdZ e Z ddde j dfdZdZdZd Zd Zd Zd,d ZdZd-dZdZd-dZd-dZd-dZdZd-dZdZdZdZd.dZ d.dZ!dZ"dZ#e#Z$dZ%dZ&d d!d"Z'd/d#Z(d/d$Z)d/d%Z*d d!d&Z+d0d'Z, d1d(Z- d2d)Z.d*Z/d+Z0dS)3rrNehloFr)cs ||_||_i|_d|_||_d|_|rC|||\}}|dkr$|t||| ||_ dStj }d|vr ||_ dSd} tj tj } n#tj$rYnwxYwd| z|_ dS)Nasciirz.z 127.0.0.1z[%s])_hosttimeoutesmtp_featurescommand_encodingsource_address_auth_challenge_countconnectcloser local_hostnamesocketZgetfqdnZ gethostbynameZ gethostnameZgaierror) rhostportrFr?rBrr Zfqdnr/ rr"z SMTP.__init__s     ',%&"  2,,tT22KT3s{ 2 &tS111  4"0D    >##Dd{ 4&*####!/0B0D0DEEDDD&,tm###s%CCCcs|Srrrr8r __enter__zSMTP.__enter__s rcs |d\}}|dkrt||n#t$rYnwxYw|dS#|wxYw)NZQUITi)docmdrrrE)rrrZmessager%r__exit__z SMTP.__exit__s  JJv..MD's{ ;+D'::: ;%    D  JJLLLLLDJJLLLLs!.1A >A>AA-cs ||_dSr) debuglevel)rrOr'rset_debuglevelzSMTP.set_debuglevel"s %rcs|jdkrJttjg|Rdt jidSt|dt jidS)Nfile)rOprintdatetimeZnowZtimesysZstderrrrr'r _print_debugzSMTP._print_debug+sm ?Q  * (#''))..00 I4 I I Icj I I I I I 4 )cj ) ) ) ) )rcs||std|jdkr|d||f|jt j||f||jS)N0Non-blocking socket (timeout=0) is not supportedrz connect: to) ValueErrorrOrWrBrGZcreate_connection)rrHrIr?r%r _get_socketzSMTP._get_socket1sv  Qw QOPP P ?Q  P   mdD\4;N O O O't g(,(;== =r localhostcsT |r||_|s|d|dkr`|d}|dkrE|d|||dzd}} t|}n#t$rt dwxYw|s|j}tjd|||| |||j |_ d|_ | \}}|jdkr#|dt!|||fS)Nz:rrQznonnumeric portzsmtplib.connectconnect:)rBZfindZrfindintrYOSError default_portrUauditrZr?sockrRgetreplyrOrWrepr)rrHrIrBZirr  rrDz SMTP.connect;sD   1"0D  534::c??: 5 3AAv 5!"1"XtAEFF|d5t99DD!555!"34445 %$D #T4666$$T4>>  mmoo s ?Q  5   j$s)) 4 4 4c{s ,A<<Bcs |jdkr#|dt||jrt |t r||j}tj d|| |j |dS#t$r$| tdwxYwtd)Nrzsend:z smtplib.sendServer not connectedzplease run connect() first)rOrWrcra isinstancestrencoderArUr`Zsendallr^rEr)rsr'rsendz SMTP.send\s% ?Q  0   gtAww / / / 9 G!S!! 4HHT233 IndA . . . E !!!$$$$$ E E E ,-CDDD E))EFF Fs =B.Ccs |dkr|}n|d|}d|vsd|vr<|dddd}td|||tdS)Nr) z  z\nz\rz=command and arguments contain prohibited newline characters: )replacerYrjr5)rcmdrrir%rputcmdz SMTP.putcmdos+ 2: AAA 19    $&&..tU;;ASPQSS  Q,,,rcs g}|j|jd|_ |jtdz}nE#t $r8}|tdt|zd}~wwxYw|s#|td|j dkr#| dt|t|tkr$|tdd||d dd |dd } t!|}n#t"$rd }YnwxYw|d d d krnfd|}|j dkr| d|d|||fS)NZrbrQz Connection unexpectedly closed: zConnection unexpectedly closedrzreply:izLine too long.is is-s zreply: retcode (z); Msg: )rRraZmakefilereadline_MAXLINEr^rErrgrOrWrclenrappendr-r]rYjoin)rresplineerZerrcodeZerrmsgrdrrbz SMTP.getreply|s  9 1 **400DI  7y))(Q,77 7 7 7 ,-O/21vv.6777 7 O ,-MNNN" 8!!(DJJ7774yy8# C +C1ABBB KKQRRz22 3 3 38D d))    AaCyD  5 8D!! ?Q  R    P Q Q Qs)"A B3B  BE.. E=<E=csX ||||Srrorb)rrnrr!rrMz SMTP.docmds'; C}}rcs |d|p|j|\}}||_||fS)Nhelo)rorFrb helo_resp)rnamerr r%rrzz SMTP.helosG  FD7D$7888mmoo sc{rcs i|_||j|p|j|\}}|dkr6t |dkr#|td||_|dkr||fSd|_ |j d d}|d=|D]}t |}|rC|jdd d z|ddz|jd<bt!j d |}|r|d }|j|d d} |dkr+|j|d d z| z|j|<| |j|<||fS) NrprreTzlatin-1rlauthr)rkz((?P[A-Za-z0-9][A-Za-z0-9\-]*) ?feature)r@roehlo_msgrFrbrsrEr ehlo_resp does_esmtpZdecodesplit OLDSTYLE_AUTHZmatchZgetZgroupsr3ZgrouplowerZstringZendr-) rr|rr rveachZ auth_matchZmrZparamsrJrr;z SMTP.ehlos ! DM4#>4+>???mmoo s 2: A#c((a- A JJLLL()?@@ @ 3; #; ~$$Y//55d;; G : :D',,T22J .2.A.E.Efb.Q.Q/ * 1 1! 4 4Q 7/8#F+ DdKKA :''),,2244!%% "2"2"3"34::<<f$:373F3J3J7TV3W3W!4"$*4+D'004:D'0c{rcs: ||jvSr)rr@)rZoptr'rhas_extnz SMTP.has_extnsEyy{{d111rcsd |d||dS)NhelprQryrVr'rrz SMTP.helps. * FD!!!}}q!!rcs< d|_|dS)Nr<rset)rArMrKr8rrz SMTP.rsets4 'zz&!!!rcsT |dS#t$rYdSwxYwr)rrrKr8r_rsetz SMTP._rsets?   IIKKKKK%    DD s  ''cs. |dS)Nnoop)rMrKr8rrz SMTP.noop s;zz&!!!rrcsL d}|rd|jr]td|Dr,|drd|_nt ddd|z}|ddt|||S) Nr)c3sFK|]}|dkVdS)smtputf8N)r).0Zxr'rz zSMTP.mail..s/::Q17799j(::::::rrzutf-8z SMTPUTF8 not supported by serverrkmailzFROM:) rZanyrrArruror rb)rr$options optionlistr%rrz SMTP.mails   1t 1::'::::: <==,,<,3D))/:<<<sxx000J FF9V+<+<+ 4dn 4499;;q> 4 4 4 4S 4 4 4 4#yy{{ tt4444s4444'd333  4 4 4 4 4 444rTinitial_response_okcs |}|r |nd}|Kt|dd}|d|dz|z\}}d|_n |d|\}}d|_|dkr|xjdz c_t j|}t||dd}||\}}|jtkr!td t||fz|dk|d vr||fSt||) Nr<r))ZeolZAUTHrkrQriNz4Server AUTH mechanism infinite loop. Last response: ii) Zupper encode_base64rhrMrCbase64Z decodebytes _MAXCHALLENGErrcr ) rZ mechanismZ authobjectrZinitial_responseZresponserrv challenges rr~z SMTP.authhs *OO%% ,?IJJLLLT  +$%5%<% !9 = rcs ||dstd|jd gd} fd|D}|st d||c|_|_|D]z}d| ddz} | |t||| \}} |d vr|| fcSb#t$r } | } Yd} ~ sd} ~ wwxYw| ) Nr~z,SMTP AUTH extension not supported by server.)zCRAM-MD5ZPLAINZLOGINcsg|]}|v| Srr)rr~advertised_authlists r zSMTP.login..s3444T224D444rz(No suitable authentication method found.Zauth_z-Z_rr) rrrr@rrrrrrmr~Zgetattrr ) rrrrZpreferred_authsZauthlistZ authmethodZ method_namerrvrxZlast_exceptionrs @rloginz SMTP.logins 6 ##%%%}}V$$ @'>@@ @#1&9??AA9884444_444 L JKK K $(  4=" # #J!J$4$4$6$6$>$>sC$H$HHK ##yyk : :(; ) = = t :%( $<'''(* # # #!" #s<0C00 D:DDcs\ ||dstd|d\}}|dkrtst d||t d||t d|| ddl}|d td |tj || }| |j |j |_ d|_d|_d|_i|_d |_nt)||||fS)Nstarttlsz+STARTTLS extension not supported by server.ZSTARTTLSr=z&No SSL support included in this Python4context and keyfile arguments are mutually exclusive5context and certfile arguments are mutually exclusiverAkeyfile and certfile are deprecated, use a custom context insteadrcertfilekeyfileZserver_hostnameF)rrrrM _have_sslZ RuntimeErrorrYwarningswarnDeprecationWarningssl_create_stdlib_context wrap_socketrar>rRr{rr@rr)rrrcontextrvZreplyrrdrrz SMTP.starttlss ##%%%}}Z(( ?'=?? ? :.. u 3; 5 M"#KLLL .w . "-... .x . "-... Oh O 78JAOOO F4h=DFFF++DI<@J,HHDIDI "DN!DN"$D #DOO (e44 4e}rcs> |g}t|tr"t|d}|jrT|dr%|dt|z|D]}||| ||\}} |dkr@|dkr| n| t|| |i} t|tr|g}|D]W} | | |\}} |dkr |dkr|| f| | <|dkr#| t| Xt| t|kr#| t| ||\}} |dkr?|dkr| n| t!|| | S)Nr<Zsizezsize=%dr}ii)rrfrgr:rhrrrtrsrrErrrrr7r) r from_addrto_addrsr mail_options rcpt_optionsZ esmtp_optsZoptionrrvZsenderrsrs rsendmailz SMTP.sendmail(s2= | ##%%% c3   1C..''00C ? *}}V$$ 8!!)c#hh"6777& * *!!&))))yyJ77 t 3; ;s{   #D$ :: : h $ $ " zH 6 6D99T<88LT4  .$#+ ."&s{ 6 +H555 6 x==CMM ) 2 JJLLL'11 1yy~~ t 3; ,s{   d++ +rcs ||d}|d}n%t|dkrd}ntd|I|dz|vr ||dzn ||dz}tj|gdd}|Sd ||d z||d z||d zfD}d tj|D}tj|} | d =| d=d} d|g| dn6#t$r)| dstdd} YnwxYwtj5} | rDtj| |jd} g|ddR}ntj| } | | d| } dddn #1swxYwY|||| ||S)Nz Resent-Dater)rQzResent-z0message has more than one 'Resent-' header blockZSenderFromrcsg|]}||Srr)rZfr'rr%SMTP.send_message..s.--- -1---rToZBccZCccsg|] }|d S)rQr)rZar'rrrsLLL!LLLrz Resent-BccFr<rzOne or more source or delivery addresses require internationalized email support, but the server does not advertise the required SMTPUTF8 capabilityT)Zutf8)policyZSMTPUTF8z BODY=8BITMIMEr)Zlinesep)rZget_allrsrYr*r+Z getaddressescopyrurhZUnicodeEncodeErrorrrioZBytesIOZ generatorZBytesGeneratorrZcloneZflattenZgetvaluer)rr rrrrZresentZ header_prefixZ addr_fieldsZmsg_copyZ internationalZbytesmsgZgZflatmsgs r send_messagezSMTP.send_messages : ##%%%]++  QMM [[A  Q%MMOPP P  D -x7C?<]X566 #MF$: ;  00)==a@CI  M--s=4+?'@'*=5+@'A'*=4+?'@'B---KMLek&>&>{&K&KLLLH9S>> UO \ "  ! GGY** + + 2 27 ; ; ; ;! ! ! !==,, L+KLLL!MMM  !Z\\ *X =O22SZ%5%54%5%@%@3BBKKzK?KK O228<< IIhI / / /''))G * * * * * * * * * * * * * * *}}Y'<)++ +s%+D>>0E10E1BH$$H(+H(cs |j}d|_|r||j}d|_|r|dSdS#|j}d|_|r|wwxYwr)rRrEra)rrRrar!rrEz SMTP.closes6 9DDI  9DDI    9DDI   s $A'A6cs |d}dx|_|_i|_d|_||S)NquitF)rMrr{r@rrE)rZresr'rrz SMTP.quitsE)jj  *..   rr[rN)r))rr)NNN)rr)NNrr)1rrrrOrarRr{rrr SMTP_PORTr_rG_GLOBAL_DEFAULT_TIMEOUTr"rLrNrPrWrZrDrjrorbrMrzr;rrrrrrrr7rrrrr~rrrrrrrrErrrrrrs 8J D DIHIJLQt7 $.4.4.4.4`%%%*** ===BGGG&     ///b 1111f222"""" """   """*: D444"BF.2.2.2.2.2`IIII7777 !!!!<@@@@@@D6666p?A ffffP:>35K+K+K+K+Z   rrcsFeZdZ eZdddddejddfdZfdZxZ S)SMTP_SSLr)rNc s2||td||td|| ddl} | dtd||_||_|t j||}||_t ||||||dS)Nrrrrrr) rYrrrrrrrrrr") rrHrIrFrrr?rBrrrJrr"zSMTP_SSL.__init__s .w . "-... .x . "-... Oh O 78JAOOO"DL$DM F4h=DFFF"DL MM$dNG( * * * * *rcs|jdkr|d||ft|||}|j||j}|S)Nrr\r)rOrWsuperrZrrr>)rrHrIr?Z new_socket __class__s rrZzSMTP_SSL._get_socketsr" <!!*tTl;;;,,T4AAJ11*BF*2NNJ r) rrr SMTP_SSL_PORTr_rGrr"rZ __classcell__r@rrrso % "4!D#;$($ * * * *.         rricsFeZdZ dZdeddejffd Zdfd ZxZ S) LMTPZlhlor)NcsV t|||||dS)N)rFrBr?)rr")rrHrIrFrBr?r rr"z LMTP.__init__<sA( tN(6  I I I I Irr[rcs |ddkr$t|||S|j|jstd t jtjtj|_|jtjur|j |jd|_ |j|nW#t$rJ|j dkr| d||jr|jd|_wxYw|\}}|j dkr| d|||fS)Nrz/)rBrXz connect fail:r\)rrDr?rYrGZAF_UNIXZ SOCK_STREAMrarZ settimeoutrRr^rOrWrErb)rrHrIrBrr rrrrDz LMTP.connectBsfK 7c> N77??4n?MM M < QDL QOPP P  fnf6HIIDI|6#AA 3 $$T\222DI I  d # # # #   " 9!!/4888y " !!!DI   mmoo s ?Q  /   j# . . .c{sBCAD'r) rrrr LMTP_PORTrGrr"rDrrrrrr,s| 4HYt $f.LIIIIII rrZ__main__cstj|dztjtjS)Nz: )rUZstdoutZwriteZflushstdinrqr-)promptr8rrrasP $''' y!!##))+++rrrz,zEnter message, end with ^D:r)rQzMessage length is %dr[)@rGrr3Z email.utilsr*Z email.messageZemail.generatorrrrrTrUZemail.base64mimerrZ__all__rrr5rrrrZcompileZIrr^rrrrrrrr r r r r0r r9r:rrZ ImportErrorrrrtrrrrZfromaddrrZtoaddrsrSr rrqrwrsZserverrPrrrrrrsR   999999 - - -       <.. ?????G???M]      M     ( ( ( ( (- ( ( ( " " " " "M " " "22222)22211111,111-----)---3   555///888JJJIIIII t t t t t t t t l 1-----4---^ NN:  /////4///h z,,, vf~~HfTll  %%G E '((( Cy!!##  Dj   E 33s88 +,,, T+  F ! OOHgs+++ KKMMMMM)s6C==DD