Class: InternetMessage::Received

Inherits:
Object
  • Object
show all
Defined in:
lib/internet_message/received.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from, by, via, with, id, for_, date) ⇒ Received

Returns a new instance of Received.

Parameters:

  • from (String)
  • by (String)
  • via (String)
  • with (String)
  • id (String)
  • for_ (Mailbox)
  • date (DateTime)


53
54
55
56
# File 'lib/internet_message/received.rb', line 53

def initialize(from, by, via, with, id, for_, date)
  @from, @by, @via, @with, @id, @for, @date =
    from, by, via, with, id, for_, date
end

Instance Attribute Details

#byObject (readonly)

Returns the value of attribute by.



44
45
46
# File 'lib/internet_message/received.rb', line 44

def by
  @by
end

#dateObject (readonly)

Returns the value of attribute date.



44
45
46
# File 'lib/internet_message/received.rb', line 44

def date
  @date
end

#forObject (readonly)

Returns the value of attribute for.



44
45
46
# File 'lib/internet_message/received.rb', line 44

def for
  @for
end

#fromObject (readonly)

Returns the value of attribute from.



44
45
46
# File 'lib/internet_message/received.rb', line 44

def from
  @from
end

#idObject (readonly)

Returns the value of attribute id.



44
45
46
# File 'lib/internet_message/received.rb', line 44

def id
  @id
end

#viaObject (readonly)

Returns the value of attribute via.



44
45
46
# File 'lib/internet_message/received.rb', line 44

def via
  @via
end

#withObject (readonly)

Returns the value of attribute with.



44
45
46
# File 'lib/internet_message/received.rb', line 44

def with
  @with
end

Class Method Details

.parse(src) ⇒ Received

Parameters:

Returns:



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/internet_message/received.rb', line 8

def self.parse(src)
  tokens = src.is_a?(String) ? Tokenizer.new(src).tokenize : src.dup
  i = tokens.index(Token.new(:CHAR, ';'))
  return unless i
  date = DateTime.parse(tokens[i+1..-1].join) rescue nil
  tokens = tokens[0, i]

  list = tokens.inject([[]]){|r, t|
    if t.type == :WSP or t.type == :COMMENT
      r.push []
    else
      r.last.push t
    end
    r
  }.reject(&:empty?)

  while list.size >= 2
    case list.shift.join.downcase
    when 'from'
      from = list.shift.join
    when 'by'
      by = list.shift.join
    when 'via'
      via = list.shift.join
    when 'with'
      with = list.shift.join
    when 'id'
      id = list.shift.join
    when 'for'
      m = Mailbox.parse(list.shift)
      for_ = m && m.address
    end
  end
  self.new(from, by, via, with, id, for_, date)
end