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

@ -902,3 +902,19 @@ mu_msg_move_to_maildir (MuMsg *self, const char *maildir,
return self->_file ? TRUE : FALSE;
}
/*
* Rename a message-file, keeping the same flags. This is useful for tricking
* some 3rd party progs such as mbsync
*/
gboolean
mu_msg_tickle (MuMsg *self, GError **err)
{
g_return_val_if_fail (self, FALSE);
return mu_msg_move_to_maildir (self,
mu_msg_get_maildir (self),
mu_msg_get_flags (self),
FALSE, TRUE, err);
}

View File

@ -476,6 +476,23 @@ gboolean mu_msg_move_to_maildir (MuMsg *msg, const char *maildir,
GError **err);
/**
* Tickle a message -- ie., rxename a message while maintaining the maildir and
* flags. This can be useful when dealing with third-party tools such as mbsync
* that depend on changed filenames.
*
* @param msg a message with an existing file system path in an actual
* maildir
* @param err (may be NULL) may contain error information; note if the
* function return FALSE, err is not set for all error condition
* (ie. not for parameter error
*
* @return TRUE if it worked, FALSE otherwise
*/
gboolean mu_msg_tickle (MuMsg *msg, GError **err);
enum _MuMsgContactType { /* Reply-To:? */
MU_MSG_CONTACT_TYPE_TO = 0,
MU_MSG_CONTACT_TYPE_FROM,

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,