Forum: Ruby on Rails Does TMail support Nested Multipart Messages?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Mariano K. (Guest)
on 2006-05-23 17:09
(Received via mailing list)
Hi,

  does anybody know if TMail supports nested multipart messages? I read
a
changelog that indicates this ...
http://dev.rubyonrails.org/svn/rails/trunk/actionm..., but I
haven't been able to get it working so far.

  Maybe I am doing something wrong here?

  I attached the sample mail. Here is the code:

require File.dirname(__FILE__) + '/../test_helper'

class TMailTest < Test::Unit::TestCase

  def test_multiparts
    assert raw = File.read("sample")
    assert mail = TMail::Mail.parse (raw)
    puts "body=!#{body_as_plain_text(mail)}!"
  end

  def body_as_plain_text(part)
    body = ''
    if part.multipart?
      part.parts.each do |subpart|
        if subpart.content_type == 'text/plain' and
subpart.content_disposition == 'inline'
          body << subpart.body
        elsif subpart.content_type =~ /^multipart/
          body << body_as_plain_text(subpart)
        end
      end
    else
      body = part.body
    end
    body
  end
end

 The output looks like this:

body=!Hi,

   I have the following code:
         @conversation_pages,
          @conversations = paginate(:conversations,
                                    :per_page => 20,
                                    :joins => 'LEFT JOIN messages on
messages.conversation_id = conversations.id '+
                                              'LEFT JOIN email_addresses
on
email_addresses.id = messages.email_address_id',
                                    :conditions =>
['email_addresses.emai_______________________________________________
Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails

!

  So the message is broken off at some point that looks arbitrary to me.

  Any idea?

Cheers,
Mariano
This topic is locked and can not be replied to.