* many changes to the config system

This commit is contained in:
Dirk-Jan C. Binnema 2011-01-04 23:19:03 +02:00
parent 38f9772270
commit fade4172fe
32 changed files with 485 additions and 602 deletions

10
TODO
View File

@ -1,21 +1,21 @@
* Future release
** release 0.10 [9%]
** release 0.10 [0%]
- [ ] mu stats
- [ ] ansi-colors in output
- [ ] config system (config file) (?)
- [ ] detect mail threads (?)
- [ ] xml,json,sexp output
- [ ] completion for zsh
- [ ] don't make test mail files executable
** release 0.9.2
** release 0.9.2 [20%]
- [ ] xml,json,sexp output
- [ ] separate exit code for 'not found' vs other errors
- [ ] fix build for Solaris
- [ ] clearer errors when /home/user does not exist
- [ ] fix -pedantic build
- [X] clearer errors when /home/user does not exist
- [X] fix -pedantic build
- [ ] make commit batch size configure param
- [ ] better 'usage' info
- [ ] add version info to output of configure, mu.log

View File

@ -53,11 +53,9 @@ libmu_la_SOURCES= \
mu-cmd-index.c \
mu-cmd-mkdir.c \
mu-cmd-view.c \
mu-cmd.c \
mu-cmd.h \
mu-config.c \
mu-config.h \
mu-error.h \
mu-index.c \
mu-index.h \
mu-log.c \
@ -86,13 +84,10 @@ libmu_la_SOURCES= \
mu-msg.h \
mu-msg-file.c \
mu-msg-file.h \
mu-output-link.c \
mu-output-link.h \
mu-output-plain.c \
mu-output-plain.h \
mu-output.c \
mu-output.h \
mu-query.cc \
mu-query.h \
mu-result.h \
mu-runtime.c \
mu-runtime.h \
mu-store.cc \

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2008-2011 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
@ -29,7 +29,7 @@
#include "mu-util.h"
static gboolean
save_numbered_parts (MuMsg *msg, MuConfigOptions *opts)
save_numbered_parts (MuMsg *msg, MuConfig *opts)
{
gboolean rv;
char **parts, **cur;
@ -131,7 +131,7 @@ save_certain_parts (MuMsg *msg, gboolean attachments_only,
static gboolean
save_parts (const char *path, MuConfigOptions *opts)
save_parts (const char *path, MuConfig *opts)
{
MuMsg* msg;
gboolean rv;
@ -179,7 +179,7 @@ each_part_show (MuMsgPart *part, gpointer user_data)
static gboolean
show_parts (const char* path, MuConfigOptions *opts)
show_parts (const char* path, MuConfig *opts)
{
MuMsg* msg;
GError *err;
@ -202,7 +202,7 @@ show_parts (const char* path, MuConfigOptions *opts)
}
static gboolean
check_params (MuConfigOptions *opts)
check_params (MuConfig *opts)
{
if (!opts->params[1]) {
g_warning ("usage: mu extract [options] <file>");
@ -230,16 +230,17 @@ check_params (MuConfigOptions *opts)
return TRUE;
}
gboolean
mu_cmd_extract (MuConfigOptions *opts)
MuExitCode
mu_cmd_extract (MuConfig *opts)
{
gboolean rv;
int rv;
g_return_val_if_fail (opts, FALSE);
g_return_val_if_fail (mu_cmd_equals (opts, "extract"), FALSE);
g_return_val_if_fail (opts, MU_EXITCODE_ERROR);
g_return_val_if_fail (opts->cmd == MU_CONFIG_CMD_EXTRACT,
MU_EXITCODE_ERROR);
if (!check_params (opts))
return FALSE;
return MU_EXITCODE_ERROR;
if (!opts->parts &&
!opts->save_attachments &&
@ -248,5 +249,5 @@ mu_cmd_extract (MuConfigOptions *opts)
else
rv = save_parts (opts->params[1], opts); /* save */
return rv;
return rv ? MU_EXITCODE_OK : MU_EXITCODE_ERROR;
}

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2008-2011 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
@ -17,7 +17,7 @@
**
*/
#ifdef HAVE_CONFIG_H
#if HAVE_CONFIG_H
#include "config.h"
#endif /*HAVE_CONFIG_H*/
@ -39,9 +39,7 @@
#include "mu-util.h"
#include "mu-util-db.h"
#include "mu-cmd.h"
#include "mu-output-plain.h"
#include "mu-output-link.h"
#include "mu-output.h"
static void
update_warning (void)
@ -52,14 +50,11 @@ update_warning (void)
}
static gboolean
print_xapian_query (MuQuery *xapian, const gchar *query)
{
char *querystr;
GError *err;
MU_WRITE_LOG ("query: '%s' (xquery)", query);
err = NULL;
querystr = mu_query_as_string (xapian, query, &err);
@ -95,55 +90,15 @@ sort_field_from_string (const char* fieldstr)
}
static size_t
print_rows (MuMsgIter *iter, const char *fields, size_t summary_len)
{
size_t count = 0;
if (mu_msg_iter_is_done (iter))
return 0;
do {
if (mu_output_plain_row (iter, fields, summary_len))
++count;
} while (mu_msg_iter_next (iter));
return count;
}
static size_t
make_links (MuMsgIter *iter, const char* linksdir, gboolean clearlinks)
{
size_t count = 0;
if (!mu_output_link_create_dir (linksdir, clearlinks))
return 0;
if (mu_msg_iter_is_done (iter))
return 0;
/* iterate over the found iters */
do {
/* ignore errors...*/
if (mu_output_link_row (iter, linksdir))
++count;
} while (mu_msg_iter_next (iter));
return count;
}
static gboolean
run_query (MuQuery *xapian, const gchar *query, MuConfigOptions *opts)
run_query (MuQuery *xapian, const gchar *query, MuConfig *opts,
size_t *count)
{
GError *err;
MuMsgIter *iter;
MuMsgFieldId sortid;
size_t matches;
gboolean rv;
sortid = MU_MSG_FIELD_ID_NONE;
if (opts->sortfield) {
@ -162,23 +117,24 @@ run_query (MuQuery *xapian, const gchar *query, MuConfigOptions *opts)
}
if (opts->linksdir)
matches = make_links (iter, opts->linksdir,
opts->clearlinks);
rv = mu_output_links (iter, opts->linksdir, opts->clearlinks,
count);
else
matches = print_rows (iter, opts->fields,
opts->summary_len);
rv = mu_output_plain (iter, opts->fields, opts->summary_len,
count);
if (matches == 0)
if (count && *count == 0)
g_warning ("no matches found");
mu_msg_iter_destroy (iter);
return matches > 0;
return rv;
}
static gboolean
query_params_valid (MuConfigOptions *opts)
query_params_valid (MuConfig *opts)
{
const gchar *xpath;
@ -200,7 +156,7 @@ query_params_valid (MuConfigOptions *opts)
}
static gchar*
resolve_bookmark (MuConfigOptions *opts)
resolve_bookmark (MuConfig *opts)
{
MuBookmarks *bm;
char* val;
@ -226,7 +182,7 @@ resolve_bookmark (MuConfigOptions *opts)
static gchar*
get_query (MuConfigOptions *opts)
get_query (MuConfig *opts)
{
gchar *query, *bookmarkval;
@ -274,46 +230,52 @@ db_is_ready (const char *xpath)
}
gboolean
mu_cmd_find (MuConfigOptions *opts)
MuExitCode
mu_cmd_find (MuConfig *opts)
{
GError *err;
MuQuery *xapian;
gboolean rv;
gchar *query;
const gchar *xpath;
size_t count;
g_return_val_if_fail (opts, FALSE);
g_return_val_if_fail (mu_cmd_equals (opts, "find"), FALSE);
g_return_val_if_fail (opts->cmd == MU_CONFIG_CMD_FIND, FALSE);
if (!query_params_valid (opts))
return FALSE;
return MU_EXITCODE_ERROR;
xpath = mu_runtime_xapian_dir ();
if (!db_is_ready(xpath))
return FALSE;
return MU_EXITCODE_ERROR;
/* first param is 'query', search params are after that */
query = get_query (opts);
if (!query)
return FALSE;
return MU_EXITCODE_ERROR;
err = NULL;
xapian = mu_query_new (xpath, &err);
if (!xapian) {
g_warning ("error: %s", err->message);
g_error_free (err);
return FALSE;
return MU_EXITCODE_ERROR;
}
if (opts->xquery)
rv = print_xapian_query (xapian, query);
else
rv = run_query (xapian, query, opts);
rv = run_query (xapian, query, opts, &count);
mu_query_destroy (xapian);
g_free (query);
return rv;
if (!rv)
return MU_EXITCODE_ERROR;
else if (count == 0)
return MU_EXITCODE_NO_MATCHES;
else
return MU_EXITCODE_OK;
}

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2008-2011 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
@ -17,7 +17,7 @@
**
*/
#ifdef HAVE_CONFIG_H
#if HAVE_CONFIG_H
#include "config.h"
#endif /*HAVE_CONFIG_H*/
@ -78,7 +78,7 @@ install_sig_handler (void)
static gboolean
check_index_or_cleanup_params (MuConfigOptions *opts)
check_index_or_cleanup_params (MuConfig *opts)
{
/* param[0] == 'index' or 'cleanup', there should be no
* param[1] */
@ -157,7 +157,7 @@ index_msg_cb (MuIndexStats* stats, void *user_data)
static gboolean
database_version_check_and_update (MuConfigOptions *opts)
database_version_check_and_update (MuConfig *opts)
{
const gchar *xpath;
@ -200,9 +200,8 @@ show_time (unsigned t, unsigned processed)
}
static gboolean
cmd_cleanup (MuIndex *midx, MuConfigOptions *opts, MuIndexStats *stats,
static MuExitCode
cmd_cleanup (MuIndex *midx, MuConfig *opts, MuIndexStats *stats,
gboolean show_progress)
{
MuResult rv;
@ -221,13 +220,14 @@ cmd_cleanup (MuIndex *midx, MuConfigOptions *opts, MuIndexStats *stats,
show_time ((unsigned)(time(NULL)-t),stats->_processed);
}
return (rv == MU_OK || rv == MU_STOP) ? TRUE: FALSE;
return (rv == MU_OK || rv == MU_STOP) ?
MU_EXITCODE_OK: MU_EXITCODE_ERROR;
}
static gboolean
cmd_index (MuIndex *midx, MuConfigOptions *opts, MuIndexStats *stats,
static MuExitCode
cmd_index (MuIndex *midx, MuConfig *opts, MuIndexStats *stats,
gboolean show_progress)
{
MuResult rv;
@ -257,16 +257,16 @@ cmd_index (MuIndex *midx, MuConfigOptions *opts, MuIndexStats *stats,
"cleaned-up: %u",
stats->_processed, stats->_updated,
stats->_cleaned_up);
return TRUE;
return MU_EXITCODE_OK;
}
return FALSE;
return MU_EXITCODE_ERROR;
}
static gboolean
cmd_index_or_cleanup (MuConfigOptions *opts)
static MuExitCode
cmd_index_or_cleanup (MuConfig *opts)
{
gboolean rv;
MuIndex *midx;
@ -274,21 +274,16 @@ cmd_index_or_cleanup (MuConfigOptions *opts)
gboolean show_progress;
GError *err;
g_return_val_if_fail (opts, FALSE);
g_return_val_if_fail (mu_cmd_equals (opts, "index") ||
mu_cmd_equals (opts, "cleanup"), FALSE);
if (!check_index_or_cleanup_params (opts) ||
!database_version_check_and_update(opts))
return FALSE;
return MU_EXITCODE_ERROR;
err = NULL;
if (!(midx = mu_index_new (mu_runtime_xapian_dir(), opts->xbatchsize,
&err))) {
g_warning ("index/cleanup failed: %s",
err->message);
if (!(midx = mu_index_new (mu_runtime_xapian_dir(),
opts->xbatchsize, &err))) {
g_warning ("index/cleanup failed: %s", err->message);
g_error_free (err);
return FALSE;
return MU_EXITCODE_ERROR;
}
/* note, 'opts->quiet' already cause g_message output not to
@ -298,34 +293,38 @@ cmd_index_or_cleanup (MuConfigOptions *opts)
mu_index_stats_clear (&stats);
install_sig_handler ();
if (mu_cmd_equals (opts, "index"))
rv = cmd_index (midx, opts, &stats, show_progress);
else if (mu_cmd_equals (opts, "cleanup"))
rv = cmd_cleanup (midx, opts, &stats, show_progress);
else
switch (opts->cmd) {
case MU_CONFIG_CMD_INDEX:
rv = cmd_index (midx, opts, &stats, show_progress); break;
case MU_CONFIG_CMD_CLEANUP:
rv = cmd_cleanup (midx, opts, &stats, show_progress); break;
default:
rv = MU_EXITCODE_ERROR;
g_assert_not_reached ();
}
mu_index_destroy (midx);
mu_index_destroy (midx);
return rv;
}
gboolean
mu_cmd_index (MuConfigOptions *opts)
MuExitCode
mu_cmd_index (MuConfig *opts)
{
g_return_val_if_fail (opts && mu_cmd_equals (opts, "index"),
g_return_val_if_fail (opts, FALSE);
g_return_val_if_fail (opts->cmd == MU_CONFIG_CMD_INDEX,
FALSE);
return cmd_index_or_cleanup (opts);
}
gboolean
mu_cmd_cleanup (MuConfigOptions *opts)
MuExitCode
mu_cmd_cleanup (MuConfig *opts)
{
g_return_val_if_fail (opts && mu_cmd_equals (opts, "cleanup"),
FALSE);
g_return_val_if_fail (opts, MU_EXITCODE_ERROR);
g_return_val_if_fail (opts->cmd != MU_CONFIG_CMD_CLEANUP,
MU_EXITCODE_ERROR);
return cmd_index_or_cleanup (opts);
}

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2008-2011 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
@ -17,7 +17,9 @@
**
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif /*HAVE_CONFIG_H*/
#include <unistd.h>
#include <stdio.h>
@ -27,22 +29,21 @@
#include "mu-maildir.h"
#include "mu-cmd.h"
#include "mu-util.h"
gboolean
mu_cmd_mkdir (MuConfigOptions *opts)
MuExitCode
mu_cmd_mkdir (MuConfig *opts)
{
int i;
g_return_val_if_fail (opts, FALSE);
g_return_val_if_fail (mu_cmd_equals (opts, "mkdir"), FALSE);
g_return_val_if_fail (opts, MU_EXITCODE_ERROR);
g_return_val_if_fail (opts->cmd == MU_CONFIG_CMD_MKDIR,
MU_EXITCODE_ERROR);
if (!opts->params[1]) {
g_warning (
"usage: mu mkdir [-u,--mode=<mode>] "
"<dir> [more dirs]");
return FALSE;
g_printerr ("usage: mu mkdir [-u,--mode=<mode>] "
"<dir> [more dirs]");
return MU_EXITCODE_ERROR;
}
i = 1;
@ -52,12 +53,12 @@ mu_cmd_mkdir (MuConfigOptions *opts)
if (!mu_maildir_mkdir (opts->params[i], opts->dirmode,
FALSE, &err))
if (err && err->message) {
g_warning ("%s", err->message);
g_printerr ("mu: %s", err->message);
g_error_free (err);
}
return FALSE;
return 1;
++i;
}
return TRUE;
return MU_EXITCODE_OK;
}

View File

@ -23,6 +23,8 @@
#include <glib.h>
#include "mu-config.h"
#error "foo"
/**
* execute the 'mkdir' command
*

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2008-2011 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
@ -17,7 +17,9 @@
**
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif /*HAVE_CONFIG_H*/
#include <unistd.h>
#include <stdio.h>
@ -28,7 +30,6 @@
#include "mu-msg.h"
#include "mu-str.h"
#include "mu-cmd.h"
#include "mu-util.h"
@ -63,21 +64,22 @@ view_msg (MuMsg *msg, const gchar *fields, size_t summary_len)
return TRUE;
}
gboolean
mu_cmd_view (MuConfigOptions *opts)
MuExitCode
mu_cmd_view (MuConfig *opts)
{
gboolean rv;
int i;
int rv, i;
g_return_val_if_fail (opts, MU_EXITCODE_ERROR);
g_return_val_if_fail (opts->cmd == MU_CONFIG_CMD_VIEW,
MU_EXITCODE_ERROR);
g_return_val_if_fail (opts, FALSE);
/* note: params[0] will be 'view' */
if (!opts->params[0] || !opts->params[1]) {
g_warning ("usage: mu view [options] <file> [<files>]");
return FALSE;
return MU_EXITCODE_ERROR;
}
rv = TRUE;
rv = MU_EXITCODE_OK;
for (i = 1; opts->params[i] && rv; ++i) {
GError *err = NULL;
@ -85,10 +87,12 @@ mu_cmd_view (MuConfigOptions *opts)
if (!msg) {
g_warning ("error: %s", err->message);
g_error_free (err);
return FALSE;
return MU_EXITCODE_ERROR;
}
rv = view_msg (msg, NULL, opts->summary_len);
if (!view_msg (msg, NULL, opts->summary_len))
rv = MU_EXITCODE_ERROR;
mu_msg_destroy (msg);
}

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2008-2011 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
@ -17,7 +17,9 @@
**
*/
#if HAVE_CONFIG_H
#include <config.h>
#endif /*HAVE_CONFIG_H*/
#include <unistd.h>
#include <stdio.h>
@ -44,10 +46,11 @@ static void
show_usage (gboolean noerror)
{
const char* usage=
"usage: mu [options] command [parameters]\n"
"usage: mu command [options] [parameters]\n"
"where command is one of index, find, view, mkdir, cleanup "
"or extract\n\n"
"see the mu or mu-easy manpages for more information\n";
"see the mu, mu-<command> or mu-easy manpages for "
"more information\n";
if (noerror)
g_print ("%s", usage);
@ -59,9 +62,11 @@ static void
show_version (void)
{
g_print ("mu (mail indexer/searcher) " VERSION "\n"
"Copyright (C) 2008-2010 Dirk-Jan C. Binnema (GPLv3+)\n");
"Copyright (C) 2008-2011 Dirk-Jan C. Binnema (GPLv3+)\n");
}
gboolean
mu_cmd_execute (MuConfigOptions *opts)
{
@ -87,6 +92,7 @@ mu_cmd_execute (MuConfigOptions *opts)
case MU_CONFIG_CMD_VIEW: return mu_cmd_view (opts);
case MU_CONFIG_CMD_UNKNOWN:
g_printerr ("mu: unknown command '%s'\n\n", opts->cmdstr);
show_usage (FALSE);
return FALSE;
default:

View File

@ -22,50 +22,19 @@
#define __MU_CMD_H__
#include <glib.h>
#include "mu-config.h"
#include <mu-config.h>
G_BEGIN_DECLS
enum _MuCmd {
MU_CMD_INDEX,
MU_CMD_FIND,
MU_CMD_CLEANUP,
MU_CMD_MKDIR,
MU_CMD_VIEW,
MU_CMD_EXTRACT,
MU_CMD_UNKNOWN
};
typedef enum _MuCmd MuCmd;
/**
* check whether the MuConfigOptions are for command X
*
* @param config the config options
* @param cmd the command to check (ie., "mkdir" or "find")
*
* @return TRUE if the options are for cmd, FALSE otherwise
*/
gboolean mu_cmd_equals (MuConfigOptions *config, const gchar *cmd);
/**
* try to execute whatever is specified on the command line
*
* @param config a config structure with the command line params
*
* @return TRUE if it succeeded, FALSE otherwise
*/
gboolean mu_cmd_execute (MuConfigOptions *config);
/**
* execute the 'mkdir' command
*
* @param opts configuration options
*
* @return TRUE if the command succeeded, FALSE otherwise
* @return MU_EXITCODE_OK (0) if the command succeeded,
* MU_EXITCODE_ERROR otherwise
*/
gboolean mu_cmd_mkdir (MuConfigOptions *opts);
MuExitCode mu_cmd_mkdir (MuConfig *opts);
/**
@ -73,9 +42,10 @@ gboolean mu_cmd_mkdir (MuConfigOptions *opts);
*
* @param opts configuration options
*
* @return TRUE if the command succeeded, FALSE otherwise
* @return MU_EXITCODE_OK (0) if the command succeeded,
* MU_EXITCODE_ERROR otherwise
*/
gboolean mu_cmd_view (MuConfigOptions *opts);
MuExitCode mu_cmd_view (MuConfig *opts);
/**
@ -83,9 +53,10 @@ gboolean mu_cmd_view (MuConfigOptions *opts);
*
* @param opts configuration options
*
* @return TRUE if the command succeede, FALSE otherwise
* @return MU_EXITCODE_OK (0) if the command succeeded,
* MU_EXITCODE_ERROR otherwise
*/
gboolean mu_cmd_index (MuConfigOptions *opts);
MuExitCode mu_cmd_index (MuConfig *opts);
/**
@ -93,19 +64,21 @@ gboolean mu_cmd_index (MuConfigOptions *opts);
*
* @param opts configuration options
*
* @return TRUE if the command succeede, FALSE otherwise
* @return MU_EXITCODE_OK (0) if the command succeeds,
* MU_EXITCODE_ERROR otherwise
*/
gboolean mu_cmd_cleanup (MuConfigOptions *opts);
MuExitCode mu_cmd_cleanup (MuConfig *opts);
/**
* execute the 'find' command
*
* @param opts configuration options
*
* @return TRUE if the command succeede, FALSE otherwise
* @return MU_EXITCODE_OK (0) if the command succeeds and
* >MU_EXITCODE_OK (0) results, MU_EXITCODE_NO_MATCHES if the command
* succeeds but there no matches, MU_EXITCODE_ERROR for all other errors
*/
gboolean mu_cmd_find (MuConfigOptions *opts);
MuExitCode mu_cmd_find (MuConfig *opts);
/**
@ -113,9 +86,11 @@ gboolean mu_cmd_find (MuConfigOptions *opts);
*
* @param opts configuration options
*
* @return TRUE if the command succeede, FALSE otherwise
* @return MU_EXITCODE_OK (0) if the command succeeds,
* MU_EXITCODE_ERROR otherwise
*/
gboolean mu_cmd_extract (MuConfigOptions *opts);
MuExitCode mu_cmd_extract (MuConfig *opts);
G_END_DECLS

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2008-2011 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
@ -26,9 +26,10 @@
#include "mu-util.h"
#include "mu-config.h"
#include "mu-cmd.h"
static void
set_group_mu_defaults (MuConfigOptions *opts)
set_group_mu_defaults (MuConfig *opts)
{
gchar *exp;
@ -43,7 +44,7 @@ set_group_mu_defaults (MuConfigOptions *opts)
}
static GOptionGroup*
config_options_group_mu (MuConfigOptions *opts)
config_options_group_mu (MuConfig *opts)
{
GOptionGroup *og;
GOptionEntry entries[] = {
@ -69,7 +70,7 @@ config_options_group_mu (MuConfigOptions *opts)
}
static void
set_group_index_defaults (MuConfigOptions * opts)
set_group_index_defaults (MuConfig * opts)
{
gchar *exp;
@ -86,7 +87,7 @@ set_group_index_defaults (MuConfigOptions * opts)
}
static GOptionGroup*
config_options_group_index (MuConfigOptions * opts)
config_options_group_index (MuConfig * opts)
{
GOptionGroup *og;
GOptionEntry entries[] = {
@ -115,7 +116,7 @@ config_options_group_index (MuConfigOptions * opts)
}
static void
set_group_find_defaults (MuConfigOptions *opts)
set_group_find_defaults (MuConfig *opts)
{
/* note, when no fields are specified, we use
* date-from-subject, and sort descending by date. If fields
@ -143,7 +144,7 @@ set_group_find_defaults (MuConfigOptions *opts)
}
static GOptionGroup*
config_options_group_find (MuConfigOptions *opts)
config_options_group_find (MuConfig *opts)
{
GOptionGroup *og;
GOptionEntry entries[] = {
@ -163,6 +164,8 @@ config_options_group_find (MuConfigOptions *opts)
"output as symbolic links to a target maildir", NULL},
{"clearlinks", 0, 0, G_OPTION_ARG_NONE, &opts->clearlinks,
"clear old links before filling a linksdir", NULL},
/* {"output", 'o', 0, G_OPTION_ARG_STRING, &opts->output, */
/* "output type ('plain'(*), 'links', 'xml', 'json', 'sexp')", NULL}, */
{NULL, 0, 0, 0, NULL, NULL, NULL}
};
@ -175,7 +178,7 @@ config_options_group_find (MuConfigOptions *opts)
}
static GOptionGroup *
config_options_group_mkdir (MuConfigOptions *opts)
config_options_group_mkdir (MuConfig *opts)
{
GOptionGroup *og;
GOptionEntry entries[] = {
@ -196,7 +199,7 @@ config_options_group_mkdir (MuConfigOptions *opts)
}
static GOptionGroup*
config_options_group_extract(MuConfigOptions *opts)
config_options_group_extract(MuConfig *opts)
{
GOptionGroup *og;
GOptionEntry entries[] = {
@ -225,54 +228,57 @@ config_options_group_extract(MuConfigOptions *opts)
}
static MuConfigCmd
cmd_from_params (int *argcp, char ***argvp)
gboolean
parse_cmd_from_params (MuConfig *opts,
int *argcp, char ***argvp)
{
int i;
const char *cmd;
typedef struct {
const gchar* _name;
MuConfigCmd _cmd;
} Cmd;
Cmd cmd_map[] = {
{ "index", MU_CONFIG_CMD_INDEX },
{ "find", MU_CONFIG_CMD_FIND },
{ "cleanup", MU_CONFIG_CMD_CLEANUP },
{ "mkdir", MU_CONFIG_CMD_MKDIR },
{ "view", MU_CONFIG_CMD_VIEW },
{ "extract", MU_CONFIG_CMD_EXTRACT }
};
int i;
typedef struct {
const gchar* _name;
MuConfigCmd _cmd;
} Cmd;
Cmd cmd_map[] = {
{ "index", MU_CONFIG_CMD_INDEX },
{ "find", MU_CONFIG_CMD_FIND },
{ "cleanup", MU_CONFIG_CMD_CLEANUP },
{ "mkdir", MU_CONFIG_CMD_MKDIR },
{ "view", MU_CONFIG_CMD_VIEW },
{ "extract", MU_CONFIG_CMD_EXTRACT }
};
opts->cmd = MU_CONFIG_CMD_NONE;
opts->cmdstr = NULL;
if (*argcp < 2) /* no command found at all */
return FALSE;
else if ((**argvp)[1] == '-')
/* if the first param starts with '-', there is no
* command, just some option (like --version, --help
* etc.)*/
return TRUE;
if (*argcp < 2)
return MU_CONFIG_CMD_UNKNOWN;
cmd = (*argvp)[1]; /* commmand or option */
for (i = 0; i != G_N_ELEMENTS(cmd_map); ++i)
if (strcmp (cmd, cmd_map[i]._name) == 0)
return cmd_map[i]._cmd;
opts->cmd = MU_CONFIG_CMD_UNKNOWN;
opts->cmdstr = (*argvp)[1];
for (i = 0; i != G_N_ELEMENTS(cmd_map); ++i)
if (strcmp (opts->cmdstr, cmd_map[i]._name) == 0)
opts->cmd = cmd_map[i]._cmd;
/* if the first param starts with '-', there is no command, just some option
* (like --version, --help etc.)*/
if (cmd[0] == '-')
return MU_CONFIG_CMD_NONE;
return MU_CONFIG_CMD_UNKNOWN;
return TRUE;
}
static gboolean
parse_params (MuConfigOptions *opts, int *argcp, char ***argvp)
parse_params (MuConfig *opts, int *argcp, char ***argvp)
{
GError *err;
GOptionContext *context;
gboolean rv;
opts->cmd = cmd_from_params (argcp, argvp);
if (opts->cmd == MU_CONFIG_CMD_UNKNOWN)
if (!parse_cmd_from_params (opts, argcp, argvp))
return FALSE;
context = g_option_context_new("- mu general option");
g_option_context_set_main_group(context, config_options_group_mu(opts));
@ -289,57 +295,115 @@ parse_params (MuConfigOptions *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_UNKNOWN:
default:
break;
}
err = NULL;
rv = g_option_context_parse(context, argcp, argvp, &err);
g_option_context_free (context);
if (!rv) {
/* use g_printerr here, as logging is not yet initialized */
if (opts->cmd != MU_CONFIG_CMD_NONE)
g_printerr ("error in options for command: %s\n", err->message);
else
g_printerr ("error in options: %s\n", err->message);
g_printerr ("mu: error in options: %s\n", err->message);
g_error_free(err);
return FALSE;
}
g_option_context_free(context);
/* fill in the defaults if user did not specify */
set_group_mu_defaults(opts);
set_group_index_defaults(opts);
set_group_find_defaults(opts);
/* set_group_mkdir_defaults (opts); */
return rv;
}
gboolean
mu_config_init (MuConfigOptions *opts, int *argcp, char ***argvp)
{
g_return_val_if_fail(opts, FALSE);
memset(opts, 0, sizeof(MuConfigOptions));
/* defaults are set in parse_params */
if (argcp && argvp)
if (!parse_params(opts, argcp, argvp))
return FALSE;
return TRUE;
}
void
mu_config_uninit (MuConfigOptions *opts)
MuConfig*
mu_config_new (int *argcp, char ***argvp)
{
g_return_if_fail(opts);
MuConfig *config;
config = g_new0 (MuConfig, 1);
/* defaults are set in parse_params */
if (argcp && argvp)
if (!parse_params(config, argcp, argvp)) {
mu_config_destroy (config);
return NULL;
}
return config;
}
void
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);
}
static void
show_usage (gboolean noerror)
{
const char* usage=
"usage: mu command [options] [parameters]\n"
"where command is one of index, find, view, mkdir, cleanup "
"or extract\n\n"
"see the mu, mu-<command> or mu-easy manpages for "
"more information\n";
if (noerror)
g_print ("%s", usage);
else
g_printerr ("%s", usage);
}
static void
show_version (void)
{
g_print ("mu (mail indexer/searcher) " VERSION "\n"
"Copyright (C) 2008-2011 Dirk-Jan C. Binnema (GPLv3+)\n");
}
MuExitCode
mu_config_execute (MuConfig *opts)
{
g_return_val_if_fail (opts, MU_EXITCODE_ERROR);
if (opts->version) {
show_version ();
return MU_EXITCODE_OK;
}
if (!opts->params||!opts->params[0]) {/* no command? */
show_version ();
g_print ("\n");
show_usage (TRUE);
return MU_EXITCODE_ERROR;
}
switch (opts->cmd) {
case MU_CONFIG_CMD_CLEANUP: return mu_cmd_cleanup (opts);
case MU_CONFIG_CMD_EXTRACT: return mu_cmd_extract (opts);
case MU_CONFIG_CMD_FIND: return mu_cmd_find (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_UNKNOWN:
g_printerr ("mu: unknown command '%s'\n\n", opts->cmdstr);
show_usage (FALSE);
return MU_EXITCODE_ERROR;
default:
g_return_val_if_reached (MU_EXITCODE_ERROR);
}
}

View File

@ -22,93 +22,107 @@
#include <glib.h>
#include <sys/types.h> /* for mode_t */
#include "mu-msg-fields.h"
#include <mu-msg-fields.h>
#include <mu-util.h>
G_BEGIN_DECLS
enum _MuConfigCmd {
MU_CONFIG_CMD_INDEX,
MU_CONFIG_CMD_FIND,
MU_CONFIG_CMD_CLEANUP,
MU_CONFIG_CMD_MKDIR,
MU_CONFIG_CMD_VIEW,
MU_CONFIG_CMD_EXTRACT,
MU_CONFIG_CMD_NONE,
MU_CONFIG_CMD_INDEX,
MU_CONFIG_CMD_FIND,
MU_CONFIG_CMD_CLEANUP,
MU_CONFIG_CMD_MKDIR,
MU_CONFIG_CMD_VIEW,
MU_CONFIG_CMD_EXTRACT,
MU_CONFIG_CMD_NONE,
MU_CONFIG_CMD_UNKNOWN
MU_CONFIG_CMD_UNKNOWN
};
typedef enum _MuConfigCmd MuConfigCmd;
/* struct with all configuration options for mu; it will be filled
* from the config file, and/or command line arguments */
struct _MuConfigOptions {
struct _MuConfig {
MuConfigCmd cmd; /* the command, or MU_CONFIG_CMD_NONE */
const char *cmdstr; /* cmd string, for user info */
MuConfigCmd cmd; /* the command, or
* MU_CONFIG_CMD_NONE */
const char *cmdstr; /* cmd string, for user info */
/* general options */
gboolean quiet; /* don't give any output */
gboolean debug; /* spew out debug info */
char *muhome; /* the House of Mu */
gboolean version; /* request mu version */
gboolean log_stderr; /* log to stderr (not logfile) */
gchar** params; /* parameters (for querying) */
/* general options */
gboolean quiet; /* don't give any output */
gboolean debug; /* spew out debug info */
char *muhome; /* the House of Mu */
gboolean version; /* request mu version */
gboolean log_stderr; /* log to stderr (not logfile) */
gchar** params; /* parameters (for querying) */
/* options for indexing */
char *maildir; /* where the mails are */
gboolean nocleanup; /* don't cleanup deleted mails from db */
gboolean reindex; /* re-index existing mails */
gboolean rebuild; /* empty the database before indexing */
gboolean autoupgrade; /* automatically upgrade db
* when needed */
int xbatchsize; /* batchsize for xapian commits, or 0 for default
* */
/* options for indexing */
char *maildir; /* where the mails are */
gboolean nocleanup; /* don't cleanup deleted mails from db */
gboolean reindex; /* re-index existing mails */
gboolean rebuild; /* empty the database before indexing */
gboolean autoupgrade; /* automatically upgrade db
* when needed */
int xbatchsize; /* batchsize for xapian
* commits, or 0 for
* default */
/* options for querying */
gboolean xquery; /* give the Xapian query instead of
search results */
char *fields; /* fields to show in output */
char *sortfield; /* field to sort by (string) */
gboolean descending; /* sort descending? */
unsigned summary_len; /* max # of lines of msg in summary */
char *bookmark; /* use bookmark */
/* output to a maildir with symlinks */
char *linksdir; /* maildir to output symlinks */
gboolean clearlinks; /* clear a linksdir before filling */
mode_t dirmode; /* mode for the created maildir */
/* options for querying */
gboolean xquery; /* give the Xapian query
instead of search
results */
char *fields; /* fields to show in output */
char *sortfield; /* field to sort by (string) */
gboolean descending; /* sort descending? */
unsigned summary_len; /* max # of lines of msg in summary */
char *bookmark; /* use bookmark */
/* options for extracting parts */
gboolean *save_all; /* extract all parts */
gboolean *save_attachments; /* extract all attachment parts */
gchar *parts; /* comma-sep'd list of parts to save */
char *targetdir; /* where to save the attachments */
gboolean overwrite; /* should we overwrite same-named files */
/* output to a maildir with symlinks */
char *linksdir; /* maildir to output symlinks */
gboolean clearlinks; /* clear a linksdir before filling */
mode_t dirmode; /* mode for the created maildir */
/* options for extracting parts */
gboolean *save_all; /* extract all parts */
gboolean *save_attachments; /* extract all attachment parts */
gchar *parts; /* comma-sep'd list of parts
* to save */
char *targetdir; /* where to save the attachments */
gboolean overwrite; /* should we overwrite same-named files */
};
typedef struct _MuConfigOptions MuConfigOptions;
typedef struct _MuConfig MuConfig;
/**
/**
* create a new mu config object
*
* set default values for the configuration options; when you call
* mu_config_init, you should also call mu_config_uninit when the data
* is no longer needed.
*
* @param opts options
*/
gboolean mu_config_init (MuConfigOptions *opts, int *argcp, char ***argvp);
MuConfig *mu_config_new (int *argcp, char ***argvp);
/**
* free the MuOptionsCOnfig structure; the the muhome and maildir
/**
* free the MuOptionsConfig structure; the the muhome and maildir
* members are heap-allocated, so must be freed.
*
* @param opts
* @param opts a MuConfig struct, or NULL
*/
void mu_config_uninit (MuConfigOptions *opts);
void mu_config_destroy (MuConfig *opts);
/**
* execute the command / options in this config
*
* @param opts the commands/options
*
* @return a value denoting the success/failure of the execution; MU_CONFIG_RETVAL_OK (0)
* for success, non-zero for a failure. This is to used for the exit
* code of the process
*/
MuExitCode mu_config_execute (MuConfig *opts);
G_END_DECLS

View File

@ -21,37 +21,9 @@
#ifndef __MU_ERROR_H__
#define __MU_ERROR_H__
enum _MuError {
/* general xapian related error */
MU_ERROR_XAPIAN,
/* xapian dir is not accessible */
MU_ERROR_XAPIAN_DIR,
/* database version is not uptodate (ie. not compatible with
* the version that mu expects) */
MU_ERROR_XAPIAN_NOT_UPTODATE,
/* missing data for a document */
MU_ERROR_XAPIAN_MISSING_DATA,
/* (parsnng) error in the query */
MU_ERROR_QUERY,
/* gmime parsing related error */
MU_ERROR_GMIME,
G_BEGIN_DECLS
/* File errors */
MU_ERROR_FILE_INVALID_SOURCE,
MU_ERROR_FILE_INVALID_NAME,
MU_ERROR_FILE_CANNOT_LINK,
MU_ERROR_FILE_CANNOT_OPEN,
MU_ERROR_FILE_CANNOT_READ,
MU_ERROR_FILE_CANNOT_CREATE,
MU_FILE_ERROR_CANNOT_MKDIR,
MU_FILE_ERROR_STAT_FAILED,
MU_FILE_ERROR_READDIR_FAILED,
/* generic file-related error */
MU_ERROR_FILE,
/* some other, internal error */
MU_ERROR_INTERNAL
};
typedef enum _MuError MuError;
G_END_DECLS
#endif /*__MU_ERROR_H__*/

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2008-2011 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
@ -22,8 +22,9 @@
#include <stdlib.h>
#include <glib.h>
#include <mu-util.h> /* for MuResult */
#include "mu-result.h" /* for MuResult */
G_BEGIN_DECLS
/* opaque structure */
struct _MuIndex;
@ -178,4 +179,6 @@ MuResult mu_index_cleanup (MuIndex *index, MuIndexStats *stats,
*/
gboolean mu_index_stats_clear (MuIndexStats *stats);
G_END_DECLS
#endif /*__MU_INDEX_H__*/

View File

@ -23,9 +23,7 @@
#include <glib.h>
#include <time.h>
#include <sys/types.h> /* for mode_t */
#include <mu-result.h> /* for MuResult */
#include <mu-error.h>
#include <mu-util.h> /* for MuResult, MuError */
G_BEGIN_DECLS

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2008-2011 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

View File

@ -91,7 +91,7 @@ mu_msg_file_get_flags_from_path (const char *path)
{
MuMsgFlags flags;
MsgType mtype;
char *info = NULL;
char *info = NULL, *cursor;
g_return_val_if_fail (path, MU_MSG_FLAG_NONE);
g_return_val_if_fail (!g_str_has_suffix(path, G_DIR_SEPARATOR_S),
@ -99,42 +99,29 @@ mu_msg_file_get_flags_from_path (const char *path)
mtype = check_msg_type (path, &info);
if (mtype == MSG_TYPE_NEW) { /* we ignore any new-msg flags */
g_free(info);
return MU_MSG_FLAG_NEW;
flags = MU_MSG_FLAG_NEW;
goto leave;
}
flags = MU_MSG_FLAG_NONE;
if (mtype == MSG_TYPE_CUR || mtype == MSG_TYPE_OTHER) {
char *cursor = info;
/* only support the "2," format */
if (cursor && cursor[0] == '2' && cursor[1] == ',') {
cursor += 2; /* jump past 2, */
for (; *cursor; ++cursor) {
switch (*cursor) {
case 'P':
flags |= MU_MSG_FLAG_PASSED;
break;
case 'T':
flags |= MU_MSG_FLAG_TRASHED;
break;
case 'R':
flags |= MU_MSG_FLAG_REPLIED;
break;
case 'S':
flags |= MU_MSG_FLAG_SEEN;
break;
case 'D':
flags |= MU_MSG_FLAG_DRAFT;
break;
case 'F':
flags |= MU_MSG_FLAG_FLAGGED;
break;
}
}
if ((mtype != MSG_TYPE_CUR && mtype != MSG_TYPE_OTHER) ||
!(info && info[0] == '2' && info[1] == ','))
goto leave;
for (cursor = info + 2; *cursor; ++cursor) {
switch (*cursor) {
case 'P': flags |= MU_MSG_FLAG_PASSED; break;
case 'T': flags |= MU_MSG_FLAG_TRASHED; break;
case 'R': flags |= MU_MSG_FLAG_REPLIED; break;
case 'S': flags |= MU_MSG_FLAG_SEEN; break;
case 'D': flags |= MU_MSG_FLAG_DRAFT; break;
case 'F': flags |= MU_MSG_FLAG_FLAGGED; break;
default: break; /* ignore */
}
}
g_free(info);
leave:
g_free(info);
return flags;
}

View File

@ -25,6 +25,8 @@
#include "mu-msg.h"
G_BEGIN_DECLS
/* we put the the MuMsg definition in this separate -priv file, so we
* can split the mu_msg implementations over separate files */
@ -57,4 +59,6 @@ struct _MuMsg {
MuMsgPrio _prio;
};
G_END_DECLS
#endif /*__MU_MSG_PRIV_H__*/

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2008-2011 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
@ -20,6 +20,8 @@
#ifndef __MU_MSG_STATUS_H__
#define __MU_MSG_STATUS_H__
G_BEGIN_DECLS
/* what kind of message is this; use by the indexer */
enum _MuMsgStatus {
MU_MSG_STATUS_NEW, /* message is new */
@ -31,4 +33,6 @@ enum _MuMsgStatus {
};
typedef enum _MuMsgStatus MuMsgStatus;
G_END_DECLS
#endif /*__MU_MSG_STATUS_H__*/

View File

@ -20,11 +20,11 @@
#ifndef __MU_MSG_H__
#define __MU_MSG_H__
#include "mu-msg-flags.h"
#include "mu-msg-fields.h"
#include "mu-msg-status.h"
#include "mu-msg-prio.h"
#include "mu-error.h"
#include <mu-msg-flags.h>
#include <mu-msg-fields.h>
#include <mu-msg-status.h>
#include <mu-msg-prio.h>
#include <mu-util.h> /* for MuResult, MuError */
G_BEGIN_DECLS
@ -32,7 +32,6 @@ struct _MuMsg;
typedef struct _MuMsg MuMsg;
/**
* initialize the GMime-system; this function needs to be called
* before doing anything else with MuMsg. mu_runtime_init will call

View File

@ -1,102 +0,0 @@
/*
** 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.
**
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /*HAVE_CONFIG_H*/
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include "mu-msg.h"
#include "mu-maildir.h"
#include "mu-index.h"
#include "mu-msg-iter.h"
#include "mu-util.h"
#include "mu-output-link.h"
/* create a linksdir if it not exist yet; if it already existed,
* remove old links if opts->clearlinks was specified */
gboolean
mu_output_link_create_dir (const char *linksdir, gboolean clearlinks)
{
GError *err;
g_return_val_if_fail (linksdir, FALSE);
err = NULL;
if (access (linksdir, F_OK) != 0) {
if (!mu_maildir_mkdir (linksdir, 0700, TRUE, &err))
goto fail;
} else if (clearlinks)
if (!mu_maildir_clear_links (linksdir, &err))
goto fail;
return TRUE;
fail:
if (err) {
g_warning ("%s", err->message ? err->message : "unknown error");
g_error_free (err);
}
return FALSE;
}
gboolean
mu_output_link_row (MuMsgIter *iter, const char* linksdir)
{
const char *path;
GError *err;
g_return_val_if_fail (iter, FALSE);
g_return_val_if_fail (linksdir, FALSE);
g_return_val_if_fail (!mu_msg_iter_is_done (iter), FALSE);
path = mu_msg_iter_get_field (iter, MU_MSG_FIELD_ID_PATH);
if (!path)
return FALSE;
/* this might happen if the database is not up-to-date, not an error */
if (access (path, R_OK) != 0) {
if (errno == ENOENT)
g_warning ("cannot find source message %s: "
"the database is not up-to-date", path);
else
g_warning ("cannot read source message %s: %s", path,
strerror (errno));
return FALSE;
}
err = NULL;
if (!mu_maildir_link (path, linksdir, &err)) {
if (err) {
g_warning ("%s", err->message ? err->message : "unknown error");
g_error_free (err);
}
return FALSE;
}
return TRUE;
}

View File

@ -1,45 +0,0 @@
/*
** Copyright (C) 2008-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.
**
*/
#ifndef __MU_OUTPUT_LINK_H__
#define __MU_OUTPUT_LINK_H__
/**
* create a target maildir to store the links if it does not exist yet
*
* @param linksdir path to the toplevel Maildir to create
* @param clearlinks if TRUE, clear any existing links in the target maildir
*
* @return TRUE if succeeded, FALSE otherwise
*/
gboolean mu_output_link_create_dir (const char *linksdir, gboolean clearlinks);
/**
* create a symlink for for a message. the target dir should already
* exist, use mu_output_link_create_dir if needed.
*
* @param iter iterator pointing to a message row
* @param fields the fields to print (see MuMsgFields)
* @param summary_len number of lines to include in message summary
*
* @return TRUE if the printing succeeded, FALSE in case of error
*/
gboolean mu_output_link_row (MuMsgIter *iter, const char *linksdir);
#endif /*__MU_OUTPUT_LINK_H__*/

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2008-2011 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
@ -17,7 +17,7 @@
**
*/
#ifdef HAVE_CONFIG_H
#if HAVE_CONFIG_H
#include "config.h"
#endif /*HAVE_CONFIG_H*/
@ -32,10 +32,6 @@
#include "mu-msg-iter.h"
#include "mu-str.h"
/* #include "mu-util.h" */
/* #include "mu-util-db.h" */
/* #include "mu-cmd.h" */
#include "mu-output-plain.h"

View File

@ -22,7 +22,7 @@
#include <glib.h>
#include <mu-msg-iter.h>
#include <mu-error.h>
#include <mu-util.h> /* for MuResult, MuError */
G_BEGIN_DECLS

View File

@ -20,11 +20,9 @@
#ifndef __MU_RESULT_H__
#define __MU_RESULT_H__
enum _MuResult {
MU_OK, /* all went ok */
MU_STOP, /* user wants to stop */
MU_ERROR /* some other error occured */
};
typedef enum _MuResult MuResult;
G_BEGIN_DECLS
G_END_DECLS
#endif /*__MU_RESULT__*/

View File

@ -39,7 +39,7 @@ struct _MuRuntimeData {
gchar *_muhome;
gchar *_xapian_dir;
gchar *_bookmarks_file;
MuConfigOptions *_config;
MuConfig *_config;
};
typedef struct _MuRuntimeData MuRuntimeData;
@ -98,7 +98,7 @@ mu_runtime_init (const char* muhome_arg)
static gboolean
init_log (MuConfigOptions *opts)
init_log (MuConfig *opts)
{
if (opts->log_stderr)
return mu_log_init_with_fd (fileno(stderr), FALSE,
@ -117,9 +117,8 @@ mu_runtime_init_from_cmdline (int *pargc, char ***pargv)
return FALSE;
_data = g_new0 (MuRuntimeData, 1);
_data->_config = g_new0 (MuConfigOptions, 1);
if (!mu_config_init (_data->_config, pargc, pargv)) {
_data->_config = mu_config_new (pargc, pargv);
if (!_data->_config) {
runtime_free ();
return FALSE;
}
@ -148,10 +147,7 @@ runtime_free (void)
g_free (_data->_xapian_dir);
g_free (_data->_muhome);
if (_data->_config) {
mu_config_uninit (_data->_config);
g_free (_data->_config);
}
mu_config_destroy (_data->_config);
mu_log_uninit();
@ -208,8 +204,8 @@ mu_runtime_bookmarks_file (void)
}
MuConfigOptions*
mu_runtime_config_options (void)
MuConfig*
mu_runtime_config (void)
{
g_return_val_if_fail (_initialized, NULL);

View File

@ -90,7 +90,7 @@ const char* mu_runtime_bookmarks_file (void);
*
* @return the configuration options
*/
MuConfigOptions* mu_runtime_config_options (void);
MuConfig* mu_runtime_config (void);
G_END_DECLS

View File

@ -22,10 +22,8 @@
#include <glib.h>
#include <inttypes.h>
#include <mu-result.h>
#include <mu-msg.h>
#include <mu-error.h>
#include <mu-util.h> /* for MuResult, MuError */
G_BEGIN_DECLS

View File

@ -225,9 +225,61 @@ unsigned char mu_util_get_dtype_with_lstat (const char *path);
G_STMT_START { \
g_log (G_LOG_DOMAIN, \
G_LOG_LEVEL_INFO, \
__VA_ARGS__); \
__VA_ARGS__); \
} G_STMT_END
enum _MuResult {
MU_OK, /* all went ok */
MU_STOP, /* user wants to stop */
MU_ERROR /* some other error occured */
};
typedef enum _MuResult MuResult;
enum _MuExitCode {
MU_EXITCODE_OK = 0,
MU_EXITCODE_ERROR = 1,
MU_EXITCODE_NO_MATCHES = 2
};
typedef enum _MuExitCode MuExitCode;
enum _MuError {
/* general xapian related error */
MU_ERROR_XAPIAN,
/* xapian dir is not accessible */
MU_ERROR_XAPIAN_DIR,
/* database version is not uptodate (ie. not compatible with
* the version that mu expects) */
MU_ERROR_XAPIAN_NOT_UPTODATE,
/* missing data for a document */
MU_ERROR_XAPIAN_MISSING_DATA,
/* (parsnng) error in the query */
MU_ERROR_QUERY,
/* gmime parsing related error */
MU_ERROR_GMIME,
/* File errors */
MU_ERROR_FILE_INVALID_SOURCE,
MU_ERROR_FILE_INVALID_NAME,
MU_ERROR_FILE_CANNOT_LINK,
MU_ERROR_FILE_CANNOT_OPEN,
MU_ERROR_FILE_CANNOT_READ,
MU_ERROR_FILE_CANNOT_CREATE,
MU_FILE_ERROR_CANNOT_MKDIR,
MU_FILE_ERROR_STAT_FAILED,
MU_FILE_ERROR_READDIR_FAILED,
/* generic file-related error */
MU_ERROR_FILE,
/* some other, internal error */
MU_ERROR_INTERNAL
};
typedef enum _MuError MuError;
G_END_DECLS
#endif /*__MU_UTIL_H__*/

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2008-2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2008-2011 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
@ -18,21 +18,20 @@
*/
#include <glib.h>
#include "mu-cmd.h"
#include "mu-runtime.h"
int
main (int argc, char *argv[])
{
gboolean rv;
int rv;
if (!mu_runtime_init_from_cmdline (&argc, &argv))
return 1;
rv = mu_cmd_execute (mu_runtime_config_options());
rv = mu_config_execute (mu_runtime_config());
mu_runtime_uninit ();
return rv ? 0 : 1;
return rv;
}

View File

@ -37,19 +37,19 @@ noinst_PROGRAMS= $(TEST_PROGS)
noinst_LTLIBRARIES=libtestmucommon.la
TEST_PROGS += test-mu-util
test_mu_util_SOURCES= test-mu-util.c
test_mu_util_SOURCES= test-mu-util.c dummy.cc
test_mu_util_LDADD= libtestmucommon.la
TEST_PROGS += test-mu-str
test_mu_str_SOURCES= test-mu-str.c
test_mu_str_SOURCES= test-mu-str.c dummy.cc
test_mu_str_LDADD= libtestmucommon.la
TEST_PROGS += test-mu-maildir
test_mu_maildir_SOURCES= test-mu-maildir.c
test_mu_maildir_SOURCES= test-mu-maildir.c dummy.cc
test_mu_maildir_LDADD= libtestmucommon.la
TEST_PROGS += test-mu-msg-fields
test_mu_msg_fields_SOURCES= test-mu-msg-fields.c
test_mu_msg_fields_SOURCES= test-mu-msg-fields.c dummy.cc
test_mu_msg_fields_LDADD= libtestmucommon.la
TEST_PROGS += test-mu-query
@ -61,11 +61,11 @@ test_mu_cmd_SOURCES= test-mu-cmd.c dummy.cc
test_mu_cmd_LDADD= libtestmucommon.la
TEST_PROGS += test-mu-msg
test_mu_msg_SOURCES= test-mu-msg.c
test_mu_msg_SOURCES= test-mu-msg.c dummy.cc
test_mu_msg_LDADD= libtestmucommon.la
TEST_PROGS += test-mu-runtime
test_mu_runtime_SOURCES= test-mu-runtime.c
test_mu_runtime_SOURCES= test-mu-runtime.c dummy.cc
test_mu_runtime_LDADD= libtestmucommon.la
TEST_PROGS += test-mu-store
@ -73,10 +73,9 @@ test_mu_store_SOURCES= test-mu-store.c dummy.cc
test_mu_store_LDADD= libtestmucommon.la
TEST_PROGS += test-mu-msg-file
test_mu_msg_file_SOURCES= test-mu-msg-file.c
test_mu_msg_file_SOURCES= test-mu-msg-file.c dummy.cc
test_mu_msg_file_LDADD= libtestmucommon.la
libtestmucommon_la_SOURCES= \
test-mu-common.c \
test-mu-common.h

View File

@ -204,6 +204,8 @@ test_mu_extract_01 (void)
G_DIR_SEPARATOR,
G_DIR_SEPARATOR);
/* g_print ("[%s]", cmdline) */
output = erroutput = NULL;
g_assert (g_spawn_command_line_sync (cmdline, &output, &erroutput, NULL, NULL));
g_assert_cmpstr (output,