Vci( 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>rrceZdZdS)rNrrrrrrKrrceZdZdS)rNrrrrrrRsrrceZdZ dZdS)rc4||_||_||f|_dSN) smtp_code smtp_errorargs)selfcodemsgs r__init__zSMTPResponseException.__init__cs3K rNrrrr(rrrrrZs(     rrceZdZ dZdS)rcD||_||_||_|||f|_dSr!)r"r#senderr$)r%r&r'r,s rr(zSMTPSenderRefused.__init__os) 3' rNr)rrrrrhs( (((((rrceZdZ dZdS)r c$||_|f|_dSr!) recipientsr$)r%r/s rr(zSMTPRecipientsRefused.__init__}s$M rNr)rrrr r us("""""rr ceZdZdS)r Nrrrrr r s11rr ceZdZdS)r Nrrrrr r s00rr ceZdZdS)r Nrrrrr r s,,rr ceZdZdS)r Nrrrrr r rrr c tj|\}}||fdkr.|dr|Sd|zSd|zS)Nr6)emailutils parseaddrstrip startswith addrstring displaynameaddrs rrrsr --j99KTh&#      ( ( - -   "" D=rc^tj|\}}||fdkr|S|S)Nr5)r8r9r:r=s r _addr_onlyrBs9 --j99KTh& Krc b tjddtjdt|S)Nz(?m)^\.z..(?:\r\n|\n|\r(?!\n))resubCRLFdatas rrrs3 6*d &d33 5 55rc.tjdd|S)Ns(?m)^\.s..)rFrG)bindatas r_quote_periodsrMs 6+ug . ..rc8tjdt|S)NrDrErIs r _fix_eolsrOs F*D$ 7 77rTFcFeZdZ 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)3rrNehloFr6c ||_||_i|_d|_||_d|_|rC|||\}}|dkr$|t||| ||_ dStj }d|vr ||_ dSd} tj tj } n#tj$rYnwxYwd| z|_ dS)Nasciir.z 127.0.0.1z[%s])_hosttimeoutesmtp_featurescommand_encodingsource_address_auth_challenge_countconnectcloser local_hostnamesocketgetfqdn gethostbyname gethostnamegaierror) r%hostportr^rWrZr&r'fqdnr@s rr(z SMTP.__init__s     ',%&"  2,,tT22KT3s{ 2 &tS111  4"0D    >##Dd{ 4&*####!/0B0D0DEEDDD&,tm###s%CCCc|Sr!rr%s r __enter__zSMTP.__enter__s rc |d\}}|dkrt||n#t$rYnwxYw|dS#|wxYw)NQUIT)docmdrrr])r%r$r&messages r__exit__z SMTP.__exit__s  JJv..MD's{ ;+D'::: ;%    D  JJLLLLLDJJLLLLs!.1A >A>AA-c ||_dSr!) debuglevel)r%rqs rset_debuglevelzSMTP.set_debuglevel"s %rc|jdkrJttjg|Rdt jidSt|dt jidS)Nfile)rqprintdatetimenowtimesysstderrr%r$s r _print_debugzSMTP._print_debug+sm ?Q  * (#''))..00 I4 I I Icj I I I I I 4 )cj ) ) ) ) )rc||std|jdkr|d||f|jt j||f||jS)N0Non-blocking socket (timeout=0) is not supportedrz connect: to) ValueErrorrqr}rZr_create_connection)r%rdrerWs r _get_socketzSMTP._get_socket1sv  Qw QOPP P ?Q  P   mdD\4;N O O O't g(,(;== =r localhostcT |r||_|s|d|dkr`|d}|dkrE|d|||dzd}} t|}n#t$rt dwxYw|s|j}tjd|||| |||j |_ d|_ | \}}|jdkr#|dt!|||fS)N:rrtznonnumeric portzsmtplib.connectconnect:)rZfindrfindintrOSError default_portrzauditrrWsockrugetreplyrqr}repr)r%rdrerZir&r's rr\z 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<<Bc |jdkr#|dt||jrt |t r||j}tj d|| |j |dS#t$r$| tdwxYwtd)Nrzsend:z smtplib.sendServer not connectedzplease run connect() first)rqr}rr isinstancestrencoderYrzrsendallrr]r)r%ss rsendz SMTP.send\s% ?Q  0   gtAww / / / 9 G!S!! 4HHT233 IndA . . . E !!!$$$$$ E E E ,-CDDD E))EFF Fs =B.Cc |dkr|}n|d|}d|vsd|vr<|dddd}td|||tdS)Nr6   z\nz\rz=command and arguments contain prohibited newline characters: )replacerrrH)r%cmdr$rs rputcmdz SMTP.putcmdos+ 2: AAA 19    $&&..tU;;ASPQSS  Q,,,rc 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)Nrbrtz Connection unexpectedly closed: zConnection unexpectedly closedrzreply:izLine too long.s - zreply: retcode (z); Msg: )rurmakefilereadline_MAXLINErr]rrrqr}rlenrappendr;rrjoin)r%resplineer&errcodeerrmsgs rrz 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=cX ||||Sr!rr)r%rr$s rrmz SMTP.docmds'; C}}rc |d|p|j|\}}||_||fS)Nhelo)rr^r helo_resp)r%namer&r's rrz SMTP.helosG  FD7D$7888mmoo sc{rc 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) NrrrTzlatin-1rauthr6rz((?P[A-Za-z0-9][A-Za-z0-9\-]*) ?feature)rXrehlo_msgr^rrr]r ehlo_resp does_esmtpdecodesplit OLDSTYLE_AUTHmatchgetgroupsrFgrouplowerstringendr;) r%rr&r'reach auth_matchmrparamss rrQz 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{rc: ||jvSr!)rrX)r%opts rhas_extnz SMTP.has_extnsEyy{{d111rcd |d||dS)Nhelprtrr|s rrz SMTP.helps. * FD!!!}}q!!rc< d|_|dS)NrSrset)rYrmrhs rrz SMTP.rsets4 'zz&!!!rcT |dS#t$rYdSwxYwr!)rrrhs r_rsetz SMTP._rsets?   IIKKKKK%    DD s  ''c. |dS)Nnoop)rmrhs rrz SMTP.noop s;zz&!!!rrcL d}|rd|jr]td|Dr,|drd|_nt ddd|z}|ddt|||S) Nr6c3FK|]}|dkVdS)smtputf8N)r).0xs r zSMTP.mail..s/::Q17799j(::::::rrzutf-8z SMTPUTF8 not supported by serverrmailzFROM:) ranyrrYrrrrr)r%r,options optionlists 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_okc |}|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||) NrSr6)eolAUTHrrtriNz4Server AUTH mechanism infinite loop. Last response: i) upper encode_base64rrmr[base64 decodebytes _MAXCHALLENGErrr ) r% mechanism authobjectrinitial_responseresponser&r challenges rrz SMTP.authhs *OO%% ,?IJJLLLT  +$%5%<% !9 = rc ||dstd|jd gd} fd|D}|st d||c|_|_|D]z}d| ddz} | |t||| \}} |d vr|| fcSb#t$r } | } Yd} ~ sd} ~ wwxYw| ) Nrz,SMTP AUTH extension not supported by server.)zCRAM-MD5PLAINLOGINcg|]}|v| Srr)rradvertised_authlists r zSMTP.login..s3444T224D444rz(No suitable authentication method found.auth_-_rr) rrrrXrrr r rrrgetattrr ) r%r r rpreferred_authsauthlist authmethod method_namer&rrlast_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:DDc\ ||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.STARTTLSrTz&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 insteadrcertfilekeyfileserver_hostnameF)rrrrm _have_ssl RuntimeErrorrwarningswarnDeprecationWarningssl_create_stdlib_context wrap_socketrrVrurrrXrr)r%r.r-contextrreplyr3s rr'z SMTP.starttlss ##%%%}}Z(( ?'=?? ? :.. u 3; 5 M"#KLLL .w . "-... .x . "-... Oh O 78JAOOO F4h=DFFF++DI<@J,HHDIDI "DN!DN"$D #DOO (e44 4e}rc> |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)NrSsizezsize=%dri)rrrrOrrrrrrr]rrrr rJr ) r% from_addrto_addrsr' mail_options rcpt_options esmtp_optsoptionr&rsenderrsrs 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++ +rc ||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-Dater6rtzResent-z0message has more than one 'Resent-' header blockSenderFromrcg|]}||Sr!r)rfs rrz%SMTP.send_message..s.--- -1---rToBccCccg|] }|d S)rtr)ras rrz%SMTP.send_message..sLLL!LLLrz Resent-BccFrSrzOne or more source or delivery addresses require internationalized email support, but the server does not advertise the required SMTPUTF8 capabilityT)utf8)policySMTPUTF8z BODY=8BITMIMEr)linesep)rget_allrrr8r9 getaddressescopyrrUnicodeEncodeErrorrrioBytesIO generatorBytesGeneratorrQcloneflattengetvaluerE)r%r'r>r?r@rAresent header_prefix addr_fieldsmsg_copy internationalbytesmsggflatmsgs 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(c |j}d|_|r||j}d|_|r|dSdS#|j}d|_|r|wwxYwr!)rur]r)r%rurs rr]z SMTP.closes6 9DDI  9DDI    9DDI   s $A'A6c |d}dx|_|_i|_d|_||S)NquitF)rmrrrXrr])r%ress rrjz SMTP.quitsE)jj  *..   rrrN)r6)rr!)NNN)rr)NNrr)1rrrrqrrurrrr SMTP_PORTrr__GLOBAL_DEFAULT_TIMEOUTr(rirorrr}rr\rrrrmrrQrrrrrrrrJrrrrrrrrr%r'rErgr]rjrrrrrs 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   rrcFeZdZ eZdddddejddfdZfdZxZ S)SMTP_SSLr6rNc 2||td||td|| ddl} | dtd||_||_|t j||}||_t ||||||dS)Nr)r*rr+rr,) rr3r4r5r.r-r6r7r9rr() r%rdrer^r.r-rWrZr9r3s rr(zSMTP_SSL.__init__s .w . "-... .x . "-... Oh O 78JAOOO"DL$DM F4h=DFFF"DL MM$dNG( * * * * *rc|jdkr|d||ft|||}|j||j}|S)Nrrr/)rqr}superrr9r8rV)r%rdrerW new_socket __class__s rrzSMTP_SSL._get_socketsr" <!!*tTl;;;,,T4AAJ11*BF*2NNJ r) rrr SMTP_SSL_PORTrr_rnr(r __classcell__rus@rrprpso % "4!D#;$($ * * * *.         rrpicFeZdZ dZdeddejffd Zdfd ZxZ S) LMTPlhlor6NcV t|||||dS)N)r^rZrW)rsr()r%rdrer^rZrWrus rr(z LMTP.__init__<sA( tN(6  I I I I Irrrc |ddkr$t|||S|j|jstd t jtjtj|_|jtjur|j |jd|_ |j|nW#t$rJ|j dkr| d||jr|jd|_wxYw|\}}|j dkr| d|||fS)Nr/)rZrz connect fail:r)rsr\rWrr_AF_UNIX SOCK_STREAMrrn settimeoutrurrqr}r]r)r%rdrerZr&r'rus rr\z 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'rl) rrrr LMTP_PORTr_rnr(r\rwrxs@rrzrz,s| 4HYt $f.LIIIIII rrz__main__ctj|dztjtjS)Nz: )rzstdoutwriteflushstdinrr;)prompts rrrasP $''' y!!##))+++rrHrK,zEnter message, end with ^D:r6rtzMessage length is %dr)@r_rXrF email.utilsr8 email.messageemail.generatorrr rVrwrzemail.base64mimerr__all__rmrvrHrrrcompileIrrrrrrrr r r r r rrBrrMrOr6r1 ImportErrorrrprrrzrrfromaddrrtoaddrsrvr'rrrrserverrrrErjrrrrsR   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