ó
Gh\c           @   s{   d  Z  d d l Z d d l Z d d l m Z d d l m Z d d l m	 Z	 d d l
 m Z d e j f d „  ƒ  YZ d S(	   s    Base repository support iÿÿÿÿN(   t   exc_info(   t   CustomConfig(   t   getglobalui(   t   OfflineImapErrort   BaseRepositoryc           B   s  e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 e
 d „  ƒ Z d	 „  Z d
 „  Z d „  Z d „  Z e
 d „  ƒ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e d „ Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s‘  t  ƒ  |  _ | |  _ | j ƒ  |  _ | |  _ | j ƒ  |  _ |  j j ƒ  |  _	 |  j
 d t ƒ |  _ t j j |  j j ƒ  d |  j ƒ |  _ t j j |  j ƒ s¶ t j |  j d ƒ n  t j j |  j d ƒ |  _ t j j |  j ƒ sü t j |  j d ƒ n  t j j |  j d ƒ |  _ t j j |  j ƒ sBt j |  j d ƒ n  d „  |  _ d „  |  _ g  |  _ d  |  _ d  |  _ |  j j |  j ƒ  d ƒ r»|  j j |  j d ƒ i t d	 6ƒ |  _ n  |  j j |  j ƒ  d
 ƒ r|  j j |  j d
 ƒ i t d	 6ƒ |  _ n  |  j j |  j ƒ  d ƒ rG|  j j |  j d ƒ i t d	 6ƒ |  _ n  |  j j |  j ƒ  d ƒ r|  j j |  j d ƒ i t d	 6ƒ |  _ n  d  S(   Nt   readonlys   Repository-iÀ  t
   UIDMappingt   FolderValidityc         S   s   |  S(   N(    (   t
   foldername(    (    s5   /usr/share/offlineimap/offlineimap/repository/Base.pyt   <lambda>0   t    c         S   s   d S(   Ni   (    (   R   (    (    s5   /usr/share/offlineimap/offlineimap/repository/Base.pyR	   1   R
   t	   nametranst   ret   folderfiltert   folderincludest
   foldersort(    R   t   uit   accountt	   getconfigt   configt   namet   getlocalevalt	   localevalt   getnamet   _accountnamet   getconfbooleant   Falset	   _readonlyt   ost   patht   joint   getmetadatadirt   uiddirt   existst   mkdirt   mapdirR   R   R   t   NoneR   t   newmail_hookt
   has_optiont
   getsectiont   evalt   getconfR   (   t   selft	   reposnameR   (    (    s5   /usr/share/offlineimap/offlineimap/repository/Base.pyt   __init__   sB    		(				"	"	"	c         C   s   d S(   sé   Sets folders' atime back to their values after a sync

        Controlled by the 'restoreatime' config parameter (default
        False), applies only to local Maildir mailboxes and does nothing
        on all other repository types.N(    (   R*   (    (    s5   /usr/share/offlineimap/offlineimap/repository/Base.pyt   restore_atimeB   s    c         C   s   d S(   sv  Establish a connection to the remote, if necessary.  This exists
        so that IMAP connections can all be established up front, gathering
        passwords as needed.  It was added in order to support the
        error recovery -- we need to connect first outside of the error
        trap in order to validate the password, and that's the point of
        this function.N(    (   R*   (    (    s5   /usr/share/offlineimap/offlineimap/repository/Base.pyt   connectK   s    c         C   s   d  S(   N(    (   R*   (    (    s5   /usr/share/offlineimap/offlineimap/repository/Base.pyt   holdordropconnectionsU   s    c         C   s   d  S(   N(    (   R*   (    (    s5   /usr/share/offlineimap/offlineimap/repository/Base.pyt   dropconnectionsX   s    c         C   s   |  j  S(   N(   R   (   R*   (    (    s5   /usr/share/offlineimap/offlineimap/repository/Base.pyt
   getaccount[   s    c         C   s   |  j  S(   N(   R   (   R*   (    (    s5   /usr/share/offlineimap/offlineimap/repository/Base.pyR   ^   s    c         C   s   |  j  S(   N(   R   (   R*   (    (    s5   /usr/share/offlineimap/offlineimap/repository/Base.pyt   __str__a   s    c         C   s   |  j  S(   s   Account name as string(   R   (   R*   (    (    s5   /usr/share/offlineimap/offlineimap/repository/Base.pyt   accountnamed   s    c         C   s   |  j  S(   N(   R    (   R*   (    (    s5   /usr/share/offlineimap/offlineimap/repository/Base.pyt	   getuiddirj   s    c         C   s   |  j  S(   N(   R#   (   R*   (    (    s5   /usr/share/offlineimap/offlineimap/repository/Base.pyt	   getmapdirm   s    c         C   s   d |  j  S(   Ns   Repository (   R   (   R*   (    (    s5   /usr/share/offlineimap/offlineimap/repository/Base.pyR'   q   s    c         C   s   |  j  S(   N(   R   (   R*   (    (    s5   /usr/share/offlineimap/offlineimap/repository/Base.pyR   u   s    c         C   s   |  j  S(   s   Is the repository readonly?(   R   (   R*   (    (    s5   /usr/share/offlineimap/offlineimap/repository/Base.pyR   x   s    c         C   s   |  j  j ƒ  S(   N(   R   R   (   R*   (    (    s5   /usr/share/offlineimap/offlineimap/repository/Base.pyR   ~   s    c         C   s   g  S(   s-   Returns a list of ALL folders on this server.(    (   R*   (    (    s5   /usr/share/offlineimap/offlineimap/repository/Base.pyt
   getfolders   s    c         C   s   d S(   sT   Forgets the cached list of folders, if any.  Useful to run
        after a sync run.N(    (   R*   (    (    s5   /usr/share/offlineimap/offlineimap/repository/Base.pyt   forgetfolders†   s    c         C   s
   t  ‚ d  S(   N(   t   NotImplementedError(   R*   (    (    s5   /usr/share/offlineimap/offlineimap/repository/Base.pyt   getsepŒ   s    c         C   s
   t  ‚ d  S(   N(   R8   (   R*   (    (    s5   /usr/share/offlineimap/offlineimap/repository/Base.pyt   getkeywordmap   s    c         C   s   | |  j  k p |  j | ƒ S(   s   Should this folder be synced?(   R   R   (   R*   t   fname(    (    s5   /usr/share/offlineimap/offlineimap/repository/Base.pyt   should_sync_folder’   s    c         C   s   |  j  o |  j d t ƒ S(   s©   Is folder creation enabled on this repository?

        It is disabled by either setting the whole repository
        'readonly' or by using the 'createfolders' setting.t   createfolders(   R   R   t   True(   R*   (    (    s5   /usr/share/offlineimap/offlineimap/repository/Base.pyt   should_create_folders—   s    
c         C   s
   t  ‚ d S(   s   Create a new folder.N(   R8   (   R*   R   (    (    s5   /usr/share/offlineimap/offlineimap/repository/Base.pyt
   makefolder    s    c         C   s
   t  ‚ d  S(   N(   R8   (   R*   R   (    (    s5   /usr/share/offlineimap/offlineimap/repository/Base.pyt   deletefolder¥   s    c         C   s
   t  ‚ d S(   sÇ   Get the folder for this repo.

        WARNING: the signature changes whether it's remote or local:
        - remote types have the decode arg
        - local types don't have the decode arg
        N(   R8   (   R*   R   t   decode(    (    s5   /usr/share/offlineimap/offlineimap/repository/Base.pyt	   getfolder¨   s    c         C   s	  |  j  ƒ  r | j  ƒ  r d S|  } i  i  } } x$ | j ƒ  D] } | | | j ƒ  <q> Wx$ | j ƒ  D] } | | | j ƒ  <qe Wxì | j ƒ  D]Þ \ } } | j  ƒ  s¨ Pn  | j ƒ  j | j ƒ  | j ƒ  ƒ }	 | j rŒ |	 | j ƒ  k rŒ y | j	 |	 ƒ | j
 ƒ  Wn= t k
 rA}
 |  j j |
 t ƒ  d d |	 | f ƒ ‚  n X| j	 |	 j | j ƒ  | j ƒ  ƒ ƒ qŒ qŒ Wx”| j ƒ  D]†\ }	 } | j  ƒ  s—Pn  | j ƒ  j | j ƒ  | j ƒ  ƒ } | j r{| | j ƒ  k r{| j | ƒ s|  j j d d | |  f ƒ q{n  | j | d t ƒ} | j ƒ  j | j ƒ  | j ƒ  ƒ } |	 | k r~t d | j ƒ  | | | | f t j j ƒ ‚ n  y | j	 | ƒ |  j
 ƒ  Wn= t k
 rØ}
 |  j j |
 t ƒ  d d | | f ƒ ‚  n X| j	 |	 j | j ƒ  | j ƒ  ƒ ƒ q{q{Wd S(   sú   Sync the folders structure.

        It does NOT sync the contents of those folders. nametrans rules
        in both directions will be honored

        Configuring nametrans on BOTH repositories could lead to infinite folder
        creation cycles.Ni   s#   Creating folder %s on repository %sR
   sZ   Not creating folder '%s' (repository '%s') as it would be filtered out on that repository.RB   s§  INFINITE FOLDER CREATION DETECTED! Folder '%s' (repository '%s') would be created as folder '%s' (repository '%s'). The latter becomes '%s' in return, leading to infinite folder creation cycles.
 SOLUTION: 1) Do set your nametrans rules on both repositories so they lead to identical names if applied back and forth. 2) Use folderfilter settings on a repository to prevent some folders from being created on the other side.(   R?   R6   R   t   itemst   getvisiblenamet   replaceR9   t	   sync_thist   keysR@   R7   R   R   t   errorR    R<   t   debugRC   R   t   ERRORt   REPOR$   (   R*   t
   local_repot   status_repot   remote_repot   remote_hasht
   local_hasht   foldert   remote_namet   remote_foldert
   local_namet   et   local_foldert   tmp_remotefoldert	   loop_name(    (    s5   /usr/share/offlineimap/offlineimap/repository/Base.pyt   sync_folder_structure±   sj    	 	 c         C   s   d S(   s+   The default implementation will do nothing.N(    (   R*   (    (    s5   /usr/share/offlineimap/offlineimap/repository/Base.pyt   startkeepalive  s    c         C   s   d S(   sO   Stop keep alive, but don't bother waiting
        for the threads to terminate.N(    (   R*   (    (    s5   /usr/share/offlineimap/offlineimap/repository/Base.pyt   stopkeepalive"  s    c         C   s   d S(   sY    Local root folder for storing messages.
        Will not be set for remote repositories.N(   R$   (   R*   (    (    s5   /usr/share/offlineimap/offlineimap/repository/Base.pyt   getlocalroot(  s    (    t   __name__t
   __module__R,   R-   R.   R/   R0   R1   R   R2   t   propertyR3   R4   R5   R'   R   R   R   R6   R7   R9   R:   R<   R?   R@   RA   R>   RC   RZ   R[   R\   R]   (    (    (    s5   /usr/share/offlineimap/offlineimap/repository/Base.pyR      s8   	%			
																					l		(   t   __doc__R   t   os.pathR   t   sysR    t   offlineimapR   t   offlineimap.uiR   t   offlineimap.errorR   t   ConfigHelperMixinR   (    (    (    s5   /usr/share/offlineimap/offlineimap/repository/Base.pyt   <module>   s   