Skip to content

Instantly share code, notes, and snippets.

@Shpigford
Created June 18, 2012 21:24
Show Gist options
  • Save Shpigford/2950817 to your computer and use it in GitHub Desktop.
Save Shpigford/2950817 to your computer and use it in GitHub Desktop.
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