"Jason R. Mastaler" <[EMAIL PROTECTED]> writes:
> Tim Legant <[EMAIL PROTECTED]> writes:
>
> > I took at quick glance at this when Cory mentioned it on tmda-users
> > and I think the solution is a custom Generator class. The problem
> > is that we only parse the headers but we use a Generator class to
> > output the message that expects the entire message to have been
> > parsed. I need to look at it in more detail to be sure I don't bork
> > anything else in TMDA, but I think this can be solved.
>
> Based on the mimelib tracker request[1] assigned to this issue, it
> seems like this should be solved in Python's email module, and not
> TMDA.
>
> Barry's thoughts on the issue were first:
>
> ``You should probably use a Generator subclass that
> overrides _dispatch().''
>
> and then:
>
> ``Moving this to version 3.0 feature requests. Specifically, add a
> Generator that can handle HeaderParser parsed messages.''
>
> So, was your thought to write this Generator for Barry?
No. My thought was only to write a Generator subclass for TMDA until
email handles it correctly. Since I believe the entire subclass would
be 10 lines or less, it didn't seem like a big deal. The reason I
think this is that the vast majority of Generator deals with turning
parsed parts back into strings. When a message is read with the
HeaderParser, though, the entire body (payload) is already a string.
It was also never decoded, so it doesn't need to be re-encoded.
There's actually no "generating" to be done. We just need to write
that payload/string.
Several other small things were affected by the change to HeaderParser
and were not updated to take advantage of the fact that we use
HeaderParser. For example, Util.body_as_raw_string does a whole lot
more work than it needs to. It was written when we used the full
Parser, so it needed to call Util.msg_from_string (going through the
whole "generation" process and then find the body part of that
string. With HeaderParser, the correct (and full) implementation of
that function is:
def body_as_raw_string(msg):
"""Return the body as a raw (undecoded) string."""
return msg.get_payload()
Therefore, since the payload is the exact body text that was read from
stdin, only the headers need to be "generated", which Generator
already does correctly. The "TMDAGenerator" class looks like this:
class TMDAGenerator(Generator):
def _dispatch(self, msg):
payload = msg.get_payload()
if payload is not None:
self._fp.write(payload)
Ok, so I got carried away and wrote it while composing this message.
As I commented above, there are a few small things in TMDA that could
also be changed to take advantage of the fact that we now use
HeaderGenerator, but the above 5 lines are the bulk of fixing this
bug.
This would allow TMDA to work with valid messages rather than bombing
out on every attempted delivery of those messages until they finally
disappear from the queue.
Tim
_________________________________________________
tmda-workers mailing list ([EMAIL PROTECTED])
http://tmda.net/lists/listinfo/tmda-workers