From b179602b31ec199aa023858ca748681e7936056a Mon Sep 17 00:00:00 2001 From: jgoerzen Date: Thu, 20 Jun 2002 07:26:28 +0100 Subject: [PATCH] /head: changeset 17 *** empty log message *** --- head/offlineimap.py | 14 ++++++++++++++ head/offlineimap/folder/Base.py | 5 ++++- head/offlineimap/folder/IMAP.py | 22 ++++++++++++++++++++++ head/offlineimap/imaputil.py | 17 ++++++++++++++--- 4 files changed, 54 insertions(+), 4 deletions(-) diff --git a/head/offlineimap.py b/head/offlineimap.py index 0edf57d..0089073 100644 --- a/head/offlineimap.py +++ b/head/offlineimap.py @@ -31,6 +31,10 @@ accounts = config.get("general", "accounts") accounts = accounts.replace(" ", "") accounts = accounts.split(",") +server = None +remoterepos = None +localrepos = None + for accountname in accounts: print "Processing account " + accountname accountmetadata = os.path.join(metadatadir, accountname) @@ -59,4 +63,14 @@ for accountname in accounts: for remotefolder in remoterepos.getfolders(): print "*** SYNCHRONIZING FOLDER %s" % 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..." diff --git a/head/offlineimap/folder/Base.py b/head/offlineimap/folder/Base.py index 60728b6..7f5b194 100644 --- a/head/offlineimap/folder/Base.py +++ b/head/offlineimap/folder/Base.py @@ -30,7 +30,10 @@ class BaseFolder: return self.sep 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): raise NotImplementedException diff --git a/head/offlineimap/folder/IMAP.py b/head/offlineimap/folder/IMAP.py index 0274055..808c1fd 100644 --- a/head/offlineimap/folder/IMAP.py +++ b/head/offlineimap/folder/IMAP.py @@ -25,4 +25,26 @@ class IMAPFolder(BaseFolder): self.root = imapserver.root self.sep = imapserver.delim 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) + diff --git a/head/offlineimap/imaputil.py b/head/offlineimap/imaputil.py index a8f28f5..2122adf 100644 --- a/head/offlineimap/imaputil.py +++ b/head/offlineimap/imaputil.py @@ -33,7 +33,18 @@ def dequote(string): def flagsplit(string): if string[0] != '(' or string[-1] != ')': 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): """Takes a string from an IMAP conversation and returns a list containing @@ -51,11 +62,11 @@ def imapsplit(string): if re.search('^\s', workstr): workstr = re.search('^\s(.*)$', workstr).group(1) elif workstr[0] == '(': - parenlist = re.search('^(\([^)]*\))', workstr).group(1) + parenlist = re.search('^(\(.*\))', workstr).group(1) workstr = workstr[len(parenlist):] retval.append(parenlist) elif workstr[0] == '"': - quotelist = re.search('^("[^"]*")', workstr).group(1) + quotelist = re.search('^("([^"]|\\")*")', workstr).group(1) workstr = workstr[len(quotelist):] retval.append(quotelist) else: