
    ho                       S r SSKJr  SSKrSSKrSSKrSSKrSSKJr  SSK	J
r
JrJr  SSKJrJr  SSKJrJrJr  SSKJrJr  SS	KJr  SS
KJrJrJr  SSKJrJr  SSK J!r!  SSK"J#r#J$r$J%r%  SSK&J'r'  SSK(J)r)  SSK*J+r+  SSK,J-r-  SSK.J/r/J0r0  Sr1 " S S5      r2\2" \5      Rf                  r4S%S jr5 " S S\#Rl                  5      r7\" \#Rp                  5       " S S5      5       r9\" \Rt                  5       " S S5      5       r; " S S\$Rx                  5      r=\" \$R|                  5       " S S 5      5       r?\" \R                  5       " S! S"\95      5       rA\" \R                  5       " S# S$5      5       rCg)&z 
Maildir-style mailbox support.
    )annotationsN)md5)IOCallableoverload)	Interfaceimplementer)checkerscredentialsportal)IUsernameHashedPasswordIUsernamePassword)UnauthorizedLogin)defer
interfacesreactor)Deferredsucceed)	IProducer)mailpop3smtp)	AliasBase)MailServicedirdbm)basic)failurelogzFrom: Twisted.mail Internals
Subject: An Error Occurred

  An internal server error has occurred.  Please contact the
  server administrator.
c                      \ rS rSrSrSr\R                  " 5       r\	R                  " 5       R                  SS5      R                  SS5      rS rSS	 jrS
rg)_MaildirNameGenerator*   a'  
A utility class to generate a unique maildir name.

@type n: L{int}
@ivar n: A counter used to generate unique integers.

@type p: L{int}
@ivar p: The ID of the current process.

@type s: L{bytes}
@ivar s: A representation of the hostname.

@ivar _clock: See C{clock} parameter of L{__init__}.
r   /z\057:z\072c                    Xl         g)z
@type clock: L{IReactorTime <interfaces.IReactorTime>} provider
@param clock: A reactor which will be used to learn the current time.
N)_clock)selfclocks     [/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/mail/maildir.py__init___MaildirNameGenerator.__init__>   s	    
     c                F   U R                   S-   U l         U R                  R                  5       n[        [	        U5      5      nS[	        U[	        U5      -
  S-  5      4-  n[
        R                  " U SU SU R                   SU R                    SU R                   3	5      $ )aC  
Generate a string which is intended to be unique across all calls to
this function (across all processes, reboots, etc).

Strings returned by earlier calls to this method will compare less
than strings returned by later calls as long as the clock provided
doesn't go backwards.

@rtype: L{bytes}
@return: A unique string.
   z%07dg    cAz.MPQ.)	nr&   secondsstrintosfsencodeps)r'   tr3   microsecondss       r)   generate_MaildirNameGenerator.generateE   s     !KK!c!f+a#a&jD%8!9 ;;{{gYbaxq$&&RSSr,   )r&   r2   N)returnbytes)__name__
__module____qualname____firstlineno____doc__r2   r6   getpidr8   socketgethostnamereplacer9   r*   r<   __static_attributes__ r,   r)   r!   r!   *   sL     	
A
		A$$S'2::3HATr,   r!   c                B   [        U [        5      (       a  U nO[        R                  " U 5      n[        R                  R                  U5      (       d  [        R                  " US5        S H7  n[        R                  " [        R                  R                  X5      S5        M9     S H9  n[        R                  " [        R                  R                  USU5      S5        M;     [        [        R                  R                  USS5      S5      R                  5         gg)zo
Create a maildir user directory if it doesn't already exist.

@param dir: The path name for a user directory.
i  )   new   cur   tmp   .Trash)rL   rM   rN   rO   s   maildirfolderwN)

isinstancer?   r6   r7   pathisdirmkdirjoinopenclose)dirbdirsubdirs      r)   initializeMaildirr[   [   s     #u{{377==
u9FHHRWW\\$/7 :.FHHRWW\\$	6:EB / 	RWW\\$	+;<cBHHJ r,   c                  .    \ rS rSrSrSrS rS rS rSr	g)MaildirMessagep   z
A message receiver which adds a header and delivers a message to a file
whose name includes the size of the message.

@type size: L{int}
@ivar size: The number of octets in the message.
Nc                    SU-  nUR                  U5        [        U5      U l        [        R                  R
                  " X/UQ70 UD6  g)ay  
@type address: L{bytes}
@param address: The address of the message recipient.

@type fp: file-like object
@param fp: The file in which to store the message while it is being
    received.

@type a: 2-L{tuple} of (0) L{bytes}, (1) L{bytes}
@param a: Positional arguments for L{FileMessage.__init__}.

@type kw: L{dict}
@param kw: Keyword arguments for L{FileMessage.__init__}.
s   Delivered-To: %s
N)writelensizer   FileMessager*   )r'   addressfpakwheaders         r)   r*   MaildirMessage.__init__{   sC     '0
K	!!$5Q5"5r,   c                    [         R                  R                  X5        U =R                  [	        U5      S-   -  sl        g)zO
Write a line to the file.

@type line: L{bytes}
@param line: A received line.
r.   N)r   rc   lineReceivedrb   ra   )r'   lines     r)   rk   MaildirMessage.lineReceived   s.     	%%d1		SY]"	r,   c                    U R                   SU R                  -  -   U l         [        R                  R	                  U 5      $ )a  
At the end of message, rename the file holding the message to its final
name concatenated with the size of the file.

@rtype: L{Deferred <defer.Deferred>} which successfully results in
    L{bytes}
@return: A deferred which returns the name of the file holding the
    message.
z,S=%d)	finalNamerb   r   rc   eomReceivedr'   s    r)   rp   MaildirMessage.eomReceived   s4     'DII*==++D11r,   )ro   rb   )
r@   rA   rB   rC   rD   rb   r*   rk   rp   rI   rJ   r,   r)   r]   r]   p   s     D6(#2r,   r]   c                  ~    \ rS rSr% SrSrS\S'   SS jrS rS r	SS	 jr
S
 rS rSS jrS r        SS jrSrg)AbstractMaildirDomain   zp
An abstract maildir-backed domain.

@ivar alias: A mapping of username to alias.

@ivar root: See L{__init__}.
NzNone | dict[bytes, AliasBase]aliasc                    X l         g)zM
@param service: An email service.

@param root: The maildir root directory.
N)root)r'   servicerx   s      r)   r*   AbstractMaildirDomain.__init__   s	     	r,   c                    g)z
Return the maildir directory for a user.

@type user: L{bytes}
@param user: A username.

@rtype: L{bytes} or L{None}
@return: The user's mail directory for a valid user. Otherwise,
    L{None}.
NrJ   r'   users     r)   userDirectory#AbstractMaildirDomain.userDirectory   s     r,   c                    Xl         g)z
Set the group of defined aliases for this domain.

@type alias: L{dict} mapping L{bytes} to L{IAlias} provider.
@param alias: A mapping of domain name to alias.
N)rv   )r'   rv   s     r)   setAliasGroup#AbstractMaildirDomain.setAliasGroup   s	     
r,   c                  ^ ^^ T R                  TR                  R                  5      b  U U4S j$  T R                  TR                  R                     nUR	                  T R                  U5      mT(       a  U4S j$ [
        R                  " S[        T5      -   5        [        R                  " T5      e! [         a    [        R                  " T5      ef = f)a>  
Check whether a user exists in this domain or an alias of it.

@type user: L{User}
@param user: A user.

@type memo: L{None} or L{dict} of L{AliasBase}
@param memo: A record of the addresses already considered while
    resolving aliases. The default value should be used by all
    external code.

@rtype: no-argument callable which returns L{IMessage <smtp.IMessage>}
    provider.
@return: A function which takes no arguments and returns a message
    receiver for the user.

@raises SMTPBadRcpt: When the given user does not exist in this domain
    or an alias of it.
c                 &   > T R                  T5      $ N)startMessager|   s   r)   <lambda>.AbstractMaildirDomain.exists.<locals>.<lambda>   s    4,,T2r,   c                    > T $ r   rJ   )aliasess   r)   r   r      s    wr,   zBad alias configuration: )r~   destlocalrv   resolver   errr4   r   SMTPBadRcptBaseException)r'   r}   memorf   r   s   ``  @r)   existsAbstractMaildirDomain.exists   s    ( diioo.:22		)

499??+A ii

D1G&&GG/#d);<""4((  	)""4((	)s   #B6 6!Cc           
        [        U[        5      (       a  UR                  SS5      u  p#O+UR                  R                  UR                  R
                  p2U R                  U5      n[        5       n[        R                  R                  USU5      n[        US5      n[        U SU 3Xv[        R                  R                  USU5      5      $ )z
Create a maildir message for a user.

@type user: L{bytes}
@param user: A username.

@rtype: L{MaildirMessage}
@return: A message receiver for this user.
@r.   tmprP   new)rQ   r4   splitr   r   domainr~   _generateMaildirNamer6   rR   rU   rV   r]   )r'   r}   namer   rX   fnamefilenamere   s           r)   r   "AbstractMaildirDomain.startMessage   s     dC  ::c1-LD&99??DII,<,<&  &$&77<<UE2(C fAfXbggll3u.M
 	
r,   c                    g)aF  
Check whether this domain will relay.

@type user: L{Address}
@param user: The destination address.

@type protocol: L{SMTP}
@param protocol: The protocol over which the message to be relayed is
    being received.

@rtype: L{bool}
@return: An indication of whether this domain will relay the message to
    the destination.
FrJ   )r'   r}   protocols      r)   	willRelayAbstractMaildirDomain.willRelay  s     r,   c                    [         e)z}
Add a user to this domain.

Subclasses should override this method.

@param user: A username.

@param password: A password.
NotImplementedErrorr'   r}   passwords      r)   addUserAbstractMaildirDomain.addUser  
     "!r,   c                    [         e)z
Return credentials checkers for this domain.

Subclasses should override this method.

@rtype: L{list} of L{ICredentialsChecker
    <checkers.ICredentialsChecker>} provider
@return: Credentials checkers for this domain.
r   rq   s    r)   getCredentialsCheckers,AbstractMaildirDomain.getCredentialsCheckers%  r   r,   c                    [        5       e)z-
Abstract domains cannot authenticate users.
r   )r'   avatarIdmindr   s       r)   requestAvatar#AbstractMaildirDomain.requestAvatar1  s     "##r,   )rv   rx   )ry   r   rx   r?   r>   Noner   r}   r?   r   r?   r>   r   r   zbytes | tuple[()]r   objectr   ztype[Interface]r>   z2tuple[type[Interface], object, Callable[[], None]])r@   rA   rB   rC   rD   rv   __annotations__r*   r~   r   r   r   r   r   r   r   rI   rJ   r,   r)   rt   rt      sb     ,0E(/)B
,"
"
"$)$17$FU$	;$r,   rt   c                      \ rS rSrSr\" \R                  5      r\" \R                  5      r
\" \R                  5      r\" \R                  5      rSS jrSS jrSS jrS rS rSS jr	SS
 jrS rS rSrg	) _MaildirMailboxAppendMessageTaski:  a  
A task which adds a message to a maildir mailbox.

@ivar mbox: See L{__init__}.

@type defer: L{Deferred <defer.Deferred>} which successfully returns
    L{None}
@ivar defer: A deferred which fires when the task has completed.

@type opencall: L{IDelayedCall <interfaces.IDelayedCall>} provider or
    L{None}
@ivar opencall: A scheduled call to L{prodProducer}.

@type msg: file-like object
@ivar msg: The message to add.

@type tmpname: L{bytes}
@ivar tmpname: The pathname of the temporary file holding the message while
    it is being transferred.

@type fh: file
@ivar fh: The new maildir file.

@type filesender: L{FileSender <basic.FileSender>}
@ivar filesender: A file sender which sends the message.

@type myproducer: L{IProducer <interfaces.IProducer>}
@ivar myproducer: The registered producer.

@type streaming: L{bool}
@ivar streaming: Indicates whether the registered producer provides a
    streaming interface.
c                    Xl         [        R                  " 5       U l        SU l        [	        US5      (       d  [
        R                  " U5      nX l        g)z
@type mbox: L{MaildirMailbox}
@param mbox: A maildir mailbox.

@type msg: L{bytes} or file-like object
@param msg: The message to add.
Nread)mboxr   r   openCallhasattrioBytesIOmsg)r'   r   r   s      r)   r*   )_MaildirMailboxAppendMessageTask.__init__c  s=     	+0>>+;
sF##**S/Cr,   c                    U R                  5         U R                  S:w  aA  [        R                  " 5       U l        U R                  R                  U R                  U 5        gg)z0
Start transferring the message to the mailbox.
N)createTempFilefhr   
FileSender
filesenderbeginFileTransferr   rq   s    r)   startUp(_MaildirMailboxAppendMessageTask.startUpr  sH     	77b=#..0DOOO--dhh= r,   c                L    Xl         X l        U(       d  U R                  5         gg)z
Register a producer and start asking it for data if it is
non-streaming.

@param producer: A producer.

@param streaming: A flag indicating whether the producer provides a
    streaming interface.
N)
myproducer	streamingprodProducer)r'   producerr   s      r)   registerProducer1_MaildirMailboxAppendMessageTask.registerProducer{  s"     #" r,   c                    SU l         U R                  bA  [        R                  " SU R                  5      U l         U R                  R                  5         gg)z;
Repeatedly prod a non-streaming producer to produce data.
Nr   )r   r   r   	callLaterr   resumeProducingrq   s    r)   r   -_MaildirMailboxAppendMessageTask.prodProducer  sD     ??&#--a1B1BCDMOO++- 'r,   c                v    SU l         SU l        U R                  U R                  5        U R	                  5         g)z1
Finish transferring the message to the mailbox.
N)r   r   oscloser   moveFileToNewrq   s    r)   unregisterProducer3_MaildirMailboxAppendMessageTask.unregisterProducer  s.     TWWr,   c                ~     U R                  U R                  U5        g! [         a    U R                  5          gf = f)zO
Write data to the maildir file.

@param data: Data to be written to the file.
N)oswriter   r   fail)r'   datas     r)   r`   &_MaildirMailboxAppendMessageTask.write  s1    	LL$' 	IIK	s    <<Nc                    Uc  [         R                  " 5       nU R                  b  U R                  R                  5         U R                  R                  U5        SU l        g)z
Fire the deferred to indicate the task completed with a failure.

@type err: L{Failure <failure.Failure>}
@param err: The error that occurred.
N)r   Failurer   cancelr   errback)r'   r   s     r)   r   %_MaildirMailboxAppendMessageTask.fail  sH     ;//#C==$MM  "

3
r,   c                    [         R                  R                  U R                  R                  S[	        5       5      n U R                  U R                  U5         UbH  U R                  R                  R                  U5        U R                  R                  S5        SU l        gg! [         aC  nUR                  u  p4SSK	nX5R                  :w  a  U R                  5         Sn SnAM   SnAOSnAff = fM  )z
Place the message in the I{new/} directory, add it to the mailbox and
fire the deferred to indicate that the task has completed
successfully.
rL   r   N)r6   rR   rU   r   r   osrenametmpnameOSErrorargserrnoEEXISTr   listappendr   callback)r'   newnameer   estrr   s         r)   r   ._MaildirMailboxAppendMessageTask.moveFileToNew  s     ggll499>>6;O;QRGdllG4 IINN!!'*JJ%DJ   ff ,,&IIK"G ' s    B) )
C633C11C6c                P   [         R                  [         R                  -  [         R                  -  [	        [         SS5      -  [	        [         SS5      -  nSnSU l         [         R                  R                  U R                  R                  S[        5       5      U l
         U R                  U R                  US5      U l        g! [         aR    US-  nUS	:  aD  U R                  R                  [        S
U R                  R                  -  5      5        SU l         g Of = fM  )zI
Create a temporary file to hold the message as it is being transferred.
O_NOINHERITr   
O_NOFOLLOWr   rN   i  Nr.   i  z Could not create tmp file for %s)r6   O_RDWRO_CREATO_EXCLgetattrr   rR   rU   r   r   r   osopenr   r   r   RuntimeError)r'   attrtriess      r)   r   /_MaildirMailboxAppendMessageTask.createTempFile  s   
 IIjjii b-+, b,*	+ 	 77<<		@T@VWDL ++dllD%@ 	 
3;JJ&&$>O
 "&DJ 	  s   $"C AD#"D#)	r   r   r   r   r   r   r   r   r   )r   MaildirMailboxr   bytes | IO[bytes]r>   r   )r>   r   )r   r   r   boolr>   r   )r   r?   r>   r   r   )r@   rA   rB   rC   rD   staticmethodr6   rV   r   r`   r   rW   r   renamer   r*   r   r   r   r   r   r   r   rI   rJ   r,   r)   r   r   :  so     D "''"F288$G288$GBII&H> .	2 r,   r   c                      \ rS rSrSr\rSS jr\SS j5       r	\SS j5       r	SSS jjr	SS jr
S	 rS
 rS rSS jrSrg)r   i  a  
A maildir-backed mailbox.

@ivar path: See L{__init__}.

@ivar list: Information about the messages in the mailbox.  For undeleted
    messages, the full path name of the message storing the file is stored.
    Deleted messages are indicated by 0.

@type deleted: A mapping of the path to a deleted file before it was
    deleted to the full path name of the deleted file in the I{.Trash/}
    subfolder.
c           
     ~   Xl         0 U l        [        U5        / nS Hn  n[        R                  " [        R                   R                  X5      5       H4  nUR                  U[        R                   R                  XU5      45        M6     Mp     UR                  5         U Vs/ s H  oUS   PM	     snU l        gs  snf )z8
@param path: The directory name for a maildir mailbox.
)rM   rL   r.   N)	rR   deletedr[   r6   listdirrU   r   sortr   )r'   rR   	computingr   fileels         r)   r*   MaildirMailbox.__init__  s     	+-$	$D

277<<#;<  $T(F!GH = % 	8A'B	"1	'B	'Bs   #B:c                    g r   rJ   rq   s    r)   listMessagesMaildirMailbox.listMessages      r,   c                    g r   rJ   r'   is     r)   r  r    r  r,   Nc                |   Ucg  / nU R                    HS  nU(       a8  UR                  [        R                  " U5      [        R                     5        MB  UR                  S5        MU     U$ U R                   U   =(       a4    [        R                  " U R                   U   5      [        R                     =(       d    S$ )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 a message.

@rtype: L{int} or L{list} of L{int}
@return: The number of octets in the specified message, or, if an index
    is not specified, a list of the number of octets for all messages
    in the mailbox.  Any value which corresponds to a deleted message
    is set to 0.

@raise IndexError: When the index does not correspond to a message in
    the mailbox.
r   )r   r   r6   statST_SIZE)r'   r  retmesss       r)   r  r    s    " 9C		JJrwwt}T\\:;JJqM	 "
 Jyy|C		! 5dll CHqHr,   c                2    [        U R                  U   5      $ )a  
Retrieve a file-like object with 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 IndexError: When the index does not correspond to a message in
    the mailbox.
)rV   r   r  s     r)   
getMessageMaildirMailbox.getMessage.  s     DIIaL!!r,   c                    [         R                  R                  U R                  U   5      n[	        U5      R                  5       $ )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 IndexError: When the index does not correspond to a message in
    the mailbox.
)r6   rR   basenamer   r   	hexdigest)r'   r  bases      r)   getUidlMaildirMailbox.getUidl=  s3     ww		!-4y""$$r,   c           	     L   [         R                  R                  U R                  SS[         R                  R                  U R                  U   5      5      n[         R
                  " U R                  U   U5        X R                  U R                  U   '   SU R                  U'   g)a  
Mark a message for deletion.

Move the message to the I{.Trash/} subfolder so it can be undeleted
by an administrator.

@type i: L{int}
@param i: The 0-based index of a message.

@raise IndexError: When the index does not correspond to a message in
    the mailbox.
z.Trashcurr   N)r6   rR   rU   r  r   r  r  )r'   r  	trashFiles      r)   deleteMessageMaildirMailbox.deleteMessageO  ss     GGLLIIx(8(81(F
	 			$))A,	*%.TYYq\"		!r,   c                   U R                   R                  5        HD  u  p [        R                  " X!5         XR                  U R                  R                  S5      '   MF     U R                   R                  5         g! [         a    U R                  R                  U5         M  f = f! [         a-  nUR                  u  pESSK
nXFR                  :w  a  e  SnAM  SnAff = f)z
Undelete all messages marked for deletion.

Move each message marked for deletion from the I{.Trash/} subfolder back
to its original position.
r   N)r  itemsr6   r  r   index
ValueErrorr   r   r   r   ENOENTclear)r'   realtrashr   r   r   r   s          r)   undeleteMessagesMaildirMailbox.undeleteMessagesc  s      <<--/KD+		%&+48IIdiiooa01 0  	 " +II$$T*+  ff ,,& 's(   B*'A>>%B'&B'*
C!4"CC!c                `    U R                  X5      nUR                  nUR                  5         U$ )z
Add a message to the mailbox.

@param txt: A message to add.

@return: A deferred which fires when the message has been added to the
    mailbox.
)AppendFactoryr   r   )r'   txttaskresults       r)   appendMessageMaildirMailbox.appendMessage|  s+     !!$,r,   )r  r   rR   )rR   r?   r>   r   )r>   z	list[int])r  r5   r>   r5   r   )r  z
int | Noner>   zint | list[int])r  r5   r>   zIO[str])r4  r  r>   zDeferred[None])r@   rA   rB   rC   rD   r   r3  r*   r   r  r  r!  r&  r0  r7  rI   rJ   r,   r)   r   r     s[     5MC    I6"%$(2r,   r   c                  J    \ rS rSrSrS rSS jrSS jrS rS r	S	 r
S
 rSrg)StringListMailboxi  z
An in-memory mailbox.

@ivar  msgs: See L{__init__}.

@type _delete: L{set} of L{int}
@ivar _delete: The indices of messages which have been marked for deletion.
c                .    Xl         [        5       U l        g)z[
@type msgs: L{list} of L{bytes}
@param msgs: The contents of each message in the mailbox.
N)msgsset_delete)r'   r<  s     r)   r*   StringListMailbox.__init__  s    
 	ur,   Nc                    Uc=  [        [        U R                  5      5       Vs/ s H  o R                  U5      PM     sn$ XR                  ;   a  g[        U R                  U   5      $ s  snf )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 a message.

@rtype: L{int} or L{list} of L{int}
@return: The number of octets in the specified message, or, if an index
    is not specified, a list of the number of octets in each message in
    the mailbox.  Any value which corresponds to a deleted message is
    set to 0.

@raise IndexError: When the index does not correspond to a message in
    the mailbox.
r   )rangera   r<  r  r>  )r'   r  r   s      r)   r  StringListMailbox.listMessages  s\    " 96;C		N6KL6Ks%%c*6KLL499Q<   Ms   A)c                H    [         R                  " U R                  U   5      $ )a	  
Return an in-memory file-like object with the contents of a message.

@param i: The 0-based index of a message.

@return: An in-memory file-like object containing the message.

@raise IndexError: When the index does not correspond to a message in
    the mailbox.
)r   r   r<  r  s     r)   r  StringListMailbox.getMessage  s     zz$))A,''r,   c                N    [        U R                  U   5      R                  5       $ )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 hash of the contents of the message at the given index.

@raise IndexError: When the index does not correspond to a message in
    the mailbox.
)r   r<  r  r  s     r)   r!  StringListMailbox.getUidl  s      499Q< **,,r,   c                :    U R                   R                  U5        g)z
Mark a message for deletion.

@type i: L{int}
@param i: The 0-based index of a message to delete.

@raise IndexError: When the index does not correspond to a message in
    the mailbox.
N)r>  addr  s     r)   r&  StringListMailbox.deleteMessage  s     	r,   c                "    [        5       U l        g)z<
Undelete any messages which have been marked for deletion.
N)r=  r>  rq   s    r)   r0  "StringListMailbox.undeleteMessages  s     ur,   c                f    U R                    H  nSU R                  U'   M     [        5       U l         g)z;
Discard the contents of any messages marked for deletion.
 N)r>  r<  r=  )r'   r*  s     r)   syncStringListMailbox.sync  s)     \\E!DIIe "ur,   )r>  r<  r   )r  r5   r>   z	IO[bytes])r@   rA   rB   rC   rD   r*   r  r  r!  r&  r0  rN  rI   rJ   r,   r)   r:  r:    s*    !.(-
r,   r:  c                  r    \ rS rSrSrSrSr S
       SS jjrSS jrSS jr	S r
        SS jrS	rg)MaildirDirdbmDomaini  ax  
A maildir-backed domain where membership is checked with a
L{DirDBM <dirdbm.DirDBM>} database.

The directory structure of a MaildirDirdbmDomain is:

/passwd <-- a DirDBM directory

/USER/{cur, new, del} <-- each user has these three directories

@ivar postmaster: See L{__init__}.

@type dbm: L{DirDBM <dirdbm.DirDBM>}
@ivar dbm: The authentication database for the domain.
Nc                R   [         R                  " U5      n[        R                  XU5        [         R                  R                  US5      n[         R                  R                  U5      (       d  [         R                  " U5        [        R                  " U5      U l
        X0l        g)z
@param service: An email service.

@param root: The maildir root directory.

@param postmaster: A flag indicating whether non-existent addresses
    should be forwarded to the postmaster (C{True}) or bounced
    (C{False}).
s   passwdN)r6   r7   rt   r*   rR   rU   r   makedirsr   rV   dbm
postmaster)r'   ry   rx   rU  rT  s        r)   r*   MaildirDirdbmDomain.__init__  sj     {{4 &&td;ggll4+ww~~c""KK;;s#$r,   c                    XR                   ;  a  U R                  (       d  gSn[        R                  R	                  U R
                  U5      n[        R                  R                  U5      (       d  [        U5        U$ )a   
Return the path to a user's mail directory.

@param name: A username.

@return: The path to the user's mail directory for a valid user. For
    an invalid user, the path to the postmaster's mailbox if bounces
    are redirected there. Otherwise, L{None}.
Ns
   postmaster)rT  rU  r6   rR   rU   rx   r   r[   )r'   r   rX   s      r)   r~   !MaildirDirdbmDomain.userDirectory  sU     xx?? Dggll499d+ww~~c""c"
r,   c                B    X R                   U'   U R                  U5        g)z
Add a user to this domain by adding an entry in the authentication
database and initializing the user's mail directory.

@type user: L{bytes}
@param user: A username.

@type password: L{bytes}
@param password: A password.
N)rT  r~   r   s      r)   r   MaildirDirdbmDomain.addUser(  s     "4 r,   c                j    U R                   c  [        U R                  5      /U l         U R                   $ )z
Return credentials checkers for this domain.

@rtype: L{list} of L{ICredentialsChecker
    <checkers.ICredentialsChecker>} provider
@return: Credentials checkers for this domain.
)_credcheckersDirdbmDatabaserT  rq   s    r)   r   *MaildirDirdbmDomain.getCredentialsCheckers7  s0     %"0":!;D!!!r,   c                T   [         R                  U;  a  [        S5      eU[        R                  :X  a  [        [        /5      nOQ[        U[        5      (       d   S5       e[        R                  R                  U R                  U5      n[        U5      n[         R                  US 4$ )a  
Get the mailbox for an authenticated user.

The mailbox for the authenticated user will be returned only if the
given interfaces include L{IMailbox <pop3.IMailbox>}.  Requests for
anonymous access will be met with a mailbox containing a message
indicating that an internal error has occurred.

@type avatarId: L{bytes} or C{twisted.cred.checkers.ANONYMOUS}
@param avatarId: A string which identifies a user or an object which
    signals a request for anonymous access.

@type mind: L{None}
@param mind: Unused.

@type interfaces: n-L{tuple} of C{zope.interface.Interface}
@param interfaces: A group of interfaces, one of which the avatar
    must support.

@rtype: 3-L{tuple} of (0) L{IMailbox <pop3.IMailbox>},
    (1) L{IMailbox <pop3.IMailbox>} provider, (2) no-argument
    callable
@return: A tuple of the supported interface, a mailbox, and a
    logout function.

@raise NotImplementedError: When the given interfaces do not include
    L{IMailbox <pop3.IMailbox>}.
zNo interfacez2avatar ID must be bytes, already checked ANONYMOUSc                     g r   rJ   rJ   r,   r)   r   3MaildirDirdbmDomain.requestAvatar.<locals>.<lambda>p  s    Tr,   )r   IMailboxr   r
   	ANONYMOUSr:  INTERNAL_ERRORrQ   r?   r6   rR   rU   rx   r   )r'   r   r   r   r   mboxroots         r)   r   !MaildirDirdbmDomain.requestAvatarC  s    D ==
*%n55x)))$n%56D%  DCD  ww||DIIx8H!(+Dt\22r,   )r\  rT  rU  )F)ry   r   rx   r?   rU  r  r>   r   )r   r?   r>   zbytes | Noner   r   )r@   rA   rB   rC   rD   r   r\  r*   r~   r   r   r   rI   rJ   r,   r)   rQ  rQ    sy      FM EJ%"%*/%=A%	%(&!
"-3#-3 -3 %	-3
 
<-3r,   rQ  c                  d    \ rS rSrSr\R                  \R                  4rSS jr	    SS jr
Srg)	r]  is  z
A credentials checker which authenticates users out of a
L{DirDBM <dirdbm.DirDBM>} database.

@ivar dirdbm: An authentication database.
c                    Xl         g)z)
@param dbm: An authentication database.
Nr   )r'   rT  s     r)   r*   DirdbmDatabase.__init__  s	     r,   c                    UR                   U R                  ;   aD  U R                  UR                      nUR                  U5      (       a  [        UR                   5      $ [	        5       e)ag  
Authenticate a user and, if successful, return their username.

@type c: L{IUsernamePassword <credentials.IUsernamePassword>} or
    L{IUsernameHashedPassword <credentials.IUsernameHashedPassword>}
    provider.
@param c: Credentials.

@rtype: L{bytes}
@return: A string which identifies an user.

@raise UnauthorizedLogin: When the credentials check fails.
)usernamer   checkPasswordr   r   )r'   cr   s      r)   requestAvatarIdDirdbmDatabase.requestAvatarId  sM      ::${{1::.Hx((qzz**!!r,   r   N)rT  zdirdbm.DirDBMr>   r   )rm  z+IUsernamePassword | IUsernameHashedPasswordr>   zDeferred[bytes | tuple[()]])r@   rA   rB   rC   rD   r   r   r   credentialInterfacesr*   rn  rI   rJ   r,   r)   r]  r]  s  s=     	%%++
"<"	$"r,   r]  )rX   zbytes | strr>   r   )DrD   
__future__r   r   r6   rF   r  hashlibr   typingr   r   r   zope.interfacer   r	   twisted.credr
   r   r   twisted.cred.credentialsr   r   twisted.cred.errorr   twisted.internetr   r   r   twisted.internet.deferr   r   twisted.internet.interfacesr   twisted.mailr   r   r   twisted.mail.aliasr   twisted.mail.mailr   twisted.persistedr   twisted.protocolsr   twisted.pythonr   r   rd  r!   r<   r   r[   rc   r]   IAliasableDomainrt   	IConsumerr   Mailboxr   rb  r:  IRealmrQ  ICredentialsCheckerr]  rJ   r,   r)   <module>r     sj   # 	 	    ) ) 1 6 6 O 0 7 7 4 1 ) ) ( ) $ # '+T +T\ -W5>> K*42T%% 42n T""#O$ O$ $O$d Z!!"n  n  #n b\T\\ \~ T]]] ] ]@ V]]C3/ C3 C3L X))*(" (" +("r,   