
    Ngw                         d Z ddlmZmZmZmZmZ ddlmZ ddl	m
Z
mZmZ ddlmZ ddlmZmZ  G d de
          Z G d	 d
e          ZdS )zUtil that Searches email messages in Office 365.

Free, but setup is required. See link below.
https://learn.microsoft.com/en-us/graph/auth/
    )AnyDictListOptionalType)CallbackManagerForToolRun)	BaseModel
ConfigDictField)O365BaseTool)
UTC_FORMAT
clean_bodyc                       e Zd ZU dZ	  edd          Zeed<    ed          Zeed<    ed	d
          Z	e
ed<    edd          Zeed<   dS )SearchEmailsInputzInput for SearchEmails Tool. z If the user wants to search in only one folder, the name of the folder. Default folders are "inbox", "drafts", "sent items", "deleted ttems", but users can search custom folders as well.)defaultdescriptionfoldera  The Microsoift Graph v1.0 $search query. Example filters include from:sender, from:sender, to:recipient, subject:subject, recipients:list_of_recipients, body:excitement, importance:high, received>2022-12-01, received<2021-12-01, sent>2022-12-01, sent<2021-12-01, hasAttachments:true  attachment:api-catalog.md, cc:samanthab@contoso.com, bcc:samanthab@contoso.com, body:excitement date range example: received:2023-06-08..2023-06-09  matching example: from:amy OR from:david.)r   query
   z(The maximum number of results to return.max_resultsTzWhether the email body is truncated to meet token number limits. Set to False for searches that will retrieve small messages, otherwise, set to TruetruncateN)__name__
__module____qualname____doc__r   r   str__annotations__r   r   intr   bool     o/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/tools/office365/messages_search.pyr   r      s         &&M%7  FC    &  E3    u>  K    U  Hd     r"   r   c                       e Zd ZU dZdZeed<   eZe	e
         ed<   dZeed<    ed          Z	 	 	 	 	 ddededededee         dedeeeef                  fdZdS )O365SearchEmailszKSearch email messages in Office 365.

    Free, but setup is required.
    messages_searchnameargs_schemazUse this tool to search for email messages. The input must be a valid Microsoft Graph v1.0 $search query. The output is a JSON list of the requested resource.r   forbid)extrar   r   TN   r   r   r   r   run_managertruncate_limitreturnc                 X   | j                                         }|dk    r|                    |          }|                                                    |          }|                    ||          }g }	|D ]0}
i }|
j        |d<   |r|
j        d |         |d<   nt          |
j	                  |d<   |
j
        |d<   |
j                            t                    |d<   g |d<   |
j        j        D ]*}|d                             t#          |                     +g |d	<   |
j        j        D ]*}|d	                             t#          |                     +g |d
<   |
j        j        D ]*}|d
                             t#          |                     +|	                    |           2|	S )Nr   )folder_name)limitr   frombodysubjectdatetoccbcc)accountmailbox
get_folderqsearchget_messagessenderbody_previewr   r3   r4   modifiedstrftimer   r6   _recipientsappendr   r7   r8   )selfr   r   r   r   r,   r-   r:   messagesoutput_messagesmessageoutput_message	recipients                r#   _runzO365SearchEmails._runI   s    ,&&(( R<<((V(<<G 		""5))''k'GG  	3 	3GN%,^N6" B)0)=o~o)Nv&&)3GL)A)Av&(/N9%%,%5%>%>z%J%JN6"#%N4 $Z3 < <	t$++C	NN;;;;#%N4 $Z3 < <	t$++C	NN;;;;$&N5!$[4 = =	u%,,S^^<<<<"">2222r"   )r   r   TNr+   )r   r   r   r   r'   r   r   r   r(   r   r	   r   r
   model_configr   r    r   r   r   r   r   rK   r!   r"   r#   r%   r%   7   s          
 "D#!!!#4Ki444	@     :  L ;?!1 11 1 	1
 1 781 1 
d38n	1 1 1 1 1 1r"   r%   N)r   typingr   r   r   r   r   langchain_core.callbacksr   pydanticr	   r
   r   (langchain_community.tools.office365.baser   )langchain_community.tools.office365.utilsr   r   r   r%   r!   r"   r#   <module>rR      s     3 2 2 2 2 2 2 2 2 2 2 2 2 2 > > > > > > 1 1 1 1 1 1 1 1 1 1 A A A A A A L L L L L L L L$ $ $ $ $	 $ $ $NC C C C C| C C C C Cr"   