Index: amavisd.conf
--- amavisd.conf.orig	2009-04-22 02:24:04 +0200
+++ amavisd.conf	2009-04-22 19:46:28 +0200
@@ -360,10 +360,10 @@
 # ['Sophos SAVI', \&sophos_savi ],
 
 # ### http://www.clamav.net/
-# ['ClamAV-clamd',
-#   \&ask_daemon, ["CONTSCAN {}\n", "/var/run/clamav/clamd"],
-#   qr/\bOK$/m, qr/\bFOUND$/m,
-#   qr/^.*?: (?!Infected Archive)(.*) FOUND$/m ],
+['ClamAV-clamd',
+  \&ask_daemon, ["CONTSCAN {}\n", "/var/run/clamav/clamd"],
+  qr/\bOK$/m, qr/\bFOUND$/m,
+  qr/^.*?: (?!Infected Archive)(.*) FOUND$/m ],
 # # NOTE: run clamd under the same user as amavisd, or run it under its own
 # #   uid such as clamav, add user clamav to the amavis group, and then add
 # #   AllowSupplementaryGroups to clamd.conf;
Index: amavisd
--- amavisd.orig	2009-04-22 02:24:12 +0200
+++ amavisd	2009-04-22 19:36:50 +0200
@@ -12048,7 +12048,10 @@
       if ($subject_tag ne '') {
         if (defined $msginfo->get_header_field('subject')) {
           $hdr_edits->edit_header('Subject',
-                    sub { $_[1]=~/^([ \t]?)(.*)\z/s; ' '.$subject_tag.$2 });
+                    sub { $_[1]=~/^([ \t]?)(.*)\z/s;
+                          my $subj = $2;
+                          $subj=~s/\Q$subject_tag\E//sg;
+                          ' '.$subject_tag.$subj });
         } else {  # no Subject header field present, insert one
           $subject_tag =~ s/[ \t]+\z//;  # trim
           $hdr_edits->add_header('Subject', $subject_tag);
Index: amavislogsumm
--- amavislogsumm.orig	2009-04-22 19:36:50 +0200
+++ amavislogsumm	2009-04-22 19:36:50 +0200
@@ -309,7 +309,7 @@
     if ($spamCount > 0) {
         printf "\tSPAM : %5.2f\n", ($spamHitSum / $spamCount); 
     }
-    if (($timeLineCount - $spamCount) > 0) { 
+    if (($timeLineCount - $spamCount - $unscoredMail) > 0) { 
         printf "\tHAM  : %5.2f\n", ($noneSpamHitSum / ($timeLineCount - $spamCount - $unscoredMail)); 
         print "\n";
     }
Index: helper-progs/Makefile.in
--- helper-progs/Makefile.in.orig	2004-04-11 01:51:52 +0200
+++ helper-progs/Makefile.in	2009-04-22 19:36:50 +0200
@@ -2,7 +2,8 @@
 # Makefile.in for amavisd-new helper-progs
 
 # Needed for autoconf to behave properly...
-AMAVISUSER=@AMAVISUSER@
+AMAVIS_USER=dummy
+AMAVIS_GROUP=dummy
 prefix=@prefix@
 exec_prefix=@exec_prefix@
 sbindir=@sbindir@
@@ -11,7 +12,7 @@
 MINCLUDE=@MINCLUDE@
 # TODO : use some VERSION variable DEFS=  -DVERSION=\"@VERSION@ and in the 2 .c helper programs
 # additional flags
-DEFS=-D_POSIX_PTHREAD_SEMANTICS 
+DEFS=-D_POSIX_PTHREAD_SEMANTICS -DAMAVIS_USER=\"$(AMAVIS_USER)\" -DMILTER_SOCKET_GROUP=\"$(AMAVIS_GROUP)\"
 
 all: amavis-milter amavis
 
Index: helper-progs/amavis-milter.c
--- helper-progs/amavis-milter.c.orig	2008-06-27 15:31:45 +0200
+++ helper-progs/amavis-milter.c	2009-04-22 19:36:50 +0200
@@ -52,7 +52,7 @@
 #ifdef HAVE_SM_GEN_H
 # include "sm/gen.h"
 #endif
-#include "libmilter/mfapi.h"
+#include "milter/mfapi.h"
 
 typedef int mybool;
 
@@ -929,13 +929,14 @@
 int
 main(int argc, char *argv[])
 {
-/*  struct passwd *userinfo;	*amavis uid*  */
+    struct passwd *userinfo;
     int c, i;
     char *p, *milter_socket = NULL, *milter_socket_group = NULL;
 /*  const char *args = "dg:p:vx";  */
-    const char *args = ":hdg:p:Dvx";  /* some mix of old and new options!!! */
+    const char *args = ":hdg:p:DvxP:";  /* some mix of old and new options!!! */
 
     pid_t pid;
+    char *pidfile = NULL;
     int devnull;
 
 #if !defined(HAVE_MKDTEMP) && !defined(HAVE_MKTEMP)
@@ -970,6 +971,9 @@
 	    }
 	    milter_socket = strdup(optarg);
 	    break;
+	case 'P':
+	    pidfile = strdup(optarg);
+	    break;
 	case 'v':
 	    verbosity++;
 	    break;
@@ -999,23 +1003,20 @@
     uname(&amavis_uts);
 
     /* check user and group */
-/*  if (!(userinfo = getpwnam(AMAVIS_USER))) {
- *	perror("getpwnam");
- *	exit(EXIT_FAILURE);
- *  }
- *  amavis_gid = userinfo->pw_gid;
- *  if (!milter_socket_group) {
- *	milter_socket_group = strdup(MILTER_SOCKET_GROUP);
- *	if (!milter_socket_group) {
- *	    perror("strdup");
- *	    exit(EXIT_FAILURE);
- *	}
- *  }
- *  if (group_member(milter_socket_group) < 0) {
- *	fprintf(stderr, "%s not member of %s group\n", AMAVIS_USER, milter_socket_group);
- *	exit(EXIT_FAILURE);
- *  }
- */
+    if (!(userinfo = getpwnam(AMAVIS_USER))) {
+  	perror("getpwnam");
+  	exit(EXIT_FAILURE);
+    }
+    amavis_gid = userinfo->pw_gid;
+    if (!milter_socket_group) {
+  	milter_socket_group = strdup(MILTER_SOCKET_GROUP);
+  	if (!milter_socket_group) {
+  	    perror("strdup");
+  	    exit(EXIT_FAILURE);
+  	}
+    }
+    group_member(milter_socket_group);
+
     if (!milter_socket) {
 	fprintf(stderr, "%s: no milter socket specified (missing option -p)\n\n", argv[0]);
 	usage();
@@ -1116,11 +1117,22 @@
 	}
     }
 
+    if (pidfile != NULL) {
+        FILE *fp;
+        if ((fp = fopen(pidfile, "w")) == NULL) {
+	     amavis_syslog(DBG_FATAL, "Unable to write PID to file \"%s\": %s", pidfile, strerror(errno));
+	     exit(EXIT_FAILURE);
+        }
+        fprintf(fp, "%ld", (long)getpid());
+        fclose(fp);
+    }
+
     /* change process group id */
     if (miltergroup && (setgid(miltergroup->gr_gid)) < 0) {
 	amavis_syslog(DBG_FATAL, "setgid(%d): %s", miltergroup->gr_gid, strerror(errno));
 	exit(EX_UNAVAILABLE);
     }
+    setuid(userinfo->pw_uid);
 
     /* smfi_settimeout(1800); */     /* defaults to 7210 seconds */
 
