# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# see http://www.akamoz.jp/you/adsl/remove-prepend-v2.htm
# for usage of this patch.
#
Index: qmail-lspawn.c
===================================================================
--- qmail-lspawn.c	(.../netqmail-1.06)	(revision 82)
+++ qmail-lspawn.c	(.../netqmail-1.06-removeprepend2-0.1)	(revision 82)
@@ -13,6 +13,7 @@
 #include "auto_qmail.h"
 #include "auto_uids.h"
 #include "qlx.h"
+#include "vdom-sep.h"
 
 char *aliasempty;
 
@@ -165,9 +166,9 @@
   }
 }
 
-int spawn(fdmess,fdout,s,r,at)
+int spawn(fdmess,fdout,s,r,at,rp)
 int fdmess; int fdout;
-char *s; char *r; int at;
+char *s; char *r; int at; int rp;
 {
  int f;
 
@@ -207,7 +208,7 @@
    args[3] = x;
    n = byte_chr(x,xlen,0); if (n++ == xlen) _exit(QLX_USAGE); x += n; xlen -= n;
 
-   args[4] = r;
+   args[4] = r + rp;
    args[5] = x;
    n = byte_chr(x,xlen,0); if (n++ == xlen) _exit(QLX_USAGE); x += n; xlen -= n;
 
Index: vdom-sep.h
===================================================================
--- vdom-sep.h	(.../netqmail-1.06)	(nonexistent)
+++ vdom-sep.h	(.../netqmail-1.06-removeprepend2-0.1)	(revision 82)
@@ -0,0 +1,3 @@
+#ifndef VSEP
+#define VSEP	":"
+#endif
Index: spawn.c
===================================================================
--- spawn.c	(.../netqmail-1.06)	(revision 82)
+++ spawn.c	(.../netqmail-1.06-removeprepend2-0.1)	(revision 82)
@@ -15,6 +15,7 @@
 #include "auto_qmail.h"
 #include "auto_uids.h"
 #include "auto_spawn.h"
+#include "vdom-sep.h"
 
 extern int truncreport;
 extern int spawn();
@@ -82,6 +83,7 @@
  int f;
  int i;
  int j;
+ int k0, k1;
  int fdmess;
  int pi[2];
  struct stat st;
@@ -118,9 +120,14 @@
  if (pipe(pi) == -1)
   { close(fdmess); err("Zqmail-spawn unable to create pipe. (#4.3.0)\n"); return; }
 
+ k0 = 0;
+ k1 = str_chr(recip.s, VSEP[0]);
+ if (k1 >= recip.len) { err("DInternal error: no vdom separator. (#5.3.5)\n"); return; }
+ if (k1 == 0) { k0 = 1; } else { recip.s[k1++] = '-'; }
+
  coe(pi[0]);
 
- f = spawn(fdmess,pi[1],sender.s,recip.s,j);
+ f = spawn(fdmess,pi[1],sender.s,recip.s+k0,j-k0,k1);
  close(fdmess);
  if (f == -1)
   { close(pi[0]); close(pi[1]); err("Zqmail-spawn unable to fork. (#4.3.0)\n"); return; }
Index: qmail-rspawn.c
===================================================================
--- qmail-rspawn.c	(.../netqmail-1.06)	(revision 82)
+++ qmail-rspawn.c	(.../netqmail-1.06-removeprepend2-0.1)	(revision 82)
@@ -77,9 +77,9 @@
     }
 }
 
-int spawn(fdmess,fdout,s,r,at)
+int spawn(fdmess,fdout,s,r,at,rp)
 int fdmess; int fdout;
-char *s; char *r; int at;
+char *s; char *r; int at; int rp;
 {
  int f;
  char *(args[5]);
@@ -87,7 +87,7 @@
  args[0] = "qmail-remote";
  args[1] = r + at + 1;
  args[2] = s;
- args[3] = r;
+ args[3] = r + rp;
  args[4] = 0;
 
  if (!(f = vfork()))
Index: qmail-send.c
===================================================================
--- qmail-send.c	(.../netqmail-1.06)	(revision 82)
+++ qmail-send.c	(.../netqmail-1.06-removeprepend2-0.1)	(revision 82)
@@ -31,6 +31,7 @@
 #include "constmap.h"
 #include "fmtqfn.h"
 #include "readsubdir.h"
+#include "vdom-sep.h"
 
 /* critical timing feature #1: if not triggered, do not busy-loop */
 /* critical timing feature #2: if triggered, respond within fixed time */
@@ -141,6 +142,7 @@
   at = byte_rchr(addr.s,addr.len,'@');
 
   if (constmap(&maplocals,addr.s + at + 1,addr.len - at - 1)) {
+    if (!stralloc_cats(&rwline,VSEP)) return 0;
     if (!stralloc_cat(&rwline,&addr)) return 0;
     if (!stralloc_0(&rwline)) return 0;
     return 1;
@@ -151,17 +153,20 @@
       if (x = constmap(&mapvdoms,addr.s + i,addr.len - i)) {
         if (!*x) break;
         if (!stralloc_cats(&rwline,x)) return 0;
-        if (!stralloc_cats(&rwline,"-")) return 0;
+        if (!stralloc_cats(&rwline,VSEP)) return 0;
         if (!stralloc_cat(&rwline,&addr)) return 0;
         if (!stralloc_0(&rwline)) return 0;
         return 1;
       }
  
+  if (!stralloc_cats(&rwline,VSEP)) return 0;
   if (!stralloc_cat(&rwline,&addr)) return 0;
   if (!stralloc_0(&rwline)) return 0;
   return 2;
 }
 
+extern char *stripvdomprepend();
+
 void senderadd(sa,sender,recip)
 stralloc *sa;
 char *sender;
@@ -175,6 +180,7 @@
  if (i >= 4)
    if (str_equal(sender + i - 4,"-@[]"))
     {
+     recip = stripvdomprepend(recip);
      j = byte_rchr(sender,i - 4,'@');
      k = str_rchr(recip,'@');
      if (recip[k] && (j + 5 <= i))
@@ -575,26 +581,11 @@
 char *recip;
 {
  int i;
- char *domain;
- int domainlen;
- char *prepend;
 
- i = str_rchr(recip,'@');
- if (!recip[i]) return recip;
- domain = recip + i + 1;
- domainlen = str_len(domain);
-
- for (i = 0;i <= domainlen;++i)
-   if ((i == 0) || (i == domainlen) || (domain[i] == '.'))
-     if (prepend = constmap(&mapvdoms,domain + i,domainlen - i))
-      {
-       if (!*prepend) break;
-       i = str_len(prepend);
-       if (str_diffn(recip,prepend,i)) break;
-       if (recip[i] != '-') break;
-       return recip + i + 1;
-      }
- return recip;
+ i = str_chr(recip, VSEP[0]);
+ if (recip[i] == '\0')
+   return recip;
+ return recip + i + 1;
 }
 
 stralloc bouncetext = {0};
Index: Makefile
===================================================================
--- Makefile	(.../netqmail-1.06)	(revision 82)
+++ Makefile	(.../netqmail-1.06-removeprepend2-0.1)	(revision 82)
@@ -1488,7 +1488,7 @@
 	prioq.o trigger.o fmtqfn.o quote.o now.o readsubdir.o \
 	qmail.o date822fmt.o datetime.a case.a ndelay.a getln.a \
 	wait.a seek.a fd.a sig.a open.a lock.a stralloc.a alloc.a \
-	substdio.a error.a str.a fs.a auto_qmail.o auto_split.o env.a
+	substdio.a error.a fs.a auto_qmail.o auto_split.o env.a str.a
 
 qmail-send.0: \
 qmail-send.8
