Page 1 of 1

Checking total email size

Posted: Tue Jan 29, 2008 3:44 pm
by alex.barylski
Is there any way to determine the length of an email (w/ attachments, etc) without resorting to a bandwidth monitor plugin?

I would like to perform a quick calculation before the loop begins and exit if the emails total size or sum is greater than a monthly quota?

Adding attachment sizes can be done manually, but I'm wondering what also gets added to the email which I would not account for doing this.???

Re: Checking total email size

Posted: Wed Jan 30, 2008 12:01 am
by Chris Corbyn
Adding attachment sizes isn't as clear cut as measuring the filesize of the attachment since base64 encoded data will always be equal to:

(originalByteCount * 4) / 3 (then padded to be a multiple of 4)

You need to account for the headers and wot-not too.

A simple strlen() should return the number of bytes in the resulting string.

Code: Select all

echo strlen($message->build()->readFull());

Re: Checking total email size

Posted: Wed Jan 30, 2008 1:23 am
by alex.barylski
Hmmm...not sure I follow.

My email host allows only X number of bytes transfer per month so I need ot make sure my application doesn't go over - to the byte or damn near if possible. If I check the strlen of just the message, how do I account for things like heads, etc?

Is there no way to retreive the entire message size just before delivery?

The only thing which changes is the To: address which I suppose I could calculate accordingly, same goes for attachements, etc...but I wondering if this is sufficient to measure exact bytes???

Sorry if I repeat myself here, but it's getting late and my eyes are starting to tire...as are my over worked hands and fingers... :)

Re: Checking total email size

Posted: Wed Jan 30, 2008 5:41 am
by Chris Corbyn
Hockey wrote:Hmmm...not sure I follow.

My email host allows only X number of bytes transfer per month so I need ot make sure my application doesn't go over - to the byte or damn near if possible. If I check the strlen of just the message, how do I account for things like heads, etc?

Is there no way to retreive the entire message size just before delivery?

The only thing which changes is the To: address which I suppose I could calculate accordingly, same goes for attachements, etc...but I wondering if this is sufficient to measure exact bytes???

Sorry if I repeat myself here, but it's getting late and my eyes are starting to tire...as are my over worked hands and fingers... :)
*sigh*

Echo the content which $message->build()->readFull() returns.