Kaydet (Commit) 6244867e authored tarafından Guido van Rossum's avatar Guido van Rossum

Revamped test case and updated doc string.

üst 452a9833
# #!/usr/local/bin/python
# A class to hand a unix-style or mmdf-style mailboxes
# """Classes to handle Unix style, MMDF style, and MH style mailboxes."""
# Jack Jansen, CWI, March 1994.
#
import rfc822 import rfc822
import os import os
import regex import regex
...@@ -134,17 +134,32 @@ class MHMailbox: ...@@ -134,17 +134,32 @@ class MHMailbox:
return rfc822.Message(fp) return rfc822.Message(fp)
if __name__ == '__main__': def _test():
import posix
import time import time
import sys import sys
import string import string
## mbox = '/usr/mail/'+posix.environ['USER'] import os
## fp = open(mbox, 'r')
## mb = UnixMailbox(fp) args = sys.argv[1:]
if not args:
mbox = posix.environ['HOME']+'/Mail/inbox' if os.environ.has_key('MAIL'):
mbox = os.environ['MAIL']
elif os.environ.has_key('MAIL'):
mbox = os.environ['USER']
else:
print "Who are you?"
return
else:
mbox = args[0]
if mbox[:1] == '+':
mbox = os.environ['HOME'] + '/Mail/' + mbox[1:]
elif not '/' in mbox:
mbox = '/usr/mail/' + mbox
if os.path.isdir(mbox):
mb = MHMailbox(mbox) mb = MHMailbox(mbox)
else:
fp = open(mbox, 'r')
mb = UnixMailbox(fp)
msgs = [] msgs = []
while 1: while 1:
...@@ -152,13 +167,13 @@ if __name__ == '__main__': ...@@ -152,13 +167,13 @@ if __name__ == '__main__':
if not msg: if not msg:
break break
msgs.append(msg) msgs.append(msg)
if len(sys.argv) > 1: if len(args) > 1:
num = string.atoi(sys.argv[1]) num = string.atoi(args[1])
print 'Message %d body:'%num print 'Message %d body:'%num
msg = msgs[num-1] msg = msgs[num-1]
msg.rewindbody() msg.rewindbody()
sys.stdout.write(msg.fp.read()) sys.stdout.write(msg.fp.read())
sys.exit(0) else:
print 'Mailbox',mbox,'has',len(msgs),'messages:' print 'Mailbox',mbox,'has',len(msgs),'messages:'
for msg in msgs: for msg in msgs:
f = msg.getheader('from') f = msg.getheader('from')
...@@ -166,3 +181,6 @@ if __name__ == '__main__': ...@@ -166,3 +181,6 @@ if __name__ == '__main__':
d = (msg.getheader('date')) d = (msg.getheader('date'))
print '%20.20s %18.18s %-30.30s'%(f, d[5:], s) print '%20.20s %18.18s %-30.30s'%(f, d[5:], s)
if __name__ == '__main__':
_test()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment