diff options
author | Francis Irving <francis@mysociety.org> | 2010-03-09 18:22:27 +0000 |
---|---|---|
committer | Francis Irving <francis@mysociety.org> | 2010-03-09 18:22:27 +0000 |
commit | 8766756cba914881a41cae3fa0ca1123c7eca99c (patch) | |
tree | 02ef59fed184c6c6258c2276beb6582e89a0c2bb | |
parent | 32ebcc8ebd82c33a29196e5456ea5e84a0ced59c (diff) |
Prefer HTML to other alternative types
-rw-r--r-- | app/models/incoming_message.rb | 11 | ||||
-rw-r--r-- | spec/models/incoming_message_spec.rb | 2 |
2 files changed, 10 insertions, 3 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb index 003499344..81cbffe06 100644 --- a/app/models/incoming_message.rb +++ b/app/models/incoming_message.rb @@ -751,15 +751,22 @@ class IncomingMessage < ActiveRecord::Base if curr_mail.sub_type == 'alternative' # Choose best part from alternatives best_part = nil + # Take the last text/plain one, or else the first one curr_mail.parts.each do |m| - # Take the first one, or the last text/plain one - # XXX - could do better! if not best_part best_part = m elsif m.content_type == 'text/plain' best_part = m end end + # Take an HTML one as even higher priority. (They tend + # to render better than text/plain, e.g. don't wrap links here: + # http://www.whatdotheyknow.com/request/amount_and_cost_of_freedom_of_in#incoming-72238 ) + curr_mail.parts.each do |m| + if m.content_type == 'text/html' + best_part = m + end + end leaves_found += _get_attachment_leaves_recursive(best_part, within_rfc822_attachment) else # Add all parts diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb index cf51c8a42..eb7126540 100644 --- a/spec/models/incoming_message_spec.rb +++ b/spec/models/incoming_message_spec.rb @@ -263,7 +263,7 @@ describe IncomingMessage, "when Outlook messages are attached to messages" do attachments = im.get_attachments_for_display attachments.size.should == 2 - attachments[0].display_filename.should == 'test.txt' + attachments[0].display_filename.should == 'test.html' # picks HTML rather than text by default, as likely to render better attachments[1].display_filename.should == 'attach.txt' end end |