[Exim] local_scan

Kezdőlap
Üzenet törlése
Válasz az üzenetre
Szerző: Adrian Bool
Dátum:  
Címzett: Exim List
Tárgy: [Exim] local_scan
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
Send mail to mime@??? for more info.
--

Hi,

Just trying to scan my email using vipul's razor...

The most efficient way I could see to do it is to use Exim4's local_scan
functionality. I intend to call razor in my local_scan function and
then use the header_add exim function to mark the message as appropriate
(always accepting it). Filtering etc can then be done later down the
line based on the header...

Right now, main problem is that when an email is submitted to exim via
SMTP I get,


     ..blah...
data
354 Enter message, ending with "." on a line by itself
Subject: Hello there


aid
.
Can't ignore signal CHLD, forcing to default.
250 OK id=18vKuB-0008GH-2s

Does anyone know why I am getting the CHLD error, and how I may correct
it?

I can but presume that is due to me using popen() to start razor. Not
sure why this is a bad thing though... Source for local_scan attached for
your amusement...

Thanks for any info.

Regards,

aid


--
Adrian Bool            | http://noc.vianw.net/
Director, Global Core Network    | tel://+44.1925.484061/
VIA NET.WORKS Inc.         | noc://+49.203.3093.1111/


--
Content-Description:

/*
 * call razor_client to see if this email is
 * probably spam. If it is, mark the email as such
 * by adding a header,
 *
 * X-Razor: RAZOR_MATCHED
 * X-Razor: RAZOR_NOT_MATCHED
 * X-Razor: ERROR
 *
 * as appropriate
 *
 */

#include "local_scan.h"

#include <stdio.h>
#include <unistd.h>

#define LOCAL_SCAN_BUFFER_SIZE 4096

unsigned char local_scan_buffer [LOCAL_SCAN_BUFFER_SIZE] ;

static char razor_header [] = "X-Razor" ;
static char razor_matched [] = "RAZOR_MATCHED" ;
static char razor_not_matched [] = "RAZOR_NOT_MATCHED" ;
static char razor_error [] = "RAZOR_ERROR" ;
static char razor_error_open [] = "RAZOR_ERROR_OPEN" ;
static char razor_error_data_read [] = "RAZOR_ERROR_DATA_READ" ;
static char razor_error_data_write [] = "RAZOR_ERROR_DATA_WRITE" ;

int local_scan ( int fd, uschar ** return_text )
  {
  FILE * razor = NULL ;
  char * result_string = NULL ;
  ssize_t size = 0 ;
  int r = 0 ;

  /* open the razor client as stdio stream */
  if ( (razor = popen ( "/usr/bin/razor-client", "w" ) ) == 0 )
    result_string = razor_error_open ;

  /* write the headers out to razor */
  if ( result_string == NULL )
    {
    header_line * hl = header_list ;

    while ( hl != NULL )
      {
      if ( hl->type != '*' ) fputs ( hl->text, razor ) ;
      hl = hl->next ;
      }

    /* output blank line */
    fputs ( "\n", razor ) ;
    }

  /* feed the file into razor */
  if ( result_string == NULL )
    {
    while ( (size = read (fd, local_scan_buffer, LOCAL_SCAN_BUFFER_SIZE)) > 0 )
      {
      if ( fwrite ( local_scan_buffer, 1 , size, razor ) != size )
        {
    result_string = razor_error_data_write ;
    break ;
    }
      }
    if ( size == -1 ) result_string = razor_error_data_read ;

    r = pclose ( razor ) ;
    }

  /* set the result string based on the razor result */
  if ( result_string == NULL )
    {
    switch ( r )
      {
      case 0:
    result_string = razor_matched ;
    break ;
      case 1:
    result_string = razor_not_matched ;
    break ;
      default:
      result_string = razor_error ;
    break ;
      }
    }

  /* return the correct data to exim */
  header_add(' ', "%s: %s\n", razor_header, result_string );

  (*return_text) = result_string ;

  return LOCAL_SCAN_ACCEPT ;
  }




--