aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/mail_handler/backends/mail_backend.rb11
-rw-r--r--spec/lib/mail_handler/mail_handler_spec.rb14
2 files changed, 15 insertions, 10 deletions
diff --git a/lib/mail_handler/backends/mail_backend.rb b/lib/mail_handler/backends/mail_backend.rb
index 6c213d370..a97e68138 100644
--- a/lib/mail_handler/backends/mail_backend.rb
+++ b/lib/mail_handler/backends/mail_backend.rb
@@ -242,8 +242,15 @@ module MailHandler
def _get_attachment_leaves_recursive(part, within_rfc822_attachment, parent_mail)
leaves_found = []
if part.multipart?
- raise "no parts on multipart mail" if part.parts.size == 0
- if part.sub_type == 'alternative'
+ if part.parts.size == 0
+ # This is typically caused by a missing final
+ # MIME boundary, in which case the text of the
+ # message (including the opening MIME
+ # boundary) is in part.body, so just add this
+ # part as a leaf and treat it as text/plain:
+ part.content_type = "text/plain"
+ leaves_found += [part]
+ elsif part.sub_type == 'alternative'
best_part = choose_best_alternative(part)
leaves_found += _get_attachment_leaves_recursive(best_part,
within_rfc822_attachment,
diff --git a/spec/lib/mail_handler/mail_handler_spec.rb b/spec/lib/mail_handler/mail_handler_spec.rb
index c49e2ea07..d4f5737bb 100644
--- a/spec/lib/mail_handler/mail_handler_spec.rb
+++ b/spec/lib/mail_handler/mail_handler_spec.rb
@@ -352,14 +352,12 @@ describe 'when getting attachment attributes' do
end
it 'should cope with a missing final MIME boundary' do
- pending do
- mail = get_fixture_mail('multipart-no-final-boundary.email')
- attributes = MailHandler.get_attachment_attributes(mail)
- attributes.length.should == 1
- attributes[0][:body].should match(/This is an acknowledgement of your email/)
- attributes[0][:content_type].should == "text/html"
- attributes[0][:url_part_number].should == 1
- end
+ mail = get_fixture_mail('multipart-no-final-boundary.email')
+ attributes = MailHandler.get_attachment_attributes(mail)
+ attributes.length.should == 1
+ attributes[0][:body].should match(/This is an acknowledgement of your email/)
+ attributes[0][:content_type].should == "text/plain"
+ attributes[0][:url_part_number].should == 1
end
it 'should ignore a TNEF attachment with no usable contents' do