Class: EmailGraph::GmailFetcher::Message

Inherits:
Struct
  • Object
show all
Defined in:
lib/email_graph/gmail_fetcher.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ Message

Returns a new instance of Message.



58
59
60
# File 'lib/email_graph/gmail_fetcher.rb', line 58

def initialize(**kwargs)
  kwargs.each{ |k, v| self[k] = v }
end

Instance Attribute Details

#bccObject

Returns the value of attribute bcc

Returns:

  • (Object)

    the current value of bcc



56
57
58
# File 'lib/email_graph/gmail_fetcher.rb', line 56

def bcc
  @bcc
end

#ccObject

Returns the value of attribute cc

Returns:

  • (Object)

    the current value of cc



56
57
58
# File 'lib/email_graph/gmail_fetcher.rb', line 56

def cc
  @cc
end

#dateObject

Returns the value of attribute date

Returns:

  • (Object)

    the current value of date



56
57
58
# File 'lib/email_graph/gmail_fetcher.rb', line 56

def date
  @date
end

#fromObject

Returns the value of attribute from

Returns:

  • (Object)

    the current value of from



56
57
58
# File 'lib/email_graph/gmail_fetcher.rb', line 56

def from
  @from
end

#toObject

Returns the value of attribute to

Returns:

  • (Object)

    the current value of to



56
57
58
# File 'lib/email_graph/gmail_fetcher.rb', line 56

def to
  @to
end

Class Method Details

.from_net_imap_envelope(e) ⇒ Message

Parameters:

  • e (+Net::IMAP::Envelope+)

Returns:



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/email_graph/gmail_fetcher.rb', line 64

def self.from_net_imap_envelope(e)
  addresses_by_field = {}
  address_fields = [:from, :to, :cc, :bcc]
  address_fields.each do |field|
    addresses = e.attr['ENVELOPE'].send(field) || []
    addresses_by_field[field] = addresses.map{ |a| Address.from_net_imap_address(a) }
  end
  
  date_raw = e.attr['ENVELOPE'].date
  date = nil
  begin
    date = Time.parse(date_raw) if date_raw
  rescue ArgumentError
    # Observed cases:
    # - date_raw == "{DATE}"
    # - Time.parse raises 'ArgumentError: argument out of range'
  end

  new(**addresses_by_field, date: date)
end