diff -ur qmailadmin-1.2.7/ChangeLog qmailadmin-1.2.7-regexpok/ChangeLog
--- qmailadmin-1.2.7/ChangeLog  2005-01-23 22:00:41.000000000 +0100
+++ qmailadmin-1.2.7-regexpok/ChangeLog 2005-03-23 12:39:42.738577464 +0100
@@ -1,6 +1,12 @@
 Numbers in square brackets ([]) indicate tracker item on SourceForge with
 patch or information related to the entry.

+1.2.7a - released 23-Mar-05
+        - personal release by Valerio Granato <valerio [at] grana.to>, spam
+          command as template; usable variables: %user%, %domain%, %dir%
+        - Added --enable-spam-start to define the line start to be used
+          to recognize if the .qmail file contains the antispam call
+
 1.2.7 - released 23-Jan-05

    Tomas Kuliavas
diff -ur qmailadmin-1.2.7/Makefile.in qmailadmin-1.2.7-regexpok/Makefile.in
--- qmailadmin-1.2.7/Makefile.in    2005-01-23 21:58:33.000000000 +0100
+++ qmailadmin-1.2.7-regexpok/Makefile.in   2005-03-23 12:41:08.807493000 +0100
@@ -82,6 +82,7 @@
 QA_VERSION = @QA_VERSION@
 RANLIB = @RANLIB@
 SPAM_COMMAND = @SPAM_COMMAND@
+SPAM_START = @SPAM_START@
 STRIP = @STRIP@
 VERSION = @QA_VERSION@
 am__include = @am__include@
diff -ur qmailadmin-1.2.7/config.h.in qmailadmin-1.2.7-regexpok/config.h.in
--- qmailadmin-1.2.7/config.h.in    2005-01-23 21:58:33.000000000 +0100
+++ qmailadmin-1.2.7-regexpok/config.h.in   2005-03-23 12:41:26.715770528 +0100
@@ -150,6 +150,9 @@
 /* "" */
 #undef SPAM_COMMAND

+/* "" */
+#undef SPAM_START
+
 /* Define to 1 if you have the ANSI C header files. */
 #undef STDC_HEADERS

diff -ur qmailadmin-1.2.7/configure qmailadmin-1.2.7-regexpok/configure
--- qmailadmin-1.2.7/configure  2005-01-23 21:58:33.000000000 +0100
+++ qmailadmin-1.2.7-regexpok/configure 2005-03-23 12:44:35.118129016 +0100
@@ -4535,6 +4535,17 @@
 #define SPAM_COMMAND "$spam_command"
 _ACEOF

+spam_start="$spam_command"
+# Check whether --enable-spam_start or --disable-spam_start was given.
+if test "${enable_spam_start+set}" = set; then
+  enableval="$enable_spam_start"
+  spam_start="$enableval"
+fi;
+
+cat >>confdefs.h <<_ACEOF
+#define SPAM_START "$spam_start"
+_ACEOF
+


 HELP=no
@@ -5835,5 +5846,6 @@
 if test "$MODIFY_SPAM" = "yes"
 then
         echo "      spam command = "$spam_command""
+        echo "      spam start   = "$spam_start""
 fi

diff -ur qmailadmin-1.2.7/configure.in qmailadmin-1.2.7-regexpok/configure.in
--- qmailadmin-1.2.7/configure.in   2005-01-23 21:58:33.000000000 +0100
+++ qmailadmin-1.2.7-regexpok/configure.in  2005-03-23 12:43:57.255884952 +0100
@@ -372,6 +372,13 @@
 AC_DEFINE_UNQUOTED(SPAM_COMMAND, "$spam_command","")
 AC_SUBST(SPAM_COMMAND)

+spam_start="$spam_command"
+AC_ARG_ENABLE(spam_start, [  --enable-spam-start=CMD    Defaults to spam-command.],
+    spam_start="$enableval",
+)
+AC_DEFINE_UNQUOTED(SPAM_START, "$spam_start","")
+AC_SUBST(SPAM_START)
+
 HELP=no
 AC_ARG_ENABLE(help, [  --enable-help  Display help links on login page.],
     HELP="$enableval",)
@@ -433,5 +440,6 @@
 if test "$MODIFY_SPAM" = "yes"
 then
         echo "      spam command = "$spam_command""
+        echo "      spam start   = "$spam_start""
 fi

diff -ur qmailadmin-1.2.7/user.c qmailadmin-1.2.7-regexpok/user.c
--- qmailadmin-1.2.7/user.c 2005-01-03 21:31:09.000000000 +0100
+++ qmailadmin-1.2.7-regexpok/user.c    2005-03-23 12:12:24.000000000 +0100
@@ -47,7 +47,9 @@
 #include "util.h"
 #include "vpopmail.h"
 #include "vauth.h"
+#include <regex.h>

+char *template_expansion(const char *string, const char *pattern, const char *replace);

 #define HOOKS 1

@@ -497,7 +499,11 @@
     if(strcmp(spamvalue, "on") == 0) {
        snprintf(NewBuf, sizeof(NewBuf), "%s/.qmail", mypw->pw_dir);
        fs = fopen(NewBuf, "w+");
-       fprintf(fs, "%s\n", SPAM_COMMAND);
+       char *real_spam_command;
+       real_spam_command = (char *) template_expansion(SPAM_COMMAND, "%user%", mypw->pw_name);
+       real_spam_command = (char *) template_expansion(real_spam_command, "%dir%", mypw->pw_dir);
+       real_spam_command = (char *) template_expansion(real_spam_command, "%domain%", Domain);
+       fprintf (fs, "%s\n", real_spam_command);
        fclose(fs);
     }
 #endif
@@ -917,7 +923,7 @@
       if ( (*dotqmailline == '|') &&
           (strstr (dotqmailline, "/true delete") == NULL) &&
           (strstr (dotqmailline, "/autorespond ") == NULL) &&
-          (strstr (dotqmailline, SPAM_COMMAND) == NULL) ) {
+          (strstr (dotqmailline, SPAM_START) == NULL) ) {
         fprintf (fs, "%s\n", dotqmailline);
         emptydotqmail = 0;
       }
@@ -970,8 +976,12 @@
     if (strcmp (cforward, "blackhole") == 0) {
       fprintf (fs, "# delete\n");
       emptydotqmail = 0;
-    } else if (spam_check == 1) {
-      fprintf (fs, "%s\n", SPAM_COMMAND);
+    } else if (spam_check == 1) {
+      char *real_spam_command;
+      real_spam_command = (char *) template_expansion(SPAM_COMMAND, "%user%", vpw->pw_name);
+      real_spam_command = (char *) template_expansion(real_spam_command, "%dir%", vpw->pw_dir);
+      real_spam_command = (char *) template_expansion(real_spam_command, "%domain%", Domain);
+      fprintf (fs, "%s\n", real_spam_command);
       emptydotqmail = 0;
     } else {
       fprintf (fs, "%s/" MAILDIR "/\n", vpw->pw_dir);
@@ -1064,7 +1074,7 @@
               fs2 = fopen (fn, "r");
             }

-            else if (strstr (linebuf, SPAM_COMMAND) != NULL )
+            else if (strstr (linebuf, SPAM_START) != NULL )
               dotqmail_flags |= DOTQMAIL_SPAMCHECK;

             else /* unrecognized program delivery, set a flag so we don't blackhole */
@@ -1179,3 +1189,82 @@

 }

+char *template_expansion(const char *string, const char *pattern, const char *replace) {
+    regex_t re;
+    regmatch_t *subs;
+
+    char *buf, *nbuf, *walkbuf, *original;
+    const char *walk;
+    int buf_len;
+    int pos, tmp, string_len, new_l;
+    int err = 0;
+
+    string_len = strlen(string);
+    original = (char *) malloc(string_len);
+    strcpy(original, string);
+
+    err = regcomp(&re, pattern, REG_ICASE|REG_EXTENDED);
+    if (err) return original;
+
+    subs = (regmatch_t *)malloc(sizeof(regmatch_t)*re.re_nsub+1);
+
+    buf_len = 2 * string_len + 1;
+    buf = (char *)malloc(buf_len*sizeof(char));
+
+    err = pos = 0;
+    buf[0] = '\0';
+    while (!err) {
+        err = regexec(&re, &string[pos], re.re_nsub+1, subs, (pos ? REG_NOTBOL : 0));
+
+        if (err && err != REG_NOMATCH) {
+            free(subs);
+            free(buf);
+            regfree(&re);
+            return original;
+        }
+
+        if (!err) {
+            tmp = strlen(buf);
+            strncat(buf, &string[pos], subs[0].rm_so);
+
+            walkbuf = &buf[tmp + subs[0].rm_so];
+            walk = replace;
+            while (*walk) {
+                *walkbuf++ = *walk++;
+            }
+
+            *walkbuf = '\0';
+            if (subs[0].rm_so == subs[0].rm_eo) {
+                if (subs[0].rm_so + pos >= string_len)  break;
+                new_l = strlen (buf) + 1;
+                if (new_l + 1 > buf_len) {
+                    buf_len = 1 + buf_len + 2 * new_l;
+                    nbuf = (char *) malloc(buf_len * sizeof(char));
+                    strcpy(nbuf, buf);
+                    free(buf);
+                    buf = nbuf;
+                }
+                pos += subs[0].rm_eo + 1;
+                buf [new_l-1] = string [pos-1];
+                buf [new_l] = '\0';
+            } else {
+                pos += subs[0].rm_eo;
+            }
+        } else {
+            new_l = strlen(buf) + strlen(&string[pos]);
+            if (new_l + 1 > buf_len) {
+                buf_len = new_l + 1;
+                nbuf = (char *) malloc(buf_len * sizeof(char));
+                strcpy(nbuf, buf);
+                free(buf);
+                buf = nbuf;
+            }
+            strcat(buf, &string[pos]);
+        }
+    }
+
+    free(subs);
+    regfree(&re);
+
+    return (buf);
+}
