2000-12-13 13:19:03 +00:00
|
|
|
/*
|
2000-12-13 15:35:14 +00:00
|
|
|
$Source$
|
|
|
|
|
$Revision$
|
|
|
|
|
|
|
|
|
|
Copyright (C) 2000 by CyberSolutions GmbH, Germany.
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
2000-12-13 13:19:03 +00:00
|
|
|
|
|
|
|
|
#include <string.h>
|
2000-12-13 15:35:14 +00:00
|
|
|
#include "libtext/text.h"
|
|
|
|
|
#include "petidomo.h"
|
2000-12-13 13:19:03 +00:00
|
|
|
|
|
|
|
|
int
|
|
|
|
|
DeleteAddress(struct Mail * MailStruct,
|
|
|
|
|
const char * param1,
|
|
|
|
|
const char * param2,
|
|
|
|
|
const char * defaultlist)
|
2001-01-11 14:10:57 +00:00
|
|
|
{
|
|
|
|
|
const struct PD_Config * MasterConfig;
|
2000-12-13 13:19:03 +00:00
|
|
|
const struct List_Config * ListConfig;
|
|
|
|
|
FILE * fh;
|
|
|
|
|
const char * address = NULL;
|
|
|
|
|
const char * listname = NULL;
|
|
|
|
|
char owner[4096];
|
|
|
|
|
char envelope[4096];
|
|
|
|
|
char * buffer;
|
|
|
|
|
char * originator;
|
|
|
|
|
char * p;
|
|
|
|
|
char * list;
|
|
|
|
|
|
2001-01-11 14:10:57 +00:00
|
|
|
/* Initialize internal stuff from master config file. */
|
|
|
|
|
|
|
|
|
|
MasterConfig = getMasterConfig();
|
|
|
|
|
sprintf(envelope, "petidomo-manager@%s", MasterConfig->fqdn);
|
|
|
|
|
originator = (MailStruct->Reply_To) ? MailStruct->Reply_To : MailStruct->From;
|
|
|
|
|
|
2000-12-13 13:19:03 +00:00
|
|
|
/* Try to find out, which parameter is what. */
|
|
|
|
|
|
2001-01-11 14:10:57 +00:00
|
|
|
if (param1 != NULL)
|
|
|
|
|
{
|
2000-12-13 13:19:03 +00:00
|
|
|
if (isValidListName(param1) == TRUE)
|
2001-01-11 14:10:57 +00:00
|
|
|
listname = param1;
|
2000-12-13 13:19:03 +00:00
|
|
|
else if (isRFC822Address(param1) == TRUE)
|
2001-01-11 14:10:57 +00:00
|
|
|
address = param1;
|
|
|
|
|
|
|
|
|
|
if (param2 != NULL)
|
|
|
|
|
{
|
|
|
|
|
if (listname == NULL && isValidListName(param2) == TRUE)
|
|
|
|
|
listname = param2;
|
|
|
|
|
else if (address == NULL && isRFC822Address(param2) == TRUE)
|
|
|
|
|
address = param2;
|
|
|
|
|
}
|
2000-12-13 13:19:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (address == NULL)
|
2001-01-11 14:10:57 +00:00
|
|
|
address = (MailStruct->Reply_To) ? MailStruct->Reply_To : MailStruct->From;
|
|
|
|
|
assert(address != NULL);
|
|
|
|
|
|
|
|
|
|
if (listname == NULL)
|
|
|
|
|
{
|
|
|
|
|
if (defaultlist != NULL)
|
|
|
|
|
listname = defaultlist;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
syslog(LOG_NOTICE, "%s: unsubscribe-command invalid: No list specified.", MailStruct->From);
|
|
|
|
|
fh = vOpenMailer(envelope, originator, NULL);
|
|
|
|
|
if (fh != NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf(fh, "From: petidomo@%s (Petidomo Mailing List Server)\n", MasterConfig->fqdn);
|
|
|
|
|
fprintf(fh, "To: %s\n", originator);
|
|
|
|
|
fprintf(fh, "Subject: Petidomo: Your request \"unsubscribe %s\"\n", address);
|
|
|
|
|
if (MailStruct->Message_Id != NULL)
|
|
|
|
|
fprintf(fh, "In-Reply-To: %s\n", MailStruct->Message_Id);
|
|
|
|
|
fprintf(fh, "Precedence: junk\n");
|
|
|
|
|
fprintf(fh, "Sender: %s\n", envelope);
|
|
|
|
|
fprintf(fh, "\n");
|
|
|
|
|
buffer = text_easy_sprintf("You tried to unsubscribe the address \"%s\" from a mailing list. " \
|
|
|
|
|
"Unfortunately, your request could not be processed, because " \
|
|
|
|
|
"you didn't specify a valid mailing list name from which the " \
|
|
|
|
|
"address should be unsubscribed. You may use the command INDEX " \
|
|
|
|
|
"to receive an overview over the available mailing lists. Also, " \
|
|
|
|
|
"use the command HELP to verify that you got the command syntax " \
|
|
|
|
|
"right.", address);
|
|
|
|
|
text_wordwrap(buffer, 70);
|
|
|
|
|
fprintf(fh, "%s\n", buffer);
|
|
|
|
|
CloseMailer(fh);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
syslog(LOG_ERR, "Failed to send email to \"%s\" concerning his request.", originator);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-12-13 13:19:03 +00:00
|
|
|
|
2001-01-11 14:10:57 +00:00
|
|
|
/* Initialize internal stuff again from list config. */
|
2000-12-13 13:19:03 +00:00
|
|
|
|
|
|
|
|
ListConfig = getListConfig(listname);
|
|
|
|
|
sprintf(owner, "%s-owner@%s", listname, ListConfig->fqdn);
|
|
|
|
|
sprintf(envelope, "%s-owner@%s", listname, ListConfig->fqdn);
|
|
|
|
|
|
|
|
|
|
/* Check whether the request is authorized at all. */
|
|
|
|
|
|
2001-01-11 14:10:57 +00:00
|
|
|
if (isValidAdminPassword(getPassword(), listname) == FALSE)
|
|
|
|
|
{
|
2000-12-13 13:19:03 +00:00
|
|
|
/* No valid password, check further. */
|
|
|
|
|
|
2001-01-15 16:55:45 +00:00
|
|
|
if (ListConfig->subtype == SUBSCRIPTION_ADMIN)
|
2001-01-11 14:10:57 +00:00
|
|
|
{
|
2000-12-13 13:19:03 +00:00
|
|
|
/* Access was unauthorized, notify the originator. */
|
|
|
|
|
|
|
|
|
|
syslog(LOG_INFO, "\"%s\" tried to unsubscribe \"%s\" from list \"%s\", but " \
|
2001-01-11 14:10:57 +00:00
|
|
|
"couldn't provide the correct password.", originator, address, listname);
|
2000-12-13 13:19:03 +00:00
|
|
|
|
|
|
|
|
fh = vOpenMailer(envelope, originator, NULL);
|
2001-01-11 14:10:57 +00:00
|
|
|
if (fh != NULL)
|
|
|
|
|
{
|
2000-12-13 13:19:03 +00:00
|
|
|
fprintf(fh, "From: %s-request@%s (Petidomo Mailing List Server)\n",
|
|
|
|
|
listname, ListConfig->fqdn);
|
|
|
|
|
fprintf(fh, "To: %s\n", originator);
|
2001-01-06 11:05:08 +00:00
|
|
|
fprintf(fh, "Subject: Petidomo: Your request \"unsubscribe %s %s\"\n",
|
2000-12-13 13:19:03 +00:00
|
|
|
address, listname);
|
|
|
|
|
if (MailStruct->Message_Id != NULL)
|
2001-01-11 14:10:57 +00:00
|
|
|
fprintf(fh, "In-Reply-To: %s\n", MailStruct->Message_Id);
|
2000-12-13 13:19:03 +00:00
|
|
|
fprintf(fh, "Precedence: junk\n");
|
|
|
|
|
fprintf(fh, "Sender: %s\n", envelope);
|
|
|
|
|
fprintf(fh, "\n");
|
|
|
|
|
buffer = text_easy_sprintf(
|
2001-01-11 14:10:57 +00:00
|
|
|
"The mailing list \"%s\" is a closed forum and only the maintainer may " \
|
|
|
|
|
"unsubscribe addresses. Your request has been forwarded to the " \
|
|
|
|
|
"appropriate person, so please don't send any further mail. You will " \
|
|
|
|
|
"be notified as soon as possible.", listname);
|
2001-01-10 17:12:40 +00:00
|
|
|
text_wordwrap(buffer, 70);
|
2000-12-13 13:19:03 +00:00
|
|
|
fprintf(fh, "%s\n", buffer);
|
|
|
|
|
CloseMailer(fh);
|
2001-01-11 14:10:57 +00:00
|
|
|
}
|
2000-12-13 13:19:03 +00:00
|
|
|
else
|
2001-01-11 14:10:57 +00:00
|
|
|
syslog(LOG_ERR, "Failed to send email to \"%s\" concerning his request.",
|
|
|
|
|
originator);
|
2000-12-13 13:19:03 +00:00
|
|
|
|
|
|
|
|
/* Notify the owner. */
|
|
|
|
|
|
|
|
|
|
fh = vOpenMailer(envelope, owner, NULL);
|
2001-01-11 14:10:57 +00:00
|
|
|
if (fh != NULL)
|
|
|
|
|
{
|
2000-12-13 13:19:03 +00:00
|
|
|
fprintf(fh, "From: %s-request@%s (Petidomo Mailing List Server)\n",
|
|
|
|
|
listname, ListConfig->fqdn);
|
|
|
|
|
fprintf(fh, "To: %s\n", owner);
|
2001-01-06 11:05:08 +00:00
|
|
|
fprintf(fh, "Subject: Petidomo: APPROVE %s@%s: Unauthorized request from \"%s\"\n", listname, ListConfig->fqdn, originator);
|
2000-12-13 13:19:03 +00:00
|
|
|
fprintf(fh, "Precedence: junk\n");
|
|
|
|
|
fprintf(fh, "Sender: %s\n", envelope);
|
|
|
|
|
fprintf(fh, "\n");
|
|
|
|
|
buffer = text_easy_sprintf(
|
2001-01-11 14:10:57 +00:00
|
|
|
"\"%s\" tried to unsubscribe the address \"%s\" from the \"%s\" mailing list, " \
|
|
|
|
|
"but couldn't provide the correct password. To unsubscribe him, send the " \
|
|
|
|
|
"following commands to the server:", originator, address, listname);
|
2001-01-10 17:12:40 +00:00
|
|
|
text_wordwrap(buffer, 70);
|
2000-12-13 13:19:03 +00:00
|
|
|
fprintf(fh, "%s\n\n", buffer);
|
|
|
|
|
fprintf(fh, "password <AdminPassword>\n");
|
|
|
|
|
fprintf(fh, "unsubscribe %s %s\n", address, listname);
|
|
|
|
|
CloseMailer(fh);
|
2001-01-11 14:10:57 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2000-12-13 13:19:03 +00:00
|
|
|
syslog(LOG_ERR, "Failed to send email to \"%s\"!", owner);
|
|
|
|
|
return -1;
|
2001-01-11 14:10:57 +00:00
|
|
|
}
|
2000-12-13 13:19:03 +00:00
|
|
|
return 0;
|
2001-01-11 14:10:57 +00:00
|
|
|
}
|
2001-01-16 11:57:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Okay, remove the address from the list. */
|
2001-01-15 17:56:33 +00:00
|
|
|
|
2001-01-16 11:57:51 +00:00
|
|
|
if (isSubscribed(listname, address, &list, &p, FALSE) == FALSE)
|
|
|
|
|
{
|
|
|
|
|
/* Notify the originator, that the address is not subscribed at
|
|
|
|
|
all. */
|
|
|
|
|
|
|
|
|
|
fh = vOpenMailer(envelope, originator, NULL);
|
|
|
|
|
if (fh != NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf(fh, "From: %s-request@%s (Petidomo Mailing List Server)\n",
|
|
|
|
|
listname, ListConfig->fqdn);
|
|
|
|
|
fprintf(fh, "To: %s\n", originator);
|
|
|
|
|
fprintf(fh, "Subject: Petidomo: Your request \"unsubscribe %s %s\"\n",
|
|
|
|
|
address, listname);
|
|
|
|
|
if (MailStruct->Message_Id != NULL)
|
|
|
|
|
fprintf(fh, "In-Reply-To: %s\n", MailStruct->Message_Id);
|
|
|
|
|
fprintf(fh, "Precedence: junk\n");
|
|
|
|
|
fprintf(fh, "Sender: %s\n", envelope);
|
|
|
|
|
fprintf(fh, "\n");
|
|
|
|
|
fprintf(fh, "The address is not subscribed to this list.\n");
|
|
|
|
|
CloseMailer(fh);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
syslog(LOG_ERR, "Failed to send email to \"%s\" concerning his request.",
|
|
|
|
|
originator);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (isValidAdminPassword(getPassword(), listname) == FALSE &&
|
|
|
|
|
ListConfig->subtype == SUBSCRIPTION_ACKED && !g_is_approved)
|
2001-01-15 17:56:33 +00:00
|
|
|
{
|
|
|
|
|
/* Require confirmation. */
|
|
|
|
|
|
|
|
|
|
char* command = text_easy_sprintf("unsubscribe %s %s", address, listname);
|
|
|
|
|
char* cookie = queue_command(MailStruct, command);
|
|
|
|
|
|
|
|
|
|
fh = vOpenMailer(envelope, address, NULL);
|
|
|
|
|
if (fh != NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf(fh, "From: petidomo-approve@%s (Petidomo Mailing List Server)\n", ListConfig->fqdn);
|
|
|
|
|
fprintf(fh, "To: %s\n", address);
|
|
|
|
|
fprintf(fh, "Subject: Petidomo: CONFIRM %s@%s: Request from \"%s\"\n", listname, ListConfig->fqdn, originator);
|
|
|
|
|
fprintf(fh, "Precedence: junk\n");
|
|
|
|
|
fprintf(fh, "Sender: %s\n", envelope);
|
|
|
|
|
fprintf(fh, "\n");
|
|
|
|
|
buffer = text_easy_sprintf("Per request from \"%s\", the address \"%s\" should be unsubscribed from " \
|
|
|
|
|
"the mailing list \"%s\". This will not happen unless you confirm the " \
|
|
|
|
|
"request by replying to this mail and citing the string",
|
|
|
|
|
originator, address, listname);
|
|
|
|
|
text_wordwrap(buffer, 70);
|
|
|
|
|
fprintf(fh, "%s\n", buffer);
|
|
|
|
|
fprintf(fh, "\n %s\n\n", cookie);
|
|
|
|
|
fprintf(fh, "in your reply.\n");
|
|
|
|
|
CloseMailer(fh);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
syslog(LOG_ERR, "Failed to send email to \"%s\"!", owner);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-16 12:09:12 +00:00
|
|
|
fh = vOpenMailer(envelope, originator, NULL);
|
|
|
|
|
if (fh != NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf(fh, "From: %s-request@%s (Petidomo Mailing List Server)\n", listname, ListConfig->fqdn);
|
|
|
|
|
fprintf(fh, "To: %s\n", originator);
|
|
|
|
|
fprintf(fh, "Subject: Petidomo: Your request \"unsubscribe %s %s\"\n", address, listname);
|
|
|
|
|
if (MailStruct->Message_Id != NULL)
|
|
|
|
|
fprintf(fh, "In-Reply-To: %s\n", MailStruct->Message_Id);
|
|
|
|
|
fprintf(fh, "Precedence: junk\n");
|
|
|
|
|
fprintf(fh, "Sender: %s\n", envelope);
|
|
|
|
|
fprintf(fh, "\n");
|
|
|
|
|
fprintf(fh, "Unsubscribing the address will need confirmation. Such a\n");
|
|
|
|
|
fprintf(fh, "request has been sent to the address already, so don't move!\n");
|
|
|
|
|
CloseMailer(fh);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
syslog(LOG_ERR, "Failed to send email to \"%s\" concerning his request.", originator);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-15 17:56:33 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-08 20:36:19 +00:00
|
|
|
fh = fopen(ListConfig->address_file, "w");
|
2001-01-11 14:10:57 +00:00
|
|
|
if (fh == NULL)
|
|
|
|
|
{
|
2001-01-08 20:36:19 +00:00
|
|
|
syslog(LOG_ERR, "Failed to open file \"%s\" for writing: %m", ListConfig->address_file);
|
2000-12-13 13:19:03 +00:00
|
|
|
return -1;
|
2001-01-11 14:10:57 +00:00
|
|
|
}
|
2000-12-13 13:19:03 +00:00
|
|
|
*p++ = '\0';
|
|
|
|
|
fprintf(fh, "%s", list);
|
|
|
|
|
p = text_find_next_line(p); /* skip address in question */
|
|
|
|
|
fprintf(fh, "%s", p);
|
|
|
|
|
fclose(fh);
|
|
|
|
|
|
|
|
|
|
/* Send success notification to the originator, and the
|
|
|
|
|
unsubscribed address. */
|
|
|
|
|
|
|
|
|
|
if (!strcasecmp(address, originator) == TRUE)
|
2001-01-11 14:10:57 +00:00
|
|
|
fh = vOpenMailer(envelope, address, owner, NULL);
|
2000-12-13 13:19:03 +00:00
|
|
|
else
|
2001-01-11 14:10:57 +00:00
|
|
|
fh = vOpenMailer(envelope, address, originator, owner, NULL);
|
|
|
|
|
if (fh != NULL)
|
|
|
|
|
{
|
2000-12-13 13:19:03 +00:00
|
|
|
fprintf(fh, "From: %s-request@%s (Petidomo Mailing List Server)\n",
|
2001-01-11 14:10:57 +00:00
|
|
|
listname, ListConfig->fqdn);
|
2000-12-13 13:19:03 +00:00
|
|
|
fprintf(fh, "To: %s\n", address);
|
|
|
|
|
if (!strcasecmp(address, originator) == TRUE)
|
2001-01-11 14:10:57 +00:00
|
|
|
fprintf(fh, "Cc: %s\n", owner);
|
2000-12-13 13:19:03 +00:00
|
|
|
else
|
2001-01-11 14:10:57 +00:00
|
|
|
fprintf(fh, "Cc: %s, %s\n", originator, owner);
|
2001-01-06 11:05:08 +00:00
|
|
|
fprintf(fh, "Subject: Petidomo: Request \"unsubscribe %s %s\"\n", address, listname);
|
2000-12-13 13:19:03 +00:00
|
|
|
if (MailStruct->Message_Id != NULL)
|
2001-01-11 14:10:57 +00:00
|
|
|
fprintf(fh, "In-Reply-To: %s\n", MailStruct->Message_Id);
|
2000-12-13 13:19:03 +00:00
|
|
|
fprintf(fh, "Precedence: junk\n");
|
|
|
|
|
fprintf(fh, "Sender: %s\n", envelope);
|
|
|
|
|
fprintf(fh, "\n");
|
2001-01-11 14:10:57 +00:00
|
|
|
if (!strcasecmp(address, originator) == TRUE)
|
|
|
|
|
{
|
2000-12-13 13:19:03 +00:00
|
|
|
buffer = text_easy_sprintf(
|
2001-01-11 14:10:57 +00:00
|
|
|
"Per your request, the address \"%s\" has been unsubscribed from the " \
|
|
|
|
|
"\"%s\" mailing list.\n\n", address, listname);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2000-12-13 13:19:03 +00:00
|
|
|
buffer = text_easy_sprintf(
|
2001-01-11 14:10:57 +00:00
|
|
|
"Per request from \"%s\", the address \"%s\" has been unsubscribed from the " \
|
|
|
|
|
"\"%s\" mailing list.\n\n", originator, address, listname);
|
|
|
|
|
}
|
2001-01-10 17:12:40 +00:00
|
|
|
text_wordwrap(buffer, 70);
|
2000-12-13 13:19:03 +00:00
|
|
|
fprintf(fh, "%s", buffer);
|
|
|
|
|
CloseMailer(fh);
|
2001-01-11 14:10:57 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2000-12-13 13:19:03 +00:00
|
|
|
syslog(LOG_ERR, "Failed to send email to \"%s\"!", owner);
|
|
|
|
|
return -1;
|
2001-01-11 14:10:57 +00:00
|
|
|
}
|
2000-12-13 13:19:03 +00:00
|
|
|
}
|
|
|
|
|
free(list);
|
|
|
|
|
return 0;
|
2001-01-11 14:10:57 +00:00
|
|
|
}
|