U
    ä«Fc8  ã                   @   sd   zd dl Z W n  ek
r,   d dlmZ  Y nX zeZW n ek
rN   eZY nX G dd„ deƒZdS )é    Nc                   @   sÆ   e Zd ZdZddd„Zedd„ ƒZejdd„ ƒZed	d
„ ƒZejdd
„ ƒZedd„ ƒZ	e	jdd„ ƒZ	edd„ ƒZ
e
jdd„ ƒZ
edd„ ƒZejdd„ ƒZedd„ ƒZejdd„ ƒZdd„ Zdd„ ZdS )ÚEmailz'An email address with an optional name.Nr   c                 C   sX   d| _ d| _|| _|r&|s&|  |¡ n|dk	r4|| _|dk	rB|| _|| _|| _|| _dS )aÅ  Create an Email with the given address and name.

        Either fill the separate name and email fields, or pass all information
        in the email parameter (e.g. email="dude Fella <example@example.com>").
        :param email: Email address, or name and address in standard format.
        :type email: string, optional
        :param name: Name for this sender or recipient.
        :type name: string, optional
        :param substitutions: String substitutions to be applied to the email.
        :type substitutions: list(Substitution), optional
        :param subject: Subject for this sender or recipient.
        :type subject: string, optional
        :param p: p is the Personalization object or Personalization object
                  index
        :type p: Personalization, integer, optional
        :param dynamic_template_data: Data for a dynamic transactional template.
        :type dynamic_template_data: DynamicTemplateData, optional
        N)	Ú_nameÚ_emailÚ_personalizationÚparse_emailÚemailÚnameÚ_substitutionsÚ_dynamic_template_dataÚ_subject)Úselfr   r   ÚsubstitutionsÚsubjectÚpÚdynamic_template_data© r   ú?/tmp/pip-unpacked-wheel-7j3043uk/sendgrid/helpers/mail/email.pyÚ__init__   s    zEmail.__init__c                 C   s   | j S )zAName associated with this email.

        :rtype: string
        )r   ©r   r   r   r   r   >   s    z
Email.namec                 C   s$   |dkst |tƒstdƒ‚|| _dS )z}Name associated with this email.

        :param value: Name associated with this email.
        :type value: string
        Nzname must be of type string.)Ú
isinstanceÚ
basestringÚ	TypeErrorr   ©r   Úvaluer   r   r   r   F   s    c                 C   s   | j S )zçEmail address.

        See http://tools.ietf.org/html/rfc3696#section-3 and its errata
        http://www.rfc-editor.org/errata_search.php?rfc=3696 for information
        on valid email addresses.

        :rtype: string
        ©r   r   r   r   r   r   R   s    
zEmail.emailc                 C   s
   || _ dS )aÈ  Email address.

        See http://tools.ietf.org/html/rfc3696#section-3 and its errata
        http://www.rfc-editor.org/errata_search.php?rfc=3696 for information
        on valid email addresses.

        :param value: Email address.
        See http://tools.ietf.org/html/rfc3696#section-3 and its errata
        http://www.rfc-editor.org/errata_search.php?rfc=3696 for information
        on valid email addresses.
        :type value: string
        Nr   r   r   r   r   r   ^   s    c                 C   s   | j S )ak  A list of Substitution objects. These substitutions will apply to
           the text and html content of the body of your email, in addition
           to the subject and reply-to parameters. The total collective size
           of your substitutions may not exceed 10,000 bytes per
           personalization object.

        :rtype: list(Substitution)
        ©r	   r   r   r   r   r   n   s    
zEmail.substitutionsc                 C   s
   || _ dS )a­  A list of Substitution objects. These substitutions will apply to
        the text and html content of the body of your email, in addition to
        the subject and reply-to parameters. The total collective size of
        your substitutions may not exceed 10,000 bytes per personalization
        object.

        :param value: A list of Substitution objects. These substitutions will
        apply to the text and html content of the body of your email, in
        addition to the subject and reply-to parameters. The total collective
        size of your substitutions may not exceed 10,000 bytes per
        personalization object.
        :type value: list(Substitution)
        Nr   r   r   r   r   r   z   s    c                 C   s   | j S )zXData for a dynamic transactional template.

        :rtype: DynamicTemplateData
        ©r
   r   r   r   r   r   ‹   s    zEmail.dynamic_template_datac                 C   s
   || _ dS )z‡Data for a dynamic transactional template.

        :param value: DynamicTemplateData
        :type value: DynamicTemplateData
        Nr   r   r   r   r   r   “   s    c                 C   s   | j S )zFSubject for this sender or recipient.

        :rtype: string
        ©r   r   r   r   r   r   œ   s    zEmail.subjectc                 C   s
   || _ dS )z‘Subject for this sender or recipient.

        :param value: Subject for this sender or recipient.
        :type value: string, optional
        Nr   r   r   r   r   r   ¤   s    c                 C   s   | j S )zmThe Personalization object or Personalization object index

        :rtype: Personalization, integer
        ©r   r   r   r   r   Úpersonalization­   s    zEmail.personalizationc                 C   s
   || _ dS )zÙThe Personalization object or Personalization object index

        :param value: The Personalization object or Personalization object
                      index
        :type value: Personalization, integer
        Nr   r   r   r   r   r   µ   s    c                 C   sB   t  |¡\}}d|kr|}d}|s&d}|s.d}|| _|| _||fS )zÜAllows passing emails as "Example Name <example@example.com>"

        :param email_info: Allows passing emails as
                           "Example Name <example@example.com>"
        :type email_info: string
        ú@N)Úrfc822Ú	parseaddrr   r   )r   Z
email_infor   r   r   r   r   r   ¿   s    zEmail.parse_emailc                 C   s0   i }| j dk	r| j |d< | jdk	r,| j|d< |S )z•
        Get a JSON-ready representation of this Email.

        :returns: This Email, ready for use in a request body.
        :rtype: dict
        Nr   r   )r   r   )r   r   r   r   r   Úget×   s    



z	Email.get)NNNNr   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr   Úsetterr   r   r   r   r   r   r#   r   r   r   r   r      sD         ú
.











	r   )	r!   ÚImportErrorÚemail.utilsÚutilsr   Ú	NameErrorÚstrÚobjectr   r   r   r   r   Ú<module>   s   
