]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
modern C: replace writen with dprintf
authorBaptiste Daroussin <bapt@FreeBSD.org>
Wed, 20 Apr 2022 10:18:32 +0000 (12:18 +0200)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Thu, 20 Oct 2022 11:17:36 +0000 (13:17 +0200)
14 files changed:
contrib/receivestrip/mlmmj-receive-strip.c
src/do_all_the_voodoo_here.c
src/incindexfile.c
src/log_oper.c
src/mail-functions.c
src/mlmmj-bounce.c
src/mlmmj-maintd.c
src/mlmmj-process.c
src/mlmmj-send.c
src/mlmmj-sub.c
src/mlmmj-unsub.c
src/prepstdreply.c
src/send_digest.c
src/send_list.c

index ea8392d9c9b5382be4862deb5b9771f9cfeb6458..01b4af271398f5e118e16d88af0dcf7927b24a96 100644 (file)
@@ -211,7 +211,7 @@ static int read_hdrs(int fd, struct strlist *allhdrs,struct strlist* delmime,str
 static int write_hdrs(int outfd,struct strlist* hdrs,off_t* unwantedmime_hdrpos) {
        int i;
        for(i = 0; i < hdrs->count ; i++) {
-               if(writen(outfd, hdrs->strs[i], strlen(hdrs->strs[i])) < 0){
+               if(dprintf(outfd, "%s", hdrs->strs[i]) < 0){
                        log_error(LOG_ARGS, "Error when dumping headers");
                        return -1;
                }
@@ -220,7 +220,7 @@ static int write_hdrs(int outfd,struct strlist* hdrs,off_t* unwantedmime_hdrpos)
        /* if this is not the header of an embedded part add the header that will
           indicate if the mail contains unwanted mime parts */
        if(unwantedmime_hdrpos) {
-               if(writen(outfd, UNWANTED_MIME_HDR,strlen(UNWANTED_MIME_HDR)) < 0){
+               if(dprintf(outfd, "%s", UNWANTED_MIME_HDR) < 0){
                        log_error(LOG_ARGS, "Error writting unwanted mime header");
                        return -1;
                }
@@ -234,7 +234,7 @@ static int write_hdrs(int outfd,struct strlist* hdrs,off_t* unwantedmime_hdrpos)
        }
 
        /* write a single line feed to terminate the header part */
-       if(writen(outfd, "\n", 1) < 0) {
+       if(dprintf(outfd, "\n") < 0) {
                log_error(LOG_ARGS,"Error writting end of hdrs.");
                return -1;
        }
@@ -250,7 +250,7 @@ static int update_unwantedmime_hdr(int outfd,off_t unwantedmime_hdrpos) {
        }
 
        /* update the header */
-       if(writen(outfd, "Y\n",2) < 0){
+       if(dprintf(outfd, "Y\n") < 0){
                log_error(LOG_ARGS, "Error writting extra header");
                return -1;
        }
@@ -279,7 +279,7 @@ static int parse_body(int infd,int outfd, struct strlist* delmime, struct strlis
                                        strip = 1;
                                else {
                                        /* write boundary */
-                                       if(writen(outfd, line, strlen(line)) < 0){
+                                       if(dprintf(outfd, "%s", line) < 0){
                                                log_error(LOG_ARGS, "Error writting boundary");
                                                return -1;
                                        }
@@ -299,7 +299,7 @@ static int parse_body(int infd,int outfd, struct strlist* delmime, struct strlis
                                        myfree(new_boundary);
                        }else{
                                /* write end of part */
-                               if(writen(outfd, line, strlen(line)) < 0){
+                               if(dprintf(outfd, "%s", line) < 0){
                                        log_error(LOG_ARGS, "Error writting hdrs");
                                        return -1;
                                }
@@ -309,7 +309,7 @@ static int parse_body(int infd,int outfd, struct strlist* delmime, struct strlis
                        }
                }else {
                        if(!strip) { /* write the current line */
-                               if(writen(outfd, line, strlen(line)) < 0){
+                               if(dprintf(outfd, "%s", line) < 0){
                                        log_error(LOG_ARGS, "Error when dumping line");
                                        return -1;
                                }
index 020ac07362cc13305355f42c6d2b1ac7ed8451b1..63676adbc24382365ea599a19cf9c802b4976f8e 100644 (file)
@@ -21,6 +21,7 @@
  * IN THE SOFTWARE.
  */
 
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -75,7 +76,7 @@ int do_all_the_voodoo_here(int infd, int outfd, int hdrfd, int footfd,
                 const struct strlist *delhdrs, struct mailhdr *readhdrs,
                 struct strlist *allhdrs, const char *prefix)
 {
-       char *hdrline, *unfolded, *subject, *unqp;
+       char *hdrline, *unfolded, *unqp;
        int hdrsadded = 0;
        int subject_present = 0;
 
@@ -108,13 +109,11 @@ int do_all_the_voodoo_here(int infd, int outfd, int hdrfd, int footfd,
                        /* add Subject if none is present
                           and a prefix is defined */
                        if (prefix && !subject_present) {
-                               subject = concatstr(3,"Subject: ",prefix,"\n");
-                               writen(outfd, subject, strlen(subject));
-                               myfree(subject);
+                               dprintf(outfd, "Subject: %s\n", prefix);
                                subject_present = 1;
                        }
                        /* write LF */
-                       if(writen(outfd, "\n", 1) < 0) {
+                       if(dprintf(outfd, "\n") < 0) {
                                myfree(hdrline);
                                myfree(unfolded);
                                log_error(LOG_ARGS, "Error writing hdrs.");
@@ -142,12 +141,7 @@ int do_all_the_voodoo_here(int infd, int outfd, int hdrfd, int footfd,
                                unqp = cleanquotedp(hdrline + 8);
                                if(strstr(hdrline + 8, prefix) == NULL &&
                                   strstr(unqp, prefix) == NULL) {
-                                       subject = concatstr(4,
-                                                       "Subject: ", prefix,
-                                                       hdrline + 8, "\n");
-                                       writen(outfd, subject,
-                                                       strlen(subject));
-                                       myfree(subject);
+                                       dprintf(outfd, "Subject: %s%s\n", prefix, hdrline + 8);
                                        myfree(hdrline);
                                        myfree(unqp);
                                        continue;
@@ -158,7 +152,7 @@ int do_all_the_voodoo_here(int infd, int outfd, int hdrfd, int footfd,
 
                /* Should it be stripped? */
                if(!delhdrs || !findit(hdrline, delhdrs))
-                       writen(outfd, unfolded, strlen(unfolded));
+                       dprintf(outfd, "%s", unfolded);
 
                myfree(hdrline);
                myfree(unfolded);
index ebfd288ce644a52ed2b642990a68caba283deb16..166bf6b080b96a860e15c6c1b28f39cae551c55e 100644 (file)
@@ -74,9 +74,8 @@ int incindexfile(const char *listdir)
        }
        index = atol(intbuf);
        index++;
-       snprintf(intbuf, sizeof(intbuf), "%ld", index);
        lseek(fd, 0, SEEK_SET);
-       writen(fd, intbuf, strlen(intbuf));
+       dprintf(fd, "%ld", index);
 
        close(fd); /* Lock is also released */
        myfree(indexfilename);
index ca3d32418b889ba6690e040923bfcf374367b6c9..3bc5e5b7afb759e6a1e33b50778234c6c174e3e2 100644 (file)
@@ -43,7 +43,7 @@
 int log_oper(const char *prefix, const char *basename, const char *fmt, ...)
 {
        int fd, statres;
-       char ct[26], *logstr, *logfilename, *tmp, log_msg[256];
+       char ct[26], *logfilename, *tmp, log_msg[256];
        struct stat st;
        time_t t;
        va_list ap;
@@ -96,13 +96,11 @@ int log_oper(const char *prefix, const char *basename, const char *fmt, ...)
 
        va_end(ap);
 
-       logstr = concatstr(4, ct, " ", log_msg, "\n");
-       if(writen(fd, logstr, strlen(logstr)) < 0)
+       if(dprintf(fd, "%s %s\n", ct, log_msg) < 0)
                log_error(LOG_ARGS, "Could not write to %s", logfilename);
        
        close(fd);
        myfree(logfilename);
-       myfree(logstr);
        
        return 0;
 }
index 9ff128c79453bb466d1cf9484512aec42654eced..8ec85d166d8e45a63ae4ad579d607eeab35d9076 100644 (file)
 #define EXTRA_EHLO_LEN 7
 int write_ehlo(int sockfd, const char *hostname)
 {
-       size_t len = (size_t)(strlen(hostname) + EXTRA_EHLO_LEN + 1);
-       char *ehlo;
        size_t bytes_written;
        
-       if((ehlo = mymalloc(len)) == 0)
-               return errno;
-       snprintf(ehlo, len, "EHLO %s\r\n", hostname);
-       len = strlen(ehlo);
-#if 0
-       fprintf(stderr, "\nwrite_ehlo, ehlo = [%s]\n", ehlo);
-#endif
-       bytes_written = writen(sockfd, ehlo, len);
+       bytes_written = dprintf(sockfd, "EHLO %s\r\n", hostname);
        if(bytes_written < 0) {
                log_error(LOG_ARGS, "Could not write EHLO");
-               myfree(ehlo);
                return errno;
        }
-       myfree(ehlo);
        return 0;
 }
 /* "HELO \r\n" has length 7 */
 #define EXTRA_HELO_LEN 7
 int write_helo(int sockfd, const char *hostname)
 {
-       size_t len = (size_t)(strlen(hostname) + EXTRA_HELO_LEN + 1);
-       char *helo;
        size_t bytes_written;
        
-       if((helo = mymalloc(len)) == 0)
-               return errno;
-       snprintf(helo, len, "HELO %s\r\n", hostname);
-       len = strlen(helo);
-#if 0
-       fprintf(stderr, "\nwrite_helo, helo = [%s]\n", helo);
-#endif
-       bytes_written = writen(sockfd, helo, len);
+       bytes_written = dprintf(sockfd, "HELO %s\r\n", hostname);
        if(bytes_written < 0) {
                log_error(LOG_ARGS, "Could not write HELO");
-               myfree(helo);
                return errno;
        }
-       myfree(helo);
        return 0;
 }
 /* "MAIL FROM:<> \r\n" has length 15 */
 #define EXTRA_FROM_LEN 15
 int write_mail_from(int sockfd, const char *from_addr, const char *extra)
 {
-       size_t len = (size_t)(strlen(from_addr) + EXTRA_FROM_LEN +
-                       strlen(extra) + 1);
-       char *mail_from;
        size_t bytes_written;
 
-       mail_from = mymalloc(len);
-
        if(extra && extra[0] != '\0') {
                if(extra[0] == ' ') extra++;
-               snprintf(mail_from, len, "MAIL FROM:<%s> %s\r\n", from_addr,
+               bytes_written = dprintf(sockfd, "MAIL FROM:<%s> %s\r\n", from_addr,
                                extra);
        } else
-               snprintf(mail_from, len, "MAIL FROM:<%s>\r\n", from_addr);
-
-       len = strlen(mail_from);
-
-#if 0
-       fprintf(stderr, "%s", mail_from);
-#endif
-       bytes_written = writen(sockfd, mail_from, len);
+               bytes_written = dprintf(sockfd, "MAIL FROM:<%s>\r\n", from_addr);
        if(bytes_written < 0) {
                log_error(LOG_ARGS, "Could not write FROM");
-               myfree(mail_from);
                return errno;
        }
-       myfree(mail_from);
        return 0;
 }
 
@@ -122,25 +86,13 @@ int write_mail_from(int sockfd, const char *from_addr, const char *extra)
 #define EXTRA_RCPT_LEN 12
 int write_rcpt_to(int sockfd, const char *rcpt_addr)
 {
-       size_t len = (size_t)(strlen(rcpt_addr) + EXTRA_RCPT_LEN + 1);
-       char *rcpt_to;
        size_t bytes_written;
        
-       if((rcpt_to = mymalloc(len)) == 0)
-               return errno;
-
-       snprintf(rcpt_to, len, "RCPT TO:<%s>\r\n", rcpt_addr);
-       len = strlen(rcpt_to);
-#if 0
-       log_error(LOG_ARGS, "%s", rcpt_to);
-#endif
-       bytes_written = writen(sockfd, rcpt_to, len);
+       bytes_written = dprintf(sockfd, "RCPT TO:<%s>\r\n", rcpt_addr);
        if(bytes_written < 0) {
                log_error(LOG_ARGS, "Could not write TO");
-               myfree(rcpt_to);
                return errno;
        }
-       myfree(rcpt_to);
        return 0;
 }
 
@@ -150,7 +102,6 @@ int write_mailbody_from_map(int sockfd, char *mapstart, size_t size,
 {
        char *cur, *next;
        char newlinebuf[3];
-       size_t len;
        int i = 1;
 
        for(next = cur = mapstart; next < mapstart + size; next++) {
@@ -161,17 +112,15 @@ int write_mailbody_from_map(int sockfd, char *mapstart, size_t size,
                        }
                        newlinebuf[0] = '\r';
                        newlinebuf[1] = '\n';
-                       len = 2;
                        if(next < (mapstart + size - 1) && *(next+1) == '.') {
                                newlinebuf[2] = '.';
-                               len = 3;
                        }
-                       if(writen(sockfd, newlinebuf, len) < 0) {
+                       if(dprintf(sockfd, "%s", newlinebuf) < 0) {
                                log_error(LOG_ARGS, "Could not write mail");
                                return -1;
                        }
                        if(i && tohdr && *(next+1) == '\n') { /* add To: header */
-                               if(writen(sockfd, tohdr, strlen(tohdr)) < 0) {
+                               if(dprintf(sockfd, "%s", tohdr) < 0) {
                                        log_error(LOG_ARGS, "Could not write"
                                                            " To: header");
                                        return -1;
@@ -268,7 +217,7 @@ int write_dot(int sockfd)
 {
        size_t bytes_written;
 
-       bytes_written = writen(sockfd, "\r\n.\r\n", 5); 
+       bytes_written = dprintf(sockfd, "\r\n.\r\n");   
        if(bytes_written < 0)
                return errno;
 
@@ -279,26 +228,13 @@ int write_dot(int sockfd)
 #define EXTRA_CUSTOM_LEN 2
 int write_custom_line(int sockfd, const char *line)
 {
-       size_t len = strlen(line) + EXTRA_CUSTOM_LEN + 1;
        size_t bytes_written;
-       char *customline;
-       
-       if((customline = mymalloc(len)) == 0)
-               return errno;
        
-       snprintf(customline, len, "%s\r\n", line);
-       len = strlen(customline);
-#if 0
-       fprintf(stderr, "write_custom_line = [%s]\n", customline);
-       fprintf(stderr, "strlen(customline) = [%d]\n", strlen(customline));
-#endif
-       bytes_written = writen(sockfd, customline, len);
+       bytes_written = dprintf(sockfd, "%s\r\n", line);
        if(bytes_written < 0) {
                log_error(LOG_ARGS, "Could not write customline");
-               myfree(customline);
                return errno;
        }
-       myfree(customline);
        return 0;
 }
 
@@ -306,26 +242,13 @@ int write_custom_line(int sockfd, const char *line)
 #define EXTRA_REPLYTO_LEN 12
 int write_replyto(int sockfd, const char *replyaddr)
 {
-       size_t len = (size_t)(strlen(replyaddr) + EXTRA_REPLYTO_LEN + 1);
-       char *replyto;
        size_t bytes_written;
        
-       if((replyto = mymalloc(len)) == 0)
-               return errno;
-
-       snprintf(replyto, len, "Reply-To: %s\r\n", replyaddr);
-       len = strlen(replyto);
-
-#if 0
-       fprintf(stderr, "\nwrite_replyto, replyto = [%s]\n", replyto);
-#endif
-       bytes_written = writen(sockfd, replyto, len);
+       bytes_written = dprintf(sockfd, "Reply-To: %s\r\n", replyaddr);
        if(bytes_written < 0) {
                log_error(LOG_ARGS, "Could not write Reply-To header");
-               myfree(replyto);
                return errno;
        }
-       myfree(replyto);
        return 0;
 }
 
index 54f62e858ec38b86c551cb743590c7628fbed2d1..e5f1d32abd4d773c5767410be94a58c1eda84d5a 100644 (file)
@@ -106,7 +106,7 @@ void do_probe(const char *listdir, const char *mlmmjsend, const char *addr)
        if(fd < 0)
                log_error(LOG_ARGS, "Could not open %s", probefile);
        else
-               if(writen(fd, a, strlen(a)) < 0)
+               if(dprintf(fd, "%s", a) < 0)
                        log_error(LOG_ARGS, "Could not write time in probe");
 
        myfree(probefile);
@@ -381,7 +381,7 @@ int main(int argc, char **argv)
        t = time(NULL);
        snprintf(buf, len-26, "%s:%ld # ", number, (long int)t);
        ctime_r(&t, buf+strlen(buf));
-       writen(fd, buf, strlen(buf));
+       dprintf(fd, "%s", buf);
        close(fd);
 
        if(mailname) {
index c8caae995e20dc019bb9ad4c587b589ded61a1c0..e753e79da0810a21b9c45c8ba7ad38345fcfef44 100644 (file)
@@ -801,11 +801,10 @@ int run_digests(const char *listdir, const char *mlmmjsend)
        char *lasttimestr, *lastindexstr, *lastissuestr;
        char *digestname, *indexname;
        char *digestintervalstr, *digestmaxmailsstr;
-       char *s1, *s2, *s3;
+       char *s1, *s2;
        time_t digestinterval, t, lasttime;
        long digestmaxmails, lastindex, index, lastissue;
        int fd, indexfd, lock;
-       size_t lenbuf, lenstr;
 
        if (statctrl(listdir, "noarchive")) {
                return 0;
@@ -911,17 +910,10 @@ int run_digests(const char *listdir, const char *mlmmjsend)
                if (lseek(fd, 0, SEEK_SET) < 0) {
                        log_error(LOG_ARGS, "Could not seek '%s'", digestname);
                } else {
-                       /* index + ':' + time + ':' + issue + '\n' + '\0' */
-                       lenbuf = 20 + 1 + 20 + 1 + 20 + 2;
-                       s3 = mymalloc(lenbuf);
-                       lenstr = snprintf(s3, lenbuf, "%ld:%ld:%ld\n", index, (long)t, lastissue);
-                       if (lenstr >= lenbuf)
-                               lenstr = lenbuf - 1;
-                       if (writen(fd, s3, lenstr) == -1) {
+                       if (dprintf(fd, "%ld:%ld:%ld\n", index, (long)t, lastissue) < 0 ) {
                                log_error(LOG_ARGS, "Could not write new '%s'",
                                                digestname);
                        }
-                       myfree(s3);
                }
        }
 
index e192e5b626b698a814511c5b317f3805fed2ca00..17985c9c556295e5dde90e39198aa5cc891bd1d1 100644 (file)
@@ -1163,7 +1163,7 @@ int main(int argc, char **argv)
                                exit(EXIT_FAILURE);
                        }
                        myfree(omitfilename);
-                       if(writen(omitfd, posteraddr, strlen(posteraddr)) < 0) {
+                       if(dprintf(omitfd, "%s", posteraddr) < 0) {
                                log_error(LOG_ARGS,
                                                "could not write omit file");
                                myfree(mqueuename);
index 65d3e276e448b67f9320f00300fb62d71be5dfd8..5112f13b5efde868771cd6c353afd193fe073639 100644 (file)
@@ -328,20 +328,20 @@ int send_mail(int sockfd, const char *from, const char *to,
                tohdr = NULL;
 
        if(prepmailinmem) {
-               retval = writen(sockfd, hdrs, hdrslen);
+               retval = dprintf(sockfd, "%s", hdrs);
                if(retval < 0) {
                        log_error(LOG_ARGS, "Could not write mailheaders.\n");
                        return retval;
                }
                if(tohdr) {
-                       retval = writen(sockfd, tohdr, strlen(tohdr));
+                       retval = dprintf(sockfd, "%s", tohdr);
                        if(retval < 0) {
                                log_error(LOG_ARGS, "Could not write To:.\n");
                                return retval;
                        }
                        myfree(tohdr);
                }
-               retval = writen(sockfd, body, bodylen);
+               retval = dprintf(sockfd, "%s", body);
                if(retval < 0) {
                        log_error(LOG_ARGS, "Could not write mailbody.\n");
                        return retval;
@@ -591,12 +591,12 @@ int send_mail_verp(int sockfd, struct strlist *addrs, char *mailmap,
        }
 
        if(prepmailinmem) {
-               retval = writen(sockfd, hdrs, hdrslen);
+               retval = dprintf(sockfd, "%s", hdrs);
                if(retval < 0) {
                        log_error(LOG_ARGS, "Could not write mailheaders.\n");
                        return retval;
                }
-               retval = writen(sockfd, body, bodylen);
+               retval = dprintf(sockfd, "%s", body);
                if(retval < 0) {
                        log_error(LOG_ARGS, "Could not write mailbody.\n");
                        return retval;
@@ -678,7 +678,7 @@ int requeuemail(const char *listdir, const char *index, struct strlist *addrs,
                int addrcount)
 {
        int addrfd, i;
-       char *dirname, *addrfilename, *addr;
+       char *dirname, *addrfilename;
        
        dirname = concatstr(3, listdir, "/requeue/", index);
        if(mkdir(dirname, 0750) < 0 && errno != EEXIST) {
@@ -703,21 +703,17 @@ int requeuemail(const char *listdir, const char *index, struct strlist *addrs,
                 * ones will be tried first when mlmmj-maintd sends out mails
                 * that have been requeued. addrcount was so far we were */
                for(i = addrcount + 1; i < addrs->count; i++) {
-                       addr = concatstr(2, addrs->strs[i], "\n");
-                       if(writen(addrfd, addr, strlen(addr)) < 0) {
+                       if(dprintf(addrfd, "%s\n", addrs->strs[i]) < 0) {
                                log_error(LOG_ARGS, "Could not add [%s] "
-                                                   "to requeue file", addr);
+                                                   "to requeue file", addrs->strs[i]);
                                return -1;
                        }
-                       myfree(addr);
                }
-               addr = concatstr(2, addrs->strs[addrcount], "\n");
-               if(writen(addrfd, addr, strlen(addr)) < 0) {
+               if(dprintf(addrfd, "%s\n", addrs->strs[addrcount]) < 0) {
                        log_error(LOG_ARGS, "Could not add [%s] to requeue "
-                                       "file", addr);
+                                       "file", addrs->strs[addrcount]);
                        return -1;
                }
-               myfree(addr);
        }
        myfree(addrfilename);
        close(addrfd);
@@ -1109,7 +1105,7 @@ int main(int argc, char **argv)
                                                S_IRUSR|S_IWUSR);
                        myfree(tmpstr);
                        if(tmpfd >= 0) {
-                               writen(tmpfd, bounceaddr, strlen(bounceaddr));
+                               dprintf(tmpfd, "%s", bounceaddr);
                                fsync(tmpfd);
                        }
                        close(tmpfd);
@@ -1122,7 +1118,7 @@ int main(int argc, char **argv)
                                                S_IRUSR|S_IWUSR);
                        myfree(tmpstr);
                        if(tmpfd >= 0) {
-                               writen(tmpfd, to_addr, strlen(to_addr));
+                               dprintf(tmpfd, "%s", to_addr);
                                fsync(tmpfd);
                        }
                        close(tmpfd);
@@ -1137,8 +1133,7 @@ int main(int argc, char **argv)
                                                        S_IRUSR|S_IWUSR);
                                myfree(tmpstr);
                                if(tmpfd >= 0) {
-                                       writen(tmpfd, replyto,
-                                               strlen(replyto));
+                                       dprintf(tmpfd, "%s", replyto);
                                        fsync(tmpfd);
                                }
                                close(tmpfd);
index 29da25e3dd56b80c8bda79e050409a3929cb1707..55d0e08346bf9853a5150cd5d08ae838d519b093 100644 (file)
@@ -99,7 +99,7 @@ static void moderate_sub(const char *listdir, const char *listaddr,
                break;
        }
 
-       if(writen(fd, str, strlen(str)) < 0) {
+       if(dprintf(fd, "%s", str) < 0) {
                log_error(LOG_ARGS, "could not write to %s"
                                "ignoring request: %s", str);
                exit(EXIT_FAILURE);
@@ -432,7 +432,7 @@ void generate_subconfirm(const char *listdir, const char *listaddr,
 
        myfree(confirmfilename);
 
-       if(writen(subconffd, subaddr, strlen(subaddr)) < 0) {
+       if(dprintf(subconffd, "%s", subaddr) < 0) {
                log_error(LOG_ARGS, "Could not write to subconffd");
                myfree(confirmfilename);
                 myfree(randomstr);
index e4f598ab912cad84d9966a82d9d1d9ae32ec69e6..44dff834c70f5bad9e1d95e9a506550eed9ae4b9 100644 (file)
@@ -189,7 +189,7 @@ void generate_unsubconfirm(const char *listdir, const char *listaddr,
 
        myfree(confirmfilename);
 
-       if(writen(subconffd, subaddr, strlen(subaddr)) < 0) {
+       if(dprintf(subconffd, "%s", subaddr) < 0) {
                log_error(LOG_ARGS, "Could not write unsubconffile");
                 myfree(randomstr);
                myfree(confirmfilename);
index 5368d6331205cd2a09a04682673cbf3fd4cbcb68..4ce9a51a5774e0bfd0578569c968d3445d08cbc0 100644 (file)
@@ -1663,9 +1663,7 @@ char *prepstdreply(text *txt, const char *listdir,
                if (*line == ' ' || *line == '\t') {
                        /* line beginning with linear whitespace is a
                           continuation of previous header line */
-                       len = strlen(line);
-                       line[len] = '\n';
-                       if(writen(outfd, line, len+1) < 0) {
+                       if(dprintf(outfd, "%s\n", line) < 0) {
                                log_error(LOG_ARGS, "Could not write std mail");
                                myfree(line);
                                myfree(retstr);
@@ -1703,9 +1701,7 @@ char *prepstdreply(text *txt, const char *listdir,
                                line = concatstr(2, "Subject: ", tmp);
                                myfree(tmp);
                        }
-                       len = strlen(line);
-                       line[len] = '\n';
-                       if(writen(outfd, line, len+1) < 0) {
+                       if(dprintf(outfd, "%s\n", line) < 0) {
                                log_error(LOG_ARGS, "Could not write std mail");
                                myfree(line);
                                myfree(retstr);
@@ -1718,9 +1714,7 @@ char *prepstdreply(text *txt, const char *listdir,
        }
 
        for (i=0; headers[i] != NULL; i++) {
-               len = strlen(headers[i]);
-               headers[i][len] = '\n';
-               if(writen(outfd, headers[i], len+1) < 0) {
+               if(dprintf(outfd, "%s\n", headers[i]) < 0) {
                        log_error(LOG_ARGS, "Could not write std mail");
                        if (line)
                                myfree(line);
@@ -1731,7 +1725,7 @@ char *prepstdreply(text *txt, const char *listdir,
        }
 
        /* end the headers */
-       if(writen(outfd, "\n", 1) < 0) {
+       if(dprintf(outfd, "\n") < 0) {
                log_error(LOG_ARGS, "Could not write std mail");
                if (line)
                        myfree(line);
@@ -1745,9 +1739,7 @@ char *prepstdreply(text *txt, const char *listdir,
                                listdir);
        }
        while(line) {
-                       len = strlen(line);
-                       line[len] = '\n';
-                       if(writen(outfd, line, len+1) < 0) {
+                       if(dprintf(outfd, "%s\n", line) < 0) {
                                myfree(str);
                                log_error(LOG_ARGS, "Could not write std mail");
                                myfree(retstr);
index a8199a992e4eb1c3aa9ca7c3de2bff9cf26aff28..b136d39cc66cbcf8ca9706715572fe166dc9900e 100644 (file)
@@ -369,21 +369,18 @@ fallback_subject:
                myfree(tmp);
        }
 
-       tmp = concatstr(10, "From: ", listname, listdelim, "help@", listfqdn,
-                          "\nMIME-Version: 1.0"
-                          "\nContent-Type: multipart/" DIGESTMIMETYPE "; "
-                          "boundary=", boundary,
-                          "\nSubject: ", subject,
-                          "\n");
-
-       myfree(listfqdn);
-       myfree(subject);
-
-       if (writen(fd, tmp, strlen(tmp)) < 0) {
-               myfree(tmp);
+       if (dprintf(fd, "From: %s%shelp@%s"
+           "\nMIME-Version: 1.0"
+           "\nContent-Type: multipart/" DIGESTMIMETYPE "; "
+           "boundary=%s"
+           "\nSubject: %s\n",
+           listname, listdelim, listfqdn, boundary, subject) < 0) {
+               myfree(listfqdn);
+               myfree(subject);
                goto errdighdrs;
        }
-       myfree(tmp);
+       myfree(listfqdn);
+       myfree(subject);
 
        if(hdrfd >= 0 && dumpfd2fd(hdrfd, fd) < 0) {
                goto errdighdrs;
@@ -392,7 +389,7 @@ fallback_subject:
        close(hdrfd);
        hdrfd = -1;
 
-       if (writen(fd, "\n", 1) < 0) {
+       if (dprintf(fd, "\n") < 0) {
 errdighdrs:
                log_error(LOG_ARGS, "Could not write digest headers to '%s'",
                                queuename);
@@ -415,17 +412,15 @@ errdighdrs:
 
        if ((txt != NULL) && !statctrl(listdir, "nodigesttext")) {
 
-               tmp = concatstr(3, "\n--", boundary,
-                               "\nContent-Type: text/plain; charset=UTF-8"
-                               "\nContent-Transfer-Encoding: 8bit"
-                               "\n\n");
-               if (writen(fd, tmp, strlen(tmp)) == -1) {
+               if (dprintf(fd, "\n--%s"
+                   "\nContent-Type: text/plain; charset=UTF-8"
+                   "\nContent-Transfer-Encoding: 8bit"
+                   "\n\n", boundary) < 0) {
                        log_error(LOG_ARGS, "Could not write digest text/plain"
                                        " part headers to '%s'", queuename);
                        close(fd);
                        unlink(queuename);
                        myfree(boundary);
-                       myfree(tmp);
                        myfree(queuename);
                        myfree(listaddr);
                        myfree(listname);
@@ -436,15 +431,12 @@ errdighdrs:
                        }
                        return -1;
                }
-               myfree(tmp);
 
                for (;;) {
                        line = get_processed_text_line(txt, 0, listaddr, listdelim,
                                        listdir);
                        if (line == NULL) break;
-                       len = strlen(line);
-                       line[len] = '\n';
-                       if(writen(fd, line, len+1) < 0) {
+                       if(dprintf(fd, "%s\n", line) < 0) {
                                myfree(line);
                                log_error(LOG_ARGS, "Could not write"
                                                " std mail");
@@ -474,12 +466,10 @@ errdighdrs:
                if (archivefd < 0)
                        continue;
                
-               tmp = concatstr(7, "\n--", boundary,
-                               "\nContent-Type: message/rfc822"
-                               "\nContent-Disposition: inline; filename=\"",
-                                       listname, "_", buf, ".eml\""
-                               "\n\n");
-               if (writen(fd, tmp, strlen(tmp)) == -1) {
+               if (dprintf(fd, "\n--%s"
+                   "\nContent-Type: message/rfc822"
+                   "\nContent-Disposition: inline; filename=\"%s_%s.eml\"\n\n",
+                   boundary, listname, buf) < 0) {
                        log_error(LOG_ARGS, "Could not write digest part "
                                        "headers for archive index %d to "
                                        "'%s'", i, queuename);
@@ -492,7 +482,6 @@ errdighdrs:
                        myfree(listname);
                        return -1;
                }
-               myfree(tmp);
 
                if (dumpfd2fd(archivefd, fd) < 0) {
                        log_error(LOG_ARGS, "Could not write digest part %d "
@@ -510,8 +499,7 @@ errdighdrs:
                close(archivefd);
        }
 
-       tmp = concatstr(3, "\n--", boundary, "--\n");
-       if (writen(fd, tmp, strlen(tmp)) == -1) {
+       if (dprintf(fd, "\n--%s--\n", boundary) < 0) {
                log_error(LOG_ARGS, "Could not write digest end to '%s'",
                                queuename);
                close(fd);
@@ -525,7 +513,6 @@ errdighdrs:
        close(fd);
        myfree(boundary);
        myfree(listname);
-       myfree(tmp);
 
        childpid = fork();
 
index 73648119e729c9d3b7bea8a4ec824085d820862a..b14f22337f6a4df6174c0d4b38caaeb9496af77a 100644 (file)
@@ -143,10 +143,10 @@ static void print_subs(int fd, subs_list_state *s)
        const char *sub;
        rewind_subs_list(s);
        while ((sub = get_sub(s)) != NULL) {
-               if (writen(fd, sub, strlen(sub)) < 0) {
+               if (dprintf(fd, "%s", sub) < 0) {
                        log_error(LOG_ARGS, "error writing subs list");
                }
-               writen(fd, "\n", 1);
+               dprintf(fd, "\n");
        }
 }
 
@@ -202,11 +202,11 @@ void send_list(const char *listdir, const char *emailaddr,
                        exit(EXIT_FAILURE);
                }
                print_subs(fd, normalsls);
-               writen(fd, "\n-- \n", 5);
+               dprintf(fd, "\n-- \n");
                print_subs(fd, nomailsls);
-               writen(fd, "\n-- \n", 5);
+               dprintf(fd, "\n-- \n");
                print_subs(fd, digestsls);
-               writen(fd, "\n-- \nend of output\n", 19);
+               dprintf(fd, "\n-- \nend of output\n");
                close(fd);
        }