Atozed Forums
Get size of TIdMessage without first saving to TStream - Printable Version

+- Atozed Forums (https://www.atozed.com/forums)
+-- Forum: Indy (https://www.atozed.com/forums/forum-8.html)
+--- Forum: Indy General Discussion (https://www.atozed.com/forums/forum-9.html)
+--- Thread: Get size of TIdMessage without first saving to TStream (/thread-814.html)



Get size of TIdMessage without first saving to TStream - edwinyzh - 11-13-2018

Hello,

We all know we can get the size of a TidMessage instance by first saving it to a TMemoryStream and read TMemoryStream.Size to get the size of the email message in bytes, but this doesn't sound performance-friend.

Is there an alternative way to get the size of a Tidmessage object?

Thanks.


RE: Get size of TIdMessage without first saving to TStream - rlebeau - 11-13-2018

Indy has a TIdCalculateSizeStream class in the IdGlobal unit. It acts similar to TMemoryStream but without using an actual memory buffer. It is intended to be used for exactly this kind of scenario - counting the number of bytes "written" to it. You can use it in the exact same way as before - save the TIdMessage to it, and then read its Size property.

Just note that TIdMessage generates its stream data dynamically, so there is no guarantee that the byte count will be exactly the same number each time you call its SaveTo...() methods, even if you don't change any of its properties in between calls. Particularly in regards to timestamps, message part boundaries, etc. So calculating the size of a TIdMessage is more of an estimate than an absolute.


RE: Get size of TIdMessage without first saving to TStream - edwinyzh - 11-14-2018

@rlebeau, Great! Thanks, will try it.