about summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--archive.h4
-rw-r--r--mbox.c33
2 files changed, 19 insertions, 18 deletions
diff --git a/archive.h b/archive.h
index 820ca37..8fd9693 100644
--- a/archive.h
+++ b/archive.h
@@ -145,8 +145,8 @@ char *templateURL(const char *template, const struct Variable vars[]);
 	"MIME-Version Content-Type Content-Disposition Content-Transfer-Encoding"
 
 int mboxFrom(FILE *file);
-int mboxHeader(FILE *file, char *header);
-int mboxBody(FILE *file, char *body);
+int mboxHeader(FILE *file, const char *header);
+int mboxBody(FILE *file, const char *body);
 
 int htmlMessageHead(FILE *file, const struct Envelope *envelope);
 int htmlMessageTail(FILE *file);
diff --git a/mbox.c b/mbox.c
index f8684de..3412129 100644
--- a/mbox.c
+++ b/mbox.c
@@ -27,28 +27,29 @@ int mboxFrom(FILE *file) {
 	return (n < 0 ? n : 0);
 }
 
-int mboxHeader(FILE *file, char *header) {
-	for (char *crlf; (crlf = strstr(header, "\r\n")); header = &crlf[2]) {
-		*crlf = '\0';
-		int n = fprintf(file, "%s\n", header);
-		if (n < 0) return n;
+int mboxHeader(FILE *file, const char *header) {
+	for (const char *crlf; (crlf = strstr(header, "\r\n")); header = &crlf[2]) {
+		if (crlf - header) {
+			size_t n = fwrite(header, crlf - header, 1, file);
+			if (!n) return -1;
+		}
+		if (fprintf(file, "\n") < 0) return -1;
 	}
 	return 0;
 }
 
-int mboxBody(FILE *file, char *body) {
-	int n;
-	for (char *crlf; (crlf = strstr(body, "\r\n")); body = &crlf[2]) {
-		*crlf = '\0';
-		char *from = body;
+int mboxBody(FILE *file, const char *body) {
+	for (const char *crlf; (crlf = strstr(body, "\r\n")); body = &crlf[2]) {
+		const char *from = body;
 		while (*from == '>') from++;
 		if (!strncmp(from, "From ", 5)) {
-			n = fprintf(file, ">%s\n", body);
-		} else {
-			n = fprintf(file, "%s\n", body);
+			if (fprintf(file, ">") < 0) return -1;
+		}
+		if (crlf - body) {
+			size_t n = fwrite(body, crlf - body, 1, file);
+			if (!n) return -1;
 		}
-		if (n < 0) return n;
+		if (fprintf(file, "\n") < 0) return -1;
 	}
-	n = fprintf(file, "\n");
-	return (n < 0 ? n : 0);
+	return (fprintf(file, "\n" ) < 0 ? -1 : 0);
 }
-07-25Add support for mime type registration and lookupLars Hjemli 2009-07-25cgit.h: keep config flags sortedLars Hjemli 2009-07-25cgitrc.5.txt: document 'embedded' and 'noheader'Lars Hjemli 2009-07-25Add support for 'noheader' optionLars Hjemli 2009-07-25cgitrc.5.txt: document 'head-include'Lars Hjemli 2009-07-25ui-blob: return 'application/octet-stream' for binary blobsLars Hjemli 2009-07-25ui-plain: Return 'application/octet-stream' for binary files.Remko Tronçon 2009-06-11use cgit_httpscheme() for atom feedDiego Ongaro 2009-06-11add cgit_httpscheme() -> http:// or https://Diego Ongaro 2009-06-07Return http statuscode 404 on unknown branchLars Hjemli 2009-06-07Add head-include configuration option.Mark Lodato 2009-03-15CGIT 0.8.2.1Lars Hjemli 2009-03-15Fix doc-related glitches in Makefile and .gitignoreLars Hjemli 2009-03-15ui-snapshot: avoid segfault when no filename is specifiedLars Hjemli 2009-03-15fix segfault when displaying empty blobsEric Wong 2009-02-19Add support for HEAD requestsLars Hjemli 2009-02-19Add support for ETag in 'plain' viewLars Hjemli 2009-02-12ui-tree: escape ascii-text properly in hexdump viewLars Hjemli 2009-02-12Makefile: add doc-related targetsLars Hjemli