aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/incoming_message.rb
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2013-09-17 17:39:51 +0100
committerLouise Crow <louise.crow@gmail.com>2013-09-17 17:39:51 +0100
commit6fbcb461025dc315d688038d9f0a8e138d00ba33 (patch)
tree628ad3d7bf9cb2310bc2bed2e94b8670532a0dd4 /app/models/incoming_message.rb
parentabde5e4a1139c41c6db23ce041fba090674f65ac (diff)
parentf41ec6d1cb167058a808b7820da5345c6da962fd (diff)
Merge branch 'feature/hide-individual-responses' into rails-3-develop
Conflicts: Gemfile app/views/admin_request/edit_outgoing.html.erb config/packages doc/CHANGES.md doc/INSTALL.md spec/models/info_request_spec.rb spec/models/public_body_spec.rb
Diffstat (limited to 'app/models/incoming_message.rb')
-rw-r--r--app/models/incoming_message.rb36
1 files changed, 29 insertions, 7 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb
index ae3c3b407..8b2aa87e7 100644
--- a/app/models/incoming_message.rb
+++ b/app/models/incoming_message.rb
@@ -1,15 +1,13 @@
# coding: utf-8
-
# == Schema Information
-# Schema version: 114
#
# Table name: incoming_messages
#
-# id :integer not null, primary key
-# info_request_id :integer not null
-# created_at :datetime not null
-# updated_at :datetime not null
-# raw_email_id :integer not null
+# id :integer not null, primary key
+# info_request_id :integer not null
+# created_at :datetime not null
+# updated_at :datetime not null
+# raw_email_id :integer not null
# cached_attachment_text_clipped :text
# cached_main_body_text_folded :text
# cached_main_body_text_unfolded :text
@@ -19,6 +17,9 @@
# last_parsed :datetime
# mail_from :text
# sent_at :datetime
+# prominence :string(255) default("normal"), not null
+# prominence_reason :text
+#
# models/incoming_message.rb:
# An (email) message from really anybody to be logged with a request. e.g. A
@@ -37,6 +38,7 @@ require 'zip/zip'
require 'iconv' unless RUBY_VERSION >= '1.9'
class IncomingMessage < ActiveRecord::Base
+ extend MessageProminence
belongs_to :info_request
validates_presence_of :info_request
@@ -48,6 +50,8 @@ class IncomingMessage < ActiveRecord::Base
belongs_to :raw_email
+ has_prominence
+
# See binary_mask_stuff function below. It just test for inclusion
# in this hash, not the value of the right hand side.
DoNotBinaryMask = {
@@ -59,6 +63,12 @@ class IncomingMessage < ActiveRecord::Base
'application/zip' => 1,
}
+ # Given that there are in theory many info request events, a convenience method for
+ # getting the response event
+ def response_event
+ self.info_request_events.detect{ |e| e.event_type == 'response' }
+ end
+
# Return a cached structured mail object
def mail(force = nil)
if (!force.nil? || @mail.nil?) && !self.raw_email.nil?
@@ -151,14 +161,17 @@ class IncomingMessage < ActiveRecord::Base
parse_raw_email!
super
end
+
def subject
parse_raw_email!
super
end
+
def mail_from
parse_raw_email!
super
end
+
def safe_mail_from
if !self.mail_from.nil?
mail_from = self.mail_from.dup
@@ -166,6 +179,15 @@ class IncomingMessage < ActiveRecord::Base
return mail_from
end
end
+
+ def specific_from_name?
+ !safe_mail_from.nil? && safe_mail_from.strip != info_request.public_body.name.strip
+ end
+
+ def from_public_body?
+ safe_mail_from.nil? || (mail_from_domain == info_request.public_body.request_email_domain)
+ end
+
def mail_from_domain
parse_raw_email!
super