mu: add --uncooked option for mu extract

To avoid replacing spaces with dashes

Fixes #2434.
This commit is contained in:
Dirk-Jan C. Binnema 2023-02-23 20:23:25 +02:00
parent 5c037f7579
commit ff08731298
4 changed files with 14 additions and 1 deletions

View File

@ -51,6 +51,11 @@ directory.
overwrite existing files with the same name; by default overwriting is not
allowed.
** -u,--uncooked
by default, ~mu~ transforms the attachment filenames a bit (such as by replacing
spaces by dashes); with this option, leave that to the minimum for creating
a legal filename in the target directory.
** --play
Try to 'play' (open) the attachment with the default application for the
particular file type. On MacOS, this uses the *open* program, on other platforms

View File

@ -33,8 +33,12 @@ save_part(const Message::Part& part, size_t idx, const Options& opts)
const auto tdir{opts.extract.targetdir};
return tdir.empty() ? tdir : tdir + G_DIR_SEPARATOR_S;
});
/* 'uncooked' isn't really _raw_; it means only doing some _minimal_
* cooking */
const auto path{targetdir +
part.cooked_filename().value_or(format("part-%zu", idx))};
part.cooked_filename(opts.extract.uncooked)
.value_or(format("part-%zu", idx))};
if (auto&& res{part.to_file(path, opts.extract.overwrite)}; !res)
return Err(res.error());

View File

@ -222,6 +222,8 @@ sub_extract(CLI::App& sub, Options& opts)
sub.add_option("message", opts.extract.message,
"Path to message file")->required()
->type_name("<message-path>");
sub.add_flag("--uncooked,-u", opts.extract.uncooked,
"Avoid massaging extracted file-names");
sub.add_option("filename-rx", opts.extract.filename_rx,
"Regular expression for files to save")
->type_name("<filename-rx>")

View File

@ -126,6 +126,8 @@ struct Options {
bool overwrite; /**< overwrite same-named files */
bool play; /**< try to 'play' attachment */
std::string filename_rx; /**< Filename rx to save */
bool uncooked{}; /**< Whether to avoid massaging
* output filename */
} extract;
/*