Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9a4d637

Browse files
committed
Patch by Mike Meyer:
Add a class to mailbox.py for dealing with qmail directory mailboxes. The test code was extended to notice these being used as well.
1 parent 99e1131 commit 9a4d637

1 file changed

Lines changed: 35 additions & 4 deletions

File tree

Lib/mailbox.py

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
160188
class 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

Comments
 (0)