summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2017-04-06 21:01:11 +0200
committerLeah Neukirchen <leah@vuxu.org>2017-04-06 21:02:16 +0200
commit93bfc9cf5f88727eb5d1e2a7f8fce526769fa66d (patch)
tree0bc1cfc91eceee20821eda320098c0ae33636835
parentc6480f4785987aa97db25e7baa5adb394f8007a8 (diff)
downloadmblaze-93bfc9cf5f88727eb5d1e2a7f8fce526769fa66d.tar.gz
mblaze-93bfc9cf5f88727eb5d1e2a7f8fce526769fa66d.tar.xz
mblaze-93bfc9cf5f88727eb5d1e2a7f8fce526769fa66d.zip
mshow: use blaze822_mime2231_parameter for filenames
-rw-r--r--Makefile2
-rw-r--r--mshow.c23
2 files changed, 12 insertions, 13 deletions
diff --git a/Makefile b/Makefile
index 9522d9b..41f2dcf 100644
--- a/Makefile
+++ b/Makefile
@@ -24,7 +24,7 @@ maddr magrep mexport mflag mgenmid mhdr mlist mpick mscan msed mseq mshow msort
   mthread : seq.o slurp.o
 maddr magrep mhdr mpick mscan mshow : rfc2047.o
 magrep mshow : rfc2045.o
-mshow : filter.o safe_u8putstr.c
+mshow : filter.o safe_u8putstr.c rfc2231.c
 msort : mystrverscmp.o
 mmime : slurp.o
 
diff --git a/mshow.c b/mshow.c
index fa72ebc..c26aaca 100644
--- a/mshow.c
+++ b/mshow.c
@@ -146,14 +146,18 @@ tlmimetype(char *ct)
 char *
 mime_filename(struct message *msg)
 {
-	char *filename = 0, *fn, *fne, *v;
+	static char buf[512];
+	char *v;
+	char *filename = 0;
 
 	if ((v = blaze822_hdr(msg, "content-disposition"))) {
-		if (blaze822_mime_parameter(v, "filename", &fn, &fne))
-			filename = strndup(fn, fne-fn);
+		if (blaze822_mime2231_parameter(v, "filename",
+		    buf, sizeof buf, "UTF-8"))
+			filename = buf;
 	} else if ((v = blaze822_hdr(msg, "content-type"))) {
-		if (blaze822_mime_parameter(v, "name", &fn, &fne))
-			filename = strndup(fn, fne-fn);
+		if (blaze822_mime2231_parameter(v, "name",
+		    buf, sizeof buf, "UTF-8"))
+			filename = buf;
 	}
 
 	return filename;
@@ -177,10 +181,8 @@ render_mime(int depth, struct message *msg, char *body, size_t bodylen)
 	for (i = 0; i < depth+1; i++)
 		printf("--- ");
 	printf("%d: %s size=%zd", mimecount, mt, bodylen);
-	if (filename) {
+	if (filename)
 		printf(" name=\"%s\"", filename);
-		free(filename);
-	}
 
 	char *cmd;
 	blaze822_mime_action r = MIME_CONTINUE;
@@ -354,10 +356,8 @@ list_mime(int depth, struct message *msg, char *body, size_t bodylen)
 	char *filename = mime_filename(msg);
 
 	printf("  %*.s%d: %s size=%zd", depth*2, "", ++mimecount, mt, bodylen);
-	if (filename) {
+	if (filename)
 		printf(" name=\"%s\"", filename);
-		free(filename);
-	}
 	printf("\n");
 
 	return MIME_CONTINUE;
@@ -496,7 +496,6 @@ extract_mime(int depth, struct message *msg, char *body, size_t bodylen)
 		}
 	}
 
-	free(filename);
 	return MIME_CONTINUE;
 }