The requestor will now receive a mail telling him something went wrong

when he tries to unsubscribe an address without specifying a list
name.
This commit is contained in:
Peter Simons 2001-01-11 14:10:57 +00:00
parent 99aaaee119
commit 1ee5bff1c4

View File

@ -26,7 +26,8 @@ DeleteAddress(struct Mail * MailStruct,
const char * param1, const char * param1,
const char * param2, const char * param2,
const char * defaultlist) const char * defaultlist)
{ {
const struct PD_Config * MasterConfig;
const struct List_Config * ListConfig; const struct List_Config * ListConfig;
FILE * fh; FILE * fh;
const char * address = NULL; const char * address = NULL;
@ -38,82 +39,119 @@ DeleteAddress(struct Mail * MailStruct,
char * p; char * p;
char * list; char * list;
/* 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;
/* Try to find out, which parameter is what. */ /* Try to find out, which parameter is what. */
if (param1 != NULL) { if (param1 != NULL)
{
if (isValidListName(param1) == TRUE) if (isValidListName(param1) == TRUE)
listname = param1; listname = param1;
else if (isRFC822Address(param1) == TRUE) else if (isRFC822Address(param1) == TRUE)
address = param1; address = param1;
if (param2 != NULL) { if (param2 != NULL)
if (isValidListName(param2) == TRUE) {
listname = param2; if (listname == NULL && isValidListName(param2) == TRUE)
else if (isRFC822Address(param2) == TRUE) listname = param2;
address = param2; else if (address == NULL && isRFC822Address(param2) == TRUE)
address = param2;
}
} }
}
if (address == NULL) if (address == NULL)
address = (MailStruct->Reply_To) ? MailStruct->Reply_To : MailStruct->From; address = (MailStruct->Reply_To) ? MailStruct->Reply_To : MailStruct->From;
if (listname == NULL && defaultlist != NULL) assert(address != NULL);
listname = defaultlist;
if (address == NULL || listname == NULL) { if (listname == NULL)
syslog(LOG_NOTICE, "%s: unsubscribe-command invalid: No list specified.", {
MailStruct->From); if (defaultlist != NULL)
return 0; 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;
}
}
/* Initialize internal stuff. */ /* Initialize internal stuff again from list config. */
ListConfig = getListConfig(listname); ListConfig = getListConfig(listname);
sprintf(owner, "%s-owner@%s", listname, ListConfig->fqdn); sprintf(owner, "%s-owner@%s", listname, ListConfig->fqdn);
sprintf(envelope, "%s-owner@%s", listname, ListConfig->fqdn); sprintf(envelope, "%s-owner@%s", listname, ListConfig->fqdn);
originator = (MailStruct->Reply_To) ? MailStruct->Reply_To : MailStruct->From;
/* Check whether the request is authorized at all. */ /* Check whether the request is authorized at all. */
if (isValidAdminPassword(getPassword(), listname) == FALSE) { if (isValidAdminPassword(getPassword(), listname) == FALSE)
{
/* No valid password, check further. */ /* No valid password, check further. */
if (ListConfig->allowpubsub == FALSE) { if (ListConfig->allowpubsub == FALSE)
{
/* Access was unauthorized, notify the originator. */ /* Access was unauthorized, notify the originator. */
syslog(LOG_INFO, "\"%s\" tried to unsubscribe \"%s\" from list \"%s\", but " \ syslog(LOG_INFO, "\"%s\" tried to unsubscribe \"%s\" from list \"%s\", but " \
"couldn't provide the correct password.", originator, address, listname); "couldn't provide the correct password.", originator, address, listname);
fh = vOpenMailer(envelope, originator, NULL); fh = vOpenMailer(envelope, originator, NULL);
if (fh != NULL) { if (fh != NULL)
{
fprintf(fh, "From: %s-request@%s (Petidomo Mailing List Server)\n", fprintf(fh, "From: %s-request@%s (Petidomo Mailing List Server)\n",
listname, ListConfig->fqdn); listname, ListConfig->fqdn);
fprintf(fh, "To: %s\n", originator); fprintf(fh, "To: %s\n", originator);
fprintf(fh, "Subject: Petidomo: Your request \"unsubscribe %s %s\"\n", fprintf(fh, "Subject: Petidomo: Your request \"unsubscribe %s %s\"\n",
address, listname); address, listname);
if (MailStruct->Message_Id != NULL) if (MailStruct->Message_Id != NULL)
fprintf(fh, "In-Reply-To: %s\n", MailStruct->Message_Id); fprintf(fh, "In-Reply-To: %s\n", MailStruct->Message_Id);
fprintf(fh, "Precedence: junk\n"); fprintf(fh, "Precedence: junk\n");
fprintf(fh, "Sender: %s\n", envelope); fprintf(fh, "Sender: %s\n", envelope);
fprintf(fh, "\n"); fprintf(fh, "\n");
buffer = text_easy_sprintf( buffer = text_easy_sprintf(
"The mailing list \"%s\" is a closed forum and only the maintainer may " \ "The mailing list \"%s\" is a closed forum and only the maintainer may " \
"unsubscribe addresses. Your request has been forwarded to the " \ "unsubscribe addresses. Your request has been forwarded to the " \
"appropriate person, so please don't send any further mail. You will " \ "appropriate person, so please don't send any further mail. You will " \
"be notified as soon as possible.", listname); "be notified as soon as possible.", listname);
text_wordwrap(buffer, 70); text_wordwrap(buffer, 70);
fprintf(fh, "%s\n", buffer); fprintf(fh, "%s\n", buffer);
CloseMailer(fh); CloseMailer(fh);
} }
else else
syslog(LOG_ERR, "Failed to send email to \"%s\" concerning his request.", syslog(LOG_ERR, "Failed to send email to \"%s\" concerning his request.",
originator); originator);
/* Notify the owner. */ /* Notify the owner. */
fh = vOpenMailer(envelope, owner, NULL); fh = vOpenMailer(envelope, owner, NULL);
if (fh != NULL) { if (fh != NULL)
{
fprintf(fh, "From: %s-request@%s (Petidomo Mailing List Server)\n", fprintf(fh, "From: %s-request@%s (Petidomo Mailing List Server)\n",
listname, ListConfig->fqdn); listname, ListConfig->fqdn);
fprintf(fh, "To: %s\n", owner); fprintf(fh, "To: %s\n", owner);
@ -122,59 +160,63 @@ DeleteAddress(struct Mail * MailStruct,
fprintf(fh, "Sender: %s\n", envelope); fprintf(fh, "Sender: %s\n", envelope);
fprintf(fh, "\n"); fprintf(fh, "\n");
buffer = text_easy_sprintf( buffer = text_easy_sprintf(
"\"%s\" tried to unsubscribe the address \"%s\" from the \"%s\" mailing list, " \ "\"%s\" tried to unsubscribe the address \"%s\" from the \"%s\" mailing list, " \
"but couldn't provide the correct password. To unsubscribe him, send the " \ "but couldn't provide the correct password. To unsubscribe him, send the " \
"following commands to the server:", originator, address, listname); "following commands to the server:", originator, address, listname);
text_wordwrap(buffer, 70); text_wordwrap(buffer, 70);
fprintf(fh, "%s\n\n", buffer); fprintf(fh, "%s\n\n", buffer);
fprintf(fh, "password <AdminPassword>\n"); fprintf(fh, "password <AdminPassword>\n");
fprintf(fh, "unsubscribe %s %s\n", address, listname); fprintf(fh, "unsubscribe %s %s\n", address, listname);
CloseMailer(fh); CloseMailer(fh);
} }
else { else
{
syslog(LOG_ERR, "Failed to send email to \"%s\"!", owner); syslog(LOG_ERR, "Failed to send email to \"%s\"!", owner);
return -1; return -1;
} }
return 0; return 0;
} }
if (ListConfig->allowaliensub == FALSE && if (ListConfig->allowaliensub == FALSE &&
(MailStruct->From == NULL || !strcasecmp(address, MailStruct->From) == FALSE) && (MailStruct->From == NULL || !strcasecmp(address, MailStruct->From) == FALSE) &&
(MailStruct->Reply_To == NULL || !strcasecmp(address, MailStruct->Reply_To) == FALSE)) { (MailStruct->Reply_To == NULL || !strcasecmp(address, MailStruct->Reply_To) == FALSE))
{
/* Trying to unsubscribe something different than himself. */ /* Trying to unsubscribe something different than himself. */
syslog(LOG_INFO, "\"%s\" tried to unsubscribe \"%s\" from list \"%s\", but the " \ syslog(LOG_INFO, "\"%s\" tried to unsubscribe \"%s\" from list \"%s\", but the " \
"list type doesn't allow this.", originator, address, listname); "list type doesn't allow this.", originator, address, listname);
fh = vOpenMailer(envelope, originator, NULL); fh = vOpenMailer(envelope, originator, NULL);
if (fh != NULL) { if (fh != NULL)
{
fprintf(fh, "From: %s-request@%s (Petidomo Mailing List Server)\n", fprintf(fh, "From: %s-request@%s (Petidomo Mailing List Server)\n",
listname, ListConfig->fqdn); listname, ListConfig->fqdn);
fprintf(fh, "To: %s\n", originator); fprintf(fh, "To: %s\n", originator);
fprintf(fh, "Subject: Petidomo: Your request \"unsubscribe %s %s\"\n", fprintf(fh, "Subject: Petidomo: Your request \"unsubscribe %s %s\"\n",
address, listname); address, listname);
if (MailStruct->Message_Id != NULL) if (MailStruct->Message_Id != NULL)
fprintf(fh, "In-Reply-To: %s\n", MailStruct->Message_Id); fprintf(fh, "In-Reply-To: %s\n", MailStruct->Message_Id);
fprintf(fh, "Precedence: junk\n"); fprintf(fh, "Precedence: junk\n");
fprintf(fh, "Sender: %s\n", envelope); fprintf(fh, "Sender: %s\n", envelope);
fprintf(fh, "\n"); fprintf(fh, "\n");
buffer = text_easy_sprintf( buffer = text_easy_sprintf(
"The mailing list \"%s\" does not allow to automatically subscribe or unsubscribe an " \ "The mailing list \"%s\" does not allow to automatically subscribe or unsubscribe an " \
"address not equal to the one, you are mailing from. Your request has been forwarded " \ "address not equal to the one, you are mailing from. Your request has been forwarded " \
"to the list administrator, so please don't send any futher mail. You will be notified " \ "to the list administrator, so please don't send any futher mail. You will be notified " \
"as soon as possible.", listname); "as soon as possible.", listname);
text_wordwrap(buffer, 70); text_wordwrap(buffer, 70);
fprintf(fh, "%s\n", buffer); fprintf(fh, "%s\n", buffer);
CloseMailer(fh); CloseMailer(fh);
} }
else else
syslog(LOG_ERR, "Failed to send email to \"%s\" concerning his request.", syslog(LOG_ERR, "Failed to send email to \"%s\" concerning his request.",
originator); originator);
/* Notify the owner. */ /* Notify the owner. */
fh = vOpenMailer(envelope, owner, NULL); fh = vOpenMailer(envelope, owner, NULL);
if (fh != NULL) { if (fh != NULL)
{
fprintf(fh, "From: %s-request@%s (Petidomo Mailing List Server)\n", fprintf(fh, "From: %s-request@%s (Petidomo Mailing List Server)\n",
listname, ListConfig->fqdn); listname, ListConfig->fqdn);
fprintf(fh, "To: %s\n", owner); fprintf(fh, "To: %s\n", owner);
@ -183,58 +225,63 @@ DeleteAddress(struct Mail * MailStruct,
fprintf(fh, "Sender: %s\n", envelope); fprintf(fh, "Sender: %s\n", envelope);
fprintf(fh, "\n"); fprintf(fh, "\n");
buffer = text_easy_sprintf( buffer = text_easy_sprintf(
"\"%s\" tried to unsubscribe the address \"%s\" from the \"%s\" mailing list. " \ "\"%s\" tried to unsubscribe the address \"%s\" from the \"%s\" mailing list. " \
"The list type does not allow unsubscribing addresses not equal to the From: " \ "The list type does not allow unsubscribing addresses not equal to the From: " \
"address, though, so the request has been denied. To unsubscribe this person " \ "address, though, so the request has been denied. To unsubscribe this person " \
"manually, send the following commands to the server:", originator, address, listname); "manually, send the following commands to the server:", originator, address, listname);
text_wordwrap(buffer, 70); text_wordwrap(buffer, 70);
fprintf(fh, "%s\n\n", buffer); fprintf(fh, "%s\n\n", buffer);
fprintf(fh, "password <AdminPassword>\n"); fprintf(fh, "password <AdminPassword>\n");
fprintf(fh, "unsubscribe %s %s\n", address, listname); fprintf(fh, "unsubscribe %s %s\n", address, listname);
CloseMailer(fh); CloseMailer(fh);
} }
else { else
{
syslog(LOG_ERR, "Failed to send email to \"%s\"!", owner); syslog(LOG_ERR, "Failed to send email to \"%s\"!", owner);
return -1; return -1;
} }
return 0; return 0;
}
} }
}
/* Okay, remove the address from the list. */ /* Okay, remove the address from the list. */
if (isSubscribed(listname, address, &list, &p, FALSE) == FALSE) { if (isSubscribed(listname, address, &list, &p, FALSE) == FALSE)
{
/* Notify the originator, that the address is not subscribed at /* Notify the originator, that the address is not subscribed at
all. */ all. */
fh = vOpenMailer(envelope, originator, NULL); fh = vOpenMailer(envelope, originator, NULL);
if (fh != NULL) { if (fh != NULL)
{
fprintf(fh, "From: %s-request@%s (Petidomo Mailing List Server)\n", fprintf(fh, "From: %s-request@%s (Petidomo Mailing List Server)\n",
listname, ListConfig->fqdn); listname, ListConfig->fqdn);
fprintf(fh, "To: %s\n", originator); fprintf(fh, "To: %s\n", originator);
fprintf(fh, "Subject: Petidomo: Your request \"unsubscribe %s %s\"\n", fprintf(fh, "Subject: Petidomo: Your request \"unsubscribe %s %s\"\n",
address, listname); address, listname);
if (MailStruct->Message_Id != NULL) if (MailStruct->Message_Id != NULL)
fprintf(fh, "In-Reply-To: %s\n", MailStruct->Message_Id); fprintf(fh, "In-Reply-To: %s\n", MailStruct->Message_Id);
fprintf(fh, "Precedence: junk\n"); fprintf(fh, "Precedence: junk\n");
fprintf(fh, "Sender: %s\n", envelope); fprintf(fh, "Sender: %s\n", envelope);
fprintf(fh, "\n"); fprintf(fh, "\n");
fprintf(fh, "The address is not subscribed to this list.\n"); fprintf(fh, "The address is not subscribed to this list.\n");
CloseMailer(fh); CloseMailer(fh);
} }
else { else
{
syslog(LOG_ERR, "Failed to send email to \"%s\" concerning his request.", syslog(LOG_ERR, "Failed to send email to \"%s\" concerning his request.",
originator); originator);
return -1; return -1;
} }
} }
else { else
{
fh = fopen(ListConfig->address_file, "w"); fh = fopen(ListConfig->address_file, "w");
if (fh == NULL) { if (fh == NULL)
{
syslog(LOG_ERR, "Failed to open file \"%s\" for writing: %m", ListConfig->address_file); syslog(LOG_ERR, "Failed to open file \"%s\" for writing: %m", ListConfig->address_file);
return -1; return -1;
} }
*p++ = '\0'; *p++ = '\0';
fprintf(fh, "%s", list); fprintf(fh, "%s", list);
p = text_find_next_line(p); /* skip address in question */ p = text_find_next_line(p); /* skip address in question */
@ -245,42 +292,46 @@ DeleteAddress(struct Mail * MailStruct,
unsubscribed address. */ unsubscribed address. */
if (!strcasecmp(address, originator) == TRUE) if (!strcasecmp(address, originator) == TRUE)
fh = vOpenMailer(envelope, address, owner, NULL); fh = vOpenMailer(envelope, address, owner, NULL);
else else
fh = vOpenMailer(envelope, address, originator, owner, NULL); fh = vOpenMailer(envelope, address, originator, owner, NULL);
if (fh != NULL) { if (fh != NULL)
{
fprintf(fh, "From: %s-request@%s (Petidomo Mailing List Server)\n", fprintf(fh, "From: %s-request@%s (Petidomo Mailing List Server)\n",
listname, ListConfig->fqdn); listname, ListConfig->fqdn);
fprintf(fh, "To: %s\n", address); fprintf(fh, "To: %s\n", address);
if (!strcasecmp(address, originator) == TRUE) if (!strcasecmp(address, originator) == TRUE)
fprintf(fh, "Cc: %s\n", owner); fprintf(fh, "Cc: %s\n", owner);
else else
fprintf(fh, "Cc: %s, %s\n", originator, owner); fprintf(fh, "Cc: %s, %s\n", originator, owner);
fprintf(fh, "Subject: Petidomo: Request \"unsubscribe %s %s\"\n", address, listname); fprintf(fh, "Subject: Petidomo: Request \"unsubscribe %s %s\"\n", address, listname);
if (MailStruct->Message_Id != NULL) if (MailStruct->Message_Id != NULL)
fprintf(fh, "In-Reply-To: %s\n", MailStruct->Message_Id); fprintf(fh, "In-Reply-To: %s\n", MailStruct->Message_Id);
fprintf(fh, "Precedence: junk\n"); fprintf(fh, "Precedence: junk\n");
fprintf(fh, "Sender: %s\n", envelope); fprintf(fh, "Sender: %s\n", envelope);
fprintf(fh, "\n"); fprintf(fh, "\n");
if (!strcasecmp(address, originator) == TRUE) { if (!strcasecmp(address, originator) == TRUE)
{
buffer = text_easy_sprintf( buffer = text_easy_sprintf(
"Per your request, the address \"%s\" has been unsubscribed from the " \ "Per your request, the address \"%s\" has been unsubscribed from the " \
"\"%s\" mailing list.\n\n", address, listname); "\"%s\" mailing list.\n\n", address, listname);
} }
else { else
{
buffer = text_easy_sprintf( buffer = text_easy_sprintf(
"Per request from \"%s\", the address \"%s\" has been unsubscribed from the " \ "Per request from \"%s\", the address \"%s\" has been unsubscribed from the " \
"\"%s\" mailing list.\n\n", originator, address, listname); "\"%s\" mailing list.\n\n", originator, address, listname);
} }
text_wordwrap(buffer, 70); text_wordwrap(buffer, 70);
fprintf(fh, "%s", buffer); fprintf(fh, "%s", buffer);
CloseMailer(fh); CloseMailer(fh);
} }
else { else
{
syslog(LOG_ERR, "Failed to send email to \"%s\"!", owner); syslog(LOG_ERR, "Failed to send email to \"%s\"!", owner);
return -1; return -1;
}
} }
}
free(list); free(list);
return 0; return 0;
} }