
    h                        d dl mZ d dlmZmZ d dlmZ d dlmZm	Z	m
Z
m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mZ d dlmZ d dlmZ  G d d      Z G d de      Z ej<                         ZejA                  dd      Z!y)    )contextmanager)EmailMessageMessage)
formataddr)AnyDictOptionalUnionN)EnvironmentTemplate)EmailStr)ConnectionConfig)
Connection)PydanticClassRequired)MailMsg)MessageSchemac                       e Zd Zed        Zy)
_MailMixinc              #      K   t         st        d      g fd}t         j                  |       	  t         j                  |       y# t         j                  |       w xY ww)aw  Records all messages. Use in unit tests for example::
            with mail.record_messages() as outbox:
                response = app.test_client.get("/email-sending-view/")
                assert len(outbox) == 1
                assert outbox[0].subject == "testing"
        You must have blinker installed in order to use this feature.
        :versionadded: 0.4
        zblinker must be installedc                 (    j                  |        y N)append)messageoutboxs    `/var/www/html/retail-simulation-api/retail/lib/python3.12/site-packages/fastapi_mail/fastmail.py_recordz+_MailMixin.record_messages.<locals>._record"   s    MM'"    N)email_dispatchedRuntimeErrorconnect
disconnect)selfr   r   s     @r   record_messagesz_MailMixin.record_messages   sY       :;;	# 	  )	1L''0''0s   .A&A A&A##A&N)__name__
__module____qualname__r   r#    r   r   r   r      s    1 1r   r   c            	           e Zd ZdZdeddfdZdededefdZ	e
d	eeeef   edf   deeef   fd
       Z	 ddedee   deeef   fdZdededefdZdeeef   fdZ	 ddedee   ddfdZy)FastMailz5
    FastMail builds the message from the config
    configreturnNc                     || _         y r   )r*   )r"   r*   s     r   __init__zFastMail.__init__2   s	    r   env_pathtemplate_namec                 ,   K   |j                  |      S wr   )get_template)r"   r.   r/   s      r   get_mail_templatezFastMail.get_mail_template5   s      $$]33s   datac                 V    t        | t              st        dt        |        d      | S )Nz+Unable to build template data dictionary - zis an invalid source data type)
isinstancedict
ValueErrortype)r3   s    r   
check_datazFastMail.check_data:   s3    $%=d4j\01 
 r   r   templatec                    K   |r+|j                   | j                  ||       d {   |_         t        |      }| j                          d {   }|j	                  |       d {   S 7 E7 7 wr   )template_body#_FastMail__template_message_builderr   _FastMail__sender_message)r"   r   r:   msgsenders        r   __prepare_messagezFastMail.__prepare_messageD   sn      --9*.*I*I+ %G! g}}&\\&)))% ')s3   $A2A,'A2A.A2'A0(A2.A20A2c                    K   t        |j                  t              r|j                  d|j                  i      S | j	                  |j                        } |j                  di |S w)Nbodyr'   )r5   r<   listrenderr9   )r"   r   r:   template_datas       r   __template_message_builderz#FastMail.__template_message_builderO   sZ      g++T2??FG,A,A#BCC OOG,A,ABM"8??3]33s   A%A'c                    K   | j                   j                  }| j                   j                  5t        | j                   j                  | j                   j                  f      S |S wr   )r*   	MAIL_FROMMAIL_FROM_NAMEr   )r"   rA   s     r   __senderzFastMail.__senderX   sN     &&;;%%1t{{994;;;P;PQRRs   A$A&c                 x  K   t        |t              st        d      | j                  j                  rO|rM| j                  | j                  j                         |       d {   }| j                  ||       d {   }n| j                  |       d {   }t        | j                        4 d {   }| j                  j                  s#|j                  j                  |       d {    t        j                  |       d d d       d {    y 7 7 7 7 i7 27 # 1 d {  7  sw Y   y xY ww)Nz:Message schema should be provided from MessageSchema class)r5   r   r   r*   TEMPLATE_FOLDERr2   template_engine_FastMail__prepare_messager   SUPPRESS_SENDsessionsend_messager   send)r"   r   r/   r:   r@   rR   s         r   rS   zFastMail.send_message^   s      '=1'L  ;;&&=!33++-} H ..wAAC..w77Cdkk**g;;,,oo223777!!#&	 +** B7*7 +***s   A!D:#D$D:=D>D:DD:5D6D:95D%.D!/D%D:D#D:D:D:D:!D%#D:%D7+D.,D73D:r   )r$   r%   r&   __doc__r   r-   r   strr   r2   staticmethodr
   r   r   r9   r   r	   r   r   rP   r=   r   r>   rS   r'   r   r   r)   r)   -   s   / D 4#4474	4
 tCH~sD89 d38n   FJ	*$	*080B	*	|W$	%	*4$4084	4hm 4  FJ'$'5=c]'	'r   r)   zemail-dispatchedz
Signal sent when an email is dispatched. This signal will also be sent
in testing mode, even though the email will not actually be sent.
)doc)"
contextlibr   email.messager   r   email.utilsr   typingr   r   r	   r
   blinkerjinja2r   r   pydanticr   fastapi_mail.configr   fastapi_mail.connectionr   fastapi_mail.errorsr   fastapi_mail.msgr   fastapi_mail.schemasr   r   r)   	Namespacesignalssignalr   r'   r   r   <module>rh      ss    % / " - -  (  0 . 5 $ .1 18E'z E'P '


>>	 "  r   