ϪfkdZddlZddlZddlZddlmZddlmZddlm Z ddl m Z ddl m Z mZmZddlmZdd lmZmZmZdd lmZmZdd lmZmZdd lmZe e j@jBGd dZ"GddZ#GddZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+e ejXGddejZej\Z/e eGddZ0e1d\Z2Z3Z4Z5iZ6e2e6e2<e2e6e3<e5e6e4<e2e6e5<Gdd ejZZ7dd!lm8Z8m9Z9m:Z:m;Z;mgd#Z?y)$zQ Post-office Protocol version 3. @author: Glyph Lefkowitz @author: Jp Calderone N)md5)Optional) implementer)cred)defer interfacestask)smtp)POP3ClientError POP3Error_POP3MessageDeleted) IMailboxPOP3IServerFactoryPOP3)basicpolicies)logceZdZdZdZdZy)APOPCredentialsz Credentials for use in APOP authentication. @ivar magic: See L{__init__} @ivar username: See L{__init__} @ivar digest: See L{__init__} c.||_||_||_y)a @type magic: L{bytes} @param magic: The challenge string used to encrypt the password. @type username: L{bytes} @param username: The username associated with these credentials. @type digest: L{bytes} @param digest: An encrypted version of the user's password. Should be generated as an MD5 hash of the challenge string concatenated with the plaintext password. N)magicusernamedigest)selfrrrs 3/usr/lib/python3/dist-packages/twisted/mail/pop3.py__init__zAPOPCredentials.__init__-s    cp|j|z}t|j}||jk(S)a4 Validate a plaintext password against the credentials. @type password: L{bytes} @param password: A plaintext password. @rtype: L{bool} @return: C{True} if the credentials represented by this object match the given password, C{False} if they do not. )rr hexdigestr)rpasswordseedmyDigests r checkPasswordzAPOPCredentials.checkPassword>s3zzH$t9&&(4;;&&rN)__name__ __module__ __qualname____doc__rr"rrrr#s" 'rrceZdZdZdZdZy)_HeadersPlusNLinesa A utility class to retrieve the header and some lines of the body of a mail message. @ivar _file: See L{__init__} @ivar _extraLines: See L{__init__} @type linecount: L{int} @ivar linecount: The number of full lines of the message body scanned. @type headers: L{bool} @ivar headers: An indication of which part of the message is being scanned. C{True} for the header and C{False} for the body. @type done: L{bool} @ivar done: A flag indicating when the desired part of the message has been scanned. @type buf: L{bytes} @ivar buf: The portion of the message body that has been scanned, up to C{n} lines. cX||_||_d|_d|_d|_d|_y)z @type file: file-like object @param file: A file containing a mail message. @type extraLines: L{int} @param extraLines: The number of lines of the message body to retrieve. rrN)_file _extraLines linecountheadersdonebuf)rfile extraLiness rrz_HeadersPlusNLines.__init__fs/ %  rc|jry|jj|}|s|S|jrN|j dd}}|dk(r|j dd}}|dk7r ||z }|d|}||d}d|_d |_nd}|j d kDru|j |zjd }|d|_|ddD]C}|j |jkDr d|_cS|d zz }|xj dz c_ES|S) a Scan bytes from the file. @type bytes: L{int} @param bytes: The number of bytes to read from the file. @rtype: L{bytes} @return: Each portion of the header as it is scanned. Then, full lines of the message body as they are scanned. When more than one line of the header and/or body has been scanned, the result is the concatenation of the lines. When the scan results in no full lines, the empty string is returned. rs s Nr+r ) r0r,readr/findr.r1splitr-)rbytesdatadfszvaldsplitlns rr9z_HeadersPlusNLines.readus 99zzu%K <<YY{+QBRx7+QBRxb3BiBCy!"  C >>A hho,,U3FbzDHSbk $>>D$4$44 !DIJrEz!!#  $ JKrN)r#r$r%r&rr9r'rrr)r)Ns. *rr)c,eZdZdZdZddZdZdZeZy)_IteratorBuffera An iterator which buffers the elements of a container and periodically passes them as input to a writer. @ivar write: See L{__init__}. @ivar memoryBufferSize: See L{__init__}. @type bufSize: L{int} @ivar bufSize: The number of bytes currently in the buffer. @type lines: L{list} of L{bytes} @ivar lines: The buffer, which is a list of strings. @type iterator: iterator which yields L{bytes} @ivar iterator: An iterator over a container of strings. rNcVg|_||_t||_|d}||_y)a @type write: callable that takes L{list} of L{bytes} @param write: A writer which is a callable that takes a list of strings. @type iterable: iterable which yields L{bytes} @param iterable: An iterable container of strings. @type memoryBufferSize: L{int} or L{None} @param memoryBufferSize: The number of bytes to buffer before flushing the buffer to the writer. Ni)lineswriteiteriteratormemoryBufferSize)rrGiterablerJs rrz_IteratorBuffer.__init__s1  X  #$  0rc|S)z Return an iterator. @rtype: iterator which yields L{bytes} @return: An iterator over strings. r'rs r__iter__z_IteratorBuffer.__iter__s  rc t|j}|}|jj||xjt |z c_|j|j kDr*|j|jg|_d|_yyy#t$r/|jr|j|j|`|`|`wxYw)a\ Get the next string from the container, buffer it, and possibly send the buffer to the writer. The contents of the buffer are written when it is full or when no further values are available from the container. @raise StopIteration: When no further values are available from the container. Nr) nextrIrFappendbufSizelenrJrG StopIteration)rvs r__next__z_IteratorBuffer.__next__s %T]]#A} !!!$ A& <<$"7"77JJtzz*!#DJ#$DL8 zz 4::& tz4:   s B8CN) r#r$r%r&rRrrNrVrPr'rrrDrDs$"G1(%8 DrrDcdt|jj|}|j|S)a} Direct the output of an iterator to the transport of a protocol and arrange for iteration to take place. @type proto: L{POP3} @param proto: A POP3 server protocol. @type gen: iterator which yields L{bytes} @param gen: An iterator over strings. @rtype: L{Deferred } @return: A deferred which fires when the iterator finishes. )rD transport writeSequenceschedule)protogencolls riterateLineGeneratorr_s) 5??88# >D >>$ rcft|tst|jd}d|zdzS)z Format an object as a positive response. @type response: stringifyable L{object} @param response: An object with a string representation. @rtype: L{bytes} @return: A positive POP3 response string. utf-8s+OK  ) isinstancer<strencode)responses rsuccessResponsergs2 h &x=''0 X  ''rc#bKd}d}|D]}|dz }||z }dtd||fzyw)a Format a list of message sizes into a STAT response. This generator function is intended to be used with L{Cooperator }. @type msgs: L{list} of L{int} @param msgs: A list of message sizes. @rtype: L{None} or L{bytes} @return: Yields none until a result is available, then a string that is suitable for use in a STAT response. The string consists of the number of messages and the total size of the messages in octets. rr+N%d %drg)msgsir<sizes rformatStatResponsernsN A E Q    (aZ/ 00s-/c#:Kd}|D]}|dz }d||fzyw)a_ Format a list of message sizes for use in a LIST response. @type msgs: L{list} of L{int} @param msgs: A list of message sizes. @rtype: L{bytes} @return: Yields a series of strings that are suitable for use as scan listings in a LIST response. Each string consists of a message number and its size in octets. rr+s%d %d Nr')rkrlrms rformatListLinesrp+s4 A' QaY&&'sc#rKtdt|fzt|Ed{dy7 w)ai Format a list of message sizes into a complete LIST response. This generator function is intended to be used with L{Cooperator }. @type msgs: L{list} of L{int} @param msgs: A list of message sizes. @rtype: L{bytes} @return: Yields a series of strings which make up a complete LIST response. s%dN. )rgrSrp)rks rformatListResponsers=s6 %3t9,. //t$$$ N%s )75 7c#Kt|D]F\}}| ||}t|tst|j d}d|dz|fzHyw)ar Format a list of message sizes for use in a UIDL response. @param msgs: See L{formatUIDListResponse} @param getUidl: See L{formatUIDListResponse} @rtype: L{bytes} @return: Yields a series of strings that are suitable for use as unique-id listings in a UIDL response. Each string consists of a message number and its unique id. Nras%d %b r+) enumeratercr<rdre)rkgetUidlrlmuids rformatUIDListLinesryOs\$.1 =!*Cc5)#hoog.!a%- - .s AAAc#ZKtdt||Ed{dy7 w)a. Format a list of message sizes into a complete UIDL response. This generator function is intended to be used with L{Cooperator }. @type msgs: L{list} of L{int} @param msgs: A list of message sizes. @type getUidl: one-argument callable returning bytes @param getUidl: A callable which takes a message index number and returns the UID of the corresponding message in the mailbox. @rtype: L{bytes} @return: Yields a series of strings which make up a complete UIDL response. Nrr)rgry)rkrvs rformatUIDListResponser|cs-" " !$000 N1s +) +cjeZdZUdZdZeeed<dZdZ gdZ dZ dZ dZ dZdZdZeej&ZdZdZd Zd Zd/d Zd0d Zd ZdZdZdZdZdZ d1dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+d1dZ,d1dZ-d Z.d!Z/d"Z0d#Z1d$Z2d%Z3d&Z4d'Z5d(Z6d)Z7d*Z8d+Z9d,Z:d-Z;d.Z} @ivar schedule: A callable that arranges for an iterator to be cooperatively iterated over along with all other iterators which have been passed to it such that runtime is divided between all of them. It returns a deferred which fires when the iterator finishes. @type magic: L{bytes} or L{None} @ivar magic: An APOP challenge. If not set, an APOP challenge string will be generated when a connection is made. @type _userIs: L{bytes} or L{None} @ivar _userIs: The username sent with the USER command. @type _onLogout: no-argument callable or L{None} @ivar _onLogout: The function to be executed when the connection is lost. @type mbox: L{IMailbox} provider @ivar mbox: The mailbox for the authenticated user. @type state: L{bytes} @ivar state: The state which indicates what type of messages are expected from the client. Valid states are 'COMMAND' and 'AUTH' @type blocked: L{None} or L{list} of 2-L{tuple} of (E{1}) L{bytes} (E{2}) L{tuple} of L{bytes} @ivar blocked: A list of blocked commands. While a response to a command is being generated by the server, other commands are blocked. When no command is outstanding, C{blocked} is set to none. Otherwise, it contains a list of information about blocked commands. Each list entry consists of the command and the arguments to the command. @type _highest: L{int} @ivar _highest: The 1-based index of the highest message retrieved. @type _auth: L{IUsernameHashedPassword } provider @ivar _auth: Authorization credentials. Nr)sCAPAUSERPASSAPOPsAUTHsRPOPQUITi,COMMANDrcT|j|j|_|j|j|j|jt |j ddr:tjdt|jjzyy)zS Send a greeting to the client after the connection has been made. NnoisyTzNew connection from ) r generateMagicrg setTimeouttimeOutgetattrfactoryrmsgrdrYgetPeerrMs rconnectionMadezPOP3.connectionMadesy :: ++-DJ TZZ(  % 4<<$ / GG*S1G1G1I-JJ K 0rcl|j|jd|_|jdy)z Clean up when the connection has been lost. @type reason: L{Failure} @param reason: The reason the connection was terminated. N) _onLogoutr)rreasons rconnectionLostzPOP3.connectionLosts+ >> % NN !DN rc*tjS)z} Generate an APOP challenge. @rtype: L{bytes} @return: An RFC 822 message id format string. )r messageidrMs rrzPOP3.generateMagics~~rcL|jjt|y)z Send a response indicating success. @type message: stringifyable L{object} @param message: An object whose string representation should be included in the response. N)rYrGrgrmessages rrgzPOP3.successResponses _W56rct|tst|jd}|j d|zy)z Send a response indicating failure. @type message: stringifyable L{object} @param message: An object whose string representation should be included in the response. ras-ERR N)rcr<rdresendLiners r failResponsezPOP3.failResponses3'5)'l))'2G h()rcb|jt|d|jz|y)z Pass a received line to a state machine function. @type line: L{bytes} @param line: A received line. state_N) resetTimeoutrstaterlines r lineReceivedzPOP3.lineReceiveds* ,h+,T2rc|j}d|_|rB|j6|jd\}}|j|g||r |j6|j|jj|yy)z Process as many blocked commands as possible. If there are no more blocked commands, set up for the next command to be sent immediately. @type _: L{object} @param _: Ignored. Nr)blockedpopprocessCommandextend)r_commandscmdargss r_unblockz POP3._unblock sw<< 4<</ QIC D   +d +4<</ << # LL   ) $rc r |j|jdS#tttt f$r}}t j|jdjd|jjjddj|jgYd}~yd}~wwxYw)z Handle received lines for the COMMAND state in which commands from the client are expected. @type line: L{bytes} @param line: A received command.  s: sbad protocol or serverrarN)rr; ValueErrorAttributeErrorr TypeErrorrerrrjoin __class__r#rer)rres r state_COMMANDzPOP3.state_COMMANDs &4&& 4(89 9NIyA  GGI    1 ,,33G<(   s B6A3B11B6c2|j|jj||fy|j}||jv}|js|st d|zt |d|jdzd}|r||St d|z)aq Dispatch a command from the client for handling. @type command: L{bytes} @param command: A POP3 command. @type args: L{tuple} of L{bytes} @param args: Arguments to the command. @raise POP3Error: When the command is invalid or the command requires prior authentication which hasn't been performed. Ns!not authenticated yet: cannot do do_rasUnknown protocol command: )rrQupper AUTH_CMDSmboxr rdecode)rcommandrauthCmdfs rrzPOP3.processCommand4s << # LL  $ 0 --/T^^+yy@7JK K D%'.."994 @ d8O5?@@rcgd}tj|jr |jj}|r*t |t st |jd}|jd|z |jj}|r*t |t st |jd}|d}|jjr@|jr/t |jj jd}n|dz}|jd|z |jj#}|r*t |t st |jd}|jj%r@|jr/t |jj&jd}n|dz}|jd|z |jj(}|jdd j+|j-z|S|S#t$rYt$rtjYwxYw#t$rY >?xc'     '      '     "   !    sbAH:AI):AJ/K: I&I&%I&) J5JJ K#KK K1K10K1c|jd|jD]}|j||jdy)zW Handle a CAPA command. Respond with the server capabilities. sI can do the following:.N)rgrr)rcaps rdo_CAPAz POP3.do_CAPAsC 78((* C MM#   drc~t|jdds|jdy|]|jd|jjD]!}|j |j #|j dy|jjj|jj }|jr|s|jdy||_ |jj}|j dtj|zd|_y) a Handle an AUTH command. If the AUTH extension is not supported, send an error response. If an authentication mechanism was not specified in the command, send a list of all supported authentication methods. Otherwise, send an authentication challenge to the client and transition to the AUTH state. @type args: L{bytes} or L{None} @param args: The name of an authentication mechanism. rNsAUTH extension unsupportedz!Supported authentication methods:rsUnsupported SASL selecteds+ AUTH)rrrrgrrrgetstripportal_auth getChallengebase64 b64encoder)rraauthchals rdo_AUTHz POP3.do_AUTHst||]D9   ; <  <  !D E\\-- ) aggi( ) MM$  ||''++DJJL,>,>,@A{{$   : ; V zz&&( ef..t445 rcBd|_ tj|jdd}t |dk7r|j dy|d|j _|d|j _|jj|j dt}|j|j|d|j|j|j|j y#t"j$$r|j dYywxYw)a Handle received lines for the AUTH state in which an authentication challenge response from the client is expected. Transition back to the COMMAND state. Check the credentials and complete the authorization process with the L{_cbMailbox} callback function on success or the L{_ebMailbox} and L{_ebUnexpected} errback functions on failure. @type line: L{bytes} @param line: The challenge response. rNr+r7sInvalid AUTH responsersInvalid BASE64 encoding)rr b64decoder;rSrrrrfrloginIMailbox addCallback _cbMailbox addErrback _ebMailbox _ebUnexpectedbinasciiError)rrpartsds r state_AUTHzPOP3.state_AUTHs  -$$T*00q9E5zQ!!":;"'(DJJ "'(DJJ  !!$**dH=A MM$//58 4 LL ) LL++ ,~~ :   8 9 :s%C77$DDctj|j||}|j|j|j |fj |jy)a Handle an APOP command. Perform APOP authentication and complete the authorization process with the L{_cbMailbox} callback function on success or the L{_ebMailbox} and L{_ebUnexpected} errback functions on failure. @type user: L{bytes} @param user: A username. @type digest: L{bytes} @param digest: An MD5 digest string.  callbackArgsN)r maybeDeferredauthenticateUserAPOP addCallbacksrrrr)ruserrrs rdo_APOPz POP3.do_APOPsP    9 94 H  OOT__D7  *T'' (rc |\}}}|tur'|jdtjdy||_||_|j dt|jddrtjd|zyy)a Complete successful authentication. Save the mailbox and logout function for the authenticated user and send a successful response to the client. @type result: C{tuple} @param result: The first item of the tuple is a C{zope.interface.Interface} which is the interface supported by the avatar. The second item of the tuple is a L{IMailbox} provider which is the mailbox for the authenticated user. The third item of the tuple is a no-argument callable which is a function to be invoked when the session is terminated. @type user: L{bytes} @param user: The user being authenticated. Authentication failedz9_cbMailbox() called with an interface other than IMailboxNzAuthentication succeededrTsAuthenticated login for ) rrrrrrrgrrr)rresultr interfaceavatarlogouts rrzPOP3._cbMailboxs{&'-#FF H $   6 7 GGO P   78 4<<$ / GG/$6 7 0rc|jtjjtjj}t |tjjr|j dt|zn5t |tjjr|j dt|jddr:tjdt|jjzyy)a Handle an expected authentication failure. Send an appropriate error response for a L{LoginDenied} or L{LoginFailed} authentication failure. @type failure: L{Failure} @param failure: The authentication error. zAccess denied: rrTzDenied login attempt from N)traprerror LoginDenied LoginFailed issubclassrrdrrrrrYrrfailures rrzPOP3._ebMailboxs,,tzz55tzz7M7MN gtzz55 6   /#g,> ? !7!7 8   6 7 4<<$ / GG03t~~7M7M7O3PP Q 0rcr|jd|jztj|y)z Handle an unexpected authentication failure. Send an error response for an unexpected authentication failure. @type failure: L{Failure} @param failure: The authentication error. zServer error: N)rgetErrorMessagerrrs rrzPOP3._ebUnexpected)s- *W-D-D-FFG rc4||_|jdy)z Handle a USER command. Save the username and send a successful response prompting the client for the password. @type user: L{bytes} @param user: A username. sUSER accepted, send PASSN)_userIsrgrrs rdo_USERz POP3.do_USER5s  89rcV|j|jdy|j}d|_dj|f|z}tj|j ||}|j |j|j|fj|jy)a2 Handle a PASS command. If a USER command was previously received, authenticate the user and complete the authorization process with the L{_cbMailbox} callback function on success or the L{_ebMailbox} and L{_ebUnexpected} errback functions on failure. If a USER command was not previously received, send an error response. @type password: L{bytes} @param password: A password. @type words: L{tuple} of L{bytes} @param words: Other parts of the password split by spaces. NsUSER required before PASSrr) rrrrrauthenticateUserPASSrrrrr)rrwordsrrs rdo_PASSz POP3.do_PASSBs <<    : ; || 99h[501    9 94 J  OOT__D7  *T'' (rcjjdg_|jj|jfd|S)a Stop timeouts and block further command processing while a long operation completes. @type d: L{Deferred } @param d: A deferred which triggers at the completion of a long operation. @rtype: L{Deferred } @return: A deferred which triggers after command processing resumes and timeouts restart after the completion of a long operation. Nc&jSrW)r)ignrrs rz%POP3._longOperation..ns$//'":r)rrrrr)rrrs` @r_longOperationzPOP3._longOperation]sC,,   dmm$ :;rc`|jt|jj|S)aG Direct the output of an iterator to the transport and arrange for iteration to take place. @type gen: iterable which yields L{bytes} @param gen: An iterator over strings. @rtype: L{Deferred } @return: A deferred which fires when the iterator finishes. )r[rDrYrZ)rr]s r _coiteratezPOP3._coiterateqs$}}_T^^-I-I3OPPrctjjj}fd}fd}j |j ||S)z Handle a STAT command. @rtype: L{Deferred } @return: A deferred which triggers after the response to the STAT command has been issued. c8jt|SrW)rrnrkrs r cbMessagesz POP3.do_STAT..cbMessagess??#5d#;< .ebMessagess2   c113 4 GG1 2 GGCLr)rrr listMessagesrr)rrrrs` rdo_STATz POP3.do_STAT~sG    6 6 7 =  ""1>>*j#IJJrc<Ttjjj}fd}fd}j |j ||S t dkr t tjjjdz }fd}fd}|j ||j |S#t$rAttstjdjdzYywxYw) a Handle a LIST command. @type i: L{bytes} or L{None} @param i: A 1-based message index. @rtype: L{Deferred } @return: A deferred which triggers after the response to the LIST command has been issued. Nc8jt|SrW)rrsrs rrz POP3.do_LIST..cbMessagess'9$'?@@rcj|jtjdtj|y)NUnexpected do_LIST failure:rrs rrz POP3.do_LIST..ebMessages2!!#"5"5"7856 rr+c2jd|fzy)Nrirj)rrlrs r cbMessagezPOP3.do_LIST..cbMessages((QH)<=rc|jtt}|e|turtjdt }|r*t |tst|jd}jd|zyj|jtjdtj|y)N}twisted.mail.pop3.IMailbox.listMessages may not raise IndexError for out-of-bounds message numbers: raise ValueError instead.raInvalid message-number: r")checkr IndexErrorwarningswarnPendingDeprecationWarningrcr<rdrerrrrr)rerrcls invalidNumrlrs r ebMessagezPOP3.do_LIST..ebMessages YYz:>F)!Z/%MM!M!:  &' %jU.K),Z)?)?)HJ))*E *RS))#*=*=*?@ => rrar() rrrrrrintrrcr<rdrer)rrlrrrr%r0s`` rdo_LISTz POP3.do_LISTs 9##DII$:$:;A A  &&q~~j*'MN N% .Fq5$,&'' (>(>AF>%,y)4**1--C C!!U+A g.A!!"="AB CsCADDc|Ttjjj}fd}fd}j |j ||S t |}|dkr t jj|dz }t|tst|jd}j|y#t$r.tj dt"j%dYyt$rj%dYywxYw#t$rj%dYywxYw)a Handle a UIDL command. @type i: L{bytes} or L{None} @param i: A 1-based message index. @rtype: L{Deferred } @return: A deferred which triggers after the response to the UIDL command has been issued. Ncbjt|jjSrW)rr|rrvrs rrz POP3.do_UIDL..cbMessagess()$ 0A0ABrcj|jtjdtj|y)NzUnexpected do_UIDL failure:rrs rrz POP3.do_UIDL..ebMessagesr#rr+razxtwisted.mail.pop3.IMailbox.getUidl may not raise IndexError for out-of-bounds message numbers: raise ValueError instead.Bad message number argument)rrrrrrr1rrvrcr<rdrergr*r+r,r-r)rrlrrrrs` rdo_UIDLz POP3.do_UIDLs* 9##DII$:$:;A    &&q~~j*'MN N .Fq5$,& .))++AE2C&c51!#hoog6((-"EMM42  %%&CD!E%%&CDE A!!"?@ As*D$5C4D!D! D!$EEc` t|dz dkr t tj j j}fd}fd}|j||j||S#t$r)jdtjdcYSwxYw)a Retrieve the size and contents of a message. @type i: L{bytes} @param i: A 1-based message index. @rtype: L{Deferred } which successfully fires with 2-L{tuple} of (E{1}) L{int}, (E{2}) file-like object @return: A deferred which successfully fires with the size of the message and a file containing the contents of the message. r+rr6NcstjtStjjj }|j fd|S)Nc |fSrWr')fObjrms rrz=POP3._getMessageFile..cbMessageSize..s 4,r)rfailr rr getMessager)rm fileDeferredrrs` r cbMessageSizez+POP3._getMessageFile..cbMessageSizesJzz"5"788 ..tyy/C/CSIL  $ $%> ? rcP|jttt}|turj dy|ttfvr4|turt j dtj dytjdtj|y)Nzmessage deletedr'r6z#Unexpected _getMessageFile failure:) r)r rr*rr+r,r-rrr)rr.rs rebMessageSomethingz0POP3._getMessageFile..ebMessageSomething!sYY2J KF,,!!"34J 33Z'MM42  !!"?@=> r) r1rrrsucceedrrrrr)rrl sizeDeferredr?rArs` @r_getMessageFilezPOP3._getMessageFiles 'a&1*CQw l" **499+A+A3G   &   / 23E '   ; <==& & 'sA;;/B-,B-c|j}fd}j|j|S)a Send the contents of a message. @type i: L{bytes} @param i: A 1-based message index. @type fpWrapper: callable that takes a file-like object and returns a file-like object @param fpWrapper: @type successResponse: callable that takes L{int} and returns L{bytes} @param successResponse: @rtype: L{Deferred} @return: A deferred which triggers after the message has been sent. cl|yt jt _|\}}|} j |t j }|j | j j} fd} fd}|j||j||S)Nc<|dk7rd}nd}j|y)Nr8 .rr)lastsentrrs rcbFileTransferzGPOP3._sendMessageContent..cbMessageFile..cbFileTransferYs!u$#DD d#rcjjtjdtj|y)Nz(Unexpected error in _sendMessageContent:)rYloseConnectionrrrrs rebFileTransferzGPOP3._sendMessageContent..cbMessageFile..ebFileTransfer`s+--/BC r) max_highestr1rgr FileSenderbeginFileTransferrYtransformChunkrr) inforespfpsrrKrN fpWrapperrlrrgs r cbMessageFilez/POP3._sendMessageContent..cbMessageFileLs| s1v6DMHD"2B  !6 7  "A##B8K8KLA $  MM. ) LL (Hr)rDrr)rrlrXrgrrYs```` r_sendMessageContentzPOP3._sendMessageContent8s6$   # :""1==#?@@rc tdkrt |j|fddS#t$r|jdYywxYw)a[ Handle a TOP command. @type i: L{bytes} @param i: A 1-based message index. @type size: L{bytes} @param size: The number of lines of the message to retrieve. @rtype: L{Deferred} @return: A deferred which triggers after the response to the TOP command has been issued. rct|SrW)r))rVrms rrzPOP3.do_TOP..s-b$7rcy)NzTop of message followsr'rms rrzPOP3.do_TOP..srzBad line count argumentN)r1rrZr)rrlrms `rdo_TOPz POP3.do_TOPksa t9Dax   ++75  9   7 8 9s1A Ac,|j|ddS)z Handle a RETR command. @type i: L{bytes} @param i: A 1-based message index. @rtype: L{Deferred} @return: A deferred which triggers after the response to the RETR command has been issued. c|SrWr')rVs rrzPOP3.do_RETR..sbrcd|fzS)Nz%dr'r^s rrzPOP3.do_RETR..s ttg~r)rZrrls rdo_RETRz POP3.do_RETRs''=:UVVrcF|jddjddS)a Transform a chunk of a message to POP3 message format. Make sure each line ends with C{'\r\n'} and byte-stuff the termination character (C{'.'}) by adding an extra one when one appears at the beginning of a line. @type chunk: L{bytes} @param chunk: A string to transform. @rtype: L{bytes} @return: The transformed string. r8rbrHs ..)replace)rchunks rrSzPOP3.transformChunks"}}UG,44XyIIrc:|dk7rd}nd}|j|y)z Send the termination sequence. @type lastsent: L{bytes} @param lastsent: The last character of the file. r8rHrNrI)rrJrs rfinishedFileTransferzPOP3.finishedFileTransfers" u DD drcvt|dz }|jj||jy)z Handle a DELE command. Mark a message for deletion and issue a successful response. @type i: L{int} @param i: A 1-based message index. r+N)r1r deleteMessagergrcs rdo_DELEz POP3.do_DELEs/ FQJ " rc$|jy)z] Handle a NOOP command. Do nothing but issue a successful response. NrjrMs rdo_NOOPz POP3.do_NOOPs rc |jjd|_|jy#t$r't j |jYywxYw)zj Handle a RSET command. Unmark any messages that have been flagged for deletion. rN)rundeleteMessagesrPrgrrrrrMs rdo_RSETz POP3.do_RSETsR  # II & & ( DM  "  GGI     s4-A$#A$c:|j|jy)zr Handle a LAST command. Respond with the 1-based index of the highest retrieved message. N)rgrPrMs rdo_LASTz POP3.do_LASTs T]]+rc&|jdy)z Handle an RPOP command. RPOP is not supported. Send an error response. @type user: L{bytes} @param user: A username. zpermission denied, suckerN)rrs rdo_RPOPz POP3.do_RPOPs 56rc|jr|jj|j|jj y)z Handle a QUIT command. Remove any messages marked for deletion, issue a successful response, and drop the connection. N)rsyncrgrYrMrMs rdo_QUITz POP3.do_QUITs5 99 IINN   %%'rc|j6|jjt|j||dtSt j j)ax Perform APOP authentication. @type user: L{bytes} @param user: The name of the user attempting to log in. @type digest: L{bytes} @param digest: The challenge response. @rtype: L{Deferred } which successfully results in 3-L{tuple} of (E{1}) L{IMailbox }, (E{2}) L{IMailbox } provider, (E{3}) no-argument callable @return: A deferred which fires when authentication is complete. If successful, it returns an L{IMailbox } interface, a mailbox, and a function to be invoked with the session is terminated. If authentication fails, the deferred fails with an L{UnathorizedLogin } error. @raise cred.error.UnauthorizedLogin: When authentication fails. N)rrrrrrrUnauthorizedLoginrrrs rrzPOP3.authenticateUserAPOPsN* ;; ";;$$ D&94 jj**,,rc|j?|jjtjj ||dt Stj j)a Perform authentication for a username/password login. @type user: L{bytes} @param user: The name of the user attempting to log in. @type password: L{bytes} @param password: The password to authenticate with. @rtype: L{Deferred } which successfully results in 3-L{tuple} of (E{1}) L{IMailbox }, (E{2}) L{IMailbox } provider, (E{3}) no-argument callable @return: A deferred which fires when authentication is complete. If successful, it returns a L{pop3.IMailbox} interface, a mailbox, and a function to be invoked with the session is terminated. If authentication fails, the deferred fails with an L{UnathorizedLogin } error. @raise cred.error.UnauthorizedLogin: When authentication fails. N)rrr credentialsUsernamePasswordrrrz)rrrs rr zPOP3.authenticateUserPASSsT* ;; ";;$$  11$A4 jj**,,rctrW)rrMs r stopProducingzPOP3.stopProducing*s !##rr{)rrW)=r#r$r%r&rrr<__annotations__rrrrrrrrr staticmethodr coiterater[rPrrrrgrrrrrrrrrrrrrr r rrrr2r7rDrZr_rdrSrirlrnrqrsrurxrr rr'rrr~r~ys25n"E8E?!GIOI FG DG EGDNN+HH L  7 *3*$,A4JX !F-:)&8>R$  :)6( QK(=.~1.f2h1Af6 WJ   #, 7 (-6-6$rr~c6eZdZdZd dZdZdZdZdZdZ y) Mailboxz% A base class for mailboxes. NcgS)a Retrieve the size of a message, or, if none is specified, the size of each message in the mailbox. @type i: L{int} or L{None} @param i: The 0-based index of the message. @rtype: L{int}, sequence of L{int}, or L{Deferred } @return: The number of octets in the specified message, or, if an index is not specified, a sequence of the number of octets for all messages in the mailbox or a deferred which fires with one of those. Any value which corresponds to a deleted message is set to 0. @raise ValueError or IndexError: When the index does not correspond to a message in the mailbox. The use of ValueError is preferred. r'rcs rrzMailbox.listMessages5s $ rct)a Retrieve a file containing the contents of a message. @type i: L{int} @param i: The 0-based index of a message. @rtype: file-like object @return: A file containing the message. @raise ValueError or IndexError: When the index does not correspond to a message in the mailbox. The use of ValueError is preferred. rrcs rr=zMailbox.getMessageIs rct)a Get a unique identifier for a message. @type i: L{int} @param i: The 0-based index of a message. @rtype: L{bytes} @return: A string of printable characters uniquely identifying the message for all time. @raise ValueError or IndexError: When the index does not correspond to a message in the mailbox. The use of ValueError is preferred. rrcs rrvzMailbox.getUidlX rct)a Mark a message for deletion. This must not change the number of messages in this mailbox. Further requests for the size of the deleted message should return 0. Further requests for the message itself may raise an exception. @type i: L{int} @param i: The 0-based index of a message. @raise ValueError or IndexError: When the index does not correspond to a message in the mailbox. The use of ValueError is preferred. rrcs rrkzMailbox.deleteMessagehrrcy)z Undelete all messages marked for deletion. Any message which can be undeleted should be returned to its original position in the message sequence and retain its original UID. Nr'rMs rrpzMailbox.undeleteMessagesxs rcy)zJ Discard the contents of any message marked for deletion. Nr'rMs rrwz Mailbox.syncs rrW) r#r$r%r&rr=rvrkrprwr'rrrr/s%(     rrr5ceZdZdZeZdZddlZejdZ dZ ddZ dZ d Z d Zd Zd Zd ZdZdZdZddZddZdZdZeZdZy) POP3Clienta| A POP3 client protocol. @type mode: L{int} @ivar mode: The type of response expected from the server. Choices include none (0), a one line response (1), the first line of a multi-line response (2), and subsequent lines of a multi-line response (3). @type command: L{bytes} @ivar command: The command most recently sent to the server. @type welcomeRe: L{Pattern } @ivar welcomeRe: A regular expression which matches the APOP challenge in the server greeting. @type welcomeCode: L{bytes} @ivar welcomeCode: The APOP challenge passed in the server greeting. sWELCOMErNs<(.*)>c>ddl}|jdtdy)z, Issue deprecation warning. rNzdtwisted.mail.pop3.POP3Client is deprecated, please use twisted.mail.pop3.AdvancedPOP3Client instead.) stacklevel)r+r,DeprecationWarning)rr+s rrzPOP3Client.__init__s"      rc|Bt|tst|jd}|j |dz|zn|j |||_t |_y)z Send a POP3 command to which a short response is expected. @type command: L{bytes} @param command: A POP3 command. @type params: stringifyable L{object} or L{None} @param params: Command arguments. Nrar)rcr<rdrerrSHORTmoderrparamss r sendShortzPOP3Client.sendShortsW  fe,V++G4 MM'D.61 2 MM' "  rc|rBt|tst|jd}|j |dz|zn|j |||_t |_y)z Send a POP3 command to which a long response is expected. @type command: L{bytes} @param command: A POP3 command. @type params: stringifyable L{object} @param params: Command arguments. rarN)rcr<rdrerr FIRST_LONGrrs rsendLongzPOP3Client.sendLongsT fe,V++G4 MM'D.61 2 MM' "  rc,|dddk(r t|_yy)z Handle responses from the server for which no other handler exists. @type line: L{bytes} @param line: A received line. Ns-ERR)NONErrs rhandle_defaultzPOP3Client.handle_defaults 9 DI rc|jdd\}}|dk7r|jjy|jj |}|r|j d|_yy)z Handle a server response which is expected to be a server greeting. @type line: L{bytes} @param line: A received line. rr+s+OKN)r;rYrM welcomeRematchgroup welcomeCode)rrcoder=rws rhandle_WELCOMEzPOP3Client.handle_WELCOMEs[ZZa( d 6> NN ) ) +$$T*A#$771: rc t|d|jdz|}|||yy#t$rtjYywxYw)a Dispatch a response from the server for handling. Command X is dispatched to handle_X() if it exists. If not, it is dispatched to the default handler. @type command: L{bytes} @param command: The command. @type default: callable that takes L{bytes} or L{None} @param default: The default handler. @type args: L{tuple} or L{None} @param args: Arguments to the handler function. handle_raN)rrrrr)rrdefaultrmethods r _dispatchzPOP3Client._dispatchsM" T9w~~g/F#FPF! "  GGI s&*A  A c|jtk(s|jtk(r@t|j|_|j |j |j |y|jtk(rk|dk(r8t|j|_|j |j dzdy|dddk(r|dd}|j |j dzd|yy)a Dispatch a received line for processing. The choice of function to handle the received line is based on the type of response expected to the command sent to the server and how much of that response has been received. An expected one line response to command X is handled by handle_X(). The first line of a multi-line response to command X is also handled by handle_X(). Subsequent lines of the multi-line response are handled by handle_X_continue() except for the last line which is handled by handle_X_end(). @type line: L{bytes} @param line: A received line. rs_endNr+s _continue)rrrNEXTrrrLONGrs rrzPOP3Client.lineReceiveds" 99 j!8TYYDI NN4<<)<)rsi&44PP. T   5 56''''7''TQQhMM` $ (10'$$.(, Z ! !"r$5 ! !8#8#8r$#r$j XU U U p!&aeZ  T U Z T x ''x vF r