Current File : //proc/self/root/lib/python3/dist-packages/twisted/mail/test/__pycache__/test_smtp.cpython-312.pyc
�

Ϫ�f�����UdZddlZddlZddlZddlmZddlmZmZm	Z	m
Z
mZddlm
Z
mZddlZddlZddlZddlZddlmZddlmZmZddlmZdd	lmZdd
lmZmZddlmZmZmZmZm Z m!Z!m"Z"ddl#m$Z$m%Z%dd
l&m'Z'ddl(m)Z)ddl*m+Z+m,Z,ddl-m.Z.ddl/m0Z0e	e1e2d<	ddl3m4Z4m5Z5dZ6ejpjse!�sdZ6d�Z:ee'jv�Gd�d��Z<Gd�d�Z=Gd�d�Z>dZ?Gd�d�Z@Gd �d!e@e'j��ZBGd"�d#e@e'j��ZDGd$�d%�ZEGd&�d'e+j��ZGGd(�d)e0eE�ZHGd*�d+�ZIGd,�d-�ZJGd.�d/eJe'j��ZLGd0�d1eJe'j��ZNGd2�d3�ZOGd4�d5eOe0�ZPGd6�d7eOe0�ZQeej�j,�Gd8�d9��ZSee'j��Gd:�d;��ZUGd<�d=�ZVGd>�d?e0eE�ZWGd@�dAe0�ZXGdB�dCeD�ZYGdD�dEe0eE�ZZGdF�dGe0�Z[GdH�dIe0eE�Z\GdJ�dKe j��Z^GdL�dMe0�Z_GdN�dOe0�Z`ee�GdP�dQ��ZaGdR�dS�ZbGdT�dUe0�ZcGdV�dWe0�ZdGdX�dYe0�ZeGdZ�d[e0�ZfGd\�d]e0�ZgGd^�d_e0�ZhGd`�dae%�ZiGdb�dce0�Zjy#e7$rdZ6Y��\wxYw)dz*
Test cases for twisted.mail.smtp module.
�N)�BytesIO)�Any�List�Optional�Tuple�Type)�directlyProvides�implementer)�cred)�AllowAnonymousAccess�ICredentialsChecker)�
IAnonymous)�UnauthorizedLogin)�IRealm�Portal)�address�defer�error�
interfaces�protocol�reactor�task)�
MemoryReactor�StringTransport)�smtp)�LOGINCredentials)�basic�loopback)�LineLog)�TestCase�sslSkip)�ClientTLSContext�ServerTLSContextzOpenSSL not presentzReactor doesn't support SSLc��y�N�)�spam�eggss  �=/usr/lib/python3/dist-packages/twisted/mail/test/test_smtp.py�	spameaterr*/s���c�(�eZdZdZd�Zd�Zd�Zd�Zy)�
BrokenMessagez�
    L{BrokenMessage} is an L{IMessage} which raises an unexpected exception
    from its C{eomReceived} method.  This is useful for creating a server which
    can be used to test client retry behavior.
    c��yr%r&��self�users  r)�__init__zBrokenMessage.__init__;���r+c��yr%r&�r0�lines  r)�lineReceivedzBrokenMessage.lineReceived>r3r+c��td��)Nz"Some problem, delivery is failing.)�RuntimeError�r0s r)�eomReceivedzBrokenMessage.eomReceivedAs���?�@�@r+c��yr%r&r:s r)�connectionLostzBrokenMessage.connectionLostDr3r+N)�__name__�
__module__�__qualname__�__doc__r2r7r;r=r&r+r)r-r-3s���
�
�A�
r+r-c�"�eZdZdZd�Zd�Zd�Zy)�DummyMessagez�
    L{BrokenMessage} is an L{IMessage} which saves the message delivered to it
    to its domain object.

    @ivar domain: A L{DummyDomain} which will be used to store the message once
        it is received.
    c�.�||_||_g|_yr%)�domainr1�buffer)r0rEr1s   r)r2zDummyMessage.__init__Qs�������	���r+c�h�tjd|�s|jj|�yy)Ns/Received: From yyy.com \(\[.*\]\) by localhost;)�re�matchrF�appendr5s  r)r7zDummyMessage.lineReceivedVs)���x�x�K�T�R��K�K���t�$�Sr+c��dj|j�dz}|jj|jj
jj|�tj�}|jd�|S)N�
�saved)�joinrFrE�messagesr1�dest�localrJr�Deferred�callback)r0�message�deferreds   r)r;zDummyMessage.eomReceived[sc���*�*�T�[�[�)�E�1�������T�Y�Y�^�^�1�1�2�9�9�'�B��>�>�#�����(�#��r+N)r>r?r@rAr2r7r;r&r+r)rCrCHs����
%�
r+rCc��eZdZdZd�Zd�Zy)�DummyDomainzf
    L{DummyDomain} is an L{IDomain} which keeps track of messages delivered to
    it in memory.
    c�>�i|_|D]}g|j|<�yr%)rO)r0�names�names   r)r2zDummyDomain.__init__is&����
��	%�D�"$�D�M�M�$��	%r+c������jj�jvrtj��fd��Stj
t
j���S)Nc���t���Sr%�rCr/s��r)�<lambda>z$DummyDomain.exists.<locals>.<lambda>ps����d�D�)A�r+)rPrQrOr�succeed�failr�SMTPBadRcptr/s``r)�existszDummyDomain.existsnsA����9�9�?�?�d�m�m�+��=�=�!A�B�B��z�z�$�*�*�4�0�1�1r+N)r>r?r@rAr2rbr&r+r)rWrWcs���
%�
2r+rWsSubject: hello

Goodbye
c�2�eZdZdd�Zd�Zd�Zd�Zd�Zd�Zy)	�MyClientNc�j�|�ddgtt�f}|d|_|d|_|d|_y)Nzmoshez@foo.barr��)r�mail�_sender�
_recipient�_data�r0�messageInfos  r)r2zMyClient.__init__|s=����+�.>�-?����O�K�"�1�~���%�a�.��� ��^��
r+c��|jSr%)rir:s r)�getMailFromzMyClient.getMailFrom�s���|�|�r+c��|jSr%)rjr:s r)�	getMailTozMyClient.getMailTo�s�����r+c��|jSr%)rkr:s r)�getMailDatazMyClient.getMailData�s���z�z�r+c��||_yr%)�_error)r0�excs  r)�	sendErrorzMyClient.sendError�s	����r+c�.�d|_d|_d|_yr%)rirjrk)r0�code�resp�numOk�	addresses�logs      r)�sentMailzMyClient.sentMail�s����������
r+r%)	r>r?r@r2rorqrsrwr~r&r+r)rdrd{s ��$�����r+rdc��eZdZdd�Zy)�MySMTPClientNc�p�tjj|d�tj||�y�Nsfoo.baz)r�
SMTPClientr2rdrls  r)r2zMySMTPClient.__init__�s&����� � ��z�2����$��,r+r%�r>r?r@r2r&r+r)r�r��s��-r+r�c��eZdZdd�Zy)�
MyESMTPClientNc�r�tjj|||d�tj|�yr�)r�ESMTPClientr2rd)r0�secret�contextFactorys   r)r2zMyESMTPClient.__init__�s*�����!�!�$���
�K����$�r+)r+Nr�r&r+r)r�r��s�� r+r�c��eZdZd�Zy)�
LoopbackMixinc�.�tj||�Sr%)r�loopbackTCP)r0�server�clients   r)rzLoopbackMixin.loopback�s���#�#�F�F�3�3r+N)r>r?r@rr&r+r)r�r��s��4r+r�c� �eZdZgd�Zd�Zd�Zy)�FakeSMTPServer)�	220 hellos250 nice to meet you�	250 greatr�s354 go on, ladc��g|_|jdd|_|jj�|j|jj	��yr%)rF�
clientData�reverse�sendLine�popr:s r)�connectionMadezFakeSMTPServer.connectionMade�sB������/�/�!�,��������!��
�
�d�o�o�)�)�+�,r+c��|jj|�|dk(r6|jjd�|jj	�n@|dk(r|jjd�n|dk(r|jj	�|j
r*|j
|j
j��yy)NsQUITs221 see ya around
�.s250 gotcha
�RSET)rFrJ�	transport�write�loseConnectionr�r�r�r5s  r)r7zFakeSMTPServer.lineReceived�s��������4� ��7�?��N�N� � �!9�:��N�N�)�)�+�
�T�\��N�N� � �!2�3�
�W�_��N�N�)�)�+��?�?��M�M�$�/�/�-�-�/�0�r+N)r>r?r@r�r�r7r&r+r)r�r��s���J�-�1r+r�c�<�eZdZdZd�Zgd�Zd�Zd�Zd�Zd�Z	d�Z
y	)
�SMTPClientTestsz'
    Tests for L{smtp.SMTPClient}.
    c�p�g}t�}|j|_|jt	��|jd�|j
�|j|dtj�|j|dj�|jt|d�d�y)z�
        L{smtp.SMTPClient.timeoutConnection} calls the C{sendError} hook with a
        fatal L{SMTPTimeoutError} with the current line log.
        r�rsHTimeout waiting for SMTP server response
<<< 220 hello
>>> HELO foo.baz
N)r�rJrw�makeConnectionrr7�timeoutConnection�assertIsInstancer�SMTPTimeoutError�
assertTrue�isFatal�assertEqual�bytes)r0�errorsr�s   r)�test_timeoutConnectionz&SMTPClientTests.test_timeoutConnection�s���
�����!�=�=������o�/�0����L�)�� � �"����f�Q�i��)>�)>�?�����q�	�)�)�*�����&��)��
"�	
r+)	sHELO foo.bazsMAIL FROM:<moshez@foo.bar>sRCPT TO:<moshez@foo.bar>sDATAsSubject: hellor+sGoodbyer�r�c����t�}t���j�|�}|j��fd��|S)z�
        L{smtp.SMTPClient} sends I{HELO}, I{MAIL FROM}, I{RCPT TO}, and I{DATA}
        commands based on the return values of its C{getMailFrom},
        C{getMailTo}, and C{getMailData} methods.
        c�P���j�j�j�Sr%)r�rF�expected_output��xr0r�s ��r)r^z/SMTPClientTests.test_messages.<locals>.<lambda>�s���� 0� 0�����@T�@T� U�r+)r�r�r�addCallback)r0r��dr�s`  @r)�
test_messageszSMTPClientTests.test_messages�s6�������!���M�M�&�&�)��	�
�
�U�V��r+c�n�tddgtd�f�}t�}|j|�|j	d�|j|jd�|j|j�|jj�|j|jt�y)z�
        If there is an error while producing the message body to the
        connection, the C{sendError} callback is invoked.
        zalice@example.comzbob@example.com�foo�(220 Ok
250 Ok
250 Ok
250 Ok
354 Ok
N)
r�rrr��dataReceived�assertNotIdentical�producer�assertFalse�	streaming�
stopProducingr�ru�	Exception�r0r�r�s   r)�test_transferErrorz"SMTPClientTests.test_transferError�s���
�
 �#4�"5�w�v��G�
��$�%�	����i�(����
�	
�	
���	� 2� 2�D�9�����,�,�-�	���(�(�*�	
���f�m�m�Y�7r+c�(�tjd�}t�}|j|�|j	tj
ddd���|j
|j�d�|j|j�y)z�
        If L{smtp.SMTPClient.sendError} is called with an L{SMTPClientError}
        which is fatal, it disconnects its transport without writing anything
        more to it.
        N�{�fooT�r�r+)
rr�rr�rw�SMTPClientErrorr��valuer��
disconnectingr�s   r)�test_sendFatalErrorz#SMTPClientTests.test_sendFatalErrorsn������&��#�%�	����i�(�����-�-�c�5�$�G�H�������*�C�0����	�/�/�0r+c�(�tjd�}t�}|j|�|j	tj
ddd���|j
|j�d�|j|j�y)z�
        If L{smtp.SMTPClient.sendError} is called with an L{SMTPClientError}
        which is not fatal, it sends C{"QUIT"} and waits for the server to
        close the connection.
        Nr�r�Fr��QUIT
)
rr�rr�rwr�r�r�r�r�r�s   r)�test_sendNonFatalErrorz&SMTPClientTests.test_sendNonFatalErrorsp������&��#�%�	����i�(�����-�-�c�5�%�H�I�������*�K�8�����0�0�1r+c��tjd�}t�}|j|�|j	td��|j
|j�d�|j|j�y)z�
        If L{smtp.SMTPClient.sendError} is called with an exception which is
        not an L{SMTPClientError}, it disconnects its transport without
        writing anything more to it.
        Nr�r+)
rr�rr�rwr�r�r�r�r�r�s   r)�test_sendOtherErrorz#SMTPClientTests.test_sendOtherError+sd������&��#�%�	����i�(�����5�)�*�������*�C�0����	�/�/�0r+N)r>r?r@rAr�r�r�r�r�r�r�r&r+r)r�r��s,���
�(
�O�
�8�81�2�1r+r�c��eZdZd�Zd�Zd�Zy)�DummySMTPMessagec�.�||_||_g|_yr%)r�usersrF)r0rr�s   r)r2zDummySMTPMessage.__init__:s�� ��
���
���r+c�:�|jj|�yr%)rFrJr5s  r)r7zDummySMTPMessage.lineReceived?s�������4� r+c��dj|j�dz}|jdjdt	|jdj
�}}g}|jD]}|j
t	|���||||f|jjt|�<tjd�S)NrLrrM)rNrFr��helor��origrJrrT�tuplerr_)r0rTr��origin�
recipientsr1s      r)r;zDummySMTPMessage.eomReceivedBs����*�*�T�[�[�)�E�1���z�z�!�}�)�)�!�,�e�D�J�J�q�M�4F�4F�.G�f���
��J�J�	+�D����e�D�k�*�	+�48�&�*�g�3V��
�
���e�J�/�0��}�}�X�&�&r+N)r>r?r@r2r7r;r&r+r)r�r�9s���
!�'r+r�c�$�eZdZd�Zd�Zd�Zd�Zy)�
DummyProtoc�H�|jj|�i|_yr%)�dummyMixinBaser�rTr:s r)r�zDummyProto.connectionMadeMs�����*�*�4�0���r+c��yr%r&)r's r)�receivedHeaderzDummyProto.receivedHeaderQ���r+c�2���td��_��fd�S)Nc���t��g�Sr%)r�r/s��r)r^z'DummyProto.validateTo.<locals>.<lambda>Vs���'��t�f�5�r+)�SimpleDelivery�deliveryr/s``r)�
validateTozDummyProto.validateToTs���&�t�,��
�5�5r+c��|Sr%r&�r0r�r�s   r)�validateFromzDummyProto.validateFromX����
r+N)r>r?r@r�r�r�r�r&r+r)r�r�Ls����6�r+r�c�$�eZdZejZy)�	DummySMTPN)r>r?r@r�SMTPr�r&r+r)r�r�\s���Y�Y�Nr+r�c�$�eZdZejZy)�
DummyESMTPN)r>r?r@r�ESMTPr�r&r+r)r�r�`s���Z�Z�Nr+r�c��eZdZUdZeeejed<dZ	eee
jed<dddgddgdfddd	d
gdd	d
gdfddd
gddgdfgZgd�Z
eeeeeefed<eD]a\ZZZZZZe
j1dezdzdddf�eD]Ze
j1dezdzdddf��e
j1ddedeeeefff��cd�Zy)�AnotherTestCaseN�serverClass�clientClass�foo.comsmoshez@foo.comsmoshez@bar.coms(From: Moshe
To: Moshe

Hi,
how are you?
stttt@rrr.comsuuu@ooosyyy@eeesSubject: pass

..rrrr..
s@this,@is,@ignored:foo@bar.coms@ignore,@this,@too:bar@foo.comsfoo@bar.comsbar@foo.coms Subject: apa
To: foo

123
.
456
))r+s220.*
$NN)sHELO foo.com
�250.*
$NN)sRSET
r�NN�datasMAIL FROM:<s>
s250.*
s	RCPT TO:<sDATA
s354.*
c�D�t�}|j�}Gd�d�}|�|_|j|�|jD�]>\}}}}|r|j|�|j
�}|j�tj||�s
t|||��|dddk(s�h|j�D]%}	|	r
|	dddk(rd|	z}	|j|	d	z��'|jd
�|j
�}|j�|\}
}tj|
|�st|
|��|dD]?}t|dd�}
|g|
d<|j|j|ft|
���A��A|j!d�y)a
        Exercise a lot of the SMTP client code.  This is a "shotgun" style unit
        test.  It does a lot of things and hopes that something will go really
        wrong if it is going to go wrong.  This test should be replaced with a
        suite of nicer tests.
        c��eZdZdZy)�/AnotherTestCase.test_buffer.<locals>.fooFactoryr�N)r>r?r@rEr&r+r)�
fooFactoryr��s���Fr+r�N�s354rrfr��
s.
rg)rr��factoryr�r�r�r��clearrHrI�AssertionError�
splitlines�listr�rTr��
setTimeout)r0r��ar��send�expect�msg�	msgexpectr�r6rz�msgdata�recip�expecteds              r)�test_bufferzAnotherTestCase.test_buffer�s���$�%�	������	 �	 ��L��	�	����#�,0�I�I�	K�(�D�&�#�y�����t�$��?�?�$�D��O�O���8�8�F�D�)�$�T�6�4�8�8��B�Q�x�6�!��N�N�,�3�D���Q�q�	�T� 1�#�d�{���N�N�4�'�>�2�3����x�(�!���(�����!� )�
��g��x�x��d�+�(��t�4�4�$�Q�Z�K�E�#�G�A�J�/�H�#(�'�H�Q�K��$�$�Q�Y�Y��x�%8�%��/�J�K�)	K�0	
���T�r+)r>r?r@r�rrr�Protocol�__annotations__r�rr�rOr�rrr�r�helo_�from_�to_�realfrom�realtorrJ�rcptrr&r+r)r�r�dsc��59�K��$�x�0�0�1�2�9�37�K��$�t���/�0�7�
��
���
��
�

	
�
��
��$��
��$�
�
	
�
�-�
.�/��
��
�
	
�7*�H�X1�D�$�u�U�E�3��+�,�
-��
5=�
�0��u�c�8�V�S����^�e�+�h�6��d�D�Q�R��	T�D��K�K���,�x�7��t�T�R�S�	T�	
��������x���=�>�	
�	
�
�'r+r�c��eZdZeZeZy)�AnotherESMTPTestsN)r>r?r@r�r�r�r�r&r+r)rr�s���K��Kr+rc��eZdZeZeZy)�AnotherSMTPTestsN)r>r?r@r�r�r�r�r&r+r)rr�s���K��Kr+rc�x�eZdZddiZej
jej
jfZd�Z	d�Z
y)�DummyChecker�testuser�testpasswordc��tj|j|j|j�j|j|j�Sr%)r�
maybeDeferred�
checkPasswordr��usernamer��_cbCheck�r0�credentialss  r)�requestAvatarIdzDummyChecker.requestAvatarId�sE���"�"��%�%�t�z�z�+�2F�2F�'G�
�
�+�d�m�m�[�%9�%9�
:�	;r+c�F�|r|Stjj��r%)rrr)r0�resultrs   r)r zDummyChecker._cbCheck�s����O��j�j�*�*�,�,r+N)r>r?r@r�rr"�IUsernamePassword�IUsernameHashedPassword�credentialInterfacesr#r r&r+r)rr�s>��
�/�*�E�	
���*�*����0�0���
;�
-r+rc�(�eZdZdZd�Zd�Zd�Zd�Zy)r�z[
    L{SimpleDelivery} is a message delivery factory with no interesting
    behavior.
    c��||_yr%��_messageFactory)r0�messageFactorys  r)r2zSimpleDelivery.__init__�s
��-��r+c��yr%r&�r0r�r�r�s    r)r�zSimpleDelivery.receivedHeader�r�r+c��|Sr%r&r�s   r)r�zSimpleDelivery.validateFrom�r�r+c������fd�S)Nc�&���j��Sr%r+r/s��r)r^z+SimpleDelivery.validateTo.<locals>.<lambda>s���t�+�+�D�1�r+r&r/s``r)r�zSimpleDelivery.validateTo�s	���1�1r+N)r>r?r@rAr2r�r�r�r&r+r)r�r��s���
.���2r+r�c��eZdZd�Zy)�
DummyRealmc�<�tjtd�d�fS)Nc��yr%r&r&r+r)r^z*DummyRealm.requestAvatar.<locals>.<lambda>��r+)r�IMessageDeliveryr�)r0�avatarId�mindrs    r)�
requestAvatarzDummyRealm.requestAvatars���$�$�n�T�&:�L�H�Hr+N)r>r?r@r;r&r+r)r4r4s��Ir+r4c��eZdZd�Zd�Zd�Zy)�	AuthTestsc����t�}tjj|�}|j	t��t
dtjji��|�_td�}tjd�}|j|��j�|�}|j��fd��|S)z�
        L{ESMTPClient} can authenticate using the I{CRAM-MD5} SASL mechanism.

        @see: U{http://tools.ietf.org/html/rfc2195}
        sCRAM-MD5rrc�<���j�jd�S)Nrf)r��
authenticatedr�s ��r)r^z,AuthTests.test_crammd5Auth.<locals>.<lambda>s���� 0� 0��1E�1E�q� I�r+)r4r�portalr�registerCheckerrr�r"�CramMD5Credentialsr�r�CramMD5ClientAuthenticator�registerAuthenticatorrr��r0�realm�pr��cAuthr�r�s`     @r)�test_crammd5AuthzAuthTests.test_crammd5Auth	s��������K�K���u�%��	���,�.�)��[�$�*:�*:�*M�*M�N�O����
���/���/�/��<���$�$�U�+��M�M�&�&�)��	�
�
�I�J��r+c�n���t�}tjj|�}|j	t��t
dti��|�_td�}tjd�}|j|��j�|�}|j��fd��|S)z�
        L{ESMTPClient} can authenticate using the I{LOGIN} SASL mechanism.

        @see: U{http://sepp.oetiker.ch/sasl-2.1.19-ds/draft-murchison-sasl-login-00.txt}
        �LOGINrrc�:���j�j�Sr%�r�r@r�s ��r)r^z*AuthTests.test_loginAuth.<locals>.<lambda>0��������0D�0D� E�r+)r4rrArrBrr�rr�r�LOGINAuthenticatorrErr�rFs`     @r)�test_loginAuthzAuthTests.test_loginAuths��������K�K���u�%��	���,�.�)��X�'7�8�9����
���/���'�'��4���$�$�U�+��M�M�&�&�)��	�
�
�E�F��r+c����t�}tjj|�}|j	t��t
dtji��|�_td�}tjd�}|j|��j�|�}|j��fd��|S)a
        When communicating with a server which implements the I{LOGIN} SASL
        mechanism using C{"Username:"} as the challenge (rather than C{"User
        Name\0"}), L{ESMTPClient} can still authenticate successfully using
        the I{LOGIN} mechanism.
        rLrrc�:���j�j�Sr%rNr�s ��r)r^z8AuthTests.test_loginAgainstWeirdServer.<locals>.<lambda>FrOr+)r4rrArrBrr�rrr�rPrErr�rFs`     @r)�test_loginAgainstWeirdServerz&AuthTests.test_loginAgainstWeirdServer3s��������K�K���u�%��	���,�.�)��X�t�'<�'<�=�>����
���/���'�'��4���$�$�U�+��M�M�&�&�)��	�
�
�E�F��r+N)r>r?r@rJrQrTr&r+r)r=r=s���*�*r+r=c�0�eZdZd�Zd�Zd�Zd�Zd�Zd�Zy)�SMTPHelperTestsc��i}td�D]/}tjd�}|j||v�d||<�1y)Ni��testcase)�ranger�	messageidr�)r0r��i�ms    r)�
testMessageIDzSMTPHelperTests.testMessageIDKsC�����t��	�A����z�*�A����Q�!�V�$��A�a�D�	r+c���ddgddgtjd�dgddgtjd�dgg}|D]*\}}|jtj|�|��,y)Nsuser@host.names<user@host.name>s"User Name" <user@host.name>ssomeguy@someplaces<someguy@someplace>r+s<>)r�Addressr��	quoteaddr)r0�cases�c�es    r)�
testQuoteAddrzSMTPHelperTests.testQuoteAddrRst��
� 3�4�
,�.A�B�
�\�\�.�
/�1G�H�
�%�L�
�\�\�#�
��&�
���	3�D�A�q����T�^�^�A�.��2�	3r+c�j�tjdddd�}|jt|�d�y)Ns	user@hostshelo.host.namez	user@host)r�Userr��str)r0�us  r)�testUserzSMTPHelperTests.testUser^s+���I�I�l�$5�t�T�B������Q���-r+c�d�gd�}|D]�\}}|jtj|�|t|�f�|j|j	d�|�|jtj
|�|t|�f�|j|j
d�|���y)N))�Hello worlds
Hello+20world)zHello+worlds
Hello+2Bworld)zs+00+01+02+03+04+05)ze=mc2@example.comse+3Dmc2@example.com�xtext)r�r�xtext_encode�len�encode�xtext_decode�decode)r0ra�caser
s    r)�testXtextEncodingz!SMTPHelperTests.testXtextEncodingbs���
��$�	=�N�D�(����T�.�.�t�4�x��T��6K�L����T�[�[��1�8�<����T�.�.�x�8�4��X��:O�P����X�_�_�W�5�t�<�		=r+c���d}|jtj|d�|jd�t	|�f�|j|jdd�|jd��y)z�
        Specifying an error policy to C{unicode.encode} with the
        I{xtext} codec should produce the same result as not
        specifying the error policy.
        rk�strictrlN)r�rrmrorn)r0�texts  r)�test_encodeWithErrorsz%SMTPHelperTests.test_encodeWithErrorspsa����������d�H�-����G�0D�c�$�i�/P�	
�	
������W�h�7����W�9M�Nr+c���d}|jtj|d�|jd�t	|�f�|j|jdd�|jd��y)zO
        Similar to L{test_encodeWithErrors}, but for C{bytes.decode}.
        sHello worldrurlN)r�rrprqrn)r0r�s  r)�test_decodeWithErrorsz%SMTPHelperTests.test_decodeWithErrors|sa����������e�X�.����g�1F��E�
�0S�	
�	
������g�x�8�%�,�,�w�:O�Pr+N)	r>r?r@r]rdrirsrwryr&r+r)rVrVJs"���
3�.�=�
O�Qr+rVc��eZdZdZd�Zy)�NoticeTLSClientFc�@�tj|||�d|_y�NT)r��esmtpState_starttls�tls)r0ryrzs   r)r~z#NoticeTLSClient.esmtpState_starttls�s���)�)�$��d�;���r+N)r>r?r@rr~r&r+r)r{r{�s��
�C�r+r{c��eZdZeZd�Zy)�TLSTestsc�����t�}t�}t|���t|������fd�}�j	���j|�S)N)r�c�v���j�jd��j�jd�yr})r�r�
startedTLS)�ignoredr�r0r�s ���r)�checkzTLSTests.testTLS.<locals>.check�s-������V�Z�Z��.����V�.�.��5r+)r"r#r{r�rr�)r0�	clientCTX�	serverCTXr�r�r�s`   @@r)�testTLSzTLSTests.testTLS�sJ���$�&�	�$�&�	� �	�:���9�5��	6��}�}�V�V�,�8�8��?�?r+N)r>r?r@r!�skipr�r&r+r)r�r��s
���D�@r+r�c��eZdZd�Zy)�EmptyLineTestsc��tj�}t�}|j|�|j	d�|jd�|j
�j�}|jt|�d�|j|djd��|j|dd�y)z�
        If L{smtp.SMTP} receives an empty line, it responds with a 500 error
        response code and a message about a syntax error.
        r+Nrgrs220rfs500 Error: bad syntax)rr�rr�r7rr�rr�rnr��
startswith)r0�protor��outs    r)�test_emptyLineSyntaxErrorz(EmptyLineTests.test_emptyLineSyntaxError�s���
�	�	���#�%�	�
���Y�'�
���3��
������o�o��*�*�,������S��1�%�����A��)�)�&�1�2�����Q��!9�:r+N)r>r?r@r�r&r+r)r�r��s��;r+r�c�4�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	y)	�TimeoutTestszE
    Check that SMTP client factories correctly use the timeout.
    c����tj��|jtjddd��}�j
|_t
�}|j|�||_��fd�}�j|tj�j|�}�jd��jd�|S)zR
        Connect the clientFactory, and check the timeout on the request.
        �TCP�example.net�c�F���j�j�d�y)N��?)r��seconds)�ign�clockr0s ��r)r�z(TimeoutTests._timeoutTest.<locals>.check�s������U�]�]�_�c�2r+g�������?g�������?)r�Clock�
buildProtocolr�IPv4Address�	callLaterrr�r�
assertFailurerr�r��advance)r0�onDone�
clientFactoryr��tr�r�r�s`      @r)�_timeoutTestzTimeoutTests._timeoutTest�s�����
�
����,�,�����}�b�9�
��!�?�?���������a� ���
�	3�
���v�t�'<�'<�=�I�I�%�P��
�
�
�c��
�
�
�c���r+c��tj�}tjddt	d�|dd��}|j||�S)z�
        Test timeout for L{smtp.SMTPSenderFactory}: the response L{Deferred}
        should be errback with a L{smtp.SMTPTimeoutError}.
        �source@addresssrecipient@address�Message bodyrr���retries�timeout�rrRr�SMTPSenderFactoryrr��r0r�r�s   r)�test_SMTPClientRecipientBytesz*TimeoutTests.test_SMTPClientRecipientBytes�sL��
���!���.�.�� ��O�$����

�
�� � ���7�7r+c��tj�}tjddt	d�|dd��}|j||�S)z-
        Use a L{unicode} recipient.
        r��recipient@addressr�rr�r�r�r�s   r)�test_SMTPClientRecipientUnicodez,TimeoutTests.test_SMTPClientRecipientUnicode�sL�����!���.�.����O�$����

�
�� � ���7�7r+c��tj�}tjddt	d�|dd��}|j||�S)z.
        Use a L{list} of recipients.
        r�)zrecipient1@addresssrecipient2@addressr�rr�r�r�r�s   r)�test_SMTPClientRecipientListz)TimeoutTests.test_SMTPClientRecipientList�sL�����!���.�.��9��O�$����

�
�� � ���7�7r+c
��tj�}tjddddt	d�|dd��}|j||�S)	z�
        Test timeout for L{smtp.ESMTPSenderFactory}: the response L{Deferred}
        should be errback with a L{smtp.SMTPTimeoutError}.
        r�passwordr�r�r�rr�r�)rrRr�ESMTPSenderFactoryrr�r�s   r)�test_ESMTPClientzTimeoutTests.test_ESMTPClient�sR��
���!���/�/������O�$����	
�
�� � ���7�7r+c��Gd�d�}g}tj�}|j|j�t	j
dd|d�|dd��}d	|_tj�}|jtjd
dd��}|j|_t�}|j|�|jd
�|j!|j"d�|j%|j&�|j)d�|j+|g�|j"j-�|j)d�|j+|g�|j"j-�|jd�|j+|g�|j+|j/�d�y)z�
        The timeout is not allowed to expire after the server has accepted a
        DATA command and the client is actively sending data to it.
        c��eZdZdZd�Zdd�Zy)�<TimeoutTests.test_resetTimeoutWhileSending.<locals>.SlowFilez�
            A file-like which returns one byte from each read call until the
            specified number of bytes have been returned.
            c��||_yr%��_size)r0�sizes  r)r2zETimeoutTests.test_resetTimeoutWhileSending.<locals>.SlowFile.__init__s	��!��
r+Nc�H�|jr|xjdzc_yy)Nrf�xr+r�)r0�maxs  r)�readzATimeoutTests.test_resetTimeoutWhileSending.<locals>.SlowFile.reads���:�:��J�J�!�O�J��r+r%)r>r?r@rAr2r�r&r+r)�SlowFiler�s��
�

"�
r+r�r�r�rfrr�r��example.orgr�r�r�r�Nrgs250 Ok
s]HELO example.org
MAIL FROM:<source@address>
RCPT TO:<recipient@address>
DATA
x
.
RSET
)rrR�
addErrbackrJrr�rErr�r�rr�r�rr�r�r�r�r�r�r�r��resumeProducingr�)r0r��failedr�r�r�r�r�s        r)�test_resetTimeoutWhileSendingz*TimeoutTests.test_resetTimeoutWhileSendings���
	�
	������!�����&�-�-�(��.�.����Q�K����

�
� .�
���
�
����,�,�����}�b�9�
��!�?�?���#�%�	����i�(����
�	
�	
���	� 2� 2�D�9�����,�,�-�	�
�
�a��	
�����$�	���*�*�,�
�
�
�a�������$�	���*�*�,����M�*������$�	
����O�O��
�	
r+N)
r>r?r@rAr�r�r�r�r�r�r&r+r)r�r��s&����.8� 
8�
8�8�$W
r+r�c��eZdZdZd�Zd�Zy)�(MultipleDeliveryFactorySMTPServerFactorya
    L{MultipleDeliveryFactorySMTPServerFactory} creates SMTP server protocol
    instances with message delivery factory objects supplied to it.  Each
    factory is used for one connection and then discarded.  Factories are used
    in the order they are supplied.
    c��||_yr%)�_messageFactories)r0�messageFactoriess  r)r2z1MultipleDeliveryFactorySMTPServerFactory.__init__ps
��!1��r+c��tjj||�}t|jjd��|_|S)Nr)r�
ServerFactoryr�r�r�r�r�)r0�addrrHs   r)r�z6MultipleDeliveryFactorySMTPServerFactory.buildProtocolss<���"�"�0�0��t�<��#�D�$:�$:�$>�$>�q�$A�B��
��r+N)r>r?r@rAr2r�r&r+r)r�r�hs���2�r+r�c��eZdZdZd�Zd�Zy)�SMTPSenderFactoryTestsz.
    Tests for L{smtp.SMTPSenderFactory}.
    c�N�t�}tj�}tjddtd�|�}|jdd|�}|jd�|j|tjd��|j|jd�y)zt
        L{smtp.SMTPSenderFactory} removes the current protocol when the client
        connection is lost.
        r�r��message�	localhostr�N�Bye.)
rrrRrr�r�
connectTCPr��clientConnectionLostr�ConnectionDoner��currentProtocol�r0r�sentDeferredr��	connectors     r)�2test_removeCurrentProtocolWhenClientConnectionLostzISMTPSenderFactoryTests.test_removeCurrentProtocolWhenClientConnectionLost~s���
 �/���~�~�'���.�.��1�7�:�3F��
�
�'�G�&�&�{�B�
�F�	��#�#�D�)��*�*�9�e�6J�6J�6�6R�S�����6�6��=r+c�N�t�}tj�}tjddtd�|�}|jdd|�}|jd�|j|tjd��|j|jd�y)zv
        L{smtp.SMTPSenderFactory} removes the current protocol when the client
        connection is failed.
        r�r�r�r�r�Nr�)
rrrRrr�rr�r��clientConnectionFailedrr�r�r�r�s     r)�4test_removeCurrentProtocolWhenClientConnectionFailedzKSMTPSenderFactoryTests.test_removeCurrentProtocolWhenClientConnectionFailed�s���
 �/���~�~�'���.�.��1�7�:�3F��
�
�'�G�&�&�{�B�
�F�	��#�#�D�)��,�,�Y��8L�8L�V�8T�U�����6�6��=r+N)r>r?r@rAr�r�r&r+r)r�r�ys���
>�
>r+r�c��eZdZdZd�Zy)�SMTPSenderFactoryRetryTestszD
    Tests for the retry behavior of L{smtp.SMTPSenderFactory}.
    c�\��	�
��d�d�
t�g��	G�fd�dtj�}tt�	fd�g�}||_t
jd|d��}|j�}�j|j�tj�}tjd	�d
zt�
�|�}d|_t
j |j"|j$|�}�j|j&��	�
��fd�}|j)|�|S)
z�
        If the protocol created by L{SMTPSenderFactory} loses its connection
        before receiving confirmation of message delivery, it reconnects and
        tries to deliver the message again.
        salicessome message textc���eZdZdZ�fd�Zy)�HSMTPSenderFactoryRetryTests.test_retryAfterDisconnect.<locals>.CleanSMTPz�
            An SMTP subclass which ensures that its transport will be
            disconnected before the test ends.
            c�|���j|j�tjj	||�yr%)�
addCleanupr�rr�r�)�	innerSelfr�r0s  �r)r�zWSMTPSenderFactoryRetryTests.test_retryAfterDisconnect.<locals>.CleanSMTP.makeConnection�s)������	� 8� 8�9��	�	�(�(��I�>r+N)r>r?r@rAr�r:s�r)�	CleanSMTPr��s
���
�

?r+r�c���t�|�Sr%r])r1rEs �r)r^zGSMTPSenderFactoryRetryTests.test_retryAfterDisconnect.<locals>.<lambda>�s����f�d�)C�r+r�	127.0.0.1)�	interfacesbob@example.orgs@example.comr�c����j�j�d�zdzgi��jt�jt��d�y)z�
            Verify that the message was successfully delivered and flush the
            error which caused the first attempt to fail.
            rLrfN)r�rOrn�flushLoggedErrorsr9)r�rErT�	recipientr0s ����r)�cbSentzESMTPSenderFactoryRetryTests.test_retryAfterDisconnect.<locals>.cbSent�sJ���

���V�_�_�y�5�7�?�U�;R�:S�.T�U����S��!7�!7��!E�F��Jr+)rWrr�r�r-rr�	listenTCP�getHostr��
stopListeningrrRr�rrEr��host�port�
disconnectr�)r0r��
serverFactory�
serverPort�
serverHostr�r��clientConnectorr�rErTr�s`        @@@r)�test_retryAfterDisconnectz5SMTPSenderFactoryRetryTests.test_retryAfterDisconnect�s����	�&���i�[�)��	?��	�	�	?�A�
�C�D�
�
�"+�
���&�&�q�-�;�O�
��'�'�)�
����
�0�0�1��~�~�'���.�.����'��G���	
�
� .�
��!�,�,��O�O�Z�_�_�m�
��	
����2�2�3�	K�	� � ��(��r+N)r>r?r@rAr�r&r+r)r�r��s���8r+r�c��eZdZdZd�Zd�Zy)�SingletonRealmz�
    Trivial realm implementation which is constructed with an interface and an
    avatar and returns that avatar when asked for that interface.
    c� �||_||_yr%�r��avatar)r0r�rs   r)r2zSingletonRealm.__init__�s��"�����r+c�R�|D]"}||jus�||jd�fcSy)Nc��yr%r&r&r+r)r^z.SingletonRealm.requestAvatar.<locals>.<lambda>�r7r+r)r0r9r:r�ifaces     r)r;zSingletonRealm.requestAvatar�s.���	8�E�����&��d�k�k�<�7�7�	8r+N)r>r?r@rAr2r;r&r+r)rr�s���
�8r+rc�"�eZdZdZd�Zd�Zd�Zy)�NotImplementedDeliveryz�
    Non-implementation of L{smtp.IMessageDelivery} which only has methods which
    raise L{NotImplementedError}.  Subclassed by various tests to provide the
    particular behavior being tested.
    c��td���Nz3This oughtn't be called in the course of this test.��NotImplementedErrorr�s   r)r�z#NotImplementedDelivery.validateFrom����!�"W�X�Xr+c��td��r
rr/s  r)r�z!NotImplementedDelivery.validateTo�r
r+c��td��r
rr/s    r)r�z%NotImplementedDelivery.receivedHeader�r
r+N)r>r?r@rAr�r�r�r&r+r)rr�s���Y�Y�Yr+rc�t�eZdZdZej
fd�Zd�Zd�Zd�Z	d�Z
d�Zd�Ze
e�d	��Zd
�Zy)�SMTPServerTestsza
    Test various behaviors of L{twisted.mail.smtp.SMTP} and
    L{twisted.mail.smtp.ESMTP}.
    c���|�}d|_t�}|j|�|jt	j
��|j
d|j��y)zb
        Test that the specified hostname shows up in the SMTP server's
        greeting.
        sexample.comN)r�rr�r=rr��assertInr�)r0r��sr�s    r)�testSMTPGreetingHostz$SMTPServerTests.testSMTPGreetingHostsS��

�M��������	�����	����-�-�/�0��
�
�n�a�g�g�i�0r+c���tj�}t�}|j|�|j	tj��|jd|j��y)z�
        Test that the string "ESMTP" does not appear in the SMTP server's
        greeting since that string strongly suggests the presence of support
        for various SMTP extensions which are not supported by L{smtp.SMTP}.
        �ESMTPN)	rr�rr�r=rr��assertNotInr��r0rr�s   r)�testSMTPGreetingNotExtendedz+SMTPServerTests.testSMTPGreetingNotExtendedsR��
�I�I�K�����	�����	����-�-�/�0�����1�7�7�9�-r+c�B�|jtj�y)zS
        Similar to testSMTPGreetingHost, but for the L{smtp.ESMTP} class.
        N)rrr�r:s r)�testESMTPGreetingHostz%SMTPServerTests.testESMTPGreetingHosts��	
�!�!�$�*�*�-r+c���tj�}t�}|j|�|j	tj��|jd|j��y)z�
        Test that the string "ESMTP" does appear in the ESMTP server's
        greeting since L{smtp.ESMTP} does support the SMTP extensions which
        that advertises to the client.
        rN)	rr�rr�r=rr�rr�rs   r)�testESMTPGreetingExtendedz)SMTPServerTests.testESMTPGreetingExtended#sP��
�J�J�L�����	�����	����-�-�/�0��
�
�h����	�*r+c�
�tj�}t�}|j|�|j	d�|jt
j��|jd|j��y)zN
        Sending an unimplemented command is responded to with a 500.
        sDOAGOODTHINGs500 Command not implementedN)
rr�rr�r7r=rr�rr�rs   r)�test_SMTPUnknownCommandz'SMTPServerTests.test_SMTPUnknownCommand/s]��
�I�I�K�����	�����	����'�	����-�-�/�0��
�
�4�a�g�g�i�@r+c���Gd�dt�}ttj|��}t	|t�g�}tj�}||_t�}|j|�|jd�|j�|jd�|jtj��|j|j!�d�y)z�
        Test that a C{MAIL FROM} command with an acceptable address is
        responded to with the correct success code.
        c��eZdZdZd�Zy)�DSMTPServerTests.test_acceptSenderAddress.<locals>.AcceptanceDeliveryzM
            Delivery object which accepts all senders as valid.
            c��|Sr%r&r�s   r)r�zQSMTPServerTests.test_acceptSenderAddress.<locals>.AcceptanceDelivery.validateFromEs���
r+N�r>r?r@rAr�r&r+r)�AcceptanceDeliveryr#@s��
�
r+r&�HELO example.com
�MAIL FROM:<alice@example.com>
s250 Sender address accepted
N�rrrr8rrr�rArr�r�r�r=r�ConnectionLostr�r�)r0r&rGrAr��transs      r)�test_acceptSenderAddressz(SMTPServerTests.test_acceptSenderAddress:s���	�!7�	��t�4�4�6H�6J�K���� 4� 6�7�8���	�	�������!��
���U�#�	���2�3�
���
�	���?�@�	���U�1�1�3�4�	
�������(J�Kr+c���Gd�dt�}ttj|��}t	|t�g�}tj�}||_t�}|j|�|jd�|j�|jd�|jtj��|j|j!�d�y)z�
        Test that a C{MAIL FROM} command with an address rejected by a
        L{smtp.IMessageDelivery} instance is responded to with the correct
        error code.
        c��eZdZdZd�Zy)�MSMTPServerTests.test_deliveryRejectedSenderAddress.<locals>.RejectionDeliveryzO
            Delivery object which rejects all senders as invalid.
            c�,�tj|��r%)r�
SMTPBadSenderr�s   r)r�zZSMTPServerTests.test_deliveryRejectedSenderAddress.<locals>.RejectionDelivery.validateFromis���(�(��0�0r+Nr%r&r+r)�RejectionDeliveryr/ds��
�
1r+r2r'r(�V550 Cannot receive from specified address <alice@example.com>: Sender not acceptable
Nr))r0r2rGrAr�r+s      r)�"test_deliveryRejectedSenderAddressz2SMTPServerTests.test_deliveryRejectedSenderAddress]s���	1� 6�	1��t�4�4�6G�6I�J���� 4� 6�7�8���	�	�������!��
���U�#�	���2�3�
���
�	���?�@�	���U�1�1�3�4�	
����K�K�M�
>�	
r+c���Gd�d�}ttjt��}t	||�g�}tj
�}||_t�}|j|�|jd�|j�|jd�|jtj��|j|j�d�y)z�
        Test that a C{MAIL FROM} command with an address rejected by an
        L{smtp.SMTP} instance's portal is responded to with the correct error
        code.
        c��eZdZdZefZd�Zy)�QSMTPServerTests.test_portalRejectedSenderAddress.<locals>.DisallowAnonymousAccesszZ
            Checker for L{IAnonymous} which rejects authentication attempts.
            c�<�tjt��Sr%)rr`rr!s  r)r#zaSMTPServerTests.test_portalRejectedSenderAddress.<locals>.DisallowAnonymousAccess.requestAvatarId�s���z�z�"3�"5�6�6r+N)r>r?r@rArr(r#r&r+r)�DisallowAnonymousAccessr7�s��
�%/�=� �
7r+r9r'r(r3N�rrr8rrr�rArr�r�r�r=rr*r�r�)r0r9rGrAr�r+s      r)� test_portalRejectedSenderAddressz0SMTPServerTests.test_portalRejectedSenderAddress�s���	7�	7��t�4�4�6L�6N�O���� 7� 9�:�;���	�	�������!��
���U�#�	���2�3�
���
�	���?�@�	���U�1�1�3�4�	
����K�K�M�
>�	
r+c��ttjt��}t	|g�}tj
�}||_t�}|j|�|jd�|j�|jd�|jtj��|j|j�d�y)z�
        Test that a C{MAIL FROM} command issued without first authenticating
        when a portal has been configured to disallow anonymous logins is
        responded to with the correct error code.
        r'r(sd550 Cannot receive from specified address <alice@example.com>: Unauthenticated senders not allowed
Nr:)r0rGrAr�r+s     r)�"test_portalRejectedAnonymousSenderz2SMTPServerTests.test_portalRejectedAnonymousSender�s����t�4�4�6L�6N�O����r�"���	�	�������!��
���U�#�	���2�3�
���
�	���?�@�	���U�1�1�3�4�	
����K�K�M�
L�	
r+N)r>r?r@rArr�rrrrr r,r4r
r
r;r=r&r+r)rr�sW���
04�y�y�
1�
.�.�
+�	A�!L�F&
�P�$�%�(
�&�(
�T
r+rc�^�eZdZd�Z	dd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zy)�ESMTPAuthenticationTestsc���|jj�|jj|�|j	||jj�j
��y)z�
        Assert that when the given bytes are delivered to the ESMTP server
        instance, it responds with the indicated lines.

        @type bytes: str
        @type response: list of str
        N)r�r�r�r�r�r�r)r0r��responses   r)�assertServerResponsez-ESMTPAuthenticationTests.assertServerResponse�sL��	
��������� � ��'�����4�>�>�#7�#7�#9�#D�#D�#F�Gr+c��|j�\}}}}|j|g�|jtjj
jj|��|j|j|�|j|j|��|jtj|�|jtj|�|jtjdd�f�|jdg|jj!�j#��y)a�
        Assert that a login attempt has been made, that the credentials and
        interfaces passed to it are correct, and that when the login request
        is satisfied, a successful response is sent by the ESMTP server
        instance.

        @param loginArgs: A C{list} previously passed to L{portalFactory}.
        @param username: The login user.
        @param password: The login password.
        Nc��yr%r&r&r+r)r^zDESMTPAuthenticationTests.assertServerAuthenticated.<locals>.<lambda>�r7r+s235 Authentication successful.)r�r�r��twistedrr"r&�
providedByrrrr�IMessageDeliveryFactoryr8rSr�r�r)r0�	loginArgsrr�r�r"r:rs        r)�assertServerAuthenticatedz2ESMTPAuthenticationTests.assertServerAuthenticated�s���,5�=�=�?�(��;��j�����B�'�����L�L�$�$�6�6�A�A�+�N�	
�	
����-�-�x�8�����1�1�(�;�<��
�
�d�2�2�J�?��
�
�d�+�+�Z�8�	�
�
�D�0�0�$��E�F����
.�/����1E�1E�1G�1R�1R�1T�	
r+c��tjdti�|_d|j_tt
jddd���|_|jj|j�y)zI
        Create an ESMTP instance attached to a StringTransport.
        rLs	localhostr�r�i90)�peerAddressN)
rr�rr�r�rrr�r�r�r:s r)�setUpzESMTPAuthenticationTests.setUp�s\���j�j�(�,<�!=�>���'�����(��+�+�E�;��F�
���	
���"�"�4�>�>�2r+c�^�|jjtj��y)zT
        Disconnect the ESMTP instance to clean up its timeout DelayedCall.
        N)r�r=rr�r:s r)�tearDownz!ESMTPAuthenticationTests.tearDowns��	
���"�"�5�#7�#7�#9�:r+c�*��G�fd�d�}|�S)Nc���eZdZ�fd�Zy)�;ESMTPAuthenticationTests.portalFactory.<locals>.DummyPortalc�Z��tj�}�j||||f�|Sr%)rrRrJ)r0r"r:rr��	loginLists     �r)�loginzAESMTPAuthenticationTests.portalFactory.<locals>.DummyPortal.logins+����N�N�$��� � �!�[�$�
�!C�D��r+N)r>r?r@rT)rSs�r)�DummyPortalrQs���
r+rUr&)r0rSrUs ` r)�
portalFactoryz&ESMTPAuthenticationTests.portalFactory
s���	�	��}�r+c�H�|jj�|jjd�|jj	�j�}|j
|dd�|j
|dd�|j
t|�d�y)zV
        Test that AUTH is advertised to clients which issue an EHLO command.
        �EHLO
rs/250-localhost Hello 127.0.0.1, nice to meet yourfs250 AUTH LOGINrgN)r�r�r�r�r�rr�rn)r0�
responseLiness  r)�'test_authenticationCapabilityAdvertisedz@ESMTPAuthenticationTests.test_authenticationCapabilityAdvertiseds���	
��������� � ��-����,�,�.�9�9�;�
�����!��P�	
�	
����q�)�+<�=�����]�+�Q�/r+c�H�g}|j|�|j_|jjd�|jj�|j
ddtjd�j�zg�|j
tjd�dzdtjd�j�zg�|j
tjd�j�dzg�|j|�y	)
zJ
        Test that the LOGIN authentication mechanism can be used
        rX�AUTH LOGIN
�334 �
User Name�usernamer��	Password�passwordN�rVr�rAr�r�r�rB�base64�	b64encode�striprI�r0rHs  r)�test_plainAuthenticationz1ESMTPAuthenticationTests.test_plainAuthentication s����	�!�/�/�	�:�������� � ��-��������!�!���&�*:�*:�>�*J�*P�*P�*R� R�S�	
�	
�!�!����[�)�G�3�
�v�'�'�
�6�<�<�>�
>�?�	
�
	
�!�!�&�"2�"2�;�"?�"E�"E�"G�'�"Q�SU�V��&�&�y�1r+c��g}|j|�|j_|jjd�|jj�|j
ddtjd�j�zg�|j
tjd�dzdtjd�j�zg�|j
dg�|j|d�	�y
)zM
        Test that giving an empty password for plain auth succeeds.
        rXr\r]r^r_r�r`r+)r�Nrbrfs  r)�%test_plainAuthenticationEmptyPasswordz>ESMTPAuthenticationTests.test_plainAuthenticationEmptyPassword7s����	�!�/�/�	�:�������� � ��-��������!�!���&�*:�*:�>�*J�*P�*P�*R� R�S�	
�	
�!�!����[�)�G�3�
�v�'�'�
�6�<�<�>�
>�?�	
�
	
�!�!�'�2�.��&�&�y�3�&�?r+c��g}|j|�|j_|jjd�|jj�|j
dtjd�j�zdzdtjd�j�zg�|j
tjd�j�dzg�|j|�y)	z�
        The response to the first challenge may be included on the AUTH command
        line.  Test that this is also supported.
        rX�AUTH LOGIN r_r�r]r`raNrbrfs  r)�'test_plainAuthenticationInitialResponsez@ESMTPAuthenticationTests.test_plainAuthenticationInitialResponseMs���
�	�!�/�/�	�:�������� � ��-��������!�!��V�-�-�k�:�@�@�B�B�W�L�
�v�'�'�
�6�<�<�>�
>�?�	
�
	
�!�!�&�"2�"2�;�"?�"E�"E�"G�'�"Q�SU�V��&�&�y�1r+c���g}|j|�|j_|jjd�|jjd�|j	ddg�y)zW
        Test that a challenge/response sequence can be aborted by the client.
        rXr\s*
s501 Authentication abortedN)rVr�rAr�rBrfs  r)�test_abortAuthenticationz1ESMTPAuthenticationTests.test_abortAuthenticationasY���	�!�/�/�	�:�������� � ��-���� � �!2�3��!�!�(�-J�,K�Lr+c��g}|j|�|j_|jjd�|jjd�|j	ddg�|j|g�y)zz
        Test that a response which is not properly Base64 encoded results in
        the appropriate error code.
        rXr\sx
�+501 Syntax error in parameters or argumentsN�rVr�rAr�rBr�rfs  r)�!test_invalidBase64EncodedResponsez:ESMTPAuthenticationTests.test_invalidBase64EncodedResponsemsn��
�	�!�/�/�	�:�������� � ��-���� � �!2�3��!�!��E�F�	
�	
����B�'r+c���g}|j|�|j_|jjd�|j	ddg�|j|g�y)z�
        Like L{test_invalidBase64EncodedResponse} but for the case of an
        initial response included with the C{AUTH} command.
        rXsAUTH LOGIN x
rpNrqrfs  r)�(test_invalidBase64EncodedInitialResponsezAESMTPAuthenticationTests.test_invalidBase64EncodedInitialResponse~s[��
�	�!�/�/�	�:�������� � ��-��!�!��"P�!Q�	
�	
����B�'r+c���g}|j|�|j_|jjd�|jj�|j
dtjd�j�zdzdtjd�j�zg�|j
tjd�j�dzg�|j�\}}}}|jtd��|jd	|jj��|jt|j!t��d
�y)z�
        If the L{Deferred} returned by L{Portal.login} fires with an
        exception of any type other than L{UnauthorizedLogin}, the exception
        is logged and the client is informed that the authentication attempt
        has failed.
        rXrkr_r�r]r`razSomething wrong with the servers9451 Requested action aborted: local error in processing
rfN)rVr�rAr�r�r�rBrcrdrer��errbackr9r�r�rnr�)r0rHr�r"r:rs      r)�test_unexpectedLoginFailurez4ESMTPAuthenticationTests.test_unexpectedLoginFailure�s%���	�!�/�/�	�:�������� � ��-��������!�!��V�-�-�k�:�@�@�B�B�W�L�
�v�'�'�
�6�<�<�>�
>�?�	
�	
�!�!�&�"2�"2�;�"?�"E�"E�"G�'�"Q�SU�V�+4�=�=�?�(��;��j�	�	�	�,�@�A�B����J��N�N� � �"�	
�
	
����T�3�3�L�A�B�A�Fr+N)r_ra)r>r?r@rBrIrLrNrVrZrgrirlrnrrrtrwr&r+r)r?r?�sM��
H�9D�
�8	3�;��0�2�.@�,2�(
M�(�"
(�Gr+r?c�"�eZdZdZd�Zd�Zd�Zy)�SMTPClientErrorTestsz,
    Tests for L{smtp.SMTPClientError}.
    c�f�tjdd�}|jt|�d�y)z�
        The string representation of a L{SMTPClientError} instance includes
        the response code and response string.
        r�z	some textz
123 some textN�rr�r�rg�r0�errs  r)�test_strzSMTPClientErrorTests.test_str�s*��
�"�"�3��4������S��?�3r+c�f�tjdd�}|jt|�d�y)z�
        If the response code supplied to L{SMTPClientError} is negative, it
        is excluded from the string representation.
        ���sfoo barzfoo barNr{r|s  r)�test_strWithNegativeCodez-SMTPClientErrorTests.test_strWithNegativeCode�s*��
�"�"�2�z�2������S��9�-r+c���td�}|jd�|jd�tjdd|j	���}|jt	|�d�y)	z�
        If a line log is supplied to L{SMTPClientError}, its contents are
        included in the string representation of the exception instance.
        �
stestlogs
secondline�dz
test error)r}z"100 test error
testlog
secondline
N)rrJrr�rgr�)r0r}r}s   r)�test_strWithLogz$SMTPClientErrorTests.test_strWithLog�sT��
�b�k���
�
�:���
�
�=�!��"�"�3��#�'�'�)�D������S��#P�Qr+N)r>r?r@rAr~r�r�r&r+r)ryry�s���4�.�	Rr+ryc��eZdZdZd�Zy)�SenderMixinSentMailTestsz�
    Tests for L{smtp.SenderMixin.sentMail}, used in particular by
    L{smtp.SMTPSenderFactory} and L{smtp.ESMTPSenderFactory}.
    c�n���jtj�tj�}|j�fd��tjddtd�|dd��}|jtjdd	d
��}ddg}|jd
dd||j�|S)z�
        L{smtp.SenderMixin.sentMail} adds only the addresses with failing
        SMTP response codes to the log passed to the factory's errback.
        c�<���j|jd�S)Ns'bob@example.com: 199 Error in sending.
)r�r})rcr0s �r)r^zFSenderMixinSentMailTests.test_onlyLogFailedAddresses.<locals>.<lambda>�s���d�&�&����B��r+r�r�r�rr�r�r�r�r�)salice@example.com��sNo errors here!)sbob@example.com��sError in sending.r�s
Test responserf)
r�rrRr�SMTPDeliveryErrorr�r�rr�rr�r~r})r0r�r�r�r|s`    r)�test_onlyLogFailedAddressesz4SenderMixinSentMailTests.test_onlyLogFailedAddresses�s����
�#�#�E�N�N�$4�d�6L�6L�M�����
�	
��.�.����O�$����

�
��,�,�����}�b�9�
��

<�;�
�	�	����-�q�)�V�Z�Z�H��
r+N)r>r?r@rAr�r&r+r)r�r��s���
r+r�c�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�ESMTPDowngradeTestCasezU
    Tests for the ESMTP -> SMTP downgrade functionality in L{smtp.ESMTPClient}.
    c�<�tjddd�|_y)Nrr)rr��clientProtocolr:s r)rLzESMTPDowngradeTestCase.setUp�s��"�.�.���k�R��r+c��t�}d|j_d|j_d|j_|jj|�|jj
d�|j�|jj
d�|jd|j��y)z�
        If both authentication and transport security are not required, and it
        is asked for, it will fall back to allowing HELO.
        FT�220 localhost
�500 not an esmtp server
�HELO testuser
N�
rr��requireAuthentication�requireTransportSecurity�heloFallbackr�r�r�r�r��r0r�s  r)� test_requireHELOFallbackOperatesz7ESMTPDowngradeTestCase.test_requireHELOFallbackOperates�s���
$�%�	�49����1�7<����4�+/����(����*�*�9�5����(�(�)=�>��������(�(�)G�H����-�y���/@�Ar+c��t�}d|j_d|j_d|j_|jj|�|jj
d�|j�|jj
d�|jd|j��y)z�
        If authentication is required, and HELO fallback is on, HELO fallback
        must not be honoured, as authentication requires EHLO to succeed.
        TFr�r�r�Nr�r�s  r)�!test_requireAuthFailsHELOFallbackz8ESMTPDowngradeTestCase.test_requireAuthFailsHELOFallbacks���
$�%�	�48����1�7<����4�+/����(����*�*�9�5����(�(�)=�>��������(�(�)G�H�����i�o�o�&7�8r+c��t�}d|j_d|j_d|j_|jj|�|jj
d�|j�|jj
d�|jd|j��y)z�
        If TLS is required and the connection is insecure, HELO fallback must
        not be honoured, as STARTTLS requires EHLO to succeed.
        FTr�r�r�Nr�r�s  r)� test_requireTLSFailsHELOFallbackz7ESMTPDowngradeTestCase.test_requireTLSFailsHELOFallbacks���
$�%�	�49����1�7;����4�+/����(����*�*�9�5����(�(�)=�>��������(�(�)G�H�����i�o�o�&7�8r+c��t�}t|tj�d|j_d|j_d|j_|jj|�|jjd�|j�|jjd�|jd|j��y)z�
        If TLS is provided at the transport level, we can honour the HELO
        fallback if we're set to require TLS.
        FTr�r�r�N)
rr	r�
ISSLTransportr�r�r�r�r�r�r�r�r�r�s  r)�/test_requireTLSAndHELOFallbackSucceedsIfOverTLSzFESMTPDowngradeTestCase.test_requireTLSAndHELOFallbackSucceedsIfOverTLS,s���
$�%�	���J�$<�$<�=�49����1�7;����4�+/����(����*�*�9�5����(�(�)=�>��������(�(�)G�H����-�y���/@�Ar+N)	r>r?r@rArLr�r�r�r�r&r+r)r�r��s#���S�B� 9� 9� Br+r�c�R�eZdZdZeZdZdZd�Zd�Z	d�Z
d�Zd�Zd	�Z
d
�Zd�Zd�Zy
)�SSLTestCasezD
    Tests for the TLS negotiation done by L{smtp.ESMTPClient}.
    s3220 localhost NO UCE NO UBE NO RELAY PROBES ESMTP
s1250-localhost Hello 127.0.0.1, nice to meet you
c��tjdt�d�|_d|j_d�|j_y)NrrTc��y)Nztest@example.orgr&r&r+r)r^z#SSLTestCase.setUp.<locals>.<lambda>Mr7r+)rr�r"r�r�ror:s r)rLzSSLTestCase.setUpHs>��"�.�.��-�/��
���8<����4�*D����'r+c�|�t�}t|tj�|jj|�|jj
|j�|j�|jj
|j|z�|jd|j��y)a�
        Verify that when L{smtp.ESMTPClient} connects to a server over a
        transport providing L{ISSLTransport}, C{requireTransportSecurity} is
        C{True}, and it is presented with the given capabilities, it will try
        to send its mail and not first attempt to negotiate TLS using the
        I{STARTTLS} protocol action.

        @param capabilities: Bytes to include in the test server's capability
            response.  These must be formatted exactly as required by the
            protocol, including a line which ends the capability response.
        @type param: L{bytes}

        @raise: C{self.failureException} if the behavior of
            C{self.clientProtocol} is not as described.
        sMAIL FROM:<test@example.org>
N)rr	rr�r�r�r��SERVER_GREETINGr��
EHLO_RESPONSEr�r�)r0�capabilitiesr�s   r)�$_requireTransportSecurityOverSSLTestz0SSLTestCase._requireTransportSecurityOverSSLTestOs��� $�%�	���J�$<�$<�=����*�*�9�5�	
���(�(��)=�)=�>�����	
���(�(��);�);�l�)J�K�	
���<�i�o�o�>O�Pr+c�&�|jd�y)z�
        When C{requireTransportSecurity} is C{True} and the client is connected
        over an SSL transport, mail may be delivered.
        �250 AUTH LOGIN
N�r�r:s r)�$test_requireTransportSecurityOverSSLz0SSLTestCase.test_requireTransportSecurityOverSSLns��
	
�1�1�2G�Hr+c�H�t�}|jj|�|jj|j�|j�|jj|jdz�|jd|j��y)z�
        When C{requireTransportSecurity} is C{True} and the client is connected
        over a non-SSL transport, if the server offers the I{STARTTLS}
        extension, it is used before mail is delivered.
        �250-AUTH LOGIN
250 STARTTLS
s
STARTTLS
N�	rr�r�r�r�r�r�r�r�r�s  r)�'test_requireTransportSecurityTLSOfferedz3SSLTestCase.test_requireTransportSecurityTLSOfferedus���$�%�	����*�*�9�5�	
���(�(��)=�)=�>�����	
���(�(����!J�J�	
�
	
����)�/�/�*;�<r+c�&�|jd�y)z�
        When C{requireTransportSecurity} is C{True} and the client is connected
        over an SSL transport, if the server offers the I{STARTTLS}
        extension, it is not used before mail is delivered.
        r�Nr�r:s r)�.test_requireTransportSecurityTLSOfferedOverSSLz:SSLTestCase.test_requireTransportSecurityTLSOfferedOverSSL�s��	
�1�1�5�	
r+c�H�t�}|jj|�|jj|j�|j�|jj|jdz�|jd|j��y)z�
        When C{requireTransportSecurity} is C{True} and the client is connected
        over a non-SSL transport, if the server does not offer the I{STARTTLS}
        extension, mail is not delivered.
        r�r�Nr�r�s  r)�*test_requireTransportSecurityTLSNotOfferedz6SSLTestCase.test_requireTransportSecurityTLSNotOffered�s���$�%�	����*�*�9�5�	
���(�(��)=�)=�>�����	
���(�(��);�);�>S�)S�T�	
����i�o�o�&7�8r+c�
�|jj}~|j|jg��}|j	t|�d�|j
|ddt�|j	|ddd�y)�<
        L{smtp.ESMTPClient.tlsMode} is deprecated.
        ��offendingFunctionsrfr�categoryrT�StlsMode attribute of twisted.mail.smtp.ESMTPClient is deprecated since Twisted 13.0N)r��tlsMode�
flushWarnings�%test_esmtpClientTlsModeDeprecationGetr�rn�assertIdentical�DeprecationWarning)r0�val�
warningsShowns   r)r�z1SSLTestCase.test_esmtpClientTlsModeDeprecationGet�s����!�!�)�)����*�*� $� J� J�K�+�
�
�	
����]�+�Q�/����]�1�-�j�9�;M�N�����!��Y�'�
/�	
r+c�8���jt�fd��y)z�
        L{smtp.ESMTPClient.__getattr__} raises an attribute error for other
        attribute names which do not exist.
        c�0���jjSr%)r��doesNotExistr:s�r)r^zQSSLTestCase.test_esmtpClientTlsModeDeprecationGetAttributeError.<locals>.<lambda>�s���$�2E�2E�2R�2R�r+N)�assertRaises�AttributeErrorr:s`r)�3test_esmtpClientTlsModeDeprecationGetAttributeErrorz?SSLTestCase.test_esmtpClientTlsModeDeprecationGetAttributeError�s���
	
���.�*R�Sr+c��d|j_|j|jg��}|j	t|�d�|j
|ddt�|j	|ddd�y)	r�Fr�rfrr�rTr�N)r�r�r��%test_esmtpClientTlsModeDeprecationSetr�rnr�r�)r0r�s  r)r�z1SSLTestCase.test_esmtpClientTlsModeDeprecationSet�s���',����#��*�*� $� J� J�K�+�
�
�	
����]�+�Q�/����]�1�-�j�9�;M�N�����!��Y�'�
/�	
r+N)r>r?r@rAr!r�r�r�rLr�r�r�r�r�r�r�r�r&r+r)r�r�>sI����D�N�O�J�M�E�Q�>I�=�*
�9�&
�"T�
r+r�c��eZdZdZdZd�Zy)�AbortableStringTransportzK
    A version of L{StringTransport} that supports C{abortConnection}.
    Fc�2�d|_|j�y)z�
        A testable version of the C{ITCPTransport.abortConnection} method.

        Since this is a special case of closing the connection,
        C{loseConnection} is also called.
        TN)�abortingr�r:s r)�abortConnectionz(AbortableStringTransport.abortConnection�s����
����r+N)r>r?r@rAr�r�r&r+r)r�r��s���
�H�r+r�c�F�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zy)�
SendmailTestsz2
    Tests for L{twisted.mail.smtp.sendmail}.
    c��tjtj�}|d}|j	t
|d�y)z{
        The default C{reactor} parameter of L{twisted.mail.smtp.sendmail} is
        L{twisted.internet.reactor}.
        r�rgN)�inspect�getfullargspecr�sendmailr�r)r0�fullSpec�defaultss   r)�"test_defaultReactorIsGlobalReactorz0SendmailTests.test_defaultReactorIsGlobalReactor�s5��
�)�)�$�-�-�8���A�;������(�1�+�.r+c�X�t�}tjdddd|||dd��	|jdd}|j	|j
d�|j	|jd�|j	|jd	�|j	|jd
�y)zk
        L{twisted.mail.smtp.sendmail} creates the ESMTP factory with the ESMTP
        arguments.
        r�r�r�r�T)rrr�r�r�rrgr��barN)	rrr��
tcpClientsr��_requireTransportSecurity�_requireAuthenticationrr�)r0rr�rr�s     r)�_honorsESMTPArgumentsz#SendmailTests._honorsESMTPArguments�s���
 �/���
�
��������%)�"&�
	
��$�$�Q�'��*������:�:�D�A�����7�7��>�����)�)�6�2�����)�)�6�2r+c�(�|jdd��S)zw
        L{twisted.mail.smtp.sendmail} should accept C{username} and C{password}
        which are L{unicode}.
        r��bar�rr��r�r:s r)�&test_honorsESMTPArgumentsUnicodeUserPWz4SendmailTests.test_honorsESMTPArgumentsUnicodeUserPWs��
�)�)�5�5�)�I�Ir+c�(�|jdd��S)zu
        L{twisted.mail.smtp.sendmail} should accept C{username} and C{password}
        which are L{bytes}.
        r�r�r�r�r:s r)�$test_honorsESMTPArgumentsBytesUserPWz2SendmailTests.test_honorsESMTPArgumentsBytesUserPWs��
�)�)�6�F�)�K�Kr+c��t�}td�}tjddd||��|jdd}|j|j|�y)	z|
        L{twisted.mail.smtp.sendmail} will pass through the message untouched
        if it is a file-like object.
        sFile!r�r�r��rrrgN)rrrr�r��assertIs�file)r0r�messageFiler�s    r)�test_messageFilePassthroughz)SendmailTests.test_messageFilePassthroughsY��
 �/���h�'���
�
������	
��$�$�Q�'��*���
�
�g�l�l�K�0r+c���t�}tjdddd|��|jdd}|j}|jd�|j
|j�d�y)	z�
        L{twisted.mail.smtp.sendmail} will turn non-file-like objects
        (eg. strings) into file-like objects before sending.
        r�r�r�r�r�rrgN)rrr�r�r��seekr�r�)r0rr�r�s    r)�test_messageStringMadeFilez(SendmailTests.test_messageStringMadeFile(sm��
 �/���
�
������	
��$�$�Q�'��*���l�l�����������)�)�+�Z�8r+c��t�}tjdddd|d��|jdd}|j	|j
d	�y
)zk
        L{twisted.mail.smtp.sendmail} passes through the sender domain name, if
        provided.
        r�r�r�r�r�)r�senderDomainNamerrgr�N)rrr�r�r�rE)r0rr�s   r)�test_senderDomainNamez#SendmailTests.test_senderDomainName:sT��
 �/���
�
������"�
	
��$�$�Q�'��*���������0r+c��t�}tjdddd|��}|j�|j	|j
djd�|j|�}|jtj�y)	z�
        When a user cancels L{twisted.mail.smtp.sendmail} before the connection
        is made, the connection is closed by
        L{twisted.internet.interfaces.IConnector.disconnect}.
        r�r�r�r�r�rTN)rrr��cancelr��
connectors�
_disconnected�failureResultOf�trapr�CancelledError)r0rr��failures    r)�test_cancelBeforeConnectionMadez-SendmailTests.test_cancelBeforeConnectionMadeKsv�� �/���M�M������
��	
���
�����+�+�A�.�<�<�d�C��&�&�q�)�����U�)�)�*r+c��t�}t�}tjdddd|��}|jdd}|jd�}|j
|�|j�|j|jd	�|j|jd	�|j|�}|jtj�y)
z�
        When a user cancels L{twisted.mail.smtp.sendmail} after the connection
        is made, the connection is closed by
        L{twisted.internet.interfaces.ITransport.abortConnection}.
        r�r�r�r�r�rrgNT)rr�rr�r�r�r�r�r�r�r�r�r�rr�)r0rr�r�r�rHr�s       r)�test_cancelAfterConnectionMadez,SendmailTests.test_cancelAfterConnectionMade^s��� �/��,�.�	��M�M������
���$�$�Q�'��*���!�!�$�'��	����#�	���
�����+�+�T�2�����0�0�$�7��&�&�q�)�����U�)�)�*r+N)
r>r?r@rAr�r�r�r�r�r�r�r�r�r&r+r)r�r��s6���/�3�.J�L�1�$9�$1�"+�&+r+r�)krArcr�rH�ior�typingrrrrr�zope.interfacer	r
�twisted.cred.checkersrE�twisted.cred.credentials�twisted.cred.error�twisted.cred.portalrrr
rrrr�twisted.internetrrrrrrr�twisted.internet.testingrr�twisted.mailr�twisted.mail._credr�twisted.protocolsrr�twisted.python.utilr�twisted.trial.unittestr rgr
�twisted.test.ssl_helpersr"r#r!�ImportError�IReactorSSLrFr*�IMessager-rCrWrhrdr�r�r�r�r��LineReceiverr�r�r�r�r�r�r�r�r�rr�checkersrr8r�r4r=rVr{r�r�r�r�r�r�r�rrrr?ryr�r�r�r�r�r&r+r)�<module>rs���
��	��3�3�8������K�/�0�.�W�W�W�C��/�-�'�+�	�#����K��G����(�(��1�+�G��
�T�]�]��
�
��
�(��62�2�"����6-�8�T�_�_�-� �H�d�.�.� �4�4�
1�U�'�'�1�:r1�h�
�r1�j'�'�&
�
� �
�D�I�I�� ��T�Z�Z� �j�j�Z ��� �
����

�T�]�]�
.�
.�/�-�-�0�-�&
�T�
"�
"�#�2�2�$�2�&I�I�
?��-�?�D:Q�h�:Q�z�m��@�x��@�";�X�;�$s
�8�]�s
�l�x�/E�/E��"!>�X�!>�H=�(�=�@
�V��
8�
8��
8� Y�Y�"N
�h�N
�bXG�x�XG�vR�8�R�B%�x�%�PGB�X�GB�TO
�(�O
�d���&Q+�H�Q+��}5�$�#�G�$�s�!K=�=L�L
¿Qué es la limpieza dental de perros? - Clínica veterinaria


Es la eliminación del sarro y la placa adherida a la superficie de los dientes mediante un equipo de ultrasonidos que garantiza la integridad de las piezas dentales a la vez que elimina en profundidad cualquier resto de suciedad.

A continuación se procede al pulido de los dientes mediante una fresa especial que elimina la placa bacteriana y devuelve a los dientes el aspecto sano que deben tener.

Una vez terminado todo el proceso, se mantiene al perro en observación hasta que se despierta de la anestesia, bajo la atenta supervisión de un veterinario.

¿Cada cuánto tiempo tengo que hacerle una limpieza dental a mi perro?

A partir de cierta edad, los perros pueden necesitar una limpieza dental anual o bianual. Depende de cada caso. En líneas generales, puede decirse que los perros de razas pequeñas suelen acumular más sarro y suelen necesitar una atención mayor en cuanto a higiene dental.


Riesgos de una mala higiene


Los riesgos más evidentes de una mala higiene dental en los perros son los siguientes:

  • Cuando la acumulación de sarro no se trata, se puede producir una inflamación y retracción de las encías que puede descalzar el diente y provocar caídas.
  • Mal aliento (halitosis).
  • Sarro perros
  • Puede ir a más
  • Las bacterias de la placa pueden trasladarse a través del torrente circulatorio a órganos vitales como el corazón ocasionando problemas de endocarditis en las válvulas. Las bacterias pueden incluso acantonarse en huesos (La osteomielitis es la infección ósea, tanto cortical como medular) provocando mucho dolor y una artritis séptica).

¿Cómo se forma el sarro?

El sarro es la calcificación de la placa dental. Los restos de alimentos, junto con las bacterias presentes en la boca, van a formar la placa bacteriana o placa dental. Si la placa no se retira, al mezclarse con la saliva y los minerales presentes en ella, reaccionará formando una costra. La placa se calcifica y se forma el sarro.

El sarro, cuando se forma, es de color blanquecino pero a medida que pasa el tiempo se va poniendo amarillo y luego marrón.

Síntomas de una pobre higiene dental
La señal más obvia de una mala salud dental canina es el mal aliento.

Sin embargo, a veces no es tan fácil de detectar
Y hay perros que no se dejan abrir la boca por su dueño. Por ejemplo…

Recientemente nos trajeron a la clínica a un perro que parpadeaba de un ojo y decía su dueño que le picaba un lado de la cara. Tenía molestias y dificultad para comer, lo que había llevado a sus dueños a comprarle comida blanda (que suele ser un poco más cara y llevar más contenido en grasa) durante medio año. Después de una exploración oftalmológica, nos dimos cuenta de que el ojo tenía una úlcera en la córnea probablemente de rascarse . Además, el canto lateral del ojo estaba inflamado. Tenía lo que en humanos llamamos flemón pero como era un perro de pelo largo, no se le notaba a simple vista. Al abrirle la boca nos llamó la atención el ver una muela llena de sarro. Le realizamos una radiografía y encontramos una fístula que llegaba hasta la parte inferior del ojo.

Le tuvimos que extraer la muela. Tras esto, el ojo se curó completamente con unos colirios y una lentilla protectora de úlcera. Afortunadamente, la úlcera no profundizó y no perforó el ojo. Ahora el perro come perfectamente a pesar de haber perdido una muela.

¿Cómo mantener la higiene dental de tu perro?
Hay varias maneras de prevenir problemas derivados de la salud dental de tu perro.

Limpiezas de dientes en casa
Es recomendable limpiar los dientes de tu perro semanal o diariamente si se puede. Existe una gran variedad de productos que se pueden utilizar:

Pastas de dientes.
Cepillos de dientes o dedales para el dedo índice, que hacen más fácil la limpieza.
Colutorios para echar en agua de bebida o directamente sobre el diente en líquido o en spray.

En la Clínica Tus Veterinarios enseñamos a nuestros clientes a tomar el hábito de limpiar los dientes de sus perros desde que son cachorros. Esto responde a nuestro compromiso con la prevención de enfermedades caninas.

Hoy en día tenemos muchos clientes que limpian los dientes todos los días a su mascota, y como resultado, se ahorran el dinero de hacer limpiezas dentales profesionales y consiguen una mejor salud de su perro.


Limpiezas dentales profesionales de perros y gatos

Recomendamos hacer una limpieza dental especializada anualmente. La realizamos con un aparato de ultrasonidos que utiliza agua para quitar el sarro. Después, procedemos a pulir los dientes con un cepillo de alta velocidad y una pasta especial. Hacemos esto para proteger el esmalte.

La frecuencia de limpiezas dentales necesaria varía mucho entre razas. En general, las razas grandes tienen buena calidad de esmalte, por lo que no necesitan hacerlo tan a menudo e incluso pueden pasarse la vida sin requerir una limpieza. Sin embargo, razas pequeñas como el Yorkshire o el Maltés, deben hacérselas todos los años desde cachorros si se quiere conservar sus piezas dentales.

Otro factor fundamental es la calidad del pienso. Algunas marcas han diseñado croquetas que limpian la superficie del diente y de la muela al masticarse.

Ultrasonido para perros

¿Se necesita anestesia para las limpiezas dentales de perros y gatos?

La limpieza dental en perros no es una técnica que pueda practicarse sin anestesia general , aunque hay veces que los propietarios no quieren anestesiar y si tiene poco sarro y el perro es muy bueno se puede intentar…… , pero no se va a poder pulir ni acceder a todas la zona de la boca …. Además los limpiadores dentales van a irrigar agua y hay riesgo de aspiración a vías respiratorias si no se realiza una anestesia correcta con intubación traqueal . En resumen , sin anestesia no se va hacer una correcta limpieza dental.

Tampoco sirve la sedación ya que necesitamos que el animal esté totalmente quieto, y el veterinario tenga un acceso completo a todas sus piezas dentales y encías.

Alimentos para la limpieza dental

Hay que tener cierto cuidado a la hora de comprar determinados alimentos porque no todos son saludables. Algunos tienen demasiado contenido graso, que en exceso puede causar problemas cardiovasculares y obesidad.

Los mejores alimentos para los dientes son aquellos que están elaborados por empresas farmacéuticas y llevan componentes químicos con tratamientos específicos para el diente del perro. Esto implica no solo limpieza a través de la acción mecánica de morder sino también un tratamiento antibacteriano para prevenir el sarro.

Conclusión

Si eres como la mayoría de dueños, por falta de tiempo , es probable que no estés prestando la suficiente atención a la limpieza dental de tu perro. Por eso te animamos a que comiences a limpiar los dientes de tu perro y consideres atender a su higiene bucal con frecuencia.

Estas simples medidas pueden conllevar a que tu perro tenga una vida más larga y mucho más saludable.

Si te resulta imposible introducir un cepillo de dientes a tu perro en la boca, pásate con él por clínica Tus Veterinarios y te explicamos cómo hacerlo.

Necesitas hacer una limpieza dental profesional a tu mascota?
Llámanos al 622575274 o contacta con nosotros

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

¡Hola!