about summary refs log tree commit diff
path: root/mshow.c
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2016-07-29 15:15:57 +0200
committerChristian Neukirchen <chneukirchen@gmail.com>2016-07-29 15:15:57 +0200
commitbe2ca1ba42029b80cffff78afee77abf9831131a (patch)
treebaa0e210bac2a1fbc863bf8ee2c45b70eb0e6c93 /mshow.c
parent5d1266b38f35916d3ce48cc07052c459c802a7d3 (diff)
downloadmblaze-be2ca1ba42029b80cffff78afee77abf9831131a.tar.gz
mblaze-be2ca1ba42029b80cffff78afee77abf9831131a.tar.xz
mblaze-be2ca1ba42029b80cffff78afee77abf9831131a.zip
mshow: actually filter the parts
Diffstat (limited to 'mshow.c')
-rw-r--r--mshow.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/mshow.c b/mshow.c
index 9c1be33..4d4e217 100644
--- a/mshow.c
+++ b/mshow.c
@@ -149,6 +149,8 @@ typedef enum {
 
 typedef mime_action (*mime_callback)(int, struct message *, char *, size_t);
 
+mime_action walk_mime(struct message *msg, int depth, mime_callback visit);
+
 char *
 mime_filename(struct message *msg)
 {
@@ -199,19 +201,29 @@ render_mime(int depth, struct message *msg, char *body, size_t bodylen)
 			setenv("PIPE_CHARSET", charset, 1);
 			free(charset);
 		}
-		printf(" filter=\"%s\" ---\n", cmd);
-		FILE *p;
-		fflush(stdout);
-		p = popen(cmd, "w");
-		if (!p) {
-			perror("popen");
-			goto nofilter;
-		}
-		fwrite(body, 1, bodylen, p);
-		if (pclose(p) != 0) {
-			perror("pclose");
+		setenv("PIPE_CONTENTTYPE", ct, 1);
+
+		char *output;
+		size_t outlen;
+		int e = filter(body, bodylen, cmd, &output, &outlen);
+
+		if (e == 0) {
+			printf(" render=\"%s\" ---\n", cmd);
+			print_ascii(output, outlen);
+		} else if (e == 64) { // decode output again
+			printf(" filter=\"%s\" ---\n", cmd);
+			struct message *imsg = blaze822_mem(output, outlen);
+			if (imsg)
+				walk_mime(imsg, depth+1, render_mime);
+			blaze822_free(imsg);
+		} else {
+			printf(" filter=\"%s\" FAILED status=%d", cmd, e);
+			free(output);
 			goto nofilter;
 		}
+
+		free(output);
+
 		r = MIME_PRUNE;
 	} else {
 nofilter: