* WIP: basic 'mu cfind' command + start of man page

This commit is contained in:
Dirk-Jan C. Binnema 2011-03-05 00:59:35 +02:00
parent 6226754a25
commit 86971d53d8
5 changed files with 195 additions and 17 deletions

View File

@ -19,6 +19,7 @@ include $(top_srcdir)/gtest.mk
dist_man_MANS = \
mu-cleanup.1 \
mu-bookmarks.5 \
mu-cfind.1 \
mu-easy.1 \
mu-extract.1 \
mu-find.1 \

74
man/mu-cfind.1 Normal file
View File

@ -0,0 +1,74 @@
.TH MU CFIND 1 "March 2011" "User Manuals"
.SH NAME
mu cfind \- find contacts in the
.B mu
database and/or export
.SH SYNOPSIS
.B mu cfind [options] [<pattern>]
.SH DESCRIPTION
\fBmu cfind\fR is the \fBmu\fR command for finding contacts (i.e., people who
were either the sender or receiver of mail).
.SH SEARCHING CONTACTS
When you index your messages (see \fBmu index\fR), \fBmu\fR creates a list of
all unique e-mail addresses found, and the accompanying name. In case the same
e-mail address is used with different names, the most recent one is used.
\fBmu cfind\fR starts a search for contacts that match a \fIregular
expression\fR. For example:
.nf
$ mu cfind '@gmail\.com'
.fi
would find all contacts with a gmail-address, while
.nf
$ mu cfind Mary
.fi
would find all contact with Mary in either name or e-mail address.
.SH OPTIONS
.TP
\fB\-\-format\fR=
set the file access mode for the new maildir(s) as in \fBchmod(1)\fR.
.SH RETURN VALUE
\fBmu find\fR return 0 upon successful completion; if it the a search was
performed, there needs to be a least one match. Anything else leads to a
non-zero return value, for example:
.sh
| code | meaning |
|------+--------------------------------|
| 0 | ok |
| 1 | general error |
| 2 | no matches (for 'mu cfind') |
.si
.SH BUGS
Please report bugs if you find them:
.BR http://code.google.com/p/mu0/issues/list
If you have specific messages which are not matched correctly, please attach
them (appropriately censored of course).
.SH AUTHOR
Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
.SH "SEE ALSO"
.BR mu(1)
.BR mu-index(1)

View File

@ -131,10 +131,62 @@ mu_cmd_mkdir (MuConfig *opts)
}
static void
each_contact (const char *email, const char *name, time_t tstamp, gpointer data)
enum _OutputFormat {
FORMAT_PLAIN,
FORMAT_MUTT,
FORMAT_WL,
FORMAT_CSV,
FORMAT_ORG_CONTACT,
FORMAT_NONE
};
typedef enum _OutputFormat OutputFormat;
static OutputFormat
get_output_format (const char *formatstr)
{
g_print ("%u: %s %s\n", (unsigned)tstamp, email, name ? name : "");
int i;
struct {
const char* name;
OutputFormat format;
} formats [] = {
{MU_CONFIG_FORMAT_PLAIN, FORMAT_PLAIN},
{MU_CONFIG_FORMAT_MUTT, FORMAT_MUTT},
{MU_CONFIG_FORMAT_WL, FORMAT_WL},
{MU_CONFIG_FORMAT_CSV, FORMAT_CSV},
{MU_CONFIG_FORMAT_ORG_CONTACT, FORMAT_ORG_CONTACT}
};
for (i = 0; i != G_N_ELEMENTS(formats); i++)
if (g_strcmp0 (formats[i].name, formatstr) == 0)
return formats[i].format;
return FORMAT_NONE;
}
static void
each_contact (const char *email, const char *name, time_t tstamp,
OutputFormat format)
{
switch (format) {
case FORMAT_MUTT:
if (name)
g_print ("alias %s <%s>\n", name, email);
break;
case FORMAT_WL:
if (name)
g_print ("%s \"%s\"\n", email, name);
break;
case FORMAT_ORG_CONTACT:
if (name)
g_print ("* %s\n:PROPERTIES:\n:EMAIL: %s\n:END:\n\n",
name, email);
break;
default:
g_print ("%u: %s %s\n", (unsigned)tstamp, email, name ? name : "");
}
}
@ -143,14 +195,23 @@ each_contact (const char *email, const char *name, time_t tstamp, gpointer data)
MuExitCode
mu_cmd_cfind (MuConfig *opts)
{
OutputFormat format;
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);
format = get_output_format (opts->formatstr);
if (format == FORMAT_NONE) {
g_warning ("invalid output format %s",
opts->formatstr ? opts->formatstr : "<none>");
return FALSE;
}
/* if (!opts->params[1]) { */
/* g_warning ("usage: mu cfind [ptrn] "); */
/* g_warning ("usage: mu cfind [OPTIONS] [<ptrn>]"); */
/* return MU_EXITCODE_ERROR; */
/* } */
@ -160,8 +221,8 @@ mu_cmd_cfind (MuConfig *opts)
return MU_EXITCODE_ERROR;
}
mu_contacts_foreach (contacts, (MuContactsForeachFunc)each_contact, NULL,
opts->params[1]);
mu_contacts_foreach (contacts, (MuContactsForeachFunc)each_contact,
GINT_TO_POINTER(format), opts->params[1]);
mu_contacts_destroy (contacts);
return MU_OK;

View File

@ -162,7 +162,7 @@ config_options_group_find (MuConfig *opts)
"clear old links before filling a linksdir (false)", NULL},
{"format", 'o', 0, G_OPTION_ARG_STRING, &opts->formatstr,
"output format ('plain'(*), 'links', 'xml',"
"'json', 'sexp', 'xquery') (plain)", NULL},
"'json', 'sexp', 'xquery')", NULL},
{"xquery", 0, 0, G_OPTION_ARG_NONE, &opts->xquery,
"obsolete, use --format=xquery instead", NULL},
@ -197,6 +197,35 @@ config_options_group_mkdir (MuConfig *opts)
return og;
}
static void
set_group_cfind_defaults (MuConfig *opts)
{
if (!opts->formatstr) /* by default, use plain output */
opts->formatstr = MU_CONFIG_FORMAT_PLAIN;
}
static GOptionGroup *
config_options_group_cfind (MuConfig *opts)
{
GOptionGroup *og;
GOptionEntry entries[] = {
{"format", 'o', 0, G_OPTION_ARG_STRING, &opts->formatstr,
"output format ('plain'(*), 'mutt', 'wanderlust',"
"'org-contact', 'csv')", NULL},
{NULL, 0, 0, 0, NULL, NULL, NULL}
};
og = g_option_group_new("cfind", "options for the 'cfind' command",
"", NULL, NULL);
g_option_group_add_entries(og, entries);
return og;
}
static GOptionGroup*
config_options_group_extract(MuConfig *opts)
{
@ -281,7 +310,6 @@ parse_params (MuConfig *opts, int *argcp, char ***argvp)
context = g_option_context_new("- mu general option");
g_option_context_set_main_group(context,
config_options_group_mu(opts));
switch (opts->cmd) {
case MU_CONFIG_CMD_INDEX:
g_option_context_add_group(context, config_options_group_index(opts));
@ -295,6 +323,9 @@ parse_params (MuConfig *opts, int *argcp, char ***argvp)
case MU_CONFIG_CMD_EXTRACT:
g_option_context_add_group(context, config_options_group_extract(opts));
break;
case MU_CONFIG_CMD_CFIND:
g_option_context_add_group(context, config_options_group_cfind(opts));
break;
default: break;
}
@ -324,9 +355,10 @@ mu_config_new (int *argcp, char ***argvp)
}
/* fill in the defaults if user did not specify */
set_group_mu_defaults(config);
set_group_index_defaults(config);
set_group_find_defaults(config);
set_group_mu_defaults (config);
set_group_index_defaults (config);
set_group_find_defaults (config);
set_group_cfind_defaults (config);
/* set_group_mkdir_defaults (config); */
return config;
@ -338,11 +370,11 @@ mu_config_destroy (MuConfig *opts)
if (!opts)
return;
g_free(opts->muhome);
g_free(opts->maildir);
g_free(opts->linksdir);
g_free(opts->targetdir);
g_strfreev(opts->params);
g_free (opts->muhome);
g_free (opts->maildir);
g_free (opts->linksdir);
g_free (opts->targetdir);
g_strfreev (opts->params);
g_free (opts);
}

View File

@ -34,6 +34,16 @@ G_BEGIN_DECLS
#define MU_CONFIG_FORMAT_SEXP "sexp" /* output sexps */
#define MU_CONFIG_FORMAT_XQUERY "xquery" /* output the xapian query */
/* for cfind */
#define MU_CONFIG_FORMAT_MUTT "mutt" /* output in mutt alias style */
#define MU_CONFIG_FORMAT_WL "wl" /* output in Wanderlust
* address-book style */
#define MU_CONFIG_FORMAT_CSV "csv" /* output in
* comma-separated
* values */
#define MU_CONFIG_FORMAT_ORG_CONTACT "org-contact" /* org-contact
* format */
enum _MuConfigCmd {
MU_CONFIG_CMD_INDEX,
MU_CONFIG_CMD_FIND,
@ -78,7 +88,7 @@ struct _MuConfig {
* default */
int max_msg_size; /* maximum size for message files */
/* options for querying */
/* options for querying */
gboolean xquery; /* (obsolete) give the Xapian
query instead of search
results */