summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacek Masiulaniec <jacekm@cvs.openbsd.org>2009-01-28 12:28:26 +0000
committerJacek Masiulaniec <jacekm@cvs.openbsd.org>2009-01-28 12:28:26 +0000
commitf799ce5ad12dc57f158c92360fd1fcb6e973017a (patch)
tree3c20772d0ed359bfd739da9dc68be88694545228
parent4aa064c23d82c21c2bf638cbb3bdebc5be5bff7a (diff)
">From" escaping and \n appending is not needed for maildir; ok gilles@
-rw-r--r--usr.sbin/smtpd/store.c50
1 files changed, 17 insertions, 33 deletions
diff --git a/usr.sbin/smtpd/store.c b/usr.sbin/smtpd/store.c
index e4c509db67e..7fef9b677d4 100644
--- a/usr.sbin/smtpd/store.c
+++ b/usr.sbin/smtpd/store.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: store.c,v 1.10 2009/01/14 22:41:41 gilles Exp $ */
+/* $OpenBSD: store.c,v 1.11 2009/01/28 12:28:25 jacekm Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -36,11 +36,10 @@
#include "smtpd.h"
-int file_copy(FILE *, FILE *);
-int file_append(FILE *, FILE *);
+int file_copy(FILE *, FILE *, enum action_type);
int
-file_copy(FILE *dest, FILE *src)
+file_copy(FILE *dest, FILE *src, enum action_type type)
{
char *buf, *lbuf;
size_t len;
@@ -61,33 +60,25 @@ file_copy(FILE *dest, FILE *src)
buf = lbuf;
}
- escape = buf;
- while (*escape != '\0' && *escape == '>')
- ++escape;
- if (strncmp("From ", escape, 5) == 0) {
- if (fprintf(dest, ">") != 1)
- return 0;
+ if (type == A_MBOX) {
+ escape = buf;
+ while (*escape == '>')
+ ++escape;
+ if (strncmp("From ", escape, 5) == 0) {
+ if (fprintf(dest, ">") != 1)
+ return 0;
+ }
}
if (fprintf(dest, "%s\n", buf) != (int)len + 1)
return 0;
}
free(lbuf);
- return 1;
-}
-
-int
-file_append(FILE *dest, FILE *src)
-{
- struct stat sb;
- size_t srcsz;
-
- if (fstat(fileno(src), &sb) == -1)
- return 0;
- srcsz = sb.st_size;
- if (! file_copy(dest, src))
- return 0;
+ if (type == A_MBOX) {
+ if (fprintf(dest, "\n") != 1)
+ return 0;
+ }
return 1;
}
@@ -233,10 +224,7 @@ store_write_daemon(struct batch *batchp, struct message *messagep)
if (fprintf(mboxfp, "Below is a copy of the original message:\n\n") == -1)
goto bad;
- if (! file_append(mboxfp, messagefp))
- goto bad;
-
- if (fprintf(mboxfp, "\n") == -1)
+ if (! file_copy(mboxfp, messagefp, messagep->recipient.rule.r_action))
goto bad;
fflush(mboxfp);
@@ -272,13 +260,9 @@ store_write_message(struct batch *batchp, struct message *messagep)
if (! store_write_header(batchp, messagep, mboxfp))
goto bad;
- if (! file_append(mboxfp, messagefp))
- goto bad;
-
- if (fprintf(mboxfp, "\n") == -1)
+ if (! file_copy(mboxfp, messagefp, messagep->recipient.rule.r_action))
goto bad;
-
fflush(mboxfp);
fsync(fileno(mboxfp));
fclose(mboxfp);