/head: changeset 32

THINGS ARE WORKING!
This commit is contained in:
jgoerzen 2002-06-21 05:30:08 +01:00
parent 7e9d9d961c
commit f441c907dd
4 changed files with 28 additions and 4 deletions

View File

@ -119,6 +119,8 @@ class BaseFolder:
if applyto == None: if applyto == None:
applyto = [dest] applyto = [dest]
print "Pass 1"
# Pass 1 -- Look for messages in self with a negative uid. # Pass 1 -- Look for messages in self with a negative uid.
# These are messages in Maildirs that were not added by us. # These are messages in Maildirs that were not added by us.
# Try to add them to the dests, and once that succeeds, get the # 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(): for uid in self.getmessagelist().keys():
if uid >= 0: if uid >= 0:
continue continue
print "Uploading new message %d" % uid
successobject = None successobject = None
successuid = None successuid = None
message = self.getmessage(uid) message = self.getmessage(uid)
@ -150,6 +153,8 @@ class BaseFolder:
# Did not find any server to take this message. Ignore. # Did not find any server to take this message. Ignore.
pass pass
print "Pass 2"
# Pass 2 -- Look for messages present in self but not in dest. # Pass 2 -- Look for messages present in self but not in dest.
# If any, add them to dest. # If any, add them to dest.
@ -157,6 +162,7 @@ class BaseFolder:
if uid < 0: # Ignore messages that pass 1 missed. if uid < 0: # Ignore messages that pass 1 missed.
continue continue
if not uid in dest.getmessagelist(): if not uid in dest.getmessagelist():
print "Uploading new message %d" % uid
message = self.getmessage(uid) message = self.getmessage(uid)
flags = self.getmessageflags(uid) flags = self.getmessageflags(uid)
for object in applyto: for object in applyto:
@ -167,6 +173,8 @@ class BaseFolder:
self.deletemessage(uid) self.deletemessage(uid)
uid = newuid uid = newuid
print "Pass 3"
# Pass 3 -- Look for message present in dest but not in self. # Pass 3 -- Look for message present in dest but not in self.
# If any, delete them. # If any, delete them.
@ -174,6 +182,7 @@ class BaseFolder:
if uid < 0: if uid < 0:
continue continue
if not uid in self.getmessagelist(): if not uid in self.getmessagelist():
print "Deleting message %d" % uid
for object in applyto: for object in applyto:
object.deletemessage(uid) object.deletemessage(uid)
@ -181,7 +190,9 @@ class BaseFolder:
# (except for potential negative uids that couldn't be placed # (except for potential negative uids that couldn't be placed
# anywhere) # anywhere)
# Pass 3 -- Look for any flag identity issues -- set dest messages print "Pass 4"
# Pass 4 -- Look for any flag identity issues -- set dest messages
# to have the same flags that we have here. # to have the same flags that we have here.
for uid in self.getmessagelist().keys(): for uid in self.getmessagelist().keys():
@ -192,11 +203,13 @@ class BaseFolder:
addflags = [x for x in selfflags if x not in destflags] addflags = [x for x in selfflags if x not in destflags]
if len(addflags): if len(addflags):
print "Adding flags to %d" % uid, addflags
for object in applyto: for object in applyto:
object.addmessageflags(uid, addflags) object.addmessageflags(uid, addflags)
delflags = [x for x in destflags if x not in selfflags] delflags = [x for x in destflags if x not in selfflags]
if len(delflags): if len(delflags):
print "Deleting flags from %d" % uid, delflags
for object in applyto: for object in applyto:
object.deletemessageflags(uid, delflags) object.deletemessageflags(uid, delflags)

View File

@ -17,7 +17,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from Base import BaseFolder from Base import BaseFolder
from imapsync import imaputil from imapsync import imaputil, imaplib
import rfc822 import rfc822
from StringIO import StringIO from StringIO import StringIO
@ -61,7 +61,7 @@ class IMAPFolder(BaseFolder):
def getmessage(self, uid): def getmessage(self, uid):
print "***************** GETMESSAGE %d" % uid print "***************** GETMESSAGE %d" % uid
assert(self.imapobj.select(self.getfullname())[0] == 'OK') 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): def getmessageflags(self, uid):
return self.getmessagelist()[uid]['flags'] return self.getmessagelist()[uid]['flags']
@ -75,6 +75,9 @@ class IMAPFolder(BaseFolder):
mid = self.imapobj._quote(message.getheader('Message-Id')) mid = self.imapobj._quote(message.getheader('Message-Id'))
date = imaplib.Time2Internaldate(rfc822.parsedate(message.getheader('Date'))) 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(), assert(self.imapobj.append(self.getfullname(),
imaputil.flagsmaildir2imap(flags), imaputil.flagsmaildir2imap(flags),
date, content)[0] == 'OK') date, content)[0] == 'OK')
@ -96,8 +99,11 @@ class IMAPFolder(BaseFolder):
self.messagelist[uid]['flags'] = imaputil.flagsimap2maildir(flags) self.messagelist[uid]['flags'] = imaputil.flagsimap2maildir(flags)
def deletemessage(self, uid): 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.select(self.getfullname())[0] == 'OK')
assert(self.imapobj.expunge()[0] == 'OK') assert(self.imapobj.expunge()[0] == 'OK')
del(self.messagelist[uid])

View File

@ -53,6 +53,7 @@ class LocalStatusFolder(BaseFolder):
line = file.readline().strip() line = file.readline().strip()
assert(line == magicline) assert(line == magicline)
for line in file.xreadlines(): for line in file.xreadlines():
line = line.strip()
uid, flags = line.split(':') uid, flags = line.split(':')
uid = long(uid) uid = long(uid)
flags = [x for x in flags] flags = [x for x in flags]
@ -91,5 +92,7 @@ class LocalStatusFolder(BaseFolder):
self.messagelist[uid]['flags'] = flags self.messagelist[uid]['flags'] = flags
def deletemessage(self, uid): def deletemessage(self, uid):
if not uid in self.messagelist:
return
del(self.messagelist[uid]) del(self.messagelist[uid])

View File

@ -158,6 +158,8 @@ class MaildirFolder(BaseFolder):
return self.getmessagelist()[uid]['flags'] return self.getmessagelist()[uid]['flags']
def deletemessage(self, uid): def deletemessage(self, uid):
if not uid in self.messagelist:
return
filename = self.getmessagelist()[uid]['filename'] filename = self.getmessagelist()[uid]['filename']
os.unlink(filename) os.unlink(filename)
del(self.messagelist[uid]) del(self.messagelist[uid])