aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/mailers/request_mailer.rb3
-rw-r--r--app/models/info_request.rb11
-rw-r--r--config/initializers/alaveteli.rb2
-rw-r--r--spec/mailers/request_mailer_spec.rb24
4 files changed, 36 insertions, 4 deletions
diff --git a/app/mailers/request_mailer.rb b/app/mailers/request_mailer.rb
index c9decc6db..252df861c 100644
--- a/app/mailers/request_mailer.rb
+++ b/app/mailers/request_mailer.rb
@@ -234,8 +234,9 @@ class RequestMailer < ApplicationMailer
def requests_matching_email(email)
# We deliberately don't use Envelope-to here, so ones that are BCC
# drop into the holding pen for checking.
+ addresses = ((email.to || []) + (email.cc || [])).compact
reply_info_requests = [] # TODO: should be set?
- for address in (email.to || []) + (email.cc || [])
+ addresses.each do |address|
reply_info_request = InfoRequest.find_by_incoming_email(address)
reply_info_requests.push(reply_info_request) if reply_info_request
end
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index 245de1e15..c203f75c3 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -427,6 +427,7 @@ public
# A new incoming email to this request
def receive(email, raw_email_data, override_stop_new_responses = false, rejected_reason = "")
+ # Is this request allowing responses?
if !override_stop_new_responses
allow = nil
reason = nil
@@ -457,9 +458,15 @@ public
raise "Unknown allow_new_responses_from '" + self.allow_new_responses_from + "'"
end
+ # If its not allowing responses, handle the message
if !allow
if self.handle_rejected_responses == 'bounce'
- RequestMailer.stopped_responses(self, email, raw_email_data).deliver if !is_external?
+ if MailHandler.get_from_address(email).nil?
+ # do nothing – can't bounce the mail as there's no
+ # address to send it to
+ else
+ RequestMailer.stopped_responses(self, email, raw_email_data).deliver if !is_external?
+ end
elsif self.handle_rejected_responses == 'holding_pen'
InfoRequest.holding_pen_request.receive(email, raw_email_data, false, reason)
elsif self.handle_rejected_responses == 'blackhole'
@@ -921,7 +928,7 @@ public
# Called by incoming_email - and used to be called to generate separate
# envelope from address until we abandoned it.
def magic_email(prefix_part)
- raise "id required to make magic" if not self.id
+ raise "id required to create a magic email" if not self.id
return InfoRequest.magic_email_for_id(prefix_part, self.id)
end
diff --git a/config/initializers/alaveteli.rb b/config/initializers/alaveteli.rb
index 9c15cb0cf..d0174c44b 100644
--- a/config/initializers/alaveteli.rb
+++ b/config/initializers/alaveteli.rb
@@ -10,7 +10,7 @@ load "debug_helpers.rb"
load "util.rb"
# Application version
-ALAVETELI_VERSION = '0.21.0.27'
+ALAVETELI_VERSION = '0.21.0.28'
# Add new inflection rules using the following format
# (all these examples are active by default):
diff --git a/spec/mailers/request_mailer_spec.rb b/spec/mailers/request_mailer_spec.rb
index 9e98dbc00..a26be866e 100644
--- a/spec/mailers/request_mailer_spec.rb
+++ b/spec/mailers/request_mailer_spec.rb
@@ -38,6 +38,12 @@ describe RequestMailer, " when receiving incoming mail" do
deliveries.clear
end
+ it "puts messages with a malformed To: in the holding pen" do
+ request = FactoryGirl.create(:info_request)
+ receive_incoming_mail('incoming-request-plain.email', 'asdfg')
+ expect(InfoRequest.holding_pen_request.incoming_messages).to have(1).item
+ end
+
it "should parse attachments from mails sent with apple mail" do
ir = info_requests(:fancy_dog_request)
ir.incoming_messages.size.should == 1
@@ -178,6 +184,24 @@ describe RequestMailer, " when receiving incoming mail" do
deliveries.clear
end
+ it "discards rejected responses with a malformed From: when set to bounce" do
+ ir = info_requests(:fancy_dog_request)
+ ir.allow_new_responses_from = 'nobody'
+ ir.handle_rejected_responses = 'bounce'
+ ir.save!
+ ir.incoming_messages.size.should == 1
+
+ receive_incoming_mail('incoming-request-plain.email', ir.incoming_email, "")
+ ir.incoming_messages.size.should == 1
+
+ last_event = ir.info_request_events.last
+ last_event.params[:rejected_reason].should =~ /there is no "From" address/
+
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 0
+ deliveries.clear
+ end
+
it "should send all new responses to holding pen if a request is marked to do so" do
# mark request as anti-spam
ir = info_requests(:fancy_dog_request)