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;
}
/* 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;
}
}
/* 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;
}
}
/* 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;
}
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;
}
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;
}
}
}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;
}
* IN THE SOFTWARE.
*/
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
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;
/* 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.");
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;
/* Should it be stripped? */
if(!delhdrs || !findit(hdrline, delhdrs))
- writen(outfd, unfolded, strlen(unfolded));
+ dprintf(outfd, "%s", unfolded);
myfree(hdrline);
myfree(unfolded);
}
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);
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;
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;
}
#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;
}
#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;
}
{
char *cur, *next;
char newlinebuf[3];
- size_t len;
int i = 1;
for(next = cur = mapstart; next < mapstart + size; next++) {
}
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;
{
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;
#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;
}
#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;
}
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);
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) {
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;
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);
}
}
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);
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;
}
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;
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) {
* 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);
S_IRUSR|S_IWUSR);
myfree(tmpstr);
if(tmpfd >= 0) {
- writen(tmpfd, bounceaddr, strlen(bounceaddr));
+ dprintf(tmpfd, "%s", bounceaddr);
fsync(tmpfd);
}
close(tmpfd);
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);
S_IRUSR|S_IWUSR);
myfree(tmpstr);
if(tmpfd >= 0) {
- writen(tmpfd, replyto,
- strlen(replyto));
+ dprintf(tmpfd, "%s", replyto);
fsync(tmpfd);
}
close(tmpfd);
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);
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);
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);
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);
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);
}
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);
}
/* 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);
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);
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;
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);
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);
}
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");
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);
myfree(listname);
return -1;
}
- myfree(tmp);
if (dumpfd2fd(archivefd, fd) < 0) {
log_error(LOG_ARGS, "Could not write digest part %d "
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);
close(fd);
myfree(boundary);
myfree(listname);
- myfree(tmp);
childpid = fork();
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");
}
}
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);
}