Class: EmailManager::ManagedEmailObserver

Inherits:
Object
  • Object
show all
Defined in:
lib/email_manager/managed_email_observer.rb

Class Method Summary collapse

Class Method Details

.delivered_email(mail) ⇒ Object

stores the mail as a ManagedEmail object

Parameters:

  • mail (Mail)

    The mail object that was just delivered



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/email_manager/managed_email_observer.rb', line 7

def self.delivered_email(mail)
  # assume the caller is in the app folder somewhere

  attributes = {}
  %w{from reply_to to cc bcc}.each do |attribute|
    attributes[attribute.to_sym] = mail.send(attribute.to_sym).nil? ? "" : mail.send(attribute.to_sym).join(", ")
  end
  %w{message_id subject body headers}.each do |attribute|
    attributes[attribute.to_sym] = mail.send(attribute.to_sym).to_s
  end
  attributes[:date_sent] = mail.date
  calling_files = caller(0).select{ |val| val.match(Rails.root.join('app').to_s) }
  attributes[:caller] = calling_files.join("\n")


  # create the managed email record
  EmailManager::ManagedEmail.create(attributes)
end