Class: Mail::ReceivedField

Inherits:
StructuredField show all
Defined in:
lib/mail/fields/received_field.rb

Constant Summary

FIELD_NAME =
'received'
CAPITALIZED_FIELD =
'Received'

Constants included from Utilities

Utilities::CRLF, Utilities::CRLF_REGEX, Utilities::LF

Constants included from Constants

Constants::ASTERISK, Constants::ATOM_UNSAFE, Constants::B_VALUES, Constants::CAPITAL_M, Constants::COLON, Constants::CONTROL_CHAR, Constants::CR, Constants::CRLF, Constants::CR_ENCODED, Constants::EMPTY, Constants::ENCODED_VALUE, Constants::EQUAL_LF, Constants::FIELD_BODY, Constants::FIELD_LINE, Constants::FIELD_PREFIX, Constants::FIELD_SPLIT, Constants::FULL_ENCODED_VALUE, Constants::FWS, Constants::HEADER_LINE, Constants::HEADER_SPLIT, Constants::HYPHEN, Constants::LF, Constants::LF_ENCODED, Constants::NULL_SENDER, Constants::PHRASE_UNSAFE, Constants::QP_SAFE, Constants::QP_UNSAFE, Constants::Q_VALUES, Constants::SPACE, Constants::TEXT, Constants::TOKEN_UNSAFE, Constants::UNDERSCORE, Constants::WSP

Instance Method Summary collapse

Methods inherited from StructuredField

#charset, #charset=, #default, #errors

Methods included from Utilities

#atom_safe?, blank?, #bracket, #capitalize_field, #constantize, #dasherize, #dquote, #escape_paren, #map_lines, #map_with_index, #match_to_s, #paren, #quote_atom, #quote_phrase, #quote_token, to_crlf, to_lf, #token_safe?, #unbracket, #underscoreize, #unparen, unquote, #uri_escape, #uri_parser, #uri_unescape

Methods included from CommonField

#default, #field_length, #name, #name=, #responsible_for?, #to_s, #value, #value=

Constructor Details

#initialize(value = nil, charset = 'utf-8') ⇒ ReceivedField

Returns a new instance of ReceivedField



29
30
31
32
33
34
35
# File 'lib/mail/fields/received_field.rb', line 29

def initialize(value = nil, charset = 'utf-8')
  self.charset = charset
  super(CAPITALIZED_FIELD, strip_field(FIELD_NAME, value), charset)
  self.parse
  self

end

Instance Method Details

#date_timeObject



47
48
49
# File 'lib/mail/fields/received_field.rb', line 47

def date_time
  @datetime ||= ::DateTime.parse("#{element.date_time}")
end

#decodedObject



67
68
69
70
71
72
73
# File 'lib/mail/fields/received_field.rb', line 67

def decoded
  if Utilities.blank?(value)
    ""
  else
    "#{info}; #{formatted_date}" 
  end
end

#elementObject



43
44
45
# File 'lib/mail/fields/received_field.rb', line 43

def element
  @element ||= Mail::ReceivedElement.new(value)
end

#encodedObject



59
60
61
62
63
64
65
# File 'lib/mail/fields/received_field.rb', line 59

def encoded
  if Utilities.blank?(value)
    "#{CAPITALIZED_FIELD}: \r\n"
  else
    "#{CAPITALIZED_FIELD}: #{info}; #{formatted_date}\r\n"
  end
end

#formatted_dateObject



55
56
57
# File 'lib/mail/fields/received_field.rb', line 55

def formatted_date
  date_time.strftime("%a, %d %b %Y %H:%M:%S ") + date_time.zone.delete(':')
end

#infoObject



51
52
53
# File 'lib/mail/fields/received_field.rb', line 51

def info
  element.info
end

#parse(val = value) ⇒ Object



37
38
39
40
41
# File 'lib/mail/fields/received_field.rb', line 37

def parse(val = value)
  unless Utilities.blank?(val)
    @element = Mail::ReceivedElement.new(val)
  end
end