/head: changeset 32
THINGS ARE WORKING!
This commit is contained in:
parent
7e9d9d961c
commit
f441c907dd
@ -119,6 +119,8 @@ class BaseFolder:
|
||||
if applyto == None:
|
||||
applyto = [dest]
|
||||
|
||||
print "Pass 1"
|
||||
|
||||
# Pass 1 -- Look for messages in self with a negative uid.
|
||||
# These are messages in Maildirs that were not added by us.
|
||||
# Try to add them to the dests, and once that succeeds, get the
|
||||
@ -128,6 +130,7 @@ class BaseFolder:
|
||||
for uid in self.getmessagelist().keys():
|
||||
if uid >= 0:
|
||||
continue
|
||||
print "Uploading new message %d" % uid
|
||||
successobject = None
|
||||
successuid = None
|
||||
message = self.getmessage(uid)
|
||||
@ -150,6 +153,8 @@ class BaseFolder:
|
||||
# Did not find any server to take this message. Ignore.
|
||||
pass
|
||||
|
||||
print "Pass 2"
|
||||
|
||||
# Pass 2 -- Look for messages present in self but not in dest.
|
||||
# If any, add them to dest.
|
||||
|
||||
@ -157,6 +162,7 @@ class BaseFolder:
|
||||
if uid < 0: # Ignore messages that pass 1 missed.
|
||||
continue
|
||||
if not uid in dest.getmessagelist():
|
||||
print "Uploading new message %d" % uid
|
||||
message = self.getmessage(uid)
|
||||
flags = self.getmessageflags(uid)
|
||||
for object in applyto:
|
||||
@ -167,6 +173,8 @@ class BaseFolder:
|
||||
self.deletemessage(uid)
|
||||
uid = newuid
|
||||
|
||||
print "Pass 3"
|
||||
|
||||
# Pass 3 -- Look for message present in dest but not in self.
|
||||
# If any, delete them.
|
||||
|
||||
@ -174,14 +182,17 @@ class BaseFolder:
|
||||
if uid < 0:
|
||||
continue
|
||||
if not uid in self.getmessagelist():
|
||||
print "Deleting message %d" % uid
|
||||
for object in applyto:
|
||||
object.deletemessage(uid)
|
||||
|
||||
# Now, the message lists should be identical wrt the uids present.
|
||||
# (except for potential negative uids that couldn't be placed
|
||||
# anywhere)
|
||||
|
||||
print "Pass 4"
|
||||
|
||||
# Pass 3 -- Look for any flag identity issues -- set dest messages
|
||||
# Pass 4 -- Look for any flag identity issues -- set dest messages
|
||||
# to have the same flags that we have here.
|
||||
|
||||
for uid in self.getmessagelist().keys():
|
||||
@ -192,11 +203,13 @@ class BaseFolder:
|
||||
|
||||
addflags = [x for x in selfflags if x not in destflags]
|
||||
if len(addflags):
|
||||
print "Adding flags to %d" % uid, addflags
|
||||
for object in applyto:
|
||||
object.addmessageflags(uid, addflags)
|
||||
|
||||
delflags = [x for x in destflags if x not in selfflags]
|
||||
if len(delflags):
|
||||
print "Deleting flags from %d" % uid, delflags
|
||||
for object in applyto:
|
||||
object.deletemessageflags(uid, delflags)
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
from Base import BaseFolder
|
||||
from imapsync import imaputil
|
||||
from imapsync import imaputil, imaplib
|
||||
import rfc822
|
||||
from StringIO import StringIO
|
||||
|
||||
@ -61,7 +61,7 @@ class IMAPFolder(BaseFolder):
|
||||
def getmessage(self, uid):
|
||||
print "***************** GETMESSAGE %d" % uid
|
||||
assert(self.imapobj.select(self.getfullname())[0] == 'OK')
|
||||
return self.imapobj.uid('fetch', '%d' % uid, '(RFC822)')[1][0][1]
|
||||
return self.imapobj.uid('fetch', '%d' % uid, '(RFC822)')[1][0][1].replace("\r\n", "\n")
|
||||
|
||||
def getmessageflags(self, uid):
|
||||
return self.getmessagelist()[uid]['flags']
|
||||
@ -75,6 +75,9 @@ class IMAPFolder(BaseFolder):
|
||||
mid = self.imapobj._quote(message.getheader('Message-Id'))
|
||||
date = imaplib.Time2Internaldate(rfc822.parsedate(message.getheader('Date')))
|
||||
|
||||
if content.find("\r\n") == -1: # Convert line endings if not already
|
||||
content = content.replace("\n", "\r\n")
|
||||
|
||||
assert(self.imapobj.append(self.getfullname(),
|
||||
imaputil.flagsmaildir2imap(flags),
|
||||
date, content)[0] == 'OK')
|
||||
@ -96,8 +99,11 @@ class IMAPFolder(BaseFolder):
|
||||
self.messagelist[uid]['flags'] = imaputil.flagsimap2maildir(flags)
|
||||
|
||||
def deletemessage(self, uid):
|
||||
self.addmessagesflags(uid, ['T'])
|
||||
if not uid in self.messagelist:
|
||||
return
|
||||
self.addmessageflags(uid, ['T'])
|
||||
assert(self.imapobj.select(self.getfullname())[0] == 'OK')
|
||||
assert(self.imapobj.expunge()[0] == 'OK')
|
||||
del(self.messagelist[uid])
|
||||
|
||||
|
||||
|
@ -53,6 +53,7 @@ class LocalStatusFolder(BaseFolder):
|
||||
line = file.readline().strip()
|
||||
assert(line == magicline)
|
||||
for line in file.xreadlines():
|
||||
line = line.strip()
|
||||
uid, flags = line.split(':')
|
||||
uid = long(uid)
|
||||
flags = [x for x in flags]
|
||||
@ -91,5 +92,7 @@ class LocalStatusFolder(BaseFolder):
|
||||
self.messagelist[uid]['flags'] = flags
|
||||
|
||||
def deletemessage(self, uid):
|
||||
if not uid in self.messagelist:
|
||||
return
|
||||
del(self.messagelist[uid])
|
||||
|
||||
|
@ -158,6 +158,8 @@ class MaildirFolder(BaseFolder):
|
||||
return self.getmessagelist()[uid]['flags']
|
||||
|
||||
def deletemessage(self, uid):
|
||||
if not uid in self.messagelist:
|
||||
return
|
||||
filename = self.getmessagelist()[uid]['filename']
|
||||
os.unlink(filename)
|
||||
del(self.messagelist[uid])
|
||||
|
Loading…
Reference in New Issue
Block a user