Sha256: 773992f816405c5ac901cc94dd2dddc353dbf81ab90c818390815d55d0b7de5e

Contents?: true

Size: 1.05 KB

Versions: 77

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

77 entries across 77 versions & 1 rubygems

Version Path
pg_rails-7.6.23 pg_engine/lib/pg_engine/email_observer.rb
pg_rails-7.6.22 pg_engine/lib/pg_engine/email_observer.rb
pg_rails-7.6.22.pre.3 pg_engine/lib/pg_engine/email_observer.rb
pg_rails-7.6.22.pre.2 pg_engine/lib/pg_engine/email_observer.rb
pg_rails-7.6.22.pre.1 pg_engine/lib/pg_engine/email_observer.rb
pg_rails-7.6.21 pg_engine/lib/pg_engine/email_observer.rb
pg_rails-7.6.21.pre.11 pg_engine/lib/pg_engine/email_observer.rb
pg_rails-7.6.21.pre.10 pg_engine/lib/pg_engine/email_observer.rb
pg_rails-7.6.21.pre.9 pg_engine/lib/pg_engine/email_observer.rb
pg_rails-7.6.21.pre.8 pg_engine/lib/pg_engine/email_observer.rb
pg_rails-7.6.21.pre.7 pg_engine/lib/pg_engine/email_observer.rb
pg_rails-7.6.21.pre.6 pg_engine/lib/pg_engine/email_observer.rb
pg_rails-7.6.21.pre.5 pg_engine/lib/pg_engine/email_observer.rb
pg_rails-7.6.21.pre.4 pg_engine/lib/pg_engine/email_observer.rb
pg_rails-7.6.21.pre.3 pg_engine/lib/pg_engine/email_observer.rb
pg_rails-7.6.21.pre.2 pg_engine/lib/pg_engine/email_observer.rb
pg_rails-7.6.21.pre.1 pg_engine/lib/pg_engine/email_observer.rb
pg_rails-7.6.20 pg_engine/lib/pg_engine/email_observer.rb
pg_rails-7.6.19 pg_engine/lib/pg_engine/email_observer.rb
pg_rails-7.6.18 pg_engine/lib/pg_engine/email_observer.rb