Ñò
u©×Nc           @   s  d  d k  l Z l Z l Z d  d k l Z d  d k l Z d  d k l	 Z	 d  d k
 l Z l Z d  d k l Z d  d k Z d  d k l Z d  d k Z y d  d k Z Wn n Xd	 „  Z d
 „  Z d „  Z d e i f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d S(   iÿÿÿÿ(   t   mbnamest   CustomConfigt   OfflineImapError(   t
   Repository(   t   getglobalui(   t   InstanceLimitedThread(   t   Popent   PIPE(   t   EventN(   t   exc_infoc         C   s   |  i  d ƒ S(   Nt   Account(   t   getsectionlist(   t   customconfig(    (    sx   /projectLibrary/707976 EPBuoyPrototypeAndTesting/SpotWatchCircleAlarm/spaetz-offlineimap-5f3ac2c/offlineimap/accounts.pyt   getaccountlist    s    c         C   s.   g  } t  |  ƒ D] } | t |  | ƒ q ~ S(   N(   R   R
   (   R   t   _[1]t   accountname(    (    sx   /projectLibrary/707976 EPBuoyPrototypeAndTesting/SpotWatchCircleAlarm/spaetz-offlineimap-5f3ac2c/offlineimap/accounts.pyt   AccountListGenerator#   s    c         C   s1   h  } x$ t  |  ƒ D] } | | | i ƒ  <q W| S(   N(   R   t   getname(   R   t   retvalt   item(    (    sx   /projectLibrary/707976 EPBuoyPrototypeAndTesting/SpotWatchCircleAlarm/spaetz-offlineimap-5f3ac2c/offlineimap/accounts.pyt   AccountHashGenerator'   s
     R
   c           B   sn   e  Z d  Z e ƒ  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 e d „  ƒ Z d „  Z d	 „  Z RS(
   sÖ   Represents an account (ie. 2 repositories) to sync

    Most of the time you will actually want to use the derived
    :class:`accounts.SyncableAccount` which contains all functions used
    for syncing an account.c         C   s{   | |  _  | |  _ | i ƒ  |  _ | i ƒ  |  _ t ƒ  |  _ |  i d d ƒ |  _	 d |  _
 |  i	 d j o d |  _	 n d S(   sö   
        :param config: Representing the offlineimap configuration file.
        :type config: :class:`offlineimap.CustomConfig.CustomConfigParser`

        :param name: A string denoting the name of the Account
                     as configuredt   autorefreshg        i    N(   t   configt   namet   getmetadatadirt   metadatadirt   getlocalevalt	   localevalR   t   uit   getconffloatt   refreshperiodt   quicknumt   None(   t   selfR   R   (    (    sx   /projectLibrary/707976 EPBuoyPrototypeAndTesting/SpotWatchCircleAlarm/spaetz-offlineimap-5f3ac2c/offlineimap/accounts.pyt   __init__7   s    			c         C   s   |  i  S(   N(   R   (   R!   (    (    sx   /projectLibrary/707976 EPBuoyPrototypeAndTesting/SpotWatchCircleAlarm/spaetz-offlineimap-5f3ac2c/offlineimap/accounts.pyR   I   s    c         C   s   |  i  S(   N(   R   (   R!   (    (    sx   /projectLibrary/707976 EPBuoyPrototypeAndTesting/SpotWatchCircleAlarm/spaetz-offlineimap-5f3ac2c/offlineimap/accounts.pyt	   getconfigL   s    c         C   s   |  i  S(   N(   R   (   R!   (    (    sx   /projectLibrary/707976 EPBuoyPrototypeAndTesting/SpotWatchCircleAlarm/spaetz-offlineimap-5f3ac2c/offlineimap/accounts.pyR   O   s    c         C   s   |  i  S(   N(   R   (   R!   (    (    sx   /projectLibrary/707976 EPBuoyPrototypeAndTesting/SpotWatchCircleAlarm/spaetz-offlineimap-5f3ac2c/offlineimap/accounts.pyt   __str__R   s    c         C   s   d |  i  ƒ  S(   Ns   Account (   R   (   R!   (    (    sx   /projectLibrary/707976 EPBuoyPrototypeAndTesting/SpotWatchCircleAlarm/spaetz-offlineimap-5f3ac2c/offlineimap/accounts.pyt
   getsectionU   s    c         C   sa   | d j o2 xM t  | ƒ D] } | i d | d d ƒ q Wn | d j o |  i i ƒ  n d S(   s  Set skip sleep/abort event for all accounts

        If we want to skip a current (or the next) sleep, or if we want
        to abort an autorefresh loop, the main thread can use
        set_abort_event() to send the corresponding signal. Signum = 1
        implies that we want all accounts to abort or skip the current
        or next sleep phase. Signum = 2 will end the autorefresh loop,
        ie all accounts will return after they finished a sync.

        This is a class method, it will send the signal to all accounts.
        i   s   Account t	   skipsleept   1i   N(   R   t   sett   abort_signal(   t   clsR   t   signumt   acctsection(    (    sx   /projectLibrary/707976 EPBuoyPrototypeAndTesting/SpotWatchCircleAlarm/spaetz-offlineimap-5f3ac2c/offlineimap/accounts.pyt   set_abort_eventX   s     c         C   sM   |  i  d d ƒ } | o  |  i i |  i ƒ  d d ƒ n | p t i i ƒ  S(   su  Checks if an abort signal had been sent

        If the 'skipsleep' config option for this account had been set,
        with `set_abort_event(config, 1)` it will get cleared in this
        function. Ie, we will only skip one sleep and not all.

        :returns: True, if the main thread had called
            :meth:`set_abort_event` earlier, otherwise 'False'.
        R&   i    t   0(   t   getconfbooleanR   R(   R%   R
   R)   t   is_set(   R!   R&   (    (    sx   /projectLibrary/707976 EPBuoyPrototypeAndTesting/SpotWatchCircleAlarm/spaetz-offlineimap-5f3ac2c/offlineimap/accounts.pyt   get_abort_eventm   s    
 c         C   sé   |  i  p d Sg  } t |  d ƒ o | i |  i ƒ n t |  d ƒ o | i |  i ƒ n x | D] } | i ƒ  qd Wt |  i  d ƒ } |  i i | |  ƒ } x | D] } | i	 ƒ  q§ W| o# t
 i i ƒ  o d Sd |  _ d Sd S(   sÜ   Sleep if the account is set to autorefresh

        :returns: 0:timeout expired, 1: canceled the timer,
                  2:request to abort the program,
                  100: if configured to not sleep at all.
        id   t
   localrepost   remotereposi<   i   i    i   (   R   t   hasattrt   appendR2   R3   t   startkeepalivet   intR   t   sleept   stopkeepaliveR
   R)   R0   R   (   R!   t   kaobjsR   R   t   sleepresult(    (    sx   /projectLibrary/707976 EPBuoyPrototypeAndTesting/SpotWatchCircleAlarm/spaetz-offlineimap-5f3ac2c/offlineimap/accounts.pyt   sleeper|   s*    
  	(   t   __name__t
   __module__t   __doc__R   R)   R"   R   R#   R   R$   R%   t   classmethodR-   R1   R<   (    (    (    sx   /projectLibrary/707976 EPBuoyPrototypeAndTesting/SpotWatchCircleAlarm/spaetz-offlineimap-5f3ac2c/offlineimap/accounts.pyR
   .   s   								t   SyncableAccountc           B   sM   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   sÕ   A syncable email account connecting 2 repositories

    Derives from :class:`accounts.Account` but contains the additional
    functions :meth:`syncrunner`, :meth:`sync`, :meth:`syncfolders`,
    used for syncing.c         O   sE   t  i |  | | Ž d  |  _ t i i |  i i ƒ  d |  ƒ |  _	 d  S(   Ns   %s.lock(
   R
   R"   R    t   _lockfdt   ost   patht   joinR   R   t   _lockfilepath(   R!   t   argst   kwargs(    (    sx   /projectLibrary/707976 EPBuoyPrototypeAndTesting/SpotWatchCircleAlarm/spaetz-offlineimap-5f3ac2c/offlineimap/accounts.pyR"   ¦   s    	c         C   sˆ   t  |  i d ƒ |  _ y! t i |  i t i t i Bƒ WnK t j
 o n: t j
 o- |  i i	 ƒ  t
 d |  t
 i i ƒ ‚ n Xd S(   s?   Lock the account, throwing an exception if it is locked alreadyt   ws   Could not lock account %s.N(   t   openRF   RB   t   fcntlt   lockft   LOCK_EXt   LOCK_NBt	   NameErrort   IOErrort   closeR   t   ERRORt   REPO(   R!   (    (    sx   /projectLibrary/707976 EPBuoyPrototypeAndTesting/SpotWatchCircleAlarm/spaetz-offlineimap-5f3ac2c/offlineimap/accounts.pyt   lock¬   s    !
c         C   sW   |  i  oI |  i  i o; |  i  i ƒ  y t i |  i ƒ WqS t j
 o qS Xn d S(   s*   Unlock the account, deleting the lock fileN(   RB   t   closedRQ   RC   t   unlinkRF   t   OSError(   R!   (    (    sx   /projectLibrary/707976 EPBuoyPrototypeAndTesting/SpotWatchCircleAlarm/spaetz-offlineimap-5f3ac2c/offlineimap/accounts.pyt   unlockº   s    c      	   C   sè  |  i  i |  i ƒ |  i ƒ  } t i i | ƒ p t i | d ƒ n t |  d ƒ |  _	 t |  d ƒ |  _
 t |  d ƒ |  _ d } x_| oW|  i  i |  ƒ zy |  i ƒ  |  i ƒ  WnÎ t t f j
 o
 ‚  nÈ t j
 oo } | i t i i j o6 | o | d 8} n | i t i i j o ‚  q1n |  i  i | t ƒ  d ƒ nN t j
 o- } |  i  i | t ƒ  d d d	 |  ƒn X|  i o
 d } n Wd  |  i  i |  ƒ |  i ƒ  | o |  i ƒ  d j o
 d
 } n Xq… Wd  S(   NiÀ  t   remotet   localt   statusi   i   i   t   msgs%   While attempting to sync account '%s'i    (   R   t   registerthreadR   t   getaccountmetaRC   RD   t   existst   mkdirR   R3   R2   t   statusrepost   acctRT   t   synct   KeyboardInterruptt
   SystemExitR   t   severityRR   RS   t   CRITICALt   errorR	   t	   ExceptionR   t   acctdoneRX   R<   (   R!   t   accountmetadatat   loopingt   e(    (    sx   /projectLibrary/707976 EPBuoyPrototypeAndTesting/SpotWatchCircleAlarm/spaetz-offlineimap-5f3ac2c/offlineimap/accounts.pyt
   syncrunnerÄ   sB      


c         C   s   t  i i |  i d |  i ƒ S(   Ns   Account-(   RC   RD   RE   R   R   (   R!   (    (    sx   /projectLibrary/707976 EPBuoyPrototypeAndTesting/SpotWatchCircleAlarm/spaetz-offlineimap-5f3ac2c/offlineimap/accounts.pyR^   ì   s    c         C   sl  g  } |  i  d d ƒ } |  i | ƒ |  i d d ƒ } | d j  o
 t } na | d j oM |  i d j p |  i | j o d |  _ t } q® |  i d |  _ t } n t } yf|  i } |  i } |  i } | i	 ƒ  | i	 ƒ  | i	 ƒ  | i
 d t ƒ p' |  i i | | ƒ | i | | ƒ n x³ | i	 ƒ  D]¥ } | i p$ |  i i d d | | f ƒ q1n t d d	 |  i i ƒ  d
 t d d | |  f d |  i | | | | | f ƒ }	 |	 i d ƒ |	 i ƒ  | i |	 ƒ q1Wx | D] }
 |
 i ƒ  qáWt i ƒ  | i ƒ  | i ƒ  Wn | i ƒ  | i ƒ  ‚  n X| i ƒ  | i ƒ  |  i  d d ƒ } |  i | ƒ d S(   sô   Synchronize the account once, then return

        Assumes that `self.remoterepos`, `self.localrepos`, and
        `self.statusrepos` has already been populated, so it should only
        be called from the :meth:`syncrunner` function.
        t   presynchookt    t   quicki    i   t   readonlys+   Not syncing filtered remote folder '%s'[%s]t   instancenamet   FOLDER_t   targetR   s   Folder %s [acc: %s]RG   t   postsynchookN(   t   getconft   callhookt
   getconfintt   TrueR   t   FalseR3   R2   Ra   t
   getfoldersR/   R   t   syncfolderst   syncfolderstot	   sync_thist   debugR   R   t
   syncfolderR   t	   setDaemont   startR5   RE   R    t   writet   forgetfolderst   dropconnectionst   holdordropconnections(   R!   t   folderthreadst   hookt   quickconfigRq   R3   R2   Ra   t   remotefoldert   threadt   thr(    (    sx   /projectLibrary/707976 EPBuoyPrototypeAndTesting/SpotWatchCircleAlarm/spaetz-offlineimap-5f3ac2c/offlineimap/accounts.pyRc   ï   sh    
 	

			


 

 





c         C   sÜ   | p d  Syy |  i  i d | ƒ t | d t d t d t d t d t ƒ} | i ƒ  } |  i  i d | ƒ |  i  i d | i ƒ WnP t t f j
 o
 ‚  n6 t	 j
 o) } |  i  i
 | t ƒ  d	 d
 d ƒn Xd  S(   Ns   Calling hook: t   shellt   stdint   stdoutt   stderrt	   close_fdss   Hook stdout: %s
Hook stderr:%s
s   Hook return code: %di   R\   s   Calling hook(   R   Rx   R   Rz   R   t   communicatet
   returncodeRd   Re   Ri   Rh   R	   (   R!   t   cmdt   pt   rRm   (    (    sx   /projectLibrary/707976 EPBuoyPrototypeAndTesting/SpotWatchCircleAlarm/spaetz-offlineimap-5f3ac2c/offlineimap/accounts.pyRx   ;  s    	(
   R=   R>   R?   R"   RT   RX   Rn   R^   Rc   Rx   (    (    (    sx   /projectLibrary/707976 EPBuoyPrototypeAndTesting/SpotWatchCircleAlarm/spaetz-offlineimap-5f3ac2c/offlineimap/accounts.pyRA   Ÿ   s   			
	(		Lc   
      C   s¼  t  ƒ  } | i |  ƒ yÍ| i | i ƒ  i | i ƒ  | i ƒ  ƒ ƒ } | i p | i d d | ƒ d St i	 |  | i ƒ  ƒ | i | i ƒ  i | i ƒ  | i ƒ  ƒ ƒ } | i
 ƒ  d j o | i ƒ  n | i ƒ  | oB | i | ƒ o- | i | ƒ o | i | ƒ | i ƒ  d Sn | i | | | | ƒ | i | | ƒ | i ƒ  | i | | | i ƒ  ƒ | i ƒ  p | i ƒ  oV | i ƒ  p | i | ƒ | i ƒ  d S| i ƒ  p | i | ƒ | i ƒ  d Sn | i ƒ  | i ƒ  | i | | ƒ | i ƒ  | i | | | i ƒ  ƒ | i d t ƒ p* | i | | | | ƒ | i | | ƒ n | i d d | i ƒ  ƒ | i d t ƒ p* | i | | | | ƒ | i | | ƒ n | i d d | i ƒ  ƒ | i ƒ  | i ƒ  WnÒ t t f j
 o
 ‚  n¸ t  j
 ok }	 |	 i! t  i" i# j o ‚  q¸| i$ |	 t% ƒ  d d d	 | i ƒ  i | i ƒ  | i ƒ  ƒ |  f ƒnB t& j
 o5 }	 | i$ |	 d d
 |  | i ƒ  t' i( ƒ  f ƒn Xd S(   sª   This function is called as target for the
    InstanceLimitedThread invokation in SyncableAccount.

    Filtered folders on the remote side will not invoke this function.Rp   s&   Not syncing filtered local folder '%s'NRr   t   imaps(   Not syncing to read-only repository '%s'i   R\   s&   Aborting sync, folder '%s' [acc: '%s']s(   ERROR in syncfolder for %s folder %s: %s()   R   R]   t	   getfoldert   getvisiblenamet   replacet   getsepR   R€   R    t   addt   getuidvalidityR    t   deletemessagelistt   cachemessagelistt   quickchangedt   skippingfoldert   restore_atimet   syncingfoldert   loadmessagelistt   messagelistloadedt   getmessagecountt   isuidvalidityokt   validityproblemt   saveuidvalidityR/   R{   t   syncingmessagest   syncmessagestoR   t   saveRd   Re   R   Rf   RR   t   FOLDERRh   R	   Ri   t	   tracebackt
   format_exc(
   R   R3   R‹   R2   Ra   Rq   R   t   localfoldert   statusfolderRm   (    (    sx   /projectLibrary/707976 EPBuoyPrototypeAndTesting/SpotWatchCircleAlarm/spaetz-offlineimap-5f3ac2c/offlineimap/accounts.pyR   L  s†    	
	

	


	



(   t   offlineimapR    R   R   t   offlineimap.repositoryR   t   offlineimap.uiR   t   offlineimap.threadutilR   t
   subprocessR   R   t	   threadingR   RC   t   sysR	   R¯   RK   R   R   R   t   ConfigHelperMixinR
   RA   R   (    (    (    sx   /projectLibrary/707976 EPBuoyPrototypeAndTesting/SpotWatchCircleAlarm/spaetz-offlineimap-5f3ac2c/offlineimap/accounts.pyt   <module>   s$   			q­