aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGareth Rees <gareth@mysociety.org>2015-05-12 12:43:04 +0100
committerGareth Rees <gareth@mysociety.org>2015-05-12 12:43:04 +0100
commit245607091397ec767272f4bd99dc5f243d6d1f42 (patch)
treeab030589069b9c84de078f388f4231baac281a56
parente2e393db294c5a7144a65f97e86e51606c42d820 (diff)
Discard rejected responses with malformed From:2422-incoming-message-spam
Stops the RequestMailer trying to send a stopped_responses mail if the To: address can’t be parsed from the incoming message. ArgumentError: An SMTP To address is required to send a message. Set the message smtp_envelope_to, to, cc, or bcc address.
-rw-r--r--app/models/info_request.rb6
-rw-r--r--spec/mailers/request_mailer_spec.rb18
2 files changed, 23 insertions, 1 deletions
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index f75d43010..d46dc63ae 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -461,7 +461,11 @@ public
# 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?
+ log_event('response', :rejected_reason => _('Could not return the message to the sender because there is no "From" address'))
+ 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'
diff --git a/spec/mailers/request_mailer_spec.rb b/spec/mailers/request_mailer_spec.rb
index 83befc4b4..a26be866e 100644
--- a/spec/mailers/request_mailer_spec.rb
+++ b/spec/mailers/request_mailer_spec.rb
@@ -184,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)