[Tmail-talk] Dealing with duplicate attachments/parts

Morten lists at kikobu.com
Fri Nov 14 06:22:50 EST 2008

Hi, thanks for the feedback on this, much appreciated.

Here's a sample of a Lotus Notes mail which uses a part instead of  


Here's a sample of a mail which has both parts and attachments (not  
Lotus notes, I confused the two, looks like some MS Exchange/OLE stuff):


For the latter, the attachments appear both as parts and attachments,  
not sure if this is a TMail issue (they're only in there once)

 >> m.attachments.size
=> 3
 >> m.parts.size
=> 4

And also, the generic headers hash is not case insensitive it seems:

 >> m.parts.last.header['content-type']
=> #<TMail::ContentTypeHeader "image/gif;\r\n name=\"ATT84490317.gif\"">
 >> m.parts.last.header['Content-Type']
=> nil

If I use m.parts.last.content_type I get the content type fine, but I  
need the raw header to access the name attribute.

For now, my work around is to scan for parts of specific content types  
(pdf, jpg, gif etc.) and check that the mail does not also have  
I will try and dig into the test cases for header case sensitivity,  
but could use some direction in the parts/attachment issue. This is  
TMail 1.2.3 BTW.



On Nov 14, 2008, at 3:21 AM, Mikel Lindsaar wrote:

> On Fri, Nov 14, 2008 at 8:05 AM, Morten <lists at kikobu.com> wrote:
> On Nov 13, 2008, at 9:45 PM, Peter Burkholder wrote:
> On Nov 13, 2008, at 8:11 AM, Morten wrote:
> This means that some files sent with the emails, appear both as a  
> part and an attachment (case 3). I would like to support all three  
> cases, but not read the same file twice (case 3 - as part AND  
> attachment). My guess is, that I will need to compare file names:
>  What mailers have you seen do this?
> Lotus Notes 2004 (I know...)
> Ouch
> >> m.parts.last.header['content-type'].params['name']
> => "ATT84490317.gif"
> >> m.attachments.last.original_filename
> => "ATT84490317.gif"
> But in this approach, the m.parts.last.header['content- 
> type'].params['name'] section is not very robust (the content-type  
> header could be cased like Content-Type for example). Is there a  
> better way?
> IIRC, the header hashes are case-insensitive.
> This is correct, TMail downcases everything in the main and sub  
> types (look at the ContentTypeHeader class in header.rb (around line  
> 750)
> It wasn't for the above, an also, the above approach just seems  
> rickety in general, perhaps there's no "name" params in the content- 
> type header, perhaps there's no disposition with the info either. I  
> take it that sending "non text" as a part is considered bad behavior  
> by most mail clients (we've processed hundreds of thousands of  
> emails and not seen this before now).
> TMail is pretty good at handling attachments and edge cases.
> There are a bunch of tests in test_mail for this, but all the new  
> edge case attachment problems I am putting in test_attachments.rb.   
> If you can find a test case which should work but doesn't, please  
> let me know.
> Mikel
> -- 
> http://lindsaar.net/
> Rails, RSpec and Life blog....
> _______________________________________________
> Tmail-talk mailing list
> Tmail-talk at rubyforge.org
> http://rubyforge.org/mailman/listinfo/tmail-talk

More information about the Tmail-talk mailing list