* mu-cmd, mu-config: add --flags parameter to 'mu move', to change the message flags

This commit is contained in:
Dirk-Jan C. Binnema
2011-08-02 08:14:19 +03:00
parent d203c26591
commit 2c1f3dafbd
3 changed files with 57 additions and 11 deletions

View File

@ -24,6 +24,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include "mu-msg.h" #include "mu-msg.h"
#include "mu-msg-part.h" #include "mu-msg-part.h"
@ -34,6 +37,7 @@
#include "mu-maildir.h" #include "mu-maildir.h"
#include "mu-contacts.h" #include "mu-contacts.h"
#include "mu-runtime.h" #include "mu-runtime.h"
#include "mu-msg-flags.h"
#define VIEW_TERMINATOR '\f' /* form-feed */ #define VIEW_TERMINATOR '\f' /* form-feed */
@ -274,23 +278,44 @@ 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=<flags>] <sourcefile> "
"<targetmaildir>");
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 MuExitCode
mu_cmd_mv (MuConfig *opts) mu_cmd_mv (MuConfig *opts)
{ {
GError *err; GError *err;
gchar *fullpath; gchar *fullpath;
MuMsgFlags flags;
if (!mv_check_params (opts, &flags))
if (!opts->params[1] || !opts->params[2]) {
g_warning ("usage: mu mv <sourcefile> <targetmaildir>");
return MU_EXITCODE_ERROR; return MU_EXITCODE_ERROR;
}
err = NULL; err = NULL;
/* special case: /dev/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) { if (unlink (opts->params[1]) != 0) {
g_warning ("unlink failed: %s", strerror (errno)); g_warning ("unlink failed: %s", strerror (errno));
return MU_EXITCODE_ERROR; return MU_EXITCODE_ERROR;
@ -298,9 +323,8 @@ mu_cmd_mv (MuConfig *opts)
return MU_EXITCODE_OK; return MU_EXITCODE_OK;
} }
fullpath = mu_msg_file_move_to_maildir (opts->params[1], opts->params[2], fullpath = mu_msg_file_move_to_maildir (opts->params[1], opts->params[2],
&err); flags, &err);
if (!fullpath) { if (!fullpath) {
if (err) { if (err) {
g_warning ("move failed: %s", err->message); g_warning ("move failed: %s", err->message);

View File

@ -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* static GOptionGroup*
config_options_group_extract (MuConfig *opts) config_options_group_extract (MuConfig *opts)
@ -407,8 +425,8 @@ add_context_group (GOptionContext *context, MuConfig *opts)
case MU_CONFIG_CMD_EXTRACT: case MU_CONFIG_CMD_EXTRACT:
group = config_options_group_extract (opts); group = config_options_group_extract (opts);
break; break;
case MU_CONFIG_CMD_MV: /* no options for this one yet */ case MU_CONFIG_CMD_MV:
/* group = config_options_group_mv (opts); */ group = config_options_group_mv (opts);
break; break;
case MU_CONFIG_CMD_CFIND: case MU_CONFIG_CMD_CFIND:
group = config_options_group_cfind (opts); group = config_options_group_cfind (opts);

View File

@ -123,6 +123,10 @@ struct _MuConfig {
* files for the matched * files for the matched
* messages */ * messages */
/* options for mv */
char *flagstr; /* message flags to set for
* the target */
/* options for view */ /* options for view */
gboolean terminator; /* add separator \f between gboolean terminator; /* add separator \f between
* multiple messages in mu * multiple messages in mu