From: Baptiste Daroussin Date: Wed, 20 Apr 2022 10:18:32 +0000 (+0200) Subject: modern C: replace writen with dprintf X-Git-Tag: RELEASE_1_4_0a1~87 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=85ea745fc402a46764ccc424628f24340ebce1f6;p=thirdparty%2Fmlmmj.git modern C: replace writen with dprintf --- diff --git a/contrib/receivestrip/mlmmj-receive-strip.c b/contrib/receivestrip/mlmmj-receive-strip.c index ea8392d9..01b4af27 100644 --- a/contrib/receivestrip/mlmmj-receive-strip.c +++ b/contrib/receivestrip/mlmmj-receive-strip.c @@ -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; } diff --git a/src/do_all_the_voodoo_here.c b/src/do_all_the_voodoo_here.c index 020ac073..63676adb 100644 --- a/src/do_all_the_voodoo_here.c +++ b/src/do_all_the_voodoo_here.c @@ -21,6 +21,7 @@ * IN THE SOFTWARE. */ +#include #include #include #include @@ -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); diff --git a/src/incindexfile.c b/src/incindexfile.c index ebfd288c..166bf6b0 100644 --- a/src/incindexfile.c +++ b/src/incindexfile.c @@ -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); diff --git a/src/log_oper.c b/src/log_oper.c index ca3d3241..3bc5e5b7 100644 --- a/src/log_oper.c +++ b/src/log_oper.c @@ -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; } diff --git a/src/mail-functions.c b/src/mail-functions.c index 9ff128c7..8ec85d16 100644 --- a/src/mail-functions.c +++ b/src/mail-functions.c @@ -41,80 +41,44 @@ #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; } diff --git a/src/mlmmj-bounce.c b/src/mlmmj-bounce.c index 54f62e85..e5f1d32a 100644 --- a/src/mlmmj-bounce.c +++ b/src/mlmmj-bounce.c @@ -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) { diff --git a/src/mlmmj-maintd.c b/src/mlmmj-maintd.c index c8caae99..e753e79d 100644 --- a/src/mlmmj-maintd.c +++ b/src/mlmmj-maintd.c @@ -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); } } diff --git a/src/mlmmj-process.c b/src/mlmmj-process.c index e192e5b6..17985c9c 100644 --- a/src/mlmmj-process.c +++ b/src/mlmmj-process.c @@ -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); diff --git a/src/mlmmj-send.c b/src/mlmmj-send.c index 65d3e276..5112f13b 100644 --- a/src/mlmmj-send.c +++ b/src/mlmmj-send.c @@ -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); diff --git a/src/mlmmj-sub.c b/src/mlmmj-sub.c index 29da25e3..55d0e083 100644 --- a/src/mlmmj-sub.c +++ b/src/mlmmj-sub.c @@ -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); diff --git a/src/mlmmj-unsub.c b/src/mlmmj-unsub.c index e4f598ab..44dff834 100644 --- a/src/mlmmj-unsub.c +++ b/src/mlmmj-unsub.c @@ -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); diff --git a/src/prepstdreply.c b/src/prepstdreply.c index 5368d633..4ce9a51a 100644 --- a/src/prepstdreply.c +++ b/src/prepstdreply.c @@ -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); diff --git a/src/send_digest.c b/src/send_digest.c index a8199a99..b136d39c 100644 --- a/src/send_digest.c +++ b/src/send_digest.c @@ -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(); diff --git a/src/send_list.c b/src/send_list.c index 73648119..b14f2233 100644 --- a/src/send_list.c +++ b/src/send_list.c @@ -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); }