--- hermes.c 2001/01/15 17:06:48 1.7
+++ hermes.c 2001/01/15 17:23:25 1.8
@@ -1,6 +1,6 @@
/*
$Source: /v/ossp/cvs/ossp-pkg/petidomo/hermes.c,v $
- $Revision: 1.7 $
+ $Revision: 1.8 $
Copyright (C) 2000 by CyberSolutions GmbH, Germany.
@@ -26,7 +26,7 @@
int
hermes_main(char * incoming_mail, const char * listname)
-{
+ {
const struct PD_Config * MasterConfig;
const struct List_Config * ListConfig;
struct stat sb;
@@ -51,32 +51,37 @@
/* Parse the incoming mail. */
rc = ParseMail(&MailStruct, incoming_mail, ListConfig->fqdn);
- if (rc != 0) {
+ if (rc != 0)
+ {
syslog(LOG_ERR, "Parsing the incoming mail failed.");
exit(rc);
- }
+ }
/* Do sanity checks. */
- if (MailStruct->Envelope == NULL) {
+ if (MailStruct->Envelope == NULL)
+ {
syslog(LOG_NOTICE, "Received mail without a valid envelope.");
return 0;
- }
- if (MailStruct->From == NULL) {
+ }
+ if (MailStruct->From == NULL)
+ {
syslog(LOG_NOTICE, "Received mail without From: line.");
return 0;
- }
- if (*MailStruct->Body == '\0') {
+ }
+ if (*MailStruct->Body == '\0')
+ {
syslog(LOG_NOTICE, "Received mail with empty body.");
return 0;
- }
+ }
/* Initialize internal stuff. */
- if (isValidListName(listname) == FALSE) {
+ if (isValidListName(listname) == FALSE)
+ {
syslog(LOG_ERR, "Mailing list \"%s\" does not exist.", listname);
exit(1);
- }
+ }
PostingHeaders = xmalloc(strlen(MailStruct->Header)+1024);
MasterConfig = getMasterConfig();
sprintf(envelope, "%s-owner@%s", listname, ListConfig->fqdn);
@@ -85,19 +90,21 @@
/* Check for authorization. */
if (FindBodyPassword(MailStruct) != 0)
- exit(1);
-
- if (isValidPostingPassword(MailStruct->Approve, listname) == FALSE) {
+ exit(1);
+ if (isValidPostingPassword(MailStruct->Approve, listname) == FALSE)
+ {
/* No valid password found. Reject the article, if the list is
of type 'moderated'. */
- if (ListConfig->listtype == LIST_MODERATED) {
+ if (ListConfig->listtype == LIST_MODERATED)
+ {
syslog(LOG_NOTICE, "\"%s\" tried to post to list \"%s\", but failed to " \
- "provide a correct password.", MailStruct->From, listname);
+ "provide a correct password.", MailStruct->From, listname);
fh = vOpenMailer(envelope, owner, NULL);
- if (fh != NULL) {
+ if (fh != NULL)
+ {
fprintf(fh, "From: %s (Petidomo Mailing List Server)\n", owner);
fprintf(fh, "To: %s\n", owner);
fprintf(fh, "Subject: Petidomo: BOUNCE %s@%s: Moderator approval required\n", listname, ListConfig->fqdn);
@@ -108,20 +115,23 @@
fprintf(fh, "%s\n", MailStruct->Header);
fprintf(fh, "%s", MailStruct->Body);
CloseMailer(fh);
- }
- else {
- syslog(LOG_ERR, "Failed to send email to \"%s\" concerning this request.",
- owner);
+ }
+ else
+ {
+ syslog(LOG_ERR, "Failed to send email to \"%s\" concerning this request.", owner);
return -1;
- }
+ }
return 0;
- }
+ }
- if (ListConfig->listtype == LIST_CLOSED) {
+ if (ListConfig->listtype == LIST_CLOSED)
+ {
/* Only subscribers may post */
- if (isSubscribed(listname, MailStruct->From, NULL, NULL, TRUE) == FALSE) {
+ if (isSubscribed(listname, MailStruct->From, NULL, NULL, TRUE) == FALSE)
+ {
fh = vOpenMailer(envelope, owner, NULL);
- if (fh != NULL) {
+ if (fh != NULL)
+ {
fprintf(fh, "From: %s (Petidomo Mailing List Server)\n", owner);
fprintf(fh, "To: %s\n", owner);
fprintf(fh, "Subject: Petidomo: BOUNCE %s@%s: Non-member submission from \"%s\"\n", listname, ListConfig->fqdn, MailStruct->From);
@@ -133,44 +143,46 @@
fprintf(fh, "%s\n", MailStruct->Header);
fprintf(fh, "%s", MailStruct->Body);
CloseMailer(fh);
- }
- else {
- syslog(LOG_ERR, "Failed to send email to \"%s\" concerning this request.",
- owner);
+ }
+ else
+ {
+ syslog(LOG_ERR, "Failed to send email to \"%s\" concerning this request.", owner);
return -1;
- }
+ }
return 0;
+ }
}
- }
- if (checkACL(MailStruct, listname, &operation, ¶meter) != 0) {
+ if (checkACL(MailStruct, listname, &operation, ¶meter) != 0)
+ {
syslog(LOG_ERR, "checkACL() failed with an error.");
exit(1);
- }
+ }
rc = handleACL(MailStruct, listname, operation, parameter);
- switch(rc) {
- case -1:
- syslog(LOG_ERR, "handleACL() failed with an error.");
- exit(1);
- case 0:
- break;
- case 1:
- return 0;
+ switch(rc)
+ {
+ case -1:
+ syslog(LOG_ERR, "handleACL() failed with an error.");
+ exit(1);
+ case 0:
+ break;
+ case 1:
+ return 0;
+ }
}
- }
/* Copy the desired headers from the original mail to our own
buffer. */
for(len = 0, currLine = MailStruct->Header, dst = PostingHeaders;
*currLine != '\0';
- currLine = nextLine) {
-
+ currLine = nextLine)
+ {
/* Find next header line. */
nextLine = text_find_next_line(currLine);
while (*nextLine == '\t' || *nextLine == ' ')
- nextLine = text_find_next_line(nextLine);
+ nextLine = text_find_next_line(nextLine);
/* Copy the current line into our own buffer. */
@@ -185,43 +197,48 @@
!strncasecmp(currLine, "In-Reply-To:", 12) ||
!strncasecmp(currLine, "References:", 11) ||
!strncasecmp(currLine, "Message-Id:", 11) ||
- !strncasecmp(currLine, "Received:", 9)) {
+ !strncasecmp(currLine, "Received:", 9))
+ {
len = nextLine - currLine;
memmove(dst, currLine, len);
dst += len;
+ }
}
- }
/* Add a Reply-To: field. */
if (ListConfig->reply_to == NULL)
- len = sprintf(dst, "Reply-To: %s@%s\n", listname, ListConfig->fqdn);
- else if (!strcasecmp(ListConfig->reply_to, "none")) {
- if (MailStruct->Reply_To != NULL) {
-
+ len = sprintf(dst, "Reply-To: %s@%s\n", listname, ListConfig->fqdn);
+ else if (!strcasecmp(ListConfig->reply_to, "none"))
+ {
+ if (MailStruct->Reply_To != NULL)
+ {
/* Copy Reply-To: line from original header. */
for(len = 0, currLine = MailStruct->Header;
*currLine != '\0';
- currLine = nextLine) {
+ currLine = nextLine)
+ {
nextLine = text_find_next_line(currLine);
while (*nextLine == '\t' || *nextLine == ' ')
- nextLine = text_find_next_line(nextLine);
+ nextLine = text_find_next_line(nextLine);
- if (!strncasecmp(currLine, "Reply-To:", 9)) {
+ if (!strncasecmp(currLine, "Reply-To:", 9))
+ {
len = nextLine - currLine;
memmove(dst, currLine, len);
+ }
}
- }
- }
+ }
else
- len = 0;
- }
- else {
+ len = 0;
+ }
+ else
+ {
len = sprintf(dst, "Reply-To: %s\n", ListConfig->reply_to);
- }
+ }
dst += len;
/* Add a Sender: field. */
@@ -252,14 +269,16 @@
/* Add the signature if there is one. */
- if (stat(ListConfig->sig_file, &sb) == 0) {
+ if (stat(ListConfig->sig_file, &sb) == 0)
+ {
buffer = loadfile(ListConfig->sig_file);
- if (buffer == NULL) {
+ if (buffer == NULL)
+ {
syslog(LOG_ERR, "Failed reading the signature file for list \"%s\".", listname);
exit(1);
- }
+ }
MailStruct->ListSignature = buffer;
- }
+ }
/* No more modifications will be made. Now copy the posting
headers into the structure instead of the original ones. */
@@ -268,29 +287,32 @@
/* Apply the posting filter. */
- if (ListConfig->postingfilter != NULL) {
+ if (ListConfig->postingfilter != NULL)
+ {
rc = MailFilter(MailStruct, ListConfig->postingfilter);
- if (rc != 0) {
+ if (rc != 0)
+ {
syslog(LOG_ERR, "Postingfilter \"%s\" returned error %d while processing posting " \
- "for list \"%s\".", ListConfig->postingfilter, rc, listname);
+ "for list \"%s\".", ListConfig->postingfilter, rc, listname);
exit(1);
+ }
}
- }
/* Deliver the article to all recipients. */
rc = ListMail(envelope, listname, MailStruct);
- if (rc != 0) {
+ if (rc != 0)
+ {
syslog(LOG_ERR, "The attempt to deliver the article to the subscribers failed.");
exit(1);
- }
+ }
syslog(LOG_INFO, "Posted article from \"%s\" to list \"%s\" successfully.",
- MailStruct->From, listname);
+ MailStruct->From, listname);
/* Archive the article. */
ArchiveMail(MailStruct, listname);
return 0;
-}
+ }
|