/offlineimap/head: changeset 168

Made some more optimizations
This commit is contained in:
jgoerzen 2002-07-24 00:36:44 +01:00
parent 9d3298f5a7
commit 045665deb9
3 changed files with 11 additions and 14 deletions

View File

@ -18,7 +18,7 @@
from Base import BaseFolder
from offlineimap import imaputil, imaplib
import rfc822, time
import rfc822, time, string
from StringIO import StringIO
from copy import copy
@ -75,7 +75,7 @@ class IMAPFolder(BaseFolder):
self.imapserver.releaseconnection(imapobj)
for messagestr in response:
# Discard the message number.
messagestr = imaputil.imapsplit(messagestr)[1]
messagestr = string.split(messagestr, maxsplit = 1)[1]
options = imaputil.flags2hash(messagestr)
uid = long(options['UID'])
flags = imaputil.flagsimap2maildir(options['FLAGS'])

View File

@ -130,7 +130,7 @@ class MaildirFolder(BaseFolder):
return self.messagelist
def getmessage(self, uid):
filename = self.getmessagelist()[uid]['filename']
filename = self.messagelist[uid]['filename']
file = open(filename, 'rt')
retval = file.read()
file.close()
@ -140,7 +140,7 @@ class MaildirFolder(BaseFolder):
if uid < 0:
# We cannot assign a new uid.
return uid
if uid in self.getmessagelist():
if uid in self.messagelist:
# We already have it.
self.savemessageflags(uid, flags)
return uid
@ -180,10 +180,10 @@ class MaildirFolder(BaseFolder):
return uid
def getmessageflags(self, uid):
return self.getmessagelist()[uid]['flags']
return self.messagelist[uid]['flags']
def savemessageflags(self, uid, flags):
oldfilename = self.getmessagelist()[uid]['filename']
oldfilename = self.messagelist[uid]['filename']
newpath, newname = os.path.split(oldfilename)
infostr = ':'
infomatch = re.search('(:.*)$', newname)
@ -198,16 +198,13 @@ class MaildirFolder(BaseFolder):
newfilename = os.path.join(newpath, newname)
if (newfilename != oldfilename):
os.rename(oldfilename, newfilename)
self.getmessagelist()[uid]['flags'] = flags
self.getmessagelist()[uid]['filename'] = newfilename
def getmessageflags(self, uid):
return self.getmessagelist()[uid]['flags']
self.messagelist[uid]['flags'] = flags
self.messagelist[uid]['filename'] = newfilename
def deletemessage(self, uid):
if not uid in self.messagelist:
return
filename = self.getmessagelist()[uid]['filename']
filename = self.messagelist[uid]['filename']
try:
os.unlink(filename)
except IOError:

View File

@ -89,14 +89,14 @@ def imapsplit(imapstring):
break
return retval
def flagsimap2maildir(string):
def flagsimap2maildir(flagstring):
flagmap = {'\\seen': 'S',
'\\answered': 'R',
'\\flagged': 'F',
'\\deleted': 'T',
'\\draft': 'D'}
retval = []
imapflaglist = [x.lower() for x in flagsplit(string)]
imapflaglist = [x.lower() for x in flagstring[1:-1].split()]
for imapflag in imapflaglist:
if flagmap.has_key(imapflag):
retval.append(flagmap[imapflag])