Forum: Ruby 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 16:21
(Received via mailing list)
Hi,

  does anybody know if TMail supports multipart messages?

  I am using TMail at the moment, but it doesn't seem to work for me.
Maybe
I am doing something wrong here?

  I attached the sample and below is the code. 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, arbitrary to me.
Cheers,
Mariano

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
This topic is locked and can not be replied to.