2 # A class to hand a unix-style or mmdf-style mailboxes
4 # Jack Jansen, CWI, March 1994.
9 def __init__(self
, fp
):
18 self
.fp
.seek(self
.seekp
)
22 self
.seekp
= self
.fp
.tell()
24 start
= self
.fp
.tell()
26 self
.seekp
= stop
= self
.fp
.tell()
29 return rfc822
.Message(_Subfile(self
.fp
, start
, stop
))
32 def __init__(self
, fp
, start
, stop
):
38 def read(self
, length
= None):
39 if self
.pos
>= self
.stop
:
42 length
= self
.stop
- self
.pos
43 self
.fp
.seek(self
.pos
)
44 self
.pos
= self
.pos
+ length
45 return self
.fp
.read(length
)
47 def readline(self
, length
= None):
48 if self
.pos
>= self
.stop
:
51 length
= self
.stop
- self
.pos
52 self
.fp
.seek(self
.pos
)
53 data
= self
.fp
.readline(length
)
54 if len(data
) < length
:
56 self
.pos
= self
.pos
+ length
60 return self
.pos
- self
.start
63 self
.pos
= pos
+ self
.start
68 class UnixMailbox(_Mailbox
):
69 def _search_start(self
):
71 line
= self
.fp
.readline()
74 if line
[:5] == 'From ':
77 def _search_end(self
):
80 line
= self
.fp
.readline()
83 if line
[:5] == 'From ':
87 class MmdfMailbox(_Mailbox
):
88 def _search_start(self
):
90 line
= self
.fp
.readline()
93 if line
[:5] == '\001\001\001\001\n':
96 def _search_end(self
):
99 line
= self
.fp
.readline()
102 if line
== '\001\001\001\001\n':
106 if __name__
== '__main__':
111 mbox
= '/usr/mail/'+posix
.environ
['USER']
120 if len(sys
.argv
) > 1:
121 num
= string
.atoi(sys
.argv
[1])
122 print 'Message %d body:'%num
125 sys
.stdout
.write(msg
.fp
.read())
127 print 'Mailbox',mbox
,'has',len(msgs
),'messages:'
129 f
= msg
.getheader('from')
130 s
= msg
.getheader('subject')
131 d
= (msg
.getheader('date'))
132 print '%20.20s %18.18s %-30.30s'%(f
, d
[5:], s
)