diff -uw mailutils/GNUmakefile mailutils-jm/GNUmakefile
--- mailutils/GNUmakefile	Thu Feb 26 14:11:27 2004
+++ mailutils-jm/GNUmakefile	Thu Apr  1 11:57:54 2004
@@ -41,22 +41,22 @@
 
 
 halve-duplicatedb:	halve-duplicatedb.c
-	cc -s -O2 -o halve-duplicatedb halve-duplicatedb.c
+	cc -s -O2 $(CFLAGS) -o halve-duplicatedb halve-duplicatedb.c
 
 
 unquote-printables:	unquote-printables.c
-	cc -s -o unquote-printables -O2 unquote-printables.c
+	cc -s $(CFLAGS) -o unquote-printables -O2 unquote-printables.c
 
 milter-size:		milter-size.c
-	cc -s -o milter-size milter-size.c -O2 -D_REENTRANT \
+	cc -s $(CFLAGS) -o milter-size milter-size.c -O2 -D_REENTRANT \
 	$(LDMILTER)
 
 milter-dnsrbl:		milter-dnsrbl.c
-	cc -s -o milter-dnsrbl milter-dnsrbl.c -O2 -D_REENTRANT \
+	cc -s $(CFLAGS) -o milter-dnsrbl milter-dnsrbl.c -O2 -D_REENTRANT \
 	$(LDDNS) $(LDMILTER)
 
 milter-regexp:		milter-regexp.c
-	cc -s -o milter-regexp milter-regexp.c -O2 -D_REENTRANT \
+	cc -s  $(CFLAGS) -o  milter-regexp milter-regexp.c -O2 -D_REENTRANT \
 	$(LDDNS) $(LDMILTER)
 
 kemail-size-logd:	kemail-size-logd.o
@@ -67,7 +67,7 @@
 
 
 clean:
-	-rm -f *~ *.o
+	-rm -f core *~ *.o
 
 
 distclean:	clean
diff -uw mailutils/halve-duplicatedb.c mailutils-jm/halve-duplicatedb.c
--- mailutils/halve-duplicatedb.c	Thu Feb 26 02:25:03 2004
+++ mailutils-jm/halve-duplicatedb.c	Fri Mar 26 10:26:15 2004
@@ -40,6 +40,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <errno.h>
 
 #define TIMEOUT 10  /*  Seconds  */
 #define ERRSTRING strerror (errno)
diff -uw mailutils/milter-regexp.c mailutils-jm/milter-regexp.c
--- mailutils/milter-regexp.c	Sun Mar  7 22:51:47 2004
+++ mailutils-jm/milter-regexp.c	Thu Apr  1 12:00:17 2004
@@ -84,6 +84,12 @@
 #define FILTER_FLAGS             SMFIF_ADDHDRS | SMFIF_ADDRCPT | SMFIF_DELRCPT
 #define STALL_TIME              10
 
+
+#define CHECK_HEADER              1
+#define CHECK_RECIPIENTS          2
+#define CHECK_SENDER              3
+#define CHECK_BODY                4
+
 #define ACTION_UNITIALISED        0
 #define ACTION_PERMFAIL           1
 #define ACTION_TEMPFAIL           2
@@ -91,6 +97,7 @@
 #define ACTION_DISCARD            4
 #define ACTION_REDIRECT           5
 #define ACTION_ACCEPT             6
+#define ACTION_COPY               7
 #define ACTION_OPTION_MASK     0xf0
 #define ACTION_OPT_STALL       0x10
 
@@ -108,7 +115,7 @@
 {
     flag inverted;                /*  Whether to invert the regexp result    */
     flag and_logic;               /*  TRUE: AND logic, FALSE: OR logic       */
-    flag check_header;            /*  TRUE: header, FALSE: body              */
+    flag check_what;              /*  value from CHECK_* constants           */
     regex_t preg;                 /*  The compiled regular expression        */
     struct regexp *next;          /*  The next regular expression structure  */
 };
@@ -172,6 +179,8 @@
     unsigned int body_overrun;    /*  Number bytes in oversized body line    */
     struct envrcpt *first;        /*  The first envelope recipient           */
     struct envrcpt *last;         /*  The last envelope recipient            */
+    char * sender;                /*  The envelope sender                    */
+    char * envid;                 /*  The envelope ID                        */
     unsigned int wpos;            /*  Position to start writing to buffer    */
     u_char buffer[BODY_BUFLEN];   /*  The overrun buffer                     */
 };
@@ -181,6 +190,7 @@
 static char *usersdir = NULL;
 static flag debug = FALSE;
 
+static void process_line (SMFICTX *ctx, const char *line, flag check_what);
 
 static void put_config (struct config *config, flag grab_lock)
 {
@@ -230,6 +240,7 @@
 */
 {
     char *ptr;
+    flag check_what = 0;
 
     while ( isspace (*line) ) ++line;  /*  Skip leading whitespace  */
     if (*line == '#') return (TRUE);
@@ -240,14 +251,38 @@
 	else break;
     }
     if (ptr <= line) return (TRUE);
-    if ( (*line == 'h') || (*line == 'b') )
+    switch(*line)
+    {
+           case 'H':
+           case 'h':
+                   check_what = CHECK_HEADER;
+                   break;
+           case 'R':
+           case 'r':
+                   check_what = CHECK_RECIPIENTS;
+                   break;
+           case 'S':
+           case 's':
+                   check_what = CHECK_SENDER;
+                   break;
+           case 'B':
+           case 'b':
+                   check_what = CHECK_BODY;
+                   break;
+           default:
+                   check_what = FALSE;
+                   break;
+    }
+
+    if (check_what)
     {
 	struct regexp tmp, *regexp;
 	struct recipe *recipe;
 
 	memset (&tmp, 0, sizeof tmp);
 	tmp.and_logic = TRUE;
-	tmp.check_header = (*line == 'h') ? TRUE : FALSE;
+	tmp.check_what = check_what;
+			
 	if ( ( line = skip_to_next (line) ) == NULL ) return (FALSE);
 	if (*line == '&')
 	{
@@ -277,7 +312,8 @@
 	    ++config->last_recipe->num_expressions;
 	    config->last_recipe->last_regexp->next = regexp;
 	    config->last_recipe->last_regexp = regexp;
-	    if (!regexp->check_header) config->last_recipe->all_header = FALSE;
+	    if (regexp->check_what == CHECK_BODY)
+		    config->last_recipe->all_header = FALSE;
 	    return (TRUE);
 	}
 	/*  Create new recipe  */
@@ -290,7 +326,7 @@
 	recipe->num_expressions = 1;
 	recipe->first_regexp = regexp;
 	recipe->last_regexp = regexp;
-	recipe->all_header = regexp->check_header;
+	recipe->all_header = !(regexp->check_what == CHECK_BODY );
 	if (config->last_recipe) config->last_recipe->next = recipe;
 	else config->first_recipe = recipe;
 	config->last_recipe = recipe;
@@ -347,6 +383,11 @@
 	    *action = (*action & ACTION_OPTION_MASK) + ACTION_REDIRECT;
 	    ptr += 8;
 	}
+	else if (strncasecmp (ptr, "COPY", 4) == 0)
+	{
+	    *action = (*action & ACTION_OPTION_MASK) + ACTION_COPY;
+	    ptr += 4;
+	}
 	else if (strncasecmp (ptr, "ACCEPT", 6) == 0)
 	{
 	    *action = (*action & ACTION_OPTION_MASK) + ACTION_REDIRECT;
@@ -540,8 +581,12 @@
 static sfsistat mlfi_envfrom (SMFICTX *ctx, char **argv)
 {
     struct message *message;
+    char * envid = NULL;
 
-    if (debug) fprintf (stderr, "mlfi_envfrom: \"%s\"\n", argv[0]);
+    if(! (envid = smfi_getsymval(ctx, "i")) )
+	    envid = "NOQUEUE";
+
+    if (debug) fprintf (stderr, "%s: mlfi_envfrom: \"%s\"\n", message->envid, argv[0]);
     if ( ( message = calloc (1, sizeof *message) ) == NULL )
 	return (SMFIS_TEMPFAIL);
     if ( ( message->first = get_envrcpt (NULL) ) == NULL )
@@ -549,8 +594,11 @@
 	free (message);
 	return (SMFIS_TEMPFAIL);
     }
+    message->sender = strdup (argv[0]);
+    message->envid = envid; 
     message->last = message->first;
     smfi_setpriv (ctx, message);
+
     return (SMFIS_CONTINUE);
 }   /*  End Function mlfi_envfrom  */
 
@@ -559,14 +607,17 @@
     struct message *message = smfi_getpriv (ctx);
     struct envrcpt *envrcpt;
 
-    if (debug) fprintf (stderr, "mlfi_envrcpt: \"%s\"\n", argv[0]);
+    if (debug) fprintf (stderr, "%s: mlfi_envrcpt: \"%s\"\n", message->envid, argv[0]);
     if ( ( envrcpt = get_envrcpt (argv[0]) ) == NULL ) return (SMFIS_TEMPFAIL);
     message->last->next = envrcpt;
     message->last = envrcpt;
+
+    process_line (ctx, argv[0], CHECK_RECIPIENTS);
+    
     return (SMFIS_CONTINUE);
 }   /*  End Function mlfi_envrcpt  */
 
-static void process_line (SMFICTX *ctx, const char *line, flag header)
+static void process_line (SMFICTX *ctx, const char *line, flag check_what)
 {
     struct message *message = smfi_getpriv (ctx);
     struct envrcpt *envrcpt;
@@ -585,7 +636,8 @@
 		struct regexp_status *re = rstatus->expressions + count;
 
 		if (re->matched) continue;
-		if (re->regexp->check_header != header) continue;
+		if (re->regexp->check_what != check_what) continue;
+
 		if (regexec (&re->regexp->preg, line, 0, NULL, 0) == 0)
 		    re->matched = TRUE;
 	    }
@@ -607,6 +659,18 @@
 	message->long_header = TRUE;
 	return (SMFIS_CONTINUE);
     }
+
+    if (strncasecmp (headerf,"From:",5) == 0)
+    {
+        process_line (ctx, headerv, CHECK_SENDER); 
+    } 
+    if ( (strncasecmp (headerf,"To:",3) == 0) ||
+         (strncasecmp (headerf,"CC:",3) == 0)
+        )
+    {
+        process_line (ctx, headerv, CHECK_RECIPIENTS);
+    }
+    
     sprintf (buffer, "%s: ", headerf);
     outptr = buffer + len + 2;
     stop = buffer + HEADER_LENGTH;
@@ -622,7 +686,7 @@
 	message->long_header = TRUE;
 	return (SMFIS_CONTINUE);
     }
-    process_line (ctx, buffer, TRUE);
+    process_line (ctx, buffer, CHECK_HEADER);
     return (SMFIS_CONTINUE);
 }   /*  End Function mlfi_header  */
 
@@ -693,6 +757,10 @@
 	    smfi_delrcpt (ctx, (char *) envrcpt->name);
 	smfi_addrcpt (ctx, matched_sys_recipe->string);
 	break;
+      case ACTION_COPY:
+        if (header_only) return (SMFIS_CONTINUE);  /*  Wait until mlfi_eom() */
+	smfi_addrcpt (ctx, matched_sys_recipe->string);
+	break;
       case ACTION_ACCEPT:
 	break;
       default:
@@ -708,7 +776,10 @@
     sfsistat retval;
     struct message *message = smfi_getpriv (ctx);
 
-    if (debug) fprintf (stderr, "mlfi_eoh\n");
+
+    if (debug) fprintf (stderr, "%s: mlfi_eoh\n", message->envid);
+    
+    process_line (ctx, message->sender, CHECK_SENDER); 
     if (message->long_header) return (SMFIS_CONTINUE);
     retval = test_all (ctx, TRUE);
     if (retval != SMFIS_CONTINUE) mlfi_abort (ctx);
@@ -763,10 +834,10 @@
 	    }
 	    memcpy (message->buffer + message->wpos, bodyp, len);
 	    message->buffer[message->wpos + len] = '\0';
-	    process_line (ctx, message->buffer, FALSE);
+	    process_line (ctx, message->buffer, CHECK_BODY);
 	    message->wpos = 0;
 	}
-	else if (eol > bodyp) process_line (ctx, bodyp, FALSE);
+	else if (eol > bodyp) process_line (ctx, bodyp, CHECK_BODY);
 	bodyp = eol + 1;
     }
     return (SMFIS_CONTINUE);
@@ -784,7 +855,7 @@
     static char *err_header = "X-Milter-regexp-error";
     static char *tag_header = "X-Milter-regexp";
 
-    if (debug) fprintf (stderr, "mlfi_eom\n");
+    if (debug) fprintf (stderr, "%s: mlfi_eom\n", message->envid);
     if (message->long_header) smfi_addheader (ctx, err_header, "long header");
     if (message->body_overrun)
     {
@@ -917,13 +988,15 @@
     struct message *message = smfi_getpriv (ctx);
     struct envrcpt *envrcpt, *envrcpt_next;
 
-    if (debug) fprintf (stderr, "mlfi_abort\n");
+    if (debug) fprintf (stderr, "%s: mlfi_abort\n", message->envid);
     smfi_setpriv (ctx, NULL);
     for (envrcpt = message->first; envrcpt; envrcpt = envrcpt_next)
     {
 	envrcpt_next = envrcpt->next;
 	free_envrcpt (envrcpt);
     }
+    if (message->sender)
+    	free (message->sender);
     free (message);
     return (SMFIS_CONTINUE);
 }   /*  End Function mlfi_abort  */
