#---
# Excerpted from "Rails Recipes"
# We make no guarantees that this code is fit for any purpose. 
# Visit http://www.pragmaticprogrammer.com/titles/fr_rr for more book information.
#---
class Receiver < ActionMailer::Base
  def receive(email)
    rating = 0
    if(email.subject + email.body =~ /opportunity/i) 
      rating += 1
    end
    if email.has_attachments?
      email.attachments.each do |attachment|
        rating += 1 if attachment.original_filename =~ /zip$/i
      end
    end
    Mail.create(:subject => email.subject, :body    => email.body,
                :sender  => email.from,    :rating  => rating)
  end
end
