about summary refs log tree commit diff
path: root/mmime.c
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2017-06-19 13:24:49 +0200
committerLeah Neukirchen <leah@vuxu.org>2017-06-19 13:24:49 +0200
commitcc7ab258141f91e49d66cde589f26e2e94d9e516 (patch)
treee341b5865bb7a3572181130f69a59a746e5bb403 /mmime.c
parent9b8ab19a2be4ed190f722b309022ea6472e7ac15 (diff)
downloadmblaze-cc7ab258141f91e49d66cde589f26e2e94d9e516.tar.gz
mblaze-cc7ab258141f91e49d66cde589f26e2e94d9e516.tar.xz
mblaze-cc7ab258141f91e49d66cde589f26e2e94d9e516.zip
mmime: allow setting content-disposition and overriding filename
Diffstat (limited to 'mmime.c')
-rw-r--r--mmime.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/mmime.c b/mmime.c
index 0dbadfb..e8f58da 100644
--- a/mmime.c
+++ b/mmime.c
@@ -115,7 +115,7 @@ basenam(const char *s)
 }
 
 static void
-gen_attachment(const char *filename)
+gen_attachment(const char *filename, char *content_disposition)
 {
 	const char *s = filename;
 	int quote = 0;
@@ -128,12 +128,12 @@ gen_attachment(const char *filename)
 	}
 
 	// filename SHOULD be an atom if possible
-	printf("Content-Disposition: attachment; filename=%s%s%s\n",
+	printf("Content-Disposition: %s; filename=%s%s%s\n", content_disposition,
 	    quote ? "\"" : "", filename, quote ? "\"" : "");
 	return;
 
 rfc2231:
-	printf("Content-Disposition: attachment");
+	printf("Content-Disposition: %s", content_disposition);
 	int i = 0;
 	int d = 0;
 
@@ -162,6 +162,20 @@ gen_file(char *file, char *ct)
 	uint8_t *content;
 	off_t size;
 
+	char *cd = "attachment";
+	char *s = strchr(ct, '#');
+	if (s) {
+		*s = 0;
+		cd = s + 1;
+	}
+
+	const char *filename = basenam(file);
+	s = strchr(file, '>');
+	if (s) {
+		*s = 0;
+		filename = s + 1;
+	}
+
 	int r = slurp(file, (char **)&content, &size);
 	if (r != 0) {
 		fprintf(stderr, "mmime: error attaching file '%s': %s\n",
@@ -191,7 +205,7 @@ gen_file(char *file, char *ct)
 			bithigh++;
 	}
 
-	gen_attachment(basenam(file));
+	gen_attachment(filename, cd);
 
 	if (bitlow == 0 && bithigh == 0 &&
 	    maxlinelen <= 78 && content[size-1] == '\n') {