--- lmtpengine.c.orig	Sun Jun 16 17:05:02 2002
+++ lmtpengine.c	Mon Jul  1 18:38:58 2002
@@ -1,5 +1,5 @@
 /* lmtpengine.c: LMTP protocol engine
- * $Id: lmtpengine.c,v 1.1.1.1 2002/06/16 16:05:02 simonl Exp $
+ * $Id: lmtpengine.c,v 1.2 2002/06/16 17:44:18 simonl Exp $
  *
  * Copyright (c) 2000 Carnegie Mellon University.  All rights reserved.
  *
@@ -1150,7 +1150,7 @@
 	}
     }
     else {
-	while (*addr != '@' && *addr != '>') {
+	while ( *addr != '>' && &addr != NULL ) {
 	    if (*addr == '\\') addr++;
 	    *dest++ = *addr++;
 	}
--- lmtpd.c.orig	Sun Jun 16 17:05:02 2002
+++ lmtpd.c	Tue Jun 18 16:53:31 2002
@@ -1,6 +1,6 @@
 /* lmtpd.c -- Program to deliver mail to a mailbox
  *
- * $Id: lmtpd.c,v 1.1.1.1 2002/06/16 16:05:02 simonl Exp $
+ * $Id: lmtpd.c,v 1.5 2002/06/18 15:53:31 simonl Exp $
  * Copyright (c) 1999-2000 Carnegie Mellon University.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -1196,12 +1196,36 @@
     for (n = 0; n < nrcpts; n++) {
 	char *rcpt = xstrdup(msg_getrcpt(msgdata, n));
 	char *plus;
+	char *at_on;
 	int quotaoverride = msg_getrcpt_ignorequota(msgdata, n);
 	int r = 0;
 
 	mydata.cur_rcpt = n;
-	plus = strchr(rcpt, '+');
+	if ( (plus = strchr(rcpt, '+')) != NULL ) {
+		/* simon */
+		/* ok so we are going to put plus in its own space
+		** and make rcpt = user@domain.com 
+		*/
+		if ( (at_on = strchr(plus,'@')) != NULL ) {
+			char *temp;
+			/* need to alloc some memory for plus */
+			temp = (char *) xmalloc(at_on - plus + 1);
+			memcpy(temp,plus+1,at_on-plus);
+			temp[at_on-plus-1] = '\0';
+			memmove(plus,at_on,strlen(at_on)+1); /* must get the null */
+			plus = temp;
+ 
+			syslog(LOG_ERR, "lmtpd patch : %s %s", plus,rcpt);
+		} else {
+			/* just do what would normally happen */
+			*plus = '\0';
+		}
+	}
+
+	/*
+ 	plus = strchr(rcpt, '+');
 	if (plus) *plus++ = '\0';
+	*/
 	/* case 1: shared mailbox request */
 	if (plus && !strcmp(rcpt, BB)) {
 	    strcpy(namebuf, lmtpd_namespace.prefix[NAMESPACE_SHARED]);
@@ -1308,6 +1332,7 @@
 	}
 
     donercpt:
+	if (plus) free(plus);
 	free(rcpt);
 	msg_setrcpt_status(msgdata, n, r);
     }
@@ -1389,6 +1414,7 @@
 {
     char buf[MAX_MAILBOX_NAME];
     char *plus;
+    char *at_on;
     int r;
     int sl = strlen(BB);
 
@@ -1396,7 +1422,6 @@
     if (!strncmp(user, BB, sl) && user[sl] == '+') {
 	/* special shared folder address */
 	strcpy(buf, user + sl + 1);
-	/* Translate any separators in user */
 	mboxname_hiersep_tointernal(&lmtpd_namespace, buf);
 	/* - must have posting privileges on shared folders
 	   - don't care about message size (1 msg over quota allowed) */
@@ -1409,8 +1434,15 @@
 	} else {
 	    strcpy(buf, "user.");
 	    strcat(buf, user);
-	    plus = strchr(buf, '+');
-	    if (plus) *plus = '\0';
+	    if ( (plus = strchr(buf, '+')) != NULL ) {
+	    	/*if (plus) *plus = '\0';*/
+		/* turn simon+what@surf.org.uk */
+		/* into simon@surf.org.uk */
+		/* find @ */
+		if ( (at_on = strchr(plus,'@')) != NULL ) {
+			memmove(plus,at_on,strlen(at_on)+1); /* must get the null */
+		}
+	    }
 	    /* Translate any separators in user */
 	    mboxname_hiersep_tointernal(&lmtpd_namespace, buf+5);
 	    /* - don't care about ACL on INBOX (always allow post)
@@ -1467,14 +1499,18 @@
      */
     if ((msg_getnumrcpt(msgdata) == 1) || singleinstance) {
 	int r = 0;
-	char *rcpt, *plus, *user = NULL;
+	char *rcpt, *plus, *user , *at_on = NULL;
 	char namebuf[MAX_MAILBOX_PATH], mailboxname[MAX_MAILBOX_PATH];
 	time_t now = time(NULL);
 
 	/* build the mailboxname from the recipient address */
 	rcpt = xstrdup(msg_getrcpt(msgdata, 0));
 	plus = strchr(rcpt, '+');
-	if (plus) *plus++ = '\0';
+	if (plus) {
+	if ( (at_on = strchr(plus,'@')) != NULL ) {
+		 memmove(plus,at_on,strlen(at_on)+1); /* must get the null */
+        }
+	}
 
 	/* case 1: shared mailbox request */
 	if (plus && !strcmp(rcpt, BB)) {

