diff options
29 files changed, 157 insertions, 283 deletions
@@ -7,7 +7,8 @@ if File.exist? "/etc/debian_version" and File.open("/etc/debian_version").read.s end source 'https://rubygems.org' -gem 'rails', '3.1.12' +gem 'rails', '3.2.15' + gem 'pg' # New gem releases aren't being done. master is newer and supports Rails > 3.0 @@ -55,10 +56,10 @@ gem 'unidecoder' group :assets do gem 'bootstrap-sass' - gem 'sass-rails', "= 3.1.4" + gem 'sass-rails', '~> 3.2.3' gem 'compass-rails' - gem 'coffee-rails', "~> 3.1" - gem 'uglifier' + gem 'coffee-rails', "~> 3.2.1" + gem 'uglifier', '>= 1.0.3' gem 'therubyracer' end diff --git a/Gemfile.lock b/Gemfile.lock index 3f73bcce7..261941455 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -18,37 +18,36 @@ GIT GEM remote: https://rubygems.org/ specs: - actionmailer (3.1.12) - actionpack (= 3.1.12) - mail (~> 2.4.4) - actionpack (3.1.12) - activemodel (= 3.1.12) - activesupport (= 3.1.12) + actionmailer (3.2.15) + actionpack (= 3.2.15) + mail (~> 2.5.4) + actionpack (3.2.15) + activemodel (= 3.2.15) + activesupport (= 3.2.15) builder (~> 3.0.0) erubis (~> 2.7.0) - i18n (~> 0.6) - rack (~> 1.3.6) + journey (~> 1.0.4) + rack (~> 1.4.5) rack-cache (~> 1.2) - rack-mount (~> 0.8.2) rack-test (~> 0.6.1) - sprockets (~> 2.0.4) - activemodel (3.1.12) - activesupport (= 3.1.12) + sprockets (~> 2.2.1) + activemodel (3.2.15) + activesupport (= 3.2.15) builder (~> 3.0.0) - i18n (~> 0.6) - activerecord (3.1.12) - activemodel (= 3.1.12) - activesupport (= 3.1.12) - arel (~> 2.2.3) + activerecord (3.2.15) + activemodel (= 3.2.15) + activesupport (= 3.2.15) + arel (~> 3.0.2) tzinfo (~> 0.3.29) - activeresource (3.1.12) - activemodel (= 3.1.12) - activesupport (= 3.1.12) - activesupport (3.1.12) + activeresource (3.2.15) + activemodel (= 3.2.15) + activesupport (= 3.2.15) + activesupport (3.2.15) + i18n (~> 0.6, >= 0.6.4) multi_json (~> 1.0) annotate (2.5.0) rake - arel (2.2.3) + arel (3.0.2) bootstrap-sass (2.3.1.2) sass (~> 3.2) builder (3.0.4) @@ -60,9 +59,9 @@ GEM net-ssh-gateway (>= 1.1.0) charlock_holmes (0.6.9.4) chunky_png (1.2.8) - coffee-rails (3.1.1) + coffee-rails (3.2.2) coffee-script (>= 2.2.0) - railties (~> 3.1.0) + railties (~> 3.2.0) coffee-script (2.2.0) coffee-script-source execjs @@ -94,6 +93,7 @@ GEM eventmachine (1.0.3) exception_notification (3.0.1) actionmailer (>= 3.0.4) + activesupport (>= 3.0.4) execjs (2.0.1) factory_girl (2.6.4) activesupport (>= 2.3.9) @@ -114,19 +114,19 @@ GEM highline (1.6.19) hike (1.2.3) i18n (0.6.5) + journey (1.0.4) jquery-rails (3.0.4) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) jquery-ui-rails (4.1.0) railties (>= 3.1.0) - json (1.8.0) + json (1.8.1) libv8 (3.16.14.3) linecache (0.46) rbx-require-relative (> 0.0.4) locale (2.0.8) mahoro (0.4) - mail (2.4.4) - i18n (>= 0.4.0) + mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) mailcatcher (0.5.11) @@ -138,8 +138,8 @@ GEM skinny (~> 0.2.3) sqlite3 (~> 1.3) thin (~> 1.5.0) - mime-types (1.23) - multi_json (1.8.0) + mime-types (1.25) + multi_json (1.8.2) net-http-local (0.1.2) net-purge (0.1.0) net-scp (1.1.1) @@ -156,34 +156,32 @@ GEM railties (~> 3.0) pg (0.15.1) polyglot (0.3.3) - rack (1.3.10) + rack (1.4.5) rack-cache (1.2) rack (>= 0.4) - rack-mount (0.8.3) - rack (>= 1.0.0) rack-protection (1.5.0) rack rack-ssl (1.3.3) rack rack-test (0.6.2) rack (>= 1.0) - rails (3.1.12) - actionmailer (= 3.1.12) - actionpack (= 3.1.12) - activerecord (= 3.1.12) - activeresource (= 3.1.12) - activesupport (= 3.1.12) + rails (3.2.15) + actionmailer (= 3.2.15) + actionpack (= 3.2.15) + activerecord (= 3.2.15) + activeresource (= 3.2.15) + activesupport (= 3.2.15) bundler (~> 1.0) - railties (= 3.1.12) + railties (= 3.2.15) rails-i18n (0.7.3) i18n (~> 0.5) - railties (3.1.12) - actionpack (= 3.1.12) - activesupport (= 3.1.12) + railties (3.2.15) + actionpack (= 3.2.15) + activesupport (= 3.2.15) rack-ssl (~> 1.3.2) rake (>= 0.8.7) rdoc (~> 3.4) - thor (~> 0.14.6) + thor (>= 0.14.6, < 2.0) rake (0.9.2.2) rbx-require-relative (0.0.9) rdoc (3.12.2) @@ -216,12 +214,10 @@ GEM vpim (>= 0.360) ruby-ole (1.2.11.6) sass (3.2.10) - sass-rails (3.1.4) - actionpack (~> 3.1.0) - railties (~> 3.1.0) - sass (>= 3.1.4) - sprockets (~> 2.0.0) - tilt (~> 1.3.2) + sass-rails (3.2.6) + railties (~> 3.2.0) + sass (>= 3.1.10) + tilt (~> 1.3) simplecov (0.7.1) multi_json (~> 1.0) simplecov-html (~> 0.7.1) @@ -237,8 +233,9 @@ GEM spork-rails (3.2.1) rails (>= 3.0.0, < 3.3.0) spork (>= 1.0rc0) - sprockets (2.0.4) + sprockets (2.2.2) hike (~> 1.2) + multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) sqlite3 (1.3.7) @@ -252,12 +249,12 @@ GEM daemons (>= 1.0.9) eventmachine (>= 0.12.6) rack (>= 1.0.0) - thor (0.14.6) - tilt (1.3.7) - treetop (1.4.12) + thor (0.18.1) + tilt (1.4.1) + treetop (1.4.15) polyglot polyglot (>= 0.3.1) - tzinfo (0.3.37) + tzinfo (0.3.38) uglifier (2.2.1) execjs (>= 0.3.0) multi_json (~> 1.0, >= 1.0.2) @@ -282,7 +279,7 @@ DEPENDENCIES bootstrap-sass capistrano charlock_holmes - coffee-rails (~> 3.1) + coffee-rails (~> 3.2.1) compass-rails coveralls debugger @@ -307,7 +304,7 @@ DEPENDENCIES nokogiri pg rack - rails (= 3.1.12) + rails (= 3.2.15) rails-i18n rake (= 0.9.2.2) rdoc @@ -317,13 +314,13 @@ DEPENDENCIES rspec-rails ruby-debug ruby-msg (~> 1.5.0) - sass-rails (= 3.1.4) + sass-rails (~> 3.2.3) spork-rails statistics2 (~> 0.54) syslog_protocol therubyracer thin - uglifier + uglifier (>= 1.0.3) unicode unidecoder vpim @@ -2,6 +2,7 @@ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require File.expand_path('../config/application', __FILE__) +ActiveSupport::Deprecation.silenced = true require 'rake' Alaveteli::Application.load_tasks if Rails.env == 'test' diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index e7bea67ef..00a3beebd 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -200,7 +200,7 @@ class ApiController < ApplicationController ]) end if feed_type == "atom" - render :template => "api/request_events.atom", :layout => false + render :template => "api/request_events", :formats => ['atom'], :layout => false elsif feed_type == "json" # For the JSON feed, we take a "since" parameter that allows the client # to restrict to events more recent than a certain other event diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index cbdffc441..161a82b26 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -138,7 +138,9 @@ class ApplicationController < ActionController::Base backtrace = Rails.backtrace_cleaner.clean(exception.backtrace, :silent) message << " " << backtrace.join("\n ") Rails.logger.fatal("#{message}\n\n") - ExceptionNotifier::Notifier.exception_notification(request.env, exception).deliver + if !AlaveteliConfiguration.exception_notifications_from.blank? && !AlaveteliConfiguration.exception_notifications_to.blank? + ExceptionNotifier::Notifier.exception_notification(request.env, exception).deliver + end @status = 500 end respond_to do |format| diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 388473b51..44f3a5b9b 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -965,8 +965,9 @@ class RequestController < ApplicationController end if !done file_info = { :filename => 'correspondence.txt', - :data => render_to_string(:template => 'request/show.text', - :layout => false) } + :data => render_to_string(:template => 'request/show', + :layout => false, + :formats => [:text]) } end file_info end diff --git a/app/controllers/track_controller.rb b/app/controllers/track_controller.rb index 72c092221..1123903f9 100644 --- a/app/controllers/track_controller.rb +++ b/app/controllers/track_controller.rb @@ -160,7 +160,10 @@ class TrackController < ApplicationController format.json { render :json => @xapian_object.results.map { |r| r[:model].json_for_api(true, lambda { |t| view_context.highlight_and_excerpt(t, @xapian_object.words_to_highlight, 150) } ) } } - format.any { render :template => 'track/atom_feed.atom', :layout => false, :content_type => 'application/atom+xml' } + format.any { render :template => 'track/atom_feed', + :formats => ['atom'], + :layout => false, + :content_type => 'application/atom+xml' } end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e3b1e57ac..6d0a111e9 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -54,16 +54,16 @@ module ApplicationHelper # Highlight words, also escapes HTML (other than spans that we add) def highlight_words(t, words, html = true) if html - highlight(h(t), words, '<span class="highlight">\1</span>').html_safe + highlight(h(t), words, :highlighter => '<span class="highlight">\1</span>').html_safe else - highlight(t, words, '*\1*') + highlight(t, words, :highlighter => '*\1*') end end def highlight_and_excerpt(t, words, excount, html = true) - newt = excerpt(t, words[0], excount) + newt = excerpt(t, words[0], :radius => excount) if not newt - newt = excerpt(t, '', excount) + newt = excerpt(t, '', :radius => excount) end t = newt t = highlight_words(t, words, html) diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb index 8b2aa87e7..bcf0b6ec9 100644 --- a/app/models/incoming_message.rb +++ b/app/models/incoming_message.rb @@ -129,15 +129,15 @@ class IncomingMessage < ActiveRecord::Base if (!force.nil? || self.last_parsed.nil?) ActiveRecord::Base.transaction do self.extract_attachments! - self.sent_at = self.mail.date || self.created_at - self.subject = self.mail.subject - self.mail_from = MailHandler.get_from_name(self.mail) + write_attribute(:sent_at, self.mail.date || self.created_at) + write_attribute(:subject, self.mail.subject) + write_attribute(:mail_from, MailHandler.get_from_name(self.mail)) if self.from_email self.mail_from_domain = PublicBody.extract_domain_from_email(self.from_email) else self.mail_from_domain = "" end - self.valid_to_reply_to = self._calculate_valid_to_reply_to + write_attribute(:valid_to_reply_to, self._calculate_valid_to_reply_to) self.last_parsed = Time.now self.foi_attachments reload=true self.save! diff --git a/app/models/public_body.rb b/app/models/public_body.rb index db6359f6b..883afc3af 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -199,7 +199,6 @@ class PublicBody < ActiveRecord::Base self.non_versioned_columns << 'info_requests_overdue_count' class Version - attr_accessor :created_at def last_edit_comment_for_html_display text = self.last_edit_comment.strip diff --git a/app/views/general/_frontpage_requests_list.html.erb b/app/views/general/_frontpage_requests_list.html.erb index fa498dfa7..a628c14ef 100644 --- a/app/views/general/_frontpage_requests_list.html.erb +++ b/app/views/general/_frontpage_requests_list.html.erb @@ -21,7 +21,7 @@ <%=link_to h(event.info_request.title), request_path(event.info_request)%> <%= _('{{length_of_time}} ago', :length_of_time => time_ago_in_words(event.described_at)) %> - <p class="excerpt" onclick="document.location.href='<%=request_path(event.info_request)%>'"><%= excerpt(event.search_text_main(true), "", 200) %></p> + <p class="excerpt" onclick="document.location.href='<%=request_path(event.info_request)%>'"><%= excerpt(event.search_text_main(true), "", :radius => 200) %></p> </li> <% end %> </ul> diff --git a/app/views/general/_header.html.erb b/app/views/general/_header.html.erb new file mode 100644 index 000000000..55bf719e2 --- /dev/null +++ b/app/views/general/_header.html.erb @@ -0,0 +1,37 @@ +<div id="banner"> + <div id="banner_inner"> + <div class="lang"><%= render :partial => 'general/locale_switcher' %></div> + + <% if not (controller.action_name == 'signin' or controller.action_name == 'signup') %> + <div id="logged_in_bar"> + <% if @user %> + <%= _('Hello, {{username}}!', :username => h(@user.name))%> + + <% if @user %> + <%=link_to _("My requests"), show_user_requests_path(:url_name => @user.url_name) %> + <%=link_to _("My profile"), show_user_profile_path(:url_name => @user.url_name) %> + <%=link_to _("My wall"), show_user_wall_path(:url_name => @user.url_name) %> + <% end %> + + + <%= link_to _("Sign out"), signout_path(:r => request.fullpath) %> + <% else %> + <%= link_to _("Sign in or sign up"), signin_path(:r => request.fullpath) %> + <% end %> + </div> + <% end %> + + <div id="navigation_search"> + <form id="navigation_search_form" method="post" action="<%= search_redirect_path %>"> + <p> + <%= text_field_tag 'query', params[:query], { :size => 40, :id => "navigation_search_query", :title => "type your search term here" } %> + <input id="navigation_search_button" type="submit" value="search"> + </p> + </form> + </div> + + <%= render :partial => 'general/orglink' %> + + <%= render :partial => 'general/topnav' %> + </div> +</div> diff --git a/app/views/layouts/default.html.erb b/app/views/layouts/default.html.erb index e90e89a00..8d69b2a08 100644 --- a/app/views/layouts/default.html.erb +++ b/app/views/layouts/default.html.erb @@ -76,43 +76,7 @@ <% end %> <div class="entirebody"> - <div id="banner"> - <div id="banner_inner"> - <div class="lang"><%= render :partial => 'general/locale_switcher' %></div> - - <% if not (controller.action_name == 'signin' or controller.action_name == 'signup') %> - <div id="logged_in_bar"> - <% if @user %> - <%= _('Hello, {{username}}!', :username => h(@user.name))%> - - <% if @user %> - <%=link_to _("My requests"), show_user_requests_path(:url_name => @user.url_name) %> - <%=link_to _("My profile"), show_user_profile_path(:url_name => @user.url_name) %> - <%=link_to _("My wall"), show_user_wall_path(:url_name => @user.url_name) %> - <% end %> - - - <%= link_to _("Sign out"), signout_path(:r => request.fullpath) %> - <% else %> - <%= link_to _("Sign in or sign up"), signin_path(:r => request.fullpath) %> - <% end %> - </div> - <% end %> - - <div id="navigation_search"> - <form id="navigation_search_form" method="post" action="<%= search_redirect_path %>"> - <p> - <%= text_field_tag 'query', params[:query], { :size => 40, :id => "navigation_search_query", :title => "type your search term here" } %> - <input id="navigation_search_button" type="submit" value="search"> - </p> - </form> - </div> - - <%= render :partial => 'general/orglink' %> - - <%= render :partial => 'general/topnav' %> - </div> - </div> + <%= render :partial => 'general/header' %> <div id="wrapper"> <div id="content"> <% if flash[:notice] %> diff --git a/app/views/request/_incoming_correspondence.text.erb b/app/views/request/_incoming_correspondence.text.erb index 33ddad926..c5e648d28 100644 --- a/app/views/request/_incoming_correspondence.text.erb +++ b/app/views/request/_incoming_correspondence.text.erb @@ -1,5 +1,5 @@ <%- if not incoming_message.user_can_view?(@user) %> - <%= render :partial => 'request/hidden_correspondence.text', :locals => { :message => incoming_message }%> + <%= render :partial => 'request/hidden_correspondence', :formats => 'text', :locals => { :message => incoming_message }%> <%- else %> <%= _('From:') %><% if incoming_message.specific_from_name? %> <%= incoming_message.safe_mail_from %><% end %><% if incoming_message.from_public_body? %>, <%= @info_request.public_body.name %><% end %> <%= _('To:') %> <% if @info_request.user_name %><%= @info_request.user_name %><% else %><%= "[#{_('An anonymous user')}]"%><% end %> diff --git a/app/views/request/_outgoing_correspondence.text.erb b/app/views/request/_outgoing_correspondence.text.erb index 80c71cc01..5375ef81b 100644 --- a/app/views/request/_outgoing_correspondence.text.erb +++ b/app/views/request/_outgoing_correspondence.text.erb @@ -1,5 +1,5 @@ <%- if not outgoing_message.user_can_view?(@user) %> - <%= render :partial => 'request/hidden_correspondence.text', :locals => { :message => outgoing_message }%> + <%= render :partial => 'request/hidden_correspondence', :formats => 'text', :locals => { :message => outgoing_message }%> <%- else %> <%= _('From:') %> <% if @info_request.user_name %><%= @info_request.user_name %><% else %><%= "[#{_('An anonymous user')}]"%><% end %> <%= _('To:') %> <%= @info_request.public_body.name %> diff --git a/app/views/request/_request_listing_single.html.erb b/app/views/request/_request_listing_single.html.erb index 56737fd3e..50f889d75 100644 --- a/app/views/request/_request_listing_single.html.erb +++ b/app/views/request/_request_listing_single.html.erb @@ -1,9 +1,9 @@ <div class="request_listing"> - <span class="head"> - <%= link_to h(info_request.title), (@play_urls ? categorise_request_path(:url_title => info_request.url_title) : request_path(info_request)) %> - </span> - <span class="desc"> - <%= excerpt(info_request.initial_request_text, "", 150) %> + <span class="head"> + <%= link_to h(info_request.title), (@play_urls ? categorise_request_path(:url_title => info_request.url_title) : request_path(info_request)) %> + </span> + <span class="desc"> + <%= excerpt(info_request.initial_request_text, "", :radius => 150) %> </span> <span class="bottomline icon_<%= info_request.calculate_status %>"> <strong> diff --git a/app/views/request/show.text.erb b/app/views/request/show.text.erb index 29ac2987f..8079d10d5 100644 --- a/app/views/request/show.text.erb +++ b/app/views/request/show.text.erb @@ -4,13 +4,13 @@ <% if info_request_event.visible %> <% case info_request_event.event_type %> <% when 'response' %> - <%= render :partial => 'request/incoming_correspondence.text', :locals => { :incoming_message => info_request_event.incoming_message } %> + <%= render :partial => 'request/incoming_correspondence', :formats => 'text', :locals => { :incoming_message => info_request_event.incoming_message } %> <% when 'sent', 'followup_sent' %> - <%= render :partial => 'request/outgoing_correspondence.text', :locals => { :outgoing_message => info_request_event.outgoing_message, :info_request_event => info_request_event }%> + <%= render :partial => 'request/outgoing_correspondence', :formats => 'text', :locals => { :outgoing_message => info_request_event.outgoing_message, :info_request_event => info_request_event }%> <% when 'resent', 'followup_resent' %> - <%= render :partial => 'request/resent_outgoing_correspondence.text', :locals => { outgoing_message => info_request_event.outgoing_message, :info_request_event => info_request_event }%> + <%= render :partial => 'request/resent_outgoing_correspondence', :formats => 'text', :locals => { outgoing_message => info_request_event.outgoing_message, :info_request_event => info_request_event }%> <% when 'comment' %> - <%= render :partial => 'comment/single_comment.text', :locals => { :comment => info_request_event.comment } %> + <%= render :partial => 'comment/single_comment', :formats => 'text', :locals => { :comment => info_request_event.comment } %> <% end %> ------------------------------- <% end %> diff --git a/app/views/track/atom_feed.atom.erb b/app/views/track/atom_feed.atom.erb index a12b9eff0..be9c39e72 100644 --- a/app/views/track/atom_feed.atom.erb +++ b/app/views/track/atom_feed.atom.erb @@ -9,7 +9,7 @@ # Get the HTML content from the same partial template as website search does content = '' if result[:model].class.to_s == 'InfoRequestEvent' - content += render :partial => 'request/request_listing_via_event.html', :locals => { :event => result[:model], :info_request => result[:model].info_request } + content += render :partial => 'request/request_listing_via_event', :formats => ['html'], :locals => { :event => result[:model], :info_request => result[:model].info_request } else content = "<p><strong>Unknown search result type " + result[:model].class.to_s + "</strong></p>" end diff --git a/config/environment.rb b/config/environment.rb index 196680b23..05f25a29e 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,5 +1,7 @@ + # Load the rails application require File.expand_path('../application', __FILE__) +ActiveSupport::Deprecation.silenced = true # Initialize the rails application Alaveteli::Application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb index ecfad3af7..dbf8d7b2a 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -39,4 +39,11 @@ Alaveteli::Application.configure do # Expands the lines which load the assets config.assets.debug = true + # Raise exception on mass assignment protection for Active Record models + config.active_record.mass_assignment_sanitizer = :strict + + # Log the query plan for queries taking more than this (works + # with SQLite, MySQL, and PostgreSQL) + config.active_record.auto_explain_threshold_in_seconds = 0.5 + end diff --git a/config/environments/test.rb b/config/environments/test.rb index df39e8873..97c2d4f7c 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -24,4 +24,9 @@ Alaveteli::Application.configure do # Print deprecation notices to the stderr config.active_support.deprecation = :stderr + if !AlaveteliConfiguration.exception_notifications_from.blank? && !AlaveteliConfiguration.exception_notifications_to.blank? + middleware.use ExceptionNotifier, + :sender_address => AlaveteliConfiguration::exception_notifications_from, + :exception_recipients => AlaveteliConfiguration::exception_notifications_to + end end diff --git a/config/test.yml b/config/test.yml index b26ca99d4..599e1e81a 100644 --- a/config/test.yml +++ b/config/test.yml @@ -116,7 +116,7 @@ HTML_TO_PDF_COMMAND: /usr/local/bin/wkhtmltopdf-amd64 # Exception notifications EXCEPTION_NOTIFICATIONS_FROM: do-not-reply-to-this-address@example.com -EXCEPTION_NOTIFICATIONS_TO: +EXCEPTION_NOTIFICATIONS_TO: exception-recipient@example.com MAX_REQUESTS_PER_USER_PER_DAY: 2 diff --git a/lib/mail_handler/backends/mail_backend.rb b/lib/mail_handler/backends/mail_backend.rb index 28c486e1b..e019eba97 100644 --- a/lib/mail_handler/backends/mail_backend.rb +++ b/lib/mail_handler/backends/mail_backend.rb @@ -95,7 +95,7 @@ module MailHandler def get_from_address(mail) first_from = first_from(mail) if first_from - if first_from.is_a?(ActiveSupport::Multibyte::Chars) + if first_from.is_a?(String) return nil else return first_from.address @@ -109,7 +109,7 @@ module MailHandler def get_from_name(mail) first_from = first_from(mail) if first_from - if first_from.is_a?(ActiveSupport::Multibyte::Chars) + if first_from.is_a?(String) return nil else return (first_from.display_name || nil) diff --git a/lib/mail_handler/backends/mail_extensions.rb b/lib/mail_handler/backends/mail_extensions.rb index 029331802..87af526bf 100644 --- a/lib/mail_handler/backends/mail_extensions.rb +++ b/lib/mail_handler/backends/mail_extensions.rb @@ -7,54 +7,6 @@ module Mail attr_accessor :within_rfc822_attachment # for parts within a message attached as text (for getting subject mainly) attr_accessor :count_parts_count attr_accessor :count_first_uudecode_count - - # A patched version of the message initializer to work around a bug where stripping the original - # input removes meaningful spaces - e.g. in the case of uuencoded bodies. - def initialize(*args, &block) - @body = nil - @body_raw = nil - @separate_parts = false - @text_part = nil - @html_part = nil - @errors = nil - @header = nil - @charset = 'UTF-8' - @defaulted_charset = true - - @perform_deliveries = true - @raise_delivery_errors = true - - @delivery_handler = nil - - @delivery_method = Mail.delivery_method.dup - - @transport_encoding = Mail::Encodings.get_encoding('7bit') - - @mark_for_delete = false - - if args.flatten.first.respond_to?(:each_pair) - init_with_hash(args.flatten.first) - else - # The replacement of this commented out line is the change. - # init_with_string(args.flatten[0].to_s.strip) - init_with_string(args.flatten[0].to_s) - end - - if block_given? - instance_eval(&block) - end - - self - end - - def set_envelope_header - raw_string = raw_source.to_s - if match_data = raw_source.to_s.match(/\AFrom\s(#{TEXT}+)#{CRLF}/m) - set_envelope(match_data[1]) - self.raw_source = raw_string.sub(match_data[0], "") - end - end - end # A patched version of the parameter hash that handles nil values without throwing @@ -77,6 +29,7 @@ module Mail # HACK: Backport encoding fixes for Ruby 1.8 from Mail 2.5 # Can be removed when we no longer support Ruby 1.8 class Ruby18 + def Ruby18.b_value_decode(str) match = str.match(/\=\?(.+)?\?[Bb]\?(.+)?\?\=/m) if match @@ -129,11 +82,11 @@ module Mail def Ruby19.b_value_decode(str) match = str.match(/\=\?(.+)?\?[Bb]\?(.+)?\?\=/m) if match - encoding = match[1] + charset = match[1] str = Ruby19.decode_base64(match[2]) # Rescue an ArgumentError arising from an unknown encoding. begin - str.force_encoding(fix_encoding(encoding)) + str.force_encoding(pick_encoding(charset)) rescue ArgumentError end end @@ -141,18 +94,5 @@ module Mail decoded.valid_encoding? ? decoded : decoded.encode("utf-16le", :invalid => :replace, :replace => "").encode("utf-8") end - def Ruby19.q_value_decode(str) - match = str.match(/\=\?(.+)?\?[Qq]\?(.+)?\?\=/m) - if match - encoding = match[1] - str = Encodings::QuotedPrintable.decode(match[2].gsub(/_/, '=20')) - # Backport line from mail 2.5 to strip a trailing = character - # Remove trailing = if it exists in a Q encoding - str = str.sub(/\=$/, '') - str.force_encoding(fix_encoding(encoding)) - end - decoded = str.encode("utf-8", :invalid => :replace, :replace => "") - decoded.valid_encoding? ? decoded : decoded.encode("utf-16le", :invalid => :replace, :replace => "").encode("utf-8") - end end end diff --git a/lib/no_constraint_disabling.rb b/lib/no_constraint_disabling.rb index d515a959a..32a4a6bfe 100644 --- a/lib/no_constraint_disabling.rb +++ b/lib/no_constraint_disabling.rb @@ -47,7 +47,7 @@ module ActiveRecord connection, table_name, class_names[table_name.to_sym] || table_name.classify, - File.join(fixtures_directory, path)) + ::File.join(fixtures_directory, path)) end all_loaded_fixtures.update(fixtures_map) diff --git a/script/handle-mail-replies.rb b/script/handle-mail-replies.rb index da0fc8e96..cbff03acb 100755 --- a/script/handle-mail-replies.rb +++ b/script/handle-mail-replies.rb @@ -20,6 +20,9 @@ $:.push(File.join($alaveteli_dir, "lib", "mail_handler")) load 'configuration.rb' MySociety::Config.set_file(File.join($alaveteli_dir, 'config', 'general'), true) MySociety::Config.load_default + + +require 'active_support/all' require 'mail_handler' if RUBY_VERSION.to_f >= 1.9 # the default encoding for IO is utf-8, and we use utf-8 internally diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb index aa351bd94..bc027eaec 100644 --- a/spec/lib/mail_handler/mail_handler_spec.rb +++ b/spec/lib/mail_handler/mail_handler_spec.rb @@ -235,7 +235,7 @@ describe 'when deriving a name, email and formatted address from a message from it 'should quote a name with quotes in it' do should_render_from_address('"FOI \" Person" <foiperson@localhost>', - ['FOI \" Person', + ['FOI " Person', 'foiperson@localhost', '"FOI \" Person" <foiperson@localhost>']) end diff --git a/spec/lib/sendmail_return_path_spec.rb b/spec/lib/sendmail_return_path_spec.rb deleted file mode 100644 index 83436c2bd..000000000 --- a/spec/lib/sendmail_return_path_spec.rb +++ /dev/null @@ -1,88 +0,0 @@ -# This is a test of the monkey patches in sendmail_return_path.rb - -# In Rails 3 the monkeypatches are not needed anymore because sendmail now has the "-f" flag -# set correctly. So, strictly these tests are testing the Rails internals. So, that means we really -# should delete them. Let's do that later when things have settled down. For the time being leave -# them in - -require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') - -describe "when sending email with an altered return path" do - before(:each) { ActionMailer::Base.deliveries = [] } - - it "should default to delivery method test" do - ActionMailer::Base.delivery_method.should == :test - end - - it "should let the helper change the method" do - with_delivery_method :smtp do - ActionMailer::Base.delivery_method.should == :smtp - end - ActionMailer::Base.delivery_method.should == :test - end - - # Documentation for fancy mock functions: http://rspec.info/documentation/mocks/message_expectations.html - it "should set the return path when sending email using SMTP" do - mock_smtp = mock("smtp") - mock_smtp_session = mock("smtp_session") - - mock_smtp.should_receive(:start).once.and_yield(mock_smtp_session) - # the second parameter to the SMTP session is the sender (return path) - mock_smtp_session.should_receive(:sendmail).once.with(anything(), "test@localhost", anything()) - - Net::SMTP.stub!(:new).and_return(mock_smtp) - - with_delivery_method :smtp do - ContactMailer.to_admin_message( - "Mr. Test", "test@localhost", "Test script spec/lib/sendmail_return_path_spec.rb", - "This is just a test for a test script", nil, nil, nil - ).deliver - end - - deliveries = ActionMailer::Base.deliveries - deliveries.size.should == 0 - end - - it "should set the return path when sending email using sendmail" do - with_stub_popen do - IO.should_receive(:popen).once.with('/usr/sbin/sendmail -i -t -f "test@localhost" postmaster@localhost', "w+") - with_delivery_method :sendmail do - ContactMailer.to_admin_message( - "Mr. Test", "test@localhost", "Test script spec/lib/sendmail_return_path_spec.rb", - "This is just a test for a test script", nil, nil, nil - ).deliver - end - end - - deliveries = ActionMailer::Base.deliveries - deliveries.size.should == 0 - end - - - protected - # Change the way Rails delivers memory, just for current scope - def with_delivery_method(new_delivery_method) - old_delivery_method, ActionMailer::Base.delivery_method = ActionMailer::Base.delivery_method, new_delivery_method - yield - ensure - ActionMailer::Base.delivery_method = old_delivery_method - end - - # By default, we can't stub popen, presumably because it is a builtin written in C. - # Replace it entirely with a normal method that just calls the C one, so we can stub it - - # this leaves IO working afterwards (for other tests that run in the same instance). - def with_stub_popen() - IO.class_eval "@orig_popen = self.method(:popen); def self.popen(a, b, &c); @orig_popen.call(a, b, &c); end" - begin - yield - ensure - # in theory would undo the popen alterations and return IO to a pristine state, but - # don't know how to (much fiddling with alias bind and the like didn't help). It - # doesn't matter - the new popen should behave just the same. - end - end - - -end - - diff --git a/spec/mailers/application_mailer_spec.rb b/spec/mailers/application_mailer_spec.rb index d8993f78f..718ac47fb 100644 --- a/spec/mailers/application_mailer_spec.rb +++ b/spec/mailers/application_mailer_spec.rb @@ -13,7 +13,7 @@ describe ApplicationMailer do end def add_mail_methods(method_names) - method_names.each{ |method_name| ApplicationMailer.send(:define_method, method_name){} } + method_names.each{ |method_name| ApplicationMailer.send(:define_method, method_name){ mail() } } end def remove_mail_methods(method_names) |