Wrong content-type when trying to parse emails with Net::IMA

i’m trying to parse an email that is supposed to be a multipart/mixed
mail but i am not getting back the expected results.

data = imap.fetch(7, [“ENVELOPE”, “RFC822.HEADER”, “BODYSTRUCTURE”,
“BODY[1]”])

[RFC822.HEADER]
…[some headers removed to protect the innocent]…
From: [email protected]
To: [email protected]
Date: Thu, 31 Aug 2006 19:03:07 -05:00
Content-type: Multipart/Mixed; boundary=Message-Boundary-22611
X-finfo: DOS,“FOOBAR.ZIP”,
Subject: foobar inc. in stock inventory
Priority: normal
X-mailer: Pegasus Mail v3.50
Message-ID: [email protected]

[BODYSTRUCTURE]
#<struct Net::IMAP::BodyTypeText media_type=“TEXT”, subtype=“PLAIN”,
param={“CHARSET”=>“US-ASCII”}, content_id=nil, description=nil,
encoding=“7BIT”, size=218060, lines=2959, md5=nil, disposition=nil,
language=nil, extension=nil>

[BODY[1]
–Message-Boundary-22611
Content-type: text/plain; charset=US-ASCII
Content-description: blah blah blah

blah blah blah
–Message-Boundary-22611
Content-Type: Application/Octet-stream; name=FOOBAR.ZIP
Content-transfer-encoding: BASE64

…[base64 encoded data]…
–Message-Boundary-22611–

as you can see above, the content-type is clearly multipart/mixed, but
yet, when i dump the bodystructure, i get text/plain. the size and
lines corresponds to the size/lines of the body of the email.

anyone got any ideas on this one?

Chris

Chris H. wrote:

i’m trying to parse an email that is supposed to be a multipart/mixed
mail but i am not getting back the expected results.

What did you expect?

/ …

as you can see above, the content-type is clearly multipart/mixed, but
yet, when i dump the bodystructure, i get text/plain. the size and
lines corresponds to the size/lines of the body of the email.

anyone got any ideas on this one?

Sure. In e-mails everything is plain text – it has to be, in order to
be
acceptable to the protocol. Therefore the content encoding is set up to
consist entirely of ASCII characters. It is up to the receiving software
to
convert this plain-text form into graphics or whatever the content
actually
represents.

On 29-Sep-06, at 4:45 PM, Paul L. wrote:

What paul means is that the Net::IMAP just returns the text, and
you’ll have to parse the MIME attachments from the text that is in
the body

Just out of curiosity, is there a lib in ruby to do this?


Paul L.
http://www.arachnoid.com

Matt

ok, maybe i overexplained…

if i look at the RFC822.HEADER, it says

Content-type: Multipart/Mixed; boundary=Message-Boundary-22611

however, BODYSTRUCTURE says otherwise

#<struct Net::IMAP::BodyTypeText media_type=“TEXT”, subtype=“PLAIN”,
param={“CHARSET”=>“US-ASCII”}, content_id=nil, description=nil,
encoding=“7BIT”, size=218060, lines=2959, md5=nil, disposition=nil,
language=nil, extension=nil>

the size and lines correspond to the size of the entire mail.

BODYSTRUCTURE should be Net::IMAP::BodyTypeMultipart

BODY[1] shows:

–Message-Boundary-22611
Content-type: text/plain; charset=US-ASCII
Content-description: blah blah blah

blah blah blah
–Message-Boundary-22611
Content-Type: Application/Octet-stream; name=FOOBAR.ZIP
Content-transfer-encoding: BASE64

…[base64 encoded data]…
–Message-Boundary-22611–

if BODYSTRUCTURE were multipart, the above would have been parsed by
Net::IMAP into the corresponding parts for me to parse, each part
being BodyTypeText and BodyTypeBasic respectively.

now, what i would EXPECT, is that the BODYSTRUCTURE corresponds with
the header and should be multipart/mixed, which would then allow me to
grab the parts described above, but as i have explained this is not
the case. I deal with other emails that are structured the same way
and the BODYSTRUCTURE does in fact show as multipart/mixed

so the only thing i can surmise from this is that Net::IMAP is not
interpreting the content-type of the mail correctly and defaults to
text/plain us-ascii, as described in the RFC. now whether it’s a
problem internal to Net::IMAP or perhaps the message itself (it was
sent using Pegasus Mail v3.50, a DOS application), i have no way of
knowing, and was looking for insight.

Chris

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs