Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting Binary Data from MIME Email Message

Status
Not open for further replies.

yvrMarc

Programmer
Nov 22, 2010
4
CA
Hi

My program downloads multipart/mime messages from a remote server and saves them to an Outlook email file (*.eml). I can open the email message in Outlook and view/process the attachments, however I want to automate this.

I want to be able to open the *.eml file in Binary mode and extract the binary content and ignore the email header information (which is in text). The "Content-Length" parameter of the email header tells me the amount of binary content to extract but I cannot determime the byte position of the BOF of the binary file. Here is an example of the message that I am trying to parse:

[tt]
--------------Boundary-144574622.1290485831618@SYSQ
MIME-Version: 1.0
From: <>
Message-Id: <13239313.69759121290467473014.JavaMail.>
Date: Mon, 22 Nov 2010 23:11:13 GMT
Accept: application/pkcs7-mime; text/plain
Disposition-notification-to: <>
Disposition-notification-options: signed-receipt-protocol=required,pkcs7-signature; signed-receipt-micalg=required,sha1
Receipt-delivery-option:
Content-Type: Application/pkcs7-mime
Content-Length: 26718

0‚hZ *†H†÷

<<<26718 of binary>>>

È<Ø? §Ðû²- Æ?ía(LÒà0²+3ÌF°'6 }a°q!ÜNJRÜn=É!ÛÀZŸëNC

--------------Boundary-144574622.1290485831618@SYSQ
MIME-Version: 1.0
From: <>
Message-Id: <29295355.61553261290208372191.JavaMail.>
Date: Fri, 19 Nov 2010 23:12:52 GMT
Accept: application/pkcs7-mime; text/plain
Disposition-notification-to: <>
Disposition-notification-options: signed-receipt-protocol=required,pkcs7-signature; signed-receipt-micalg=required,sha1
Receipt-delivery-option:
Content-Type: Application/pkcs7-mime
Content-Length: 26726

0‚hb *†H†÷

<<<26726>>> of binary

}°Ù÷" µkÌ¢öäFØlø)OhjKU TStðÉqÒÃôù;ò5®{ã æ‡¼kÕ2Üï?ýëà(*»Ëö«=—?@Ì[½KlÙ ?;?àÅðÍüÖYâF

--------------Boundary-144574622.1290485831618@SYSQ--
[/tt]

Does anyone have any ideas how to do this?

Thanks in advance
 
>I cannot determime the byte position of the BOF of the binary file


The format of each MIME part is essentially just like a standard RFC/822 formatted message. It will contain a series of headers, followed by a blank line, then the body data.

In other words your BOf for the binary file should start immediately after the blank line after the header.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top