class Coppertone::MacroContext
A context used to evaluate MacroStrings. Responds to all of the macro letter directives except 'p'.
Constants
- RESERVED_REGEXP
- UNKNOWN_HOSTNAME
Attributes
d[R]
domain[R]
h[R]
helo_domain[R]
hostname[R]
ip_address_wrapper[R]
sender_identity[R]
Public Class Methods
new(domain, ip_as_s, sender, helo_domain = 'unknown', options = {})
click to toggle source
# File lib/coppertone/macro_context.rb, line 19 def initialize(domain, ip_as_s, sender, helo_domain = 'unknown', options = {}) @ip_address_wrapper = IPAddressWrapper.new(ip_as_s) @sender_identity = SenderIdentity.new(sender) @domain = domain || @sender_identity.domain @helo_domain = helo_domain @hostname = options[:hostname] end
Public Instance Methods
escape(string)
click to toggle source
# File lib/coppertone/macro_context.rb, line 40 def escape(string) encoding = string.encoding string.b.gsub(RESERVED_REGEXP) do |m| "%#{m.unpack('H2' * m.bytesize).join('%').upcase}" end.force_encoding(encoding) end
r()
click to toggle source
# File lib/coppertone/macro_context.rb, line 29 def r valid = Coppertone::Utils::DomainUtils.valid?(raw_hostname) valid ? raw_hostname : UNKNOWN_HOSTNAME end
raw_hostname()
click to toggle source
# File lib/coppertone/macro_context.rb, line 54 def raw_hostname @raw_hostname ||= begin hostname || Coppertone.config.hostname || Coppertone::Utils::HostUtils.hostname end end
t()
click to toggle source
# File lib/coppertone/macro_context.rb, line 34 def t Time.now.to_i end
with_domain(new_domain)
click to toggle source
Generates a new MacroContext
with all the same info, but a new domain
# File lib/coppertone/macro_context.rb, line 63 def with_domain(new_domain) options = {} options[:hostname] = hostname if hostname MacroContext.new(new_domain, c, s, h, options) end