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
|
2000-10-10 13:24:54 +04:00
|
|
|
while line = f.gets()
|
2000-02-25 06:51:23 +03:00
|
|
|
line.chop!
|
|
|
|
next if /^From /=~line # skip From-line
|
|
|
|
break if /^$/=~line # end of header
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2001-10-02 08:31:23 +04:00
|
|
|
if /^(\S+?):\s*(.*)/=~line
|
1999-01-20 07:59:39 +03:00
|
|
|
(attr = $1).capitalize!
|
|
|
|
@header[attr] = $2
|
1998-01-16 15:19:22 +03:00
|
|
|
elsif attr
|
2000-02-25 06:51:23 +03:00
|
|
|
line.sub!(/^\s*/, '')
|
|
|
|
@header[attr] += "\n" + line
|
1998-01-16 15:19:22 +03:00
|
|
|
end
|
1998-01-16 15:13:05 +03:00
|
|
|
end
|
|
|
|
|
2000-02-25 06:51:23 +03:00
|
|
|
return unless line
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-02-25 06:51:23 +03:00
|
|
|
while line = f.gets()
|
|
|
|
break if /^From /=~line
|
|
|
|
@body.push(line)
|
1998-01-16 15:19:22 +03:00
|
|
|
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)
|
1999-08-13 09:45:20 +04:00
|
|
|
@header[field.capitalize]
|
1998-01-16 15:13:05 +03:00
|
|
|
end
|
|
|
|
end
|