/head: changeset 17
*** empty log message ***
This commit is contained in:
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
@ -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:
|
||||
|
Reference in New Issue
Block a user