akohan
asked on
dealing with email attachement
Hello group,
Using a C# class I am able to open a file on POP3 server (Thanks to CodeProject) but now the issues is that the attached PDF file to email is in encoded into base64 (algorithm) I guess. How can I save it as a real PDF file now?
Any help is appreciated.
Regards,
ak
Content-Transfer-Encoding: base64
Content-ID: <931142921@25062009-2C73>
Content-Description: image002.jpg
Content-Location: image002.jpg
/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAoHBwgHBgoICAgLCgoLDhgQDg0NDh0VFhEYIx8lJCIf
IiEmKzcvJik0KSEiMEExNDk7Pj4+JS5ESUM8SDc9Pjv/2wBDAQoLCw4NDhwQEBw7KCIoOzs7Ozs7
Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozv/wAARCACHAJoDASIA
AhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA
and more ...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Where the encoded content starts is defined in the protocol definition for the email format (in this cases POP3/SMTP.
Seeing the simple example you give, that would be right after the headers and any whitespace following them, so at the beginning of line 6.
If the file is an attachment instead of inlined in the email, it could well be contained as encoded data inside the headers.
Seeing the simple example you give, that would be right after the headers and any whitespace following them, so at the beginning of line 6.
If the file is an attachment instead of inlined in the email, it could well be contained as encoded data inside the headers.
Headers should have a single cariage return between each of them and a double carriage return after the last one.
The carriage returns mentioned are actually \r\n (CR followed by a line feed)
eg:
Content-Transfer-Encoding: base64\r\n
Content-ID: <931142921@25062009-2C73>\ r\n
Content-Description: image002.jpg\r\n
Content-Location: image002.jpg\r\n
\r\n
CONTENT_HERE
eg:
Content-Transfer-Encoding:
Content-ID: <931142921@25062009-2C73>\
Content-Description: image002.jpg\r\n
Content-Location: image002.jpg\r\n
\r\n
CONTENT_HERE
Also between each section should be something like this
------_=_NextPart_001_01C9FAF9.FBDB9745
As mentioned above, check the email specification for what to look for. Each section should tell you what the "boundary" is for the next section as shown below
Content-Type: multipart/mixed; boundary="=======AVGMAIL-31DB56D0======="
--=======AVGMAIL-31DB56D0=======
Content-Type: multipart/related;
boundary=----_SmarterMail_NextPart_5110738565878520
Which shows you how one boundary leads on to another
ASKER
Hello all,
Thanks for your comments and hints. Does this mean that I should read it line by line? Below I have pasted a smal portion of the PDF file (in base64). From what I have understood so far I think that I have to read a text file and keep an eye on those boundries like two numeric lines in below:
--------------080501060300
--------------080107050402
Content-Type: application/pdf;
name="myfile.pdf"
Content-Transfer-Encoding:
Content-Disposition: inline;
filename="test.pdf"
JVBERi0xLjQNJeLjz9MNCjEzMC
MzIvRSAzODk4MS9OIDM2L1QgMj
ICAgICAgDQp4cmVmDQoxMzAgMj
MDAwMCBuDQowMDAwMDAxMzc4ID
MTcwNyAwMDAwMCBuDQowMDAwMD
MDAyNTk2MDkgMDAwMDAgbg0KMD
..........................
..........................
..........................
..........................
IG4NCjAwMDAyNjM1NDMgMDAwMD
cmVmDQoxMTYNCiUlRU9GDQo=
--------------080107050402
Content-Type: multipart/alternative;
boundary="=======AVGMAIL-3
--=======AVGMAIL-3918184C=
Content-Type: text/plain; x-avg=cert; charset=us-ascii
Content-Transfer-Encoding:
Content-Disposition: inline
Content-Description: "AVG certification"
No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 8.5.375 / Virus Database: 270.13.2/2214 - Release Date: 07/02/09 05=
:54:00
--=======AVGMAIL-3918184C=
--------------080107050402
Thanks,
ak
ASKER
Thanks!
ASKER
Thanks to all for your help.
ASKER
Thank you so much for your help but one thing I'm not sure is how should I know or how does the function know where it starts and where it ends?
Once again thank you.
Regards.