2008-06-04 18:16:06 -07:00
|
|
|
class SMSGateway < ActionMailer::Base
|
|
|
|
|
CONTEXT_NAME = 'Inbox'
|
|
|
|
|
def receive(email)
|
|
|
|
|
user = User.find(:first, :include => [:preference], :conditions => ["preferences.sms_email = ?", email.from[0].strip])
|
2008-06-07 17:15:12 -07:00
|
|
|
logger.info "Receiving SMS task from #{email.from[0].strip} For user #{user.nil? nil : user.login}"
|
|
|
|
|
return if user.nil?
|
2008-06-04 18:16:06 -07:00
|
|
|
context = user.prefs.sms_context
|
|
|
|
|
|
|
|
|
|
description = nil
|
|
|
|
|
notes = nil
|
|
|
|
|
|
|
|
|
|
if email.content_type == "multipart/related"
|
|
|
|
|
description = email.subject
|
|
|
|
|
body_part = email.parts.find{|m| m.content_type == "text/plain"}
|
|
|
|
|
notes = body_part.body.strip
|
|
|
|
|
else
|
|
|
|
|
if email.subject.empty?
|
|
|
|
|
description = email.body.strip
|
|
|
|
|
notes = nil
|
|
|
|
|
else
|
|
|
|
|
description = email.subject.strip
|
|
|
|
|
notes = email.body.strip
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
unless user.todos.find(:first, :conditions => {:description => description})
|
|
|
|
|
# stupid T-Mobile often sends the same message multiple times
|
|
|
|
|
todo = user.todos.create(:context => context, :description => description, :notes => notes)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|