AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3/dist-packages/twisted/mail/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /lib/python3/dist-packages/twisted/mail/test/__pycache__/test_mail.cpython-310.pyc
o

�b\�@s�dZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlmZddlmZddlmZmZddlmZddlZddlZddlZddlZddlZddlZddlZddlZddl Zddlm!Z!m"Z"ddl#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)dd	l*m+Z+dd
l,m-Z-m.Z.m/Z/m0Z0ddl1m2Z2m3Z3ddl m4Z4dd
l5m6Z6ddl7m8Z8m9Z9m:Z:ddl;m<Z<ddl=m>Z>m?Z?ddl@mAZAddlBmCZCddlDmEZEmFZFmGZGddlHmIZIeeCdkd�Gdd�deI��ZJeeCdkd�Gdd�deI��ZKeeCdkd�Gdd�deI��ZLeeCdkd�Gdd�deI��ZMeeCdkd�Gdd �d eI��ZNeeCdkd�Gd!d"�d"eI��ZOeeCdkd�Gd#d$�d$e"jPjQ��ZRGd%d&�d&�ZSeeCdkd�Gd'd(�d(eIeS��ZTeeCdkd�Gd)d*�d*eIeS��ZUeeCdkd�Gd+d,�d,eI��ZVeeCdkd�Gd-d.�d.eI��ZWeeCdkd�Gd/d0�d0eI��ZXee"j"jY�Gd1d2�d2��ZZeeCdkd�Gd3d4�d4eI��Z[eeCdkd�Gd5d6�d6eI��Z\Gd7d8�d8e3j]�Z^eeCdkd�Gd9d:�d:eI��Z_eeCdkd�Gd;d<�d<eI��Z`Gd=d>�d>�ZaeeCdkd�Gd?d@�d@eI��ZbeeCdkd�GdAdB�dBeI��ZcddCl5mdZdmeZemfZfGdDdE�dEeejg�ZhdFdG�ZidHdI�ZjeeCdkd�GdJdK�dKeI��ZkeeCdkd�GdLdM�dMeI��ZlGdNdO�dO�ZmeeCdkd�GdPdQ�dQeI��ZnGdRdS�dS�ZoeeCdkd�GdTdU�dUeI��ZpGdVdW�dW�ZqGdXdY�dYe"jrjs�ZtGdZd[�d[e"jrju�ZvGd\d]�d]�ZweeCdkd�Gd^d_�d_eI��ZxGd`da�da�ZyGdbdc�dc�ZzGddde�de�Z{eeCdkd�Gdfdg�dgeI��Z|dS)hz.
Tests for large portions of L{twisted.mail}.
�N)�md5)�skipIf)�	Interface�implementer)�verifyClass)�cred�mail)�address�defer�
interfaces�protocol�reactor�task)�Deferred)�CannotListenError�DNSLookupError�ProcessDone�ProcessTerminated)�pop3�smtp)�_AttemptManager)�dns)�Record_CNAME�	Record_MX�RRHeader)�DNSNameError)�failure�log)�FilePath)�platformType)�LineSendingProtocol�MemoryReactorClock�StringTransport)�TestCase�posixz twisted.mail only works on posixc@sDeZdZeejdkd�dd��Zdd�Zdd�Zd	d
�Z	dd�Z
d
S)�DomainWithDefaultsTests���not ported to Python 3cCs�dd�td�D�}tj�|d�}|�t|�d�|�tt|��ttd���|�t|���tt|���t|���}|�	�|�|dd�td�D��t|�
��}|�	�|�|ttdd���|��}|�	�|�|dd�td�D��|��}|�	�|�|ttdd���td�D]}|�|||d�|�|�
|�|d�|�||v�q�|d	=|d
=|d=|�t|�d�|�|d	d�|�|d
d�|�|dd�|�dd
dd��|�t|�d�|�|dd�|�|dd
�|�|dd�|��|�t|�d�|�|�dd�d�|�|dd�|�|��d�|�t|�d�|��}|�|j|j�|�|j|j�dS)NcSsi|]}||d�qS��
���.0�xr+r+�=/usr/lib/python3/dist-packages/twisted/mail/test/test_mail.py�
<dictcomp>@�z7DomainWithDefaultsTests.testMethods.<locals>.<dictcomp>r*�DefaultcS�g|]}||df�qSr)r+r,r+r+r/�
<listcomp>I�z7DomainWithDefaultsTests.testMethods.<locals>.<listcomp>�cSr3r)r+r,r+r+r/r4Qr5����r+�*)�a�b�cr<r=r>r�key�value)r?r@)�ranger�DomainWithDefaultDict�assertEqual�len�list�iter�iterkeys�	iteritems�sort�
itervalues�items�values�get�
assertTrue�update�clear�
setdefault�popitem�copy�domains�default)�self�drKrLr.�dcopyr+r+r/�testMethods>sPz#DomainWithDefaultsTests.testMethodscCsFtj�id�}|�|jj||��d|d<|�tddi�||��dS)a�
        Assert that the class name of a L{mail.mail.DomainWithDefaultDict}
        instance and the string-formatted underlying domain dictionary both
        appear in the string produced by the given string-returning function.

        @type stringifier: one-argument callable
        @param stringifier: either C{str} or C{repr}, to be used to get a
            string to make assertions against.
        r2r@r?N)rrB�assertIn�	__class__�__name__�str)rV�stringifier�domainr+r+r/�_stringificationTestvs
z,DomainWithDefaultsTests._stringificationTestcC�|�t�dS)z�
        L{DomainWithDefaultDict.__str__} should return a string including
        the class name and the domain mapping held by the instance.
        N)r`r]�rVr+r+r/�test_str��z DomainWithDefaultsTests.test_strcCra)z�
        L{DomainWithDefaultDict.__repr__} should return a string including
        the class name and the domain mapping held by the instance.
        N)r`�reprrbr+r+r/�	test_repr�rdz!DomainWithDefaultsTests.test_reprcCsftj�id�}|�d�d}|�|jg�}|�dt|��|�t|dd�|�||dd�dS)	z,
        has_key is now deprecated.
        r2�anythingzotwisted.mail.mail.DomainWithDefaultDict.has_key was deprecated in Twisted 16.3.0. Use the `in` keyword instead.�r�category�messageN)rrB�has_key�
flushWarnings�test_has_keyDeprecationrCrD�DeprecationWarning)rV�sutrj�warningsr+r+r/rm�s
�z/DomainWithDefaultsTests.test_has_keyDeprecationN)r\�
__module__�__qualname__r�sys�version_inforYr`rcrfrmr+r+r+r/r%<s
7r%c@�,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�BounceTestscC�tj��|_dS�N)r�BounceDomainr_rbr+r+r/�setUp��zBounceTests.setUpcCs|�tj|jjd�dS)Nzany user)�assertRaisesr�AddressErrorr_�existsrbr+r+r/�
testExists�szBounceTests.testExistscCs|�|j�dd�d�dS)Nzrandom q emailerrF)rCr_�	willRelayrbr+r+r/�	testRelay�szBounceTests.testRelaycCs&|j�dd�|�tj|jjd�dS)N�bob�password)r_�addUserr|r�SMTPBadRcptr~rbr+r+r/�testAddUser�szBounceTests.testAddUserN)r\rqrrrzrr�r�r+r+r+r/rv�s
rvc@�eZdZdZdd�ZdS)�BounceWithSMTPServerTestsz_
    Tests for L{twisted.mail.mail.BounceDomain} with
    L{twisted.mail.smtp.SMTPServer}.
    cCs�tj��}tj��}|�d|�tj�|�}|�d�}tj�|dd�}||_t	�}|�
|�|�d�|�d�|�d�|�d�|�|j
�|�d�|�|�����d�dd	�dS)
zo
        Incoming emails to a SMTP server with L{twisted.mail.mail.BounceDomain}
        are rejected.
        sfoo.comNsHELO baz.netsMAIL FROM:<a@baz.net>sRCPT TO:<any@foo.com>sQUITs
���s(550 Cannot receive for specified address)r�MailServicery�	addDomain�	protocols�SMTPFactory�
buildProtocol�SMTPDomainDelivery�deliveryr"�makeConnection�lineReceivedrN�
disconnecting�connectionLostrCr@�strip�split)rV�servicer_�factoryr�	deliverer�	transportr+r+r/�
test_rejected�s&








�z'BounceWithSMTPServerTests.test_rejectedN)r\rqrr�__doc__r�r+r+r+r/r��sr�c@s\eZdZdd�Zdd�Zdd�Zdd�Zeej	d	kd
�dd��Z
eej	d	kd
�d
d��ZdS)�FileMessageTestscCs6d|_d|_t|jd�|_tj�|j|j|j�|_dS)NzfileMessage.testFilezfinal.fileMessage.testFile�w)�name�final�open�fr�FileMessage�fprbr+r+r/rz�szFileMessageTests.setUpcCsnz|j��Wn	tyYnwzt�|j�Wn	ty"Ynwz	t�|j�WdSty6YdSwrx)r��close�
BaseException�os�remover�r�rbr+r+r/�tearDown�s���zFileMessageTests.tearDowncCs|j���|j�Srx)r��eomReceived�addCallback�_cbFinalNamerbr+r+r/�
testFinalName��zFileMessageTests.testFinalNamecCs4|�||j�|�|jj�|�tj�|j	��dSrx)
rCr�rNr��closed�assertFalser��pathr~r��rV�resultr+r+r/r��szFileMessageTests._cbFinalNamer&r(cCshd}|��D]}|j�|�q|j��t|j��}|�|��|�Wd�dS1s-wYdS)Nz"first line
second line
third line
)�
splitlinesr�r�r�r�r�rC�read)rV�contents�liner�r+r+r/�testContents�s
"�zFileMessageTests.testContentscCsTd}|��D]}|j�|�q|j��|�tj�|j��|�tj�|j	��dS)Nzfirst line
second line
)
r�r�r�r�r�r�r�r~r�r�)rVr�r�r+r+r/�testInterrupteds
z FileMessageTests.testInterruptedN)r\rqrrrzr�r�r�rrsrtr�r�r+r+r+r/r��s
r�c@s$eZdZdd�Zdd�Zdd�ZdS)�MailServiceTestscCrwrx)rr�r�rbr+r+r/rzr{zMailServiceTests.setUpcCs�|j��}|�t|tj��|�|�d�tj�|j�	�}|�t|tj��|�|�d�t
j�|j��}|�t|tj��|�|�d�t
j
�dS)N)�	127.0.0.1�90)r��getPOP3FactoryrN�
isinstancer�
ServerFactoryr�r�POP3�getSMTPFactoryr�SMTP�getESMTPFactory�ESMTP)rVr�r+r+r/�
testFactoriess


zMailServiceTests.testFactoriescCsRt�}t�}||jjd<||jjd<|�|j�d�|u�|�|j��|u�dS)Nr_�)�objectr��portalsrN�lookupPortal�
defaultPortal)rV�o1�o2r+r+r/�testPortalsszMailServiceTests.testPortalsN)r\rqrrrzr�r�r+r+r+r/r�
s
r�c@sheZdZdZdd�Zdd�Zeejdkd�dd	��Z	eejdkd�d
d��Z
dd
�Zdd�Zdd�Z
dS)�StringListMailboxTestszc
    Tests for L{StringListMailbox}, an in-memory only implementation of
    L{pop3.IMailbox}.
    cCsJtj�gd��}|�|�d�d�|�|�d�d�|�|�d�d�dS)z�
        L{StringListMailbox.listMessages} returns the length of the message at
        the offset into the mailbox passed to it.
        )�abc�abr<rr'rhr7N�r�maildir�StringListMailboxrC�listMessages�rV�mailboxr+r+r/�test_listOneMessage0sz*StringListMailboxTests.test_listOneMessagecCs(tj�gd��}|�|��gd��dS)z�
        L{StringListMailbox.listMessages} returns a list of the lengths of all
        messages if not passed an index.
        )r<r�r�)rhr'r7Nr�r�r+r+r/�test_listAllMessages:sz+StringListMailboxTests.test_listAllMessagesr&r(cCs*tj�ddg�}|�|�d���d�dS)z�
        L{StringListMailbox.getMessage} returns a file-like object from which
        the contents of the message at the given offset into the mailbox can be
        read.
        �fooz
real contentsrhN)rr�r�rC�
getMessager�r�r+r+r/�test_getMessageBsz&StringListMailboxTests.test_getMessagecCs,tj�ddg�}|�|�d�|�d��dS)z�
        L{StringListMailbox.getUidl} returns a unique identifier for the
        message at the given offset into the mailbox.
        r��barrrhN)rr�r��assertNotEqual�getUidlr�r+r+r/�test_getUidlLsz#StringListMailboxTests.test_getUidlcCs@tj�dg�}|�d�|�|�d�d�|�|��dg�dS)z�
        L{StringListMailbox.deleteMessage} marks a message for deletion causing
        further requests for its length to return 0.
        r�rN)rr�r��
deleteMessagerCr�r�r+r+r/�test_deleteMessageUs
z)StringListMailboxTests.test_deleteMessagecCsHtj�dg�}|�d�|��|�|�d�d�|�|��dg�dS)z�
        L{StringListMailbox.undeleteMessages} causes any messages marked for
        deletion to be returned to their original state.
        r�rr'N)rr�r�r��undeleteMessagesrCr�r�r+r+r/�test_undeleteMessages_s

z,StringListMailboxTests.test_undeleteMessagescCsPtj�dg�}|�d�|��|��|�|�d�d�|�|��dg�dS)zy
        L{StringListMailbox.sync} causes any messages as marked for deletion to
        be permanently deleted.
        r�rN)rr�r�r��syncr�rCr�r�r+r+r/�	test_syncjs
z StringListMailboxTests.test_syncN)r\rqrrr�r�r�rrsrtr�r�r�r�r�r+r+r+r/r�)s

	

r�c@s0eZdZdZdZdZdd�Zdd�Zdd�ZdS)	�&FailingMaildirMailboxAppendMessageTaskTcCs |jr
t�|||�Sttjd���NzFaked Permission Problem)�
_openstater�r��OSError�errno�EPERM)rV�fn�attr�moder+r+r/�osopensz-FailingMaildirMailboxAppendMessageTask.osopencC�|jr	t�||�Sttjd��)NzFaked Space problem)�_writestater��writer�r��ENOSPC)rV�fh�datar+r+r/�oswrite��z.FailingMaildirMailboxAppendMessageTask.oswritecCr�r�)�_renamestater��renamer�r�r�)rV�oldname�newnamer+r+r/�osrename�r�z/FailingMaildirMailboxAppendMessageTask.osrenameN)	r\rqrrr�r�r�r�r�r�r+r+r+r/r�wsr�c@r�)�_AppendTestMixinz�
    Mixin for L{MaildirMailbox.appendMessage} test cases which defines a helper
    for serially appending multiple messages to a mailbox.
    cs:g����fdd�}t�|����}|��fdd��|S)z�
        Deliver the given messages one at a time.  Delivery is serialized to
        guarantee a predictable order in the mailbox (overlapped message deliver
        makes no guarantees about which message which appear first).
        c3s,��D]}��|�}|��j�|VqdSrx)�
appendMessager��append)�mrW��mbox�messages�resultsr+r/r��s�
�z0_AppendTestMixin._appendMessages.<locals>.appendc��Srxr+��ignored)rr+r/�<lambda>��z2_AppendTestMixin._appendMessages.<locals>.<lambda>)r�	cooperate�whenDoner�)rVrrr�rWr+rr/�_appendMessages�s
z _AppendTestMixin._appendMessagesN)r\rqrrr�rr+r+r+r/r��sr�c@sJeZdZdZdd�Zdd�Zddd�Zeej	d	kd
�dd��Z
d
d�ZdS)�MaildirAppendStringTests�O
    Tests for L{MaildirMailbox.appendMessage} when invoked with a C{str}.
    cC�|��|_tj�|j�dSrx��mktemprWrr��initializeMaildirrbr+r+r/rz��
zMaildirAppendStringTests.setUpcCs|�d�}|�|t�S)N�TEST)r��
assertFailure�	Exception�rVrrrWr+r+r/�_append�s
z MaildirAppendStringTests._appendNcCsz|dur|�t|jd|jj�||j_|dur&|�t|jd|jj�||j_|dur;|�t|jd|jj�||j_dSdS)a�
        Change the behavior of future C{rename}, C{write}, or C{open} calls made
        by the mailbox C{mbox}.

        @param rename: If not L{None}, a new value for the C{_renamestate}
            attribute of the mailbox's append factory.  The original value will
            be restored at the end of the test.

        @param write: Like C{rename}, but for the C{_writestate} attribute.

        @param open: Like C{rename}, but for the C{_openstate} attribute.
        Nr�r�r�)�
addCleanup�setattr�
AppendFactoryr�r�r�)rVrrr�r�r�r+r+r/�	_setState�s,
����z"MaildirAppendStringTests._setStater&r(cCsVtj�|j�}t|_|�|dd�tdd�D��}|�|j	dgd�|�|j
|�|S)��
        L{MaildirMailbox.appendMessage} returns a L{Deferred} which fires when
        the message has been added to the end of the mailbox.
        cSsg|]}d|�qS)�Xr+�r-�ir+r+r/r4�sz8MaildirAppendStringTests.test_append.<locals>.<listcomp>rh�Nr*)rr��MaildirMailboxrWr�rrrAr�rC�
_cbTestAppend)rVrrWr+r+r/�test_append�sz$MaildirAppendStringTests.test_appendcs�|�t����d�|��fdd�td�D�ttdd���|jd�dd�|�d��}|j|j�d	dd
�|�|j��|j|j�d	dd�|�|j��|j|j�d	d�|S)
��
        Check that the mailbox has the expected number (ten) of messages in it,
        and that each has the expected contents, and that they are in the same
        order as that in which they were appended.
        r*c�g|]}t��|�����qSr+�rDr�r�r�rr+r/r4��z:MaildirAppendStringTests._cbTestAppend.<locals>.<listcomp>rhr!NF)r�T)r�r�)r�r�)r�)rCrDr�rArErrr�rr+r(r/r#�s �z&MaildirAppendStringTests._cbTestAppend)NNN)r\rqrrr�rzrrrrsrtr$r#r+r+r+r/r
�s
#

r
c@s8eZdZdZdd�Zeejdkd�dd��Zdd	�Z	d
S)�MaildirAppendFileTestsrcCrrxrrbr+r+r/rzrzMaildirAppendFileTests.setUpr&r(cCsxtj�|j�}g}tdd�D]}t��}|�d|�|�dd�|�	|�|�
|j�q|�||�}|�
|j|�|S)rrhr!rr)rr�r"rWrA�tempfile�
TemporaryFiler��seekr�rr�rr�r#)rVrrr �temprWr+r+r/r$	s
z"MaildirAppendFileTests.test_appendcs@|�t����d�|��fdd�td�D�ttdd���dS)r%r*cr&r+r'rr(r+r/r4$r)z8MaildirAppendFileTests._cbTestAppend.<locals>.<listcomp>rhr!N)rCrDr�rArE)rVr�rr+r(r/r#s �z$MaildirAppendFileTests._cbTestAppendN)
r\rqrrr�rzrrsrtr$r#r+r+r+r/r*�s
r*c@sDeZdZdd�Zdd�Zdd�Zdd�Zeej	d	kd
�dd��Z
d
S)�MaildirTestscCrrxrrbr+r+r/rz*rzMaildirTests.setUpcC�t�|j�dSrx)�shutil�rmtreerWrbr+r+r/r�.r{zMaildirTests.tearDowncCs�|j}tj�|d�}|�tj�|�otj�|��|�tj�tj�|d���|�tj�tj�|d���|�tj�tj�|d���|�tj�tj�|d���|�tj�tj�|d���|�tj�tj�|d���|�tj�tj�|d���|�tj�tj�|d���|�tj�tj�|d���|�tj�tj�|d���|�tj�tj�|d���|�tj�tj�|d���dS)N�.Trash�new�cur�tmp)rWr�r��joinrNr~�isdir)rVrW�trashr+r+r/�testInitializer1s zMaildirTests.testInitializercCsJt��}|�d�tj�|�}|��}|�d�|��}|�||k�dS)a
        Each call to L{_MaildirNameGenerator.generate} returns a unique
        string suitable for use as the basename of a new message file.  The
        names are ordered such that those generated earlier sort less than
        those generated later.
        g�������?N)r�Clock�advancerr��_MaildirNameGenerator�generaterN)rV�clock�	generator�	firstName�
secondNamer+r+r/�test_nameGeneratorDs

zMaildirTests.test_nameGeneratorr&r(c		s�tjj�tjj���fdd�dD�}d}|D]&}t�|j|�d��}|�d|�Wd�n1s3wY|d}qtj�	|j�}|�
|��tt
dd���|�
|�d�d	�|�
|�d
�d�|�
|�d���d�|�
|�d���d
�i}t
d�D]}|�|�}|�||v�d||<qtj�|d
�\}}|�d
�|�
|�d
�d�|�tj��|jdd|���|�tj��|j|d
���|��|�
|�d
�d�|�tj��|jdd|���|�tj��|j|d
���dS)zb
        Exercise the methods of L{IMailbox} as implemented by
        L{MaildirMailbox}.
        cs&g|]}td�D]}�|����qqS)�)rA)r-r=r.��j�nr+r/r4]s&z-MaildirTests.test_mailbox.<locals>.<listcomp>)r5r4rhr�r.Nr!r7rDr9�xxxxxxx�xxr*rr3r5)r�r�r7rr��_generateMaildirNamer�rWr�r"rCr�rErAr�r�r�r�r�r�rNr~r�)	rV�msgsr r��fObj�mbrW�u�pr+rEr/�test_mailboxUs:�



"zMaildirTests.test_mailboxN)r\rqrrrzr�r:rCrrsrtrPr+r+r+r/r/(sr/c@r�)�AbstractMaildirDomainTestszB
    Tests for L{twisted.mail.maildir.AbstractMaildirDomain}.
    cCsttjjtjj�dS)zW
        L{maildir.AbstractMaildirDomain} implements L{mail.IAliasableDomain}.
        N)rr�IAliasableDomainr��AbstractMaildirDomainrbr+r+r/�test_interface��z)AbstractMaildirDomainTests.test_interfaceN)r\rqrrr�rTr+r+r+r/rQ�srQc@s�eZdZdZdd�Zdd�Zeejdkd�dd	��Z	d
d�Z
eejdkd�dd
��Zeejdkd�dd��Zeejdkd�dd��Z
dS)�MaildirDirdbmDomainTestsz+
    Tests for L{MaildirDirdbmDomain}.
    cCs.|��|_tj��|_tj�|j|j�|_dS)zw
        Create a temporary L{MaildirDirdbmDomain} and parent
        L{MailService} before running each test.
        N)r�Prr��Sr��MaildirDirdbmDomain�Drbr+r+r/rz�s
zMaildirDirdbmDomainTests.setUpcCst�|j�dS)z_
        Remove the temporary C{maildir} directory when the test has
        finished.
        N)r1r2rWrbr+r+r/r��sz!MaildirDirdbmDomainTests.tearDownr&r(c	Csvd}|D]\}}|j�||�q|D]&\}}|�||jjv�|�|jj||�|�tj�tj�|j	|���qdS)z�
        L{MaildirDirdbmDomain.addUser} accepts a user and password
        argument. It stores those in a C{dbm} dictionary
        attribute and creates a directory for each user.
        ))�user1�pwd1)�user2�pwd2)�user3�pwd3N)
rZr�rN�dbmrCr�r�r~r7rW)rV�toAddrNrOr+r+r/�test_addUser�s �z%MaildirDirdbmDomainTests.test_addUsercCsN|j��}|�t|�d�|�tjj�|d��|�tj	j
|djv�dS)z�
        L{MaildirDirdbmDomain.getCredentialsCheckers} initializes and
        returns one L{ICredentialsChecker} checker by default.
        rhrN)rZ�getCredentialsCheckersrCrDrNr�checkers�ICredentialsChecker�
providedBy�credentials�IUsernamePassword�credentialInterfaces)rV�credsr+r+r/�test_credentials�s
�z)MaildirDirdbmDomainTests.test_credentialscCs�Gdd�dt�}|j�dd�|�t|jjdd|�|j�ddtj�}|�t	|�d�|�
|dtju�|�
tj�|d��|d	�dS)
a?
        L{MaildirDirdbmDomain.requestAvatar} raises L{NotImplementedError}
        unless it is supplied with an L{pop3.IMailbox} interface.
        When called with an L{pop3.IMailbox}, it returns a 3-tuple
        containing L{pop3.IMailbox}, an implementation of that interface
        and a NOOP callable.
        c@seZdZdS)z?MaildirDirdbmDomainTests.test_requestAvatar.<locals>.ISomethingN)r\rqrrr+r+r+r/�
ISomething�srm�userr�Nr'rrhr7)rrZr�r|�NotImplementedError�
requestAvatarr�IMailboxrCrDrNrg)rVrm�tr+r+r/�test_requestAvatar�s
�z+MaildirDirdbmDomainTests.test_requestAvatarcCsb|j�dd�|j��d}tj�dd�}|�tjj|j	|�tj�dd�}|�
|�	|�d�dS)a
        L{DirdbmDatabase.requestAvatarId} raises L{UnauthorizedLogin} if
        supplied with invalid user credentials.
        When called with valid credentials, L{requestAvatarId} returns
        the username associated with the supplied credentials.
        rnr�r�wrong passwordN)rZr�rdrrh�UsernamePasswordr|�error�UnauthorizedLogin�requestAvatarIdrC)rV�databaserkr+r+r/�test_requestAvatarId�sz-MaildirDirdbmDomainTests.test_requestAvatarIdcCsz|j�dd�|�|j�d�tj�|jjd��d|j_|�	|j�d�d�d|j_|�|j�d�tj�|jjd��dS)a]
        L{MaildirDirdbmDomain.userDirectory} is supplied with a user name
        and returns the path to that user's maildir subdirectory.
        Calling L{MaildirDirdbmDomain.userDirectory} with a
        non-existent user returns the 'postmaster' directory if there
        is a postmaster or returns L{None} if there is no postmaster.
        rnr�F�nouserNT�
postmaster)
rZr�rC�
userDirectoryr�r�r7�rootr|�assertIdenticalrbr+r+r/�test_userDirectory�s	��z+MaildirDirdbmDomainTests.test_userDirectoryN)r\rqrrr�rzr�rrsrtrcrlrsrzr�r+r+r+r/rV�s	


rVc@s2eZdZdZddd�Zdd�Zdd�Zd	d
�ZdS)�StubAliasableDomainz>
    Minimal testable implementation of IAliasableDomain.
    NcC�t���z{
        No test coverage for invocations of this method on domain objects,
        so we just won't implement it.
        �ro�rVrn�memor+r+r/r~�zStubAliasableDomain.existscCr�r�r�)rVrnr�r+r+r/r�r�zStubAliasableDomain.addUsercCsgS)a!
        This needs to succeed in order for other tests to complete
        successfully, but we don't actually assert anything about its
        behavior.  Return an empty list.  Sometime later we should return
        something else and assert that a portal got set up properly.
        r+rbr+r+r/rd�z*StubAliasableDomain.getCredentialsCheckerscC�
||_dS)zG
        Just record the value so the test can check it later.
        N)�
aliasGroup)rV�aliasesr+r+r/�
setAliasGroups
z!StubAliasableDomain.setAliasGrouprx)r\rqrrr�r~r�rdr�r+r+r+r/r�s
	r�c@steZdZdd�Zdd�Zdd�Zeejdkd�d	d
��Z	eejdkd�dd��Z
d
d�Zdd�Zdd�Z
dd�ZdS)�ServiceDomainTestscCsrtj��|_tj�|jd�|_|j|j_d|j_d|j_|�	�|_
tj�|j|j
�}|�
dd�|j�d|�dS)Nr�hostname�user�password�test.domain)rr�rXr��DomainDeliveryBaserZr��protocolName�hostr�tmpdirr�rYr�r��rVr_r+r+r/rz(s

zServiceDomainTests.setUpcCr0rx�r1r2r�rbr+r+r/r�4r{zServiceDomainTests.tearDowncCs4t�}t�}||j_|j�d|�|�|j|�dS)z�
        Test that adding an IAliasableDomain to a mail service properly sets
        up alias group references and such.
        �example.comN)r�r�rXr�r�rr�)rVr�r_r+r+r/�testAddAliasableDomain7s
z)ServiceDomainTests.testAddAliasableDomainr&r(cCsZ|j�dt�d�dg�}t�|�}tj��}|�	|�}|�
t|���d�|�
d|�dS)N)�
remotehostz123.232.101.234z<someguy@someplace>zuser@host.namerh�Received)rZ�receivedHeaderr�Address�io�BytesIO�email�parser�Parser�parserCrDrKrZ)rV�hdrr��emailParserrr+r+r/�testReceivedHeaderBs�


z%ServiceDomainTests.testReceivedHeadercCs(t�dddd�}t�|jj|��|j�S)Nzuser@test.domain�helo�wherever@whatever)r�Userr
�
maybeDeferredrZ�
validateTor��
_cbValidateTo�rVrnr+r+r/�testValidateToOs�z!ServiceDomainTests.testValidateTocCs|�t|��dSrx)rN�callabler�r+r+r/r�Vr�z ServiceDomainTests._cbValidateTocC�*t�dddd�}|�t�|jj|�tj�S)Nzresu@test.domainr�r��rr�rr
r�rZr�r�r�r+r+r/�testValidateToBadUsernameY��z,ServiceDomainTests.testValidateToBadUsernamecCr�)Nzuser@domain.testr�r�r�r�r+r+r/�testValidateToBadDomain_r�z*ServiceDomainTests.testValidateToBadDomaincCs�d}t�d�}|�|j�||�|u�d}t�d�}|�|j�||�|u�d}t�d�}|�|j�||�|u�|�tj|jjd|�dS)N)r�r�z<user@hostname>)r��1.2.3.4z<>)rr�rNrZ�validateFromr|�
SMTPBadSender)rVr��originr+r+r/�testValidateFromes


z#ServiceDomainTests.testValidateFromN)r\rqrrrzr�r�rrsrtr�r�r�r�r�r�r+r+r+r/r�&s

r�c@s�eZdZdd�Zdd�Zeejdkd�dd��Zd	d
�Z	eejdkd�dd��Z
eejdkd�d
d��Zeejdkd�dd��Zdd�Z
eejdkd�dd��Zeejdkd�dd��ZdS)�VirtualPOP3TestscCs�|��|_tj��|_tj�|j|j�|_|j�dd�|j�	d|j�t
j�|j�}t
|j|j���||jjd<|jjd<tj��|_|j|j_d|j_dS)Nr�r�r�r�z<unit test magic>)rr�rr�rXr�rYrZr�r�r�portal�Portal�map�registerCheckerrdr�r��VirtualPOP3rWr��magic)rVr�r+r+r/rzws

zVirtualPOP3Tests.setUpcCr0rxr�rbr+r+r/r��r{zVirtualPOP3Tests.tearDownr&r(cCs*t|jjd���}|j�d|��|j�S)Nr�rn)rrWr��	hexdigest�authenticateUserAPOPr��_cbAuthenticateAPOP�rV�respr+r+r/�testAuthenticateAPOP�s�z%VirtualPOP3Tests.testAuthenticateAPOPcC�F|�t|�d�|�|dtj�|�tj�|d��|d�dS�Nr'rrhr7�rCrDrrqrNrgr�r+r+r/r���z$VirtualPOP3Tests._cbAuthenticateAPOPcCs.t|jjd���}|�|j�d|�tjj�S)Nr��resu)	rrWr�r�rr�rrvrwr�r+r+r/�!testAuthenticateIncorrectUserAPOP�s�z2VirtualPOP3Tests.testAuthenticateIncorrectUserAPOPcCs&td���}|�|j�d|�tjj�S)Nzwrong digestrn)rr�rrWr�rrvrwr�r+r+r/�%testAuthenticateIncorrectResponseAPOP�s�z6VirtualPOP3Tests.testAuthenticateIncorrectResponseAPOPcCs|j�dd��|j�S)Nrnr�)rW�authenticateUserPASSr��_cbAuthenticatePASSrbr+r+r/�testAuthenticatePASS�s�z%VirtualPOP3Tests.testAuthenticatePASScCr�r�r�r�r+r+r/r��r�z$VirtualPOP3Tests._cbAuthenticatePASScC�|�|j�dd�tjj�S)Nr�r��rrWr�rrvrwrbr+r+r/�testAuthenticateBadUserPASS���z,VirtualPOP3Tests.testAuthenticateBadUserPASScCr�)Nrnrtr�rbr+r+r/�testAuthenticateBadPasswordPASS�r�z0VirtualPOP3Tests.testAuthenticateBadPasswordPASSN)r\rqrrrzr�rrsrtr�r�r�r�r�r�r�r�r+r+r+r/r�us"




r�c@seZdZdd�ZdS)�emptycCsdSrxr+rbr+r+r/�__init__�szempty.__init__N)r\rqrrr�r+r+r+r/r��sr�c@s$eZdZeejdkd�dd��ZdS)�
RelayTestsr&r(cs�tj��}tj�|�}t�d�t�ddd�g}t�ddd�t�ddd�g}|D]'�t�}d	|_d
|_	t�|_
t�|j
_�fdd�|j
j_|�
t|�|���q'|D]&�t�}d
|_t�|_
t�|j
_�fdd�|j
j_d|_	|�tj|j|�qQdS)Nz/var/run/mail-relay�TCPr�r�z192.168.2.1�>r�i�z	user@hostz	tsoh@resucrrxr+r+��peerr+r/r�r	z'RelayTests.testExists.<locals>.<lambda>z
some@placecrrxr+r+r�r+r/r�r	z	who@cares)rr��relay�DomainQueuerr	�UNIXAddress�IPv4Addressr��orig�destrr��getPeerrNr�r~r|rr�)rVr�r_�doRelay�	dontRelayrnr+r�r/r�s2
��

�zRelayTests.testExistsN)r\rqrrrrsrtrr+r+r+r/r��sr�c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�RelayerTestsc	Cs�|��|_t�|j�g|_td�D]J}tj�|jd|f�}t|dd��}t	�
d|fd|fg|�Wd�n1s?wYt|dd�}|�|�|�d	d	�|j�
|�qtj��|_|j�|j�dS)
Nr*�body-%d�-H�wb�from-%d�to-%d�-Dr�r)rr�r��mkdir�messageFilesrAr�r7r��pickle�dumpr�r-r�rr��RelayerMixin�R�loadMessages)rVr r�r�r+r+r/rz�s
�
zRelayerTests.setUpcCr0rxr�rbr+r+r/r��r{zRelayerTests.tearDowncCsPtd�D]}|�|j��d|f�|j�ddddd�q|�|j��d�dS)Nr*r��)rArCr��getMailFrom�sentMail�rVr r+r+r/�testMailFromszRelayerTests.testMailFromcCsRtd�D]}|�|j��d|fg�|j�ddddd�q|�|j��d�dS)Nr*r�r�)rArCr��	getMailTor�r�r+r+r/�
testMailToszRelayerTests.testMailTocCsdtd�D]"}tj�|jd|f�}|�|j����|�|j�	ddddd�q|�|j��d�dS)Nr*r�r�)
rAr�r�r7r�rCr��getMailDatar�r�)rVr r�r+r+r/�testMailDatas
zRelayerTests.testMailDataN)r\rqrrrzr�r�r�r�r+r+r+r/r��sr�c@ru)
�ManagercCsg|_g|_g|_dSrx)�successr�donerbr+r+r/r��
zManager.__init__cC�|j�||f�dSrx)r�r��rVr�rjr+r+r/�
notifySuccess�zManager.notifySuccesscCrrx)rr�rr+r+r/�
notifyFailurerzManager.notifyFailurecC�|j�|�dSrx)r�r�)rVr�r+r+r/�
notifyDone r{zManager.notifyDoneN)r\rqrrr�rrrr+r+r+r/r�s
r�c@ru)
�ManagedRelayerTestscCsdt�|_ttddd��|_t�|_tj�	|j�|_
|jdd�|j
_|jdd�|j
_|j|j
_dS)Nrr6r7)r��managerrErArr�r�r�relaymanager�ManagedRelayerMixinr��namesrbr+r+r/rz&szManagedRelayerTests.setUpc�D�jD]}�j�ddddd�q���jj�fdd��jD��dS)Nr�c�g|]}�j|f�qSr+�r��r-rrbr+r/r44r1z>ManagedRelayerTests.testSuccessfulSentMail.<locals>.<listcomp>)rr�r�rCr	r�r�r+rbr/�testSuccessfulSentMail/�

�z*ManagedRelayerTests.testSuccessfulSentMailcr
)Ni&crr+rrrbr+r/r4<r1z:ManagedRelayerTests.testFailedSentMail.<locals>.<listcomp>)rr�r�rCr	rr�r+rbr/�testFailedSentMail7rz&ManagedRelayerTests.testFailedSentMailcCs,|j�t�t���|�|jj|jg�dSrx)	r�r�r�FailurerrCr	r�r�rbr+r+r/�testConnectionLost?sz&ManagedRelayerTests.testConnectionLostN)r\rqrrrzrrrr+r+r+r/r$s
	rc@sleZdZdd�Zdd�Zeejdkd�dd��Zeejdkd�d	d
��Z	eejdkd�dd��Z
d
d�ZdS)�DirectoryQueueTestsc	Cs�|��|_t�|j�tj�|j�|_d|j_t	d�D]/}|j�
�\}}|�t�d|g|�Wd�n1s9wY|�
d|f�|��q|j��dS)NF��headersbody: %d)rr�r�r�rr
�Queue�queue�noisyrA�createNewMessager�r�r�r��
readDirectory)rVr�hdrF�msgFr+r+r/rzFs
�
zDirectoryQueueTests.setUpcCr0rxr�rbr+r+r/r�Tr{zDirectoryQueueTests.tearDownr&r(cCs�|�|j���|�t|j���d�|j��}|j�|d�|�t|j���d�|j�|d�|�t|j���d�dS)Nrr�)rNr�
hasWaitingrCrD�
getWaiting�setRelaying�
setWaiting)rV�waitingr+r+r/�testWaitingWs
zDirectoryQueueTests.testWaitingcCs�|j��D]}|j�|�|�t|j���dt|j����q|�|j���|j��}|j�|d�|�t|j���d�|�t|j���d�dS)Nrrrhr )	rr"r#rCrD�
getRelayedr�r!r$)rVr�relayedr+r+r/�testRelayingcs�
z DirectoryQueueTests.testRelayingcCs~|j��d}|j�|�|j�|�|�t|j���d�|�t|j���d�|�||j��v�|�||j��v�dS)Nrr )rr"r#r�rCrDr'r�)rV�msgr+r+r/�testDonerszDirectoryQueueTests.testDonecCsVg}|j��D]}|�|j�|��q|��td�D]
}|�|�d�d|g�qdS)Nrrr)rr"r��getEnveloperIrArC�pop)rV�	envelopesr*r r+r+r/�testEnvelope~s�z DirectoryQueueTests.testEnvelopeN)r\rqrrrzr�rrsrtr&r)r+r/r+r+r+r/rDs


r)�client�common�serverc@�eZdZdd�Zddd�ZdS)�
TestAuthoritycCstj�|�i|_dSrx)r1�ResolverBaser��	addressesrbr+r+r/r��s
zTestAuthority.__init__NcCsv||jvr0|tjkr0g}|j|D]}t�|tjtjdt�d|��}|�|�qt�|ggf�St�	t
�t�|���S)N�<r)
r6r�MXr�INrr�r
�succeed�failrr�DomainError)rVr��cls�type�timeoutrr<r�r+r+r/�_lookup�szTestAuthority._lookuprx)r\rqrrr�r@r+r+r+r/r4��r4cCs�t�|_t�|jg�}t�|�}	tjd|dd�|_|j�	�j}ztj
||dd�|_Wnty9|j�
�Ynwnqtjd|fgd�|_dS)Nrhrr���	interface)�servers)r4�authr2�DNSServerFactoryr�DNSDatagramProtocolr
�	listenTCP�port�getHost�	listenUDP�udpPortr�
stopListeningr0�Resolver�resolver)rVr�r�
portNumberr+r+r/�setUpDNS�s 
���rQcCsZg}|�t�|jj��|�t�|jj��z|jj��Wn	t	y'Ynwt�
|�Srx)r�r
r�rIrMrLrO�
_parseCall�cancelr��DeferredList)rV�dlr+r+r/�tearDownDNS�s�
rVc@s�eZdZdZdd�Zdd�Zdd�Zeej	dkd	�d
d��Z
dd
�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zeej	dkd	�d*d+��Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4S)5�MXTestsz6
    Tests for L{mail.relaymanager.MXCalculator}.
    cCs*t|�t��|_tj�|j|j�|_dSrx)	rQrr;r?rr
�MXCalculatorrO�mxrbr+r+r/rz�s
z
MXTests.setUpcCst|�Srx)rVrbr+r+r/r��szMXTests.tearDowncCs|�tj�|j�jt�dS)zQ
        L{MXCalculator}'s default clock is C{twisted.internet.reactor}.
        N)rrr
rXrOr?r
rbr+r+r/�test_defaultClock�s�zMXTests.test_defaultClockr&r(cCs"dg|jjd<|j�d��|j�S)N�the.email.test.domainr�)rEr6rY�getMXr��_cbSimpleSuccessrbr+r+r/�testSimpleSuccess�szMXTests.testSimpleSuccesscCs$|�|jd�|�t|j�d�dS)Nrr[)rC�
preferencer]r��rVrYr+r+r/r]�szMXTests._cbSimpleSuccesscCsd|j_|�|j�d�t�S)NFr�)rY�fallbackToDomainrr\�IOErrorrbr+r+r/�testSimpleFailure�szMXTests.testSimpleFailurecCs|�|j�d�t�S�Nr�)rrYr\rrbr+r+r/�testSimpleFailureWithFallback�rz%MXTests.testSimpleFailureWithFallbackcsFG��fdd�d�}|��j_�j���}��fdd�}|�|�|S)aZ
        Issue an MX request for the given domain and arrange for it to be
        responded to with the given records.  Verify that the resulting mail
        exchange is the indicated host.

        @type domain: C{str}
        @type records: C{list} of L{RRHeader}
        @type correctMailExchange: C{str}
        @rtype: L{Deferred}
        c�eZdZ��fdd�ZdS)z,MXTests._exchangeTest.<locals>.DummyResolvercs&|�krt��ggf�St�t���Srx)r
r:r;r)rVr��r_�recordsr+r/�lookupMailExchange�sz?MXTests._exchangeTest.<locals>.DummyResolver.lookupMailExchangeN�r\rqrrrir+rgr+r/�
DummyResolver��rkcs��t|j���dSrx�rCr]r�)�record)�correctMailExchangerVr+r/�gotMailExchange�sz.MXTests._exchangeTest.<locals>.gotMailExchange)rYrOr\r�)rVr_rhrorkrWrpr+)ror_rhrVr/�
_exchangeTest�s

zMXTests._exchangeTestcCsZd}d}d}t|tjtd|�d�t|tjtd|�d�t|tjtd|�d�g}|�|||�S)zh
        The MX record with the lowest preference is returned by
        L{MXCalculator.getMX}.
        r��good.example.com�bad.example.comrh�r�r>�payloadrr7)rr�TYPErq�rVr_�good�badrhr+r+r/�test_mailExchangePreference�s�z#MXTests.test_mailExchangePreferencecCsRd}d}d}t|tjtd|�d�t|tjtd|�d�g}|j�|�|�|||�S)z�
        L{MXCalculator.getMX} returns the MX record with the lowest preference
        which is not also marked as bad.
        r�rrrsrrtrh�rrrvrY�markBadrqrwr+r+r/�test_badExchangeExcluded
s�z MXTests.test_badExchangeExcludedcCs^d}d}d}t|tjtd|�d�t|tjtd|�d�g}|j�|�|j�|�|�|||�S)z�
        L{MXCalculator.getMX} returns the MX record with the lowest preference
        if all the MX records in the response have been marked bad.
        r�rszworse.example.comrrtrhr{)rVr_ry�worserhr+r+r/�test_fallbackForAllBadExchangess�z'MXTests.test_fallbackForAllBadExchangescCsbd}d}d}t|tjtd|�d�t|tjtd|�d�g}|j�|�|j�|jj�|�|||�S)z�
        L{MXCalculator.getMX} returns the MX record with the lowest preference
        if it was last marked bad longer than L{MXCalculator.timeOutBadMX}
        seconds ago.
        r�rrrsrrtrh)	rrrvrYr|r?r<�timeOutBadMXrq�rVr_rx�
previouslyBadrhr+r+r/�test_badExchangeExpires+s��zMXTests.test_badExchangeExpirescCsnd}d}d}t|tjtd|�d�t|tjtd|�d�g}|j�|�|j�|�|j�|jj�|�	|||�S)z�
        L{MXCalculator.getMX} returns the MX record with the lowest preference
        if it was marked good after it was marked bad.
        r�rrrsrrtrh)
rrrvrYr|�markGoodr?r<r�rqr�r+r+r/�test_goodExchangeUsed?s��zMXTests.test_goodExchangeUsedcsJd�d�G��fdd�d�}|�|j_|j���}|�|jt�d��|S)z�
        If an MX lookup succeeds but the result set is empty,
        L{MXCalculator.getMX} should try to look up an I{A} record for the
        requested name and call back its returned Deferred with that
        address.
        r�zexample.orgcs6eZdZdZ�gggfiZ��iZdd�Zdd�ZdS)z9MXTests.test_successWithoutResults.<locals>.DummyResolverah
            Fake resolver which will respond to an MX lookup with an empty
            result set.

            @ivar mx: A dictionary mapping hostnames to three-tuples of
                results to be returned from I{MX} lookups.

            @ivar a: A dictionary mapping hostnames to addresses to be
                returned from I{A} lookups.
            cS�t�|j|�Srx)r
r:rYr�r+r+r/rilr{zLMXTests.test_successWithoutResults.<locals>.DummyResolver.lookupMailExchangecSr�rx)r
r:r<r�r+r+r/�
getHostByNameor{zGMXTests.test_successWithoutResults.<locals>.DummyResolver.getHostByNameN)r\rqrrr�rYr<rir�r+�r_�ipr+r/rk]srk�r��rYrOr\r�rCr�rVrkrWr+r�r/�test_successWithoutResultsSs
z"MXTests.test_successWithoutResultscCs<Gdd�d�}|�|j_|j�d�}|�|jtdd��|S)a'
        Test that if the MX record lookup fails, fallback is enabled, and an A
        record is available for the name, then the Deferred returned by
        L{MXCalculator.getMX} ultimately fires with a Record_MX instance which
        gives the address in the A record for the name.
        c@s eZdZdZdd�Zdd�ZdS)zAMXTests.test_failureWithSuccessfulFallback.<locals>.DummyResolverzw
            Fake resolver which will fail an MX lookup but then succeed a
            getHostByName call.
            cSst�t��Srx)r
r;rr�r+r+r/ri�szTMXTests.test_failureWithSuccessfulFallback.<locals>.DummyResolver.lookupMailExchangecSs
t�d�S)Nr�)r
r:r�r+r+r/r���
zOMXTests.test_failureWithSuccessfulFallback.<locals>.DummyResolver.getHostByNameN)r\rqrrr�rir�r+r+r+r/rksrkr_r�r�r�r�r+r+r/�"test_failureWithSuccessfulFallbackws

z*MXTests.test_failureWithSuccessfulFallbackcsPd�d�d�G���fdd�d�}|�|j_|j���}|�|jt�d��|S)z�
        If an MX lookup returns a single CNAME record as a result, MXCalculator
        will perform an MX lookup for the canonical name indicated and return
        the MX record which results.
        �alias.example.com�canonical.example.com�mail.example.comcs eZdZdZ���fdd�ZdS)z;MXTests.test_cnameWithoutGlueRecords.<locals>.DummyResolverz�
            Fake resolver which will return a CNAME for an MX lookup of a name
            which is an alias and an MX for an MX lookup of the canonical name.
            csd|�krt�t|tjt��d�gggf�S|�kr+t�t|tjtd��d�gggf�St�t|��S)Nrtr)r
r:rrrvrr;rr���alias�	canonical�exchanger+r/ri�s2����
����zNMXTests.test_cnameWithoutGlueRecords.<locals>.DummyResolver.lookupMailExchangeN)r\rqrrr�rir+r�r+r/rk�srkr�r�r�r+r�r/�test_cnameWithoutGlueRecords�s
&z$MXTests.test_cnameWithoutGlueRecordscsXGdd�d�}d�|��j_�j�d��}��|tjjj���fdd�}|�|�|S)z�
        If L{MXCalculator.getMX} encounters a CNAME chain which is longer than
        the length specified, the returned L{Deferred} should errback with
        L{CanonicalNameChainTooLong}.
        c@seZdZdZdZdd�ZdS)z.MXTests.test_cnameChain.<locals>.DummyResolverz
            Fake resolver which generates a CNAME chain of infinite length in
            response to MX lookups.
            rcSs<|jd7_d|jf}t�t|tjt|�d�gggf�S)Nrh�x-%d.example.comrt)�chainCounterr
r:rrrv)rVr_r�r+r+r/ri�s����zAMXTests.test_cnameChain.<locals>.DummyResolver.lookupMailExchangeN)r\rqrrr�r�rir+r+r+r/rk�srkr'r�cs:��|jdtd�df�����jjj�d�dS)Nrr�rh)rC�argsrrYrOr�)rv��
cnameLimitrVr+r/�cbChainTooLong�s�z/MXTests.test_cnameChain.<locals>.cbChainTooLong)	rYrOr\r�twistedrr
�CanonicalNameChainTooLongr�)rVrkrWr�r+r�r/�test_cnameChain�s

zMXTests.test_cnameChaincsVg�d�d�d�G����fdd�d�}|�|j_|j���}|�|jt�d��|S)z�
        If an MX lookup returns a CNAME and the MX record for the CNAME, the
        L{Deferred} returned by L{MXCalculator.getMX} should be called back
        with the name from the MX record without further lookups being
        attempted.
        r�r�r�cseZdZ����fdd�ZdS)z8MXTests.test_cnameWithGlueRecords.<locals>.DummyResolverc	sL|�ks�rgggfSt�t�tjt��d�t�tjt�d�d�gggf�S)Nrtr�)r
r:rrrvrr��r�r�r��lookedUpr+r/ris$
�����zKMXTests.test_cnameWithGlueRecords.<locals>.DummyResolver.lookupMailExchangeNrjr+r�r+r/rk�srkr�r�r�r+r�r/�test_cnameWithGlueRecords�s
z!MXTests.test_cnameWithGlueRecordscsHd�d�G��fdd�d�}|�|j_|j���}|�|tjjj�|S)z�
        If an MX lookup returns two CNAME records which point to each other,
        the loop should be detected and the L{Deferred} returned by
        L{MXCalculator.getMX} should be errbacked with L{CanonicalNameLoop}.
        zcname1.example.comzcname2.example.comcrf)z<MXTests.test_cnameLoopWithGlueRecords.<locals>.DummyResolvercs4t�t�tjt��d�t�tjt��d�gggf�S)Nrt)r
r:rrrvr���
firstAlias�secondAliasr+r/ri's �����zOMXTests.test_cnameLoopWithGlueRecords.<locals>.DummyResolver.lookupMailExchangeNrjr+r�r+r/rk&rlrk)rYrOr\rr�rr
�CanonicalNameLoopr�r+r�r/�test_cnameLoopWithGlueRecordss
z%MXTests.test_cnameLoopWithGlueRecordscCs$gd�|jjd<|j�d��|j�S)N)zmx1.test.domainzmx2.test.domainzmx3.test.domainr�)rEr6rYr\r��_cbManyRecordsSuccessfulLookuprbr+r+r/�testManyRecords@s�zMXTests.testManyRecordscCsH|�t|j��dd�ddv�|j�t|j��|j�d��|j|�S)N�.rhr)�mx1�mx2�mx3r�)	rNr]r�r�rYr|r\r��_cbManyRecordsDifferentResultr`r+r+r/r�Ks
 �z&MXTests._cbManyRecordsSuccessfulLookupcCsB|�t|j�t|j��|j�t|j��|j�d��|j||�Srd)r�r]r�rYr|r\r��_cbManyRecordsLastResult)rV�nextMXrYr+r+r/r�Rs
�z%MXTests._cbManyRecordsDifferentResultcCsj|�t|j�t|j��|�t|j�t|j��|j�t|j��|j�t|j��|j�d��|j|�Srd)	r�r]r�rYr|r�r\r��"_cbManyRecordsRepeatSpecificResult)rV�lastMXrYr�r+r+r/r�Zs�z MXTests._cbManyRecordsLastResultcCs|�t|j�t|j��dSrxrm)rV�againMXr�r+r+r/r�esz*MXTests._cbManyRecordsRepeatSpecificResultN)r\rqrrr�rzr�rZrrsrtr^r]rcrerqrzr}rr�r�r�r�r�r�r�r�r�r�r�r�r�r+r+r+r/rW�s8
$5.*#

rWc@s`eZdZe�ed�durdZdd�Zdd�Ze	e
jdkd�d	d
��Ze	e
jdkd�dd��Z
dS)
�LiveFireExerciseTestsNz1UDP support is required to determining MX recordscCst|�gd�|_dS)N)�	domainDir�insertionDomain�insertionQueue�destinationDomain�destinationQueue)rQ�tmpdirsrbr+r+r/rznszLiveFireExerciseTests.setUpcCs*|jD]
}tj�|�rt�|�qt|�Srx)r�r�r�r~r1r2rV)rVrWr+r+r/r�xs


�zLiveFireExerciseTests.tearDownr&r(cs�tj��}|j�tj���tj�|d����	dd�|�
d��|jd|jd<t|jdj��
��|�tj�|��|��}tjd|dd��_tgd	���t��t��}�fd
d�|_�fdd�|_t�d�j��j|���fd
d�}��|��S)Nr�rnr�r�r�rr�rB)�
HELO mesonzMAIL FROM: <user@hostname>zRCPT TO: <user@test.domain>�DATA�This is the messager��QUITcrrxr+r+�r0r+r/r�r	z9LiveFireExerciseTests.testLocalDelivery.<locals>.<lambda>c�
��d�Srx��callback�r��r�r+r/r��
cs>��ddtj�d}|�d���}��|�d�d��j��S�Nrnrhrr����)	rprrqr�r�r��find�
smtpServerrM��ignrr*)r_rVr+r/�finished�s
z9LiveFireExerciseTests.testLocalDelivery.<locals>.finished)rr��
smtpPortalr�rre�AllowAnonymousAccessr�rYr�r�r�r�rd�setQueuer�r�r�r
rHr�r rr�
ClientFactory�clientConnectionLost�
connectTCPrJrIr�)rVr�r�r�r+)r0r_r�rVr/�testLocalDelivery~s*
�
z'LiveFireExerciseTests.testLocalDeliverycs�tj��}|j�tj���tj�|d��|�	d��t
�d�|�tj
�d��|j�tj�|��tj
�|j���jd7_tj
��d��tj
��j��_dg�jjd<|��}tjd|dd	��_tj��}|j�tj���tj�|d
���� dd�|�	d��t
�d
�|�tj
�d
��tj
��d����!�|��}tjd|dd	��_"�j"�#�j$�_%t&gd���t'��t(�)�}�fdd�|_(�fdd�|_*t�+d�j�#�j$|�����fdd�}��,|��S)Nr�zinsertion.domainr�)ztest.identity.hostnamerhr�zdestination.domainrrBr�rnr�r�)r�zMAIL FROM: <user@wherever>z"RCPT TO: <user@destination.domain>r�r�r�r�crrxr+r+r�r+r/r�r	z9LiveFireExerciseTests.testRelayDelivery.<locals>.<lambda>cr�rxr�r�r�r+r/r�r�cs&���}���fdd�}|�|�|S)NcsT��ddtj�d}|�d���}��|�d�d��j���j	����
�dSr�)rprrqr�r�r�r��	insServerrM�
destServer�stopServicer�)r_�helperrVr+r/�	delivered�s

zLLiveFireExerciseTests.testRelayDelivery.<locals>.finished.<locals>.delivered)�
checkStater�)r�r�r�)r_r�r	rVr+r/r��s
	z9LiveFireExerciseTests.testRelayDelivery.<locals>.finished)-rr�r�r�rrer�r�rYr�r�r�r�r
rrT�setDefaultDomainr�r��SmartHostSMTPRelayingManagerr�fArgs�RelayStateHelperrXrO�mxcalcrEr6r�r
rHr�r��startServicer�rJrI�PORTr rrr�r�r�r�)rV�insServr��destServr�r+)r0r_r�r�r	rVr/�testRelayDelivery�sJ



�
z'LiveFireExerciseTests.testRelayDelivery)r\rqrrr�IReactorUDPr
�skiprzr�rrsrtr�r�r+r+r+r/r�is

+r�c@ru)
�LineBufferMessagecCsg|_d|_d|_dS)NF)�lines�eom�lostrbr+r+r/r��rzLineBufferMessage.__init__cCrrx)r�r�)rVr�r+r+r/r��r{zLineBufferMessage.lineReceivedcCsd|_t�d�S)NTz
<Whatever>)r�r
r:rbr+r+r/r��
zLineBufferMessage.eomReceivedcCs
d|_dS)NT)r�rbr+r+r/r�r�z LineBufferMessage.connectionLostN)r\rqrrr�r�r�r�r+r+r+r/r��s
r�c@sdeZdZgd�Zdd�Zeejdkd�dd��Zdd	�Z	d
d�Z
eejdkd�dd
��Zdd�ZdS)�
AliasTests�z
First linez	Next liner�zAfter a blank linez	Last linecCsxi}gd�}|D]}tj�||dd�q|�|dddg�|�|ddg�|�|dd	g�|�|d
gd��dS)N)zuser:  another@host
znextuser:  |/bin/program
zuser:  me@again
z"moreusers: :/etc/include/filename
z3multiuser: first@host, second@host,last@anotherhostr#rnzanother@hostzme@again�nextuserz
|/bin/program�	moreusersz:/etc/include/filename�	multiuser)z
first@hostzsecond@hostzlast@anotherhost)rr��handlerC)rVr�r��lr+r+r/�
testHandles�zAliasTests.testHandler&r(cCs
dt�i}tjj|t�t�d����d�}|�	t
|�d�|d}t|�}dD]}|�|�
|�d�q'|�	t
|�d�|d	}t|�}d
D]}|�|�
|�d�qE|�	t
|�d�|d}t|�}|�	|�
d�d�d
D]}|�|�
|�dd|�ql|�	t
|�d�dS)Nr�a�                    # Here's a comment
                       # woop another one
                    testuser:                   address1,address2, address3,
                        continuation@address, |/bin/process/this

                    usertwo:thisaddress,thataddress, lastaddress
                    lastuser:       :/includable, /filename, |/program, address
                    )r�r'�testuser)�address1�address2�address3zcontinuation@addressz/bin/process/thisr�rD�usertwo)�thisaddress�thataddress�lastaddress�lastuserz/includable)z	/filename�programr	z%s not found)r�rr��
loadAliasFiler�r��textwrap�dedent�encoderCrDr]r�r�)rVrTr��group�sr<r+r+r/�testFileLoader"s6
�
��zAliasTests.testFileLoadercCsDt�t�t�f}tj�|�}|jD]}|�|�q|���|j|�Srx)	r�rr��MultiWrapperr�r�r�r��_cbMultiWrapper)rVrKr*�Lr+r+r/�testMultiWrapperQs

zAliasTests.testMultiWrappercCs6|D]}|�|j�|�|j�|�|j|j�qdSrx)rNr�r�r�rCr�)rVrrKrr+r+r/rYs
�zAliasTests._cbMultiWrappercCsH|��}tj�|dd�}|��}|jD]}|�|�q|���|j	|�Srx)
rrr��	FileAlias�createMessageReceiverr�r�r�r��_cbTestFileAlias)rV�tmpfiler<rr�r+r+r/�
testFileAlias_s
zAliasTests.testFileAliascCsLt|��}|��}Wd�n1swY|�dd�|D�|j�dS)NcS�g|]}|dd��qS�Nr�r+�r-rr+r+r/r4lr5z/AliasTests._cbTestFileAlias.<locals>.<listcomp>�r��	readlinesrCr�)rVrrr�r�r+r+r/ri�

�zAliasTests._cbTestFileAliasN)
r\rqrrr�r�rrsrtrrrr
rr+r+r+r/r�
s
.
	r�c@s"eZdZdZdd�Zddd�ZdS)�DummyDomainz/
    Test domain for L{AddressAliasTests}.
    cCs
||_dSrx)r	)rVr	r+r+r/r�tr�zDummyDomain.__init__Ncs|rtj�d����fdd�S)a

        @returns: When a C{memo} is passed in this will raise a
            L{smtp.SMTPBadRcpt} exception, otherwise a boolean
            indicating if the C{user} and string version of
            L{self.address} are equal or not.
        @rtype: C{bool}
        �hamcs�t�j�kSrx)r]r	r+r�r+r/r�sz$DummyDomain.exists.<locals>.<lambda>)rrr�r�r+r�r/r~wszDummyDomain.existsrx)r\rqrrr�r�r~r+r+r+r/rosrc@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�AddressAliasTestsz7
    Tests for L{twisted.mail.alias.AddressAlias}.
    cCs:tj�d�|_|jjt|j�i}tj�|j||j�|_dS)z+
        Setup an L{AddressAlias}.
        zfoo@barN)rrr�r	r_rr��AddressAlias)rVrTr+r+r/rz�szAddressAliasTests.setUpcCs|�|j���dS)z�
        L{createMessageReceiever} calls C{exists()} on the domain object
        which key matches the C{alias} passed to L{AddressAlias}.
        N)rNr�r
rbr+r+r/�test_createMessageReceiver�sz,AddressAliasTests.test_createMessageReceivercCs|�t|j�d�dS)zP
        The string presentation of L{AddressAlias} includes the alias.
        z<Address foo@bar>N)rCr]r�rbr+r+r/rc�rUzAddressAliasTests.test_strcCs|�|j�|jdi�d�dS)z�
        L{resolve} will look for additional aliases when an C{aliasmap}
        dictionary is passed, and returns L{None} if none were found.
        r�N)rCr��resolver	rbr+r+r/�test_resolve�szAddressAliasTests.test_resolvecCs|�|j�i�d�dS)z�
        L{resolve} returns L{None} when the alias could not be found in the
        C{aliasmap} and no L{mail.smtp.User} with this alias exists either.
        N)rCr�rrbr+r+r/�test_resolveWithoutAliasmap�sz-AddressAliasTests.test_resolveWithoutAliasmapN)	r\rqrrr�rzrrcrrr+r+r+r/r�src@seZdZdgZdS)�DummyProcess�onEndN)r\rqrr�	__slots__r+r+r+r/r�s
rc@r�)�MockProcessAliaszD
    An alias processor that doesn't actually launch processes.
    cC�dS)z(
        Don't spawn a process.
        Nr+)rV�protor�r�r+r+r/�spawnProcess�r	zMockProcessAlias.spawnProcessN)r\rqrrr�r"r+r+r+r/r�src@seZdZdZeZdS)�MockAliasGroupz3
    An alias group using C{MockProcessAlias}.
    N)r\rqrrr�r�processAliasFactoryr+r+r+r/r#�sr#c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�StubProcessz�
    Fake implementation of L{IProcessTransport}.

    @ivar signals: A list of all the signals which have been sent to this fake
        process.
    cCs
g|_dSrx)�signalsrbr+r+r/r��r�zStubProcess.__init__cCr )z8
        No-op implementation of disconnection.
        Nr+rbr+r+r/�loseConnection�r	zStubProcess.loseConnectioncCs|j�|�dS)zL
        Record a signal sent to this process for later inspection.
        N)r&r�)rV�signalr+r+r/�
signalProcess�szStubProcess.signalProcessN)r\rqrrr�r�r'r)r+r+r+r/r%�s
r%c@s�eZdZdZe�ed�durdZgd�Zdd�Z	dd�Z
d	d
�Zdd�Ze
ejd
kd�dd��Zdd�Zdd�Zdd�Zdd�Zdd�Ze
ejd
kd�dd��Ze
ejd
kd�dd��ZdS)�ProcessAliasTestsz%
    Tests for alias resolution.
    NzIReactorProcess not supportedr�cCsB|d>dB}|�t�|��|�t�|�|�|�t�|��|S)a
        Construct a status from the given exit code.

        @type code: L{int} between 0 and 255 inclusive.
        @param code: The exit status which the code will represent.

        @rtype: L{int}
        @return: A status integer for the given exit code.
        �r)rNr��	WIFEXITEDrC�WEXITSTATUSr��WIFSIGNALED)rV�code�statusr+r+r/�
exitStatus�s
zProcessAliasTests.exitStatuscCs:|}|�t�|��|�t�|�|�|�t�|��|S)a
        Construct a status from the given signal.

        @type signal: L{int} between 0 and 255 inclusive.
        @param signal: The signal number which the status will represent.

        @rtype: L{int}
        @return: A status integer for the given signal.
        )rNr�r.rC�WTERMSIGr�r,)rVr(r0r+r+r/�signalStatus�s
zProcessAliasTests.signalStatuscCstj|_dt_dS)zB
        Replace L{smtp.DNSNAME} with a well-known value.
        r�N)r�DNSNAMErbr+r+r/rzs
zProcessAliasTests.setUpcCs|jt_dS)z@
        Restore the original value of L{smtp.DNSNAME}.
        N)r4rrbr+r+r/r�szProcessAliasTests.tearDownr&r(csnt����}|�d�t�|jd�tj�|jdd�}|�	�}�j
D]}|�|�q"�fdd�}|���
|�S)z�
        Standard call to C{mail.alias.ProcessAlias}: check that the specified
        script is called, and that the input is correctly transferred to it.
        zX#!/bin/sh
rm -f process.alias.out
while read i; do
    echo $i >> process.alias.out
donei�NcsLtd��}|��}Wd�n1swY��dd�|D��j�dS)Nzprocess.alias.outcSrrr+rr+r+r/r4;r5zPProcessAliasTests.test_processAlias.<locals>._cbProcessAlias.<locals>.<listcomp>r)rr�r�rbr+r/�_cbProcessAlias8rz<ProcessAliasTests.test_processAlias.<locals>._cbProcessAlias)rr�
setContentr��chmodr�rr��ProcessAliasr
r�r�r�r�)rV�shr<rr�r5r+rbr/�test_processAlias"s�
z#ProcessAliasTests.test_processAliascstt��}t��tj�������tj��d|�}|��}|�	|j
����fdd�}��|tjj�|�
|�|S)a
        If the alias child process does not exit within a particular period of
        time, the L{Deferred} returned by L{MessageWrapper.eomReceived} should
        fail with L{ProcessAliasTimeout} and send the I{KILL} signal to the
        child process..
        Ncs*���jdg���t��tj���dS)N�KILL)rCr&�processEndedrr3r(�SIGKILLr�r!rVr�r+r/�timedOutOsz<ProcessAliasTests.test_processAliasTimeout.<locals>.timedOut)rr;r%rr��ProcessAliasProtocolr��MessageWrapperr�r<�completionTimeoutr�ProcessAliasTimeoutr�)rVr
�receiverrWr?r+r>r/�test_processAliasTimeout?s


z*ProcessAliasTests.test_processAliasTimeoutcCsNt�}tj��}|�|�tj�|dd�}|�t�t	d���|�
|��t	�S)z�
        If the process associated with an L{mail.alias.MessageWrapper} exits
        before I{eomReceived} is called, the L{Deferred} returned by
        I{eomReceived} should fail.
        Nr)r%rr�r@r�rAr<rrrrr�)rVr�rrDr+r+r/�test_earlyProcessTerminationY�

z.ProcessAliasTests.test_earlyProcessTerminationcCsNt�}tj��}|�|�tj�|dd�}|�t�t	|���|�
|��t	�S)z�
        Verify that if the process associated with an
        L{mail.alias.MessageWrapper} exits with the given status, the
        L{Deferred} returned by I{eomReceived} fails with L{ProcessTerminated}.
        N)r%rr�r@r�rAr<rrrrr�)rVr0r�rrDr+r+r/�_terminationTestfrGz"ProcessAliasTests._terminationTestcCs|�|�d��S)z�
        If the process associated with an L{mail.alias.MessageWrapper} exits
        with a non-zero exit code, the L{Deferred} returned by I{eomReceived}
        should fail.
        rh)rHr1rbr+r+r/�test_errorProcessTerminationssz.ProcessAliasTests.test_errorProcessTerminationcCs|�|�tj��S)z�
        If the process associated with an L{mail.alias.MessageWrapper} exits
        because it received a signal, the L{Deferred} returned by
        I{eomReceived} should fail.
        )rHr3r(�SIGHUPrbr+r+r/�test_signalProcessTermination{sz/ProcessAliasTests.test_signalProcessTerminationc
Csxi}dt|gd��i}tgd�|d�}tddg|d�}tj�d|d�}|�|||d	��|�|�}tt|j	�}|�
�tttj�d
dd�tj�t�d�tj�
d
�g�}|�
�|�||�|�|�}	tt|	j	�}
|
�
�tttj�ddd�tj�ddd�g�}|�
�|�|
|�|�|�}tt|j	�}|�
�tttj�d
dd�tj�t�d�tj�
d
�g�}|�
�|�||�dS)a�
        Check that the C{resolve} method of alias processors produce the correct
        set of objects:
            - direct alias with L{mail.alias.AddressAlias} if a simple input is passed
            - aliases in a file with L{mail.alias.FileWrapper} if an input in the format
              '/file' is given
            - aliases resulting of a process call wrapped by L{mail.alias.MessageWrapper}
              if the format is '|process'
        r�)r[r]r_)r[�|echo�/file�alias1r]r_�alias2�alias3�rNrOrPr[N�echorM)�
TestDomainr#rr�rrOrr�r]�objsrIrAr�FileWrapperrC)
rVr�r_�A1�A2�A3�res1�r1�expected�res2�r2�res3�r3r+r+r/�test_aliasResolution�s\��

��
��

��z&ProcessAliasTests.test_aliasResolutionc
Cs�i}dt|g�i}tj�d|d�}tj�d|d�}tj�d|d�}|�|||d��|�|d�|�d�|�|d�|�d�|�|d�|�d�tddg|d�}||d<|�|�}tt	|j
�}|��tt	tj�t
�d	�g�}	|	��|�||	�dS)
zN
        Check that a cycle in alias resolution is correctly handled.
        r�rOrNrPrQNrL�alias4rR)rSrr�rrOrCrr#r�r]rTrIrAr)
rVr�r_rVrWrX�A4�res�rr[r+r+r/�test_cyclicAlias�s"
z"ProcessAliasTests.test_cyclicAlias)r\rqrrr�r�IReactorProcessr
r�r�r1r3rzr�rrsrtr:rErFrHrIrKr`rer+r+r+r/r*�s(



@r*c@r3)rScCs||_||_dSrx)r��users)rVr�rgr+r+r/r��r�zTestDomain.__init__Ncsn�jj��|jvr�fdd�Sz|j�}Wnty"t����w|�|j|���r2�fdd�St����)Ncstj��dd�Srx)rr�rr+)rnr+r/r�sz#TestDomain.exists.<locals>.<lambda>crrxr+r+)r�r+r/r�r	)r��localrgr�r�rr�r)rVrnr�r<r+)r�rnr/r~�s

�
zTestDomain.existsrx)r\rqrrr�r~r+r+r+r/rS�rArSc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�
DummyQueuez�
    A fake relay queue to use for testing.

    This queue doesn't keep track of which messages are waiting to be relayed
    or are in the process of being relayed.

    @ivar directory: See L{__init__}.
    cCr�)z�
        @type directory: L{bytes}
        @param directory: The pathname of the directory holding messages in the
            queue.
        N)�	directory)rVrjr+r+r/r��s
zDummyQueue.__init__cCs8tj�|�}t�|�|�d�t�|�|�d�dS)z�
        Remove a message from the queue.

        @type message: L{bytes}
        @param message: The base filename of a message.
        r�r�N)r�r��basenamer��getPath�rVrjr+r+r/r�	szDummyQueue.donecCsttj�|j|d�d�S)z�
        Get the envelope file for a message in the queue.

        @type message: L{bytes}
        @param message: The base filename of a message.

        @rtype: L{file}
        @return: The envelope file for the message.
        r��rb)r�r�r�r7rjrmr+r+r/�getEnvelopeFile	s
zDummyQueue.getEnvelopeFilecCstj�|j|�S)z�
        Return the full base pathname of a message in the queue.

        @type message: L{bytes}
        @param message: The base filename of a message.

        @rtype: L{bytes}
        @return: The full base pathname of the message.
        )r�r�r7rjrmr+r+r/rl	s
zDummyQueue.getPathcCsvt���dt|���}ttj�|j|d�d�}tj�|j|d�}tj�|j|d�}t|d�}|tj�|||�fS)z�
        Create a new message in the queue.

        @rtype: 2-L{tuple} of (E{1}) L{file}, (E{2}) L{FileMessage}
        @return: The envelope file and a message receiver for a new message in
            the queue.
        �_r�r�z-Cr�)	�time�idr�r�r�r7rjrr�)rV�fname�
headerFile�tempFilename�
finalFilename�messageFiler+r+r/r(	s
�zDummyQueue.createNewMessagecCr )z�
        Ignore the request to mark a message as waiting to be relayed.

        @type message: L{bytes}
        @param message: The base filename of a message.
        Nr+rmr+r+r/r$:	r�zDummyQueue.setWaitingN)
r\rqrrr�r�r�rorlrr$r+r+r+r/ri�s	ric@r�)�!DummySmartHostSMTPRelayingManagera4
    A fake smart host to use for testing.

    @type managed: L{dict} of L{bytes} -> L{list} of
        L{list} of L{bytes}
    @ivar managed: A mapping of a string identifying a managed relayer to
        filenames of messages the managed relayer is responsible for.

    @ivar queue: See L{__init__}.
    cCsi|_||_dS)z�
        Initialize the minimum necessary members of a smart host.

        @type queue: L{DummyQueue}
        @param queue: A queue that can be used for testing purposes.
        N)�managedr)rVrr+r+r/r�P	s
z*DummySmartHostSMTPRelayingManager.__init__N)r\rqrrr�r�r+r+r+r/rxD	srxc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
eejdkd�dd��Zeejdkd�dd��Zdd�Zdd�Zd d!�Zd"d#�Zd$S)%�_AttemptManagerTestsa
    Test the behavior of L{_AttemptManager}.

    @type tmpdir: L{bytes}
    @ivar tmpdir: The path to a temporary directory holding the message files.

    @type reactor: L{MemoryReactorClock}
    @ivar reactor: The reactor used for test purposes.

    @type eventLog: L{None} or L{dict} of L{bytes} -> L{object}
    @ivar eventLog: Information about the last informational log message
        generated or none if no log message has been generated.

    @type noisyAttemptMgr: L{_AttemptManager}
    @ivar noisyAttemptMgr: An attempt manager which generates informational
        log messages.

    @type quietAttemptMgr: L{_AttemptManager}
    @ivar quietAttemptMgr: An attempt manager which does not generate
        informational log messages.

    @type noisyMessage: L{bytes}
    @ivar noisyMessage: The full base pathname of the message to be used with
        the noisy attempt manager.

    @type quietMessage: L{bytes}
    @ivar quietMessage: The full base pathname of the message to be used with
        the quiet.
    cCs^|��|_t�|j�t�|_d|_t�|j	�t
tt|j��d|j�|_
t
tt|j��d|j�|_d}d}tj�|j|�|_tj�|j|�|_t|jdd���t|jdd���|g|j
jjd<|g|jjjd	<t|jd
d��}t�dd
g|�Wd�n1s�wYt|jd
d��}t�ddg|�Wd�dS1s�wYdS)a
        Set up a temporary directory for the queue, attempt managers with the
        noisy flag on and off, message files for use with each attempt manager,
        and a reactor.  Also, register to be notified when log messages are
        generated.
        NTF�noisyMessage�quietMessager�r��noisyRelayer�quietRelayerr�r�zfrom-noisy@domainzto-noisy@domainzfrom-quiet@domainzto-quiet@domain)rr�r�r�r!r
�eventLogr�addObserver�_logObserverrrxri�noisyAttemptMgr�quietAttemptMgrr�r7r{r|r�r�r	ryr�r�)rV�
noisyBaseName�
quietBaseName�enveloper+r+r/rz{	s:
���"�z_AttemptManagerTests.setUpcCst�|j�t�|j�dS)zO
        Unregister for log events and remove the temporary directory.
        N)r�removeObserverr�r1r2r�rbr+r+r/r��	sz_AttemptManagerTests.tearDowncCr�)z�
        A log observer.

        @type eventDict: L{dict} of L{bytes} -> L{object}
        @param eventDict: Information about the last informational log message
            generated.
        N)r)rV�	eventDictr+r+r/r��	s
z!_AttemptManagerTests._logObservercCs"ttt|j���}|�|j�dS)z�
        When an attempt manager is created without the noisy parameter, the
        noisy instance variable should default to true.
        N)rrxrir�rNr�rV�amr+r+r/�test_initNoisyDefault�	sz*_AttemptManagerTests.test_initNoisyDefaultcC�|�|jj�dS)z�
        When an attempt manager is created with the noisy parameter set to
        true, the noisy instance variable should be set to true.
        N)rNr�rrbr+r+r/�test_initNoisy�	�z#_AttemptManagerTests.test_initNoisycCr�)z�
        When an attempt manager is created with the noisy parameter set to
        false, the noisy instance variable should be set to false.
        N)r�r�rrbr+r+r/�test_initQuiet�	r�z#_AttemptManagerTests.test_initQuietcCs$ttt|j���}|�|jt�dS)z�
        When an attempt manager is created without the reactor parameter, the
        reactor instance variable should default to the global reactor.
        N)rrxrir�rCr
r�r+r+r/�test_initReactorDefault�	sz,_AttemptManagerTests.test_initReactorDefaultcCs|�|jj|j�dS)z�
        When an attempt manager is created with a reactor provided, the
        reactor instance variable should default to that reactor.
        N)rCr�r
rbr+r+r/�test_initReactor�	sz%_AttemptManagerTests.test_initReactorcC� |j�d|j�|�|j�dS)zw
        For an attempt manager with the noisy flag set, notifySuccess should
        result in a log message.
        r}N)r�rr{rNrrbr+r+r/�test_notifySuccessNoisy�	�z,_AttemptManagerTests.test_notifySuccessNoisycCr�)z|
        For an attempt manager with the noisy flag not set, notifySuccess
        should result in no log message.
        r~N)r�rr|r�rrbr+r+r/�test_notifySuccessQuiet�	r�z,_AttemptManagerTests.test_notifySuccessQuietr&r(cCr�)zw
        For an attempt manager with the noisy flag set, notifyFailure should
        result in a log message.
        r}N)r�rr{rNrrbr+r+r/�test_notifyFailureNoisy�	�z,_AttemptManagerTests.test_notifyFailureNoisycCr�)z|
        For an attempt manager with the noisy flag not set, notifyFailure
        should result in no log message.
        r~N)r�rr|r�rrbr+r+r/�test_notifyFailureQuiet�	r�z,_AttemptManagerTests.test_notifyFailureQuietcC�|j�d�|�|j�dS)zt
        For an attempt manager with the noisy flag set, notifyDone should
        result in a log message.
        r}N)r�rrNrrbr+r+r/�test_notifyDoneNoisy
�z)_AttemptManagerTests.test_notifyDoneNoisycCr�)zy
        For an attempt manager with the noisy flag not set, notifyDone
        should result in no log message.
        r~N)r�rr�rrbr+r+r/�test_notifyDoneQuiet
r�z)_AttemptManagerTests.test_notifyDoneQuietcC�(|j�d�|�|j�|j�d�dS)z|
        For an attempt manager with the noisy flag set, notifyNoConnection
        should result in a log message.
        r}r7N)r��notifyNoConnectionrNrr
r<rbr+r+r/�test_notifyNoConnectionNoisy
�z1_AttemptManagerTests.test_notifyNoConnectionNoisycCr�)z�
        For an attempt manager with the noisy flag not set, notifyNoConnection
        should result in no log message.
        r~r7N)r�r�r�rr
r<rbr+r+r/�test_notifyNoConnectionQuiet
r�z1_AttemptManagerTests.test_notifyNoConnectionQuietN)r\rqrrr�rzr�r�r�r�r�r�r�r�r�rrsrtr�r�r�r�r�r�r+r+r+r/rz[	s(-


	rz)}r��
email.messager��email.parserr�r�r�r�r1r(rsr+r�rq�hashlibr�unittestr�zope.interfacerr�zope.interface.verifyr�twisted.cred.checkersr��twisted.cred.credentials�twisted.cred.portal�twisted.mail.alias�twisted.mail.mail�twisted.mail.maildir�twisted.mail.protocols�twisted.mail.relay�twisted.mail.relaymanagerrr�twisted.internetr	r
rrr
r�twisted.internet.deferr�twisted.internet.errorrrrr�twisted.mailrrr�
twisted.namesr�twisted.names.dnsrrr�twisted.names.errorr�twisted.pythonrr�twisted.python.filepathr�twisted.python.runtimer�twisted.test.proto_helpersr r!r"�twisted.trial.unittestr#r%rvr�r�r�r�r�� _MaildirMailboxAppendMessageTaskr�r�r
r*r/rQrVrRr�r�r�r�r�r�r�r�rrr0r1r2r5r4rQrVrWr�r�r�rrrr�r8r�
AliasGroupr#r%r*rSrirxrzr+r+r+r/�<module>s� h&0M
�S(X
s#NI%)D2d)Q

Anon7 - 2022
AnonSec Team