diff options
-rw-r--r-- | app/models/info_request.rb | 11 | ||||
-rw-r--r-- | spec/models/info_request_spec.rb | 22 |
2 files changed, 30 insertions, 3 deletions
diff --git a/app/models/info_request.rb b/app/models/info_request.rb index f80876813..33fc87357 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -22,7 +22,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: info_request.rb,v 1.116 2008-06-11 00:05:44 francis Exp $ +# $Id: info_request.rb,v 1.117 2008-06-11 15:00:35 francis Exp $ require 'digest/sha1' require File.join(File.dirname(__FILE__),'../../vendor/plugins/acts_as_xapian/lib/acts_as_xapian') @@ -188,7 +188,7 @@ public # the prefix and domain, as sometimes those change, or might be elided by # copying an email, and that doesn't matter) def InfoRequest.find_by_incoming_email(incoming_email) - # Match case insensitively + # Match case insensitively, FOI officers often write Request with capital R. incoming_email = incoming_email.downcase # The optional bounce- dates from when we used to have separate emails for the envelope from. @@ -198,6 +198,13 @@ public id = $1.to_i hash = $2 + if not hash.nil? + # Convert l to 1, and o to 0. FOI officers quite often retype the + # email address and make this kind of error. + hash.gsub!(/l/, "1") + hash.gsub!(/o/, "0") + end + return self.find_by_magic_email(id, hash) end diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb index 8c968ef3b..0c76c3176 100644 --- a/spec/models/info_request_spec.rb +++ b/spec/models/info_request_spec.rb @@ -1,7 +1,7 @@ require File.dirname(__FILE__) + '/../spec_helper' describe InfoRequest, " when emailing" do - fixtures :info_requests + fixtures :info_requests, :public_bodies, :users before do @info_request = info_requests(:fancy_dog_request) @@ -23,6 +23,26 @@ describe InfoRequest, " when emailing" do found_info_request.should == (@info_request) end + it "should recognise l and 1 as the same in incoming emails" do + # Make info request with a 1 in it + while true + ir = InfoRequest.new(:title => "testing", :public_body => public_bodies(:geraldine_public_body), + :user => users(:bob_smith_user)) + ir.save! + hash_part = ir.incoming_email.match(/-[0-9a-f]+@/)[0] + break if hash_part.match(/1/) + end + + # Make email with a 1 in the hash part changed to l + test_email = ir.incoming_email + new_hash_part = hash_part.gsub(/1/, "l") + test_email.gsub!(hash_part, new_hash_part) + + # Try and find with an l + found_info_request = InfoRequest.find_by_incoming_email(test_email) + found_info_request.should == (ir) + end + it "should recognise old style request-bounce- addresses" do incoming_email = @info_request.magic_email("request-bounce-") found_info_request = InfoRequest.find_by_incoming_email(incoming_email) |