module Roda::RodaPlugins::MailProcessor::ClassMethods

  1. lib/roda/plugins/mail_processor.rb

Methods

Public Instance

  1. freeze
  2. process_mail
  3. process_mailbox
  4. rcpt

Public Instance methods

freeze()

Freeze the rcpt routes if they are present.

[show source]
    # File lib/roda/plugins/mail_processor.rb
292 def freeze
293   if string_routes = mail_processor_string_routes.freeze
294     string_routes.freeze
295     mail_processor_regexp_routes.freeze
296   end
297   super
298 end
process_mail(mail)

Process the given Mail instance, calling the appropriate hooks depending on whether the mail was handled during processing.

[show source]
    # File lib/roda/plugins/mail_processor.rb
302 def process_mail(mail)
303   scope = new("PATH_INFO"=>'', 'SCRIPT_NAME'=>'', "REQUEST_METHOD"=>"PROCESSMAIL", 'rack.input'=>StringIO.new, 'roda.mail'=>mail)
304 
305   begin
306     begin
307       scope.process_mail
308     rescue UnhandledMail
309       scope.unhandled_mail_hook
310     else
311       scope.handled_mail_hook
312     end
313   ensure
314     scope.after_mail_hook
315   end
316 end
process_mailbox(opts=OPTS)

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.

[show source]
    # File lib/roda/plugins/mail_processor.rb
324 def process_mailbox(opts=OPTS)
325   (opts[:retriever] || Mail).find_and_delete(opts.dup){|m| process_mail(m)}
326   nil
327 end
rcpt(*addresses, &block)

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.

[show source]
    # File lib/roda/plugins/mail_processor.rb
332 def rcpt(*addresses, &block)
333   opts[:mail_processor_string_routes] ||= {}
334   opts[:mail_processor_regexp_routes] ||= {}
335   string_meth = nil
336   regexp_meth = nil
337   addresses.each do |address|
338     case address
339     when String
340       unless string_meth
341         string_meth = define_roda_method("mail_processor_string_route_#{address}", 1, &convert_route_block(block))
342       end
343       mail_processor_string_routes[address] = string_meth 
344     when Regexp
345       unless regexp_meth
346         regexp_meth = define_roda_method("mail_processor_regexp_route_#{address}", :any, &convert_route_block(block))
347       end
348       mail_processor_regexp_routes[address] = regexp_meth
349     else
350       raise RodaError, "invalid address format passed to rcpt, should be Array or String"
351     end
352   end
353   nil
354 end