changeset 677:c8e85bb330ed

Added support for static bounce addresses (Thomas Jarosch)
author mortenp
date Sat, 01 Nov 2008 02:43:37 +1100
parents c334ffdf8807
children 1d42f8d7a597
files ChangeLog TUNABLES src/mlmmj-send.c
diffstat 3 files changed, 50 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sat Nov 01 01:45:49 2008 +1100
+++ b/ChangeLog	Sat Nov 01 02:43:37 2008 +1100
@@ -1,3 +1,4 @@
+ o Added support for static bounce addresses (Thomas Jarosch)
  o Added a sanity check in mlmmj-receive-strip (Chris Webb)
  o Added more sanity checks (Thomas Jarosch)
  o Disabled digest mails when 'noarchive' is set (Thomas Jarosch)
--- a/TUNABLES	Sat Nov 01 01:45:49 2008 +1100
+++ b/TUNABLES	Sat Nov 01 02:43:37 2008 +1100
@@ -197,3 +197,9 @@
 
    If this is set, the LISTNAME+list@ functionality for requesting an
    email with the subscribers for owner is disabled.
+
+ · staticbounceaddr      	(normal)
+
+   If this is set to something@example.org, the bounce address (Return-Path:)
+   will be fixed to something+listname-bounces-and-so-on@example.org
+   in case you need to disable automatic bounce handling.
--- a/src/mlmmj-send.c	Sat Nov 01 01:45:49 2008 +1100
+++ b/src/mlmmj-send.c	Sat Nov 01 02:43:37 2008 +1100
@@ -102,10 +102,13 @@
 }
 
 char *bounce_from_adr(const char *recipient, const char *listadr,
-		      const char *listdelim, const char *mailfilename)
+		      const char *listdelim, const char *mailfilename,
+		      const char *listdir)
 {
-	char *bounceaddr, *myrecipient, *mylistadr, *mylistdelim;
+	char *bounceaddr, *myrecipient, *mylistadr;
 	char *indexstr, *listdomain, *a = NULL, *mymailfilename;
+	char *staticbounceaddr, *staticbounceaddr_localpart;
+	char *staticbounceaddr_domain;
 	size_t len;
 
 	mymailfilename = mystrdup(mailfilename);
@@ -114,6 +117,10 @@
 	}
 
 	indexstr = get_index_from_filename(mymailfilename);
+	if (!indexstr) {
+		myfree(mymailfilename);
+		return NULL;
+	}
 
 	myrecipient = mystrdup(recipient);
 	if (!myrecipient) {
@@ -131,40 +138,57 @@
 		return NULL;
 	}
 
-	mylistdelim = mystrdup(listdelim);
-	if (!mylistdelim) {
-		myfree(mymailfilename);
-		myfree(myrecipient);
-		myfree(mylistadr);
-		return NULL;
-	}
-
 	listdomain = strchr(mylistadr, '@');
 	if (!listdomain) {
 		myfree(mymailfilename);
 		myfree(myrecipient);
 		myfree(mylistadr);
-		myfree(mylistdelim);
 		return NULL;
 	}
 	*listdomain++ = '\0';
 
 	/* 11 = "bounces-" + "-" + "@" + NUL */
-	len = strlen(mylistadr) + strlen(mylistdelim) + strlen(myrecipient)
+	len = strlen(mylistadr) + strlen(listdelim) + strlen(myrecipient)
 		 + strlen(indexstr) + strlen(listdomain) + 11;
+
+	staticbounceaddr = ctrlvalue(listdir, "staticbounceaddr");
+	if (staticbounceaddr) {
+		staticbounceaddr_localpart = genlistname(staticbounceaddr);
+		staticbounceaddr_domain = genlistfqdn(staticbounceaddr);
+
+		/* localpart + "-" + domain */
+		len += strlen(staticbounceaddr_localpart) + 1
+				+ strlen(staticbounceaddr_domain);
+	} else {
+		staticbounceaddr_localpart = NULL;
+		staticbounceaddr_domain = NULL;
+	}
+
 	bounceaddr = mymalloc(len);
 	if (!bounceaddr) {
+		myfree(staticbounceaddr);
+		myfree(staticbounceaddr_localpart);
+		myfree(staticbounceaddr_domain);
 		myfree(myrecipient);
 		myfree(mylistadr);
-		myfree(mylistdelim);
 		return NULL;
 	}
+
+	if (staticbounceaddr) {
+		snprintf(bounceaddr, len, "%s%s%s-bounces-%s-%s@%s", 
+			staticbounceaddr_localpart, listdelim, mylistadr,
+			indexstr, myrecipient, staticbounceaddr_domain);
+
+		myfree(staticbounceaddr);
+		myfree(staticbounceaddr_localpart);
+		myfree(staticbounceaddr_domain);
+	} else {
 	snprintf(bounceaddr, len, "%s%sbounces-%s-%s@%s", mylistadr, listdelim,
 		 indexstr, myrecipient, listdomain);
+	}
 
 	myfree(myrecipient);
 	myfree(mylistadr);
-	myfree(mylistdelim);
 	myfree(indexstr);
 	myfree(mymailfilename);
 
@@ -629,7 +653,7 @@
 					    hdrs, hdrslen, body, bodylen);
 		} else {
 			bounceaddr = bounce_from_adr(addr, listaddr, listdelim,
-						     archivefilename);
+						     archivefilename, listdir);
 			res = send_mail(sockfd, bounceaddr, addr, replyto,
 				  mailmap, mailsize, listdir, mlmmjbounce,
 				  hdrs, hdrslen, body, bodylen);
@@ -929,7 +953,7 @@
 		deletewhensent = 0;
 		archivefilename = mystrdup(mailfilename);
 		bounceaddr = bounce_from_adr(to_addr, listaddr, listdelim,
-						archivefilename);
+						archivefilename, listdir);
 		break;
 	default: /* normal list mail -- now handled when forking */
 		addtohdr = statctrl(listdir, "addtohdr");