[spambayes-dev] Use of email factory function
Sjoerd Mullender
sjoerd at acm.org
Mon Aug 2 22:47:41 CEST 2004
I'm resending this because I didn't see it arrive on the list after 10
hours.
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.
try:
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:
x).parsestr(data[self.rfc822_key])
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/2673763f/signature.pgp
More information about the spambayes-dev
mailing list