diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/info_request.rb | 4 | ||||
-rw-r--r-- | app/models/info_request_event.rb | 6 | ||||
-rw-r--r-- | app/models/outgoing_message.rb | 29 |
3 files changed, 27 insertions, 12 deletions
diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 60b921e69..e553c9700 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -23,7 +23,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: info_request.rb,v 1.171 2009-03-06 13:06:20 tony Exp $ +# $Id: info_request.rb,v 1.172 2009-03-07 01:16:18 francis Exp $ require 'digest/sha1' require File.join(File.dirname(__FILE__),'../../vendor/plugins/acts_as_xapian/lib/acts_as_xapian') @@ -573,7 +573,7 @@ public if outgoing_messages.empty? # mainly for use with incomplete fixtures return "" end - excerpt = self.outgoing_messages[0].body_without_salutation + excerpt = self.outgoing_messages[0].get_text_for_indexing return excerpt end diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb index 938b5313a..bd6a565dc 100644 --- a/app/models/info_request_event.rb +++ b/app/models/info_request_event.rb @@ -21,7 +21,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: info_request_event.rb,v 1.74 2009-03-04 11:26:35 tony Exp $ +# $Id: info_request_event.rb,v 1.75 2009-03-07 01:16:18 francis Exp $ class InfoRequestEvent < ActiveRecord::Base belongs_to :info_request @@ -127,9 +127,9 @@ class InfoRequestEvent < ActiveRecord::Base def search_text_main text = '' if self.event_type == 'sent' - text = text + self.outgoing_message.body_without_salutation + "\n\n" + text = text + self.outgoing_message.get_text_for_indexing + "\n\n" elsif self.event_type == 'followup_sent' - text = text + self.outgoing_message.body_without_salutation + "\n\n" + text = text + self.outgoing_message.get_text_for_indexing + "\n\n" elsif self.event_type == 'response' text = text + self.incoming_message.get_text_for_indexing + "\n\n" elsif self.event_type == 'comment' diff --git a/app/models/outgoing_message.rb b/app/models/outgoing_message.rb index 3c114cd25..4c2a2db59 100644 --- a/app/models/outgoing_message.rb +++ b/app/models/outgoing_message.rb @@ -22,7 +22,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: outgoing_message.rb,v 1.79 2009-03-04 11:26:35 tony Exp $ +# $Id: outgoing_message.rb,v 1.80 2009-03-07 01:16:18 francis Exp $ class OutgoingMessage < ActiveRecord::Base strip_attributes! @@ -100,12 +100,6 @@ class OutgoingMessage < ActiveRecord::Base read_attribute(:body) end - def body_without_salutation - ret = self.body - ret.sub!(/Dear .+,/, "") - return ret - end - # Used to give warnings when writing new messages def contains_email? MySociety::Validate.email_find_regexp.match(self.body) @@ -194,9 +188,30 @@ class OutgoingMessage < ActiveRecord::Base end end + # We hide emails from display in outgoing messages. + def remove_privacy_sensitive_things(text) + text = text.dup + text.gsub!(MySociety::Validate.email_find_regexp, "[email address]") + return text + end + + # Returns text for indexing / text display + def get_text_for_indexing + text = self.body.strip + + # Remove salutation + text.sub!(/Dear .+,/, "") + + # Remove email addresses from display/index etc. + text = self.remove_privacy_sensitive_things(text) + + return text + end + # Return body for display as HTML def get_body_for_html_display text = self.body.strip + text = self.remove_privacy_sensitive_things(text) text = MySociety::Format.wrap_email_body(text) # reparagraph and wrap it so is good preview of emails text = CGI.escapeHTML(text) text = MySociety::Format.make_clickable(text, :contract => 1) |