aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2017-04-06 22:31:27 +0200
committerLeah Neukirchen <leah@vuxu.org>2017-04-06 22:31:27 +0200
commitbbbde2616b215413b4011ca473eb1591bf8c9567 (patch)
tree237eac7076e9096c3ba77d37c754d4c6ade47af4
parentf8a305f4413d6910ae999daf61121c1f9713a1ec (diff)
downloadmblaze-bbbde2616b215413b4011ca473eb1591bf8c9567.tar.gz
mshow: safely print filenames
-rw-r--r--mshow.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/mshow.c b/mshow.c
index c26aaca..b526b62 100644
--- a/mshow.c
+++ b/mshow.c
@@ -165,6 +165,16 @@ mime_filename(struct message *msg)
static void choose_alternative(struct message *msg, int depth);
+void
+print_filename(char *filename)
+{
+ if (filename) {
+ printf(" name=\"");
+ safe_u8putstr(filename, strlen(filename), stdout);
+ printf("\"");
+ }
+}
+
blaze822_mime_action
render_mime(int depth, struct message *msg, char *body, size_t bodylen)
{
@@ -181,8 +191,7 @@ 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)
- printf(" name=\"%s\"", filename);
+ print_filename(filename);
char *cmd;
blaze822_mime_action r = MIME_CONTINUE;
@@ -356,8 +365,7 @@ 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)
- printf(" name=\"%s\"", filename);
+ print_filename(filename);
printf("\n");
return MIME_CONTINUE;
@@ -435,7 +443,8 @@ extract_mime(int depth, struct message *msg, char *body, size_t bodylen)
fwrite(body, 1, bodylen, stdout);
} else { // extract all named attachments
if (filename) {
- printf("%s\n", filename);
+ safe_u8putstr(filename, strlen(filename), stdout);
+ printf("\n");
writefile(filename, body, bodylen);
}
}
@@ -489,7 +498,8 @@ extract_mime(int depth, struct message *msg, char *body, size_t bodylen)
fwrite(body, 1, bodylen, stdout);
}
} else {
- printf("%s\n", filename);
+ safe_u8putstr(filename, strlen(filename), stdout);
+ printf("\n");
writefile(filename, body, bodylen);
}
}