Public Instance methods
Freeze the rcpt routes if they are present.
# File lib/roda/plugins/mail_processor.rb 289 def freeze 290 if string_routes = opts[:mail_processor_string_routes].freeze 291 string_routes.freeze 292 opts[:mail_processor_regexp_routes].freeze 293 end 294 super 295 end
Process the given Mail instance, calling the appropriate hooks depending on whether the mail was handled during processing.
# File lib/roda/plugins/mail_processor.rb 299 def process_mail(mail) 300 scope = new("PATH_INFO"=>'', 'SCRIPT_NAME'=>'', "REQUEST_METHOD"=>"PROCESSMAIL", 'rack.input'=>StringIO.new, 'roda.mail'=>mail) 301 302 begin 303 begin 304 scope.process_mail 305 rescue UnhandledMail 306 scope.unhandled_mail_hook 307 else 308 scope.handled_mail_hook 309 end 310 ensure 311 scope.after_mail_hook 312 end 313 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.
# File lib/roda/plugins/mail_processor.rb 321 def process_mailbox(opts=OPTS) 322 (opts[:retriever] || Mail).find_and_delete(opts.dup){|m| process_mail(m)} 323 nil 324 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.
# File lib/roda/plugins/mail_processor.rb 329 def rcpt(*addresses, &block) 330 opts[:mail_processor_string_routes] ||= {} 331 opts[:mail_processor_regexp_routes] ||= {} 332 string_meth = nil 333 regexp_meth = nil 334 addresses.each do |address| 335 case address 336 when String 337 unless string_meth 338 string_meth = define_roda_method("mail_processor_string_route_#{address}", 1, &convert_route_block(block)) 339 end 340 opts[:mail_processor_string_routes][address] = string_meth 341 when Regexp 342 unless regexp_meth 343 regexp_meth = define_roda_method("mail_processor_regexp_route_#{address}", :any, &convert_route_block(block)) 344 end 345 opts[:mail_processor_regexp_routes][address] = regexp_meth 346 else 347 raise RodaError, "invalid address format passed to rcpt, should be Array or String" 348 end 349 end 350 nil 351 end