aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/admin_request_controller.rb13
-rw-r--r--app/models/info_request.rb22
-rw-r--r--app/views/admin_request/show_raw_email.rhtml18
3 files changed, 44 insertions, 9 deletions
diff --git a/app/controllers/admin_request_controller.rb b/app/controllers/admin_request_controller.rb
index d0bf9cd48..b8b9fb56a 100644
--- a/app/controllers/admin_request_controller.rb
+++ b/app/controllers/admin_request_controller.rb
@@ -4,7 +4,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: admin_request_controller.rb,v 1.38 2009-07-21 12:09:29 francis Exp $
+# $Id: admin_request_controller.rb,v 1.39 2009-09-07 16:35:05 francis Exp $
class AdminRequestController < AdminController
def index
@@ -228,12 +228,13 @@ class AdminRequestController < AdminController
def show_raw_email
@raw_email = RawEmail.find(params[:id])
- # For the holding pen, use domain of email to try and guess which public body it
- # is associated with, so we can display that.
+ # For the holding pen, try to guess where it should be ...
@holding_pen = false
if (@raw_email.incoming_message.info_request == InfoRequest.holding_pen_request && @raw_email.incoming_message.mail.from_addrs.size > 0)
@holding_pen = true
+ # 1. Use domain of email to try and guess which public body it
+ # is associated with, so we can display that.
email = @raw_email.incoming_message.mail.from_addrs[0].spec
domain = PublicBody.extract_domain_from_email(email)
@@ -243,6 +244,12 @@ class AdminRequestController < AdminController
@public_bodies = PublicBody.find(:all, :order => "name",
:conditions => [ "lower(request_email) like lower('%'||?||'%')", domain ])
end
+
+ # 2. Match the email address in the message without matching the hash
+ @info_requests = []
+ for address in (@raw_email.incoming_message.mail.to || []) + (@raw_email.incoming_message.mail.cc || [])
+ @info_requests += InfoRequest.guess_by_incoming_email(address)
+ end
end
end
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index 1969d1947..da5270c40 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -24,7 +24,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.201 2009-08-21 17:43:33 francis Exp $
+# $Id: info_request.rb,v 1.202 2009-09-07 16:35:06 francis Exp $
require 'digest/sha1'
require File.join(File.dirname(__FILE__),'../../vendor/plugins/acts_as_xapian/lib/acts_as_xapian')
@@ -246,6 +246,23 @@ 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)
+ id, hash = InfoRequest._extract_id_hash_from_email(incoming_email)
+ return self.find_by_magic_email(id, hash)
+ end
+
+ # Return list of info requests which *might* be right given email address
+ # e.g. For the id-hash email addresses, don't match the hash.
+ def InfoRequest.guess_by_incoming_email(incoming_email)
+ id, hash = InfoRequest._extract_id_hash_from_email(incoming_email)
+ begin
+ return [InfoRequest.find(id)]
+ rescue ActiveRecord::RecordNotFound
+ return []
+ end
+ end
+
+ # Internal function used by find_by_magic_email and guess_by_incoming_email
+ def InfoRequest._extract_id_hash_from_email(incoming_email)
# Match case insensitively, FOI officers often write Request with capital R.
incoming_email = incoming_email.downcase
@@ -263,9 +280,10 @@ public
hash.gsub!(/o/, "0")
end
- return self.find_by_magic_email(id, hash)
+ return [id, hash]
end
+
# When constructing a new request, use this to check user hasn't double submitted.
# XXX could have a date range here, so say only check last month's worth of new requests. If somebody is making
# repeated requests, say once a quarter for time information, then might need to do that.
diff --git a/app/views/admin_request/show_raw_email.rhtml b/app/views/admin_request/show_raw_email.rhtml
index fa2a4f9e6..10b97f4fd 100644
--- a/app/views/admin_request/show_raw_email.rhtml
+++ b/app/views/admin_request/show_raw_email.rhtml
@@ -4,10 +4,20 @@
<p>
FOI request: <%= link_to request_both_links(@raw_email.incoming_message.info_request) %>
- <% if @holding_pen && @public_bodies.size > 0 %>
- <br>Guessed authority:
- <% for public_body in @public_bodies %>
- <%=public_body_both_links(public_body)%>
+ <% if @holding_pen %>
+ <% if @public_bodies.size > 0 %>
+ <br>Guessed authority:
+ <% for public_body in @public_bodies %>
+ <%=public_body_both_links(public_body)%>
+ <% end %>
+ (based on From: email domain)
+ <% end %>
+ <% if @info_requests.size > 0 %>
+ <br>Guessed request:
+ <% for info_request in @info_requests %>
+ <%=request_both_links(info_request)%>
+ <% end %>
+ (based on id, not hash, in To/Cc email)
<% end %>
<% end %>
</p>