/head: changeset 41

Now store the folder MD5 to make copies more robust
This commit is contained in:
jgoerzen 2002-06-22 05:32:29 +01:00
parent 749296b79e
commit 97f39b5ea8

View File

@ -18,7 +18,20 @@
from Base import BaseFolder from Base import BaseFolder
from offlineimap import imaputil from offlineimap import imaputil
import os.path, os, re, time, socket import os.path, os, re, time, socket, md5
timeseq = 0
lasttime = long(0)
def gettimeseq():
thistime = long(time.time())
if thistime == lasttime:
timeseq += 1
return timeseq
else:
lasttime = long(time.time())
timeseq = 0
return timeseq
class MaildirFolder(BaseFolder): class MaildirFolder(BaseFolder):
def __init__(self, root, name): def __init__(self, root, name):
@ -70,13 +83,23 @@ class MaildirFolder(BaseFolder):
filename in os.listdir(fulldirname)]) filename in os.listdir(fulldirname)])
for file in files: for file in files:
messagename = os.path.basename(file) messagename = os.path.basename(file)
uidmatch = re.search(',U=(\d+)', messagename) foldermatch = re.search(',FMD5=([0-9a-f]{32})', messagename)
uid = None if (not foldermatch) or \
if not uidmatch: md5.new(self.getvisiblename()).hexdigest() \
!= foldermatch.group(1):
# If there is no folder MD5 specified, or if it mismatches,
# assume it is a foreign (new) message and generate a
# negative uid for it
uid = nouidcounter uid = nouidcounter
nouidcounter -= 1 nouidcountr -= 1
else: else: # It comes from our folder.
uid = long(uidmatch.group(1)) uidmatch = re.search(',U=(\d+)', messagename)
uid = None
if not uidmatch:
uid = nouidcounter
nouidcounter -= 1
else:
uid = long(uidmatch.group(1))
flagmatch = re.search(':.*2,([A-Z]+)', messagename) flagmatch = re.search(':.*2,([A-Z]+)', messagename)
flags = [] flags = []
if flagmatch: if flagmatch:
@ -111,11 +134,13 @@ class MaildirFolder(BaseFolder):
while 1: while 1:
if attempts > 15: if attempts > 15:
raise IOError, "Couldn't write to file %s" % messagename raise IOError, "Couldn't write to file %s" % messagename
messagename = '%d.%d.%s,U=%d' % \ messagename = '%d_%d.%d.%s,U=%d,FMD5=%s' % \
(long(time.time()), (long(time.time()),
gettimeseq(),
os.getpid(), os.getpid(),
socket.gethostname(), socket.gethostname(),
uid) uid,
md5.new(self.getvisiblename()).hexdigest())
if os.path.exists(os.path.join(tmpdir, messagename)): if os.path.exists(os.path.join(tmpdir, messagename)):
time.sleep(2) time.sleep(2)
attempts += 1 attempts += 1