Ñò
u©×Nc           @   s  d  d k  Z  d  d k Z d  d k Z d  d k i Z d  d k Z d  d k Z d  d k Z d  d k	 l
 Z
 y d  d k Z Wn e j
 o n Xd  d k Z d  d k l Z l Z l Z d  d k l Z d  d k l Z l Z l Z d  d k l Z d d	 d „  ƒ  YZ d S(
   iÿÿÿÿN(   t   OptionParser(   t   accountst
   threadutilt
   syncmaster(   t   OfflineImapError(   t   UI_LISTt   setglobaluit   getglobalui(   t   CustomConfigParsert   OfflineImapc           B   s    e  Z d  Z d „  Z d „  Z RS(   s¥   The main class that encapsulates the high level use of OfflineImap.

    To invoke OfflineImap you would call it with::

      oi = OfflineImap()
      oi.run()
    c   '   $      sœ
  t  d t i d d t i t i f ƒ } | i d d d d d d	 t d
 d ƒ| i d d d d d d
 d ƒ| i d d d d d d
 d ƒ| i d d d d d d	 d d
 d ƒ| i d d d d d d
 d ƒ| i d d d d d d
 d  ƒ| i d! d d" d d# d
 d$ ƒ| i d% d d& d d' d d( d
 d) ƒ| i d* d d d d+ d	 t d
 d, ƒ| i d- d d d d. d	 t d
 d/ ƒ| i d0 d d1 d
 d2 d3 i t i	 ƒ  ƒ ƒ| i
 ƒ  \ } } t i i | i ƒ } t ƒ  } t i i | ƒ p" t i d4 | ƒ t i d5 ƒ n | i | ƒ | i o | i p t i d6 ƒ t | _ n t i i | i ƒ o t i d7 | i ƒ n t i | i ƒ t i i | i ƒ t i d8 | i ƒ n | i o„ x | i D]r } | i d9 d5 ƒ \ } } d: | j o. | i d: d5 ƒ \ }	 } |	 i  d; d< ƒ }
 n d= }
 | i! |
 | | ƒ qÅWn | i" d= d> d? ƒ } | i# dr j o | i# } n d@ | j o7 | i d@ ƒ dA } t i% dB d3 i t i	 ƒ  ƒ ƒ n y t | i& ƒ  | ƒ } WnF t' j
 o: t i dC | d3 i t i	 ƒ  ƒ f ƒ t i d5 ƒ n Xt( | ƒ | i) o | i* t+ | i) dD ƒ ƒ n | i, ƒ  | i- oÈ | i- i& ƒ  dE j o dF | _- n dG | i- i dH ƒ j o | i p | i. dI ƒ t | _ n | i- i dH ƒ dJ g } xK | D]? } | i/ ƒ  } | i0 | ƒ | i& ƒ  dK j o dL t1 _2 qÞqÞWn | i3 o2 x/ t4 i5 | ƒ D] }
 | i6 dM |
 dN ƒ q?Wn | i7 o5 x2 t4 i5 | ƒ D] }
 | i! dM |
 d. d ƒ q{Wn | i8 o³ | i8 i dH ƒ } dO | } dP } xŽ t4 i5 | ƒ D]y } dM | } dQ | i9 | dR ƒ } dQ | i9 | dS ƒ } x: | | g D], }
 | i! |
 dT | ƒ | i! |
 dU | ƒ q%WqÜWn | ˆ  _: dV „  } t; i; t; i< | ƒ yD t+ | i= ƒ  dW dX ƒ } | i> t? t i@ ƒ  ƒ dY ƒ | iA ƒ  Wn n Xy^| i) o | i) t _B n | iC d= dZ d[ ƒ } | d[ j o tD iE | ƒ n | i9 d= d ƒ } | i4 o | i4 } n | i  d< dJ ƒ } | i dH ƒ } t4 iF | ƒ } g  } xª | D]¢ } | | j oq tG | ƒ d[ j o d\ | } n0 d] | } x" | i	 ƒ  D] } | d^ | 7} qÑW| iH d5 d_ d` | da | ƒn | | j o | iI | ƒ q†q†Wdr } dr }  dr }! t iJ db | iC d= dc d5 ƒ ƒ xw | iK dd ƒ D]f }" x] de |" df |" g D]G }# | i o t iJ |# d5 ƒ qˆt iJ |# | iC dQ |" dg dh ƒ ƒ qˆWqmW‡  f di †  }$ t; i; t; iL |$ ƒ t; i; t; iM |$ ƒ t; i; t; iN |$ ƒ t iO iP | | ƒ t+ ˆ  i: i= ƒ  dj dX ƒ ˆ  _Q y! tR iS ˆ  iQ tR iT tR iU Bƒ Wn: tV j
 o n) tW j
 o tX dk tX iY iZ ƒ ‚ n X| i o ˆ  i[ | | ƒ nW t i dl t\ i] dm dn do h | d 6| dp 6ƒ }% |% i^ d5 ƒ |% i_ ƒ  t i` t ia ƒ | iH ƒ  Wng tb j
 o | iH d5 da dq ƒdr Stc j
 o
 ‚  n- td j
 o  }& | i |& ƒ | iH ƒ  n Xdr S(s   s+   Parse the commandline and invoke everythingt   versiont   descriptions   %s.

%ss   -1t   actiont
   store_truet   destt   singlethreadingt   defaultt   helps®   Disable all multithreading operations and use solely a single-thread sync. This effectively sets the maxsyncaccounts and all maxconnections configuration file variables to 1.s   -Pt
   profiledirt   metavart   DIRsÔ  Sets OfflineIMAP into profile mode. The program will create DIR (it must not already exist). As it runs, Python profiling information about each thread is logged into profiledir. Please note: This option is present for debugging and optimization only, and should NOT be used unless you have a specific reason to do so. It will significantly decrease program performance, may reduce reliability, and can generate huge amounts of data. This option implies the -1 option.s   -aR   t   ACCOUNTSs=  Overrides the accounts section in the config file.
              Lets you specify a particular account or set of
              accounts to sync without having to edit the config
              file. You might use this to exclude certain accounts,
              or to sync some accounts that you normally prefer not to.s   -ct
   configfilet   FILEs   ~/.offlineimaprcs:   Specifies a configuration file to use in lieu of %default.s   -dt	   debugtypes   type1,[type2...]sB  Enables debugging for OfflineIMAP. This is useful
              if you are to track down a malfunction or figure out what is
              going on under the hood. This option requires one or more
              debugtypes, separated by commas. These define what exactly
              will be debugged, and so far include two options: imap, thread,
              maildir or ALL. The imap option will enable IMAP protocol
              stream and parsing debugging. Note that the output may contain
              passwords, so take care to remove that from the debugging
              output before sending it to anyone else. The maildir option
              will enable debugging for certain Maildir operations.
              The use of any debug option (unless 'thread' is included),
              implies the single-thread option -1.s   -lt   logfiles   Log to FILEs   -ft   folderss   folder1,[folder2...]sÃ   Only sync the specified folders. The folder names are the *untranslated* foldernames. This command-line option overrides any 'folderfilter' and 'folderincludes' options in the configuration file.s   -kt   configoverridet   appends   [section:]option=valuess  Override configuration file option. If"section" is
              omitted, it defaults to "general". Any underscores
              in the section name are replaced with spaces:
              for instance, to override option "autorefresh" in
              the "[Account Personal]" section in the config file
              one would use "-k Account_Personal:autorefresh=30".s   -ot   runoncesJ   Run only once, ignoring any autorefresh setting in the configuration file.s   -qt   quicksº   Run only quick synchronizations. Ignore any flag updates on IMAP servers (if a flag on the remote IMAP changes, and we have the message locally, it will be left untouched in a quick run.s   -ut	   interfaces÷   Specifies an alternative user interface to use. This overrides the default specified in the configuration file. The UI specified with -u will be forced to be used, even if checks determine that it is not usable. Possible interface choices are: %s s   , s/    *** Config file '%s' does not exist; aborting!i   s(   Profile mode: Forcing to singlethreaded.s,   Profile mode: Directory '%s' already exists!s<   Profile mode: Potentially large data will be created in '%s't   =t   :t   _t    t   generalt   uit   ttyuit   .iÿÿÿÿs2   Using old interface name, consider using one of %ss)   UI '%s' does not exist, choose one of: %st   wtt   alls   imap,maildir,threadt   threadt   ,s&   Debug mode: Forcing to singlethreaded.t    t   imapi   s   Account t   autorefreshs   lambda f: f in %ss   []s   Repository t   remoterepositoryt   localrepositoryt   folderfiltert   folderincludesc         S   s   t  ƒ  } | i d d ƒ d  S(   Nt   errormsgs   terminating...(   R   t	   terminate(   t   signumt   frameR%   (    (    st   /projectLibrary/707976 EPBuoyPrototypeAndTesting/SpotWatchCircleAlarm/spaetz-offlineimap-5f3ac2c/offlineimap/init.pyt   sigterm_handlerö   s    	s   /pidt   ws   
t   socktimeouti    s@   The account "%s" does not exist because no accounts are defined!s5   The account "%s" does not exist.  Valid accounts are:s   
%st
   errortitles   Unknown Account "%s"R3   t   ACCOUNTLIMITt   maxsyncaccountst
   Repositoryt   FOLDER_t   MSGCOPY_t   maxconnectionsi   c            sh   |  t  i j p |  t  i j o t i i ˆ  i d ƒ n+ |  t  i j o t i i ˆ  i d ƒ n d  S(   Ni   i   (   t   signalt   SIGUSR1t   SIGHUPR   t   Accountt   set_abort_eventt   configt   SIGUSR2(   t   sigR6   (   t   self(    st   /projectLibrary/707976 EPBuoyPrototypeAndTesting/SpotWatchCircleAlarm/spaetz-offlineimap-5f3ac2c/offlineimap/init.pyt   sig_handler1  s     s   /locks   Could not take global lock.t   targett   names   Sync Runnert   kwargsRF   s   CTRL-C pressed, aborting...N(e   R    t   offlineimapt   __version__t   __copyright__t   __license__t
   add_optiont   Falset   joinR   t   keyst
   parse_argst   ost   patht
   expanduserR   R   t   existst   loggingt   errort   syst   exitt   readR   R   t   warnt   Truet   mkdirR   t   ExitNotifyThreadt   set_profiledirR   t   splitt   replacet   sett
   getdefaultR   t   Nonet   warningt   lowert   KeyErrorR   R   t   setlogfdt   opent   init_bannerR   t   _msgt   stript	   add_debugt   imaplibt   DebugR   R   t   getaccountlistt   remove_optionR   R   t   getRF   RA   t   SIGTERMt   getmetadatadirt   writet   strt   getpidt   closet   stderrt   getdefaultintt   sockett   setdefaulttimeoutt   AccountHashGeneratort   lenR4   R   t   initInstanceLimitt   getsectionlistRC   RB   RG   t   mbnamest   initt   _legacy_lockt   fcntlt   lockft   LOCK_EXt   LOCK_NBt	   NameErrort   IOErrorR   t   ERRORt   REPOt   sync_singlethreadedR   t	   syncitallt	   setDaemont   startt   exitnotifymonitorloopt   threadexitedt   KeyboardInterruptt
   SystemExitt	   Exception('   RI   t   parsert   optionst   argst   configfilenameRF   t   optiont   keyt   valuet   secnamet   sectiont   ui_typeR%   t
   debugtypest   typet   foldernamesR1   R2   t   accountnamet   account_sectiont   remote_repo_sectiont   local_repo_sectionR7   t   pidfdR9   t   activeaccountst   allaccountst   syncaccountst   accountR3   RL   t   servert   remoterepost
   localrepost	   reposnamet   instancenameRJ   t   tt   e(    (   RI   st   /projectLibrary/707976 EPBuoyPrototypeAndTesting/SpotWatchCircleAlarm/spaetz-offlineimap-5f3ac2c/offlineimap/init.pyt   run-   s   		

		

 		



 
 
 

 
 		

 
 !		 
 
	!


c         C   sG   x@ | D]8 } t  i i | | ƒ } d | t i ƒ  _ | i ƒ  q Wd S(   s®   Executed if we do not want a separate syncmaster thread

        :param accs: A list of accounts that should be synced
        :param config: The CustomConfig object
        s   Account sync %sN(   RN   R   t   SyncableAccountt	   threadingt   currentThreadRL   t
   syncrunner(   RI   t   accsRF   R§   R¯   (    (    st   /projectLibrary/707976 EPBuoyPrototypeAndTesting/SpotWatchCircleAlarm/spaetz-offlineimap-5f3ac2c/offlineimap/init.pyR‘   c  s
     (   t   __name__t
   __module__t   __doc__R·   R‘   (    (    (    st   /projectLibrary/707976 EPBuoyPrototypeAndTesting/SpotWatchCircleAlarm/spaetz-offlineimap-5f3ac2c/offlineimap/init.pyR	   %   s   	ÿ 7(    (   RW   R]   R¹   t   offlineimap.imaplib2t   imaplib2Rs   RA   R€   R[   t   optparseR    R‰   t   ImportErrorRN   R   R   R   t   offlineimap.errorR   t   offlineimap.uiR   R   R   t   offlineimap.CustomConfigR   R	   (    (    (    st   /projectLibrary/707976 EPBuoyPrototypeAndTesting/SpotWatchCircleAlarm/spaetz-offlineimap-5f3ac2c/offlineimap/init.pyt   <module>   s"   