Fix issue number in comment.
[python.git] / Demo / scripts / from.py
blob3c04fcd4978a1d223de8f6bd8448e7a177aaaceb
1 #! /usr/bin/env python
3 # Print From and Subject of messages in $MAIL.
4 # Extension to multiple mailboxes and other bells & whistles are left
5 # as exercises for the reader.
7 import sys, os
9 # Open mailbox file. Exits with exception when this fails.
11 try:
12 mailbox = os.environ['MAIL']
13 except (AttributeError, KeyError):
14 sys.stderr.write('No environment variable $MAIL\n')
15 sys.exit(2)
17 try:
18 mail = open(mailbox)
19 except IOError:
20 sys.exit('Cannot open mailbox file: ' + mailbox)
22 while 1:
23 line = mail.readline()
24 if not line:
25 break # EOF
26 if line.startswith('From '):
27 # Start of message found
28 print line[:-1],
29 while 1:
30 line = mail.readline()
31 if not line or line == '\n':
32 break
33 if line.startswith('Subject: '):
34 print repr(line[9:-1]),
35 print