Class: Mail

Inherits:
Object show all
Defined in:
sample/tkfrom.rb,
sample/tkbiff.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(f) ⇒ Mail

Returns a new instance of Mail.


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'sample/tkfrom.rb', line 20

def initialize(f)
  @header = {}
  @body = []
  while line = f.gets()
    $_.chop!
    next if /^From / =~ line  # skip From-line
    break if /^$/ =~ line     # end of header
    if /^(\S+):\s*(.*)/ =~ line
      @header[attr = $1.capitalize] = $2
    elsif attr
      sub(/^\s*/, '')
      @header[attr] += "\n" + $_
    end
  end

  return unless $_

  while line = f.gets()
    break if /^From / =~ line
    @body.push($_)
  end
end

Class Method Details

.new(f) ⇒ Object


9
10
11
12
13
14
15
16
17
18
# File 'sample/tkfrom.rb', line 9

def Mail.new(f)
  if !f.kind_of?(IO)
    f = open(f, "r")
    me = super(f)
    f.close
  else
    me = super
  end
  return me
end

Instance Method Details

#bodyObject


47
48
49
# File 'sample/tkfrom.rb', line 47

def body
  return @body
end

#headerObject


43
44
45
# File 'sample/tkfrom.rb', line 43

def header
  return @header
end