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