mirror of https://github.com/djcb/mu.git
* WIP: rudimentary implementation of the 'cfind' command, to find contacts
This commit is contained in:
parent
17eb035bd2
commit
b9be7f210c
37
src/mu-cmd.c
37
src/mu-cmd.c
|
@ -29,7 +29,8 @@
|
|||
#include "mu-util.h"
|
||||
#include "mu-str.h"
|
||||
#include "mu-maildir.h"
|
||||
|
||||
#include "mu-contacts.h"
|
||||
#include "mu-runtime.h"
|
||||
|
||||
/* we ignore fields for now */
|
||||
static gboolean
|
||||
|
@ -128,3 +129,37 @@ mu_cmd_mkdir (MuConfig *opts)
|
|||
|
||||
return MU_EXITCODE_OK;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
each_contact (const char *email, const char *name, gpointer data)
|
||||
{
|
||||
g_print ("%s %s\n", email, name ? name : "");
|
||||
}
|
||||
|
||||
MuExitCode
|
||||
mu_cmd_cfind (MuConfig *opts)
|
||||
{
|
||||
MuContacts *contacts;
|
||||
|
||||
g_return_val_if_fail (opts, MU_EXITCODE_ERROR);
|
||||
g_return_val_if_fail (opts->cmd == MU_CONFIG_CMD_CFIND,
|
||||
MU_EXITCODE_ERROR);
|
||||
|
||||
/* if (!opts->params[1]) { */
|
||||
/* g_warning ("usage: mu cfind [ptrn] "); */
|
||||
/* return MU_EXITCODE_ERROR; */
|
||||
/* } */
|
||||
|
||||
contacts = mu_contacts_new (mu_runtime_contacts_cache_file());
|
||||
if (!contacts) {
|
||||
g_warning ("could not retrieve contacts");
|
||||
return MU_EXITCODE_ERROR;
|
||||
}
|
||||
|
||||
mu_contacts_foreach (contacts, (MuContactsForeachFunc)each_contact, NULL);
|
||||
mu_contacts_destroy (contacts);
|
||||
|
||||
return MU_OK;
|
||||
}
|
||||
|
||||
|
|
11
src/mu-cmd.h
11
src/mu-cmd.h
|
@ -92,6 +92,17 @@ MuExitCode mu_cmd_find (MuConfig *opts);
|
|||
MuExitCode mu_cmd_extract (MuConfig *opts);
|
||||
|
||||
|
||||
/**
|
||||
* execute the cfind command
|
||||
*
|
||||
* @param opts configuration options
|
||||
*
|
||||
* @return MU_EXITCODE_OK (0) if the command succeeds,
|
||||
* MU_EXITCODE_ERROR otherwise
|
||||
*/
|
||||
MuExitCode mu_cmd_cfind (MuConfig *opts);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /*__MU_CMD_H__*/
|
||||
|
|
|
@ -244,7 +244,8 @@ parse_cmd (MuConfig *opts, int *argcp, char ***argvp)
|
|||
{ "cleanup", MU_CONFIG_CMD_CLEANUP },
|
||||
{ "mkdir", MU_CONFIG_CMD_MKDIR },
|
||||
{ "view", MU_CONFIG_CMD_VIEW },
|
||||
{ "extract", MU_CONFIG_CMD_EXTRACT }
|
||||
{ "extract", MU_CONFIG_CMD_EXTRACT },
|
||||
{ "cfind", MU_CONFIG_CMD_CFIND },
|
||||
};
|
||||
|
||||
opts->cmd = MU_CONFIG_CMD_NONE;
|
||||
|
@ -394,6 +395,7 @@ mu_config_execute (MuConfig *opts)
|
|||
case MU_CONFIG_CMD_INDEX: return mu_cmd_index (opts);
|
||||
case MU_CONFIG_CMD_MKDIR: return mu_cmd_mkdir (opts);
|
||||
case MU_CONFIG_CMD_VIEW: return mu_cmd_view (opts);
|
||||
case MU_CONFIG_CMD_CFIND: return mu_cmd_cfind (opts);
|
||||
case MU_CONFIG_CMD_UNKNOWN:
|
||||
g_printerr ("mu: unknown command '%s'\n\n", opts->cmdstr);
|
||||
show_usage (FALSE);
|
||||
|
|
|
@ -41,6 +41,7 @@ enum _MuConfigCmd {
|
|||
MU_CONFIG_CMD_MKDIR,
|
||||
MU_CONFIG_CMD_VIEW,
|
||||
MU_CONFIG_CMD_EXTRACT,
|
||||
MU_CONFIG_CMD_CFIND,
|
||||
MU_CONFIG_CMD_NONE,
|
||||
|
||||
MU_CONFIG_CMD_UNKNOWN
|
||||
|
|
|
@ -63,7 +63,7 @@ gboolean mu_contacts_add (MuContacts *contacts, const char* name, const char *em
|
|||
void mu_contacts_destroy (MuContacts *contacts);
|
||||
|
||||
|
||||
typedef void (*MuContactsForeachFunc) (const char *email, const char *mail,
|
||||
typedef void (*MuContactsForeachFunc) (const char *email, const char *name,
|
||||
gpointer user_data);
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue