class method
self.new_from_port
Ruby on Rails 2.3.18
Since v2.2.3 Last seen in v2.3.18Available in: v2.2.3 v2.3.18
Signature
self.new_from_port( port, name, conf = DEFAULT_CONFIG )
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 email)
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 <mikel@nowhere.com>" h = TMail::HeaderField.new_from_port(port, "EvelopeSender") h.addrs.to_s #=> "mike@anotherplace.com.au" h = TMail::HeaderField.new_from_port(port, "SomeWeirdHeaderField") h #=> nil
Parameters
-
portreq -
namereq -
confopt = DEFAULT_CONFIG
Source
# File actionmailer/lib/action_mailer/vendor/tmail-1.2.7/tmail/header.rb, line 77
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
Defined in actionmailer/lib/action_mailer/vendor/tmail-1.2.7/tmail/header.rb line 77
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in TMail::HeaderField