module Roda::RodaPlugins::MailProcessor::RequestMethods
def _match_address(field, val, addresses)
strings (case insensitive match of any string), or regexp
can be a string (case insensitive match of the string), array of
Match if any of the given addresses match the given val, which
def _match_address(field, val, addresses) case val when String addresses.any?{|a| address_match?(a, val)} when Array overlap = [] addresses.each do |a| val.each do |v| if address_match?(a, v) overlap << a end end end unless overlap.empty? @captures.concat(overlap) end when Regexp matched = false addresses.each do |v| if md = val.match(v) matched = true @captures.concat(md.captures) end end matched else unsupported_matcher(:field=>val) end end
def _match_content(field, val, content)
strings (case sensitive substring match of any string), or regexp
can be a string (case sensitive substring match), array of
Match if the content matches the given val, which
def _match_content(field, val, content) case val when String content.include?(val) when Array val.each do |v| if content.include?(v) return @captures << v end end false when Regexp if md = val.match(content) @captures.concat(md.captures) end else unsupported_matcher(field=>val) end end
def address_match?(a1, a2)
def address_match?(a1, a2) a1.casecmp?(a2) end
def address_match?(a1, a2)
def address_match?(a1, a2) a1.downcase == a2.downcase end
def block_result_body(_)
If the routing did not explicitly mark the mail as handled
def block_result_body(_) unless env['roda.mail_handled'] scope.unhandled_mail('mail was not handled during mail_processor routing') end end
def handle(&block)
Mark the mail as having been handled, so routing will not call
def handle(&block) env['roda.mail_handled'] = true always(&block) end
def handle_header(key, value=nil)
def handle_header(key, value=nil) header(key, value) do |*args| handle do yield(*args) end end end
def header(key, value=nil, &block)
def header(key, value=nil, &block) on(:header=>[key, value], &block) end
def mail
def mail env['roda.mail'] end
def match_body(val)
def match_body(val) _match_content(:body, val, mail.body.decoded) end
def match_header((key, value))
Match against a header specified by key with the given
def match_header((key, value)) return unless content = mail.header[key] if value.nil? @captures << content.decoded else _match_content(:header, value, content.decoded) end end
def match_rcpt(address)
def match_rcpt(address) _match_address(:rcpt, address, scope.mail_recipients) end
def match_subject(val)
def match_subject(val) _match_content(:subject, val, mail.subject) end
def match_text(val)
def match_text(val) _match_content(:text, val, scope.mail_text) end