Re: suggestion: message filtering hooks

Kezdőlap
Üzenet törlése
Válasz az üzenetre
Szerző: Rahul Dhesi
Dátum:  
Címzett: exim-users
Tárgy: Re: suggestion: message filtering hooks
Philip Hazel writes:

> Thanks for the suggestion, but let me first say that
>
>    - After headers have been read.

>
> is not sensible, because the headers and the body are read as one block
> of data, and the SMTP receiver cannot send any response until both have
> been read. (It could drop the call, but that isn't sensible, because the
> sending host will just try again.)


Ok, in that case please omit this part.

> Access to the body of the message would not be easy, because Exim has
> written it to disc. After all, it could be tens of megabytes long.


Perhaps the smtp hook function could be provided with an open file ptr
connected to the file holding the message. The interface to the hook
function could be quite simple:

     int smtphook(stage, host, ip, sender, recipient, message, text)
     int stage;     /* value is CONNECT, MAILFROM, RCPT_TO, DATA, or BODY */
     char *host;    /* remote host name if known, else NULL */
     unsigned long ip;    /* remote hosts's IP address in machine byte order */
     char *sender;     /* if non-NULL, MAIL FROM sender */
     char *recipient;   /* if non-NULL, current RCPT TO recipient */
     FILE *message;    /* if non-NULL, read-only file pointer to message */
     char *text;    /* text string returned from smtphook() */


Meanings of stage:
   CONNECT:  Got incoming SMTP connection and have host name and IP address.
   MAILFROM: Got MAIL FROM sender.
   RCPTTO:   One RCPT TO recipient has been read.  smtphook() is called
             once after each RCPT TO recipient has been read.
   DATA:     Got all recipients, about to read mesage body.
   BODY:     Message body read, is in file.


No need to supply any of the message headers -- let the smtphook
function do its own parsing as needed, reading from the message file.
Any time smtphook() returns with a non-zero value, we take this to mean
that we should reject the message with a 500 series code, and print
contents of 'text' as the error string. If smtphook() returns with
zero, it's a no-op and we keep going. The caller should supply a buffer
of known length to which 'text' points, initialized to text[0] = 0.

> > Providing such a hook function would allow site-specific filtering code,
> > written in C and to be linked with Exim, to be added without having to
> > add unofficial patches to Exim.
>
> I have made a note of this idea, but I am uneasy about it because of the
> support implications. It might constrain my options for changing things
> internally in the future, and there would be a lot of documentation
> needed.


If you implement it as above, accepting only a 0 or nonzero return code
from smtphook(), no more documentation is needed :-) because what I
wrote above should be sufficient. And no data structures are needed,
because smtphook() is expected to do its own parsing of the message
headers.

In the future you may of course add more things, e.g., accepting various
SMTP return codes from smtphook() (e.g. 4xx or 5xx) and acting
accordingly, or you could add another argument pointing to a structure
containing the parsed message headers. But smtphook() will be very
useful with just the simple interface above.

Rahul Dhesi <dhesi@???>

--
* This is sent by the exim-users mailing list.  To unsubscribe send a
    mail with subject "unsubscribe" to exim-users-request@???
* Exim information can be found at http://www.exim.org/