# Does TMail support Nested Multipart Messages? (Repost)

**URL:** <https://www.ruby-forum.com/t/does-tmail-support-nested-multipart-messages-repost/61633>\
**Category:** Rails\
**Created:** [May 25, 2006, 7:37pm UTC](https://www.ruby-forum.com/t/does-tmail-support-nested-multipart-messages-repost/61633 "2006-05-25T19:37:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mariano\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@Mariano\_K](https://www.ruby-forum.com/u/Mariano_K)\
**Post date:** [May 25, 2006, 7:37pm UTC](https://www.ruby-forum.com/t/does-tmail-support-nested-multipart-messages-repost/61633/1 "2006-05-25T19:37:50Z")

</div>

Hi,

does anybody know if TMail supports nested multipart messages? I read  
a changelog that indicates so  
([http://dev.rubyonrails.org/svn/rails/trunk/actionmailer/CHANGELOG](http://dev.rubyonrails.org/svn/rails/trunk/actionmailer/CHANGELOG)), 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  
removed\_email\_address@domain.invalid  
[http://lists.rubyonrails.org/mailman/listinfo/rails](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

---

<div class="post-metadata">

**Author:** ![Mariano\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@Mariano\_K](https://www.ruby-forum.com/u/Mariano_K)\
**Post date:** [May 25, 2006, 7:50pm UTC](https://www.ruby-forum.com/t/does-tmail-support-nested-multipart-messages-repost/61633/2 "2006-05-25T19:50:57Z")

</div>

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 K. wrote:

> ```
> end
> 
> :conditions =>  
> 
> ```
> 
> Any idea?
> 
> Cheers,  
> Mariano
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

Dae San H.  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![Mariano\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@Mariano\_K](https://www.ruby-forum.com/u/Mariano_K)\
**Post date:** [May 25, 2006, 8:09pm UTC](https://www.ruby-forum.com/t/does-tmail-support-nested-multipart-messages-repost/61633/3 "2006-05-25T20:09:37Z")

</div>

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 L.]
> > - 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  
([Problem with joins and overlapping field names - Rails - 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

---

<div class="post-metadata">

**Author:** ![Mariano\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@Mariano\_K](https://www.ruby-forum.com/u/Mariano_K)\
**Post date:** [May 26, 2006, 3:51pm UTC](https://www.ruby-forum.com/t/does-tmail-support-nested-multipart-messages-repost/61633/4 "2006-05-26T15:51:59Z")

</div>

Glad to hear that you solved the problem.

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

cheers,  
Daesan

On May 26, 2006, at 7:37 PM, Mariano K. 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](http://lists.rubyonrails.org/mailman/listinfo/rails)
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

Dae San H.  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![Mariano\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eada6e/32.png) [@Mariano\_K](https://www.ruby-forum.com/u/Mariano_K)\
**Post date:** [May 26, 2006, 12:40pm UTC](https://www.ruby-forum.com/t/does-tmail-support-nested-multipart-messages-repost/61633/5 "2006-05-26T12:40:02Z")

</div>

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
