summaryrefslogtreecommitdiff
path: root/lib/mailread.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mailread.rb')
-rw-r--r--lib/mailread.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/mailread.rb b/lib/mailread.rb
new file mode 100644
index 0000000000..d9feffbb7a
--- /dev/null
+++ b/lib/mailread.rb
@@ -0,0 +1,48 @@
+class Mail
+ def Mail.new(f)
+ unless f.kind_of?(IO)
+ f = open(f, "r")
+ me = super(f)
+ f.close
+ else
+ me = super
+ end
+ return me
+ end
+
+ def initialize(f)
+ @header = {}
+ @body = []
+ 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" + $_
+ end
+ end
+
+ return unless $_
+
+ while f.gets()
+ break if /^From /
+ @body.push($_)
+ end
+ end
+
+ def header
+ return @header
+ end
+
+ def body
+ return @body
+ end
+
+ def [](field)
+ @header[field]
+ end
+end