* use the sexp export that moved to mu-msg-sexp

This commit is contained in:
Dirk-Jan C. Binnema 2011-07-31 12:17:14 +03:00
parent 5c2417a041
commit dabbfc3b62
4 changed files with 56 additions and 75 deletions

2
NEWS
View File

@ -23,7 +23,7 @@
wildcards
- remove --xquery completely; use --output=xquery instead
- fix progress info in 'mu index'
- display the references for a message using the 'r' character (mu find)
- display the references for a message using the 'r' character (xmu find)
- remove --summary-len/-k, instead use --summary for mu view and mu find, and
- support colorized output for some sub-commands (view, cfind and
extract). Disabled by default, use --color to enable, or set env

View File

@ -85,6 +85,7 @@ libmu_la_SOURCES= \
mu-msg-prio.c \
mu-msg-prio.h \
mu-msg-priv.h \
mu-msg-sexp.c \
mu-msg.c \
mu-msg.h \
mu-msg.h \

View File

@ -709,6 +709,38 @@ print_attr_xml (const char* elm, const char *str)
g_free (esc);
}
static gboolean
output_sexp (MuMsgIter *iter, size_t *count)
{
MuMsgIter *myiter;
size_t mycount;
g_return_val_if_fail (iter, FALSE);
for (myiter = iter, mycount = 0; !mu_msg_iter_is_done (myiter);
mu_msg_iter_next (myiter), ++mycount) {
MuMsg *msg;
char *sexp;
msg = mu_msg_iter_get_msg (iter, NULL); /* don't unref */
if (!msg)
return FALSE;
sexp = mu_msg_to_sexp (msg, TRUE);
fputs (sexp, stdout);
g_free (sexp);
}
if (count)
*count = mycount;
return TRUE;
}
static gboolean
output_xml (MuMsgIter *iter, size_t *count)
{
@ -761,7 +793,7 @@ print_attr_json (const char* elm, const char *str, gboolean comma)
if (!str || strlen(str) == 0)
return; /* empty: don't include */
esc = mu_str_escape_c_literal (str);
esc = mu_str_escape_c_literal (str, FALSE);
g_print ("\t\t\t\"%s\":\"%s\"%s\n", elm, esc, comma ? "," : "");
g_free (esc);
}
@ -793,6 +825,7 @@ output_json (MuMsgIter *iter, size_t *count)
print_attr_json ("to", mu_msg_get_to (msg),TRUE);
print_attr_json ("cc", mu_msg_get_cc (msg),TRUE);
print_attr_json ("subject", mu_msg_get_subject (msg), TRUE);
/* emacs likes it's date in a particular way... */
g_print ("\t\t\t\"date\":%u,\n",
(unsigned) mu_msg_get_date (msg));
g_print ("\t\t\t\"size\":%u,\n",
@ -811,74 +844,6 @@ output_json (MuMsgIter *iter, size_t *count)
}
static void
print_attr_sexp (const char* elm, const char *str, gboolean nl)
{
gchar *esc;
if (!str || strlen(str) == 0)
return; /* empty: don't include */
esc = mu_str_escape_c_literal (str);
g_print (" :%s \"%s\"%s", elm, esc, nl ? "\n" : "");
g_free (esc);
}
static void
output_sexp_date (time_t t)
{
unsigned date_high, date_low;
/* emacs likes it's date in a particular way... */
date_high = t >> 16;
date_low = t & 0xffff;
g_print (" :date %u\n", (unsigned)t);
g_print (" :date-high %u\n", date_high);
g_print (" :date-low %u\n", date_low);
}
static gboolean
output_sexp (MuMsgIter *iter, size_t *count)
{
MuMsgIter *myiter;
size_t mycount;
g_return_val_if_fail (iter, FALSE);
for (myiter = iter, mycount = 0; !mu_msg_iter_is_done (myiter);
mu_msg_iter_next (myiter), ++mycount) {
MuMsg *msg;
if (!(msg = mu_msg_iter_get_msg (iter, NULL))) /* don't unref */
return FALSE;
if (mycount != 0)
g_print ("\n");
g_print ("(%u\n", (unsigned)mycount);
print_attr_sexp ("from", mu_msg_get_from (msg),TRUE);
print_attr_sexp ("to", mu_msg_get_to (msg),TRUE);
print_attr_sexp ("cc", mu_msg_get_cc (msg),TRUE);
print_attr_sexp ("subject", mu_msg_get_subject (msg),TRUE);
output_sexp_date (mu_msg_get_date (msg));
g_print (" :size %u\n", (unsigned) mu_msg_get_size (msg));
print_attr_sexp ("msgid", mu_msg_get_msgid (msg),TRUE);
print_attr_sexp ("path", mu_msg_get_path (msg),TRUE);
print_attr_sexp ("maildir", mu_msg_get_maildir (msg),FALSE);
g_print (")\n;;eom");
}
fputs ("\n", stdout);
if (count)
*count = mycount;
return TRUE;
}
MuExitCode
mu_cmd_find (MuConfig *opts)
{

View File

@ -38,6 +38,14 @@
#define VIEW_TERMINATOR '\f' /* form-feed */
static gboolean
view_msg_sexp (MuMsg *msg)
{
fputs (mu_msg_to_sexp (msg, FALSE), stdout);
return TRUE;
}
static void
each_part (MuMsg *msg, MuMsgPart *part, gchar **attach)
{
@ -114,7 +122,7 @@ body_or_summary (MuMsg *msg, gboolean summary, gboolean color)
/* we ignore fields for now */
static gboolean
view_msg (MuMsg *msg, const gchar *fields, gboolean summary,
view_msg_plain (MuMsg *msg, const gchar *fields, gboolean summary,
gboolean color)
{
gchar *attachs;
@ -164,11 +172,18 @@ handle_msg (const char *fname, MuConfig *opts)
g_error_free (err);
return MU_EXITCODE_ERROR;
}
if (view_msg (msg, NULL, opts->summary, opts->color))
rv = MU_EXITCODE_OK;
else
switch (opts->format) {
case MU_CONFIG_FORMAT_PLAIN:
rv = view_msg_plain (msg, NULL, opts->summary, opts->color);
break;
case MU_CONFIG_FORMAT_SEXP:
rv = view_msg_sexp (msg);
break;
default:
g_critical ("bug: should not be reached");
rv = MU_EXITCODE_ERROR;
}
mu_msg_unref (msg);