Created
June 18, 2012 21:24
-
-
Save Shpigford/2950817 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def receive_email | |
from = find_email(params["from"]).downcase | |
tracking_number = Tracking::Extractor.extract(params["text"]) | |
if tracking_number.blank? | |
PostOffice.email_tracking_failure(from, "We could not find a valid tracking number in your email.").deliver | |
else | |
tracking_number.each do |tracking| | |
user = User.first(:conditions => ["email_forwards LIKE ?", "%#{from}%"]) | |
user = User.find_by_email(from) unless user | |
if user | |
@number = Number.where(:tracking => tracking).first | |
if @number.blank? | |
@number = Number.new(:tracking => tracking) | |
@number.user_id = user.id | |
@number.notes = params["subject"] | |
@number.track | |
end | |
else | |
PostOffice.email_tracking_failure(from, "Could not find a user with the email #{from}") | |
end | |
end | |
end | |
respond_to do |format| | |
format.xml | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment