diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/application_mailer.rb | 14 | ||||
-rw-r--r-- | app/models/foi_attachment.rb | 3 | ||||
-rw-r--r-- | app/models/request_mailer.rb | 32 | ||||
-rw-r--r-- | app/models/track_mailer.rb | 2 | ||||
-rw-r--r-- | app/models/track_thing.rb | 2 |
5 files changed, 36 insertions, 17 deletions
diff --git a/app/models/application_mailer.rb b/app/models/application_mailer.rb index cdb279c3c..1a97a4bf9 100644 --- a/app/models/application_mailer.rb +++ b/app/models/application_mailer.rb @@ -77,6 +77,17 @@ class ApplicationMailer < ActionMailer::Base # and via template_path, which is created from it) in the create! method when # looking for templates. Our modified version looks for templates in the view_paths # in order. + + # It also has a line converting the mail subject to a string. This is because we + # use translated strings in the subject lines, sometimes in conjunction with + # user input, like request titles. The _() function used for translation + # returns an instance of SafeBuffer, which doesn't handle gsub calls in the block form + # with $ variables - https://github.com/rails/rails/issues/1555. + # Unfortunately ActionMailer uses that form in quoted_printable(), which will be + # called if any part of the subject requires quoting. So we convert the subject + # back to a string via to_str() before passing in to create_mail. There is a test + # for this in spec/models/request_mailer_spec.rb + # Changed lines marked with *** # Initialize the mailer via the given +method_name+. The body will be @@ -139,6 +150,9 @@ class ApplicationMailer < ActionMailer::Base # already set. @mime_version ||= "1.0" if !@parts.empty? + # *** Convert into a string + @subject = @subject.to_str if @subject + # build the mail object itself @mail = create_mail end diff --git a/app/models/foi_attachment.rb b/app/models/foi_attachment.rb index 723bc4abb..bba0b6a8d 100644 --- a/app/models/foi_attachment.rb +++ b/app/models/foi_attachment.rb @@ -317,8 +317,7 @@ class FoiAttachment < ActiveRecord::Base text = CGI.escapeHTML(text) text = MySociety::Format.make_clickable(text) html = text.gsub(/\n/, '<br>') - return '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" - "http://www.w3.org/TR/html4/loose.dtd"><html><head><title></title></head><body>' + html + "</body></html>", wrapper_id + return '<!DOCTYPE html><html><head><title></title></head><body>' + html + "</body></html>", wrapper_id end # the extractions will also produce image files, which go in the diff --git a/app/models/request_mailer.rb b/app/models/request_mailer.rb index 493d6961c..6f8d88a1a 100644 --- a/app/models/request_mailer.rb +++ b/app/models/request_mailer.rb @@ -5,7 +5,11 @@ # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ require 'alaveteli_file_types' - +if Rails.env == 'test' && RUBY_VERSION.to_f >= 1.9 + # Avoid spec/script/mailin_spec.rb running script/runner as a test suite + # http://stackoverflow.com/questions/1899009/why-are-tests-running-in-production-mode-and-causing-my-script-runners-to-fail + Test::Unit.run = true +end class RequestMailer < ApplicationMailer @@ -67,8 +71,8 @@ class RequestMailer < ApplicationMailer @from = user.name_and_email @recipients = contact_from_name_and_email @subject = _("FOI response requires admin ({{reason}}) - {{title}}", :reason => info_request.described_state, :title => info_request.title) - url = main_url(request_url(info_request)) - admin_url = request_admin_url(info_request) + url = request_url(info_request) + admin_url = admin_request_show_url(info_request) @body = {:reported_by => user, :info_request => info_request, :url => url, :admin_url => admin_url } end @@ -76,14 +80,14 @@ class RequestMailer < ApplicationMailer def new_response(info_request, incoming_message) # Don't use login link here, just send actual URL. This is # because people tend to forward these emails amongst themselves. - url = main_url(incoming_message_url(incoming_message)) + url = incoming_message_url(incoming_message) @from = contact_from_name_and_email headers 'Return-Path' => blackhole_email, 'Reply-To' => @from, # not much we can do if the user's email is broken 'Auto-Submitted' => 'auto-generated', # http://tools.ietf.org/html/rfc3834 'X-Auto-Response-Suppress' => 'OOF' @recipients = info_request.user.name_and_email - @subject = _("New response to your FOI request - ") + info_request.title + @subject = (_("New response to your FOI request - ") + info_request.title).html_safe @body = { :incoming_message => incoming_message, :info_request => info_request, :url => url } end @@ -102,7 +106,7 @@ class RequestMailer < ApplicationMailer 'Auto-Submitted' => 'auto-generated', # http://tools.ietf.org/html/rfc3834 'X-Auto-Response-Suppress' => 'OOF' @recipients = user.name_and_email - @subject = _("Delayed response to your FOI request - ") + info_request.title + @subject = (_("Delayed response to your FOI request - ") + info_request.title).html_safe @body = { :info_request => info_request, :url => url } end @@ -121,7 +125,7 @@ class RequestMailer < ApplicationMailer 'Auto-Submitted' => 'auto-generated', # http://tools.ietf.org/html/rfc3834 'X-Auto-Response-Suppress' => 'OOF' @recipients = user.name_and_email - @subject = _("You're long overdue a response to your FOI request - ") + info_request.title + @subject = (_("You're long overdue a response to your FOI request - ") + info_request.title).html_safe @body = { :info_request => info_request, :url => url } end @@ -131,7 +135,7 @@ class RequestMailer < ApplicationMailer # Make a link going to the form to describe state, and which logs the # user in. post_redirect = PostRedirect.new( - :uri => main_url(request_url(info_request)) + "#describe_state_form_1", + :uri => request_url(info_request) + "#describe_state_form_1", :user_id => info_request.user.id) post_redirect.save! url = confirm_url(:email_token => post_redirect.email_token) @@ -153,7 +157,7 @@ class RequestMailer < ApplicationMailer 'X-Auto-Response-Suppress' => 'OOF' @recipients = info_request.user.name_and_email @subject = _("Someone has updated the status of your request") - url = main_url(request_url(info_request)) + url = request_url(info_request) @body = {:info_request => info_request, :url => url} end @@ -173,7 +177,7 @@ class RequestMailer < ApplicationMailer 'Auto-Submitted' => 'auto-generated', # http://tools.ietf.org/html/rfc3834 'X-Auto-Response-Suppress' => 'OOF' @recipients = info_request.user.name_and_email - @subject = _("Clarify your FOI request - ") + info_request.title + @subject = (_("Clarify your FOI request - ") + info_request.title).html_safe @body = { :incoming_message => incoming_message, :info_request => info_request, :url => url } end @@ -184,8 +188,8 @@ class RequestMailer < ApplicationMailer 'Auto-Submitted' => 'auto-generated', # http://tools.ietf.org/html/rfc3834 'X-Auto-Response-Suppress' => 'OOF' @recipients = info_request.user.name_and_email - @subject = _("Somebody added a note to your FOI request - ") + info_request.title - @body = { :comment => comment, :info_request => info_request, :url => main_url(comment_url(comment)) } + @subject = (_("Somebody added a note to your FOI request - ") + info_request.title).html_safe + @body = { :comment => comment, :info_request => info_request, :url => comment_url(comment) } end def comment_on_alert_plural(info_request, count, earliest_unalerted_comment) @from = contact_from_name_and_email @@ -193,8 +197,8 @@ class RequestMailer < ApplicationMailer 'Auto-Submitted' => 'auto-generated', # http://tools.ietf.org/html/rfc3834 'X-Auto-Response-Suppress' => 'OOF' @recipients = info_request.user.name_and_email - @subject = _("Some notes have been added to your FOI request - ") + info_request.title - @body = { :count => count, :info_request => info_request, :url => main_url(comment_url(earliest_unalerted_comment)) } + @subject = (_("Some notes have been added to your FOI request - ") + info_request.title).html_safe + @body = { :count => count, :info_request => info_request, :url => comment_url(earliest_unalerted_comment) } end # Class function, called by script/mailin with all incoming responses. diff --git a/app/models/track_mailer.rb b/app/models/track_mailer.rb index 7dfa87f52..51440e4d7 100644 --- a/app/models/track_mailer.rb +++ b/app/models/track_mailer.rb @@ -7,7 +7,7 @@ class TrackMailer < ApplicationMailer def event_digest(user, email_about_things) post_redirect = PostRedirect.new( - :uri => main_url(user_url(user)) + "#email_subscriptions", + :uri => user_url(user) + "#email_subscriptions", :user_id => user.id) post_redirect.save! unsubscribe_url = confirm_url(:email_token => post_redirect.email_token) diff --git a/app/models/track_thing.rb b/app/models/track_thing.rb index dfe92b7fe..a0c74bdb6 100644 --- a/app/models/track_thing.rb +++ b/app/models/track_thing.rb @@ -23,6 +23,8 @@ require 'set' +# TODO: TrackThing looks like a good candidate for single table inheritance + class TrackThing < ActiveRecord::Base belongs_to :tracking_user, :class_name => 'User' validates_presence_of :track_query |