/head: changeset 10

Updated!
This commit is contained in:
jgoerzen 2002-06-20 03:55:24 +01:00
parent 2659dab118
commit f2f66546be
4 changed files with 62 additions and 12 deletions

View File

@ -18,15 +18,45 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from imapsync import imaplib, imaputil, imapserver, repository, folder from imapsync import imaplib, imaputil, imapserver, repository, folder
import re import re, getpass, os, os.path
import getpass from ConfigParser import ConfigParser
host = raw_input('Host: ') config = ConfigParser()
user = raw_input('Username: ') config.read("imapsync.conf")
passwd = getpass.getpass('Password: ') metadatadir = os.path.expanduser(config.get("general", "metadata"))
if not os.path.exists(metadatadir):
os.mkdir(metadatadir, 0700)
server = imapserver.IMAPServer(user, passwd, host, ssl = 1) accounts = config.get("general", "accounts")
imapobj = server.makeconnection() accounts = accounts.replace(" ", "")
delim, root = imaputil.imapsplit(imapobj.list('""', '""')[1][0])[1:] accounts = accounts.split(",")
repos = repository.IMAP.IMAPRepository(server) for accountname in accounts:
print "Processing account " + accountname
accountmetadata = os.path.join(metadatadir, accountname)
if not os.path.exists(accountmetadata):
os.mkdir(accountmetadata, 0700)
host = config.get(accountname, "remotehost")
user = config.get(accountname, "remoteuser")
port = None
if config.has_option(accountname, "remoteport"):
port = config.getint(accountname, "remoteport")
password = None
if config.has_option(accountname, "remotepass"):
password = config.get(accountname, "remotepass")
else:
password = getpass.getpass("Password for %s: " % accountname)
ssl = config.getboolean(accountname, "ssl")
server = imapserver.IMAPServer(user, password, host, port, ssl)
#print "Connecting to server...",
#imapobj = server.makeconnection()
#print "Done."
remoterepos = repository.IMAP.IMAPRepository(server)
localrepos = repository.Maildir.MaildirRepository(os.path.expanduser(config.get(accountname, "localfolders")))
print "Synchronizing folder list..."
remoterepos.syncfoldersto(localrepos)
print "Done."
for remotefolder in remoterepos.getfolders():
print "*** SYNCHRONIZING FOLDER %s" % remotefolder.getname()
localfolder = localrepos.getfolder(remotefolder.getname())

View File

@ -24,10 +24,13 @@ class BaseRepository:
def getsep(self): def getsep(self):
raise NotImplementedError raise NotImplementedError
def makefolder(self): def makefolder(self, foldername):
raise NotImplementedError raise NotImplementedError
def deletefolder(self): def deletefolder(self, foldername):
raise NotImplementedError
def getfolder(self, foldername):
raise NotImplementedError raise NotImplementedError
def syncfoldersto(self, dest): def syncfoldersto(self, dest):

View File

@ -30,6 +30,9 @@ class IMAPRepository(BaseRepository):
def getsep(self): def getsep(self):
return self.imapserver.delim return self.imapserver.delim
def getfolder(self, foldername):
return folder.IMAP.IMAPFolder(self.imapserver, name)
def getfolders(self): def getfolders(self):
if self.folders != None: if self.folders != None:
return self.folders return self.folders

View File

@ -32,6 +32,20 @@ class MaildirRepository(BaseRepository):
def getsep(self): def getsep(self):
return '.' return '.'
def makefolder(self, foldername):
folderdir = os.path.join(self.root, foldername)
os.mkdir(folderdir, 0700)
for subdir in ['cur', 'new', 'tmp']:
os.mkdir(os.path.join(folderdir, subdir), 0700)
def deletefolder(self, foldername):
print "NOT YET IMPLEMENTED: DELETE FOLDER %s" % foldername
def getfolder(self, foldername):
return folder.Maildir.MaildirFolder(self.root, foldername)
def getfolders(self): def getfolders(self):
if self.folders != None: if self.folders != None:
return self.folders return self.folders
@ -45,7 +59,7 @@ class MaildirRepository(BaseRepository):
os.path.isdir(os.path.join(fullname, 'new')) and os.path.isdir(os.path.join(fullname, 'new')) and
os.path.isdir(os.path.join(fullname, 'tmp'))): os.path.isdir(os.path.join(fullname, 'tmp'))):
continue continue
retval.append(MaildirFolder(self.root, dirname)) retval.append(folder.Maildir.MaildirFolder(self.root, dirname))
self.folders = retval self.folders = retval
return retval return retval