1998-01-16 07:13:05 -05:00
|
|
|
class Mail
|
1998-01-16 07:19:22 -05:00
|
|
|
|
|
|
|
def initialize(f)
|
1999-01-19 23:59:39 -05:00
|
|
|
unless defined? f.gets
|
1998-01-16 07:13:05 -05:00
|
|
|
f = open(f, "r")
|
1998-01-16 07:19:22 -05:00
|
|
|
opened = true
|
1998-01-16 07:13:05 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
@header = {}
|
|
|
|
@body = []
|
1998-01-16 07:19:22 -05:00
|
|
|
begin
|
2000-02-24 22:51:23 -05:00
|
|
|
while line = f.gets()
|
|
|
|
line.chop!
|
|
|
|
next if /^From /=~line # skip From-line
|
|
|
|
break if /^$/=~line # end of header
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-02-24 22:51:23 -05:00
|
|
|
if /^(\S+):\s*(.*)/=~line
|
1999-01-19 23:59:39 -05:00
|
|
|
(attr = $1).capitalize!
|
|
|
|
@header[attr] = $2
|
1998-01-16 07:19:22 -05:00
|
|
|
elsif attr
|
2000-02-24 22:51:23 -05:00
|
|
|
line.sub!(/^\s*/, '')
|
|
|
|
@header[attr] += "\n" + line
|
1998-01-16 07:19:22 -05:00
|
|
|
end
|
1998-01-16 07:13:05 -05:00
|
|
|
end
|
|
|
|
|
2000-02-24 22:51:23 -05:00
|
|
|
return unless line
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-02-24 22:51:23 -05:00
|
|
|
while line = f.gets()
|
|
|
|
break if /^From /=~line
|
|
|
|
@body.push(line)
|
1998-01-16 07:19:22 -05:00
|
|
|
end
|
|
|
|
ensure
|
|
|
|
f.close if opened
|
1998-01-16 07:13:05 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def header
|
|
|
|
return @header
|
|
|
|
end
|
|
|
|
|
|
|
|
def body
|
|
|
|
return @body
|
|
|
|
end
|
|
|
|
|
|
|
|
def [](field)
|
1999-08-13 01:45:20 -04:00
|
|
|
@header[field.capitalize]
|
1998-01-16 07:13:05 -05:00
|
|
|
end
|
|
|
|
end
|