From 04d4355c3fb349d8881c4c0e7b4705b0df05c8ff Mon Sep 17 00:00:00 2001 From: Peter Simons Date: Tue, 16 Jan 2001 11:33:36 +0000 Subject: [PATCH] Implemented the acked-once feature. --- Makefile.in | 2 +- address-db.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++ hermes.c | 54 ++++++++++++++++++++++++++++++++++++ petidomo.h | 5 ++++ 4 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 address-db.c diff --git a/Makefile.in b/Makefile.in index 1276c24..e72ceab 100644 --- a/Makefile.in +++ b/Makefile.in @@ -27,7 +27,7 @@ OBJS = acl.o archive.o authen.o config.o generate_cookie.o \ filter.o handleacl.o help.o hermes.o index.o io.o listserv.o \ mailer.o members.o parsearray.o password.o rfcparse.o \ subscribe.o tool.o unsubscribe.o main.o queue_command.o \ - queue_posting.o approve.o + queue_posting.o approve.o address-db.o LIBS = librfc822/librfc822.a libmpools/libmpools.a liblists/liblists.a libargv/libargv.a \ libconfigfile/libconfigfile.a libtext/libtext.a diff --git a/address-db.c b/address-db.c new file mode 100644 index 0000000..fe73d01 --- /dev/null +++ b/address-db.c @@ -0,0 +1,78 @@ +/* + $Source$ + $Revision$ + + Copyright (C) 2000 by Peter Simons + + This file is part of OpenPetidomo. + + OpenPetidomo is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + OpenPetidomo is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. +*/ + +#include +#include +#include +#include "libtext/text.h" +#include "petidomo.h" + +/* + * rc == 0: Address is not on list. + * rc == -1: Error occured while reading the file. + * rc == 1: Address is on list. + */ +int is_address_on_list(const char* file, const char* address) + { + char * list; + char * p; + unsigned int len; + int rc; + + list = loadfile(file); + if (list == NULL) + { + if (errno == ENOENT) + return 0; + else + return -1; + } + + for (len = strlen(address), p = list; *p != '\0'; p = text_find_next_line(p)) + { + if (strncasecmp(p, address, len) == 0 && + (p == list || p[-1] == '\n') && + (isspace((int)p[len]) || p[len] == '\0')) + { + break; + } + } + + rc = ((*p != '\0') ? 1 : 0); + free(list); + return rc; + } + +int add_address(const char* file, const char* address) + { + FILE* fh; + int rc = is_address_on_list(file, address); + if (rc != 0) + return rc; + + fh = fopen(file, "a"); + if (fh == NULL) + { + syslog(LOG_ERR, "Failed to open file \"%s\" for writing: %m", file); + return -1; + } + fprintf(fh, "%s\n", address); + fclose(fh); + return 0; + } diff --git a/hermes.c b/hermes.c index 313d1f4..d2208c4 100644 --- a/hermes.c +++ b/hermes.c @@ -199,6 +199,60 @@ hermes_main(char * incoming_mail, const char * listname) } return 0; } + + else if (ListConfig->listtype == LIST_ACKED_ONCE) + { + /* First posting needs an acknowledgement. */ + + if (g_is_approved) + { + int rc = add_address(ListConfig->ack_file, MailStruct->From); + if (rc < 0) + { + syslog(LOG_ERR, "Can't add address to ack file."); + return -1; + } + } + else + { + int rc = is_address_on_list(ListConfig->ack_file, MailStruct->From); + if (rc == 0) + rc = is_address_on_list(ListConfig->ack_file, MailStruct->Envelope); + if (rc < 0) + { + syslog(LOG_ERR, "Can't verify whether address \"%s\" needs to be acknowledged or not.", MailStruct->From); + return -1; + } + else if (rc == 0) + { + char* cookie = queue_posting(MailStruct, listname); + fh = vOpenMailer(owner, MailStruct->Envelope, NULL); + if (fh != NULL) + { + fprintf(fh, "From: petidomo-approve@%s (Petidomo Mailing List Server)\n", ListConfig->fqdn); + fprintf(fh, "To: %s\n", MailStruct->Envelope); + fprintf(fh, "Subject: Petidomo: CONFIRM %s@%s: Your posting to list \"%s\"\n", + listname, ListConfig->fqdn, listname); + fprintf(fh, "Precedence: junk\n"); + fprintf(fh, "Sender: %s\n", owner); + fprintf(fh, "\n"); + fprintf(fh, "Your posting needs to be confirmed. Do this by replying\n"); + fprintf(fh, "to this mail and citing the string\n"); + fprintf(fh, "\n"); + fprintf(fh, " %s\n", cookie); + fprintf(fh, "\n"); + fprintf(fh, "in your reply. You won't have to do that again.\n"); + CloseMailer(fh); + } + else + { + syslog(LOG_ERR, "Failed to send email to \"%s\" concerning this request.", owner); + return -1; + } + return 0; + } + } + } } /* Copy the desired headers from the original mail to our own diff --git a/petidomo.h b/petidomo.h index 8cc2229..cc44e06 100644 --- a/petidomo.h +++ b/petidomo.h @@ -251,4 +251,9 @@ char* queue_posting(const struct Mail* mail, const char* listname); char* queue_command(const struct Mail* mail, const char* command); +/********** address_db.c **********/ + +int is_address_on_list(const char* file, const char* address); +int add_address(const char* file, const char* address); + #endif /* !defined(__PETIDOMO_H__) */