@@ -155,8 +155,36 @@ def next(self):
155155 del self .boxes [0 ]
156156 fp = open (os .path .join (self .dirname , fn ))
157157 return rfc822 .Message (fp )
158-
159-
158+
159+ class Maildir :
160+
161+ # Qmail directory mailbox
162+
163+ def __init__ (self , dirname ):
164+ import string
165+ self .dirname = dirname
166+ self .boxes = []
167+
168+ # check for new mail
169+ newdir = os .path .join (self .dirname , 'new' )
170+ for file in os .listdir (newdir ):
171+ if len (string .split (file , '.' )) > 2 :
172+ self .boxes .append (os .path .join (newdir , file ))
173+
174+ # Now check for current mail in this maildir
175+ curdir = os .path .join (self .dirname , 'cur' )
176+ for file in os .listdir (curdir ):
177+ if len (string .split (file , '.' )) > 2 :
178+ self .boxes .append (os .path .join (curdir , file ))
179+
180+ def next (self ):
181+ if not self .boxes :
182+ return None
183+ fn = self .boxes [0 ]
184+ del self .boxes [0 ]
185+ fp = open (os .path .join (self .dirname , fn ))
186+ return rfc822 .Message (fp )
187+
160188class BabylMailbox (_Mailbox ):
161189
162190 def _search_start (self ):
@@ -186,7 +214,7 @@ def _test():
186214
187215 args = sys .argv [1 :]
188216 if not args :
189- for key in 'MAIL' , 'LOGNAME' , 'USER' :
217+ for key in 'MAILDIR' , ' MAIL' , 'LOGNAME' , 'USER' :
190218 if os .environ .has_key (key ):
191219 mbox = os .environ [key ]
192220 break
@@ -200,7 +228,10 @@ def _test():
200228 elif not '/' in mbox :
201229 mbox = '/usr/mail/' + mbox
202230 if os .path .isdir (mbox ):
203- mb = MHMailbox (mbox )
231+ if os .path .isdir (os .path .join (mbox , 'cur' )):
232+ mb = Maildir (mbox )
233+ else :
234+ mb = MHMailbox (mbox )
204235 else :
205236 fp = open (mbox , 'r' )
206237 mb = UnixMailbox (fp )
0 commit comments