PageRenderTime 343ms CodeModel.GetById 181ms app.highlight 3ms RepoModel.GetById 158ms app.codeStats 0ms

/Demo/scripts/from.py

http://unladen-swallow.googlecode.com/
Python | 35 lines | 23 code | 6 blank | 6 comment | 9 complexity | 7ac20134b5ce765688685106c4f501ab MD5 | raw file
 1#! /usr/bin/env 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
 7import sys, os
 8
 9# Open mailbox file.  Exits with exception when this fails.
10
11try:
12    mailbox = os.environ['MAIL']
13except (AttributeError, KeyError):
14    sys.stderr.write('No environment variable $MAIL\n')
15    sys.exit(2)
16
17try:
18    mail = open(mailbox)
19except IOError:
20    sys.exit('Cannot open mailbox file: ' + mailbox)
21
22while 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