Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get size of TIdMessage without first saving to TStream

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?

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.

@rlebeau, Great! Thanks, will try it.

Forum Jump:

Users browsing this thread: 1 Guest(s)