]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Revamped test case and updated doc string.
authorGuido van Rossum <guido@python.org>
Tue, 17 Sep 1996 21:33:15 +0000 (21:33 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 17 Sep 1996 21:33:15 +0000 (21:33 +0000)
Lib/mailbox.py

index e60b73b966af6197993857b6b881a108ad7ae554..3d7d2fc7dce5956ffcd726411cdc25b373a12ef7 100755 (executable)
@@ -1,8 +1,8 @@
-#
-# A class to hand a unix-style or mmdf-style mailboxes
-#
-# Jack Jansen, CWI, March 1994.
-#
+#!/usr/local/bin/python
+
+"""Classes to handle Unix style, MMDF style, and MH style mailboxes."""
+
+
 import rfc822
 import os
 import regex
@@ -134,17 +134,32 @@ class MHMailbox:
        return rfc822.Message(fp)
            
     
-if __name__ == '__main__':
-       import posix
+def _test():
        import time
        import sys
        import string
-##     mbox = '/usr/mail/'+posix.environ['USER']
-##     fp = open(mbox, 'r')
-##     mb = UnixMailbox(fp)
-
-       mbox = posix.environ['HOME']+'/Mail/inbox'
-       mb = MHMailbox(mbox)
+       import os
+
+       args = sys.argv[1:]
+       if not args:
+               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)
+       else:
+               fp = open(mbox, 'r')
+               mb = UnixMailbox(fp)
        
        msgs = []
        while 1:
@@ -152,17 +167,20 @@ if __name__ == '__main__':
                if not msg:
                        break
                msgs.append(msg)
-       if len(sys.argv) > 1:
-               num = string.atoi(sys.argv[1])
+       if len(args) > 1:
+               num = string.atoi(args[1])
                print 'Message %d body:'%num
                msg = msgs[num-1]
                msg.rewindbody()
                sys.stdout.write(msg.fp.read())
-               sys.exit(0)
-       print 'Mailbox',mbox,'has',len(msgs),'messages:'
-       for msg in msgs:
-               f = msg.getheader('from')
-               s = msg.getheader('subject')
-               d = (msg.getheader('date'))
-               print '%20.20s   %18.18s   %-30.30s'%(f, d[5:], s)
-               
+       else:
+               print 'Mailbox',mbox,'has',len(msgs),'messages:'
+               for msg in msgs:
+                       f = msg.getheader('from')
+                       s = msg.getheader('subject')
+                       d = (msg.getheader('date'))
+                       print '%20.20s   %18.18s   %-30.30s'%(f, d[5:], s)
+
+
+if __name__ == '__main__':
+       _test()