mu: add 'tickle' command, for renaming messages

The new command 'tickle' renames message files in place, which can be
useful for 3rd-party tools.
This commit is contained in:
djcb
2017-01-14 13:09:17 +02:00
parent f91969e0b7
commit 786e7c3d1f
6 changed files with 76 additions and 0 deletions

View File

@ -412,6 +412,33 @@ mu_cmd_remove (MuStore *store, MuConfig *opts, GError **err)
return foreach_msg_file (store, opts, remove_path_func, err);
}
static gboolean
tickle_func (MuStore *store, const char *path, GError **err)
{
MuMsg *msg;
gboolean rv;
msg = mu_msg_new_from_file (path, NULL, err);
if (!msg)
return FALSE;
rv = mu_msg_tickle (msg, err);
mu_msg_unref (msg);
return rv;
}
MuError
mu_cmd_tickle (MuStore *store, MuConfig *opts, GError **err)
{
g_return_val_if_fail (opts, MU_ERROR_INTERNAL);
g_return_val_if_fail (opts->cmd == MU_CONFIG_CMD_TICKLE,
MU_ERROR_INTERNAL);
return foreach_msg_file (store, opts, tickle_func, err);
}
struct _VData {
MuMsgPartSigStatus combined_status;
char *report;
@ -632,6 +659,8 @@ mu_cmd_execute (MuConfig *opts, GError **err)
merr = with_store (mu_cmd_add, opts, FALSE, err); break;
case MU_CONFIG_CMD_REMOVE:
merr = with_store (mu_cmd_remove, opts, FALSE, err); break;
case MU_CONFIG_CMD_TICKLE:
merr = with_store (mu_cmd_tickle, opts, FALSE, err); break;
case MU_CONFIG_CMD_SERVER:
merr = with_store (mu_cmd_server, opts, FALSE, err); break;
default:

View File

@ -151,6 +151,18 @@ MuError mu_cmd_add (MuStore *store, MuConfig *opts, GError **err);
*/
MuError mu_cmd_remove (MuStore *store, MuConfig *opts, GError **err);
/**
* execute the tickle command
*
* @param store store object to use
* @param opts configuration options
* @param err receives error information, or NULL
*
* @return MU_OK (0) if the command succeeds,
* some error code otherwise
*/
MuError mu_cmd_tickle (MuStore *store, MuConfig *opts, GError **err);
/**
* execute the server command

View File

@ -471,6 +471,7 @@ cmd_from_string (const char *str)
{ "remove", MU_CONFIG_CMD_REMOVE },
{ "script", MU_CONFIG_CMD_SCRIPT },
{ "server", MU_CONFIG_CMD_SERVER },
{ "tickle", MU_CONFIG_CMD_TICKLE },
{ "verify", MU_CONFIG_CMD_VERIFY },
{ "view", MU_CONFIG_CMD_VIEW }
};

View File

@ -74,6 +74,7 @@ enum _MuConfigCmd {
MU_CONFIG_CMD_REMOVE,
MU_CONFIG_CMD_SCRIPT,
MU_CONFIG_CMD_SERVER,
MU_CONFIG_CMD_TICKLE,
MU_CONFIG_CMD_VERIFY,
MU_CONFIG_CMD_VIEW,