Implemented the acked-once feature.
This commit is contained in:
parent
e4beacc940
commit
04d4355c3f
@ -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
|
||||
|
||||
|
||||
78
address-db.c
Normal file
78
address-db.c
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
$Source$
|
||||
$Revision$
|
||||
|
||||
Copyright (C) 2000 by Peter Simons <simons@computer.org>
|
||||
|
||||
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 <string.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#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;
|
||||
}
|
||||
54
hermes.c
54
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
|
||||
|
||||
@ -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__) */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user