
    7|h                    x    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y)zO365 tool utils.    )annotationsN)TYPE_CHECKINGAccountc                P   	 ddl m} 	  |t        |       d      }|j                         } dj	                  | j                               } dj	                  | j                               } 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   strget_textjoin
splitlinessplit	ExceptionImportError)bodyr   soups      h/var/www/html/test/engine/venv/lib/python3.12/site-packages/langchain_community/tools/office365/utils.py
clean_bodyr      s    %	 TM:D==?D 774??,-D 88DJJL)Dt9 	t9	 4ys/   B A*A4 4BB 
BB B%$B%c                    	 ddl m}  dt        j                  v r=dt        j                  v r+t        j                  d   }t        j                  d   }||f}nt
        j                  d       y | |      }|j                  du r"|j                  g d	
      st        d       y|S |S # t        $ r}t        d      |d}~ww xY w)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      bjj _

%BJJ{+	

?3 -0D	

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