* implement 'mu view'

This commit is contained in:
Dirk-Jan C. Binnema
2010-02-04 22:44:05 +02:00
parent fa08d66380
commit 9206894e02
3 changed files with 100 additions and 28 deletions

4
TODO
View File

@ -2,7 +2,7 @@
* Future release * Future release
** release 0.7 [81%] ** release 0.7 [90%]
- [X] signal handler for indexing - [X] signal handler for indexing
- [X] fix max 10000 matches limit - [X] fix max 10000 matches limit
@ -11,7 +11,7 @@
- [X] make 'make distcheck' work - [X] make 'make distcheck' work
- [ ] don't store both values and terms - [ ] don't store both values and terms
- [X] fix the batch stuff - [X] fix the batch stuff
- [ ] mu view <path> - [X] mu view <path>
- [X] basic test suite - [X] basic test suite
- [X] auto clean log file - [X] auto clean log file
- [X] configure error for missing ->dt_dtype - [X] configure error for missing ->dt_dtype

View File

@ -1,4 +1,4 @@
.TH MU 1 "January 2010" "User Manuals" .TH MU 1 "February 2010" "User Manuals"
.SH NAME .SH NAME
@ -8,22 +8,26 @@ mu \- index and search e-mail messages stored in Maildirs
.B mu index [options] .B mu index [options]
.B mu find [options] <search expression>
.B mu mkdir [options] <dir> [<dirs>]
.B mu cleanup [options] .B mu cleanup [options]
.B mu help [options] .B mu find [options] <search expression>
.B mu view <file> [<files>]
.B mu mkdir [options] <dir> [<dirs>]
.B mu [options] .B mu [options]
.SH DESCRIPTION .SH DESCRIPTION
\fBmu\fR is a set of tools for indexing and searching e-mail messages stored \fBmu\fR is a set of tools for dealing with e-mail messages in Maildirs.
in Maildirs. It does so by scanning a Maildir directory tree and analyzing the
e-mail messages found. The results of this analysis are stored in a database, Its main function is enable searching of e-mail messages. It does so by
which can then be queried. scanning a Maildir directory tree and analyzing the e-mail messages found. The
results of this analysis are stored in a database, which can then be queried.
In addition to indexing and searching, \fBmu\fR also offers functionality for
viewing messages and creating maildirs.
\fBmu\fR can be used from the command line, or can be integrated with e-mail \fBmu\fR can be used from the command line, or can be integrated with e-mail
clients. This manpage contains examples of both. clients. This manpage contains examples of both.
@ -40,14 +44,18 @@ information in a database
.TP .TP
\fBfind\fR \fBfind\fR
for finding messages in your database, using certain search parameters (see for finding messages in your database, using certain search parameters (see
below for details). below for details)
.TP
\fBview\fR
for displaying e-mail messages
.TP .TP
\fBmkdir\fR \fBmkdir\fR
for creating Maildirs. for creating Maildirs
.TP .TP
The various commands are discussed in more detail below. The various commands are discussed in more detail below
.SH GENERAL OPTIONS .SH GENERAL OPTIONS
@ -217,7 +225,8 @@ but the author has not seen it getting under 30,0000 messages per second).
.SH THE CLEANUP COMMAND .SH THE CLEANUP COMMAND
The \fBcleanup\fR command removes messages for which no corresponding file can The \fBcleanup\fR command removes messages for which no corresponding file can
be found, from the database. be found, from the database. Note that this is done automatically when running
\fBmu index\fR (unless \fB\-\-nocleanup\fR was specified).
.SH THE FIND COMMAND .SH THE FIND COMMAND
@ -469,12 +478,17 @@ typing 'Q' will start a query.
(message "Query failed"))) (message "Query failed")))
.fi .fi
.SH THE VIEW COMMAND
With the \fBview\fR command, you can view one or more e-mail messages as they
are stored as files on disk. It does not require or use the Xapian database.
Currently, the command shows some common headers (From:, To:, Cc:, Subject:
and Date:) and the plain-text body of the message.
.SH THE MKDIR COMMAND .SH THE MKDIR COMMAND
With the With the \fBmkdir\fR command, you can create new Maildirs with permissions
.B mkdir 0755. For example,
command, you can create new Maildirs with permissions 0755. For example,
.nf .nf
mu mkdir tom dick harry mu mkdir tom dick harry

View File

@ -41,7 +41,7 @@
static void static void
update_warning (void) update_warning (void)
{ {
g_warning ("the database needs to be updated to version %s", g_printerr ("the database needs to be updated to version %s\n",
MU_XAPIAN_DB_VERSION); MU_XAPIAN_DB_VERSION);
g_message ("please run 'mu index --empty' (see the manpage)"); g_message ("please run 'mu index --empty' (see the manpage)");
} }
@ -274,19 +274,19 @@ query_params_valid (MuConfigOptions *opts)
{ {
if (opts->linksdir) if (opts->linksdir)
if (opts->xquery) { if (opts->xquery) {
g_warning ("Invalid option for '--linksdir'"); g_printerr ("Invalid option for '--linksdir'\n");
return FALSE; return FALSE;
} }
if (!opts->params[0] || !opts->params[1]) { if (!opts->params[0] || !opts->params[1]) {
g_warning ("Missing search expression"); g_printerr ("Missing search expression\n");
return FALSE; return FALSE;
} }
if (mu_util_check_dir (opts->xpath, TRUE, FALSE)) if (mu_util_check_dir (opts->xpath, TRUE, FALSE))
return TRUE; return TRUE;
g_warning ("%s is not a readable Xapian directory", opts->xpath); g_printerr ("%s is not a readable Xapian directory\n", opts->xpath);
g_message ("Did you run 'mu index'?"); g_message ("Did you run 'mu index'?");
return FALSE; return FALSE;
@ -305,8 +305,8 @@ mu_cmd_find (MuConfigOptions *opts)
return FALSE; return FALSE;
if (mu_util_xapian_db_is_empty (opts->xpath)) { if (mu_util_xapian_db_is_empty (opts->xpath)) {
g_warning ("The database is empty; " g_printerr ("The database is empty; "
"use 'mu index' to add some messages"); "use 'mu index' to add some messages\n");
return FALSE; return FALSE;
} }
@ -322,7 +322,7 @@ mu_cmd_find (MuConfigOptions *opts)
xapian = mu_query_xapian_new (opts->xpath); xapian = mu_query_xapian_new (opts->xpath);
if (!xapian) { if (!xapian) {
g_warning ("Failed to create Xapian query"); g_printerr ("Failed to create a Xapian query\n");
mu_msg_gmime_uninit (); mu_msg_gmime_uninit ();
return FALSE; return FALSE;
} }
@ -335,13 +335,71 @@ mu_cmd_find (MuConfigOptions *opts)
return rv; return rv;
} }
/* we ignore fields for now */
static gboolean
view_file (const gchar *path, const gchar *fields)
{
MuMsgGMime* msg;
const char *field;
time_t date;
msg = mu_msg_gmime_new (path);
if (!msg)
return FALSE;
field = mu_msg_gmime_get_from (msg);
if (field)
g_print ("From: %s\n", field);
field = mu_msg_gmime_get_to (msg);
if (field)
g_print ("To: %s\n", field);
field = mu_msg_gmime_get_cc (msg);
if (field)
g_print ("Cc: %s\n", field);
field = mu_msg_gmime_get_subject (msg);
if (field)
g_print ("Subject: %s\n", field);
date = mu_msg_gmime_get_date (msg);
if (date)
g_print ("Date: %s\n",
mu_msg_str_date_s (date));
field = mu_msg_gmime_get_body_text (msg);
if (field)
g_print ("\n%s\n", field);
else
/* not really an error */
g_warning ("No text body found for %s", path);
mu_msg_gmime_destroy (msg);
return TRUE;
}
gboolean gboolean
mu_cmd_view (MuConfigOptions *opts) mu_cmd_view (MuConfigOptions *opts)
{ {
g_return_val_if_fail (opts, FALSE); gboolean rv;
int i;
return TRUE; /* FIXME */ g_return_val_if_fail (opts, FALSE);
/* note: params[0] will be 'view' */
if (!opts->params[0] || !opts->params[1]) {
g_printerr ("Missing files to view\n");
return FALSE;
}
mu_msg_gmime_init();
rv = TRUE;
for (i = 1; opts->params[i] && rv; ++i)
rv = view_file (opts->params[i], NULL);
mu_msg_gmime_uninit();
return rv;
} }