diff options
author | Louise Crow <louise.crow@gmail.com> | 2014-12-18 15:42:53 +0000 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2014-12-18 15:42:53 +0000 |
commit | bbdcb09cb9eeb94e3244a22b1129a1e9521947f4 (patch) | |
tree | 4ad15f4138796087c32957261e8b9e7b6f59887b /app/controllers/admin_raw_email_controller.rb | |
parent | 5cfcdaac505e60914ee4398cfe431bd5d21b58ed (diff) | |
parent | abdc92fd922dd82da85f7c00bdb50e85ed047714 (diff) |
Merge branch 'restful-admin-routes' into rails-3-develop
Diffstat (limited to 'app/controllers/admin_raw_email_controller.rb')
-rw-r--r-- | app/controllers/admin_raw_email_controller.rb | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/app/controllers/admin_raw_email_controller.rb b/app/controllers/admin_raw_email_controller.rb new file mode 100644 index 000000000..1b3ee2871 --- /dev/null +++ b/app/controllers/admin_raw_email_controller.rb @@ -0,0 +1,45 @@ +# app/controllers/admin_raw_email_controller.rb: +# Controller for managing raw emails from the admin interface. +# +# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. +# Email: hello@mysociety.org; WWW: http://www.mysociety.org/ + +class AdminRawEmailController < AdminController + + def show + @raw_email = RawEmail.find(params[:id]) + respond_to do |format| + format.html do + # 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.empty_from_field?) + @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.from_email + domain = PublicBody.extract_domain_from_email(email) + + if domain.nil? + @public_bodies = [] + else + @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 = InfoRequest.guess_by_incoming_email(@raw_email.incoming_message) + + # 3. Give a reason why it's in the holding pen + last_event = InfoRequestEvent.find_by_incoming_message_id(@raw_email.incoming_message.id) + @rejected_reason = last_event.params[:rejected_reason] || "unknown reason" + end + end + format.text do + response.content_type = 'message/rfc822' + render :text => @raw_email.data + end + end + end + +end |