/offlineimap/head: changeset 168
Made some more optimizations
This commit is contained in:
parent
9d3298f5a7
commit
045665deb9
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
from Base import BaseFolder
|
from Base import BaseFolder
|
||||||
from offlineimap import imaputil, imaplib
|
from offlineimap import imaputil, imaplib
|
||||||
import rfc822, time
|
import rfc822, time, string
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
from copy import copy
|
from copy import copy
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ class IMAPFolder(BaseFolder):
|
|||||||
self.imapserver.releaseconnection(imapobj)
|
self.imapserver.releaseconnection(imapobj)
|
||||||
for messagestr in response:
|
for messagestr in response:
|
||||||
# Discard the message number.
|
# Discard the message number.
|
||||||
messagestr = imaputil.imapsplit(messagestr)[1]
|
messagestr = string.split(messagestr, maxsplit = 1)[1]
|
||||||
options = imaputil.flags2hash(messagestr)
|
options = imaputil.flags2hash(messagestr)
|
||||||
uid = long(options['UID'])
|
uid = long(options['UID'])
|
||||||
flags = imaputil.flagsimap2maildir(options['FLAGS'])
|
flags = imaputil.flagsimap2maildir(options['FLAGS'])
|
||||||
|
@ -130,7 +130,7 @@ class MaildirFolder(BaseFolder):
|
|||||||
return self.messagelist
|
return self.messagelist
|
||||||
|
|
||||||
def getmessage(self, uid):
|
def getmessage(self, uid):
|
||||||
filename = self.getmessagelist()[uid]['filename']
|
filename = self.messagelist[uid]['filename']
|
||||||
file = open(filename, 'rt')
|
file = open(filename, 'rt')
|
||||||
retval = file.read()
|
retval = file.read()
|
||||||
file.close()
|
file.close()
|
||||||
@ -140,7 +140,7 @@ class MaildirFolder(BaseFolder):
|
|||||||
if uid < 0:
|
if uid < 0:
|
||||||
# We cannot assign a new uid.
|
# We cannot assign a new uid.
|
||||||
return uid
|
return uid
|
||||||
if uid in self.getmessagelist():
|
if uid in self.messagelist:
|
||||||
# We already have it.
|
# We already have it.
|
||||||
self.savemessageflags(uid, flags)
|
self.savemessageflags(uid, flags)
|
||||||
return uid
|
return uid
|
||||||
@ -180,10 +180,10 @@ class MaildirFolder(BaseFolder):
|
|||||||
return uid
|
return uid
|
||||||
|
|
||||||
def getmessageflags(self, uid):
|
def getmessageflags(self, uid):
|
||||||
return self.getmessagelist()[uid]['flags']
|
return self.messagelist[uid]['flags']
|
||||||
|
|
||||||
def savemessageflags(self, uid, flags):
|
def savemessageflags(self, uid, flags):
|
||||||
oldfilename = self.getmessagelist()[uid]['filename']
|
oldfilename = self.messagelist[uid]['filename']
|
||||||
newpath, newname = os.path.split(oldfilename)
|
newpath, newname = os.path.split(oldfilename)
|
||||||
infostr = ':'
|
infostr = ':'
|
||||||
infomatch = re.search('(:.*)$', newname)
|
infomatch = re.search('(:.*)$', newname)
|
||||||
@ -198,16 +198,13 @@ class MaildirFolder(BaseFolder):
|
|||||||
newfilename = os.path.join(newpath, newname)
|
newfilename = os.path.join(newpath, newname)
|
||||||
if (newfilename != oldfilename):
|
if (newfilename != oldfilename):
|
||||||
os.rename(oldfilename, newfilename)
|
os.rename(oldfilename, newfilename)
|
||||||
self.getmessagelist()[uid]['flags'] = flags
|
self.messagelist[uid]['flags'] = flags
|
||||||
self.getmessagelist()[uid]['filename'] = newfilename
|
self.messagelist[uid]['filename'] = newfilename
|
||||||
|
|
||||||
def getmessageflags(self, uid):
|
|
||||||
return self.getmessagelist()[uid]['flags']
|
|
||||||
|
|
||||||
def deletemessage(self, uid):
|
def deletemessage(self, uid):
|
||||||
if not uid in self.messagelist:
|
if not uid in self.messagelist:
|
||||||
return
|
return
|
||||||
filename = self.getmessagelist()[uid]['filename']
|
filename = self.messagelist[uid]['filename']
|
||||||
try:
|
try:
|
||||||
os.unlink(filename)
|
os.unlink(filename)
|
||||||
except IOError:
|
except IOError:
|
||||||
|
@ -89,14 +89,14 @@ def imapsplit(imapstring):
|
|||||||
break
|
break
|
||||||
return retval
|
return retval
|
||||||
|
|
||||||
def flagsimap2maildir(string):
|
def flagsimap2maildir(flagstring):
|
||||||
flagmap = {'\\seen': 'S',
|
flagmap = {'\\seen': 'S',
|
||||||
'\\answered': 'R',
|
'\\answered': 'R',
|
||||||
'\\flagged': 'F',
|
'\\flagged': 'F',
|
||||||
'\\deleted': 'T',
|
'\\deleted': 'T',
|
||||||
'\\draft': 'D'}
|
'\\draft': 'D'}
|
||||||
retval = []
|
retval = []
|
||||||
imapflaglist = [x.lower() for x in flagsplit(string)]
|
imapflaglist = [x.lower() for x in flagstring[1:-1].split()]
|
||||||
for imapflag in imapflaglist:
|
for imapflag in imapflaglist:
|
||||||
if flagmap.has_key(imapflag):
|
if flagmap.has_key(imapflag):
|
||||||
retval.append(flagmap[imapflag])
|
retval.append(flagmap[imapflag])
|
||||||
|
Loading…
Reference in New Issue
Block a user