aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/api_controller.rb25
-rw-r--r--app/controllers/request_controller.rb29
-rw-r--r--app/mailers/application_mailer.rb143
-rw-r--r--app/models/info_request.rb8
-rw-r--r--app/views/admin_general/debug.html.erb2
5 files changed, 31 insertions, 176 deletions
diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb
index 61b68a2db..57eca965e 100644
--- a/app/controllers/api_controller.rb
+++ b/app/controllers/api_controller.rb
@@ -148,28 +148,9 @@ class ApiController < ApplicationController
:filename => filename
)
end
- if MailHandler.backend == "TMail"
- # Directly construct Tmail object using attachment_hashes
- mail = TMail::Mail.new
- mail.body = body
- blackhole_email = Configuration::blackhole_prefix+"@"+Configuration::incoming_email_domain
- mail.from = blackhole_email
- mail.to = request.incoming_name_and_email
- mail.date = sent_at.dup.localtime
- b = TMail::Mail.new
- b.body = body
- mail.parts << b
- attachment_hashes.each do |attachment_hash|
- attachment = TMail::Mail.new
- attachment.body = Base64.encode64(attachment_hash[:body])
- attachment.transfer_encoding = "Base64"
- attachment.set_content_type(attachment_hash[:content_type])
- attachment['Content-Disposition'] = "attachment; filename=#{attachment_hash[:filename]}"
- mail.parts << attachment
- end
- else
- mail = RequestMailer.external_response(request, body, sent_at, attachment_hashes)
- end
+
+ mail = RequestMailer.external_response(request, body, sent_at, attachment_hashes)
+
request.receive(mail, mail.encoded, true)
end
render :json => {
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index c8da8e845..680833ae4 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/request_controller.rb
@@ -853,33 +853,8 @@ class RequestController < ApplicationController
return
end
- # There is duplication of the email creation code in api_controller.rb
- # TODO: Remove duplication
- if MailHandler.backend == "TMail"
- # Directly construct Tmail object using attachment_hashes
- mail = TMail::Mail.new
- mail.from = @user.name_and_email
- mail.to = @info_request.incoming_name_and_email
-
- b = TMail::Mail.new
- b.body = body
- b.set_content_type("text/plain")
- b['Content-Disposition'] = "inline"
- mail.parts << b
-
- if !file_name.nil? && !file_content.nil?
- content_type = AlaveteliFileTypes.filename_to_mimetype(file_name) || 'application/octet-stream'
-
- attachment = TMail::Mail.new
- attachment.body = Base64.encode64(file_content)
- attachment.transfer_encoding = "base64"
- attachment['Content-Type'] = "#{content_type}; name=\"#{file_name}\""
- attachment['Content-Disposition'] = "attachment; filename=#{file_name}"
- mail.parts << attachment
- end
- else
- mail = RequestMailer.fake_response(@info_request, @user, body, file_name, file_content)
- end
+ mail = RequestMailer.fake_response(@info_request, @user, body, file_name, file_content)
+
@info_request.receive(mail, mail.encoded, true)
flash[:notice] = _("Thank you for responding to this FOI request! Your response has been published below, and a link to your response has been emailed to ") + CGI.escapeHTML(@info_request.user.name) + "."
redirect_to request_url(@info_request)
diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb
index 84b045795..3877c4a33 100644
--- a/app/mailers/application_mailer.rb
+++ b/app/mailers/application_mailer.rb
@@ -26,128 +26,37 @@ 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).
-
- # TEMPORARY: commented out method below while upgrading to Rails 3
- #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
+ # 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
- return nil
end
+ end
- # FIXME: This check was disabled temporarily during the Rails 3 upgrade
- 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
+ # 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
-
- # 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
-
+ return nil
+ end
end
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index b66c388c4..913d053bf 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -405,14 +405,6 @@ public
# A new incoming email to this request
def receive(email, raw_email_data, override_stop_new_responses = false, rejected_reason = "")
- # Just adding a bit of extra error checking just to save a lot of deep chasing of
- # strangeness.
- # TODO: Remove this when we don't use the TMail backend anymore for anything
- if (MailHandler.backend == "TMail" && !email.kind_of?(TMail::Mail)) ||
- (MailHandler.backend == "Mail" && !email.kind_of?(Mail::Message))
- raise "Wrong kind of mail object passed in receive"
- end
-
if !override_stop_new_responses
allow = nil
reason = nil
diff --git a/app/views/admin_general/debug.html.erb b/app/views/admin_general/debug.html.erb
index b0749bedb..88a3f5b32 100644
--- a/app/views/admin_general/debug.html.erb
+++ b/app/views/admin_general/debug.html.erb
@@ -17,8 +17,6 @@ RUBY_VERSION <%=h RUBY_VERSION %>
<br>
Rails::VERSION::STRING <%=h Rails::VERSION::STRING%>
<br>
-TMail::VERSION::STRING <%=h TMail::VERSION::STRING%>
-<br>
Xapian::version_string <%=h Xapian::version_string%>
</p>