
    ,hr                         d dl mZ d dlZd dlmZmZ d dlZd dlmZ d dl	m
Z
mZ d dlmZ d dlmZ d dlZd Zd	 Zd
 Zd Zd ZdddZd Zi Zd ZddZ G d de      Zy)    )unicode_literalsN)environpath)	iteritems)SafeConfigParserNoOptionError)urlopen)	urlencodec                 4    t        j                  d| z   |      S )Nimapclient_)r   get)namedefaults     S/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/imapclient/config.pygetenvr      s    ;;}T)733    c                      t        t        dd       t        dd       dddd d dddt        dd       t        dd       t        dd       d       S )	NusernamepasswordTFoauth2_client_idoauth2_client_secretoauth2_refresh_token)r   r   sslssl_check_hostnamessl_verify_certssl_ca_filetimeoutstarttlsstreamoauth2r   r   r   expect_failure)dictr    r   r   get_config_defaultsr$      s_    
D)
D) 2D9#$:DA#$:DA r   c                 @   t        t                     }t        | d      5 }|j                  |       ddd       t	        |d      }|j
                  rt        d      i |_        |j                         D ]  }t	        ||      |j                  |<    |S # 1 sw Y   cxY w)zaParse INI files containing IMAP connection details.

    Used by livetest.py and interact.py
    rNDEFAULTz8expect_failure should not be set for the DEFAULT section)	r   get_string_config_defaultsopenreadfp_read_config_sectionr!   
ValueError
alternatessections)filenameparserfhconfsections        r   parse_config_filer4   )   s     8:;F	h	 b  	2DSTTDO??$ I#7#H I K s   BBc                  d    i } t        t                     D ]  \  }}|du rd}n|du rd}|| |<    | S )NTtrueFfalse)r   r$   )outkvs      r   r(   r(   >   sK    
C-/0 19A%ZAA Jr   c                      fd} fd} fdfd}fd} |d      }|rt        j                  |      }t        di d |d      d |d      d	 |d	      d
 |d
      d |d      d |d      d|d |d      d |d      d |d      d |d      d |d      d |d      d |d      d |d      d |d      S )Nc                 (    j                  |       S N)r   r   r0   r3   s    r   <lambda>z&_read_config_section.<locals>.<lambda>J   s    vzz'40 r   c                 (    j                  |       S r=   )
getbooleanr>   s    r   r?   z&_read_config_section.<locals>.<lambda>K   s    f//> r   c                 ^    	 j                  |       }|sy  ||      S # t        $ r Y y w xY wr=   )r   r   )r   typefuncr:   r0   r3   s      r   get_allowing_nonez/_read_config_section.<locals>.get_allowing_noneM   s>    	

7D)A {	  		s     	,,c                      | t               S r=   )intr   rD   s    r   getintz$_read_config_section.<locals>.getintV   s     s++r   c                      | t               S r=   )floatrG   s    r   getfloatz&_read_config_section.<locals>.getfloatY   s     u--r   r   hostportr   r   r   r   r   r   r   r   r    r   r   r   r!   r#   )r   
expanduserBunch)r0   r3   r   rA   rH   rK   r   rD   s   ``     @r   r+   r+   I   s/   
0C>J,. m$Kook2 [F^ u J'	
 &&:; ##45   # (# Z Z (#  /0!" !!78#$ !!78%( +,) r   z*https://accounts.google.com/o/oauth2/tokenz,https://api.login.yahoo.com/oauth2/get_token)zimap.gmail.comzimap.mail.yahoo.comc                 v   t         j                  |       }|st        d| z        t        |j	                  d      |j	                  d      |j	                  d      d      }t        |t        |      j	                  d            j                         }t        j                  |j                  d            d   S )Nz/don't know where to refresh OAUTH2 token for %rasciis   refresh_token)	client_idclient_secretrefresh_token
grant_typeaccess_token)OAUTH2_REFRESH_URLSr   r,   r"   encoder	   r
   readjsonloadsdecode)hostnamerR   rS   rT   urlpostresponses          r   refresh_oauth2_tokenra   |   s    

!
!(
+CJXUVV)**73+227;+227;+-D sIdO227;<AACH::hoog./??r   c                 r    | |||f}t         j                  |      }|r|S t        | |||      }|t         |<   |S r=   )_oauth2_cacher   ra   )r]   rR   rS   rT   	cache_keytokens         r   get_oauth2_tokenrf      sG    9m]CIi(E 9m]SE$M)Lr   c                    | j                   sJ d       d }| j                  rnt        j                         }| j                  |_        | j
                  st        j                  |_        | j                  r|j                  | j                         t        j                  | j                   | j                  | j                  || j                  | j                        }|s|S 	 | j                  r|j                          | j                   r| j"                  sJ d       | j$                  sJ d       | j&                  sJ d       t)        | j                   | j"                  | j$                  | j&                        }|j+                  | j,                  |       |S | j                  sL| j,                  sJ d       | j.                  sJ d       |j1                  | j,                  | j.                         |S #  |j3                           xY w)	Nzmissing host)cafile)rM   r   ssl_contextr   r   zmissing oauth2 idzmissing oauth2 secretzmissing oauth2 refresh tokenzmissing usernamezmissing password)rL   r   create_default_contextr   check_hostnamer   	CERT_NONEverify_moder   load_verify_locations
imapclient
IMAPClientrM   r   r   r   r    r   r   r   rf   oauth2_loginr   r   loginshutdown)r2   rr   ri   clientrV   s        r   create_client_from_configru      s   99$n$Kxx002%)%<%<"##&)mmK#--T5E5E-F""499499'+xx/:*.+++/<<	9F
 ==OO;;((=*==,,E.EE,,L.LL+DII,0,A,A,0,E,E,0,E,EGL |< 	 ==4"44==4"44LL6s   "B4G1 AG1 1Hc                       e Zd Zd Zd Zy)rO   c                 4    	 | |   S # t         $ r t        w xY wr=   )KeyErrorAttributeError)selfr9   s     r   __getattr__zBunch.__getattr__   s%    	!7N 	!  	!s    c                     || |<   y r=   r#   )rz   r9   r:   s      r   __setattr__zBunch.__setattr__   s    Qr   N)__name__
__module____qualname__r{   r}   r#   r   r   rO   rO      s    !r   rO   )T)
__future__r   rZ   osr   r   r   sixr   six.moves.configparserr   r   six.moves.urllib.requestr	   six.moves.urllib.parser
   ro   r   r$   r4   r(   r+   rW   ra   rc   rf   ru   r"   rO   r#   r   r   <module>r      sq   
 (   
  B , , 4&*,^ CI 

@ )X	D 	r   