aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/application_mailer.rb123
-rw-r--r--app/models/public_body.rb14
-rw-r--r--app/models/request_mailer.rb4
-rw-r--r--app/models/track_thing.rb18
4 files changed, 147 insertions, 12 deletions
diff --git a/app/models/application_mailer.rb b/app/models/application_mailer.rb
index 3a11733a8..add05ffdb 100644
--- a/app/models/application_mailer.rb
+++ b/app/models/application_mailer.rb
@@ -5,7 +5,7 @@
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
# $Id: application_mailer.rb,v 1.8 2009-02-09 10:37:12 francis Exp $
-
+require 'action_mailer/version'
class ApplicationMailer < ActionMailer::Base
# Include all the functions views get, as emails call similar things.
helper :application
@@ -26,5 +26,126 @@ class ApplicationMailer < ActionMailer::Base
# Site-wide access to configuration settings
include ConfigHelper
+
+ # Instantiate a new mailer object. If +method_name+ is not +nil+, the mailer
+ # will be initialized according to the named method. If not, the mailer will
+ # remain uninitialized (useful when you only need to invoke the "receive"
+ # method, for instance).
+ def initialize(method_name=nil, *parameters) #:nodoc:
+ create!(method_name, *parameters) if method_name
+ end
+
+ # For each multipart template (e.g. "the_template_file.text.html.erb") available,
+ # add the one from the view path with the highest priority as a part to the mail
+ def render_multipart_templates
+ added_content_types = {}
+ self.view_paths.each do |view_path|
+ Dir.glob("#{view_path}/#{mailer_name}/#{@template}.*").each do |path|
+ template = view_path["#{mailer_name}/#{File.basename(path)}"]
+
+ # Skip unless template has a multipart format
+ next unless template && template.multipart?
+ next if added_content_types[template.content_type] == true
+ @parts << Part.new(
+ :content_type => template.content_type,
+ :disposition => "inline",
+ :charset => charset,
+ :body => render_message(template, @body)
+ )
+ added_content_types[template.content_type] = true
+ end
+ end
+ end
+
+ # Look for the current template in each element of view_paths in order,
+ # return the first
+ def find_template
+ self.view_paths.each do |view_path|
+ if template = view_path["#{mailer_name}/#{@template}"]
+ return template
+ end
+ end
+ return nil
+ end
+
+ if ActionMailer::VERSION::MAJOR == 2
+
+ # This method is a customised version of ActionMailer::Base.create!
+ # modified to allow templates to be selected correctly for multipart
+ # mails when themes have added to the view_paths. The problem from our
+ # point of view with ActionMailer::Base is that it sets template_root to
+ # the first element of the view_paths array and then uses only that (directly
+ # 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.
+ # Changed lines marked with ***
+
+ # Initialize the mailer via the given +method_name+. The body will be
+ # rendered and a new TMail::Mail object created.
+ def create!(method_name, *parameters) #:nodoc:
+ initialize_defaults(method_name)
+ __send__(method_name, *parameters)
+
+ # If an explicit, textual body has not been set, we check assumptions.
+ unless String === @body
+ # First, we look to see if there are any likely templates that match,
+ # which include the content-type in their file name (i.e.,
+ # "the_template_file.text.html.erb", etc.). Only do this if parts
+ # have not already been specified manually.
+ if @parts.empty?
+ # *** render_multipart_templates replaces the following code
+ # Dir.glob("#{template_path}/#{@template}.*").each do |path|
+ # template = template_root["#{mailer_name}/#{File.basename(path)}"]
+ #
+ # # Skip unless template has a multipart format
+ # next unless template && template.multipart?
+ #
+ # @parts << Part.new(
+ # :content_type => template.content_type,
+ # :disposition => "inline",
+ # :charset => charset,
+ # :body => render_message(template, @body)
+ # )
+ # end
+ render_multipart_templates
+
+ unless @parts.empty?
+ @content_type = "multipart/alternative" if @content_type !~ /^multipart/
+ @parts = sort_parts(@parts, @implicit_parts_order)
+ end
+ end
+
+ # Then, if there were such templates, we check to see if we ought to
+ # also render a "normal" template (without the content type). If a
+ # normal template exists (or if there were no implicit parts) we render
+ # it.
+ template_exists = @parts.empty?
+
+ # *** find_template replaces template_root call
+ # template_exists ||= template_root["#{mailer_name}/#{@template}"]
+ template_exists ||= find_template
+
+ @body = render_message(@template, @body) if template_exists
+
+ # Finally, if there are other message parts and a textual body exists,
+ # we shift it onto the front of the parts and set the body to nil (so
+ # that create_mail doesn't try to render it in addition to the parts).
+ if !@parts.empty? && String === @body
+ @parts.unshift ActionMailer::Part.new(:charset => charset, :body => @body)
+ @body = nil
+ end
+ end
+
+ # If this is a multipart e-mail add the mime_version if it is not
+ # already set.
+ @mime_version ||= "1.0" if !@parts.empty?
+
+ # build the mail object itself
+ @mail = create_mail
+ end
+ else
+ raise "ApplicationMailer.create! is obsolete - find another way to ensure that themes can override mail templates for multipart mails"
+ end
+
end
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index e9a90bce3..d212c371f 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -509,6 +509,20 @@ class PublicBody < ActiveRecord::Base
return self.request_email_domain
end
+ # Returns nil if configuration variable not set
+ def override_request_email
+ e = MySociety::Config.get("OVERRIDE_ALL_PUBLIC_BODY_REQUEST_EMAILS", "")
+ e if e != ""
+ end
+
+ def request_email
+ if override_request_email
+ override_request_email
+ else
+ read_attribute(:request_email)
+ end
+ end
+
# Domain name of the request email
def request_email_domain
return PublicBody.extract_domain_from_email(self.request_email)
diff --git a/app/models/request_mailer.rb b/app/models/request_mailer.rb
index 4316a9be9..3fc6b0471 100644
--- a/app/models/request_mailer.rb
+++ b/app/models/request_mailer.rb
@@ -50,7 +50,7 @@ class RequestMailer < ApplicationMailer
headers 'Return-Path' => blackhole_email, 'Reply-To' => @from, # we don't care about bounces, likely from spammers
'Auto-Submitted' => 'auto-replied' # http://tools.ietf.org/html/rfc3834
@recipients = email.from_addrs[0].to_s
- @subject = "Your response to an FOI request was not delivered"
+ @subject = _("Your response to an FOI request was not delivered")
attachment :content_type => 'message/rfc822', :body => raw_email_data,
:filename => "original.eml", :transfer_encoding => '7bit', :content_disposition => 'inline'
@body = {
@@ -154,7 +154,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 = "Someone has updated the status of your request"
+ @subject = _("Someone has updated the status of your request")
url = main_url(request_url(info_request))
@body = {:info_request => info_request, :url => url}
end
diff --git a/app/models/track_thing.rb b/app/models/track_thing.rb
index 9a553b382..63f356168 100644
--- a/app/models/track_thing.rb
+++ b/app/models/track_thing.rb
@@ -51,15 +51,15 @@ class TrackThing < ActiveRecord::Base
def TrackThing.track_type_description(track_type)
if track_type == 'request_updates'
- "Individual requests"
+ _("Individual requests")
elsif track_type == 'all_new_requests' || track_type == "all_successful_requests"
- "Many requests"
+ _("Many requests")
elsif track_type == 'public_body_updates'
- "Public authorities"
+ _("Public authorities")
elsif track_type == 'user_updates'
- "People"
+ _("People")
elsif track_type == 'search_query'
- "Search queries"
+ _("Search queries")
else
raise "internal error " + track_type
end
@@ -195,7 +195,7 @@ class TrackThing < ActiveRecord::Base
if self.track_type == 'request_updates'
@params = {
# Website
- :list_description => _("'{{link_to_request}}', a request", :link_to_request => "<a href=\"/request/" + CGI.escapeHTML(self.info_request.url_title) + "\">" + CGI.escapeHTML(self.info_request.title) + "</a>"), # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how
+ :list_description => _("'{{link_to_request}}', a request", :link_to_request => "<a href=\"/request/" + CGI.escapeHTML(self.info_request.url_title) + "\">" + CGI.escapeHTML(self.info_request.title) + "</a>"), # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how
:verb_on_page => _("Follow this request"),
:verb_on_page_already => _("You are already following this request"),
# Email
@@ -246,7 +246,7 @@ class TrackThing < ActiveRecord::Base
elsif self.track_type == 'public_body_updates'
@params = {
# Website
- :list_description => _("'{{link_to_authority}}', a public authority", :link_to_authority => "<a href=\"/body/" + CGI.escapeHTML(self.public_body.url_name) + "\">" + CGI.escapeHTML(self.public_body.name) + "</a>"), # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how
+ :list_description => _("'{{link_to_authority}}', a public authority", :link_to_authority => "<a href=\"/body/" + CGI.escapeHTML(self.public_body.url_name) + "\">" + CGI.escapeHTML(self.public_body.name) + "</a>"), # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how
:verb_on_page => _("Follow requests to {{public_body_name}}",:public_body_name=>CGI.escapeHTML(self.public_body.name)),
:verb_on_page_already => _("You are already following requests to {{public_body_name}}", :public_body_name=>CGI.escapeHTML(self.public_body.name)),
# Email
@@ -262,7 +262,7 @@ class TrackThing < ActiveRecord::Base
elsif self.track_type == 'user_updates'
@params = {
# Website
- :list_description => _("'{{link_to_user}}', a person", :link_to_user => "<a href=\"/user/" + CGI.escapeHTML(self.tracked_user.url_name) + "\">" + CGI.escapeHTML(self.tracked_user.name) + "</a>"), # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how
+ :list_description => _("'{{link_to_user}}', a person", :link_to_user => "<a href=\"/user/" + CGI.escapeHTML(self.tracked_user.url_name) + "\">" + CGI.escapeHTML(self.tracked_user.name) + "</a>"), # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how
:verb_on_page => _("Follow this person"),
:verb_on_page_already => _("You are already following this person"),
# Email
@@ -278,7 +278,7 @@ class TrackThing < ActiveRecord::Base
elsif self.track_type == 'search_query'
@params = {
# Website
- :list_description => "<a href=\"/search/" + CGI.escapeHTML(self.track_query) + "/newest/advanced\">" + self.track_query_description + "</a>", # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how
+ :list_description => "<a href=\"/search/" + CGI.escapeHTML(self.track_query) + "/newest/advanced\">" + self.track_query_description + "</a>", # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how
:verb_on_page => _("Follow things matching this search"),
:verb_on_page_already => _("You are already following things matching this search"),
# Email