* remove the 'rm' command

This commit is contained in:
djcb 2011-10-25 08:42:21 +03:00
parent 991cc06f20
commit fee3096d54
5 changed files with 2 additions and 253 deletions

View File

@ -25,7 +25,6 @@ dist_man_MANS = \
mu-index.1 \
mu-mkdir.1 \
mu-view.1 \
mu-mv.1 \
mu-add.1 \
mu-remove.1 \
mu-server.1 \

View File

@ -1,134 +0,0 @@
.TH MU MV 1 "August 2011" "User Manuals"
.SH NAME
mu mv\- move a message file to a Maildir
.SH SYNOPSIS
.B mu mv [--flags=<flags>] [--printtarget] <source-path> [<target-maildir>]
.SH DESCRIPTION
\fBmu mv\fR is the \fBmu\fR sub-command for moving mail files to new
directories. It does \fBnot\fR use the mu database. The command is
deliberately limited and tries hard to maintain the Maildir-integrity and to
minimize chance of accidents
The \fIsource-path\fR must be a full, absolute path to the message you want to
move, while the \fItarget-maildir\fR is the path to the maildir, but
\fBwithout\fR the 'cur' or 'new' part - that part will be constructed from the
source message, so that message that live in 'new' will also be in 'new' in
the target, and the same for 'cur'. If needed, consult the \fBmaildir(5)\fR
documentation for details about 'cur' and 'new'.
As a special case, when \fI/dev/null\fR is specified as the target directory,
the mail file will be unlinked (deleted).
Note, unlike the UNIX \fImv\fR command, \fImu mv\fR takes precisely one source
message parameter. It's recommended not to use wildcards on the shell, as the
result may be unexpected.
Also note, \fBmu mv\fR only updates the file system; it does \fBnot\fR update
the database. To update the database, there is \fBmu index(1)\fR or \fBmu add\fR
and \fBmu remove\fR.
.SH OPTIONS
.TP
\fB\-\-flags\fR=\fI<flags>\fR
using the this option, you can change the file flags of the target file. If
you change the 'N' (new) flag, this will also change the exact target
directory ('new' vs 'cur').
The flags is a sequence of characters from the set D (draft), F (flagged), N
(new), P (passed), R (replied), S (seen) and T (trashed). Note, the
flags-parameter is case-sensitive. Any other characters will be silently
ignored.
The \fB\-\-flags\fR also has a second, 'delta', syntax. In this syntax, each
of the flag characters is prefixed with either '+' or '-', which means that
the corresponding flag will be added or removed. Using this syntax, you can
change individual flags, without changing all of them.
.TP
\fB\-\-print-target\fR
return the target path on standard output upon succesful completion of the
move (with or without a succesful database update).
.TP
\fB\-\-ignore-dups\fR
silently ignore the case where the source file is the same as the target.
.SH EXAMPLE
To move a message \fI/home/jimbo/Maildir/scuba/cur/123123123:2,S\fR to
\fI/home/jimbo/Maildir/archive\fR, you can use:
.nf
mu mv /home/jimbo/Maildir/scuba/cur/123123123:2,S /home/jimbo/Maildir/archive
.fi
This will move the message to the new path:
\fI/home/jimbo/Maildir/archive/cur/123123123:2,S\fR.
To remove a message \fI/home/fred/Maildir/trash/cur/123123123:2,S\fR, you
could do:
.nf
mu mv /home/fred/Maildir/trash/cur/123123123:2,S /dev/null
.fi
Obviously, you could also simply use \fBrm\fR in this case.
To mark a message as no longer new and 'Seen', and update the database
afterwards, you could do:
.nf
mu mv /home/roger/Maildir/inbox/new/123123123 /home/roger/Maildir/inbox/ --flags=S
.fi
In this case, as we are not moving the message to a diffent maildir, we can
leave off the maildir-argument; so the following is equivalent:
.nf
mu mv /home/roger/Maildir/inbox/new/123123123 --flags=S
.fi
Finally, using the 'delta'-syntax, you can set the 'seen'-flag
and 'replied'-flag while removing the 'new' flag with:
.nf
mu mv /home/billy/Maildir/inbox/new/12aa34343 --flags=+S+R-N
.fi
which would give us a new file:
\fI/home/billy/Maildir/inbox/cur/12aa34343:2,SR\fR
.SH LIMITATIONS
Both source-path and target-directory must be on the same disk partition,
except when the target-directory is \fI/dev/null\fR.
.SH RETURN VALUE
\fBmu mv\fR returns 0 upon success, and some other value when an error
occurs. See \fBmu(1)\fR for a list.
.SH BUGS
Please report bugs if you find them:
.BR http://code.google.com/p/mu0/issues/list
.SH AUTHOR
Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
.SH "SEE ALSO"
.BR maildir(5)
.BR mu(1)
.BR mu-index(1)
.BR mu-add(1)
.BR mu-remove(1)
.BR chmod(1)

View File

@ -277,86 +277,6 @@ mu_cmd_mkdir (MuConfig *opts, GError **err)
}
static gboolean
mv_check_params (MuConfig *opts, MuFlags *flags, GError **err)
{
if (!opts->params[1]) {
g_set_error (err, 0, MU_ERROR_IN_PARAMETERS,
"missing source mailfile");
return FALSE;
}
/* FIXME: check for invalid flags */
if (!opts->flagstr)
*flags = MU_FLAG_INVALID; /* ie., ignore flags */
else {
/* if there's a '+' or '-' sign in the string, it must
* be a flag-delta */
if (strstr (opts->flagstr, "+") || strstr (opts->flagstr, "-")) {
MuFlags oldflags;
oldflags = mu_maildir_get_flags_from_path (opts->params[1]);
*flags = mu_flags_from_str_delta (opts->flagstr,
oldflags,
MU_FLAG_TYPE_MAILDIR|
MU_FLAG_TYPE_MAILFILE);
} else
*flags = mu_flags_from_str (opts->flagstr,
MU_FLAG_TYPE_MAILDIR |
MU_FLAG_TYPE_MAILFILE);
}
return TRUE;
}
static MuError
cmd_mv_dev_null (MuConfig *opts)
{
if (unlink (opts->params[1]) != 0) {
g_warning ("unlink failed: %s", strerror (errno));
return MU_ERROR_FILE;
}
if (opts->print_target)
g_print ("/dev/null\n"); /* /dev/null */
return MU_OK;
}
MuError
mu_cmd_mv (MuConfig *opts, GError **err)
{
gchar *fullpath;
MuFlags flags;
if (!mv_check_params (opts, &flags, err)) {
if (MU_G_ERROR_CODE(err) == MU_ERROR_IN_PARAMETERS)
g_message ("usage: mu mv [--flags=<flags>] <mailfile> "
"[<maildir>]");
return MU_G_ERROR_CODE(err);
}
/* special case: /dev/null */
if (g_strcmp0 (opts->params[2], "/dev/null") == 0)
return cmd_mv_dev_null (opts);
err = NULL;
fullpath = mu_maildir_move_message (opts->params[1], opts->params[2],
flags, opts->ignore_dups, err);
if (!fullpath)
return MU_G_ERROR_CODE(err);
else {
if (opts->print_target)
g_print ("%s\n", fullpath);
return MU_OK;
}
g_free (fullpath);
return MU_OK;
}
static gboolean
check_file_okay (const char *path, gboolean cmd_add)
@ -471,7 +391,7 @@ show_usage (void)
{
g_message ("usage: mu command [options] [parameters]");
g_message ("where command is one of index, find, cfind, view, mkdir, cleanup, "
"extract, mv, add, remove or server");
"extract, add, remove or server");
g_message ("see the mu, mu-<command> or mu-easy manpages for "
"more information");
}
@ -539,7 +459,6 @@ mu_cmd_execute (MuConfig *opts, GError **err)
switch (opts->cmd) {
case MU_CONFIG_CMD_CFIND: return mu_cmd_cfind (opts, err);
case MU_CONFIG_CMD_MKDIR: return mu_cmd_mkdir (opts, err);
case MU_CONFIG_CMD_MV: return mu_cmd_mv (opts, err);
case MU_CONFIG_CMD_VIEW: return mu_cmd_view (opts, err);
case MU_CONFIG_CMD_EXTRACT: return mu_cmd_extract (opts, err);

View File

@ -308,30 +308,6 @@ 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},
{"ignore-dups", 0, 0, G_OPTION_ARG_NONE, &opts->ignore_dups,
"whether to silently ignore the source = target case",
NULL},
{"print-target", 0, 0, G_OPTION_ARG_NONE, &opts->print_target,
"whether to print the target path upon succesful completion",
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)
@ -398,7 +374,6 @@ parse_cmd (MuConfig *opts, int *argcp, char ***argvp)
{ "find", MU_CONFIG_CMD_FIND },
{ "index", MU_CONFIG_CMD_INDEX },
{ "mkdir", MU_CONFIG_CMD_MKDIR },
{ "mv", MU_CONFIG_CMD_MV },
{ "view", MU_CONFIG_CMD_VIEW },
{ "add", MU_CONFIG_CMD_ADD },
{ "remove", MU_CONFIG_CMD_REMOVE },
@ -441,8 +416,6 @@ add_context_group (GOptionContext *context, MuConfig *opts)
group = config_options_group_mkdir (opts); break;
case MU_CONFIG_CMD_EXTRACT:
group = config_options_group_extract (opts); break;
case MU_CONFIG_CMD_MV:
group = config_options_group_mv (opts); break;
case MU_CONFIG_CMD_CFIND:
group = config_options_group_cfind (opts); break;
case MU_CONFIG_CMD_VIEW:

View File

@ -67,7 +67,6 @@ enum _MuConfigCmd {
MU_CONFIG_CMD_VIEW,
MU_CONFIG_CMD_EXTRACT,
MU_CONFIG_CMD_CFIND,
MU_CONFIG_CMD_MV,
MU_CONFIG_CMD_ADD,
MU_CONFIG_CMD_REMOVE,
MU_CONFIG_CMD_SERVER,
@ -125,14 +124,7 @@ struct _MuConfig {
* messages */
gboolean include_unreadable; /* don't ignore messages
* without a disk file */
/* options for mv */
char *flagstr; /* message flags to set for
* the target */
gboolean print_target; /* should be print the
* target file path on
* stdout */
gboolean ignore_dups; /* silently ignore the
* src=target case */
/* options for view */
gboolean terminator; /* add separator \f between
* multiple messages in mu