[spambayes-dev] Use of email factory function

Sjoerd Mullender sjoerd at acm.org
Mon Aug 2 12:43:10 CEST 2004

While looking through the code in sb_imapfilter.py I noticed this 
comment with the associated code:

         # Annoyingly, we can't just pass over the RFC822 message to an
         # existing message object (like self) and have it parse it. So
         # we go through the hoops of creating a new message, and then
         # copying over all its internals.
             new_msg = email.Parser.Parser().parsestr(data[self.rfc822_key])

I was wondering, instead of having the email parser create a new 
instance and then copying over the internals, could we not make use of 
the factory function argument?

We could call the parser like this:

new_msg = email.Parser.Parser(lambda x=self: 

The parser will call the factory function passed as its first argument 
to get a new instance of a Message.  But we could also just use a 
factory function that returns the already existing instance (lambda 
x=self: x) and then not copy over the internals.

Or is this something that doesn't work in older but still supported 
versions of the email package?

Sjoerd Mullender <sjoerd at acm.org>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 374 bytes
Desc: OpenPGP digital signature
Url : http://mail.python.org/pipermail/spambayes-dev/attachments/20040802/fcf6c816/signature.pgp

More information about the spambayes-dev mailing list