Quantcast
Channel: Exchange Server Development forum
Viewing all articles
Browse latest Browse all 7132

How to use MimeWriter properly ?

$
0
0

Hi,

I am trying to use Microsoft.Exchange.Data.Mime.MimeWriter (and MimeReader )

to convert a email object (originally in TNEF binary encoding ) to TNEF base64 encoding and save

it to an eml file.

When writing the part context, the eml always append additional data after the base64 attachment.

This is my program flow:

MimeWriter wrter = new MimeWriter();

MimeReader reader = MimeReader(email.GetMimeReadStream());

// copy header part skipped

// convert body part

// add 2 more headers

writer.WriteHeader("Content-Transfer-Encoding", "base64");

writer.WriteHeader("Content-Disposition", "attachment;filename=\"winmail.dat\"");

Steam rawInput = email.TnefPart.GetRawContentReadStream();

byte[] buf = new byte[1024*16];

int readb = 0;

EncoderStream sx = new EncoderStream(rawInput, new Base64Encoder(), EncoderStreamAccess.Read);

while ((readb = sx.Read(buf, 0, buf.Length)) > 0)

{

   writer.WriteRawContent(buf, 0, readb);

}

writer.EndPart();

I also writer the output from the EncoderStream to another file (not shown in above)

and compare the result with the above eml and found that additional data is appended

at the end.

This make the base64 decode failed when processing the eml by another system.

Can anybody help ?

Thanks!


Viewing all articles
Browse latest Browse all 7132

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>