
    dh!                    0   S r SSKJr  SSKrSSKrSSKJrJrJrJ	r	  SSK
Jr  \(       a  SSKJr  SSKJr  SSKJr  SS	KJr  SS
KJr  \R,                  " \5      rSS jrSS jrSS jrS/rSrSr   S       SS jjr   S       SS jjr SS jr!g)zGmail tool utils.    )annotationsN)TYPE_CHECKINGListOptionalTuple)guard_import)Request)Credentials)InstalledAppFlow)Resource)buildc                 R    [        SSS9R                  [        SSS9R                  4$ )zeImport 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
        ]/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/tools/gmail/utils.pyimport_googler      s6     	8+	
 '3>T	

+ r   c                 *    [        SSS9R                  $ )zWImport 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                 *    [        SSS9R                  $ )zyImport 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                   [        5       u  p4[        5       nSnU=(       d    [        nU =(       d    [        n U=(       d    [        n[
        R                  R                  U 5      (       a  UR                  " X5      nU(       a  UR                  (       d  U(       a9  UR                  (       a(  UR                  (       a  UR                  U" 5       5        O"UR                  " X5      nUR                  SSS9n[        U S5       nUR!                  UR#                  5       5        SSS5        U$ U$ ! , (       d  f       U$ = f)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7J-L1L 
ww~~j!!55jIU]]u':':MM')$ $<<#D ))qu)EE*c"eKK( #L5L #"Ls    D..
D=c                J    U =(       d
    [        5       n [        5       nU" XU S9$ )zBuild a Gmail service.)credentials)r4   r   )r6   service_nameservice_versionbuilders       r   build_resource_servicer:   c   s'     8!6!8K57G<kJJr   c                :    SSK Jn   U" [        U 5      S5      nUR                  5       n [        U 5      $ ! [         a*  n[
        R                  U5        [        U 5      s SnA$ SnAff = f! [         a#    [
        R                  S5        [        U 5      s $ f = f)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t9 	LLOt9	  HI4ys8   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   