Skip to contentSkip to conversation

Per-list recipient delimiters (patch attached)

PATCH Joel Aelwyn 2 participants 2 messages Oct 1, 2005 – Oct 2, 2005

lore
Share & tools
lore
#0 lore raw

As discussed a bit ago, I've been working on a patch to support per-list configurable recipient delimiters. I believe the patch below covers just about everything, and in some ways is significantly more flexible than most of the alternatives which I've seen so far:

1) Recipient delimiters are considered strings, not characters. This means that it supports arbitrary multi-character sequences; something which isn't used very often in practice, but which is supported by at least some mailers. Really, it's no more complex or slower, so why not support it?

2) Uses the standard configuration file arrangement. The delimiter for a list is read from the first line of .../control/delimiter (not including the newline, if present, of course).

3) I have attempted to keep the patch minimally invasive. Casual visual inspection should be enough to make it fairly obvious what's going on; I have specifically *not* cleaned up several sub-optimal situations that I came across while doing the patch (mostly places with memory leaks that almost certainly don't matter in practice, or where things are re-allocated several times rather than being passed around, despite all callers being guaranteed to have the data available).

4) I have *not* attempted to write a help file for this (apart from, well, this mail).

5) The code has at least a couple of points where it assumes that the literal '-' is safe to use (things like -moderators). However, I cannot find anything where this is actually a failure case; all of the addresses generated this way are either unused, or occur after at least one instance of the actual delimiter (as 'parameter' separators), or do not appear to be used for anything but labeling. However, I don't know every possible situation that could fall into this category offhand, so...

6) The only guarantee you have about this patch is that I'm running it, and so far it hasn't broken things on my server. I certainly tried to throw several pathological cases at it, but I could always have missed something. Since MLMMJ doesn't appear to have any unit test suite, I didn't add any.

7) There is at least one known... hmmm. I'm not sure if it's a 'misfeature' or not, and it will only occur if your server is configured to recognize *multiple* list delimiters (say, both '+' and '-') on all lists. In this case, if someone sends email to, say, 'list-subscribe' but your list is configured to look for '+' as a delimiter, it will fail to match the recipient-extra string (since it is looking for '+...' but the string is '-subscribe'). The only obvious way around this would be to make the delimiter entirely optional, and parse it up front, but read a string provided by the mailer in some fashion to find the recipient-extra portion if it can't match the extra portion at all. If there's demand, I can investigate this; I might do so anyway (since I believe my mailer can provide this, and it would allow users to use either extension), but no promises.

[ Note: the patch was made against sources based on the Debian 1.2.8-7 package, but as far as I know, it *should* patch just fine against stock 1.2.8, possibly with the free() -> myfree() patch for prepstdreply.c that was posted previously. ]

Signature · 1 line
Joel Aelwyn <[email protected]>
include/getlistdelim.h +29 -0
diff -urNad mlmmj-1.2.8.DEBIAN-7/include/getlistdelim.h chroot-work.5/include/getlistdelim.h
@@ -0,0 +1,29 @@
+/* Copyright 2005 Joel Aelwyn <[email protected]>
+ *
+ * $Id$
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef GETLISTDELIM_H
+#define GETLISTDELIM_H
+
+char *getlistdelim(const char *listdir);
+
+#endif /* GETLISTDELIM_H */
include/mlmmj.h +1 -1
diff -urNad mlmmj-1.2.8.DEBIAN-7/include/mlmmj.h chroot-work.5/include/mlmmj.h
@@ -28,7 +28,7 @@
 
 #define RELAYHOST "127.0.0.1"
 #define READ_BUFSIZE 2048
-#define RECIPDELIM '+'  /* XXX Warning: not changable at the moment */
+#define DEFAULT_RECIPDELIM "+"  /* Default recipient delimiter */
 #define MODREQLIFE 604800 /* How long time will moderation requests be kept?
 			   * 604800s is 7 days */
 #define DISCARDEDLIFE 604800 /* How long time will discarded mails be kept?
include/mlmmj-send.h +8 -8
diff -urNad mlmmj-1.2.8.DEBIAN-7/include/mlmmj-send.h chroot-work.5/include/mlmmj-send.h
@@ -31,16 +31,16 @@
 	      size_t bodylen);
 int send_mail_many_fd(int sockfd, const char *from, const char *replyto,
 		   char *mailmap, size_t mailsize, int subfd,
-		   const char *listaddr, const char *archivefilename,
-		   const char *listdir, const char *mlmmjbounce,
-		   const char *hdrs, size_t hdrslen, const char *body,
-		   size_t bodylen);
+		   const char *listaddr, const char *listdelim,
+		   const char *archivefilename, const char *listdir,
+		   const char *mlmmjbounce, const char *hdrs, size_t hdrslen,
+		   const char *body, size_t bodylen);
 int send_mail_many_list(int sockfd, const char *from, const char *replyto,
 		   char *mailmap, size_t mailsize, struct strlist *addrs,
-		   const char *listaddr, const char *archivefilename,
-		   const char *listdir, const char *mlmmjbounce,
-		   const char *hdrs, size_t hdrslen, const char *body,
-		   size_t bodylen);
+		   const char *listaddr, const char *listdelim,
+		   const char *archivefilename, const char *listdir,
+		   const char *mlmmjbounce, const char *hdrs, size_t hdrslen,
+		   const char *body, size_t bodylen);
 int send_mail_verp(int sockfd, struct strlist *addrs, char *mailmap,
 		   size_t mailsize, const char *from, const char *listdir,
 		   const char *hdrs, size_t hdrslen, const char *body,
include/mlmmj-sub.h +4 -4
diff -urNad mlmmj-1.2.8.DEBIAN-7/include/mlmmj-sub.h chroot-work.5/include/mlmmj-sub.h
@@ -27,10 +27,10 @@
 #include <mlmmj.h>
 
 void confirm_sub(const char *listdir, const char *listaddr,
-		 const char *subaddr, const char *mlmmjsend,
-		 enum subtype typesub);
+		 const char *listdelim, const char *subaddr,
+		 const char *mlmmjsend, enum subtype typesub);
 void generate_subconfirm(const char *listdir, const char *listadr,
-		const char *subaddr, const char *mlmmjsend,
-		enum subtype typesub);
+		const char *listdelim, const char *subaddr,
+		const char *mlmmjsend, enum subtype typesub);
 
 #endif /* MLMMJ_SUBSCRIBE_H */
include/mlmmj-unsub.h +4 -4
diff -urNad mlmmj-1.2.8.DEBIAN-7/include/mlmmj-unsub.h chroot-work.5/include/mlmmj-unsub.h
@@ -27,11 +27,11 @@
 #include <sys/types.h>
 
 void confirm_unsub(const char *listdir, const char *listaddr,
-		   const char *subaddr, const char *mlmmj,
-		   enum subtype typesub);
+		   const char *listdelim, const char *subaddr,
+		   const char *mlmmj, enum subtype typesub);
 ssize_t unsubscribe(int subreadfd, int subwritefd, const char *address);
 void generate_unsubconfirm(const char *listdir, const char *listaddr,
-			   const char *subaddr, const char *mlmmjsend,
-			   enum subtype typesub);
+			   const char *listdelim, const char *subaddr,
+			   const char *mlmmjsend, enum subtype typesub);
 
 #endif /* MLMMJ_UNSUBSCRIBE_H */
include/prepstdreply.h +4 -4
diff -urNad mlmmj-1.2.8.DEBIAN-7/include/prepstdreply.h chroot-work.5/include/prepstdreply.h
@@ -24,10 +24,10 @@
 #ifndef PREPSTDREPLY_H
 #define PREPSTDREPLY_H
 
-char *substitute(const char *line, const char *listaddr, size_t datacount,
-		 char **data);
-char *substitute_one(const char *line, const char *listaddr, size_t datacount,
-		 char **data);
+char *substitute(const char *line, const char *listaddr, const char *listdelim,
+		 size_t datacount, char **data);
+char *substitute_one(const char *line, const char *listaddr,
+		 const char *listdelim, size_t datacount, char **data);
 char *prepstdreply(const char *listdir, const char *filename, const char *from,
 		   const char *to, const char *replyto, size_t tokencount,
 		   char **data);
src/getlistdelim.c +70 -0

70 lines not on this page · raw message

src/listcontrol.c +6 -3
diff -urNad mlmmj-1.2.8.DEBIAN-7/src/listcontrol.c chroot-work.6/src/listcontrol.c
@@ -34,6 +34,7 @@
 #include "mlmmj.h"
 #include "listcontrol.h"
 #include "find_email_adr.h"
+#include "getlistdelim.h"
 #include "strgen.h"
 #include "send_help.h"
 #include "send_list.h"
@@ -100,7 +101,7 @@
 		const char *mlmmjunsub, const char *mlmmjsend,
 		const char *mlmmjbounce, const char *mailname)
 {
-	char *atsign, *recipdelimsign, *bouncenr, *tmpstr;
+	char *atsign, *recipdelimsign, *listdelim, *bouncenr, *tmpstr;
 	char *controlstr, *param = NULL, *conffilename, *moderatefilename;
 	char *c, *archivefilename, *sendfilename;
 	const char *subswitch;
@@ -120,7 +121,8 @@
 	else
 		subswitch = "-C";
 	
-	recipdelimsign = index(controladdr, RECIPDELIM);
+	listdelim = getlistdelim(listdir);
+	recipdelimsign = strstr(controladdr, listdelim);
 	MY_ASSERT(recipdelimsign);
 	atsign = index(controladdr, '@');
 	MY_ASSERT(atsign);
@@ -128,7 +130,8 @@
 
 	controlstr = mymalloc(len);
 	MY_ASSERT(controlstr);
-	snprintf(controlstr, len, "%s", recipdelimsign + 1);
+	snprintf(controlstr, len, "%s", recipdelimsign + strlen(listdelim));
+	myfree(listdelim);
 
 #if 0
 	log_error(LOG_ARGS, "controlstr = [%s]\n", controlstr);
src/Makefile.in +27 -26

116 lines not on this page · raw message

src/mlmmj-bounce.c +5 -2
diff -urNad mlmmj-1.2.8.DEBIAN-7/src/mlmmj-bounce.c chroot-work.5/src/mlmmj-bounce.c
@@ -36,6 +36,7 @@
 #include <ctype.h>
 
 #include "getlistaddr.h"
+#include "getlistdelim.h"
 #include "mlmmj.h"
 #include "strgen.h"
 #include "wrappers.h"
@@ -101,7 +102,7 @@
 void do_probe(const char *listdir, const char *mlmmjsend, const char *addr)
 {
 	char *myaddr, *from, *a, *indexstr, *queuefilename, *listaddr;
-	char *listfqdn, *listname, *probefile;
+	char *listfqdn, *listname, *probefile, *listdelim=getlistdelim(listdir);
 	char *maildata[] = { "bouncenumbers", NULL };
 	int fd;
 	time_t t;
@@ -112,9 +113,11 @@
 	listname = genlistname(listaddr);
 	listfqdn = genlistfqdn(listaddr);
 
-	from = concatstr(5, listname, "+bounces-probe-", myaddr, "@", listfqdn);
+	from = concatstr(6, listname, listdelim, "bounces-probe-", myaddr, "@",
+			 listfqdn);
 
 	myfree(listaddr);
+	myfree(listdelim);
 	myfree(listfqdn);
 	myfree(listname);
 
src/mlmmj-process.c +32 -18

128 lines not on this page · raw message

src/mlmmj-send.c +62 -33

266 lines not on this page · raw message

src/mlmmj-sub.c +33 -26

164 lines not on this page · raw message

src/mlmmj-unsub.c +33 -25

164 lines not on this page · raw message

src/prepstdreply.c +32 -21

138 lines not on this page · raw message

src/send_digest.c +7 -2
diff -urNad mlmmj-1.2.8.DEBIAN-7/src/send_digest.c chroot-work.5/src/send_digest.c
@@ -36,6 +36,7 @@
 #include "strgen.h"
 #include "memory.h"
 #include "getlistaddr.h"
+#include "getlistdelim.h"
 #include "wrappers.h"
 
 
@@ -45,7 +46,7 @@
 	int i, fd, archivefd, status, hdrfd;
 	char buf[45];
 	char *tmp, *queuename = NULL, *archivename, *fromstr;
-	char *boundary, *listaddr, *listname, *listfqdn;
+	char *boundary, *listaddr, *listdelim, *listname, *listfqdn;
 	pid_t childpid, pid;
 
 	if (addr) {
@@ -90,7 +91,11 @@
 		snprintf(buf, sizeof(buf), " (%d-%d)", firstindex, lastindex);
 	}
 
-	fromstr = concatstr(5, "From: ", listname, "+help@", listfqdn, "\n");
+	listdelim = getlistdelim(listdir);
+	fromstr = concatstr(6, "From: ", listname, listdelim, "help@", listfqdn,
+			    "\n");
+	myfree(listdelim);
+
 	tmp = concatstr(6, "MIME-Version: 1.0"
 			    "\nContent-Type: multipart/" DIGESTMIMETYPE "; "
 			    "boundary=", boundary,
src/send_help.c +6 -2
diff -urNad mlmmj-1.2.8.DEBIAN-7/src/send_help.c chroot-work.5/src/send_help.c
@@ -34,6 +34,7 @@
 #include "strgen.h"
 #include "find_email_adr.h"
 #include "getlistaddr.h"
+#include "getlistdelim.h"
 #include "log_error.h"
 #include "chomp.h"
 #include "wrappers.h"
@@ -44,13 +45,16 @@
 void send_help(const char *listdir, const char *emailaddr,
 	       const char *mlmmjsend)
 {
-	char *queuefilename, *listaddr, *listname, *listfqdn, *fromaddr;
+	char *queuefilename, *listaddr, *listdelim, *listname, *listfqdn;
+	char *fromaddr;
 
 	listaddr = getlistaddr(listdir);
+	listdelim = getlistdelim(listdir);
 	listname = genlistname(listaddr);
 	listfqdn = genlistfqdn(listaddr);
 
-	fromaddr = concatstr(3, listname, "+bounces-help@", listfqdn);
+	fromaddr = concatstr(4, listname, listdelim, "bounces-help@", listfqdn);
+	myfree(listdelim);
 
 	queuefilename = prepstdreply(listdir, "listhelp", "$listowner$",
 					emailaddr, NULL, 0, NULL);
src/send_list.c +6 -3
diff -urNad mlmmj-1.2.8.DEBIAN-7/src/send_list.c chroot-work.5/src/send_list.c
@@ -34,6 +34,7 @@
 #include "send_list.h"
 #include "strgen.h"
 #include "getlistaddr.h"
+#include "getlistdelim.h"
 #include "log_error.h"
 #include "chomp.h"
 #include "wrappers.h"
@@ -44,18 +45,20 @@
 void send_list(const char *listdir, const char *emailaddr,
 	       const char *mlmmjsend)
 {
-	char *queuefilename, *listaddr, *listname, *listfqdn, *fromaddr;
-	char *subdir, *fileiter;
+	char *queuefilename, *listaddr, *listdelim, *listname, *listfqdn;
+	char *fromaddr, *subdir, *fileiter;
 	DIR *dirp;
 	struct dirent *dp;
 	int fd, subfd;
 
 	listaddr = getlistaddr(listdir);
+	listdelim = getlistdelim(listdir);
 	listname = genlistname(listaddr);
 	listfqdn = genlistfqdn(listaddr);
 	subdir = concatstr(2, listdir, "/subscribers.d/");
 
-	fromaddr = concatstr(3, listname, "+bounces-help@", listfqdn);
+	fromaddr = concatstr(4, listname, listdelim, "bounces-help@", listfqdn);
+	myfree(listdelim);
 
 	queuefilename = prepstdreply(listdir, "listsubs", "$listowner$",
 					emailaddr, NULL, 0, NULL);
#1 lore raw
Quoted 4 lines · Joel Aelwyn

As discussed a bit ago, I've been working on a patch to support per-list configurable recipient delimiters. I believe the patch below covers just about everything, and in some ways is significantly more flexible than most of the alternatives which I've seen so far:

[snip good stuff]

Thanks a lot. I'll review and merge the patch next week. 1.2.9 is coming closer.

Signature · 4 lines
Mads Martin Joergensen, http://mmj.dk
"Why make things difficult, when it is possible to make them cryptic
 and totally illogical, with just a little bit more effort?"
                                -- A. P. J.