§
    Žpma÷2  ã                   óp   — 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  G d„ dej        ¦  «        ZdS )	a   Base repository support
Copyright (C) 2002-2017 John Goerzen & contributors

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
é    N)Úexc_info)ÚCustomConfig)Úgetglobalui)ÚOfflineImapErrorc                   óÜ   — e Z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ed„ ¦   «         Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd d„Zd„ Zd„ Zd„ Zd„ Z dS )!ÚBaseRepositoryz#
    Base Class for Repository
    c                 óH  — t          ¦   «         | _        || _        |                     ¦   «         | _        || _        |                     ¦   «         | _        | j                             ¦   «         | _	        |  
                    dd¦  «        | _        t          j                             | j                             ¦   «         d| j        z   ¦  «        | _        t          j                             | j        ¦  «        st          j        | j        d¦  «         t          j                             | j        d¦  «        | _        t          j                             | j        ¦  «        st          j        | j        d¦  «         t          j                             | j        d¦  «        | _        t          j                             | j        ¦  «        st          j        | j        d¦  «         d„ | _        d„ | _        g | _        d | _        d | _        | j                             |                      ¦   «         d	¦  «        r:| j                             |                      d	¦  «        d
t:          i¦  «        | _        | j                             |                      ¦   «         d¦  «        r:| j                             |                      d¦  «        d
t:          i¦  «        | _        | j                             |                      ¦   «         d¦  «        r:| j                             |                      d¦  «        d
t:          i¦  «        | _        | j                             |                      ¦   «         d¦  «        r<| j                             |                      d¦  «        d
t:          i¦  «        | _        d S d S )NÚreadonlyFzRepository-iÀ  Ú
UIDMappingÚFolderValidityc                 ó   — | S ©N© ©Ú
foldernames    ú6/usr/share/offlineimap3/offlineimap/repository/Base.pyú<lambda>z)BaseRepository.__init__.<locals>.<lambda>3   s   € ¨J€ ó    c                 ó   — dS )Né   r   r   s    r   r   z)BaseRepository.__init__.<locals>.<lambda>4   s   € ¨q€ r   Ú	nametransÚreÚfolderfilterÚfolderincludesÚ
foldersort)r   ÚuiÚaccountÚ	getconfigÚconfigÚnameÚgetlocalevalÚ	localevalÚgetnameÚ_accountnameÚgetconfbooleanÚ	_readonlyÚosÚpathÚjoinÚgetmetadatadirÚuiddirÚexistsÚmkdirÚmapdirr   r   r   r   Únewmail_hookÚ
has_optionÚ
getsectionÚevalÚgetconfr   )ÚselfÚ	reposnamer   s      r   Ú__init__zBaseRepository.__init__   sÜ  € Ý‘-”-ˆŒØˆŒØ×'Ò'Ñ)Ô)ˆŒØˆŒ	Ø ×-Ò-Ñ/Ô/ˆŒØ œL×0Ò0Ñ2Ô2ˆÔØ×,Ò,¨Z¸Ñ?Ô?ˆŒÝ”g—l’l 4¤;×#=Ò#=Ñ#?Ô#?Ø#0°4´9Ñ#<ñ>ô >ˆŒåŒw�~Š~˜dœkÑ*Ô*ð 	)ÝŒH�T”[ %Ñ(Ô(Ð(Ý”g—l’l 4¤;°Ñ=Ô=ˆŒÝŒw�~Š~˜dœkÑ*Ô*ð 	)ÝŒH�T”[ %Ñ(Ô(Ð(å”g—l’l 4¤;Ð0@ÑAÔAˆŒÝŒw�~Š~˜dœkÑ*Ô*ð 	)ÝŒH�T”[ %Ñ(Ô(Ð(à6Ð6ˆŒØ0Ð0ˆÔØ ˆÔØˆŒØ ˆÔØŒ;×!Ò! $§/¢/Ñ"3Ô"3°[ÑAÔAð 	7Ø!œ^×0Ò0Ø—’˜[Ñ)Ô)¨Dµ"¨:ñ7ô 7ˆDŒNàŒ;×!Ò! $§/¢/Ñ"3Ô"3°^ÑDÔDð 	:Ø $¤× 3Ò 3Ø—’˜^Ñ,Ô,¨tµR¨jñ!:ô !:ˆDÔàŒ;×!Ò! $§/¢/Ñ"3Ô"3Ð5EÑFÔFð 	<Ø"&¤.×"5Ò"5Ø—’Ð-Ñ.Ô.°µr°
ñ#<ô #<ˆDÔàŒ;×!Ò! $§/¢/Ñ"3Ô"3°\ÑBÔBð 	8Ø"œn×1Ò1Ø—’˜\Ñ*Ô*¨Tµ2¨Jñ8ô 8ˆDŒOˆOˆOð	8ð 	8r   c                 ó   — dS )zé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.Nr   ©r4   s    r   Úrestore_atimezBaseRepository.restore_atimeE   ó   € € € r   c                 ó   — dS )av  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.Nr   r8   s    r   ÚconnectzBaseRepository.connectL   r:   r   c                 ó   — dS )zN
        Hold the drop connections functions.

        Returns: None

        Nr   r8   s    r   Úholdordropconnectionsz$BaseRepository.holdordropconnectionsT   r:   r   c                 ó   — dS )zE
        Drop connections functions.

        Returns: None

        Nr   r8   s    r   ÚdropconnectionszBaseRepository.dropconnections\   r:   r   c                 ó   — | j         S )zO
        This patch returns the account

        Returns: The account

        )r   r8   s    r   Ú
getaccountzBaseRepository.getaccountd   s   € ð Œ|Ðr   c                 ó   — | j         S )z\
        Get the repository name

        Returns: String with the repository name

        ©r    r8   s    r   r#   zBaseRepository.getnamem   s   € ð ŒyÐr   c                 ó   — | j         S r   rD   r8   s    r   Ú__str__zBaseRepository.__str__v   s
   € ØŒyÐr   c                 ó   — | j         S )zAccount name as string)r$   r8   s    r   ÚaccountnamezBaseRepository.accountnamey   s   € ð Ô Ð r   c                 ó   — | j         S )z^
        The FolderValidity directory

        Returns: The FolderValidity directory

        )r+   r8   s    r   Ú	getuiddirzBaseRepository.getuiddir   ó   € ð Œ{Ðr   c                 ó   — | j         S )zZ
        Get the map dir (UIDMapping)

        Returns: The UIDMapping directory

        )r.   r8   s    r   Ú	getmapdirzBaseRepository.getmapdirˆ   rK   r   c                 ó   — d| j         z   S )NzRepository rD   r8   s    r   r1   zBaseRepository.getsection’   s   € Ø˜tœyÑ(Ð(r   c                 ó   — | j         S r   )r   r8   s    r   r   zBaseRepository.getconfig–   s
   € ØŒ{Ðr   c                 ó   — | j         S )zIs the repository readonly?)r&   r8   s    r   r
   zBaseRepository.readonly™   s   € ð Œ~Ðr   c                 ó4   — | j                              ¦   «         S )z]
        Get the account local eval.

        Returns: LocalEval class for account.

        )r   r!   r8   s    r   r!   zBaseRepository.getlocalevalŸ   s   € ð Œ|×(Ò(Ñ*Ô*Ð*r   c                 ó   — g S )z-Returns a list of ALL folders on this server.r   r8   s    r   Ú
getfolderszBaseRepository.getfolders¨   s	   € ð ˆ	r   c                 ó   — dS )zTForgets the cached list of folders, if any.  Useful to run
        after a sync run.Nr   r8   s    r   ÚforgetfolderszBaseRepository.forgetfolders­   r:   r   c                 ó   — t           ‚)zg
        Get the separator.

        This function is not implemented.

        Returns: None

        ©ÚNotImplementedErrorr8   s    r   ÚgetsepzBaseRepository.getsep±   ó
   € õ "Ð!r   c                 ó   — t           ‚)zi
        Get the keyword map.

        This function is not implemented.

        Returns: None

        rW   r8   s    r   ÚgetkeywordmapzBaseRepository.getkeywordmap¼   rZ   r   c                 ó>   — || j         v p|                      |¦  «        S )zShould this folder be synced?)r   r   )r4   Úfnames     r   Úshould_sync_folderz!BaseRepository.should_sync_folderÇ   s%   € ð ˜Ô+Ð+ÐG¨t×/@Ò/@ÀÑ/GÔ/GÐGr   c                 ó>   — | j          o|                      dd¦  «        S )z©Is folder creation enabled on this repository?

        It is disabled by either setting the whole repository
        'readonly' or by using the 'createfolders' setting.ÚcreatefoldersT)r&   r%   r8   s    r   Úshould_create_foldersz$BaseRepository.should_create_foldersÌ   s1   € ð ”NÐ"ð B¨×(;Ò(;¸OØ<@ñ)Bô )Bð 	Br   c                 ó   — t           ‚)zŸ
        Create a new folder.
        This function is not implemented

        Args:
            foldername: Folder to create

        Returns: None

        rW   ©r4   r   s     r   Ú
makefolderzBaseRepository.makefolderÕ   s
   € õ "Ð!r   c                 ó   — t           ‚)z§
        Remove the selected folder.

        This function is not implemented

        Args:
            foldername: Folder to delete

        Returns: None

        rW   rd   s     r   ÚdeletefolderzBaseRepository.deletefolderâ   s
   € õ "Ð!r   Tc                 ó   — t           ‚)zÇ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
        rW   )r4   r   Údecodes      r   Ú	getfolderzBaseRepository.getfolderð   s
   € õ "Ð!r   c                 óÆ  — |                       ¦   «         s|                      ¦   «         sdS | }i i }}|                     ¦   «         D ]}|||                     ¦   «         <   Œ|                     ¦   «         D ]}|||                     ¦   «         <   Œt          |                     ¦   «         ¦  «        D �]R\  }}|                      ¦   «         s �n7|                     ¦   «                              |                     ¦   «         |                     ¦   «         ¦  «        }	|j        râ|	t          | 	                    ¦   «         ¦  «        vr¿	 | 
                    |	¦  «         |                     ¦   «          nG# t          $ r:}
| j                             |
t          ¦   «         d         d|	›d|›�¦  «         ‚ d}
~
ww xY w| 
                    |	                     |                     ¦   «         |                     ¦   «         ¦  «        ¦  «         �ŒTt          |                     ¦   «         ¦  «        D �]<\  }	}|                      ¦   «         s �n!|                     ¦   «                              |                     ¦   «         |                     ¦   «         ¦  «        }|j        �rË|t          | 	                    ¦   «         ¦  «        v�r§|                     |¦  «        s%d|›d| ›d�}| j                             d|¦  «         ŒÏ|                     |d	¬
¦  «        }|                     ¦   «                              |                     ¦   «         |                     ¦   «         ¦  «        }|	|k    rCd|                     ¦   «         ›d|›d|›d|›d|›d�}t          |t          j        j        ¦  «        ‚	 | 
                    |¦  «         |                      ¦   «          nI# t          $ r<}
d|›d|›�}| j                             |
t          ¦   «         d         |¦  «         ‚ d}
~
ww xY w| 
                    |	                     |                     ¦   «         |                     ¦   «         ¦  «        ¦  «         �Œ>dS )zú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.Né   zCreating folder z on repository zNot creating folder 'z' (repository 'z2') as it would be filtered out on that repository.Ú F)ri   z+INFINITE FOLDER CREATION DETECTED! Folder 'z') would be created as folder 'z'). The latter becomes 'a  ' 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.)rb   rS   r#   ÚlistÚitemsÚgetvisiblenameÚreplacerY   Ú	sync_thisÚkeysre   rU   r   r   Úerrorr   r_   Údebugrj   ÚERRORÚREPO)r4   Ú
local_repoÚstatus_repoÚremote_repoÚremote_hashÚ
local_hashÚfolderÚremote_nameÚremote_folderÚ
local_nameÚexcÚlocal_folderÚmsgÚtmp_remotefolderÚ	loop_names                  r   Úsync_folder_structurez$BaseRepository.sync_folder_structureù   sÁ  € ð ×)Ò)Ñ+Ô+ð 	Ø"×8Ò8Ñ:Ô:ð	ð �4àˆØ"$ b�Zˆà!×,Ò,Ñ.Ô.ð 	3ð 	3ˆFØ,2ˆK˜ŸšÑ(Ô(Ñ)Ð)à ×+Ò+Ñ-Ô-ð 	2ð 	2ˆFØ+1ˆJ�v—~’~Ñ'Ô'Ñ(Ð(õ +/¨{×/@Ò/@Ñ/BÔ/BÑ*CÔ*Cð 	@ñ 	@Ñ&ˆK˜à×3Ò3Ñ5Ô5ð Ø‘ð '×5Ò5Ñ7Ô7×?Ò?Ø×"Ò"Ñ$Ô$ j×&7Ò&7Ñ&9Ô&9ñ;ô ;ˆJàÔ&ð @Ø"­$¨z¯ªÑ/@Ô/@Ñ*AÔ*AÐAÐAðØ×)Ò)¨*Ñ5Ô5Ð5à×,Ò,Ñ.Ô.Ð.Ð.øÝ'ð ð ð Ø”G—M’M #¥x¡z¤z°!¤} }à#- : :¨z¨zð#;ñ<ô <ð <ð øøøøð	øøøð
 ×&Ò& z×'9Ò'9Ø×%Ò%Ñ'Ô'¨×);Ò);Ñ)=Ô)=ñ(?ô (?ñ @ô @ð @ùõ )-¨Z×-=Ò-=Ñ-?Ô-?Ñ(@Ô(@ð >	@ñ >	@Ñ$ˆJ˜Ø×4Ò4Ñ6Ô6ð à‘ð '×5Ò5Ñ7Ô7×?Ò?Ø×!Ò!Ñ#Ô# [×%7Ò%7Ñ%9Ô%9ñ;ô ;ˆKàÔ%ñ 6@Ø#­4°×0@Ò0@Ñ0BÔ0BÑ+CÔ+CÐCÑCð #×5Ò5°kÑBÔBð ð ð '˜;˜;¨¨¨ð.�Cð ”G—M’M " cÑ*Ô*Ð*Øð $/×#8Ò#8¸Ø@Eð $9ñ $Gô $GÐ à,×;Ò;Ñ=Ô=×EÒEØ×&Ò&Ñ(Ô(¨*×*;Ò*;Ñ*=Ô*=ñ?ô ?�	à Ò*Ð*Ð*ð (×/Ò/Ñ1Ô1Ð1Ð1°:°:°:¸{¸{¸{Ø&˜;˜;¨	¨	¨	ð3�Cõ +¨3Õ0@Ô0FÔ0KÑLÔLÐLðØ×*Ò*¨;Ñ7Ô7Ð7à×&Ò&Ñ(Ô(Ð(Ð(øÝ'ð ð ð ð à&˜;˜;¨¨ð5�Cà”G—M’M #¥x¡z¤z°!¤}°cÑ:Ô:Ð:Øøøøøð	øøøð
 ×&Ò& z×'9Ò'9Ø×%Ò%Ñ'Ô'¨×);Ò);Ñ)=Ô)=ñ(?ô (?ñ @ô @ð @ùð
 ˆts0   Å)E,Å,
F0Å65F+Æ+F0Î)O	Ï	
PÏ7P
Ð
Pc                 ó   — dS )z+The default implementation will do nothing.Nr   r8   s    r   ÚstartkeepalivezBaseRepository.startkeepalivel  r:   r   c                 ó   — dS )zOStop keep alive, but don't bother waiting
        for the threads to terminate.Nr   r8   s    r   ÚstopkeepalivezBaseRepository.stopkeepaliveo  r:   r   c                 ó   — dS )zY Local root folder for storing messages.
        Will not be set for remote repositories.Nr   r8   s    r   ÚgetlocalrootzBaseRepository.getlocalroots  s	   € ð ˆtr   N)T)!Ú__name__Ú
__module__Ú__qualname__Ú__doc__r6   r9   r<   r>   r@   rB   r#   rF   ÚpropertyrH   rJ   rM   r1   r   r
   r!   rS   rU   rY   r\   r_   rb   re   rg   rj   r†   rˆ   rŠ   rŒ   r   r   r   r   r      sê  € € € € € ðð ð$8ð $8ð $8ðL*ð *ð *ðð ð ðð ð ðð ð ðð ð ðð ð ðð ð ð ð!ð !ñ „Xð!ð
ð ð ðð ð ð)ð )ð )ðð ð ð ðð ñ „Xðð
+ð +ð +ðð ð ð
ð ð ð	"ð 	"ð 	"ð	"ð 	"ð 	"ðHð Hð Hð
Bð Bð Bð"ð "ð "ð"ð "ð "ð"ð "ð "ð "ðqð qð qðf:ð :ð :ð)ð )ð )ðð ð ð ð r   r   )r�   r   Úos.pathr'   Úsysr   Úofflineimapr   Úofflineimap.uir   Úofflineimap.errorr   ÚConfigHelperMixinr   r   r   r   ú<module>r˜      s¬   ððð ð" 
€	€	€	Ø €€€Ø Ð Ð Ð Ð Ð à $Ð $Ð $Ð $Ð $Ð $Ø &Ð &Ð &Ð &Ð &Ð &Ø .Ð .Ð .Ð .Ð .Ð .ð\ð \ð \ð \ð \�\Ô3ñ \ô \ð \ð \ð \r   