aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/incoming_message.rb67
-rw-r--r--app/models/outgoing_message.rb14
-rw-r--r--app/views/request/_correspondence.rhtml4
-rw-r--r--app/views/request_mailer/followup.rhtml8
-rw-r--r--app/views/request_mailer/initial_request.rhtml5
5 files changed, 63 insertions, 35 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb
index a6a869769..32e5a6073 100644
--- a/app/models/incoming_message.rb
+++ b/app/models/incoming_message.rb
@@ -20,7 +20,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: incoming_message.rb,v 1.26 2008-01-10 01:13:28 francis Exp $
+# $Id: incoming_message.rb,v 1.27 2008-01-10 19:59:33 francis Exp $
class IncomingMessage < ActiveRecord::Base
belongs_to :info_request
@@ -48,6 +48,23 @@ class IncomingMessage < ActiveRecord::Base
self.mail.date || self.created_at
end
+ # Converts email addresses we know about into textual descriptions of them
+ def mask_special_emails(text)
+ # XXX can later display some of these special emails as actual emails,
+ # if they are public anyway. For now just be precautionary and only
+ # put in descriptions of them in square brackets.
+ if not self.info_request.public_body.request_email.empty?
+ text = text.gsub(self.info_request.public_body.request_email, "[" + self.info_request.public_body.short_name + " request email]")
+ end
+ if not self.info_request.public_body.complaint_email.empty?
+ text = text.gsub(self.info_request.public_body.complaint_email, "[" + self.info_request.public_body.short_name + " complaint email]")
+ end
+ text = text.gsub(self.info_request.incoming_email, "[FOI #" + self.info_request.id.to_s + " email]")
+ text = text.gsub(self.info_request.envelope_email, "[FOI #" + self.info_request.id.to_s + " bounce email]")
+ text = text.gsub(MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost'), "[GovernmentSpy contact email]")
+ return text
+ end
+
# Remove email addresses from text (mainly to reduce spam - particularly
# we want to stop spam to our own magic archiving request-* addresses,
# which would otherwise appear a lot in bounce messages and reply quotes etc.)
@@ -66,7 +83,7 @@ class IncomingMessage < ActiveRecord::Base
# Remove quoted sections from emails (eventually the aim would be for this
# to do as good a job as GMail does) XXX bet it needs a proper parser
# XXX and this BEGIN_QUOTED / END_QUOTED stuff is a mess
- def self.remove_quoted_sections(text)
+ def self.mark_quoted_sections(text)
text = text.dup
text.gsub!(/^(>.*\n)/, "BEGIN_QUOTED\\1END_QUOTED")
@@ -82,10 +99,8 @@ class IncomingMessage < ActiveRecord::Base
return text
end
- # Returns body text as HTML with quotes flattened, and emails removed.
- def get_body_for_display(collapse_quoted_sections = true)
- # Find the body text
-
+ # Returns body text from main text part of email, converted to UTF-8
+ def get_main_body_text
# XXX make this part scanning for mime parts properly recursive,
# allow download of specific parts, and always show them all (in
# case say the HTML differs from the text part)
@@ -122,26 +137,18 @@ class IncomingMessage < ActiveRecord::Base
end
end
- # Format the body text...
-
- # Show special emails we know about
- # XXX can later display some of these special emails as actual emails,
- # if they are public anyway. For now just be precautionary and only
- # put in descriptions of them in square brackets.
- if not self.info_request.public_body.request_email.empty?
- text = text.gsub(self.info_request.public_body.request_email, "[" + self.info_request.public_body.short_name + " request email]")
- end
- if not self.info_request.public_body.complaint_email.empty?
- text = text.gsub(self.info_request.public_body.complaint_email, "[" + self.info_request.public_body.short_name + " complaint email]")
- end
- text = text.gsub(self.info_request.incoming_email, "[FOI #" + self.info_request.id.to_s + " email]")
- text = text.gsub(self.info_request.envelope_email, "[FOI #" + self.info_request.id.to_s + " bounce email]")
- text = text.gsub(MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost'), "[GovernmentSpy contact email]")
- # Remove all other emails
+ return text
+ end
+
+ # Returns body text as HTML with quotes flattened, and emails removed.
+ def get_body_for_html_display(collapse_quoted_sections = true)
+ # Find the body text and remove emails for privacy/anti-spam reasons
+ text = get_main_body_text
+ text = self.mask_special_emails(text)
text = IncomingMessage.remove_email_addresses(text)
- # Removing quoted sections, adding HTML
- text = IncomingMessage.remove_quoted_sections(text)
+ # Remove quoted sections, adding HTML
+ text = IncomingMessage.mark_quoted_sections(text)
text = CGI.escapeHTML(text)
text = MySociety::Format.make_clickable(text, :contract => 1)
if collapse_quoted_sections
@@ -157,6 +164,18 @@ class IncomingMessage < ActiveRecord::Base
return text
end
+ # Returns body for quoting in reply
+ def get_body_for_quoting
+ # Find the body text and remove emails for privacy/anti-spam reasons
+ text = get_main_body_text
+ text = self.mask_special_emails(text)
+ text = IncomingMessage.remove_email_addresses(text)
+
+ # Remove existing quoted sections
+ text = IncomingMessage.mark_quoted_sections(text)
+ text = text.gsub(/BEGIN_QUOTED(.+?)END_QUOTED/m, '')
+ end
+
# Returns the name of the person the incoming message is from, or nil if there isn't one
# or if there is only an email address.
def safe_mail_from
diff --git a/app/models/outgoing_message.rb b/app/models/outgoing_message.rb
index a9244c652..fdd950ba5 100644
--- a/app/models/outgoing_message.rb
+++ b/app/models/outgoing_message.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: outgoing_message.rb,v 1.20 2008-01-10 18:12:10 francis Exp $
+# $Id: outgoing_message.rb,v 1.21 2008-01-10 19:59:33 francis Exp $
class OutgoingMessage < ActiveRecord::Base
belongs_to :info_request
@@ -110,8 +110,17 @@ class OutgoingMessage < ActiveRecord::Base
end
end
+ # Returns the text to quote the original message when sending this one
+ def get_quoted_part_of_followup
+ if self.message_type == 'followup' && !self.incoming_message_followup.nil?
+ return "\n\n-----Original Message-----\n\n" + self.incoming_message_followup.get_body_for_quoting + "\n"
+ else
+ return ""
+ end
+ end
+
# Return body for display as HTML
- def get_body_for_display
+ def get_body_for_html_display
text = body
text = MySociety::Format.make_clickable(text, :contract => 1)
text = text.gsub(/\n/, '<br>')
@@ -119,7 +128,6 @@ class OutgoingMessage < ActiveRecord::Base
return text
end
-
end
diff --git a/app/views/request/_correspondence.rhtml b/app/views/request/_correspondence.rhtml
index 8b8fbc7c9..d22aa5d67 100644
--- a/app/views/request/_correspondence.rhtml
+++ b/app/views/request/_correspondence.rhtml
@@ -4,7 +4,7 @@
if (correspondence.class.to_s == 'IncomingMessage')
incoming_message = correspondence%>
- <%= render :partial => 'bubble', :locals => { :body => incoming_message.get_body_for_display(@collapse_quotes) } %>
+ <%= render :partial => 'bubble', :locals => { :body => incoming_message.get_body_for_html_display(@collapse_quotes) } %>
<p class="event_bubble">
<% if !incoming_message.safe_mail_from.nil? %>
@@ -28,7 +28,7 @@
if info_request_event.event_type == 'sent' || info_request_event.event_type == 'followup_sent'
outgoing_message = OutgoingMessage.find(info_request_event.params[:outgoing_message_id])
%>
- <%= render :partial => 'bubble', :locals => { :body => outgoing_message.get_body_for_display() } %>
+ <%= render :partial => 'bubble', :locals => { :body => outgoing_message.get_body_for_html_display() } %>
<p class="event_bubble">
<%= user_link(@info_request.user) %>
diff --git a/app/views/request_mailer/followup.rhtml b/app/views/request_mailer/followup.rhtml
index 6de4b0397..a3198d038 100644
--- a/app/views/request_mailer/followup.rhtml
+++ b/app/views/request_mailer/followup.rhtml
@@ -1,8 +1,10 @@
-<%= @outgoing_message.body %>
-
---
+<%= @outgoing_message.body.strip %>
+-------------------------------------------------------------------
Disclaimer: This message and all responses to it are public. Any reply that you
make will be published on the Internet.
Sent using GovernmentSpy, a project of UKCOD, registered charity number 1076346.
+-------------------------------------------------------------------
+
+<%= @outgoing_message.get_quoted_part_of_followup.strip %>
diff --git a/app/views/request_mailer/initial_request.rhtml b/app/views/request_mailer/initial_request.rhtml
index 234c5da1a..e4c11d13f 100644
--- a/app/views/request_mailer/initial_request.rhtml
+++ b/app/views/request_mailer/initial_request.rhtml
@@ -1,7 +1,5 @@
<%= @outgoing_message.body %>
-
---
-
+-------------------------------------------------------------------
Disclaimer: This message and all responses to it are public. Any reply that you
make will be published on the Internet.
@@ -12,3 +10,4 @@ of Information requests to <%= @info_request.public_body.name%>? If so please
let us know by emailing <%=@contact_email%> quoting reference PB<%=
@info_request.public_body.id%>. We'll make sure future ones go to the right
place.
+-------------------------------------------------------------------