]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
New function to prepare a standard mail in an easy way, and make send_help
authormmj <none@none>
Mon, 7 Jun 2004 12:36:39 +0000 (22:36 +1000)
committermmj <none@none>
Mon, 7 Jun 2004 12:36:39 +0000 (22:36 +1000)
use it. More to follow :)

src/Makefile.am
src/prepstdreply.c [new file with mode: 0644]
src/send_help.c

index b568aa8189506b1079681db1209eaec1ccf0009d..a153205d9b9e05fc467c28e40b130e6f58d35858 100644 (file)
@@ -23,21 +23,23 @@ mlmmj_recieve_SOURCES = mlmmj-recieve.c writen.c random-int.c strgen.c \
 mlmmj_process_SOURCES = mlmmj-process.c writen.c find_email_adr.c \
                        incindexfile.c itoa.c getlistaddr.c chomp.c \
                        mylocking.c listcontrol.c random-int.c strgen.c \
-                       print-version.c send_help.c \
+                       print-version.c send_help.c prepstdreply.c \
                        do_all_the_voodo_here.c mygetline.c gethdrline.c \
                        log_error.c statctrl.c ctrlvalue.c dumpfd2fd.c
 
 mlmmj_sub_SOURCES = mlmmj-sub.c writen.c mylocking.c \
                        getlistaddr.c chomp.c random-int.c strgen.c \
                        subscriberfuncs.c print-version.c \
-                       log_error.c mygetline.c
+                       log_error.c mygetline.c prepstdreply.c
 
 mlmmj_unsub_SOURCES = mlmmj-unsub.c writen.c mylocking.c \
                        getlistaddr.c chomp.c subscriberfuncs.c random-int.c \
-                       strgen.c print-version.c log_error.c mygetline.c
-
+                       strgen.c print-version.c log_error.c mygetline.c \
+                       prepstdreply.c
+                       
 mlmmj_bounce_SOURCES = mlmmj-bounce.c print-version.c log_error.c \
-                      subscriberfuncs.c strgen.c random-int.c writen.c
+                      subscriberfuncs.c strgen.c random-int.c writen.c \
+                      prepstdreply.c mygetline.c
 
 mlmmj_maintd_SOURCES = mlmmj-maintd.c print-version.c log_error.c mygetline.c \
                       strgen.c random-int.c chomp.c
diff --git a/src/prepstdreply.c b/src/prepstdreply.c
new file mode 100644 (file)
index 0000000..bf1e958
--- /dev/null
@@ -0,0 +1,73 @@
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <errno.h>
+
+#include "prepstdreply.h"
+#include "strgen.h"
+#include "chomp.h"
+#include "log_error.h"
+#include "mygetline.h"
+#include "wrappers.h"
+
+char *prepstdreply(const char *listdir, const char *filename, const char *from,
+                  const char *to, const char *replyto, const char *subject,
+                  size_t tokencount, char **data)
+{
+       int infd, outfd;
+       size_t i;
+       char *str, *tmp, *retstr;
+
+       tmp = concatstr(3, listdir, "/text/", filename);
+       infd = open(tmp, O_RDONLY);
+       free(tmp);
+       if(infd < 0) {
+               log_error(LOG_ARGS, "Could not open std mail %s", filename);
+               return NULL;
+       }
+
+       tmp = concatstr(6, "From: ", from, "\nTo: ", to, "\nSubject: ", subject);
+       if(replyto)
+               str = concatstr(3, tmp, "\nReply-To: ", replyto, "\n\n");
+       else
+               str = concatstr(2, tmp, "\n\n");
+               
+       free(tmp);
+
+       tmp = random_str();
+       retstr = concatstr(3, listdir, "/queue/", random);
+       free(tmp);
+       outfd = open(retstr, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR);
+       if(outfd < 0) {
+               log_error(LOG_ARGS, "Could not open std mail %s", tmp);
+               return NULL;
+       }
+
+       if(writen(outfd, str, strlen(str)) < 0) {
+               log_error(LOG_ARGS, "Could not write std mail");
+               return NULL;
+       }
+       free(str);
+
+       while((str = mygetline(infd))) {
+               for(i = 0; i < tokencount; i++) {
+                       if(strncmp(str, data[i*2], strlen(data[i*2])) == 0) {
+                               free(str);
+                               str = strdup(data[(i*2)+1]);
+                       }
+               }
+               if(writen(outfd, str, strlen(str)) < 0) {
+                       log_error(LOG_ARGS, "Could not write std mail");
+                       return NULL;
+               }
+               free(str);
+       }
+       
+       fsync(outfd);
+       close(outfd);
+
+       return retstr;
+}      
index f3dd8474c7beafbd8f37ea33b86247a8b259ce65..783831801d43bac769479d532a0beda7da53c8aa 100644 (file)
 #include "chomp.h"
 #include "wrappers.h"
 #include "mygetline.h"
+#include "prepstdreply.h"
 
 void send_help(const char *listdir, const char *emailaddr,
               const char *mlmmjsend)
 {
-       int helpfd, queuefd;
-       char *listaddr, *buf, *fromaddr;
-       char *helpfilename, *queuefilename, *listname;
-       char *randomstr, *listfqdn, *s1;
+       char *queuefilename, *listaddr, *listname, *listfqdn, *fromaddr;
+       char *fromstr, *subject;
+       char *maildata[] = { "*UNSUBADDR*", NULL, "*SUBADDR*", NULL,
+                            "*HLPADDR*", NULL };
 
         listaddr = getlistaddr(listdir);
        chomp(listaddr);
 
-       helpfilename = concatstr(2, listdir, "/text/listhelp");
-
-       if((helpfd = open(helpfilename, O_RDONLY)) < 0) {
-               log_error(LOG_ARGS, "Could not open text/help");
-               free(helpfilename);
-               exit(EXIT_FAILURE);
-       }
-
-       free(helpfilename);
-
        listname = genlistname(listaddr);
        listfqdn = genlistfqdn(listaddr);
-       randomstr = random_str();
-
-       queuefilename = concatstr(3, listdir, "/queue/", randomstr);
-       
-       queuefd = open(queuefilename, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR);
-       if(queuefd < 0) {
-               log_error(LOG_ARGS, "Could not open '%s'", queuefilename);
-               free(queuefilename);
-               free(randomstr);
-               exit(EXIT_FAILURE);
-       }
-       free(randomstr);
 
        fromaddr = concatstr(3, listname, "+bounces-help@", listfqdn);
 
-       s1 = concatstr(9, "From: ", listname, "+owner@", listfqdn,
-                       "\nTo: ", emailaddr, "\nSubject: Help for ",
-                       listaddr, "\n\n");
+        maildata[1] = concatstr(3, listname, "+unsubscribe@", listfqdn);
+       maildata[3] = concatstr(3, listname, "+subscribe@", listfqdn);
+       maildata[5] = concatstr(3, listname, "+help@", listfqdn);
+       fromstr = concatstr(3, listname, "+owner@", listfqdn);
+       subject = concatstr(2, "Help for ", listaddr);
 
-       if(writen(queuefd, s1, strlen(s1)) < 0) {
-               log_error(LOG_ARGS, "Could not write help mail");
+       queuefilename = prepstdreply(listdir, "listhelp", fromstr, emailaddr,
+                               NULL, subject, 3, maildata);
+       if(queuefilename == NULL) {
+               log_error(LOG_ARGS, "Could not prepare help mail");
                exit(EXIT_FAILURE);
        }
-
-       free(s1);
-
-       while((buf = mygetline(helpfd)) != NULL) {
-               if(strncmp(buf, "*UNSUBADDR*", 11) == 0) {
-                       s1 = concatstr(3, listname, "+unsubscribe@", listfqdn);
-                       if(writen(queuefd, s1, strlen(s1)) < 0) {
-                               log_error(LOG_ARGS,
-                                               "Could not write help mail");
-                               exit(EXIT_FAILURE);
-                       }
-                       free(s1);
-               } else if(strncmp(buf, "*SUBADDR*", 9) == 0) {
-                       s1 = concatstr(3, listname, "+subscribe@", listfqdn);
-                       if(writen(queuefd, s1, strlen(s1)) < 0) {
-                               log_error(LOG_ARGS,
-                                               "Could not write help mail");
-                               exit(EXIT_FAILURE);
-                       }
-                       free(s1);
-               } else if(strncmp(buf, "*HLPADDR*", 9) == 0) {
-                       s1 = concatstr(3, listname, "+help@", listfqdn);
-                       if(writen(queuefd, s1, strlen(s1)) < 0) {
-                               log_error(LOG_ARGS,
-                                               "Could not write help mail");
-                               exit(EXIT_FAILURE);
-                       }
-                       free(s1);
-               } else if(writen(queuefd, buf, strlen(buf)) < 0) {
-                               log_error(LOG_ARGS,
-                                               "Could not write help mail");
-                               exit(EXIT_FAILURE);
-               }
-               free(buf);
-       }
        
+       free(fromstr);
+       free(listaddr);
        free(listname);
        free(listfqdn);
-       close(helpfd);
-       close(queuefd);
+       free(maildata[1]);
+       free(maildata[3]);
+       free(maildata[5]);
+       free(subject);
 
        execlp(mlmmjsend, mlmmjsend,
                                "-l", "1",
                                "-T", emailaddr,
                                "-F", fromaddr,
                                "-m", queuefilename, 0);
+
        log_error(LOG_ARGS, "execlp() of '%s' failed", mlmmjsend);
        exit(EXIT_FAILURE);
 }