Class: Mail

Class | Mail
In: | mailread.rb
Parent: | Object

### Methods

[] body header new

### Public Class methods

new(f)

[Source]

    # File mailread.rb, line 3
      def initialize(f)
        unless defined? f.gets
          f = open(f, "r")
          opened = true
        end

        @header = {}
        @body = []
        begin
          while line = f.gets()
            line.chop!
            next if /^From /=~line # skip From-line
            break if /^$/=~line    # end of header

            if /^(\S+?):\s*(.*)/=~line
              (attr = $1).capitalize!
              @header[attr] = $2
            elsif attr
              line.sub!(/^\s*/, '')
              @header[attr] += "\n" + line
            end
          end

          return unless line

          while line = f.gets()
            break if /^From /=~line
            @body.push(line)
          end
        ensure
          f.close if opened
        end
      end

### Public Instance methods

[](field)

[Source]

    # File mailread.rb, line 45
      def [](field)
        @header[field.capitalize]
      end

body()

[Source]

    # File mailread.rb, line 41
      def body
        return @body
      end

header()

[Source]

    # File mailread.rb, line 37
      def header
        return @header
      end

[Validate]