summaryrefslogtreecommitdiff
path: root/lib/mailread.rb
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-01-16 12:19:22 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-01-16 12:19:22 +0000
commit7ea2ceddb832b9973694fecac9fe3c30400735ba (patch)
treea9b60dec20fa5f7f52ca7c8113195f2d65728a22 /lib/mailread.rb
parent62e41d3f2e48422bbdf1bb2db83ae60b255b1a1a (diff)
This commit was generated by cvs2svn to compensate for changes in r11,
which included commits to RCS files with non-trunk default branches. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/mailread.rb')
-rw-r--r--lib/mailread.rb43
1 files changed, 21 insertions, 22 deletions
diff --git a/lib/mailread.rb b/lib/mailread.rb
index d9feffbb7a..a5d60c84b4 100644
--- a/lib/mailread.rb
+++ b/lib/mailread.rb
@@ -1,36 +1,35 @@
class Mail
- def Mail.new(f)
+
+ def initialize(f)
unless f.kind_of?(IO)
f = open(f, "r")
- me = super(f)
- f.close
- else
- me = super
+ opened = true
end
- return me
- end
- def initialize(f)
@header = {}
@body = []
- while f.gets()
- $_.chop!
- next if /^From / # skip From-line
- break if /^$/ # end of header
+ begin
+ while f.gets()
+ $_.chop!
+ next if /^From / # skip From-line
+ break if /^$/ # end of header
- if /^(\S+):\s*(.*)/
- @header[attr = $1.capitalize!] = $2
- elsif attr
- sub!(/^\s*/, '')
- @header[attr] += "\n" + $_
+ if /^(\S+):\s*(.*)/
+ @header[attr = $1.capitalize!] = $2
+ elsif attr
+ sub!(/^\s*/, '')
+ @header[attr] += "\n" + $_
+ end
end
- end
- return unless $_
+ return unless $_
- while f.gets()
- break if /^From /
- @body.push($_)
+ while f.gets()
+ break if /^From /
+ @body.push($_)
+ end
+ ensure
+ f.close if opened
end
end