[Email-SIG] size of a message

Eric S. Johansson esj at harvee.org
Thu Aug 5 22:26:54 CEST 2004


Matthew Dixon Cowles wrote:
> Dear Eric,
> 
> 
>>I'm looking to find how to calculate the size of a message held by
>>a e-mail object.  Obviously, I could convert the whole thing to a
>>string and take its length but that seems rather distasteful.
> 
> 
> As far as I'm aware, that's the way to do it. The as_string() method
> of a Message object should make it pretty painless. I don't really
> know how you'd figure it out in another way.

I just didn't know if there was some way of walking all of the objects 
in the mail message and summing up the individual elements.

>>additionally, the project I working on gave me a reason to add
>>extra headers dynamically to mail messages.  So I have a new set of
>>classes and examples of how to do this and I've figured out how to
>>add this to the current classes in an upwards compatible fashion.
> 
> 
> I haven't had any trouble adding and removing headers with the
> Message object's ordinary API. I'm sure that you've got something
> interesting; can you tell us a little more about it?

in a nutshell, I have a situation where constantly modifying a message 
was not desirable.  The message object could be shared among several 
other message container objects and modifying in one place would 
obviously be shared with others which would be a bad thing(tm).  So I 
created a new generator object which replaces _write_headers.

the new generator takes a header object as an argument to generate 
additional message headers on-the-fly during a as_string call.  For me, 
it serves the purpose of allowing me to store state information in the 
message container object and push it into the message on output without 
modifying the original message.  this is really important in a case 
where a single e-mail object may be shared among multiple container objects.

I added an optional argument to my as_string (which is a close copy of 
the original except it turns off line wrap) to take a header class to 
create the additional header elements.

as I said, I don't know if it would be useful to anyone else but it's 
certainly saving my bacon right now.

---eric

-- 
Speech recognition in use.  It makes mistakes, I correct most


More information about the Email-SIG mailing list