.netinteropoutlookpia

Why attachment size given by Outlook programming interface is always wrong?


Trying to use Outlook Interop in C#, I noticed a curious thing.

Comparing the real size of a saved file and a size given by Outlook, I notice that the real, saved file is always smaller than expected from Attachment.Size. The saved files seem to be valid and not truncated.

Sample results http://www.freeimagehosting.net/uploads/224d342eba.png

So, what's wrong with it? Is there a bug in Attachment.Size? Or maybe it is expected to give something other than the size of an attachment?

I thought it converts CR to CRLF, including binary files, which may explain the overhead, but some attached files are in raw text format with CRLF, so this hypothesis is wrong.


First edit:

It is not Base64 encoding, because Base64 encoding would be:

Now, looking at nearly random overhead in a range of 89 to 3658 bytes, I would agree that it might be some strange headers.


Second edit:

I tested this on a larger set of files. What I notice is that the difference between real file size and size given by Outlook:

Here is an example:

alt text http://www.freeimagehosting.net/uploads/a767d3cacf.png

IMHO, Outlook does something with the name of the file, some sort of very strange encoding, maybe a generation of an unique identifier based on file name. This means that:


Solution

  • I'm not sure but I'd assume that it might be MIME headers and/or encoding overhead. For more information, look at this Wiki article about Base64 and search for the word overhead.

    Edit: Sorry, I wasn't very clear, I meant the Base64 article just as an example of that there might be overhead related to encoding, not that it was actually Base64 since, as mentioned by others, Base64 overhead would probably be much larger than those differences.