lib/autoheathen/email_processor.rb
# Processes the given email, submits attachments to the Heathen server, delivers responses as configured
# @param email [String] The encoded email (suitable to be decoded using Mail.read(input))
# @return [Hash] a hash of the decoded attachments (or the reason why they could not be decoded)
Processes the given email, submits attachments to the Heathen server, delivers responses as configured
Processes the given email submits attachments to the Heathen server delivers responses as configured
def process email, mail_to, is_rts=false
      documents = []
      unless email.has_attachments?
        logger.info "From: {email.from} Subject: ({email.subject}) Files: no attachments"
        return
      end
      logger.info "From: {email.from} Subject: ({email.subject}) Files: {email.attachments.map(&:filename).join(',')}"
       Convert the attachments
      email.attachments.each do |attachment|
        begin
          converter = Heathen::Converter.new( logger: logger )
          language = @cfg[:language]
          input_source = attachment.body.decoded
          action = get_action input_source.content_type
          logger.info "    convert {attachment.filename} using action: {action}"
          data = converter.convert action, input_source, language
          converted_filename = Heathen::Filename.suggest attachment.filename, data.mime_type
          documents << { orig_filename: attachment.filename, orig_content: input_source, filename: converted_filename, content: data, error: false }
        rescue StandardError => e
          documents << { orig_filename: attachment.filename, orig_content: input_source, filename: nil, content: nil, error: e.message }
        end
      end
       deliver the results
      if is_rts
        deliver_rts email, documents, mail_to
      else
        deliver_onward email, documents, mail_to
      end
       Summarise the processing
      logger.info "Results of conversion"
      documents.each do |doc|
        if doc[:content].nil?
          logger.info "  {doc[:orig_filename]} was not converted ({doc[:error]}) "
        else
          logger.info "  {doc[:orig_filename]} was converted successfully"
        end
      end
      documents
    end
def process email , mail_to , is_rts = false documents = [ ] unless email . has_attachments? logger . info "From: #{email.from} Subject: (#{email.subject}) Files: no attachments" return end logger . info "From: #{email.from} Subject: (#{email.subject}) Files: #{email.attachments.map(&:filename).join(',')}" email . attachments . each do | attachment | begin converter = Heathen :: Converter . new ( logger : logger ) language = @cfg [ :language ] input_source = attachment . body . decoded action = get_action input_source . content_type logger . info "    convert #{attachment.filename} using action: #{action}" data = converter . convert action , input_source , language converted_filename = Heathen :: Filename . suggest attachment . filename , data . mime_type documents << { orig_filename : attachment . filename , orig_content : input_source , filename : converted_filename , content : data , error : false } rescue StandardError => e documents << { orig_filename : attachment . filename , orig_content : input_source , filename : nil , content : nil , error : e . message } end end if is_rts deliver_rts email , documents , mail_to else deliver_onward email , documents , mail_to end logger . info "Results of conversion" documents . each do | doc | if doc [ :content ] . nil? logger . info "  #{doc[:orig_filename]} was not converted (#{doc[:error]}) " else logger . info "  #{doc[:orig_filename]} was converted successfully" end end documents end
Processes the given email, submits attachments to the Heathen server, delivers responses as configured
Processes the given email submits attachments to the Heathen server delivers responses as configured
# # Convert the attachments # # # deliver the results # # # Summarise the processing #
a hash of the decoded attachments (or the reason why they could not be decoded)
a hash of the decoded attachments ( or the reason why they could not be decoded )
Hash
email
The encoded email (suitable to be decoded using Mail.read(input))
The encoded email ( suitable to be decoded using Mail . read ( input ))
mail_to
<not_specific>
is_rts
<not_specific>