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

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.
F0aaa796f43b5c4bc21db2051ecb4bfa?d=identicon&s=25 Mariano Kamp (Guest)
on 2006-05-25 19:37
(Received via mailing list)
Hi,

   does anybody know if TMail supports nested multipart messages? I read
a changelog that indicates so
(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 to parse it:

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
Rails@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails

!

   So the message is broken off at some point that looks arbitrary to me
(emai, 4th non-empty line from the bottom).

   Any idea?

Cheers,
Mariano
921432719b51a266a06878ff4128a7b1?d=identicon&s=25 Dae San Hwang (Guest)
on 2006-05-25 19:50
(Received via mailing list)
Mariano,

Maybe you want to explain why you need nested multipart support?  I
can't answer your question but, if you explain what the use of such
functionality is, I may dig more into it.

Cheers,
daesan


On May 26, 2006, at 2:34 AM, Mariano Kamp wrote:

>
>
>       end
>
>                                     :conditions =>
>   Any idea?
>
> Cheers,
> Mariano
> <sample>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails

Dae San Hwang
daesan@gmail.com
F0aaa796f43b5c4bc21db2051ecb4bfa?d=identicon&s=25 Mariano Kamp (Guest)
on 2006-05-25 20:09
(Received via mailing list)
Hi Dae,

  thanks for showing some interest in it :-)

  A multipart message is a message that consists of more than one MIME
part. A nested mutlipart message consists of a mutlipart message that
contains other parts.

  So for example the email you'll find in the attachment contains two
parts that are alternatives for each other, one is text/plain and the
other one is the text/html representation of the same content. Both
are  encoded ISO-8859-1 .. And then there is a last part in the mail
that contains the RoR mailing list footer in text/plain, encoded as
US-ASCII.

  So reading the changelog mentionend below I found the following:
>>*1.0.0* (6 July, 2005)
>>
>> ...
>> * Better multipart support with implicit multipart/alternative and
sorting of subparts [John Long]
>> * Allow for nested parts in multipart mails #1570 [Flurin Egger]

When looking at this bug this seems more like an Action Mailer thing.
On the other hand though, TMail seems to be part of the Action Mailer
libraries.

I can also view the offending mail (see attachment) with ruby-forum
(http://www.ruby-forum.com/topic/66359)... And they use TMail too.

So I guess I am doing something wrong here, but I am not sure what.

Cheers,
Mariano
F0aaa796f43b5c4bc21db2051ecb4bfa?d=identicon&s=25 Mariano Kamp (Guest)
on 2006-05-26 12:40
(Received via mailing list)
It works now.

So the short answert to my question is: Yes, TMail supports Nested
Mulipart Messages.

Why didn't that work for me?

TMail uses message_text.unpack('M*') to unpack quoted printables.
Unfortunately this chokes on CR/LFs. After replacing CR/LFs with LFs
it works now.

Cheers,
Mariano
921432719b51a266a06878ff4128a7b1?d=identicon&s=25 Dae San Hwang (Guest)
on 2006-05-26 15:51
(Received via mailing list)
Glad to hear that you solved the problem.

Maybe you should report that to http://i.loveruby.net/en/projects/tmail/

cheers,
Daesan

On May 26, 2006, at 7:37 PM, Mariano Kamp wrote:

>
>> part. A nested mutlipart message consists of a mutlipart message that
>> >>*1.0.0* (6 July, 2005)
>> I can also view the offending mail (see attachment) with ruby-forum
>> > Maybe you want to explain why you need nested multipart support?  I
>> > >
>> > >   I attached the sample mail. Here is the code to parse it:
>> > >   end
>> > >         end
>> > > body=!Hi,
>> > > email_addresses on
>> > >   So the message is broken off at some point that looks arbitrary
>> > > http://lists.rubyonrails.org/mailman/listinfo/rails
>> >
>>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails

Dae San Hwang
daesan@gmail.com
This topic is locked and can not be replied to.