* mu-cmd, mu-config: add --flags parameter to 'mu move', to change the message flags
This commit is contained in:
42
src/mu-cmd.c
42
src/mu-cmd.c
@ -24,6 +24,9 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#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=<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
|
||||
mu_cmd_mv (MuConfig *opts)
|
||||
{
|
||||
GError *err;
|
||||
gchar *fullpath;
|
||||
MuMsgFlags flags;
|
||||
|
||||
|
||||
if (!opts->params[1] || !opts->params[2]) {
|
||||
g_warning ("usage: mu mv <sourcefile> <targetmaildir>");
|
||||
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);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user