This is the up-to-date version of Courier-MTA and MailScanner integration
patches.
I simply checked the modification points of 0.38.2 sources and no relevant
changes was found.
So I did neither recompilations nor any other changes. (no time, sorry)
It should be okay but let me no if not.

now patches are against MailScanner-3.12-5 and Courier-0.38.2

step-by-step
1. install MailScanner as usual
2. apply some patches (#1 and #2):
3. set the following in mailscanner.conf:

     Run As User = <couriersuser>
     Run As Group = <couriersgroup>

     Incoming Queue Dir = /somewhere/where/couriersuser/can/write/to.in
     Outgoing Queue Dir = /somewhere/where/couriersuser/can/write/to.out

     Delivery Method = queue

4. start mailscanner. It will wait for sendmail style qf and df files in
the incoming queue directory.
5. place #3 into srcdir/courier/filters
6. patch courier sources with #4
7. compile and install courier
8. place script #5 somewhere, modify IQDIR, OQDIR in its beginning to those
mailscanners dir
9. put its name with full path in courier/etc/filters/wrapperfilter-config
10. put "all" in courier/etc/filters/wrapperconfig-mode
11. run "filterctl start wrapperfilter"
12. dont forget to "courierfilter start"
13+. ask me, maybe I forget something :-)

how it works
1. wrapperfilter is installed as a globalfilter for courier.
2. when it gets input wrapperfilter runs simply the command written in
wrapperfilter-config with piped stdin and stdout
3. the shell script #5 assembles a sendmail style qf and df file from
couriers data and control files, places them in incoming queue and waits
for mailscanner
4. mailscanner does its job, and creates df and qf files in outgoing queue
dir.
5. the script reassembles courier files and accepts the mail
6. mailscanner calls sendmail directly to send notifications

mailscanner patch:
because mailscanner calls sendmail directly, and sendmail through submit
waits for globalfilter, which is waiting for mailscanner -> deadlock
mailscanners patches run sendmail in a child process, so mailscanner can
return.

courier patch:
allow globalfilters to modify couriers datafile by reassembling its
MIME-things after filters running.
this feature maybe interresting alone too. :-))


So lets try it out!


Dobos Sandor
IBCnet Hungary Ltd.


<1><1><1><1><1><1><1><1><1><1><1><1><1><1><1>
--- mailscanner.bck Tue Mar  5 11:23:33 2002
+++ mailscanner     Mon Apr  8 10:39:54 2002
@@ -154,6 +154,8 @@
 Log::DieLog("$Config::InQueueDir and $Config::OutQueueDir must be on the
same filesystem/partition!")
   unless $indevice == $outdevice;

+$SIG{CHLD} = "IGNORE";
+
 # Clean up the entire outgoing sendmail queue in case I was
 # killed off half way through processing some messages.
 my $CleanUpList = Sendmail::ListWholeQueue($Config::InQueueDir);

<1><1><1><1><1><1><1><1><1><1><1><1><1><1><1>
<2><2><2><2><2><2><2><2><2><2><2><2><2><2><2>
--- sendmail.pl.bck Fri Apr  5 10:51:39 2002
+++ sendmail.pl     Mon Apr  8 10:57:50 2002
@@ -829,8 +829,6 @@
     # Don't send a message to "" or "<>"
     next if $from eq "" || $from eq "<>";

-    open(SENDMAIL, "|$Config::Sendmail $SendmailOptions")
-      or Log::WarnLog("Could not notify senders"), return;

     # Set the report filename dependent on what triggered MailScanner, be
it
     # a virus, a filename trap, a Denial Of Service attack, or an parsing
error.
@@ -851,12 +849,25 @@
       $result = eval "\"$1\"";
       $output .= $result . "\n";
     }
-    print SENDMAIL $output;
-    close SENDMAIL;
-    $counter++;
+
+    my $pid = fork();
+    die "Can't fork: $!" unless defined($pid);
+
+    if ($pid == 0) {
+        # In the child
+        POSIX::setsid();
+
+        open(SENDMAIL, "|$Config::Sendmail $SendmailOptions")
+          or Log::WarnLog("Could not notify senders"), exit -1;
+        print SENDMAIL $output;
+        close SENDMAIL;
+
+        exit 0;
+    }
   }

-  Log::InfoLog("Notified senders about $counter infections") if $counter;
+  $counter = scalar(@$Ids);
+  Log::InfoLog("Notifying senders about $counter infections");
 }

 # Notify the local postmaster that virus-infected email messages have been
@@ -872,25 +883,33 @@

   return unless @$Ids; # Do nothing if no infections

-  open(SENDMAIL, "|$Config::Sendmail $SendmailOptions")
-    or Log::WarnLog("Could not notify local postmaster"), return;
-  print SENDMAIL <<EONOTE1;
+
+  my $pid = fork();
+  die "Can't fork: $!" unless defined($pid);
+
+  if ($pid == 0) {
+      # In the child
+      POSIX::setsid();
+
+      open(SENDMAIL, "|$Config::Sendmail $SendmailOptions")
+        or Log::WarnLog("Could not notify local postmaster"), exit -1;
+      print SENDMAIL <<EONOTE1;
 From: "MailScanner" <$Config::LocalPostmaster>
 To: $Config::LocalPostmaster
 Subject: Warning: E-mail viruses detected

 The following e-mail messages were found to have viruses in them:
 EONOTE1
-  foreach $id (@$Ids) {
-    #next if $id eq "";
-    $info = $MessagesInfo->{$id};
-    ($from, $to, $subject, $relay) = split(/\0/, $info);
-
-    # Find every report for this message id
-    $parts = $Reports->{$id};
-    $report = join("   Report: ", values %$parts);
+      foreach $id (@$Ids) {
+        #next if $id eq "";
+        $info = $MessagesInfo->{$id};
+        ($from, $to, $subject, $relay) = split(/\0/, $info);
+
+        # Find every report for this message id
+        $parts = $Reports->{$id};
+        $report = join("   Report: ", values %$parts);

-    print SENDMAIL <<EONOTE2;
+        print SENDMAIL <<EONOTE2;

    Sender: $from
 Recipient: $to
@@ -898,25 +917,28 @@
 MessageID: $id
    Report: $report
 EONOTE2
-    $counter++;

-    # New for 2.70. Optionally print full message headers in the postie
msg.
-    if ($Config::PostmasterFullHeaders) {
-      $H = $Headers->{$id};
-      next unless $H;
-      print SENDMAIL "Full headers are:\n";
-      print SENDMAIL " " . join(' ', @$H) . "\n";
-    }
-  }
+        # New for 2.70. Optionally print full message headers in the
postie msg.
+        if ($Config::PostmasterFullHeaders) {
+          $H = $Headers->{$id};
+          next unless $H;
+          print SENDMAIL "Full headers are:\n";
+          print SENDMAIL " " . join(' ', @$H) . "\n";
+        }
+      }

-  print SENDMAIL <<EONOTE3;
+      print SENDMAIL <<EONOTE3;
 --
 MailScanner
 Email Virus Scanner
 EONOTE3
-  close SENDMAIL;
+      close SENDMAIL;

-  Log::InfoLog("Notified $Config::LocalPostmaster about $counter
infections") if $counter;
+      exit 0;
+  }
+
+  $counter = scalar(@$Ids);
+  Log::InfoLog("Notifying $Config::LocalPostmaster about $counter
infections");
 }

 # Send a message completely contained in a MIME::Entity structure.
@@ -927,10 +949,18 @@
   # Send message
   # It is a good idea to have "hardwired" error text in seemingly
   # generic function, as below? -nwp
-  open SENDMAIL, "|$Config::Sendmail $SendmailOptions"
-    or Log::WarnLog("Could not send disinfected attachments"), return;
-  $top->print(\*SENDMAIL);
-  close SENDMAIL;
+  my $pid = fork();
+  die "Can't fork: $!" unless defined($pid);
+
+  if ($pid == 0) {
+      # In the child
+      POSIX::setsid();
+
+      open SENDMAIL, "|$Config::Sendmail $SendmailOptions"
+        or Log::WarnLog("Could not send disinfected attachments"), exit
-1;
+      $top->print(\*SENDMAIL);
+      close SENDMAIL;
+  }
 }

 1;
<2><2><2><2><2><2><2><2><2><2><2><2><2><2><2>
<3><3><3><3><3><3><3><3><3><3><3><3><3><3><3>
#include  <stdio.h>
#include  <errno.h>
#include  <syslog.h>
#include  <stdlib.h>
#include  <unistd.h>
#include    <sys/types.h>
#include    <sys/wait.h>
#include    <signal.h>
#include  "comctlfile.h"
#include  "filtersocketdir.h"
#include  "courier.h"
#include  "libfilter/libfilter.h"


int main(int argc, char **argv)
{
    int   listensock;
    int ufd;
    char * cmd;
    char * cfile;

    openlog(NULL,LOG_PID,LOG_MAIL);

     if ((listensock=lf_init("filters/wrapperfilter-mode",
          ALLFILTERSOCKETDIR "/wrapperfilter",
          ALLFILTERSOCKETDIR "/.wrapperfilter",
          FILTERSOCKETDIR "/wrapperfilter",
          FILTERSOCKETDIR "/.wrapperfilter"))<0) {
            syslog(LOG_ERR,"wrapperfilter: lf_init");
          return 1;
    }

    if ((cfile=config_search("filters/wrapperfilter-config"))==NULL) {
        syslog(LOG_ERR,"wrapperfilter: 'filters/wrapperfilter-config' not
found");
        return 2;
    }

    if ((cmd=config_read1l(cfile))==NULL) {
        free(cfile);
        syslog(LOG_ERR,"wrapperfilter: cannot read
'filters/wrapperfilter-config'");
        return 3;
    }

    free(cfile);


     lf_init_completed(listensock);

    signal(SIGCHLD,SIG_IGN);

     for (;;) {
          if ((ufd=lf_accept(listensock)) < 0) {
            syslog(LOG_ERR,"wrapperfilter: lf_accept");
            break;
        }
        if (fork()==0) {

            dup2(ufd,0);
            dup2(ufd,1);

            system(cmd);
            free(cmd);

            close(ufd);

            return 0;
        }
        close(ufd);
    }

    free(cmd);
    close(listensock);

     return 0;
}
<3><3><3><3><3><3><3><3><3><3><3><3><3><3><3>
<4><4><4><4><4><4><4><4><4><4><4><4><4><4><4>
diff -ur courier-0.38.2.orig/courier/filters/Makefile.in
courier-0.38.2/courier/filters/Makefile.in
--- courier-0.38.2.orig/courier/filters/Makefile.in     Mon Jun  3 23:26:10
2002
+++ courier-0.38.2/courier/filters/Makefile.in     Fri Jun 14 11:34:16 2002
@@ -88,7 +88,7 @@
 sbin_PROGRAMS = courierfilter

 filterbindir = $(libexecdir)/filters
-filterbin_PROGRAMS = dupfilter
+filterbin_PROGRAMS = dupfilter wrapperfilter

 filtersocketdir = $(localstatedir)/filters
 allfiltersocketdir = $(localstatedir)/allfilters
@@ -108,6 +108,15 @@
     ../../threadlib/libthreadlib.a `cat ../../threadlib/libthread.dep` \
     @NETLIBS@

+wrapperfilter_SOURCES = wrapperfilter.c
+wrapperfilter_DEPENDENCIES = libfilter/libfilter.a \
+    ../libs/libcommon.a ../libs/libcourier.a \
+    ../../liblock/liblock.a ../../authlib/libauth.a
+
+wrapperfilter_LDADD = libfilter/libfilter.a \
+    ../libs/libcommon.a ../libs/libcourier.a \
+    ../../liblock/liblock.a ../../authlib/libauth.a
+

 courierfilter_SOURCES = courierfilter.c
 courierfilter_DEPENDENCIES = ../libs/libcommon.a ../libs/libcourier.a \
@@ -141,6 +150,8 @@
 LIBS = @LIBS@
 dupfilter_OBJECTS =  dupfilter.o duphash.o msghash.o
 dupfilter_LDFLAGS =
+wrapperfilter_OBJECTS =  wrapperfilter.o
+wrapperfilter_LDFLAGS =
 courierfilter_OBJECTS =  courierfilter.o
 courierfilter_LDFLAGS =
 SCRIPTS =  $(databin_SCRIPTS)
@@ -163,8 +174,8 @@

 TAR = gtar
 GZIP_ENV = --best
-SOURCES = $(dupfilter_SOURCES) $(courierfilter_SOURCES)
-OBJECTS = $(dupfilter_OBJECTS) $(courierfilter_OBJECTS)
+SOURCES = $(dupfilter_SOURCES) $(courierfilter_SOURCES)
$(wrapperfilter_SOURCES)
+OBJECTS = $(dupfilter_OBJECTS) $(courierfilter_OBJECTS)
$(wrapperfilter_OBJECTS)

 all: all-redirect
 .SUFFIXES:
@@ -287,6 +298,10 @@
     @rm -f dupfilter
     $(LINK) $(dupfilter_LDFLAGS) $(dupfilter_OBJECTS) $(dupfilter_LDADD)
$(LIBS)

+wrapperfilter: $(wrapperfilter_OBJECTS) $(wrapperfilter_DEPENDENCIES)
+    @rm -f wrapperfilter
+    $(LINK) $(wrapperfilter_LDFLAGS) $(wrapperfilter_OBJECTS)
$(wrapperfilter_LDADD) $(LIBS)
+
 courierfilter: $(courierfilter_OBJECTS) $(courierfilter_DEPENDENCIES)
     @rm -f courierfilter
     $(LINK) $(courierfilter_LDFLAGS) $(courierfilter_OBJECTS)
$(courierfilter_LDADD) $(LIBS)
@@ -524,6 +539,10 @@
     ../config.h filtersocketdir.h ../../threadlib/threadlib.h \
     ../../threadlib/config.h ../../threadlib/havepthread.h \
     ../libs/commsgcancel.h libfilter/libfilter.h
+wrapperfilter.o: wrapperfilter.c config.h  \
+    ../libs/comctlfile.h ../courier.h \
+    ../config.h filtersocketdir.h \
+    ../libs/commsgcancel.h libfilter/libfilter.h
 duphash.o: duphash.c msghash.h ../../md5/md5.h ../../md5/config.h \
     duphash.h
 libfilter.o: libfilter.c config.h ../courier.h ../config.h libfilter.h
@@ -658,6 +677,8 @@
     test -w /etc || exit 0; for f in $(htmldoc_DATA); do chown bin
$(DESTDIR)$(htmldocdir)/$$f ; chgrp bin $(DESTDIR)$(htmldocdir)/$$f ; done
     chmod 755 $(DESTDIR)$(filterbindir)/dupfilter
     test -w /etc || exit 0; chown @mailuser@ $(DESTDIR)
$(filterbindir)/dupfilter; chgrp @mailgroup@ $(DESTDIR)
$(filterbindir)/dupfilter
+    chmod 755 $(DESTDIR)$(filterbindir)/wrapperfilter
+    test -w /etc || exit 0; chown @mailuser@ $(DESTDIR)
$(filterbindir)/wrapperfilter; chgrp @mailgroup@ $(DESTDIR)
$(filterbindir)/wrapperfilter

 install-perms:
     @$(MAKE) install-perms-recursive
@@ -670,6 +691,7 @@
 install-perms-local:
     @echo "$(filterbindir) 755 bin bin" >>permissions.dat
     @echo "$(filterbindir)/dupfilter 755 @mailuser@ @mailgroup@"
>>permissions.dat
+    @echo "$(filterbindir)/wrapperfilter 755 @mailuser@ @mailgroup@"
>>permissions.dat
     @echo "$(filtersocketdir) 750 @mailuser@ @mailgroup@"
>>permissions.dat
     @echo "$(allfiltersocketdir) 750 @mailuser@ @mailgroup@"
>>permissions.dat
     @echo "$(filterconfdir) 750 @mailuser@ @mailgroup@" >>permissions.dat
diff -ur courier-0.38.2.orig/courier/submit.h
courier-0.38.2/courier/submit.h
--- courier-0.38.2.orig/courier/submit.h      Sun Aug  5 22:01:35 2001
+++ courier-0.38.2/courier/submit.h      Fri Jun 14 11:34:59 2002
@@ -77,6 +77,7 @@

 class SubmitFile {
 private:
+    int chkmsg(int *,char**,char**);

 static   SubmitFile *current_submit_file;

diff -ur courier-0.38.2.orig/courier/submit2.C
courier-0.38.2/courier/submit2.C
--- courier-0.38.2.orig/courier/submit2.C     Wed May  8 04:28:23 2002
+++ courier-0.38.2/courier/submit2.C     Fri Jun 14 11:44:19 2002
@@ -774,15 +774,8 @@
 }


-/* ------------ */
-
-int SubmitFile::MessageEnd(unsigned rcptnum, int iswhitelisted)
+int SubmitFile::chkmsg(int * dorewriteptr, char ** mimeptr, char **
rfcerrptr)
 {
-int is8bit=0, dorewrite=0, rwmode=0;
-const    char *mime=getenv("MIME");
-unsigned n;
-struct   stat stat_buf;
-const char *rfcerr=NULL;
 const char *bofhbadmime=getenv("BOFHBADMIME");
 int bofhbadmimebounce= bofhbadmime && strcmp(bofhbadmime, "reject") == 0;
 int bofhbadmimeaccept= bofhbadmime && strcmp(bofhbadmime, "accept") == 0;
@@ -808,8 +801,8 @@

     if (rwrfcptr->rfcviolation & RFC2045_ERR8BITHEADER)
     {
-         rfcerr= SYSCONFDIR "/rfcerr2047.txt";
-         dorewrite=1;
+         *rfcerrptr= SYSCONFDIR "/rfcerr2047.txt";
+         *dorewriteptr=1;

          if (bofhbadmimebounce)
          {
@@ -822,14 +815,14 @@

          if (bofhbadmimeaccept)
          {
-              dorewrite=0;
-              mime="none";
+              *dorewriteptr=0;
+              *mimeptr="none";
          }
         }
     else if (rwrfcptr->rfcviolation & RFC2045_ERR8BITCONTENT)
     {
-         rfcerr= SYSCONFDIR "/rfcerr2045.txt";
-         dorewrite=1;
+         *rfcerrptr= SYSCONFDIR "/rfcerr2045.txt";
+         *dorewriteptr=1;

          if (bofhbadmimebounce)
          {
@@ -843,14 +836,14 @@

          if (bofhbadmimeaccept)
          {
-              dorewrite=0;
-              mime="none";
+              *dorewriteptr=0;
+              *mimeptr="none";
          }
         }
     else if (rwrfcptr->rfcviolation & RFC2045_ERRBADBOUNDARY)
     {
-         rfcerr= SYSCONFDIR "/rfcerr2046.txt";
-         dorewrite=1;
+         *rfcerrptr= SYSCONFDIR "/rfcerr2046.txt";
+         *dorewriteptr=1;

          if (bofhbadmimebounce)
          {
@@ -863,8 +856,8 @@

          if (bofhbadmimeaccept)
          {
-              dorewrite=0;
-              mime="none";
+              *dorewriteptr=0;
+              *mimeptr="none";
          }
         }
     else
@@ -875,6 +868,26 @@
          return (1);
     }

+    return(0);
+}
+
+
+/* ------------ */
+
+int SubmitFile::MessageEnd(unsigned rcptnum, int iswhitelisted)
+{
+const char *rfcerr=NULL;
+int is8bit=0, dorewrite=0, rwmode=0;
+const    char *mime=getenv("MIME");
+unsigned n;
+struct   stat stat_buf;
+
+
+
+    if (chkmsg(&dorewrite,(char**)&mime,(char**)&rfcerr)) {
+        return (1);
+    }
+
     datfile << flush;
     if (datfile.fail()) clog_msg_errno();

@@ -887,9 +900,36 @@

 SubmitFile *voidp=this;

+
+    datfile.close();
+    if (datfile.fail()) clog_msg_errno();
+    rfc2045_free(rwrfcptr);
+
+
     if (run_filter(dfile, num_control_files_created, iswhitelisted,
          &SubmitFile::get_msgid_for_filtering, &voidp))
          return (1);
+
+
+    {
+         int nfd=open((const char*)dfile, O_RDWR, PERMISSION);
+         if (nfd < 0) clog_msg_errno();
+
+        datfile.fd(nfd);
+         if (datfile.fail()) clog_msg_errno();
+
+         rwrfcptr=rfc2045_fromfd_ac(nfd);
+         if (rwrfcptr == NULL)
+         clog_msg_errno();
+    }
+
+
+
+    if (chkmsg(&dorewrite,(char**)&mime,(char**)&rfcerr)) {
+        return (1);
+    }
+
+

     if (rwrfcptr->has8bitchars)
          is8bit=1;
diff -ur courier-0.38.2.orig/rfc2045/rfc2045.h
courier-0.38.2/rfc2045/rfc2045.h
--- courier-0.38.2.orig/rfc2045/rfc2045.h     Sun Apr  8 01:38:50 2001
+++ courier-0.38.2/rfc2045/rfc2045.h     Fri Jun 14 11:45:48 2002
@@ -147,7 +147,9 @@

 const char *rfc2045_getdefaultcharset();
 void rfc2045_setdefaultcharset(const char *);
-struct rfc2045 *rfc2045_fromfd(int);
+struct rfc2045 *rfc2045_fromfd_x(int,int);
+#define  rfc2045_fromfd(f)   (rfc2045_fromfd_x((f),0))
+#define  rfc2045_fromfd_ac(f)     (rfc2045_fromfd_x((f),1))
 #define  rfc2045_fromfp(f)   (rfc2045_fromfd(fileno((f))))

 extern void rfc2045_error(const char *);
diff -ur courier-0.38.2.orig/rfc2045/rfc2045_fromfd.c
courier-0.38.2/rfc2045/rfc2045_fromfd.c
--- courier-0.38.2.orig/rfc2045/rfc2045_fromfd.c   Wed Dec 15 23:27:57 1999
+++ courier-0.38.2/rfc2045/rfc2045_fromfd.c   Fri Jun 14 11:46:53 2002
@@ -19,7 +19,7 @@

 /* Convert a message to the RFC2045 structure */

-struct rfc2045 *rfc2045_fromfd(int fd)
+struct rfc2045 *rfc2045_fromfd_x(int fd,int ac)
 {
 struct   rfc2045   *rfc;
 char     buf[BUFSIZ];
@@ -28,7 +28,11 @@

     if ((orig_pos=lseek(fd, 0L, SEEK_CUR)) == (off_t)-1) return (NULL);
     if (lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1)    return (NULL);
-    if ((rfc=rfc2045_alloc()) == 0)     return (NULL);
+    if (ac) {
+         if ((rfc=rfc2045_alloc_ac()) == 0)  return (NULL);
+    } else {
+         if ((rfc=rfc2045_alloc()) == 0)     return (NULL);
+    }

     while ((n=read(fd, buf, sizeof(buf))) > 0)
          rfc2045_parse(rfc, buf, n);
<4><4><4><4><4><4><4><4><4><4><4><4><4><4><4>
<5><5><5><5><5><5><5><5><5><5><5><5><5><5><5>
#!/bin/bash


IQDIR=/usr/local/mailscanner/var/mqueue.in
OQDIR=/usr/local/mailscanner/var/mqueue.out

myname=$(basename $0)

InfoLog () {
#    echo "$(date '+%b %d %X') INFO: $1" >> /tmp/wrapperfilter.log
    /usr/bin/logger -i -t $myname -p mail.info $1
}

ErrorLog () {
#    echo "$(date '+%b %d %X') ERROR: $1" >> /tmp/wrapperfilter.log
    /usr/bin/logger -i -t $myname -p mail.err $1
}


InfoLog "Reading filenames..."
read datafile
read controlfiles
while [ 1 ]; do
    read tmp
    controlfiles="$controlfiles $tmp"
    if [ -z "$tmp" ]; then
        break;
    fi
done

if [ -z "$datafile" -o -z "$controlfiles" ]; then
    ErrorLog "Error reading input"
    exit -1;
fi

InfoLog $datafile
InfoLog $controlfiles

suffix=$(basename $datafile)

InfoLog "Removing $IQDIR/*$suffix..."
rm -rf $IQDIR/*$suffix

iqtfile=$IQDIR/~qf$suffix
iqfile=$IQDIR/qf$suffix
idfile=$IQDIR/df$suffix
oqfile=$OQDIR/qf$suffix
odfile=$OQDIR/df$suffix


InfoLog "Writing $idfile..."
touch $idfile
OIFS=$IFS
IFS=""
inhead=1;
cat $datafile | while [ 1 ]; do
    read line
    if [ ! $? = 0 ]; then
        break;
    fi
    if [ $inhead = 0 ]; then
        echo $line >> $idfile
    else
        if [ -z "$line" ]; then
            if [ $inhead -gt 0 ]; then
                inhead=$(($inhead - 1))
            fi
        fi
    fi
done
IFS=$OIFS

InfoLog "Writing $iqtfile..."
touch $iqtfile
for f in $controlfiles; do
    for sender in $(grep ^s $f|cut -b2-); do
        echo "S<$sender>" >> $iqtfile
    done
done
for f in $controlfiles; do
    for recipient in $(grep ^r $f|cut -b2-); do
        echo "RPFD: <$recipient>" >> $iqtfile
    done
done
OIFS=$IFS
IFS=""
cat $datafile 2>/dev/null| while [ 1 ]; do
    read line
    if [ ! $? = 0 ]; then
        break;
    fi

    if [ -z "$line" ]; then
        break;
    fi

    if [ -z "$(echo "$line"|grep '^[[:space:]]')" ]; then
        echo "H$line" >> $iqtfile
    else
        echo "$line" >> $iqtfile
    fi
done
echo "." >> $iqtfile
IFS=$OIFS

InfoLog "Renaming $iqtfile to $iqfile..."
mv $iqtfile $iqfile

InfoLog "Waiting for mailscanner..."
while [ -e $iqfile -o -e $idfile ]; do
#    InfoLog "."
    sleep 1s
done

InfoLog "Mailscanner finished..."
InfoLog "Re-assembling $datafile..."

echo -n "" > $datafile

OIFS=$IFS
IFS=""
cat $oqfile |egrep -v "(^S|^RPFD|^\.)"| while [ 1 ]; do
    read line
    if [ ! $? = 0 ]; then
        break;
    fi

    if [ "${line:0:1}" = "H" ]; then
        echo "$line"|cut -b2- >> $datafile
    else
        echo "$line" >> $datafile
    fi
done
IFS=$OIFS
echo -e "\n" >> $datafile
cat $odfile >> $datafile

rm -rf $odfile
rm -rf $oqfile

echo "200 Ok."

InfoLog "Finished."

exit 0
<5><5><5><5><5><5><5><5><5><5><5><5><5><5><5>




Dobos Sandor
IBCnet Hungary Ltd.





_______________________________________________________________

Don't miss the 2002 Sprint PCS Application Developer's Conference
August 25-28 in Las Vegas - 
http://devcon.sprintpcs.com/adp/index.cfm?source=osdntextlink

_______________________________________________
courier-users mailing list
[EMAIL PROTECTED]
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-users

Reply via email to