/head: changeset 17

*** empty log message ***
This commit is contained in:
jgoerzen 2002-06-20 07:26:28 +01:00
parent 0aa3ee1fb8
commit b179602b31
4 changed files with 54 additions and 4 deletions

View File

@ -31,6 +31,10 @@ accounts = config.get("general", "accounts")
accounts = accounts.replace(" ", "") accounts = accounts.replace(" ", "")
accounts = accounts.split(",") accounts = accounts.split(",")
server = None
remoterepos = None
localrepos = None
for accountname in accounts: for accountname in accounts:
print "Processing account " + accountname print "Processing account " + accountname
accountmetadata = os.path.join(metadatadir, accountname) accountmetadata = os.path.join(metadatadir, accountname)
@ -59,4 +63,14 @@ for accountname in accounts:
for remotefolder in remoterepos.getfolders(): for remotefolder in remoterepos.getfolders():
print "*** SYNCHRONIZING FOLDER %s" % remotefolder.getname() print "*** SYNCHRONIZING FOLDER %s" % remotefolder.getname()
localfolder = localrepos.getfolder(remotefolder.getname()) localfolder = localrepos.getfolder(remotefolder.getname())
#if not localfolder.isuidvalidityok(remotefolder):
# print 'UID validity is a problem for this folder; skipping.'
# continue
#print "Reading remote message list...",
#remotefolder.cachemessagelist()
#print len(remotefolder.getmessagelist().keys()), "messages."
print "Reading local message list...",
localfolder.cachemessagelist()
print len(localfolder.getmessagelist().keys()), "messages."
print "Synchronizing locally-made changes..."

View File

@ -30,7 +30,10 @@ class BaseFolder:
return self.sep return self.sep
def getfullname(self): def getfullname(self):
return self.getroot() + self.getsep() + self.getname() if self.getroot():
return self.getroot() + self.getsep() + self.getname()
else:
return self.getname()
def isuidvalidityok(self, remotefolder): def isuidvalidityok(self, remotefolder):
raise NotImplementedException raise NotImplementedException

View File

@ -25,4 +25,26 @@ class IMAPFolder(BaseFolder):
self.root = imapserver.root self.root = imapserver.root
self.sep = imapserver.delim self.sep = imapserver.delim
self.imapserver = imapserver self.imapserver = imapserver
self.imapobj = self.imapserver.makeconnection()
self.messagelist = None
def getuidvalidity(self):
x = self.imapobj.status(self.getfullname(), ('UIDVALIDITY'))[1][0]
uidstring = imaputil.imapsplit(x)[1]
return int(imaputil.flagsplit(x)[1])
def cachemessagelist(self):
assert(self.imapobj.select(self.getfullname())[0] == 'OK')
self.messagelist = {}
response = self.imapobj.status(self.getfullname(), ('MESSAGES'))[1][0]
result = imaputil.imapsplit(response)[1]
maxmsgid = int(imaputil.flags2hash(result)['MESSAGES'])
# Now, get the flags and UIDs for these.
response = self.imapobj.fetch('1:%d' % maxmsgid, '(FLAGS UID)')[1]
for messagestr in response:
# Discard the message number.
messagestr = imaputil.imapsplit(messagestr)[1]
options = imaputil.flags2hash(messagestr)

View File

@ -33,7 +33,18 @@ def dequote(string):
def flagsplit(string): def flagsplit(string):
if string[0] != '(' or string[-1] != ')': if string[0] != '(' or string[-1] != ')':
raise ValueError, "Passed string '%s' is not a flag list" % string raise ValueError, "Passed string '%s' is not a flag list" % string
return string[1:-1].split(" ") return imapsplit(string[1:-1])
def options2hash(list):
retval = {}
counter = 0
while (counter < len(list)):
retval[list[counter]] = list[counter + 1]
counter += 2
return retval
def flags2hash(string):
return options2hash(flagsplit(string))
def imapsplit(string): def imapsplit(string):
"""Takes a string from an IMAP conversation and returns a list containing """Takes a string from an IMAP conversation and returns a list containing
@ -51,11 +62,11 @@ def imapsplit(string):
if re.search('^\s', workstr): if re.search('^\s', workstr):
workstr = re.search('^\s(.*)$', workstr).group(1) workstr = re.search('^\s(.*)$', workstr).group(1)
elif workstr[0] == '(': elif workstr[0] == '(':
parenlist = re.search('^(\([^)]*\))', workstr).group(1) parenlist = re.search('^(\(.*\))', workstr).group(1)
workstr = workstr[len(parenlist):] workstr = workstr[len(parenlist):]
retval.append(parenlist) retval.append(parenlist)
elif workstr[0] == '"': elif workstr[0] == '"':
quotelist = re.search('^("[^"]*")', workstr).group(1) quotelist = re.search('^("([^"]|\\")*")', workstr).group(1)
workstr = workstr[len(quotelist):] workstr = workstr[len(quotelist):]
retval.append(quotelist) retval.append(quotelist)
else: else: