Class: Astrotrain::LoggedMail

Inherits:
Object
  • Object
show all
Includes:
DataMapper::Resource
Defined in:
lib/astrotrain/logged_mail.rb

Overview

Logs details of each incoming message.

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.log_pathObject

Returns the value of attribute log_path.



7
8
9
# File 'lib/astrotrain/logged_mail.rb', line 7

def log_path
  @log_path
end

.log_processedObject

Returns the value of attribute log_processed.



7
8
9
# File 'lib/astrotrain/logged_mail.rb', line 7

def log_processed
  @log_processed
end

Class Method Details

.from(message, file = nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/astrotrain/logged_mail.rb', line 27

def self.from(message, file = nil)
  logged = new
  begin
    logged.message_id = message.message_id
    logged.sender     = Message.parse_email_addresses(message.sender).first
    logged.subject    = message.subject
    logged.mail_file  = file if file
  end
  if !block_given? || yield(logged)
    begin
      logged.save
      if logged.delivered_at && File.exist?(logged.mail_file.to_s)
        FileUtils.rm_rf logged.mail_file
      end
    rescue
      puts $!.inspect
    end
  end
  logged
end