Class: ChocolateRain::MailHandler

Inherits:
ActionMailer::Base
  • Object
show all
Defined in:
lib/chocolate_rain/mail_handler.rb

Instance Method Summary collapse

Instance Method Details

#receive(email) ⇒ Object



13
14
15
# File 'lib/chocolate_rain/mail_handler.rb', line 13

def receive(email)
  resend_multipart(email)
end

#resend(sender, recipient, subject, body) ⇒ Object



6
7
8
9
10
11
# File 'lib/chocolate_rain/mail_handler.rb', line 6

def resend(sender, recipient, subject, body)
  mail(:from => sender,
       :to => recipient,
       :subject => subject,
       :body => body)
end

#resend_multipart(email) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/chocolate_rain/mail_handler.rb', line 17

def resend_multipart(email)
  email.attachments.each do |att|
    fn = att.filename
    v = ChocolateRain::YVideo.new()
    begin
      f = StringIO.new(att.body.decoded)
      v.filename = fn 
      v.file_object = f 
      v.title = fn
      begin 
        v.save
      rescue Exception => e
        puts "Exception: #{e.message}"
      end
    rescue Exception => e
      puts "Exception: #{e.message}"
    end

    begin
      resent = resend("[email protected]", "[email protected]", "[CAIN] Successful Upload", "A new testimonial video has been uploaded via email to s3.  Its url is http://s3.amazonaws.com/whyHermanCain/#{v.filename}")
      resent.deliver
    rescue
      return
    end
  end
end