Guido van Rossum | ec758ea | 1991-06-04 20:36:54 +0000 | [diff] [blame^] | 1 | #! /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 | |
| 7 | import posix |
| 8 | |
| 9 | # Open mailbox file. Exits with exception when this fails. |
| 10 | |
| 11 | mail = open(posix.environ['MAIL'], 'r') |
| 12 | |
| 13 | while 1: |
| 14 | line = mail.readline() |
| 15 | if not line: break # EOF |
| 16 | if line[:5] = 'From ': |
| 17 | # Start of message found |
| 18 | print line[:-1], |
| 19 | while 1: |
| 20 | line = mail.readline() |
| 21 | if not line: break # EOF |
| 22 | if line = '\n': break # Blank line ends headers |
| 23 | if line[:8] = 'Subject:': |
| 24 | print `line[9:-1]`, |
| 25 | print |