From e421c6366087b8430654ef79954f096e43b921aa Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Mon, 11 May 2015 12:12:31 +0100 Subject: Use each instead of for Extract email collection to explaining variable --- app/mailers/request_mailer.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/mailers/request_mailer.rb b/app/mailers/request_mailer.rb index c9decc6db..d4d5db1dd 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 || []) 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 -- cgit v1.2.3 From 89d15ebeefac4dcece18bd728944489325b90d39 Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Mon, 11 May 2015 14:16:09 +0100 Subject: Put emails with malformed To: field in holding pen Prevents mailin exiting with an error code of 75 and sending error reports to the team@ email address. --- app/mailers/request_mailer.rb | 2 +- spec/mailers/request_mailer_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/mailers/request_mailer.rb b/app/mailers/request_mailer.rb index d4d5db1dd..252df861c 100644 --- a/app/mailers/request_mailer.rb +++ b/app/mailers/request_mailer.rb @@ -234,7 +234,7 @@ 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 || []) + addresses = ((email.to || []) + (email.cc || [])).compact reply_info_requests = [] # TODO: should be set? addresses.each do |address| reply_info_request = InfoRequest.find_by_incoming_email(address) diff --git a/spec/mailers/request_mailer_spec.rb b/spec/mailers/request_mailer_spec.rb index 9e98dbc00..83befc4b4 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 -- cgit v1.2.3 From 7d04bf1b30460235075ad39305d45462c1b99a8d Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Mon, 11 May 2015 16:18:13 +0100 Subject: Sensible error message --- app/models/info_request.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 245de1e15..0b7838219 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -921,7 +921,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 -- cgit v1.2.3 From cfed22d9a2d4fab6c8d008a74bcdf97c908384c2 Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Tue, 12 May 2015 12:05:51 +0100 Subject: Add explaining comments --- app/models/info_request.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 0b7838219..f75d43010 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,6 +458,7 @@ 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? -- cgit v1.2.3 From da6c11531a761847ee129f92677a44fdb02de04e Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Tue, 12 May 2015 12:43:04 +0100 Subject: Discard rejected responses with malformed From: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- app/models/info_request.rb | 7 ++++++- spec/mailers/request_mailer_spec.rb | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/models/info_request.rb b/app/models/info_request.rb index f75d43010..c203f75c3 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -461,7 +461,12 @@ 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? + # 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' 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) -- cgit v1.2.3 From d45fa666cb97f1beb7af93c5cad8f554c2e5de5a Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Wed, 13 May 2015 10:54:04 +0100 Subject: Bump alaveteli version --- config/initializers/alaveteli.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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): -- cgit v1.2.3