I’m writing a program to read from a POP3 mailbox and upload the email message into my ticketing system. I would like to then take the attachments and upload them as well. I’ve got all the information I need except the file size.
Is there a way to determine the file size from the mail message? I am taking the attachment, decoding the base64 encoded string and breaking it into a byte array to store in database. If there is another way to determine the file size, I’m willing to try that too.
I’m working in C# and .NET 3.5.
Thanks!!!
Is the size of the base64-decoded byte array correct for you? If so, all you need to do is calculate the size without decoding it, right?
A byte array of size N will encode to (N * 4)/3 bytes, always rounding up. You need to look at the last few characters of the string to work out how much to remove for rounding. Basically it should be something like:
This is untested, but presumably you’ve got good test data you can try it with 🙂