Cosmetic change: Reformatted the source.
This commit is contained in:
parent
56addb6b2f
commit
afe1f3f231
94
hermes.c
94
hermes.c
@ -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,29 +51,34 @@ hermes_main(char * incoming_mail, const char * listname)
|
||||
/* 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);
|
||||
}
|
||||
@ -87,17 +92,19 @@ hermes_main(char * incoming_mail, const char * listname)
|
||||
if (FindBodyPassword(MailStruct) != 0)
|
||||
exit(1);
|
||||
|
||||
if (isValidPostingPassword(MailStruct->Approve, listname) == FALSE) {
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
@ -109,19 +116,22 @@ hermes_main(char * incoming_mail, const char * listname)
|
||||
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);
|
||||
@ -134,21 +144,23 @@ hermes_main(char * incoming_mail, const char * listname)
|
||||
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) {
|
||||
switch(rc)
|
||||
{
|
||||
case -1:
|
||||
syslog(LOG_ERR, "handleACL() failed with an error.");
|
||||
exit(1);
|
||||
@ -164,8 +176,8 @@ hermes_main(char * incoming_mail, const char * listname)
|
||||
|
||||
for(len = 0, currLine = MailStruct->Header, dst = PostingHeaders;
|
||||
*currLine != '\0';
|
||||
currLine = nextLine) {
|
||||
|
||||
currLine = nextLine)
|
||||
{
|
||||
/* Find next header line. */
|
||||
|
||||
nextLine = text_find_next_line(currLine);
|
||||
@ -185,7 +197,8 @@ hermes_main(char * incoming_mail, const char * listname)
|
||||
!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;
|
||||
@ -196,20 +209,23 @@ hermes_main(char * incoming_mail, const char * listname)
|
||||
|
||||
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) {
|
||||
|
||||
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);
|
||||
|
||||
if (!strncasecmp(currLine, "Reply-To:", 9)) {
|
||||
if (!strncasecmp(currLine, "Reply-To:", 9))
|
||||
{
|
||||
len = nextLine - currLine;
|
||||
memmove(dst, currLine, len);
|
||||
}
|
||||
@ -219,7 +235,8 @@ hermes_main(char * incoming_mail, const char * listname)
|
||||
else
|
||||
len = 0;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
len = sprintf(dst, "Reply-To: %s\n", ListConfig->reply_to);
|
||||
}
|
||||
dst += len;
|
||||
@ -252,9 +269,11 @@ hermes_main(char * incoming_mail, const char * listname)
|
||||
|
||||
/* 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);
|
||||
}
|
||||
@ -268,9 +287,11 @@ hermes_main(char * incoming_mail, const char * listname)
|
||||
|
||||
/* 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);
|
||||
exit(1);
|
||||
@ -280,7 +301,8 @@ hermes_main(char * incoming_mail, const char * listname)
|
||||
/* 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);
|
||||
}
|
||||
@ -293,4 +315,4 @@ hermes_main(char * incoming_mail, const char * listname)
|
||||
ArchiveMail(MailStruct, listname);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user