
    [Th                        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mZmZ  G d d      Z G d de      Z ej@                         Z!e!jE                  dd      Z#y)    )contextmanager)EmailMessageMessage)
formataddr)AnyDictOptionalUnionN)EnvironmentTemplate)EmailStr)ConnectionConfig)
Connection)PydanticClassRequired)MailMsg)MessageSchemaMessageTypeMultipartSubtypeEnumc                       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    Z/home/www/backend.miabetepe.com/venv/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ee   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deeef   fdZdededefdZdedeeef   fdZ	 	 	 ddedee   de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$   r0   r1   s      r   get_mail_templatezFastMail.get_mail_template5   s      $$]33s   datac                 ~    t        | t              r| S t        | t              rd| iS t        dt	        |        d      )Nbodyz+Unable to build template data dictionary - zis an invalid source data type)
isinstancedictlist
ValueErrortype)r5   s    r   
check_datazFastMail.check_data:   sE    dD!Kd#D>!=d4j\01 r   r   templatec                    K   |r+|j                   | j                  ||       d {   |_         t        |      }| j                  |       d {   }|j	                  |       d {   S 7 F7 7 wr   )template_body#_FastMail__template_message_builderr   _FastMail__sender_message)r$   r   r>   msgsenders        r   __prepare_messagezFastMail.__prepare_messageF   sq      --9*.*I*I+ %G! g}}W--\\&)))% .)s3   $A3A-(A3A/A3(A1)A3/A31A3html_templateplain_templatec                   K   | j                  |j                        } |j                  di |} |j                  di |}t        j                  |_        |j                  t        j                  k(  r||_        ||_	        n||_        ||_	        t        |      }| j                  |       d {   }|j                  |       d {   S 7 7 w)Nr)   )r=   r@   renderr   alternativemultipart_subtypesubtyper   htmlalternative_bodyr   rB   rC   )	r$   r   rG   rH   template_datarN   plainrD   rE   s	            r    __prepare_html_and_plain_messagez)FastMail.__prepare_html_and_plain_messageQ   s      (=(=>#}##4m4%%%66$8$D$D!??k...$(G!',G$$)G!'+G$g}}W--\\&))) .)s$   B.C0C1C	C
CCc                    K   t        |j                  t              r|j                  d|j                  i      S | j	                  |j                        } |j                  di |S w)Nr7   r)   )r8   r@   r:   rJ   r=   )r$   r   r>   rP   s       r   __template_message_builderz#FastMail.__template_message_builderg   sZ      g++T2??FG,A,A#BCC OOG,A,ABM"8??3]33s   A%A'c                    K   |j                   xs | j                  j                  }|j                  xs | j                  j                  x}t        ||f      S |S wr   )
from_emailr,   	MAIL_FROM	from_nameMAIL_FROM_NAMEr   )r$   r   rE   rX   s       r   __senderzFastMail.__senderp   sU     ##<t{{'<'< **Hdkk.H.HHIUy&122s   AAc                   K   t        |t              st        d      | j                  j                  r|s|r|r|rM| j                  | j                  j                         |       d {   }| j                  ||       d {   }n| j                  | j                  j                         |xs d       d {   }| j                  | j                  j                         |xs d       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 7 7 7 q7 :7 # 1 d {  7  sw Y   y xY ww)Nz:Message schema should be provided from MessageSchema class )r8   r   r   r,   TEMPLATE_FOLDERr4   template_engine_FastMail__prepare_message)_FastMail__prepare_html_and_plain_messager   SUPPRESS_SENDsessionsend_messager    send)
r$   r   r1   rG   rH   template_objrD   html_template_objplain_template_objrb   s
             r   rc   zFastMail.send_messagev   s     '=1'L  ;;&&m%)%;%;KK//1=&   !227LII*.*@*@KK//1=3FB+ %! ,0+A+AKK//1>3GR, &" !AA.0B  ..w77Cdkk* 	' 	'g;;,,oo223777!!#&		' 	' 	'#  J%& 8	'7	' 	' 	' 	's   A'G)F'*GF*6G:F-;5G0F/1GF1G%F3&GF5G5F;<F7=F;G!F9"G*G-G/G1G3G5G7F;9G;GGG	Gr   )NNN)r&   r'   r(   __doc__r   r/   r   strr   r4   staticmethodr
   r   r   r:   r=   r   r	   r   r   r_   r`   rA   r   rB   rc   r)   r   r   r+   r+   -   sj   / D 4#4474	4
 	tCH~sD$s)CD 	cSVh 	 	 FJ	*$	*080B	*	|W$	%	***  * !	*
 
|W$	%*,4$4084	4m hm8L  (,'+(,%'%'  }%'  }	%'
 !%' 
%'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   r   r+   	Namespacesignalssignalr    r)   r   r   <module>r{      sv    % / " - -  (  0 . 5 $ Q Q1 18n'z n'b '


>>	 "  r   