diff options
Diffstat (limited to 'app/models/info_request.rb')
-rw-r--r-- | app/models/info_request.rb | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 275c39746..65099b1c4 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -428,6 +428,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 @@ -458,9 +459,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' @@ -777,7 +784,14 @@ public end def public_response_events - self.info_request_events.select{|e| e.response? && e.incoming_message.all_can_view? } + condition = <<-SQL + info_request_events.event_type = ? + AND incoming_messages.prominence = ? + SQL + + info_request_events. + joins(:incoming_message). + where(condition, 'response', 'normal') end # The last public response is the default one people might want to reply to @@ -804,8 +818,9 @@ public # Text from the the initial request, for use in summary display def initial_request_text - return '' if outgoing_messages.empty? # mainly for use with incomplete fixtures - outgoing_messages.first.get_text_for_indexing + return '' if outgoing_messages.empty? + body_opts = { :censor_rules => applicable_censor_rules } + outgoing_messages.first.try(:get_text_for_indexing, true, body_opts) or '' end # Returns index of last event which is described or nil if none described. @@ -925,7 +940,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 @@ -1383,6 +1398,15 @@ public end end + # The DateTime of the last InfoRequestEvent belonging to the InfoRequest + # Only available if the last_event_time attribute has been set. This is + # currentlt only set through .find_in_state + # + # Returns a DateTime + def last_event_time + attributes['last_event_time'].try(:to_datetime) + end + private def set_defaults |