* mu-cmd-extract.c: implement color output
This commit is contained in:
@ -47,10 +47,11 @@ save_part (MuMsg *msg, const char *targetdir, guint partidx, gboolean overwrite,
|
|||||||
|
|
||||||
err = NULL;
|
err = NULL;
|
||||||
if (!mu_msg_part_save (msg, filepath, partidx, overwrite, FALSE, &err)) {
|
if (!mu_msg_part_save (msg, filepath, partidx, overwrite, FALSE, &err)) {
|
||||||
g_warning ("failed to save MIME-part: %s",
|
if (err) {
|
||||||
err&&err->message ? err->message : "error");
|
g_warning ("failed to save MIME-part: %s",
|
||||||
if (err)
|
err->message);
|
||||||
g_error_free (err);
|
g_error_free (err);
|
||||||
|
}
|
||||||
g_free (filepath);
|
g_free (filepath);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -118,7 +119,7 @@ anchored_regex (const char* pattern)
|
|||||||
|
|
||||||
if (!rx) {
|
if (!rx) {
|
||||||
g_warning ("error in regular expression '%s': %s",
|
g_warning ("error in regular expression '%s': %s",
|
||||||
pattern, err->message);
|
pattern, err->message ? err->message : "error");
|
||||||
g_error_free (err);
|
g_error_free (err);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -264,8 +265,10 @@ save_parts (const char *path, const char *filename, MuConfig *opts)
|
|||||||
err = NULL;
|
err = NULL;
|
||||||
msg = mu_msg_new_from_file (path, NULL, &err);
|
msg = mu_msg_new_from_file (path, NULL, &err);
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
g_warning ("error: %s", err->message);
|
if (err) {
|
||||||
g_error_free (err);
|
g_warning ("error: %s", err->message);
|
||||||
|
g_error_free (err);
|
||||||
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,14 +298,27 @@ save_parts (const char *path, const char *filename, MuConfig *opts)
|
|||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
each_part_show (MuMsg *msg, MuMsgPart *part, gpointer user_data)
|
each_part_show (MuMsg *msg, MuMsgPart *part, gboolean color)
|
||||||
{
|
{
|
||||||
g_print (" %u %s %s/%s [%s]\n",
|
g_print (" %u %s%s%s %s%s/%s%s [%s%s%s]\n",
|
||||||
part->index,
|
part->index,
|
||||||
|
|
||||||
|
/* filename */
|
||||||
|
color && part->file_name ? MU_COLOR_GREEN : "",
|
||||||
part->file_name ? part->file_name : "<none>",
|
part->file_name ? part->file_name : "<none>",
|
||||||
|
color ? MU_COLOR_DEFAULT : "",
|
||||||
|
|
||||||
|
/* content type */
|
||||||
|
color ? MU_COLOR_BLUE : "",
|
||||||
part->type ? part->type : "",
|
part->type ? part->type : "",
|
||||||
part->subtype ? part->subtype : "",
|
part->subtype ? part->subtype : "",
|
||||||
part->disposition ? part->disposition : "<none>");
|
color ? MU_COLOR_DEFAULT : "",
|
||||||
|
|
||||||
|
/* disposition */
|
||||||
|
color && part->disposition ? MU_COLOR_MAGENTA : "",
|
||||||
|
part->disposition ? part->disposition : "<none>",
|
||||||
|
color ? MU_COLOR_DEFAULT : ""
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -315,45 +331,50 @@ show_parts (const char* path, MuConfig *opts)
|
|||||||
err = NULL;
|
err = NULL;
|
||||||
msg = mu_msg_new_from_file (path, NULL, &err);
|
msg = mu_msg_new_from_file (path, NULL, &err);
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
g_warning ("error: %s", err->message);
|
if (err) {
|
||||||
g_error_free (err);
|
g_warning ("error: %s", err->message);
|
||||||
|
g_error_free (err);
|
||||||
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_print ("MIME-parts in this message:\n");
|
g_print ("MIME-parts in this message:\n");
|
||||||
mu_msg_part_foreach (msg, each_part_show, NULL);
|
|
||||||
|
mu_msg_part_foreach
|
||||||
|
(msg,(MuMsgPartForeachFunc)each_part_show,
|
||||||
|
GUINT_TO_POINTER(opts->color));
|
||||||
|
|
||||||
mu_msg_unref (msg);
|
mu_msg_unref (msg);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
check_params (MuConfig *opts)
|
check_params (MuConfig *opts)
|
||||||
{
|
{
|
||||||
if (!opts->params[1] || (opts->params[2] && opts->params[3])) {
|
guint param_num;
|
||||||
g_warning ("usage: mu extract [options] <file> [<pattern>]");
|
|
||||||
return MU_EXITCODE_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
param_num = mu_config_param_num(opts);
|
||||||
|
|
||||||
if (opts->params[2] && (opts->save_attachments || opts->save_all)) {
|
if (param_num < 2) {
|
||||||
g_warning ("--save-attachments --save-all don't accept "
|
g_warning ("usage: mu extract [options] <file> [<pattern>]");
|
||||||
"a filename");
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (opts->save_attachments || opts->save_all)
|
||||||
|
if (opts->parts || param_num == 3) {
|
||||||
|
g_warning ("--save-attachments --save-all don't accept "
|
||||||
|
"a filename pattern or --parts");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (opts->save_attachments && opts->save_all) {
|
if (opts->save_attachments && opts->save_all) {
|
||||||
g_warning ("only one of --save-attachments and"
|
g_warning ("only one of --save-attachments and"
|
||||||
" --save-all is allowed");
|
" --save-all is allowed");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((opts->save_attachments || opts->save_all) && opts->parts) {
|
|
||||||
g_warning ("with --save-attachments/--save-all, "
|
|
||||||
"parts should not be specified");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user