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
|
|
|
|
while f.gets()
|
|
|
|
$_.chop!
|
|
|
|
next if /^From / # skip From-line
|
|
|
|
break if /^$/ # end of header
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
if /^(\S+):\s*(.*)/
|
1999-01-19 23:59:39 -05:00
|
|
|
(attr = $1).capitalize!
|
|
|
|
@header[attr] = $2
|
1998-01-16 07:19:22 -05:00
|
|
|
elsif attr
|
|
|
|
sub!(/^\s*/, '')
|
|
|
|
@header[attr] += "\n" + $_
|
|
|
|
end
|
1998-01-16 07:13:05 -05:00
|
|
|
end
|
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
return unless $_
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
while f.gets()
|
|
|
|
break if /^From /
|
|
|
|
@body.push($_)
|
|
|
|
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
|