Class: TMail::HeaderField

Inherits:
Object show all
Includes:
StrategyInterface, TextUtils
Defined in:
lib/action_mailer/vendor/tmail-1.2.1/tmail/header.rb,
lib/action_mailer/vendor/tmail-1.2.1/tmail/header.rb

Overview

redefine

Direct Known Subclasses

StructuredHeader, UnstructuredHeader

Constant Summary collapse

FNAME_TO_CLASS =
{
  'date'                      => DateTimeHeader,
  'resent-date'               => DateTimeHeader,
  'to'                        => AddressHeader,
  'cc'                        => AddressHeader,
  'bcc'                       => AddressHeader,
  'from'                      => AddressHeader,
  'reply-to'                  => AddressHeader,
  'resent-to'                 => AddressHeader,
  'resent-cc'                 => AddressHeader,
  'resent-bcc'                => AddressHeader,
  'resent-from'               => AddressHeader,
  'resent-reply-to'           => AddressHeader,
  'sender'                    => SingleAddressHeader,
  'resent-sender'             => SingleAddressHeader,
  'return-path'               => ReturnPathHeader,
  'message-id'                => MessageIdHeader,
  'resent-message-id'         => MessageIdHeader,
  'in-reply-to'               => ReferencesHeader,
  'received'                  => ReceivedHeader,
  'references'                => ReferencesHeader,
  'keywords'                  => KeywordsHeader,
  'encrypted'                 => EncryptedHeader,
  'mime-version'              => MimeVersionHeader,
  'content-type'              => ContentTypeHeader,
  'content-transfer-encoding' => ContentTransferEncodingHeader,
  'content-disposition'       => ContentDispositionHeader,
  'content-id'                => MessageIdHeader,
  'subject'                   => UnstructuredHeader,
  'comments'                  => UnstructuredHeader,
  'content-description'       => UnstructuredHeader
}

Constants included from TextUtils

TextUtils::ATOM_UNSAFE, TextUtils::CONTROL_CHAR, TextUtils::MESSAGE_ID, TextUtils::MIME_ENCODED, TextUtils::MONTH, TextUtils::NKF_FLAGS, TextUtils::PHRASE_UNSAFE, TextUtils::RFC2231_ENCODED, TextUtils::TOKEN_UNSAFE, TextUtils::WDAY, TextUtils::ZONESTR_TABLE

Class Method Summary collapse

Instance Method Summary collapse

Methods included from StrategyInterface

#accept_strategy, create_dest, #decoded, #encoded

Methods included from TextUtils

#atom_safe?, #decode_RFC2231, #decode_params, #join_domain, #message_id?, #mime_encoded?, #quote_atom, #quote_boundary, #quote_phrase, #quote_token, #time2str, #timezone_string_to_unixtime, #to_kcode, #token_safe?, #unquote

Constructor Details

#initialize(body, conf, intern = false) ⇒ HeaderField

class << self



110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/action_mailer/vendor/tmail-1.2.1/tmail/header.rb', line 110

def initialize( body, conf, intern = false )
  @body = body
  @config = conf

  @illegal = false
  @parsed = false
  
  if intern
    @parsed = true
    parse_init
  end
end

Class Method Details

.internal_new(name, conf) ⇒ Object



104
105
106
# File 'lib/action_mailer/vendor/tmail-1.2.1/tmail/header.rb', line 104

def internal_new( name, conf )
  FNAME_TO_CLASS[name].newobj('', conf, true)
end

.new(name, body, conf = DEFAULT_CONFIG) ⇒ Object



52
53
54
55
# File 'lib/action_mailer/vendor/tmail-1.2.1/tmail/header.rb', line 52

def new( name, body, conf = DEFAULT_CONFIG )
  klass = FNAME_TO_CLASS[name.downcase] || UnstructuredHeader
  klass.newobj body, conf
end

.new_from_port(port, name, conf = DEFAULT_CONFIG) ⇒ Object

Returns a HeaderField object matching the header you specify in the “name” param. Requires an initialized TMail::Port to be passed in.

The method searches the header of the Port you pass into it to find a match on the header line you pass. Once a match is found, it will unwrap the matching line as needed to return an initialized HeaderField object.

If you want to get the Envelope sender of the email object, pass in “EnvelopeSender”, if you want the From address of the email itself, pass in ‘From’.

This is because a mailbox doesn’t have the : after the From that designates the beginning of the envelope sender (which can be different to the from address of the emial)

Other fields can be passed as normal, “Reply-To”, “Received” etc.

Note: Change of behaviour in 1.2.1 => returns nil if it does not find the specified header field, otherwise returns an instantiated object of the correct header class

For example:

port = TMail::FilePort.new("/test/fixtures/raw_email_simple")
h = TMail::HeaderField.new_from_port(port, "From")
h.addrs.to_s #=> "Mikel Lindsaar <[email protected]>"
h = TMail::HeaderField.new_from_port(port, "EvelopeSender")
h.addrs.to_s #=> "[email protected]"
h = TMail::HeaderField.new_from_port(port, "SomeWeirdHeaderField")
h #=> nil


84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/action_mailer/vendor/tmail-1.2.1/tmail/header.rb', line 84

def new_from_port( port, name, conf = DEFAULT_CONFIG )
  if name == "EnvelopeSender"
    name = "From"
    re = Regexp.new('\A(From) ', 'i')
  else
    re = Regexp.new('\A(' + Regexp.quote(name) + '):', 'i')
  end
  str = nil
  port.ropen {|f|
      f.each do |line|
        if m = re.match(line)            then str = m.post_match.strip
        elsif str and /\A[\t ]/ === line then str << ' ' << line.strip
        elsif /\A-*\s*\z/ === line       then break
        elsif str                        then break
        end
      end
  }
  new(name, str, Config.to_config(conf)) if str
end

.newobjObject



50
# File 'lib/action_mailer/vendor/tmail-1.2.1/tmail/header.rb', line 50

alias newobj new

Instance Method Details

#accept(strategy) ⇒ Object



170
171
172
173
174
# File 'lib/action_mailer/vendor/tmail-1.2.1/tmail/header.rb', line 170

def accept( strategy )
  ensure_parsed
  do_accept strategy
  strategy.terminate
end

#bodyObject



155
156
157
158
159
160
161
# File 'lib/action_mailer/vendor/tmail-1.2.1/tmail/header.rb', line 155

def body
  ensure_parsed
  v = Decoder.new(s = '')
  do_accept v
  v.terminate
  s
end

#body=(str) ⇒ Object



163
164
165
166
# File 'lib/action_mailer/vendor/tmail-1.2.1/tmail/header.rb', line 163

def body=( str )
  @body = str
  clear_parse_status
end

#empty?Boolean

Returns:

  • (Boolean)


131
132
133
134
135
# File 'lib/action_mailer/vendor/tmail-1.2.1/tmail/header.rb', line 131

def empty?
  ensure_parsed
  return true if @illegal
  isempty?
end

#illegal?Boolean

Returns:

  • (Boolean)


127
128
129
# File 'lib/action_mailer/vendor/tmail-1.2.1/tmail/header.rb', line 127

def illegal?
  @illegal
end

#inspectObject



123
124
125
# File 'lib/action_mailer/vendor/tmail-1.2.1/tmail/header.rb', line 123

def inspect
  "#<#{self.class} #{@body.inspect}>"
end