aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/incoming_message.rb15
-rw-r--r--spec/models/incoming_message_spec.rb8
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