module Roda::RodaPlugins::MailProcessor::RequestMethods
Public Instance Methods
Source
# File lib/roda/plugins/mail_processor.rb, line 500 def handle(&block) env['roda.mail_handled'] = true always(&block) end
Mark the mail as having been handled, so routing will not call unhandled_mail implicitly.
Source
# File lib/roda/plugins/mail_processor.rb, line 485 def handle_header(key, value=nil) header(key, value) do |*args| handle do yield(*args) end end end
Same as header
, but also mark the message as being handled.
Source
# File lib/roda/plugins/mail_processor.rb, line 494 def header(key, value=nil, &block) on(:header=>[key, value], &block) end
Match based on a mail header value.
Private Instance Methods
Source
# File lib/roda/plugins/mail_processor.rb, line 524 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
Match if any of the given addresses match the given val, which can be a string (case insensitive match of the string), array of strings (case insensitive match of any string), or regexp (normal regexp match).
Source
# File lib/roda/plugins/mail_processor.rb, line 559 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
Match if the content matches the given val, which can be a string (case sensitive substring match), array of strings (case sensitive substring match of any string), or regexp (normal regexp match).
Source
# File lib/roda/plugins/mail_processor.rb, line 509 def address_match?(a1, a2) a1.casecmp?(a2) end
Whether the addresses are the same (case insensitive match).
Source
# File lib/roda/plugins/mail_processor.rb, line 618 def block_result_body(_) unless env['roda.mail_handled'] scope.unhandled_mail('mail was not handled during mail_processor routing') end end
If the routing did not explicitly mark the mail as handled mark it as unhandled.
Source
# File lib/roda/plugins/mail_processor.rb, line 612 def mail env['roda.mail'] end
The mail instance being processed.
Source
# File lib/roda/plugins/mail_processor.rb, line 580 def match_body(val) _match_content(:body, val, mail.body.decoded) end
Match the value against the full mail body.
Source
# File lib/roda/plugins/mail_processor.rb, line 601 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
Match against a header specified by key with the given value (which may be nil).
Source
# File lib/roda/plugins/mail_processor.rb, line 590 def match_rcpt(address) _match_address(:rcpt, address, scope.mail_recipients) end
Match the given address against all recipients in the mail.
Source
# File lib/roda/plugins/mail_processor.rb, line 585 def match_subject(val) _match_content(:subject, val, mail.subject) end
Match the value against the mail subject.
Source
# File lib/roda/plugins/mail_processor.rb, line 595 def match_text(val) _match_content(:text, val, scope.mail_text) end
Match the value against the extracted mail text.