module Roda::RodaPlugins::MailProcessor::ClassMethods
Public Instance Methods
Source
# File lib/roda/plugins/mail_processor.rb, line 289 def freeze if string_routes = opts[:mail_processor_string_routes].freeze string_routes.freeze opts[:mail_processor_regexp_routes].freeze end super end
Freeze the rcpt routes if they are present.
Source
# File lib/roda/plugins/mail_processor.rb, line 299 def process_mail(mail) scope = new("PATH_INFO"=>'', 'SCRIPT_NAME'=>'', "REQUEST_METHOD"=>"PROCESSMAIL", 'rack.input'=>StringIO.new, 'roda.mail'=>mail) begin begin scope.process_mail rescue UnhandledMail scope.unhandled_mail_hook else scope.handled_mail_hook end ensure scope.after_mail_hook end end
Process the given Mail instance, calling the appropriate hooks depending on whether the mail was handled during processing.
Source
# File lib/roda/plugins/mail_processor.rb, line 321 def process_mailbox(opts=OPTS) (opts[:retriever] || Mail).find_and_delete(opts.dup){|m| process_mail(m)} nil end
Process all mail in the given mailbox. If the :retriever
option is given, should be an object supporting the Mail retriever API, otherwise uses the default Mail retriever_method. This deletes retrieved mail from the mailbox after processing, so that when called multiple times it does not reprocess the same mail. If mail should be archived and not deleted, the after_mail
method should be used to perform the archiving of the mail.
Source
# File lib/roda/plugins/mail_processor.rb, line 329 def rcpt(*addresses, &block) opts[:mail_processor_string_routes] ||= {} opts[:mail_processor_regexp_routes] ||= {} string_meth = nil regexp_meth = nil addresses.each do |address| case address when String unless string_meth string_meth = define_roda_method("mail_processor_string_route_#{address}", 1, &convert_route_block(block)) end opts[:mail_processor_string_routes][address] = string_meth when Regexp unless regexp_meth regexp_meth = define_roda_method("mail_processor_regexp_route_#{address}", :any, &convert_route_block(block)) end opts[:mail_processor_regexp_routes][address] = regexp_meth else raise RodaError, "invalid address format passed to rcpt, should be Array or String" end end nil end
Setup a routing tree for the given recipient addresses, which can be strings or regexps. Any messages matching the given recipient address will use these routing trees instead of the normal routing tree.