
    Ng                    v    d Z ddlmZ ddlZddlZddlmZ erddlmZ  ej	        e
          Zdd	ZddZdZdS )zO365 tool utils.    )annotationsN)TYPE_CHECKINGAccountbodystrreturnc                   	 ddl m} 	  |t          |           d          }|                                } d                    |                                           } d                    |                                           } t          |           S # t          $ r t          |           cY S w xY w# t          $ r t          |           cY S w xY w)z!Clean body of a message or event.r   )BeautifulSoupzhtml.parser  )	bs4r   r   get_textjoin
splitlinessplit	ExceptionImportError)r   r   soups      e/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/tools/office365/utils.py
clean_bodyr      s    %%%%%%	 =TM::D==??D 774??,,--D 88DJJLL))Dt99 	 	 	t99	   4yys/   B2 B	B B/,B2 .B//B2 2CCr   c                    	 ddl m}  n"# t          $ r}t          d          |d}~ww xY wdt          j        v r7dt          j        v r)t          j        d         }t          j        d         }||f}nt
                              d           dS  | |          }|j        du r+|                    g d	
          st          d           dS |S |S )z*Authenticate using the Microsoft Graph APIr   r   zGCannot import 0365. Please install the package with `pip install O365`.N	CLIENT_IDCLIENT_SECRETzError: The CLIENT_ID and CLIENT_SECRET environmental variables have not been set. Visit the following link on how to acquire these authorization tokens: https://learn.microsoft.com/en-us/graph/auth/F)z*https://graph.microsoft.com/Mail.ReadWritez%https://graph.microsoft.com/Mail.Sendz/https://graph.microsoft.com/Calendars.ReadWritez5https://graph.microsoft.com/MailboxSettings.ReadWrite)scopeszError: Could not authenticate)
O365r   r   osenvironloggererroris_authenticatedauthenticateprint)r   e	client_idclient_secretcredentialsaccounts         r   r"   r"   &   s             U
 
	
 bj  _
%B%BJ{+	
?3 -0D	
 	
 	

 tgk""G5((##   $ 
 
 	 12224Ns   	 
(#(z%Y-%m-%dT%H:%M:%S%z)r   r   r	   r   )r	   r   )__doc__
__future__r   loggingr   typingr   r   r   	getLogger__name__r   r   r"   
UTC_FORMAT     r   <module>r2      s      " " " " " "  				             		8	$	$   .% % % %P #
 & &r1   