Posts: 17
Threads: 5
Joined: May 2018
Reputation:
0
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.
Posts: 642
Threads: 2
Joined: Mar 2018
Reputation:
35
Location: USA
11-13-2018, 07:13 PM
(This post was last modified: 11-13-2018, 07:18 PM by rlebeau.)
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.
Posts: 17
Threads: 5
Joined: May 2018
Reputation:
0
@rlebeau, Great! Thanks, will try it.