* update: some refactoring of commands

This commit is contained in:
djcb
2010-08-20 21:07:36 +03:00
parent 7ea074431c
commit a4515de466
8 changed files with 202 additions and 185 deletions

View File

@ -35,7 +35,7 @@
#include "mu-util.h"
#include "mu-util-xapian.h"
#include "mu-cmd-find.h"
#include "mu-cmd.h"
static void
@ -358,79 +358,3 @@ mu_cmd_find (MuConfigOptions *opts)
return rv;
}
/* we ignore fields for now */
static gboolean
view_file (const gchar *path, const gchar *fields, size_t summary_len)
{
MuMsgGMime* msg;
const char *field;
time_t date;
msg = mu_msg_gmime_new (path, NULL);
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));
if (summary_len > 0) {
field = mu_msg_gmime_get_summary (msg, summary_len);
g_print ("Summary: %s\n", field ? field : "<none>");
} else {
field = mu_msg_gmime_get_body_text (msg);
if (field)
g_print ("\n%s\n", field);
else
/* not really an error */
g_debug ("No text body found for %s", path);
}
mu_msg_gmime_destroy (msg);
return TRUE;
}
gboolean
mu_cmd_view (MuConfigOptions *opts)
{
gboolean rv;
int i;
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,
opts->summary_len);
mu_msg_gmime_uninit();
return rv;
}