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.



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

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



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

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



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

def body
  return @body
end

#headerObject



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

def header
  return @header
end