]>
code.delx.au - offlineimap/blob - head/offlineimap/repository/Base.py
1 # Base repository support
2 # Copyright (C) 2002, 2003 John Goerzen
3 # <jgoerzen@complete.org>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 from offlineimap
import CustomConfig
22 def LoadRepository(name
, account
, reqtype
):
23 from offlineimap
.repository
.IMAP
import IMAPRepository
, MappedIMAPRepository
24 from offlineimap
.repository
.Maildir
import MaildirRepository
25 if reqtype
== 'remote':
26 # For now, we don't support Maildirs on the remote side.
27 typemap
= {'IMAP': IMAPRepository
}
28 elif reqtype
== 'local':
29 typemap
= {'IMAP': MappedIMAPRepository
,
30 'Maildir': MaildirRepository
}
32 raise ValueError, "Request type %s not supported" % reqtype
33 config
= account
.getconfig()
34 repostype
= config
.get('Repository ' + name
, 'type').strip()
35 return typemap
[repostype
](name
, account
)
37 class BaseRepository(CustomConfig
.ConfigHelperMixin
):
38 def __init__(self
, reposname
, account
):
39 self
.account
= account
40 self
.config
= account
.getconfig()
42 self
.localeval
= account
.getlocaleval()
43 self
.accountname
= self
.account
.getname()
44 self
.uiddir
= os
.path
.join(self
.config
.getmetadatadir(), 'Repository-' + self
.name
)
45 if not os
.path
.exists(self
.uiddir
):
46 os
.mkdir(self
.uiddir
, 0700)
47 self
.mapdir
= os
.path
.join(self
.uiddir
, 'UIDMapping')
48 if not os
.path
.exists(self
.mapdir
):
49 os
.mkdir(self
.mapdir
, 0700)
50 self
.uiddir
= os
.path
.join(self
.uiddir
, 'FolderValidity')
51 if not os
.path
.exists(self
.uiddir
):
52 os
.mkdir(self
.uiddir
, 0700)
54 def holdordropconnections(self
):
57 def dropconnections(self
):
72 def getaccountname(self
):
73 return self
.accountname
76 return 'Repository ' + self
.name
81 def getlocaleval(self
):
82 return self
.account
.getlocaleval()
85 """Returns a list of ALL folders on this server."""
89 raise NotImplementedError
91 def makefolder(self
, foldername
):
92 raise NotImplementedError
94 def deletefolder(self
, foldername
):
95 raise NotImplementedError
97 def getfolder(self
, foldername
):
98 raise NotImplementedError
100 def syncfoldersto(self
, dest
):
101 """Syncs the folders in this repository to those in dest.
102 It does NOT sync the contents of those folders."""
104 srcfolders
= src
.getfolders()
105 destfolders
= dest
.getfolders()
107 # Create hashes with the names, but convert the source folders
108 # to the dest folder's sep.
111 for folder
in srcfolders
:
112 srchash
[folder
.getvisiblename().replace(src
.getsep(), dest
.getsep())] = \
115 for folder
in destfolders
:
116 desthash
[folder
.getvisiblename()] = folder
122 for key
in srchash
.keys():
123 if not key
in desthash
:
127 # Find deleted folders.
129 # We don't delete folders right now.
131 #for key in desthash.keys():
132 # if not key in srchash:
133 # dest.deletefolder(key)
137 def startkeepalive(self
):
138 """The default implementation will do nothing."""
141 def stopkeepalive(self
, abrupt
= 0):
142 """Stop keep alive. If abrupt is 1, stop it but don't bother waiting
143 for the threads to terminate."""