Class: DeadLetterOffice::DeadLetter

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/dead_letter_office/dead_letter.rb

Class Method Summary collapse

Class Method Details

.format_recipient(recipient) ⇒ Object



31
32
33
# File 'app/models/dead_letter_office/dead_letter.rb', line 31

def self.format_recipient(recipient)
  Array.wrap(recipient).join(",")
end

.recover_parcel(parcel) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/dead_letter_office/dead_letter.rb', line 7

def self.recover_parcel(parcel)
  payload = parcel.dup
  ex_name, ex_message = *payload.delete(:exception)

  to   = format_recipient(payload.delete(:to))
  cc   = format_recipient(payload.delete(:cc))
  bcc  = format_recipient(payload.delete(:bcc))
  from = format_recipient(payload.delete(:from))
  mail = ::Mail.new(payload.delete(:mail)).body.decoded
  date = payload.delete(:date) || Time.zone.now

  new(payload) do |dead_letter|
    dead_letter.to = to
    dead_letter.cc = cc
    dead_letter.bcc = bcc
    dead_letter.from = from
    dead_letter.mail = mail
    dead_letter.date = date
    dead_letter.exception_name = ex_name
    dead_letter.exception_message = ex_message
    dead_letter.save
  end
end