aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/incoming_message.rb31
-rw-r--r--app/models/public_body_change_request.rb9
2 files changed, 21 insertions, 19 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb
index 59e61952e..6db145348 100644
--- a/app/models/incoming_message.rb
+++ b/app/models/incoming_message.rb
@@ -35,7 +35,7 @@
require 'htmlentities'
require 'rexml/document'
require 'zip/zip'
-require 'iconv' unless RUBY_VERSION >= '1.9'
+require 'iconv' unless String.method_defined?(:encode)
class IncomingMessage < ActiveRecord::Base
extend MessageProminence
@@ -294,7 +294,7 @@ class IncomingMessage < ActiveRecord::Base
emails = ascii_chars.scan(MySociety::Validate.email_find_regexp)
# Convert back to UCS-2, making a mask at the same time
- if RUBY_VERSION >= '1.9'
+ if String.method_defined?(:encode)
emails.map! do |email|
# We want the ASCII representation of UCS-2
[email[0].encode('UTF-16LE').force_encoding('US-ASCII'),
@@ -520,7 +520,7 @@ class IncomingMessage < ActiveRecord::Base
# should instead tell elinks to respect the source
# charset
use_charset = "utf-8"
- if RUBY_VERSION.to_f >= 1.9
+ if String.method_defined?(:encode)
begin
text.encode('utf-8')
rescue Encoding::UndefinedConversionError, Encoding::InvalidByteSequenceError
@@ -551,7 +551,7 @@ class IncomingMessage < ActiveRecord::Base
end
def _sanitize_text(text)
- if RUBY_VERSION.to_f >= 1.9
+ if String.method_defined?(:encode)
begin
# Test if it's good UTF-8
text.encode('utf-8')
@@ -796,27 +796,28 @@ class IncomingMessage < ActiveRecord::Base
return self.cached_attachment_text_clipped
end
- def _get_attachment_text_internal
+ def _extract_text
# Extract text from each attachment
- text = ''
- attachments = self.get_attachments_for_display
- for attachment in attachments
- text += MailHandler.get_attachment_text_one_file(attachment.content_type,
+ self.get_attachments_for_display.reduce(''){ |memo, attachment|
+ memo += MailHandler.get_attachment_text_one_file(attachment.content_type,
attachment.body,
attachment.charset)
- end
+ }
+ end
+
+ def _get_attachment_text_internal
+ text = self._extract_text
# Remove any bad characters
- if RUBY_VERSION >= '1.9'
- text.encode("utf-8", :invalid => :replace,
- :undef => :replace,
- :replace => "")
+ if String.method_defined?(:encode)
+ # handle "problematic" encoding
+ text.encode!('UTF-16', 'UTF-8', :invalid => :replace, :undef => :replace, :replace => '')
+ text.encode('UTF-8', 'UTF-16')
else
Iconv.conv('utf-8//IGNORE', 'utf-8', text)
end
end
-
# Returns text for indexing
def get_text_for_indexing_full
return get_body_for_quoting + "\n\n" + get_attachment_text_full
diff --git a/app/models/public_body_change_request.rb b/app/models/public_body_change_request.rb
index c1f395c0c..0e59cbecc 100644
--- a/app/models/public_body_change_request.rb
+++ b/app/models/public_body_change_request.rb
@@ -75,7 +75,8 @@ class PublicBodyChangeRequest < ActiveRecord::Base
def thanks_notice
if self.public_body
- _("Your request to update the address for #{get_public_body_name} has been sent. Thank you for getting in touch! We'll get back to you soon.")
+ _("Your request to update the address for {{public_body_name}} has been sent. Thank you for getting in touch! We'll get back to you soon.",
+ :public_body_name => get_public_body_name)
else
_("Your request to add an authority has been sent. Thank you for getting in touch! We'll get back to you soon.")
end
@@ -89,12 +90,12 @@ class PublicBodyChangeRequest < ActiveRecord::Base
end
def comment_for_public_body
- comments = [_("Requested by: #{get_user_name} (#{get_user_email})")]
+ comments = ["Requested by: #{get_user_name} (#{get_user_email})"]
if !source_url.blank?
- comments << _("Source URL: #{source_url}")
+ comments << "Source URL: #{source_url}"
end
if !notes.blank?
- comments << _("Notes: #{notes}")
+ comments << "Notes: #{notes}"
end
comments.join("\n")
end