Sha256: 773992f816405c5ac901cc94dd2dddc353dbf81ab90c818390815d55d0b7de5e

Contents?: true

Size: 1.05 KB

Versions: 85

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module PgEngine
  class EmailObserver
    def self.delivered_email(message)
      message_id = message.message_id
      mailer = message.delivery_handler.to_s
      status = get_status(message)
      if message['email_object'].present?
        email_object = message['email_object'].unparsed_value
        email_object.update_columns(message_id:, mailer:, status:)
      else
        to = [message.to].flatten.join(', ')
        from = [message.from].flatten.join(', ')
        email_object = Email.create!(message_id:, subject: message.subject, to:, mailer:, status:, from_address: from,
                                     from_name: '')
      end
      email_object.encoded_eml.attach({ io: StringIO.new(message.encoded), filename: "email-#{email_object.id}.eml" })
    rescue StandardError => e
      pg_err e
    end

    def self.get_status(_message)
      # TODO: falta implementar el interceptor y habría que dar algún detalle de por uqé se bloqueó
      # message.perform_deliveries ? :sent : :failed
      :sent
    end
  end
end

Version data entries

85 entries across 85 versions & 1 rubygems

Version Path
pg_rails-7.1.4 pg_engine/lib/pg_engine/email_observer.rb
pg_rails-7.1.3 pg_engine/lib/pg_engine/email_observer.rb
pg_rails-7.1.2 pg_engine/lib/pg_engine/email_observer.rb
pg_rails-7.1.1.pre.6 pg_engine/lib/pg_engine/email_observer.rb
pg_rails-7.1.1.pre.5 pg_engine/lib/pg_engine/email_observer.rb