head 1.6; access; symbols PETIDOMO_4_0b6:1.6 PETIDOMO_4_0b5:1.6 PETIDOMO_4_0b4:1.6 PETIDOMO_4_0b3:1.6 BEFORETHL:1.6; locks; strict; comment @ * @; 1.6 date 2001.01.20.14.57.04; author simons; state Exp; branches; next 1.5; 1.5 date 2001.01.20.14.30.50; author simons; state Exp; branches; next 1.4; 1.4 date 2001.01.19.14.56.33; author rse; state Exp; branches; next 1.3; 1.3 date 2001.01.18.20.30.50; author rse; state Exp; branches; next 1.2; 1.2 date 2001.01.16.10.47.15; author simons; state Exp; branches; next 1.1; 1.1 date 2001.01.15.18.48.49; author simons; state Exp; branches; next ; desc @@ 1.6 log @- Petidomo is now more responsive when dealing with approve mails. For sure, Ralf is going to change the mail texts as soon as he sees this. :-) - Converting incoming codes to all upper-case in case the code got mixed up by some crazy mailer. @ text @/* $Source: /e/ossp/cvs/ossp-pkg/petidomo/approve.c,v $ $Revision: 1.5 $ Copyright (C) 2000 by Peter Simons . This file is part of Petidomo. Petidomo 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. Petidomo 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 #include #include #include #include #include #include #include "petidomo.h" #include "libtext/text.h" void approve_main(char* mail) { const struct PD_Config* MasterConfig = getMasterConfig(); struct Mail* MailStruct; char* originator; char* envelope; FILE* fh; static const char* cookie_regex = "[0-9a-f]{32}"; regex_t preg; regmatch_t match[3]; int offset; int number_of_hits = 0; if (chdir(MasterConfig->ack_queue_dir) == -1) { syslog(LOG_ERR, "Can't change directory to \"%s\": %s", MasterConfig->ack_queue_dir, strerror(errno)); exit(1); } if (regcomp(&preg, cookie_regex, REG_EXTENDED | REG_ICASE) != 0) { syslog(LOG_CRIT, "Can't compile my internal regular expressions. This is serious!"); exit(1); } offset = 0; while(regexec(&preg, mail + offset, sizeof(match)/sizeof(regmatch_t), match, 0) == 0) { struct stat sb; char buffer[33]; char* src; char* dst = buffer; unsigned int i; /* Copy found string into buffer and convert it to all upper-case while doing so. */ src = mail + offset + match[0].rm_so; for (i = 0; i < 32; ++i) *dst++ = toupper(*src++); *dst = '\0'; /* Correct offset for the next match. */ offset += match[0].rm_so + 1; /* Do we have a hit here? If, execute the file and remove it. Then go on. */ if (stat(buffer, &sb) == 0) { char cmd[128]; syslog(LOG_INFO, "Received valid approval code for spool file \"%s\".", buffer); ++number_of_hits; sprintf(cmd, "/bin/sh %s && /bin/rm -f %s", buffer, buffer); if (((signed char)system(cmd)) == -1) { syslog(LOG_ERR, "system() failed for \"%s\": %s", buffer, strerror(errno)); exit(1); } } else syslog(LOG_INFO, "Received approval code \"%s\", but there is no corresponding posting.", buffer); } /* Report results back to the originator */ if (ParseMail(&MailStruct, mail, MasterConfig->fqdn) != 0) { syslog(LOG_ERR, "Parsing the incoming mail failed."); exit(-1); } if (MailStruct->From == NULL) { syslog(LOG_NOTICE, "Received mail without From: line."); return; } originator = (MailStruct->Reply_To) ? MailStruct->Reply_To : MailStruct->From; envelope = text_easy_sprintf("petidomo-manager@@%s", MasterConfig->fqdn); 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 approval mail has been received\n"); 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"); if (number_of_hits > 0) fprintf(fh, "Your approval mail has been received and been processed sucessfully."); else fprintf(fh, "I couldn't find any approval codes in your mail."); CloseMailer(fh); } else { syslog(LOG_ERR, "Failed to send email to \"%s\" concerning his request.", originator); exit(-1); } } @ 1.5 log @- Changed prototype of approve_main() to return "void". - Added code that will parse the incoming mail after we've processed it in order to retrieve the originator's address for a reply. @ text @d3 1 a3 1 $Revision: 1.4 $ d26 1 d29 1 d36 2 d42 1 a42 2 int number_of_hits = 0; int number_of_successful_hits = 0; d65 2 a66 3 ++number_of_hits; /* Copy found string into buffer. */ d70 1 a70 1 *dst++ = *src++; d84 2 a85 1 ++number_of_successful_hits; d93 2 d112 1 d114 22 @ 1.4 log @Get rid of all complaints from GCC 2.97 (except for two things which I do not want to change on my own) @ text @d3 1 a3 1 $Revision: 1.3 $ d29 1 a29 1 int approve_main(char* mail) d32 2 d38 2 d62 2 d82 1 d90 9 d100 4 d106 2 a107 1 return 0; @ 1.3 log @As we agreed today, Petidomo is now open because licensed under GPL and always will be licensed under GPL, so use "Petidomo" as the program name everywhere and consistently. @ text @d3 1 a3 1 $Revision: 1.2 $ a19 1 #include "petidomo.h" d24 4 d39 1 a39 1 syslog(LOG_ERR, "Can't change directory to \"%s\": %m", MasterConfig->ack_queue_dir); d79 1 a79 1 syslog(LOG_ERR, "system() failed: %m", MasterConfig->ack_queue_dir); @ 1.2 log @Added include of sys/types.h. Required on some systems to be able to include regex.h. @ text @d2 2 a3 2 $Source: /d1/e/petidomo/cvs/petidomo/source/approve.c,v $ $Revision: 1.1 $ d7 1 a7 1 This file is part of OpenPetidomo. d9 1 a9 1 OpenPetidomo is free software; you can redistribute it and/or modify d14 1 a14 1 OpenPetidomo is distributed in the hope that it will be useful, but @ 1.1 log @Implemented the approve mode, where incoming mails are searched for confirmation cookies and the apropriate queue entries will be executed. @ text @d2 2 a3 2 $Source: /d1/e/petidomo/cvs/petidomo/source/listserv.c,v $ $Revision: 1.5 $ d21 1 a21 1 #include d24 1 @