Ë
    µŒj!  ã                  ó  — d Z ddlmZ ddlZddlZddlmZmZmZm	Z	 ddl
mZ er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  ej,                  e«      Zdd„Zdd„Zdd„ZdgZdZdZ	 	 	 d	 	 	 	 	 	 	 dd„Z	 	 	 d	 	 	 	 	 	 	 dd„Z dd„Z!y)zGmail tool utils.é    )ÚannotationsN)ÚTYPE_CHECKINGÚListÚOptionalÚTuple)Úguard_import)ÚRequest)ÚCredentials)ÚInstalledAppFlow)ÚResource)Úbuildc                 ó^   — t        dd¬«      j                  t        dd¬«      j                  fS )zqImport google libraries.

    Returns:
        Tuple[Request, Credentials]: Request and Credentials classes.
    zgoogle.auth.transport.requestszgoogle-auth-httplib2©Úmodule_nameÚpip_namezgoogle.oauth2.credentials)r   r	   r
   © ó    úo/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain_community/tools/gmail/utils.pyÚimport_googler      s6   € ô 	Ø8Ø+ô	
÷ ‰'ÜØ3Ð>Tô	
ç
‰+ðð r   c                 ó0   — t        dd¬«      j                  S )zcImport InstalledAppFlow class.

    Returns:
        InstalledAppFlow: InstalledAppFlow class.
    zgoogle_auth_oauthlib.flowzgoogle-auth-oauthlibr   )r   r   r   r   r   Úimport_installed_app_flowr   &   s   € ô Ø/Ð:PôçÑðr   c                 ó0   — t        dd¬«      j                  S )z…Import googleapiclient.discovery.build function.

    Returns:
        build_resource: googleapiclient.discovery.build function.
    zgoogleapiclient.discoveryzgoogle-api-python-clientr   )r   r   r   r   r   Ú'import_googleapiclient_resource_builderr   1   s   € ô Ø/Ð:Tôç�eðr   zhttps://mail.google.com/z
token.jsonzcredentials.jsonc                ó(  — t        «       \  }}t        «       }d}|xs t        }| xs t        } |xs t        }t
        j                  j                  | «      r |j                  | |«      }|r|j                  s�|r/|j                  r#|j                  r|j                   |«       «       n& |j                  ||«      }|j                  dd¬«      }t        | d«      5 }|j!                  |j#                  «       «       ddd«       |S |S # 1 sw Y   |S xY w)zGet credentials.Nr   F)ÚportÚopen_browserÚw)r   r   ÚDEFAULT_SCOPESÚDEFAULT_CREDS_TOKEN_FILEÚDEFAULT_CLIENT_SECRETS_FILEÚosÚpathÚexistsÚfrom_authorized_user_fileÚvalidÚexpiredÚrefresh_tokenÚrefreshÚfrom_client_secrets_fileÚrun_local_serverÚopenÚwriteÚto_json)	Ú
token_fileÚclient_secrets_fileÚscopesr	   r
   r   ÚcredsÚflowÚtokens	            r   Úget_gmail_credentialsr4   A   sõ   € ô )›?Ñ€Gˆ[Ü0Ó2ÐØ€EØÒ%”~€FØÒ7Ô7€JØ-ÒLÔ1LÐô 
‡w�w‡~�~�jÔ!Ø5�×5Ñ5°jÀ&ÓIˆá˜ŸšÙ�U—]’] u×':Ò':Ø�M‰M™'›)Õ$ð =Ð#×<Ñ<Ø# VóˆDð ×)Ñ)¨q¸uÐ)ÓEˆEä�*˜cÔ" eØ�K‰K˜Ÿ™›Ô(÷ #à€Lˆ5€L÷ #à€Lús   Ã DÄDc                óH   — | xs
 t        «       } t        «       } |||| ¬«      S )zBuild a Gmail service.)Úcredentials)r4   r   )r6   Úservice_nameÚservice_versionÚbuilders       r   Úbuild_resource_servicer:   c   s)   € ð Ò8Ô!6Ó!8€KÜ5Ó7€GÙ�< ¸kÔJÐJr   c                ó6  — 	 ddl m} 	  |t        | «      d«      }|j                  «       } t        | «      S # t        $ r*}t
        j                  |«       t        | «      cY d}~S d}~ww xY w# t        $ r# t
        j                  d«       t        | «      cY S w xY w)zClean email body.r   )ÚBeautifulSoupzhtml.parserNz/BeautifulSoup not installed. Skipping cleaning.)	Úbs4r<   ÚstrÚget_textÚ	ExceptionÚloggerÚerrorÚImportErrorÚwarning)Úbodyr<   ÚsoupÚes       r   Úclean_email_bodyrH   n   s€   € ðÝ%ð	Ù ¤ T£¨MÓ:ˆDØ—=‘=“?ˆDÜ�t“9ÐøÜò 	Ü�L‰L˜ŒOÜ�t“9Õûð	ûô ò Ü�‰ÐHÔIÜ�4‹yÒðús7   ‚A, ‰,6 ¶	A)¿A$ÁA)ÁA, Á$A)Á)A, Á,)BÂB)ÚreturnzTuple[Request, Credentials])rI   r   )rI   Úbuild_resource)NNN)r.   úOptional[str]r/   rK   r0   zOptional[List[str]]rI   r
   )NÚgmailÚv1)r6   zOptional[Credentials]r7   r>   r8   r>   rI   r   )rE   r>   rI   r>   )"Ú__doc__Ú
__future__r   Úloggingr!   Útypingr   r   r   r   Úlangchain_core.utilsr   Úgoogle.auth.transport.requestsr	   Úgoogle.oauth2.credentialsr
   Úgoogle_auth_oauthlib.flowr   Úgoogleapiclient.discoveryr   r   rJ   Ú	getLoggerÚ__name__rA   r   r   r   r   r   r    r4   r:   rH   r   r   r   Ú<module>rY      sÖ   ðÙ å "ã Û 	ß 7Ó 7å -áÝ6Ý5Ý:Ý2ÝAà	ˆ×	Ñ	˜8Ó	$€óó"óð -Ð-€Ø'Ð Ø0Ð ð !%Ø)-Ø"&ðØðà&ðð  ðð ó	ðF *.ØØðKØ&ðKàðKð ðKð ó	Kôr   