Mercurial > cpython-lru_cache-weakref
annotate Demo/scripts/from.py @ 4566:6403c94de50d legacy-trunk
Added safeguard against failure in __del__.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 27 Nov 1996 19:39:58 +0000 |
| parents | d02ce30d7ddb |
| children | 73758db2f464 |
| rev | line source |
|---|---|
| 1267 | 1 #! /usr/local/bin/python |
| 274 | 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 | |
|
756
5d2f62ad8dee
change posix to os; and change error message
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
7 import sys, os |
| 274 | 8 |
| 9 # Open mailbox file. Exits with exception when this fails. | |
| 10 | |
|
501
ddbcd532c114
Improved error handling.
Guido van Rossum <guido@python.org>
parents:
274
diff
changeset
|
11 try: |
|
756
5d2f62ad8dee
change posix to os; and change error message
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
12 mailbox = os.environ['MAIL'] |
|
5d2f62ad8dee
change posix to os; and change error message
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
13 except (AttributeError, KeyError): |
|
5d2f62ad8dee
change posix to os; and change error message
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
14 sys.stderr.write('No environment variable $MAIL\n') |
|
501
ddbcd532c114
Improved error handling.
Guido van Rossum <guido@python.org>
parents:
274
diff
changeset
|
15 sys.exit(2) |
|
ddbcd532c114
Improved error handling.
Guido van Rossum <guido@python.org>
parents:
274
diff
changeset
|
16 |
|
ddbcd532c114
Improved error handling.
Guido van Rossum <guido@python.org>
parents:
274
diff
changeset
|
17 try: |
|
ddbcd532c114
Improved error handling.
Guido van Rossum <guido@python.org>
parents:
274
diff
changeset
|
18 mail = open(mailbox, 'r') |
|
870
9715fdc1e462
IOError instead of RuntimeError
Guido van Rossum <guido@python.org>
parents:
756
diff
changeset
|
19 except IOError: |
|
501
ddbcd532c114
Improved error handling.
Guido van Rossum <guido@python.org>
parents:
274
diff
changeset
|
20 sys.stderr.write('Cannot open mailbox file: ' + mailbox + '\n') |
|
ddbcd532c114
Improved error handling.
Guido van Rossum <guido@python.org>
parents:
274
diff
changeset
|
21 sys.exit(2) |
| 274 | 22 |
| 23 while 1: | |
| 24 line = mail.readline() | |
| 25 if not line: break # EOF | |
| 559 | 26 if line[:5] == 'From ': |
| 274 | 27 # Start of message found |
| 28 print line[:-1], | |
| 29 while 1: | |
| 30 line = mail.readline() | |
| 31 if not line: break # EOF | |
| 559 | 32 if line == '\n': break # Blank line ends headers |
| 33 if line[:8] == 'Subject:': | |
| 274 | 34 print `line[9:-1]`, |
| 35 print |
