Module: Roda::RodaPlugins::MailProcessor::InstanceMethods

Defined in:
lib/roda/plugins/mail_processor.rb

Instance Method Summary collapse

Instance Method Details

#after_mail_hookObject

Hook called after processing any mail, whether the mail was handled or not. Does nothing by default.



412
413
414
# File 'lib/roda/plugins/mail_processor.rb', line 412

def after_mail_hook
  nil
end

#handled_mail_hookObject

Hook called after processing a mail, when the mail was handled. Does nothing by default.



418
419
420
# File 'lib/roda/plugins/mail_processor.rb', line 418

def handled_mail_hook
  nil
end

#mailObject

The mail instance being processed.



430
431
432
# File 'lib/roda/plugins/mail_processor.rb', line 430

def mail
  env['roda.mail']
end

#mail_recipientsObject

The recipients of the mail instance being processed, uses the To and CC headers by default.



442
443
444
# File 'lib/roda/plugins/mail_processor.rb', line 442

def mail_recipients
  Array(to) + Array(cc)
end

#mail_textObject

The text of the mail instance being processed, uses the decoded body of the mail by default.



436
437
438
# File 'lib/roda/plugins/mail_processor.rb', line 436

def mail_text
  mail.body.decoded
end

#process_mail(&block) ⇒ Object

Perform the processing of mail for this request, first considering routes defined via the class-level rcpt method, and then the normal routing tree passed in as the block.



384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
# File 'lib/roda/plugins/mail_processor.rb', line 384

def process_mail(&block)
  if string_routes = opts[:mail_processor_string_routes]
    addresses = mail_recipients

    addresses.each do |address|
      if meth = string_routes[address.to_s.downcase]
        _roda_handle_route{send(meth, @_request)}
        return
      end
    end

    opts[:mail_processor_regexp_routes].each do |regexp, meth|
      addresses.each do |address|
        if md = regexp.match(address)
          _roda_handle_route{send(meth, @_request, *md.captures)}
          return 
        end
      end
    end
  end

  _roda_handle_main_route

  nil
end

#unhandled_mail(reason) ⇒ Object

Raise an UnhandledMail exception with the given reason, used to mark the mail as not handled. A reason why the mail was not handled must be provided, which will be used as the exception message.

Raises:



449
450
451
# File 'lib/roda/plugins/mail_processor.rb', line 449

def unhandled_mail(reason)
  raise UnhandledMail, reason
end

#unhandled_mail_hookObject

Hook called after processing a mail, when the mail was not handled. Reraises the UnhandledMail exception raised during mail processing by default.



425
426
427
# File 'lib/roda/plugins/mail_processor.rb', line 425

def unhandled_mail_hook
  raise
end