blob: 21ca081669ef92f56e7b5cf3cad58ec4af98f6f0 [file] [log] [blame]
Guido van Rossumec758ea1991-06-04 20:36:54 +00001#! /usr/local/python
2
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.
6
Guido van Rossum5558b891991-12-18 13:38:42 +00007import sys, posix
Guido van Rossumec758ea1991-06-04 20:36:54 +00008
9# Open mailbox file. Exits with exception when this fails.
10
Guido van Rossum5558b891991-12-18 13:38:42 +000011try:
12 mailbox = posix.environ['MAIL']
13except RuntimeError:
14 sys.stderr.write \
15 ('Please set environment variable MAIL to your mailbox\n')
16 sys.exit(2)
17
18try:
19 mail = open(mailbox, 'r')
20except RuntimeError:
21 sys.stderr.write('Cannot open mailbox file: ' + mailbox + '\n')
22 sys.exit(2)
Guido van Rossumec758ea1991-06-04 20:36:54 +000023
24while 1:
25 line = mail.readline()
26 if not line: break # EOF
27 if line[:5] = 'From ':
28 # Start of message found
29 print line[:-1],
30 while 1:
31 line = mail.readline()
32 if not line: break # EOF
33 if line = '\n': break # Blank line ends headers
34 if line[:8] = 'Subject:':
35 print `line[9:-1]`,
36 print