diff options
author | Rowan Crawford <wombleton@gmail.com> | 2014-02-23 18:09:35 +1300 |
---|---|---|
committer | Rowan Crawford <wombleton@gmail.com> | 2014-02-23 18:09:35 +1300 |
commit | 71deb85e4460d255e04741e6d1e2850f9ace1fd5 (patch) | |
tree | c98a49fa4e9b0054464c5d53eefac72d2253b5bf | |
parent | efea8f2aa0ac36e83b15f3a56f9f243467f8225b (diff) |
Add test for _get_attachment_text_internal with invalid utf-8
-rw-r--r-- | app/models/incoming_message.rb | 15 | ||||
-rw-r--r-- | spec/models/incoming_message_spec.rb | 8 |
2 files changed, 15 insertions, 8 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb index 32123ae49..52f28a3fd 100644 --- a/app/models/incoming_message.rb +++ b/app/models/incoming_message.rb @@ -792,15 +792,17 @@ 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 String.method_defined?(:encode) @@ -812,7 +814,6 @@ class IncomingMessage < ActiveRecord::Base 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/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb index c0a7e5340..9c45b34b5 100644 --- a/spec/models/incoming_message_spec.rb +++ b/spec/models/incoming_message_spec.rb @@ -742,5 +742,11 @@ describe IncomingMessage, "when extracting attachments" do attachments.first.body.should == 'No way!' end -end + it 'makes invalid utf-8 encoded attachment text valid' do + im = incoming_messages(:useless_incoming_message) + im.stub!(:extract_text).and_return("\xBF") + + im._get_attachment_text_internal.valid_encoding?.should be_true + end +end |