o
    rMf\                     @   st   d dl Z d dlZd dlmZmZ d dlmZ d dlmZ d dl	m
Z
 d dlZd dlZd dlmZ G dd deZdS )	    N)sixurllib)AWSAuthConnection)BotoServerError)
RegionInfo)
exceptionsc                       s   e Zd ZeZdZdZdZ					d5 fdd		Zd
d Z	dd Z
d6 fdd	Zdd Z			d7ddZd8ddZdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd6d1d2Zd9d3d4Z  ZS ):SESConnectionz	us-east-1zemail.us-east-1.amazonaws.comz
2010-12-01NTr   /c                    sP   |s
t | | j| j}|| _tt| j| jj|||||||||	|
||||d d S )N)security_tokenvalidate_certsprofile_name)r   DefaultRegionNameDefaultRegionEndpointregionsuperr   __init__endpoint)selfaws_access_key_idaws_secret_access_key	is_secureportproxy
proxy_port
proxy_user
proxy_passdebughttps_connection_factoryr   pathr
   r   r   	__class__ U/var/www/html/analyze/labelStudio/lib/python3.10/site-packages/boto/ses/connection.pyr   )   s   
zSESConnection.__init__c                 C   s   dgS )Nsesr!   r   r!   r!   r"   _required_auth_capability;   s   z'SESConnection._required_auth_capabilityc                 C   sF   t |tjr	|g}tdt|d D ]}||d  |d||f < qdS )a-  Add an AWS API-compatible parameter list to a dictionary.

        :type params: dict
        :param params: The parameter dictionary

        :type items: list
        :param items: Items to be included in the list

        :type label: string
        :param label: The parameter list's name
           z%s.%dN)
isinstancer   string_typesrangelen)r   paramsitemslabelir!   r!   r"   _build_list_params>   s
   z SESConnection._build_list_paramsc                    s   d}d|i}|p	i }||d< |  D ]\}}t|tjr#|d||< qtt| jdd|tj	
|d}| d}|jdkrZd	}	d
}
tjj|	|
d}tj|d}|	| |S | || dS )zMake a call to the SES API.

        :type action: string
        :param action: The API method to use (e.g. SendRawEmail)

        :type params: dict
        :param params: Parameters that will be sent as POST data with the API
            call.
        z0application/x-www-form-urlencoded; charset=UTF-8zContent-TypeActionutf-8POSTr	   )headersdata   )VerifiedEmailAddresses
Identities
DkimTokensDkimAttributesVerificationAttributesSendDataPoints)memberitementry)list_markeritem_markerN)r,   r'   r   	text_typeencoder   r   make_requestr   parse	urlencodereaddecodestatusbotojsonresponseElement
XmlHandler_handle_error)r   actionr+   ctr3   kvresponsebodylist_markersitem_markersehr   r!   r"   _make_requestO   s2   




zSESConnection._make_requestc                 C   s   t jd|j|jf  t jd|  d|v rtj}d}nXd|v r(tj}d}nNd|v r2tj}d}nDd|v r<tj	}d}n:d|v rFtj
}d}n0d|v rPtj}d	}n&d
|v rZtj}d
}ntd|rftj}d}nd|v rptj}d}n| j}|j}||j||)z
        Handle raising the correct exception, depending on the error. Many
        errors share the same HTTP response code, meaning we have to get really
        kludgey and do string searches to figure out what went wrong.
        z%s %sz%szAddress blacklisted.zEmail address is not verified.zDaily message quota exceeded.zMaximum sending rate exceeded.zDomain ends with dot.z,Local address contains control or whitespacez-Local address contains control or whitespace.zIllegal addresszIdentity.*is not verifiedzIdentity is not verified.zownership not confirmedz"Domain ownership is not confirmed.)rI   logerrorrH   reasonses_exceptionsSESAddressBlacklistedErrorSESAddressNotVerifiedErrorSESDailyQuotaExceededErrorSESMaxSendingRateExceededErrorSESDomainEndsWithDotErrorSESLocalAddressCharacterErrorSESIllegalAddressErrorresearchSESIdentityNotVerifiedErrorSESDomainNotConfirmedErrorResponseError)r   rR   rS   ExceptionToRaise
exc_reasonr!   r!   r"   rM   y   s@   zSESConnection._handle_errortextc                 C   s   |   }|dur#|dkr|
durtd|}
n
|dur!td|}||d}|	r.|	|d< |dur6||d< |
dur>|
|d< |d	vrFtd
|sN|
sNtd| ||d |r^| ||d |rg| ||d |rp| ||d | d|S )a  Composes an email message based on input data, and then immediately
        queues the message for sending.

        :type source: string
        :param source: The sender's email address.

        :type subject: string
        :param subject: The subject of the message: A short summary of the
                        content, which will appear in the recipient's inbox.

        :type body: string
        :param body: The message body.

        :type to_addresses: list of strings or string
        :param to_addresses: The To: field(s) of the message.

        :type cc_addresses: list of strings or string
        :param cc_addresses: The CC: field(s) of the message.

        :type bcc_addresses: list of strings or string
        :param bcc_addresses: The BCC: field(s) of the message.

        :type format: string
        :param format: The format of the message's body, must be either "text"
                       or "html".

        :type reply_addresses: list of strings or string
        :param reply_addresses: The reply-to email address(es) for the
                                message. If the recipient replies to the
                                message, each reply-to address will
                                receive the reply.

        :type return_path: string
        :param return_path: The email address to which bounce notifications are
                            to be forwarded. If the message cannot be delivered
                            to the recipient, then an error message will be
                            returned from the recipient's ISP; this message
                            will then be forwarded to the email address
                            specified by the ReturnPath parameter.

        :type text_body: string
        :param text_body: The text body to send with this email.

        :type html_body: string
        :param html_body: The html body to send with this email.

        Nrk   zMYou've passed in both a body and a text_body; please choose one or the other.zNYou've passed in both a body and an html_body; please choose one or the other.)SourcezMessage.Subject.Data
ReturnPathzMessage.Body.Html.DatazMessage.Body.Text.Data)rk   htmlz*'format' argument must be 'text' or 'html'z#No text or html body found for mailzDestination.ToAddresses.memberzDestination.CcAddresses.memberzDestination.BccAddresses.memberzReplyToAddresses.member	SendEmail)lowerstripWarning
ValueErrorr/   rX   )r   sourcesubjectrS   to_addressescc_addressesbcc_addressesformatreply_addressesreturn_path	text_body	html_bodyr+   r!   r!   r"   
send_email   sL   3zSESConnection.send_emailc                 C   sN   t |tjr|d}dt|i}|r||d< |r!| ||d | d|S )at  Sends an email message, with header and content specified by the
        client. The SendRawEmail action is useful for sending multipart MIME
        emails, with attachments or inline content. The raw text of the message
        must comply with Internet email standards; otherwise, the message
        cannot be sent.

        :type source: string
        :param source: The sender's email address. Amazon's docs say:

          If you specify the Source parameter, then bounce notifications and
          complaints will be sent to this email address. This takes precedence
          over any Return-Path header that you might include in the raw text of
          the message.

        :type raw_message: string
        :param raw_message: The raw text of the message. The client is
          responsible for ensuring the following:

          - Message must contain a header and a body, separated by a blank line.
          - All required header fields must be present.
          - Each part of a multipart MIME message must be formatted properly.
          - MIME content types must be among those supported by Amazon SES.
            Refer to the Amazon SES Developer Guide for more details.
          - Content must be base64-encoded, if MIME requires it.

        :type destinations: list of strings or string
        :param destinations: A list of destinations for the message.

        r1   zRawMessage.Datarl   zDestinations.memberSendRawEmail)r'   r   rA   rB   base64	b64encoder/   rX   )r   raw_messagert   destinationsr+   r!   r!   r"   send_raw_email  s   

zSESConnection.send_raw_emailc                 C   
   |  dS )zFetch a list of the email addresses that have been verified.

        :rtype: dict
        :returns: A ListVerifiedEmailAddressesResponse structure. Note that
                  keys must be unicode strings.
        ListVerifiedEmailAddressesrX   r$   r!   r!   r"   list_verified_email_addressesE     
z+SESConnection.list_verified_email_addressesc                 C   r   )zFetches the user's current activity limits.

        :rtype: dict
        :returns: A GetSendQuotaResponse structure. Note that keys must be
                  unicode strings.
        GetSendQuotar   r$   r!   r!   r"   get_send_quotaN  r   zSESConnection.get_send_quotac                 C   r   )au  Fetches the user's sending statistics. The result is a list of data
        points, representing the last two weeks of sending activity.

        Each data point in the list contains statistics for a 15-minute
        interval.

        :rtype: dict
        :returns: A GetSendStatisticsResponse structure. Note that keys must be
                  unicode strings.
        GetSendStatisticsr   r$   r!   r!   r"   get_send_statisticsW  s   
z!SESConnection.get_send_statisticsc                 C      |  dd|iS )a  Deletes the specified email address from the list of verified
        addresses.

        :type email_adddress: string
        :param email_address: The email address to be removed from the list of
                              verified addreses.

        :rtype: dict
        :returns: A DeleteVerifiedEmailAddressResponse structure. Note that
                  keys must be unicode strings.
        DeleteVerifiedEmailAddressEmailAddressr   r   email_addressr!   r!   r"   delete_verified_email_addressd  s   z+SESConnection.delete_verified_email_addressc                 C   r   )ap  Verifies an email address. This action causes a confirmation email
        message to be sent to the specified address.

        :type email_adddress: string
        :param email_address: The email address to be verified.

        :rtype: dict
        :returns: A VerifyEmailAddressResponse structure. Note that keys must
                  be unicode strings.
        VerifyEmailAddressr   r   r   r!   r!   r"   verify_email_addresst     z"SESConnection.verify_email_addressc                 C   r   )a  
        Returns a set of DNS records, or tokens, that must be published in the
        domain name's DNS to complete the DKIM verification process. These
        tokens are DNS ``CNAME`` records that point to DKIM public keys hosted
        by Amazon SES. To complete the DKIM verification process, these tokens
        must be published in the domain's DNS.  The tokens must remain
        published in order for Easy DKIM signing to function correctly.

        After the tokens are added to the domain's DNS, Amazon SES will be able
        to DKIM-sign email originating from that domain.  To enable or disable
        Easy DKIM signing for a domain, use the ``SetIdentityDkimEnabled``
        action.  For more information about Easy DKIM, go to the `Amazon SES
        Developer Guide
        <http://docs.amazonwebservices.com/ses/latest/DeveloperGuide>`_.

        :type domain: string
        :param domain: The domain name.

        VerifyDomainDkimDomainr   r   domainr!   r!   r"   verify_domain_dkim  s   z SESConnection.verify_domain_dkimc                 C       |  d||rddS ddS )a  Enables or disables DKIM signing of email sent from an identity.

        * If Easy DKIM signing is enabled for a domain name identity (e.g.,
        * ``example.com``),
          then Amazon SES will DKIM-sign all email sent by addresses under that
          domain name (e.g., ``user@example.com``)
        * If Easy DKIM signing is enabled for an email address, then Amazon SES
          will DKIM-sign all email sent by that email address.

        For email addresses (e.g., ``user@example.com``), you can only enable
        Easy DKIM signing  if the corresponding domain (e.g., ``example.com``)
        has been set up for Easy DKIM using the AWS Console or the
        ``VerifyDomainDkim`` action.

        :type identity: string
        :param identity: An email address or domain name.

        :type dkim_enabled: bool
        :param dkim_enabled: Specifies whether or not to enable DKIM signing.

        SetIdentityDkimEnabledtruefalse)IdentityDkimEnabledr   )r   identitydkim_enabledr!   r!   r"   set_identity_dkim_enabled  s   z'SESConnection.set_identity_dkim_enabledc                 C      i }|  ||d | d|S )af  Get attributes associated with a list of verified identities.

        Given a list of verified identities (email addresses and/or domains),
        returns a structure describing identity notification attributes.

        :type identities: list
        :param identities: A list of verified identities (email addresses
            and/or domains).

        Identities.memberGetIdentityDkimAttributesr/   rX   r   
identitiesr+   r!   r!   r"   get_identity_dkim_attributes  s   z*SESConnection.get_identity_dkim_attributesc                 C   r   )a+  Returns a list containing all of the identities (email addresses
        and domains) for a specific AWS Account, regardless of
        verification status.

        :rtype: dict
        :returns: A ListIdentitiesResponse structure. Note that
                  keys must be unicode strings.
        ListIdentitiesr   r$   r!   r!   r"   list_identities  s   
	zSESConnection.list_identitiesc                 C   r   )a  Given a list of identities (email addresses and/or domains),
        returns the verification status and (for domain identities)
        the verification token for each identity.

        :type identities: list of strings or string
        :param identities: List of identities.

        :rtype: dict
        :returns: A GetIdentityVerificationAttributesResponse structure.
                  Note that keys must be unicode strings.
        r   !GetIdentityVerificationAttributesr   r   r!   r!   r"   $get_identity_verification_attributes  s
   z2SESConnection.get_identity_verification_attributesc                 C   r   )zVerifies a domain.

        :type domain: string
        :param domain: The domain to be verified.

        :rtype: dict
        :returns: A VerifyDomainIdentityResponse structure. Note that
                  keys must be unicode strings.
        VerifyDomainIdentityr   r   r   r!   r!   r"   verify_domain_identity  s   
z$SESConnection.verify_domain_identityc                 C   r   )aq  Verifies an email address. This action causes a confirmation
        email message to be sent to the specified address.

        :type email_adddress: string
        :param email_address: The email address to be verified.

        :rtype: dict
        :returns: A VerifyEmailIdentityResponse structure. Note that keys must
                  be unicode strings.
        VerifyEmailIdentityr   r   r   r!   r!   r"   verify_email_identity  r   z#SESConnection.verify_email_identityc                 C   r   )aJ  Deletes the specified identity (email address or domain) from
        the list of verified identities.

        :type identity: string
        :param identity: The identity to be deleted.

        :rtype: dict
        :returns: A DeleteIdentityResponse structure. Note that keys must
                  be unicode strings.
        DeleteIdentityr   r   )r   r   r!   r!   r"   delete_identity  r   zSESConnection.delete_identityc                 C   s"   ||d}|r||d< |  d|S )a  Sets an SNS topic to publish bounce or complaint notifications for
        emails sent with the given identity as the Source. Publishing to topics
        may only be disabled when feedback forwarding is enabled.

        :type identity: string
        :param identity: An email address or domain name.

        :type notification_type: string
        :param notification_type: The type of feedback notifications that will
                                  be published to the specified topic.
                                  Valid Values: Bounce | Complaint | Delivery

        :type sns_topic: string or None
        :param sns_topic: The Amazon Resource Name (ARN) of the Amazon Simple
                          Notification Service (Amazon SNS) topic.
        )r   NotificationTypeSnsTopicSetIdentityNotificationTopicr   )r   r   notification_type	sns_topicr+   r!   r!   r"   set_identity_notification_topic  s   z-SESConnection.set_identity_notification_topicc                 C   r   )a  
        Enables or disables SES feedback notification via email.
        Feedback forwarding may only be disabled when both complaint and
        bounce topics are set.

        :type identity: string
        :param identity: An email address or domain name.

        :type forwarding_enabled: bool
        :param forwarding_enabled: Specifies whether or not to enable feedback forwarding.
        $SetIdentityFeedbackForwardingEnabledr   r   )r   ForwardingEnabledr   )r   r   forwarding_enabledr!   r!   r"   (set_identity_feedback_forwarding_enabled&  s   z6SESConnection.set_identity_feedback_forwarding_enabled)NNTNNNNNr   NNr	   NTN)N)NNrk   NNNN)NN)T)__name__
__module____qualname__r   rh   r   r   
APIVersionr   r%   r/   rX   rM   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__r!   r!   r   r"   r   "   sF    *;

c/		
r   )rd   r   boto.compatr   r   boto.connectionr   boto.exceptionr   boto.regioninfor   rI   boto.jsonresponseboto.sesr   r\   r   r!   r!   r!   r"   <module>   s   