§
    cÌc$  ã                   óN  — d Z ddlmZmZ ddlZddlZddlZddlmZm	Z	 ddl
mZmZ  ej        ddd¬	¦  «        Z ej        d
dd¬	¦  «        Z ej        ddd¬	¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Z G d„ d¦  «        ZdS )z#A convenience class around smtplib.é    )ÚgetaddressesÚ	parseaddrNé   )ÚconfigÚosutils)ÚBzrErrorÚInternalBzrErrorÚsmtp_passwordz3Password to use for authentication to SMTP server.
)ÚdefaultÚhelpÚsmtp_serverz6Hostname of the SMTP server to use for sending email.
Úsmtp_usernamez3Username to use for authentication to SMTP server.
c                   ó   — e Zd ZdZd„ ZdS )Ú	SMTPErrorzSMTP error: %(error)sc                 ó   — || _         d S ©N)Úerror)Úselfr   s     ú8/usr/lib/python3/dist-packages/breezy/smtp_connection.pyÚ__init__zSMTPError.__init__5   s   € ØˆŒ
ˆ
ˆ
ó    N©Ú__name__Ú
__module__Ú__qualname__Ú_fmtr   © r   r   r   r   1   s(   € € € € € à"€Dðð ð ð ð r   r   c                   ó   — e Zd ZdZd„ ZdS )ÚSMTPConnectionRefusedz#SMTP connection to %(host)s refusedc                 ó"   — || _         || _        d S r   )r   Úhost)r   r   r!   s      r   r   zSMTPConnectionRefused.__init__=   s   € ØˆŒ
ØˆŒ	ˆ	ˆ	r   Nr   r   r   r   r   r   9   s(   € € € € € à0€Dðð ð ð ð r   r   c                   ó   — e Zd ZdZdS )ÚDefaultSMTPConnectionRefusedz;Please specify smtp_server.  No server at default %(host)s.N©r   r   r   r   r   r   r   r#   r#   B   s   € € € € € àH€D€D€Dr   r#   c                   ó   — e Zd ZdZdS )ÚNoDestinationAddressz,Message does not have a destination address.Nr$   r   r   r   r&   r&   G   s   € € € € € à9€D€D€Dr   r&   c                   óL   — e Zd ZdZdZd
d„Zd„ Zd„ Zd„ Ze	d„ ¦   «         Z
d	„ ZdS )ÚSMTPConnectionzëConnect to an SMTP server and send an email.

    This is a gateway between breezy.config.Config and smtplib.SMTP. It
    understands the basic bzr SMTP configuration information: smtp_server,
    smtp_username, and smtp_password.
    Ú	localhostNc                 ó  — || _         | j         €t          j        | _         || _         |j        d¦  «        | _        | j        | _        | j        €| j        | _         |j        d¦  «        | _         |j        d¦  «        | _	        d | _
        d S )Nr   r   r
   )Ú_smtp_factoryÚsmtplibÚSMTPÚ_configÚgetÚ_config_smtp_serverÚ_smtp_serverÚ_default_smtp_serverÚ_smtp_usernameÚ_smtp_passwordÚ_connection)r   r   r+   s      r   r   zSMTPConnection.__init__V   s�   € Ø*ˆÔØÔÐ%Ý!(¤ˆDÔØˆŒØ#- 6¤:¨mÑ#<Ô#<ˆÔ Ø Ô4ˆÔØÔÐ$Ø $Ô 9ˆDÔà(˜fœj¨Ñ9Ô9ˆÔØ(˜fœj¨Ñ9Ô9ˆÔàˆÔÐÐr   c                 óh   — | j         �dS |                      ¦   «          |                      ¦   «          dS )z2If we haven't connected, connect and authenticate.N)r5   Ú_create_connectionÚ_authenticate)r   s    r   Ú_connectzSMTPConnection._connecte   s<   € àÔÐ'ØˆFà×ÒÑ!Ô!Ð!ð 	×ÒÑÔÐÐÐr   c                 ó8  — 	 |                       | j        ¬¦  «        | _        ns# t          $ rf}|j        d         t
          j        k    rE| j        €t          t          j
        | j        ¦  «        ‚t          t          j
        | j        ¦  «        ‚‚ d}~ww xY w| j                             ¦   «         \  }}d|cxk    rdk    sAn | j                             ¦   «         \  }}d|cxk    rdk    sn t          d||fz  ¦  «        ‚| j                             d¦  «        r~| j                             ¦   «         \  }}d|cxk    rdk    sn t          d||fz  ¦  «        ‚| j                             ¦   «         \  }}d|cxk    rdk    sn t          d	||fz  ¦  «        ‚dS dS )
zCreate an SMTP connection.)r!   r   NéÈ   i+  zserver refused HELO: %d %sÚstarttlszserver refused STARTTLS: %d %szserver refused EHLO: %d %s)r+   r1   r5   ÚOSErrorÚargsÚerrnoÚECONNREFUSEDr0   r#   Úsocketr   r   ÚehloÚhelor   Úhas_extnr<   )r   ÚeÚcodeÚresps       r   r7   z!SMTPConnection._create_connectionp   s  € ð	Ø#×1Ò1°tÔ7HÐ1ÑIÔIˆDÔÐøÝð 		ð 		ð 		ØŒv�aŒy�EÔ.Ò.Ð.ØÔ+Ð3Ý6µv´|Ø7;Ô7HñJô Jð Jõ 0µ´Ø04Ô0AñCô Cð Cð øøøøð		øøøð Ô%×*Ò*Ñ,Ô,‰
ˆˆdØ�tÐ"Ð"Ò"Ð"˜sÒ"Ð"Ð"Ð"ØÔ)×.Ò.Ñ0Ô0‰JˆD�$Ø˜4Ð&Ð&Ò&Ð& 3Ò&Ð&Ð&Ð&ÝÐ <ÀÀd¸|Ñ KÑLÔLÐLð Ô×$Ò$ ZÑ0Ô0ð 	MØÔ)×2Ò2Ñ4Ô4‰JˆD�$Ø˜4Ð&Ð&Ò&Ð& 3Ò&Ð&Ð&Ð&ÝÐ @Ø!% t ñ!-ñ .ô .ð .ð Ô)×.Ò.Ñ0Ô0‰JˆD�$Ø˜4Ð&Ð&Ò&Ð& 3Ò&Ð&Ð&Ð&ÝÐ <ÀÀd¸|Ñ KÑLÔLÐLð	Mð 	Mð 'Ð&s   ‚ # £
B­A!BÂBc                 ó€  — t          j        ¦   «         }| j        €)|                     d| j        ¦  «        | _        | j        €dS | j        €&|                     d| j        | j        ¦  «        | _        t          j        | j        ¦  «        }t          j        | j        ¦  «        }| j	         
                    ||¦  «         dS )z1If necessary authenticate yourself to the server.NÚsmtp)r   ÚAuthenticationConfigr3   Úget_userr1   r4   Úget_passwordr   Ú	safe_utf8r5   Úlogin)r   ÚauthÚusernameÚpasswords       r   r8   zSMTPConnection._authenticate‘   s¹   € åÔ*Ñ,Ô,ˆØÔÐ&ð #'§-¢-°¸Ô8IÑ"JÔ"JˆDÔØÔ"Ð*Ø�àÔÐ&Ø"&×"3Ò"3Ø˜Ô)¨4Ô+>ñ#@ô #@ˆDÔõ Ô$ TÔ%8Ñ9Ô9ˆÝÔ$ TÔ%8Ñ9Ô9ˆàÔ×Ò˜x¨Ñ2Ô2Ð2Ð2Ð2r   c                 óö   — t          |                      dd¦  «        ¦  «        d         }g }dD ]/}|                      |d¦  «        }|r|                     |¦  «         Œ0d„ t          |¦  «        D ¦   «         }||fS )a·  Get the origin and destination addresses of a message.

        :param message: A message object supporting get() to access its
            headers, like email.message.Message or
            breezy.email_message.EmailMessage.
        :return: A pair (from_email, to_emails), where from_email is the email
            address in the From header, and to_emails a list of all the
            addresses in the To, Cc, and Bcc headers.
        ÚFromNr   )ÚToÚCcÚBccc                 ó   — g | ]
}|d          ‘ŒS )r   r   )Ú.0Úpairs     r   ú
<listcomp>z8SMTPConnection.get_message_addresses.<locals>.<listcomp>º   s(   € ð 6ð 6ð 6 �T˜!”Wð 6ð 6ð 6r   )r   r/   Úappendr   )ÚmessageÚ
from_emailÚto_full_addressesÚheaderÚvalueÚ	to_emailss         r   Úget_message_addressesz$SMTPConnection.get_message_addresses©   s�   € õ ˜wŸ{š{¨6°4Ñ8Ô8Ñ9Ô9¸!Ô<ˆ
ØÐØ)ð 	0ð 	0ˆFØ—K’K ¨Ñ-Ô-ˆEØð 0Ø!×(Ò(¨Ñ/Ô/Ð/øð6ð 6Ý!Ð"3Ñ4Ô4ð6ñ 6ô 6ˆ	ð ˜9Ð$Ð$r   c           
      ó>  — |                       |¦  «        \  }}|st          ‚	 |                      ¦   «          | j                             |||                     ¦   «         ¦  «         dS # t          j        $ rH}t          dt          t          |j                             ¦   «         ¦  «        ¦  «        z  ¦  «        ‚d}~wt          j        $ r#}t          d|j        |j        fz  ¦  «        ‚d}~wt          j        $ r!}t          t#          |¦  «        ¦  «        ‚d}~ww xY w)zûSend an email message.

        The message will be sent to all addresses in the To, Cc and Bcc
        headers.

        :param message: An email.message.Message or
            email.mime.multipart.MIMEMultipart object.
        :return: None
        zserver refused recipient: %d %sNz%d %s)rb   r&   r9   r5   ÚsendmailÚ	as_stringr,   ÚSMTPRecipientsRefusedr   ÚnextÚiterÚ
recipientsÚvaluesÚSMTPResponseExceptionÚ	smtp_codeÚ
smtp_errorÚSMTPExceptionÚstr)r   r\   r]   ra   rE   s        r   Ú
send_emailzSMTPConnection.send_email¿   s6  € ð !%× :Ò :¸7Ñ CÔ CÑˆ
�Iàð 	'Ý&Ð&ð
	$Ø�MŠM‰OŒOˆOØÔ×%Ò% j°)Ø&-×&7Ò&7Ñ&9Ô&9ñ;ô ;ð ;ð ;ð ;øåÔ,ð 	?ð 	?ð 	?ÝÐ=Ý ¥ a¤l×&9Ò&9Ñ&;Ô&;Ñ!<Ô!<Ñ=Ô=ñ>ñ ?ô ?ð ?øøøøåÔ,ð 	Cð 	Cð 	CÝ˜G q¤{°A´LÐ&AÑAÑBÔBÐBøøøøÝÔ$ð 	$ð 	$ð 	$Ý�C ™FœFÑ#Ô#Ð#øøøøð	$øøøs1   £AA' Á'DÁ6AB9Â9DÃC)Ã)DÃ;DÄDr   )r   r   r   Ú__doc__r2   r   r9   r7   r8   Ústaticmethodrb   rp   r   r   r   r(   r(   L   s•   € € € € € ðð ð 'Ðð ð  ð  ð  ð	ð 	ð 	ðMð Mð MðB3ð 3ð 3ð0 ð%ð %ñ „\ð%ð*$ð $ð $ð $ð $r   r(   )rq   Úemail.utilsr   r   r?   r,   rA   Ú r   r   Úerrorsr   r	   ÚOptionr
   r   r   r   r   r#   r&   r(   r   r   r   ú<module>rw      sç  ðð" *Ð )à /Ð /Ð /Ð /Ð /Ð /Ð /Ð /à €€€Ø €€€Ø €€€ðð ð ð ð ð ð ð ðð ð ð ð ð ð ð ð �”˜o°tð$ðñ ô €ð ˆfŒm˜M°4ð"ðñ ô €ð �”˜o°tð$ðñ ô €ðð ð ð ð �ñ ô ð ðð ð ð ð ˜Iñ ô ð ðIð Ið Ið Ið IÐ#8ñ Iô Ið Ið
:ð :ð :ð :ð :Ð+ñ :ô :ð :ð
L$ð L$ð L$ð L$ð L$ñ L$ô L$ð L$ð L$ð L$r   