[spambayes-dev] Use of email factory function

Tony Meyer tameyer at ihug.co.nz
Tue Aug 3 10:00:19 CEST 2004


[Sjoerd Mullender]
> 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.

[Tony Meyer] 
> I (think I) wrote that code, and I'm certainly hazy on many 
> parts of the email package and the parsers.  I didn't know 
> that the above was possible (I suspected something like it, 
> but couldn't figure it out).
> 
> +1 to checking this in.

Thinking about things more (and going over sb_imapfilter code for other
reasons), I'm again not sure how this works (but if it does, then still
+1!).

What we want is to make _ourselves_ be the message that is returned from
email.Parser.Parser.  I can see the above being nicer if we were copying
*to* new_msg, but we are copying *from* it.  I think the proper solution is
to move the code that calls this outside of the message instance itself, but
that involves a fair bit of work.  Hopefully, though, I'm misunderstanding
things :)

=Tony Meyer



More information about the spambayes-dev mailing list