aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/request_mailer.rb14
-rw-r--r--app/models/user_mailer.rb4
-rw-r--r--app/views/request_mailer/bounced_message.rhtml4
-rw-r--r--config/environment.rb3
-rw-r--r--config/general-example7
-rw-r--r--spec/fixtures/incoming-request-plain.email2
-rw-r--r--spec/models/request_mailer_spec.rb11
7 files changed, 38 insertions, 7 deletions
diff --git a/app/models/request_mailer.rb b/app/models/request_mailer.rb
index 758034994..4b691150d 100644
--- a/app/models/request_mailer.rb
+++ b/app/models/request_mailer.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: request_mailer.rb,v 1.5 2007-10-30 14:23:21 francis Exp $
+# $Id: request_mailer.rb,v 1.6 2007-11-13 12:02:14 francis Exp $
class RequestMailer < ActionMailer::Base
@@ -19,6 +19,13 @@ class RequestMailer < ActionMailer::Base
@body = {:info_request => info_request, :outgoing_message => outgoing_message}
end
+ def bounced_message(email)
+ @from = MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost')
+ @recipients = @from
+ @subject = "Incoming email to unknown FOI request"
+ email.setup_forward(self)
+ end
+
# Copy of function from action_mailer/base.rb, which passes the
# raw_email to the member function, as we want to record it.
# script/mailin calls this function.
@@ -38,6 +45,11 @@ class RequestMailer < ActionMailer::Base
info_requests.push(info_request) if info_request
end
+ # Nothing found
+ if info_requests.size == 0
+ RequestMailer.deliver_bounced_message(email)
+ end
+
# Send the message to each request
for info_request in info_requests
info_request.receive(email, raw_email)
diff --git a/app/models/user_mailer.rb b/app/models/user_mailer.rb
index a7e59f36a..d3638c38b 100644
--- a/app/models/user_mailer.rb
+++ b/app/models/user_mailer.rb
@@ -4,12 +4,12 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: user_mailer.rb,v 1.1 2007-11-05 16:46:10 francis Exp $
+# $Id: user_mailer.rb,v 1.2 2007-11-13 12:02:14 francis Exp $
class UserMailer < ActionMailer::Base
def confirm_login(user, reasons, url)
- @from = MySociety::Config.get("CONTACT_EMAIL")
+ @from = MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost')
@recipients = user.email
@subject = reasons[:email_subject]
@body[:reasons] = reasons
diff --git a/app/views/request_mailer/bounced_message.rhtml b/app/views/request_mailer/bounced_message.rhtml
new file mode 100644
index 000000000..8c42bd1b5
--- /dev/null
+++ b/app/views/request_mailer/bounced_message.rhtml
@@ -0,0 +1,4 @@
+An incoming email arrived which was not to a known FOI request. Find the
+message attached.
+
+This message was sent by mysociety/foi/models/request_mailer.rb.
diff --git a/config/environment.rb b/config/environment.rb
index 14bf2658e..548db1b72 100644
--- a/config/environment.rb
+++ b/config/environment.rb
@@ -11,7 +11,8 @@ RAILS_GEM_VERSION = '1.2.1' unless defined? RAILS_GEM_VERSION
require File.join(File.dirname(__FILE__), 'boot')
# MySociety specific helper functions
-$:.push("../rblib")
+$:.push(File.join(File.dirname(__FILE__), '../../rblib'))
+
load "validate.rb"
load "config.rb"
diff --git a/config/general-example b/config/general-example
index 6e8f3e0bb..6b860cd8d 100644
--- a/config/general-example
+++ b/config/general-example
@@ -10,11 +10,16 @@
*
* Copy this file to one called "general" in the same directory. Or
* have multiple config files and use a symlink to change between them.
+ *
+ * NOTE ON USE IN RAILS: So that people don't have to have PHP installed just
+ * to run this stuff, by convention we always provide a default config value
+ * in the source code when reading the config option. The Rails application
+ * should run fine without the general config file, it is a bug if it does not.
*
* Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
* Email: francis@mysociety.org; WWW: http://www.mysociety.org
*
- * $Id: general-example,v 1.3 2007-11-05 16:46:11 francis Exp $
+ * $Id: general-example,v 1.4 2007-11-13 12:02:16 francis Exp $
*
*/
diff --git a/spec/fixtures/incoming-request-plain.email b/spec/fixtures/incoming-request-plain.email
index 9072b32cc..ce1c7caa7 100644
--- a/spec/fixtures/incoming-request-plain.email
+++ b/spec/fixtures/incoming-request-plain.email
@@ -9,7 +9,7 @@ No way! That's so totally a rubbish question. No way am I answering that.
The Geraldine Quango
-On Wed, Oct 24, 2007 at 11:30:06AM +0100, francis@flourish.org wrote:
+On Wed, Oct 24, 2007 at 11:30:06AM +0100, Francis wrote:
> Please let me know why Francis isn't getting ready to leave the house
> to go to the UN talk.
>
diff --git a/spec/models/request_mailer_spec.rb b/spec/models/request_mailer_spec.rb
index 030395a2d..8bac9e5da 100644
--- a/spec/models/request_mailer_spec.rb
+++ b/spec/models/request_mailer_spec.rb
@@ -13,7 +13,16 @@ describe RequestMailer, " when receiving incoming mail" do
ir.incoming_messages.size.should == 1
end
- it "should XXX when the email is not to any information request"
+ it "should bounce email to admin when the email is not to any information request" do
+ ir = info_requests(:fancy_dog_request)
+ receive_incoming_mail('incoming-request-plain.email', 'dummy@localhost')
+ ir.incoming_messages.size.should == 0
+
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 1
+ mail = deliveries[0]
+ mail.to.should == [ MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost') ]
+ end
end