o
    ›¨Êh¦  ã                   @   s¢   d dl mZ d dlmZ d dlZd dlmZmZmZ ddl	m
Z
 G dd„ deƒZG d	d
„ d
eeƒZddd„Zddd„Zg d¢ZG dd„ deƒZG dd„ deƒZdS )é    )Ú	MIMEImage)ÚunquoteN)ÚEmailMessageÚEmailMultiAlternativesÚ
make_msgidé   )ÚUNSETc                       s4   e Zd ZdZ‡ fdd„Zd
dd„Zddd	„Z‡  ZS )ÚAnymailMessageMixinaM  Mixin for EmailMessage that exposes Anymail features.

    Use of this mixin is optional. You can always just set Anymail
    attributes on any EmailMessage.

    (The mixin can be helpful with type checkers and other development
    tools that complain about accessing Anymail's added attributes
    on a regular EmailMessage.)
    c                    s®   |  dt¡| _|  dt¡| _|  dt¡| _|  dt¡| _|  dt¡| _|  dt¡| _|  dt¡| _|  dt¡| _	|  d	t¡| _
|  d
t¡| _tƒ | _tt| ƒj|i |¤Ž d S )NÚ	esp_extraÚenvelope_senderÚmetadataÚsend_atÚtagsÚtrack_clicksÚtrack_opensÚtemplate_idÚ
merge_dataÚmerge_global_data)Úpopr   r
   r   r   r   r   r   r   r   r   r   ÚAnymailStatusÚanymail_statusÚsuperr	   Ú__init__)ÚselfÚargsÚkwargs©Ú	__class__© úA/var/www/html/env/lib/python3.10/site-packages/anymail/message.pyr      s   zAnymailMessageMixin.__init__NÚimgc                 C   s   t | tƒsJ ‚t| ||||ƒS )úMAdd inline image from file path to an EmailMessage, and return its content id)Ú
isinstancer   Úattach_inline_image_file)r   ÚpathÚsubtypeÚidstringÚdomainr   r   r   r#   %   s   z,AnymailMessageMixin.attach_inline_image_filec                 C   s    t | tƒsJ ‚t| |||||ƒS )z*Add inline image and return its content id)r"   r   Úattach_inline_image)r   ÚcontentÚfilenamer%   r&   r'   r   r   r   r(   *   s   z'AnymailMessageMixin.attach_inline_image©Nr    N©NNr    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r#   r(   Ú__classcell__r   r   r   r   r	   
   s
    

r	   c                   @   s   e Zd ZdS )ÚAnymailMessageN)r-   r.   r/   r   r   r   r   r2   0   s    r2   r    c                 C   sP   t j |¡}t|dƒ�}| ¡ }W d  ƒ n1 sw   Y  t| |||||ƒS )r!   ÚrbN)Úosr$   ÚbasenameÚopenÚreadr(   )Úmessager$   r%   r&   r'   r*   Úfr)   r   r   r   r#   4   s
   
ÿr#   c                 C   sB   t ||ƒ}t||ƒ}|jdd|d� | d|¡ |  |¡ t|ƒS )z>Add inline image to an EmailMessage, and return its content idzContent-DispositionÚinline)r*   z
Content-ID)r   r   Ú
add_headerÚattachr   )r8   r)   r*   r%   r&   r'   Ú
content_idÚimager   r   r   r(   <   s   


r(   )ÚsentÚqueuedÚinvalidÚrejectedÚfailedÚunknownc                   @   s   e Zd ZdZdd„ ZdS )ÚAnymailRecipientStatuszFInformation about an EmailMessage's send status for a single recipientc                 C   s   || _ || _d S ©N)Ú
message_idÚstatus)r   rG   rH   r   r   r   r   S   s   
zAnymailRecipientStatus.__init__N)r-   r.   r/   r0   r   r   r   r   r   rE   P   s    rE   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )r   zBInformation about an EmailMessage's send status for all recipientsc                 C   s   d | _ d | _i | _d | _d S rF   )rG   rH   Ú
recipientsÚesp_response)r   r   r   r   r   [   s   
zAnymailStatus.__init__c                 C   s\   | j  |¡ | j  ¡ }tdd„ |D ƒƒ| _t| jƒdkr"| j ¡ | _tdd„ |D ƒƒ| _d S )Nc                 S   ó   g | ]}|j ‘qS r   )rG   ©Ú.0Ú	recipientr   r   r   Ú
<listcomp>d   ó    z6AnymailStatus.set_recipient_status.<locals>.<listcomp>r   c                 S   rK   r   )rH   rL   r   r   r   rO   g   rP   )rI   ÚupdateÚvaluesÚsetrG   Úlenr   rH   )r   rI   Úrecipient_statusesr   r   r   Úset_recipient_statusa   s   
z"AnymailStatus.set_recipient_statusN)r-   r.   r/   r0   r   rV   r   r   r   r   r   X   s    r   r+   r,   )Úemail.mime.imager   Úemail.utilsr   r4   Údjango.core.mailr   r   r   Úutilsr   Úobjectr	   r2   r#   r(   ÚANYMAIL_STATUSESrE   r   r   r   r   r   Ú<module>   s    &



