Jon Nelson writes:


Mr. Sam: could you please give us a detailed "process overview" as to
how messages go from (say, esmtpd) through submit, through the global
filters, and then the final signaling of courierd?  If the queue docs on
courier-mta.org are close but a bit out of date (I don't see /any/
mention of global filtering there) I'm sure many of us would appreciate
an update somehwere.

The queue docs are slightly dated, but they are mostly correct. 95% of the essential stuff in them hasn't changed.

The submit process is responsible for inserting a new message into the mail queue. submit gets invoked by sendmail, courieresmtpd, or the courierdsn modules, as a child process.

It receives the necessary information it needs through a combination of command line options, environment variables, and standard input and output. The message itself is read from standard input, and saved in what eventually will be message's data file. The message's control file is created at the same time. The actual mechanics of creating and naming the files is still what the docs say it is.

The reason why a global filter cannot modify the message is because the submit process creates a data structure in memory, in parallel. The data structure describes the starting position and the ending position of each logical entity within the message: where the headers and the message body begins and ends. If the message contains MIME attachments each MIME attachment is also described as well.

This structure is needed in the even the submit process feels it necessary to rewrite the message. A message may be rewritten for several reasons. The most common one would be to provide default values for MIME headers. If you have a system script that runs a jobs and mails its output, and your system uses the iso-8859-1 character set natively, then chances are that your system script will not bother to supply the MIME header that specifies that the messages uses the iso-8859-1 character set. Well, submit will do that for you, in this case.

The reason that external filters cannot modify the message is because doing so will throw off the internal data structure that describes the logical structure of the message, which is relied upon in order for submit to rewrite the message properly. You do that, and submit is going to spit out complete crap.

And the reason that filtering cannot occur before the data structure is parsed is for efficiency's sake. The message's structure is parsed in one sweep. And it is done at the same time submit reads the message from standard input.

Rather than reading the message from standard input, saving it in a file, then reopening the file and reading the message again in order to parse it into its logical components, everything is done in one shot. As submit reads the message and saves it in the data file, it simultaneously parses it at the same time, at virtually no additional cost.

The above should be sufficient to explain why global filters cannot touch the message.

Not that it's impossible to do this, but it is more than a trivial change or an addition, and will require some non-trivial effort to do that in an efficient manner.


Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to