[PATCH 4/4] reformime: scan for "name" in addition (and in preference) to "filename".
Joshua Judson Rosen
jrosen at harvestai.com
Thu Oct 2 18:12:07 UTC 2014
Signed-off-by: Joshua Judson Rosen <jrosen at harvestai.com>
---
mailutils/reformime.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/mailutils/reformime.c b/mailutils/reformime.c
index 0f5d768..303beb7 100644
--- a/mailutils/reformime.c
+++ b/mailutils/reformime.c
@@ -145,6 +145,8 @@ static int parse(const char *boundary, char **argv)
/* Compose target filename */
char *filename = (char *)find_token(tokens, "filename", NULL);
+ char *name = (char *)find_token(tokens, "name", NULL);
+
if (!filename)
filename = xasprintf(uniq, monotonic_us());
else
@@ -164,6 +166,7 @@ static int parse(const char *boundary, char **argv)
xsetenv("CHARSET", charset);
xsetenv("ENCODING", encoding);
xsetenv("FILENAME", filename);
+ xsetenv("NAME", name);
BB_EXECVP_or_die(argv);
}
/* parent will write to fd[1] */
@@ -172,6 +175,16 @@ static int parse(const char *boundary, char **argv)
signal(SIGPIPE, SIG_IGN);
} else {
/* write to file */
+ if (name) {
+ /* Prefer `name' over `filename', because `name' is
+ the useful part that we get when processing form-data;
+ `filename' is what the file was originally called
+ by the user.
+ */
+ free(filename);
+ filename = bb_get_last_path_component_strip(xstrdup(name));
+ }
+
char *fname = xasprintf("%s%s", *argv, filename);
fp = xfopen_for_write(fname);
free(fname);
--
1.7.10.4
More information about the busybox
mailing list