]>
code.delx.au - offlineimap/blob - head/offlineimap/folder/Maildir.py
1 # Maildir folder support
2 # Copyright (C) 2002 John Goerzen
3 # <jgoerzen@complete.org>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 from Base
import BaseFolder
20 from imapsync
import imaputil
21 import os
.path
, os
, re
23 class MaildirFolder(BaseFolder
):
24 def __init__(self
, root
, name
):
28 self
.uidfilename
= os
.path
.join(self
.getfullname(), "imapsync.uidvalidity")
29 self
.messagelist
= None
31 def getuidvalidity(self
):
32 if not os
.path
.exists(self
.uidfilename
):
34 file = open(self
.uidfilename
, "rt")
35 retval
= int(file.readline().strip())
39 def saveuidvalidity(self
, newval
):
40 file = open(self
.uidfilename
, "wt")
41 file.write("%d\n", newval
)
44 def isuidvalidityok(self
, remotefolder
):
45 myval
= self
.getuidvalidity()
47 return myval
== remotefolder
.getuidvalidity()
49 self
.saveuidvalidity(remotefolder
.getuidvalidity())
51 def cachemessagelist(self
):
52 """Cache the message list. Maildir flags are:
58 and must occur in ASCII order."""
61 nouidcounter
= -1 # Messages without UIDs get
62 # negative UID numbers.
63 for dirannex
in ['new', 'cur']:
64 fulldirname
= os
.path
.join(self
.getfullname(), dirannex
)
65 files
.append([os
.path
.join(fulldirname
, filename
) for
66 filename
in os
.listdir(fulldirname
)])
68 messagename
= os
.path
.basename(file)
69 uidmatch
= re
.search(',U=(\d+)', messagename
)
75 uid
= int(uidmatch
.group(1))
76 flagmatch
= re
.search(':.*2,([A-Z]+)')
79 flags
= [f
for x
in flagmatch
.group(1)]
80 self
.messagelist
[uid
] = {'uid': uid
,
82 'filename': messagename
}
84 def getmessagelist(self
):
85 return self
.messagelist