From 2c1f3dafbdda1da299e1709d46e2866762d108d3 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Tue, 2 Aug 2011 08:14:19 +0300 Subject: [PATCH] * mu-cmd, mu-config: add --flags parameter to 'mu move', to change the message flags --- src/mu-cmd.c | 42 +++++++++++++++++++++++++++++++++--------- src/mu-config.c | 22 ++++++++++++++++++++-- src/mu-config.h | 4 ++++ 3 files changed, 57 insertions(+), 11 deletions(-) diff --git a/src/mu-cmd.c b/src/mu-cmd.c index d0481a10..cb530905 100644 --- a/src/mu-cmd.c +++ b/src/mu-cmd.c @@ -24,6 +24,9 @@ #include #include +#include +#include +#include #include "mu-msg.h" #include "mu-msg-part.h" @@ -34,6 +37,7 @@ #include "mu-maildir.h" #include "mu-contacts.h" #include "mu-runtime.h" +#include "mu-msg-flags.h" #define VIEW_TERMINATOR '\f' /* form-feed */ @@ -274,33 +278,53 @@ mu_cmd_mkdir (MuConfig *opts) } +static gboolean +mv_check_params (MuConfig *opts, MuMsgFlags *flags) +{ + if (!opts->params[1] || !opts->params[2]) { + g_warning ("usage: mu mv [--flags=] " + ""); + return FALSE; + } + + if (!opts->flagstr) + *flags = MU_MSG_FLAG_NONE; + else { + *flags = mu_msg_flags_from_str (opts->flagstr); + if (*flags == MU_MSG_FLAG_NONE) { + g_warning ("error in flags"); + return FALSE; + } + } + + return TRUE; +} + + MuExitCode mu_cmd_mv (MuConfig *opts) { GError *err; gchar *fullpath; + MuMsgFlags flags; - - if (!opts->params[1] || !opts->params[2]) { - g_warning ("usage: mu mv "); + if (!mv_check_params (opts, &flags)) return MU_EXITCODE_ERROR; - } - + err = NULL; /* special case: /dev/null */ - if (strcmp (opts->params[2], "/dev/null") == 0) { + if (g_strcmp0 (opts->params[2], "/dev/null") == 0) { if (unlink (opts->params[1]) != 0) { g_warning ("unlink failed: %s", strerror (errno)); return MU_EXITCODE_ERROR; } else return MU_EXITCODE_OK; } - - + fullpath = mu_msg_file_move_to_maildir (opts->params[1], opts->params[2], - &err); + flags, &err); if (!fullpath) { if (err) { g_warning ("move failed: %s", err->message); diff --git a/src/mu-config.c b/src/mu-config.c index f6d04651..f88c1446 100644 --- a/src/mu-config.c +++ b/src/mu-config.c @@ -312,6 +312,24 @@ config_options_group_view (MuConfig *opts) } +static GOptionGroup * +config_options_group_mv (MuConfig *opts) +{ + GOptionGroup *og; + GOptionEntry entries[] = { + {"flags", 0, 0, G_OPTION_ARG_STRING, &opts->flagstr, + "flags to set for the target (DFNPRST)", NULL}, + {NULL, 0, 0, 0, NULL, NULL, NULL} + }; + + og = g_option_group_new ("mv", "options for the 'mv' command", + "", NULL, NULL); + g_option_group_add_entries(og, entries); + + return og; +} + + static GOptionGroup* config_options_group_extract (MuConfig *opts) @@ -407,8 +425,8 @@ add_context_group (GOptionContext *context, MuConfig *opts) case MU_CONFIG_CMD_EXTRACT: group = config_options_group_extract (opts); break; - case MU_CONFIG_CMD_MV: /* no options for this one yet */ - /* group = config_options_group_mv (opts); */ + case MU_CONFIG_CMD_MV: + group = config_options_group_mv (opts); break; case MU_CONFIG_CMD_CFIND: group = config_options_group_cfind (opts); diff --git a/src/mu-config.h b/src/mu-config.h index 4ce6498b..a013a4f5 100644 --- a/src/mu-config.h +++ b/src/mu-config.h @@ -122,6 +122,10 @@ struct _MuConfig { char *exec; /* command to execute on the * files for the matched * messages */ + + /* options for mv */ + char *flagstr; /* message flags to set for + * the target */ /* options for view */ gboolean terminator; /* add separator \f between