3.16.0.txt

doc/release_notes/3.16.0.txt
Last Update: 2019-01-18 09:03:43 -0800

New Features

  • A mail_processor plugin has been added for processing mail using a routing tree. Quick example:

    class MailProcessor < Roda
      plugin :mail_processor
    
      route do |r|
        # Match based on the To header, extracting the ticket_id
        r.to /ticket\+(\d+)@example.com/ do |ticket_id|
          if ticket = Ticket[ticket_id.to_i]
            # Mark the mail as handled if there is a valid ticket
            # associated
            r.handle do
              ticket.add_note(text: mail_text, from: from)
            end
          end
        end
      end
    end
    

    You can submit mail for processing by calling the process_mail method with a Mail instance:

    MailProcessor.process_mail(Mail.read('/path/to/message.eml'))
    

    The mail_processor routing tree uses routing methods specific to mail:

    r.from

    match on the mail From address

    r.to

    match on the mail To address

    r.cc

    match on the mail CC address

    r.rcpt

    match on the mail recipients (To and CC addresses by default)

    r.subject

    match on the mail subject

    r.body

    match on the mail body

    r.text

    match on text extracted from the message (same as mail body by default)

    r.header

    match on a mail header

    To mark a mail as having been handled, you call the r.handle method with a block, or one of the above methods prefixed by handle_ (e.g. r.handle_text).

    The mail_processor plugin supports hooks that are called for handled mail, unhandled mail, and all mail (for archiving). It also supports the ability to configure how reply text is parsed out of mail, who to consider as the recipients of the email, and the ability to have separate routing blocks per recipient email address (with O(1) delegation to the appropriate block if the recipient addresses to match is a string).