From: mmj Date: Sun, 3 Sep 2006 17:59:07 +0000 (+1000) Subject: Subscriber moderation finished. Will test it all later tonight, but X-Git-Tag: RELEASE_1_2_12_RC1~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=324fe52ef13024be4251534c92bf509a79d7cbf5;p=thirdparty%2Fmlmmj.git Subscriber moderation finished. Will test it all later tonight, but these codepaths won't be touched by regular operation, so it should be allright. --- diff --git a/ChangeLog b/ChangeLog index 70aa76d0..dbf32188 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + o Add subscriber moderation o Fix default subject in administrative mails o Add French listtexts (Christophe Gallienne) o Add search and pagination functionality to the perl-admin web interface diff --git a/TUNABLES b/TUNABLES index accade1e..ac60f939 100644 --- a/TUNABLES +++ b/TUNABLES @@ -28,6 +28,12 @@ to specify several entries (one pr. line), it's marked "list". If this file is present, the emailaddresses in the file listdir/control/moderators will act as moderators for the list. + · submod (list) + + If this file is present, subscription will be moderated by owner(s). + If there's emailaddresses in this file, then these will be used + instead of owner. + · tocc (boolean) If this file is present, the list address does not have to be in the To: diff --git a/include/mlmmj-sub.h b/include/mlmmj-sub.h index 700e9803..2df0e03a 100644 --- a/include/mlmmj-sub.h +++ b/include/mlmmj-sub.h @@ -29,6 +29,8 @@ void moderate_sub(const char *listdir, const char *listaddr, const char *listdelim, const char *subaddr, const char *mlmmjsend, enum subtype typesub); +void getaddrandtype(const char *listdir, const char *modstr, + char **addrptr, enum subtype *subtypeptr); void confirm_sub(const char *listdir, const char *listaddr, const char *listdelim, const char *subaddr, const char *mlmmjsend, enum subtype typesub); diff --git a/src/listcontrol.c b/src/listcontrol.c index 197de883..4197f50d 100644 --- a/src/listcontrol.c +++ b/src/listcontrol.c @@ -584,6 +584,16 @@ int listcontrol(struct email_container *fromemails, const char *listdir, case CTRL_MODERATE: /* TODO Add accept/reject parameter to moderate */ moderatefilename = concatstr(3, listdir, "/moderation/", param); + + /* Subscriber moderation */ + if(strncmp(param, "subscribe", 9) == 0) { + log_oper(listdir, OPLOGFNAME, "%s moderated %s", + fromemails->emaillist[0], moderatefilename); + execlp(mlmmjsub, mlmmjsub, + "-L", listdir, + "-m", param, (char *)NULL); + } + sendfilename = concatstr(2, moderatefilename, ".sending"); if(stat(moderatefilename, &stbuf) < 0) { @@ -603,10 +613,6 @@ int listcontrol(struct email_container *fromemails, const char *listdir, log_oper(listdir, OPLOGFNAME, "%s moderated %s", fromemails->emaillist[0], moderatefilename); - if(strncmp(param, "subscribe", 9) == 0) - execlp(mlmmjsub, mlmmjsub, - "-L", listdir, - "-m", param, (char *)NULL); myfree(moderatefilename); execlp(mlmmjsend, mlmmjsend, "-L", listdir, diff --git a/src/mlmmj-sub.c b/src/mlmmj-sub.c index 94ac0656..43975152 100644 --- a/src/mlmmj-sub.c +++ b/src/mlmmj-sub.c @@ -48,6 +48,7 @@ #include "prepstdreply.h" #include "memory.h" #include "ctrlvalues.h" +#include "chomp.h" void moderate_sub(const char *listdir, const char *listaddr, const char *listdelim, const char *subaddr, @@ -120,7 +121,7 @@ void moderate_sub(const char *listdir, const char *listaddr, myfree(submods); submods = ctrlvalues(listdir, "owner"); myfree(mods); - mods = concatstr(2, listdir, "/control/submod"); + mods = concatstr(2, listdir, "/control/owner"); } /* send mail to moderators about request pending */ @@ -171,11 +172,9 @@ void moderate_sub(const char *listdir, const char *listaddr, log_error(LOG_ARGS, "execl() of '%s' failed", mlmmjsend); } - myfree(from); myfree(to); myfree(replyto); myfree(moderators); - myfree(queuefilename); /* send mail to requester that the list is submod'ed */ @@ -194,15 +193,63 @@ void moderate_sub(const char *listdir, const char *listaddr, log_error(LOG_ARGS, "execl() of '%s' failed", mlmmjsend); } +void getaddrandtype(const char *listdir, const char *modstr, + char **addrptr, enum subtype *subtypeptr) +{ + int fd; + char *readaddr, *readtype, *modfilename; + + modfilename = concatstr(3, listdir, "/moderation/", modstr); + + fd = open(modfilename, O_RDONLY); + if(fd < 0) { + log_error(LOG_ARGS, "Could not open %s", modfilename); + exit(EXIT_FAILURE); + } + + readaddr = mygetline(fd); + readtype = mygetline(fd); + + close(fd); + + if(readaddr == NULL || readtype == NULL) { + log_error(LOG_ARGS, "Could not parse %s", modfilename); + exit(EXIT_FAILURE); + } + + chomp(readaddr); + *addrptr = readaddr; + + if(strncmp(readtype, "SUB_NORMAL", 10) == 0) { + *subtypeptr = SUB_NORMAL; + goto freedone; + } + + if(strncmp(readtype, "SUB_DIGEST", 10) == 0) { + *subtypeptr = SUB_DIGEST; + goto freedone; + } + + if(strncmp(readtype, "SUB_NOMAIL", 10) == 0) { + *subtypeptr = SUB_NOMAIL; + goto freedone; + } + + log_error(LOG_ARGS, "Type %s not valid in %s", readtype, + modfilename); + +freedone: + myfree(readtype); + unlink(modfilename); + myfree(modfilename); +} + void confirm_sub(const char *listdir, const char *listaddr, const char *listdelim, const char *subaddr, const char *mlmmjsend, enum subtype typesub) { char *queuefilename, *fromaddr, *listname, *listfqdn, *listtext; - moderate_sub(listdir, listaddr, listdelim, subaddr, mlmmjsend, - typesub); - listname = genlistname(listaddr); listfqdn = genlistfqdn(listaddr); @@ -379,7 +426,7 @@ void generate_subconfirm(const char *listdir, const char *listaddr, static void print_help(const char *prg) { - printf("Usage: %s -L /path/to/list -a john@doe.org " + printf("Usage: %s -L /path/to/list [-a john@doe.org | -m str]" "[-c] [-C] [-h]\n [-L] [-d | -n] [-s] [-U] [-V]\n" " -a: Email address to subscribe \n" " -c: Send welcome mail\n" @@ -387,12 +434,13 @@ static void print_help(const char *prg) " -d: Subscribe to digest of list\n" " -h: This help\n" " -L: Full path to list directory\n" - " -n: Subscribe to no mail version of list\n" - " -s: Don't send a mail to the subscriber if already subscribed\n" + " -m: moderation string\n" + " -n: Subscribe to no mail version of list\n", prg); + printf(" -s: Don't send a mail to subscriber if already subscribed\n" " -U: Don't switch to the user id of the listdir owner\n" " -V: Print version\n" "When no options are specified, subscription silently " - "happens\n", prg); + "happens\n"); exit(EXIT_SUCCESS); } @@ -433,8 +481,9 @@ int main(int argc, char **argv) char *listaddr, *listdelim, *listdir = NULL, *address = NULL; char *subfilename = NULL, *mlmmjsend, *bindir, chstr[2], *subdir; char *subddirname = NULL, *sublockname, *lowcaseaddr; + char *modstr = NULL; int subconfirm = 0, confirmsub = 0, opt, subfilefd, lock, notifysub; - int changeuid = 1, status, digest = 0, nomail = 0, i = 0, submod; + int changeuid = 1, status, digest = 0, nomail = 0, i = 0, submod = 0; int groupwritable = 0, sublock, sublockfd, nogensubscribed = 0, subbed; size_t len; struct stat st; @@ -450,7 +499,7 @@ int main(int argc, char **argv) mlmmjsend = concatstr(2, bindir, "/mlmmj-send"); myfree(bindir); - while ((opt = getopt(argc, argv, "hcCdnsVUL:a:")) != -1) { + while ((opt = getopt(argc, argv, "hcCdm:nsVUL:a:")) != -1) { switch(opt) { case 'a': address = optarg; @@ -470,6 +519,9 @@ int main(int argc, char **argv) case 'L': listdir = optarg; break; + case 'm': + modstr = optarg; + break; case 'n': nomail = 1; break; @@ -484,12 +536,21 @@ int main(int argc, char **argv) exit(0); } } - - if(listdir == 0 || address == 0) { + + if(listdir == NULL) { fprintf(stderr, "You have to specify -L and -a\n"); fprintf(stderr, "%s -h for help\n", argv[0]); exit(EXIT_FAILURE); } + + if(address == NULL || modstr == NULL) { + fprintf(stderr, "You have to specify -a or -m\n"); + fprintf(stderr, "%s -h for help\n", argv[0]); + exit(EXIT_FAILURE); + } + + if(modstr) + getaddrandtype(listdir, modstr, &address, &typesub); if(strchr(address, '@') == NULL) { log_error(LOG_ARGS, "No '@' sign in '%s', not subscribing", @@ -606,7 +667,8 @@ int main(int argc, char **argv) } subbed = is_subbed_in(subddirname, address); listdelim = getlistdelim(listdir); - submod = statctrl(listdir, "submod"); + if(modstr == NULL) + submod = statctrl(listdir, "submod"); if(subbed) { if(subconfirm) {