2010-01-01 19:44:19 +01:00
|
|
|
/*
|
|
|
|
** Copyright (C) 2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
|
|
|
**
|
|
|
|
** This program is free software; you can redistribute it and/or modify it
|
|
|
|
** under the terms of the GNU General Public License as published by the
|
|
|
|
** Free Software Foundation; either version 3, or (at your option) any
|
|
|
|
** later version.
|
|
|
|
**
|
|
|
|
** This program is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with this program; if not, write to the Free Software Foundation,
|
|
|
|
** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
2010-01-02 13:44:26 +01:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
2010-01-01 19:44:19 +01:00
|
|
|
#include <string.h>
|
2010-01-02 15:06:36 +01:00
|
|
|
#include <errno.h>
|
2010-01-02 13:44:26 +01:00
|
|
|
|
|
|
|
#include "mu-msg-gmime.h"
|
|
|
|
#include "mu-maildir.h"
|
|
|
|
#include "mu-index.h"
|
|
|
|
#include "mu-query-xapian.h"
|
|
|
|
#include "mu-msg-xapian.h"
|
|
|
|
#include "mu-msg-str.h"
|
2010-01-01 19:44:19 +01:00
|
|
|
#include "mu-cmd.h"
|
|
|
|
|
2010-01-02 13:44:26 +01:00
|
|
|
static MuCmd
|
|
|
|
_cmd_from_string (const char* cmd)
|
2010-01-01 19:44:19 +01:00
|
|
|
{
|
|
|
|
if (!cmd)
|
|
|
|
return MU_CMD_UNKNOWN;
|
|
|
|
|
|
|
|
if (strcmp (cmd, "index") == 0)
|
|
|
|
return MU_CMD_INDEX;
|
|
|
|
|
|
|
|
/* support some synonyms... */
|
|
|
|
if ((strcmp (cmd, "query") == 0) ||
|
|
|
|
(strcmp (cmd, "find") == 0) ||
|
|
|
|
(strcmp (cmd, "search") == 0))
|
|
|
|
return MU_CMD_QUERY;
|
|
|
|
|
2010-01-04 19:21:03 +01:00
|
|
|
if (strcmp (cmd, "cleanup") == 0)
|
|
|
|
return MU_CMD_CLEANUP;
|
|
|
|
|
2010-01-01 19:44:19 +01:00
|
|
|
if ((strcmp (cmd, "mkmdir") == 0) ||
|
|
|
|
(strcmp (cmd, "mkdir") == 0))
|
|
|
|
return MU_CMD_MKDIR;
|
2010-01-04 19:21:03 +01:00
|
|
|
|
|
|
|
/* if (strcmp (cmd, "link") == 0) */
|
|
|
|
/* return MU_CMD_LINK; */
|
2010-01-01 19:44:19 +01:00
|
|
|
|
2010-01-03 22:49:45 +01:00
|
|
|
/* if ((strcmp (cmd, "help") == 0) || */
|
|
|
|
/* (strcmp (cmd, "info") == 0)) */
|
|
|
|
/* return MU_CMD_HELP; */
|
2010-01-01 19:44:19 +01:00
|
|
|
|
|
|
|
return MU_CMD_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-02 13:44:26 +01:00
|
|
|
static gboolean
|
|
|
|
_print_query (MuQueryXapian *xapian, const gchar *query)
|
|
|
|
{
|
|
|
|
char *querystr;
|
|
|
|
|
|
|
|
querystr = mu_query_xapian_as_string (xapian, query);
|
|
|
|
g_print ("%s\n", querystr);
|
|
|
|
g_free (querystr);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const gchar*
|
|
|
|
_display_field (MuMsgXapian *row, const MuMsgField* field)
|
|
|
|
{
|
|
|
|
gint64 val;
|
|
|
|
|
|
|
|
switch (mu_msg_field_type(field)) {
|
|
|
|
case MU_MSG_FIELD_TYPE_STRING:
|
|
|
|
return mu_msg_xapian_get_field (row, field);
|
|
|
|
|
|
|
|
case MU_MSG_FIELD_TYPE_INT:
|
|
|
|
|
|
|
|
if (mu_msg_field_id(field) == MU_MSG_FIELD_ID_PRIORITY) {
|
|
|
|
val = mu_msg_xapian_get_field_numeric (row, field);
|
|
|
|
return mu_msg_str_prio ((MuMsgPriority)val);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mu_msg_field_id(field) == MU_MSG_FIELD_ID_FLAGS) {
|
|
|
|
val = mu_msg_xapian_get_field_numeric (row, field);
|
|
|
|
return mu_msg_str_flags_s ((MuMsgPriority)val);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mu_msg_xapian_get_field (row, field); /* as string */
|
|
|
|
case MU_MSG_FIELD_TYPE_TIME_T:
|
|
|
|
val = mu_msg_xapian_get_field_numeric (row, field);
|
|
|
|
return mu_msg_str_date_s ((time_t)val);
|
|
|
|
case MU_MSG_FIELD_TYPE_BYTESIZE:
|
|
|
|
val = mu_msg_xapian_get_field_numeric (row, field);
|
|
|
|
return mu_msg_str_size_s ((time_t)val);
|
|
|
|
default:
|
|
|
|
g_return_val_if_reached (NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* returns NULL if there is an error */
|
|
|
|
const MuMsgField*
|
|
|
|
_sort_field_from_string (const char* fieldstr)
|
|
|
|
{
|
|
|
|
const MuMsgField *field;
|
|
|
|
|
|
|
|
field = mu_msg_field_from_name (fieldstr);
|
|
|
|
if (!field && strlen(fieldstr) == 1)
|
|
|
|
field = mu_msg_field_from_shortcut(fieldstr[0]);
|
|
|
|
if (!field)
|
|
|
|
g_printerr ("not a valid sort field: '%s'\n",
|
|
|
|
fieldstr);
|
|
|
|
return field;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-03 22:49:45 +01:00
|
|
|
|
|
|
|
|
2010-01-02 13:44:26 +01:00
|
|
|
static gboolean
|
|
|
|
_print_rows (MuQueryXapian *xapian, const gchar *query, MuConfigOptions *opts)
|
|
|
|
{
|
|
|
|
MuMsgXapian *row;
|
|
|
|
const MuMsgField *sortfield;
|
|
|
|
|
|
|
|
sortfield = NULL;
|
|
|
|
if (opts->sortfield) {
|
|
|
|
sortfield = _sort_field_from_string (opts->sortfield);
|
|
|
|
if (!sortfield) /* error occured? */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
row = mu_query_xapian_run (xapian, query, sortfield,
|
|
|
|
!opts->descending);
|
|
|
|
if (!row) {
|
|
|
|
g_printerr ("error: running query failed\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* iterate over the found rows */
|
|
|
|
while (!mu_msg_xapian_is_done (row)) {
|
|
|
|
const char* fields = opts->fields;
|
|
|
|
int printlen = 0;
|
|
|
|
while (*fields) {
|
|
|
|
const MuMsgField* field =
|
|
|
|
mu_msg_field_from_shortcut (*fields);
|
|
|
|
if (!field ||
|
|
|
|
!mu_msg_field_is_xapian_enabled (field))
|
|
|
|
printlen += printf ("%c", *fields);
|
|
|
|
else
|
|
|
|
printlen += printf ("%s",
|
|
|
|
_display_field(row, field));
|
|
|
|
++fields;
|
|
|
|
}
|
|
|
|
if (printlen >0)
|
|
|
|
printf ("\n");
|
|
|
|
|
|
|
|
mu_msg_xapian_next (row);
|
|
|
|
}
|
|
|
|
|
|
|
|
mu_msg_xapian_destroy (row);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_do_output_text (MuQueryXapian *xapian, MuConfigOptions* opts,
|
|
|
|
const gchar **params)
|
|
|
|
{
|
|
|
|
gchar *query;
|
|
|
|
gboolean retval = TRUE;
|
|
|
|
|
|
|
|
query = mu_query_xapian_combine (params, FALSE);
|
|
|
|
|
|
|
|
/* if xquery is set, we print the xapian query instead of the
|
|
|
|
* output; this is for debugging purposes */
|
|
|
|
if (opts->xquery)
|
|
|
|
retval = _print_query (xapian, query);
|
|
|
|
else
|
|
|
|
retval = _print_rows (xapian, query, opts);
|
|
|
|
|
|
|
|
g_free (query);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2010-01-03 12:42:23 +01:00
|
|
|
|
|
|
|
/* create a linksdir if it not exist yet; if it already existed,
|
|
|
|
* remove old links if opts->clearlinks was specified */
|
2010-01-02 13:44:26 +01:00
|
|
|
static gboolean
|
2010-01-03 12:42:23 +01:00
|
|
|
_create_or_clear_linksdir_maybe (MuConfigOptions* opts)
|
2010-01-02 13:44:26 +01:00
|
|
|
{
|
2010-01-03 12:42:23 +01:00
|
|
|
if (access (opts->linksdir, F_OK) != 0) {
|
|
|
|
if (!mu_maildir_mkmdir (opts->linksdir, 0700, TRUE))
|
2010-01-02 13:44:26 +01:00
|
|
|
return FALSE;
|
2010-01-03 12:42:23 +01:00
|
|
|
} else if (opts->clearlinks)
|
|
|
|
mu_maildir_clear_links (opts->linksdir);
|
2010-01-02 13:44:26 +01:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_do_output_links (MuQueryXapian *xapian, MuConfigOptions* opts,
|
|
|
|
const gchar **params)
|
|
|
|
{
|
|
|
|
gchar *query;
|
|
|
|
gboolean retval = TRUE;
|
|
|
|
MuMsgXapian *row;
|
|
|
|
const MuMsgField *pathfield;
|
|
|
|
|
2010-01-03 12:42:23 +01:00
|
|
|
if (!_create_or_clear_linksdir_maybe (opts))
|
2010-01-02 13:44:26 +01:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
query = mu_query_xapian_combine (params, FALSE);
|
|
|
|
row = mu_query_xapian_run (xapian, query, NULL, FALSE);
|
|
|
|
if (!row) {
|
|
|
|
g_printerr ("error: running query failed\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
pathfield = mu_msg_field_from_id (MU_MSG_FIELD_ID_PATH);
|
|
|
|
|
|
|
|
/* iterate over the found rows */
|
2010-01-02 15:06:36 +01:00
|
|
|
for (;!mu_msg_xapian_is_done (row); mu_msg_xapian_next (row)) {
|
|
|
|
|
2010-01-02 13:44:26 +01:00
|
|
|
const char *path;
|
2010-01-02 15:06:36 +01:00
|
|
|
|
2010-01-02 13:44:26 +01:00
|
|
|
path = mu_msg_xapian_get_field (row, pathfield);
|
2010-01-02 15:06:36 +01:00
|
|
|
if (!path)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* this might happen if the database is not up-to-date */
|
|
|
|
if (access (path, R_OK) != 0) {
|
|
|
|
g_warning ("Cannot read source message %s: %s",
|
|
|
|
path, strerror (errno));
|
|
|
|
continue;
|
2010-01-02 13:44:26 +01:00
|
|
|
}
|
2010-01-02 15:06:36 +01:00
|
|
|
|
|
|
|
if (!mu_maildir_link (path, opts->linksdir))
|
|
|
|
break;
|
2010-01-02 13:44:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
mu_msg_xapian_destroy (row);
|
|
|
|
g_free (query);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2010-01-01 19:44:19 +01:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_check_query_params (MuConfigOptions *opts)
|
|
|
|
{
|
|
|
|
if (opts->linksdir)
|
2010-01-02 13:44:26 +01:00
|
|
|
if (opts->xquery) {
|
2010-01-01 19:44:19 +01:00
|
|
|
g_warning ("Invalid option for '--linksdir'");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-01-02 13:44:26 +01:00
|
|
|
|
2010-01-01 19:44:19 +01:00
|
|
|
if (!opts->params[0] || !opts->params[1]) {
|
|
|
|
g_warning ("Missing search expression");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-02 13:44:26 +01:00
|
|
|
|
|
|
|
gboolean
|
|
|
|
_cmd_query (MuConfigOptions *opts)
|
|
|
|
{
|
|
|
|
MuQueryXapian *xapian;
|
|
|
|
gboolean rv;
|
|
|
|
const gchar **params;
|
|
|
|
|
|
|
|
if (!_check_query_params (opts))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* first param is 'query', search params are after that */
|
|
|
|
params = (const gchar**)&opts->params[1];
|
|
|
|
|
|
|
|
mu_msg_gmime_init();
|
|
|
|
|
|
|
|
xapian = mu_query_xapian_new (opts->muhome);
|
|
|
|
if (!xapian) {
|
|
|
|
mu_msg_gmime_uninit ();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opts->linksdir)
|
|
|
|
rv = _do_output_links (xapian, opts, params);
|
|
|
|
else
|
|
|
|
rv = _do_output_text (xapian, opts, params);
|
|
|
|
|
|
|
|
mu_query_xapian_destroy (xapian);
|
|
|
|
mu_msg_gmime_uninit();
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-01 19:44:19 +01:00
|
|
|
static gboolean
|
|
|
|
_check_index_params (MuConfigOptions *opts)
|
|
|
|
{
|
|
|
|
if (opts->linksdir)
|
|
|
|
if (opts->linksdir || opts->fields ||
|
|
|
|
opts->sortfield || opts->xquery ||
|
2010-01-02 13:44:26 +01:00
|
|
|
opts->descending|| opts->xquery) {
|
2010-01-01 19:44:19 +01:00
|
|
|
g_warning ("Invalid option(s) for command");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-02 13:44:26 +01:00
|
|
|
static MuResult
|
2010-01-04 19:21:03 +01:00
|
|
|
_index_msg_cb (MuIndexStats* stats, void *user_data)
|
2010-01-02 13:44:26 +01:00
|
|
|
{
|
|
|
|
char *kars="-\\|/";
|
|
|
|
char output[100];
|
|
|
|
|
|
|
|
static int i = 0;
|
|
|
|
static int len = 0;
|
|
|
|
|
|
|
|
while (len --> 0)
|
|
|
|
printf ("\b");
|
|
|
|
|
|
|
|
len = snprintf (output, sizeof(output),
|
2010-01-04 19:21:03 +01:00
|
|
|
"%c indexing mail; processed: %d; "
|
|
|
|
"updated/new: %d, cleaned up: %d",
|
|
|
|
kars[i % 4], stats->_processed,
|
|
|
|
stats->_updated, stats->_cleaned_up);
|
2010-01-02 13:44:26 +01:00
|
|
|
g_print ("%s", output);
|
|
|
|
|
|
|
|
++i;
|
|
|
|
|
|
|
|
return MU_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_cmd_index (MuConfigOptions *opts)
|
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
if (!_check_index_params (opts))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
mu_msg_gmime_init ();
|
|
|
|
{
|
2010-01-04 19:21:03 +01:00
|
|
|
MuIndex *midx;
|
|
|
|
MuIndexStats stats;
|
|
|
|
|
|
|
|
mu_index_stats_clear (&stats);
|
2010-01-02 13:44:26 +01:00
|
|
|
midx = mu_index_new (opts->muhome);
|
2010-01-04 19:21:03 +01:00
|
|
|
rv = mu_index_run (midx, opts->maildir,
|
|
|
|
opts->reindex, &stats,
|
|
|
|
opts->quiet ? NULL : _index_msg_cb,
|
|
|
|
NULL, NULL);
|
|
|
|
if (opts->cleanup) {
|
|
|
|
stats._processed = 0; /* start over */
|
|
|
|
mu_index_cleanup (midx, &stats,
|
|
|
|
opts->quiet ? NULL : _index_msg_cb,
|
|
|
|
NULL);
|
|
|
|
}
|
2010-01-04 20:23:03 +01:00
|
|
|
|
|
|
|
if (!opts->quiet)
|
|
|
|
g_print ("\n");
|
|
|
|
|
2010-01-02 13:44:26 +01:00
|
|
|
mu_index_destroy (midx);
|
|
|
|
}
|
|
|
|
mu_msg_gmime_uninit ();
|
|
|
|
|
|
|
|
return rv == MU_OK ? TRUE : FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-04 19:21:03 +01:00
|
|
|
MuResult
|
|
|
|
_cleanup_cb (MuIndexStats *stats, void *user_data)
|
|
|
|
{
|
|
|
|
char *kars="-\\|/";
|
|
|
|
char output[100];
|
|
|
|
|
|
|
|
static int i = 0;
|
|
|
|
static int len = 0;
|
|
|
|
|
|
|
|
while (len --> 0)
|
|
|
|
printf ("\b");
|
|
|
|
|
|
|
|
len = snprintf (output, sizeof(output),
|
|
|
|
"%c mu is cleaning up the message database; "
|
|
|
|
"processed: %d; cleaned-up: %d",
|
|
|
|
kars[i % 4], stats->_processed, stats->_cleaned_up);
|
|
|
|
g_print ("%s", output);
|
|
|
|
++i;
|
|
|
|
|
|
|
|
return MU_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_cmd_cleanup (MuConfigOptions *opts)
|
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
if (!_check_index_params (opts))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
mu_msg_gmime_init ();
|
|
|
|
{
|
|
|
|
MuIndex *midx;
|
|
|
|
MuIndexStats stats;
|
|
|
|
|
|
|
|
mu_index_stats_clear (&stats);
|
|
|
|
midx = mu_index_new (opts->muhome);
|
|
|
|
mu_index_cleanup (midx, &stats,
|
|
|
|
opts->quiet ? NULL :_cleanup_cb,
|
|
|
|
NULL);
|
|
|
|
mu_index_destroy (midx);
|
|
|
|
}
|
2010-01-04 20:23:03 +01:00
|
|
|
|
|
|
|
if (!opts->quiet)
|
|
|
|
g_print ("\n");
|
|
|
|
|
2010-01-04 19:21:03 +01:00
|
|
|
mu_msg_gmime_uninit ();
|
|
|
|
|
|
|
|
return rv == MU_OK ? TRUE : FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-02 13:44:26 +01:00
|
|
|
static int
|
|
|
|
_cmd_mkdir (MuConfigOptions *opts)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!opts->params[0])
|
|
|
|
return FALSE; /* shouldn't happen */
|
|
|
|
|
|
|
|
if (!opts->params[1]) {
|
|
|
|
g_printerr ("usage: mu mkdir <dir> [more dirs]\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 1;
|
|
|
|
while (opts->params[i]) {
|
|
|
|
if (!mu_maildir_mkmdir (opts->params[i], 0755, FALSE))
|
|
|
|
return FALSE;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-04 19:21:03 +01:00
|
|
|
#if 0 /* currently, turned off */
|
2010-01-02 13:44:26 +01:00
|
|
|
static gboolean
|
|
|
|
_cmd_link (MuConfigOptions *opts)
|
|
|
|
{
|
|
|
|
if (!opts->params[0])
|
|
|
|
return FALSE; /* shouldn't happen */
|
|
|
|
|
|
|
|
if (!opts->params[1] || !opts->params[2]) {
|
|
|
|
g_printerr ("usage: mu link <src> <targetdir>\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mu_maildir_link (opts->params[1], opts->params[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-04 19:21:03 +01:00
|
|
|
static gboolean
|
|
|
|
_cmd_help (MuConfigOptions *opts)
|
|
|
|
{
|
|
|
|
/* FIXME: get context-sensitive help */
|
|
|
|
_show_version ();
|
|
|
|
return _show_usage (FALSE);
|
|
|
|
}
|
|
|
|
#endif /* 0 */
|
|
|
|
|
|
|
|
|
2010-01-02 13:44:26 +01:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_show_usage (gboolean noerror)
|
|
|
|
{
|
|
|
|
const char* usage=
|
|
|
|
"usage: mu [options] command [parameters]\n"
|
2010-01-04 19:21:03 +01:00
|
|
|
"\twhere command is one of index, find, cleanup, mkdir\n"
|
2010-01-03 22:49:45 +01:00
|
|
|
"see mu(1) for more information\n";
|
2010-01-02 13:44:26 +01:00
|
|
|
|
|
|
|
if (noerror)
|
|
|
|
g_print ("%s", usage);
|
|
|
|
else
|
|
|
|
g_printerr ("%s", usage);
|
|
|
|
|
|
|
|
return noerror;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_show_version (void)
|
|
|
|
{
|
|
|
|
const char* msg =
|
|
|
|
"mu (mail indexer / searcher version) " VERSION "\n\n"
|
|
|
|
"Copyright (C) 2010 Dirk-Jan C. Binnema\n"
|
|
|
|
"License GPLv3+: GNU GPL version 3 or later "
|
|
|
|
"<http://gnu.org/licenses/gpl.html>.\n\n"
|
|
|
|
"This is free software: you are free to change "
|
|
|
|
"and redistribute it.\n"
|
|
|
|
"There is NO WARRANTY, to the extent permitted by law.";
|
|
|
|
|
|
|
|
g_print ("%s\n", msg);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-01 19:44:19 +01:00
|
|
|
|
|
|
|
gboolean
|
2010-01-02 13:44:26 +01:00
|
|
|
mu_cmd_execute (MuConfigOptions *opts)
|
2010-01-01 19:44:19 +01:00
|
|
|
{
|
2010-01-02 13:44:26 +01:00
|
|
|
MuCmd cmd;
|
|
|
|
|
|
|
|
if (opts->version)
|
|
|
|
return _show_version ();
|
|
|
|
|
|
|
|
if (!opts->params||!opts->params[0]) /* no command? */
|
|
|
|
return _show_usage (FALSE);
|
|
|
|
|
|
|
|
cmd = _cmd_from_string (opts->params[0]);
|
|
|
|
|
2010-01-01 19:44:19 +01:00
|
|
|
switch (cmd) {
|
2010-01-04 19:21:03 +01:00
|
|
|
|
2010-01-02 13:44:26 +01:00
|
|
|
case MU_CMD_INDEX: return _cmd_index (opts);
|
|
|
|
case MU_CMD_QUERY: return _cmd_query (opts);
|
2010-01-04 19:21:03 +01:00
|
|
|
case MU_CMD_CLEANUP: return _cmd_cleanup (opts);
|
|
|
|
case MU_CMD_MKDIR: return _cmd_mkdir (opts);
|
|
|
|
/* case MU_CMD_HELP: return _cmd_help (opts); */
|
|
|
|
/* case MU_CMD_LINK: return _cmd_link (opts); */
|
|
|
|
case MU_CMD_UNKNOWN: return _show_usage (FALSE);
|
2010-01-01 19:44:19 +01:00
|
|
|
default:
|
2010-01-02 13:44:26 +01:00
|
|
|
g_return_val_if_reached (FALSE);
|
|
|
|
}
|
2010-01-01 19:44:19 +01:00
|
|
|
}
|