* add optional separator (\f, form-feed) between multiple messages in 'mu
view' when using --separate (fixes issue #41)
This commit is contained in:
@ -25,6 +25,11 @@ any).
|
|||||||
instead of displaying the full message, output a summary based upon the first
|
instead of displaying the full message, output a summary based upon the first
|
||||||
lines of the message.
|
lines of the message.
|
||||||
|
|
||||||
|
\fB\-\-separate\fR
|
||||||
|
add an ascii \\014 (0x0c, or \fIform-feed\fR) between messages when displaying
|
||||||
|
multiple messages.
|
||||||
|
|
||||||
|
|
||||||
.SH BUGS
|
.SH BUGS
|
||||||
|
|
||||||
Please report bugs if you find them:
|
Please report bugs if you find them:
|
||||||
|
|||||||
51
src/mu-cmd.c
51
src/mu-cmd.c
@ -35,6 +35,8 @@
|
|||||||
#include "mu-contacts.h"
|
#include "mu-contacts.h"
|
||||||
#include "mu-runtime.h"
|
#include "mu-runtime.h"
|
||||||
|
|
||||||
|
#define VIEW_SEPARATOR '\f' /* form-feed */
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
each_part (MuMsg *msg, MuMsgPart *part, gchar **attach)
|
each_part (MuMsg *msg, MuMsgPart *part, gchar **attach)
|
||||||
@ -129,6 +131,34 @@ view_msg (MuMsg *msg, const gchar *fields, gboolean summary,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static MuExitCode
|
||||||
|
handle_msg (const char *fname, MuConfig *opts)
|
||||||
|
{
|
||||||
|
GError *err;
|
||||||
|
MuMsg *msg;
|
||||||
|
MuExitCode rv;
|
||||||
|
|
||||||
|
err = NULL;
|
||||||
|
msg = mu_msg_new_from_file (fname, NULL, &err);
|
||||||
|
|
||||||
|
if (!msg) {
|
||||||
|
g_warning ("error: %s", err->message);
|
||||||
|
g_error_free (err);
|
||||||
|
return MU_EXITCODE_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (view_msg (msg, NULL, opts->summary, opts->color))
|
||||||
|
rv = MU_EXITCODE_OK;
|
||||||
|
else
|
||||||
|
rv = MU_EXITCODE_ERROR;
|
||||||
|
|
||||||
|
mu_msg_unref (msg);
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
MuExitCode
|
MuExitCode
|
||||||
mu_cmd_view (MuConfig *opts)
|
mu_cmd_view (MuConfig *opts)
|
||||||
{
|
{
|
||||||
@ -144,21 +174,16 @@ mu_cmd_view (MuConfig *opts)
|
|||||||
return MU_EXITCODE_ERROR;
|
return MU_EXITCODE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
;
|
for (i = 1; opts->params[i]; ++i) {
|
||||||
for (i = 1, rv = MU_EXITCODE_OK;
|
|
||||||
opts->params[i] && rv == MU_EXITCODE_OK; ++i) {
|
|
||||||
GError *err = NULL;
|
|
||||||
MuMsg *msg = mu_msg_new_from_file (opts->params[i], NULL, &err);
|
|
||||||
if (!msg) {
|
|
||||||
g_warning ("error: %s", err->message);
|
|
||||||
g_error_free (err);
|
|
||||||
return MU_EXITCODE_ERROR;
|
|
||||||
}
|
|
||||||
if (!view_msg (msg, NULL, opts->summary, opts->color))
|
|
||||||
rv = MU_EXITCODE_ERROR;
|
|
||||||
|
|
||||||
mu_msg_unref (msg);
|
rv = handle_msg (opts->params[i], opts);
|
||||||
|
if (rv != MU_EXITCODE_OK)
|
||||||
|
break;
|
||||||
|
/* add a separator between two messages? */
|
||||||
|
if (opts->params[i+1] && opts->separate)
|
||||||
|
g_print ("%c", VIEW_SEPARATOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -241,10 +241,12 @@ config_options_group_view (MuConfig *opts)
|
|||||||
GOptionEntry entries[] = {
|
GOptionEntry entries[] = {
|
||||||
{"summary", 0, 0, G_OPTION_ARG_NONE, &opts->summary,
|
{"summary", 0, 0, G_OPTION_ARG_NONE, &opts->summary,
|
||||||
"only show a short summary of the message (false)", NULL},
|
"only show a short summary of the message (false)", NULL},
|
||||||
|
{"separate", 0, 0, G_OPTION_ARG_NONE, &opts->separate,
|
||||||
|
"separate messages with ascii-0x07 (form-feed)", NULL},
|
||||||
{NULL, 0, 0, 0, NULL, NULL, NULL}
|
{NULL, 0, 0, 0, NULL, NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
og = g_option_group_new("cfind", "options for the 'cfind' command",
|
og = g_option_group_new("view", "options for the 'view' command",
|
||||||
"", NULL, NULL);
|
"", NULL, NULL);
|
||||||
g_option_group_add_entries(og, entries);
|
g_option_group_add_entries(og, entries);
|
||||||
|
|
||||||
|
|||||||
@ -103,6 +103,11 @@ struct _MuConfig {
|
|||||||
char *formatstr; /* output type
|
char *formatstr; /* output type
|
||||||
* (plain,links,xml,json,sexp) */
|
* (plain,links,xml,json,sexp) */
|
||||||
|
|
||||||
|
/* options for view */
|
||||||
|
gboolean separate; /* add separator between
|
||||||
|
* multiple messages in mu
|
||||||
|
* view */
|
||||||
|
|
||||||
/* output to a maildir with symlinks */
|
/* output to a maildir with symlinks */
|
||||||
char *linksdir; /* maildir to output symlinks */
|
char *linksdir; /* maildir to output symlinks */
|
||||||
gboolean clearlinks; /* clear a linksdir before filling */
|
gboolean clearlinks; /* clear a linksdir before filling */
|
||||||
|
|||||||
@ -115,6 +115,7 @@ EXTRA_DIST= \
|
|||||||
testdir2/bar/cur/mail2 \
|
testdir2/bar/cur/mail2 \
|
||||||
testdir2/bar/cur/mail3 \
|
testdir2/bar/cur/mail3 \
|
||||||
testdir2/bar/cur/mail4 \
|
testdir2/bar/cur/mail4 \
|
||||||
|
testdir2/bar/cur/mail5 \
|
||||||
testdir2/Foo/cur/mail5 \
|
testdir2/Foo/cur/mail5 \
|
||||||
testdir2/Foo/cur/arto.eml
|
testdir2/Foo/cur/arto.eml
|
||||||
|
|
||||||
|
|||||||
@ -115,7 +115,7 @@ test_mu_index (void)
|
|||||||
store = mu_store_new (xpath, NULL, NULL);
|
store = mu_store_new (xpath, NULL, NULL);
|
||||||
g_assert (store);
|
g_assert (store);
|
||||||
|
|
||||||
g_assert_cmpuint (mu_store_count (store), ==, 6);
|
g_assert_cmpuint (mu_store_count (store), ==, 7);
|
||||||
mu_store_destroy (store);
|
mu_store_destroy (store);
|
||||||
|
|
||||||
g_free (muhome);
|
g_free (muhome);
|
||||||
@ -453,6 +453,81 @@ test_mu_view_01 (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_mu_view_multi (void)
|
||||||
|
{
|
||||||
|
gchar *cmdline, *output, *tmpdir;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
tmpdir = test_mu_common_get_random_tmpdir();
|
||||||
|
g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0);
|
||||||
|
|
||||||
|
cmdline = g_strdup_printf ("%s view --muhome=%s "
|
||||||
|
"%s%cbar%ccur%cmail5 "
|
||||||
|
"%s%cbar%ccur%cmail5",
|
||||||
|
MU_PROGRAM,
|
||||||
|
tmpdir,
|
||||||
|
MU_TESTMAILDIR2,
|
||||||
|
G_DIR_SEPARATOR,
|
||||||
|
G_DIR_SEPARATOR,
|
||||||
|
G_DIR_SEPARATOR,
|
||||||
|
MU_TESTMAILDIR2,
|
||||||
|
G_DIR_SEPARATOR,
|
||||||
|
G_DIR_SEPARATOR,
|
||||||
|
G_DIR_SEPARATOR);
|
||||||
|
output = NULL;
|
||||||
|
g_assert (g_spawn_command_line_sync (cmdline, &output, NULL, NULL, NULL));
|
||||||
|
g_assert_cmpstr (output, !=, NULL);
|
||||||
|
|
||||||
|
len = strlen(output);
|
||||||
|
/* g_print ("\n[%s](%u)\n", output, len); */
|
||||||
|
g_assert_cmpuint (len,==,164);
|
||||||
|
|
||||||
|
g_free (output);
|
||||||
|
g_free (cmdline);
|
||||||
|
g_free (tmpdir);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_mu_view_multi_separate (void)
|
||||||
|
{
|
||||||
|
gchar *cmdline, *output, *tmpdir;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
tmpdir = test_mu_common_get_random_tmpdir();
|
||||||
|
g_assert (g_mkdir_with_parents (tmpdir, 0700) == 0);
|
||||||
|
|
||||||
|
cmdline = g_strdup_printf ("%s view --separate --muhome=%s "
|
||||||
|
"%s%cbar%ccur%cmail5 "
|
||||||
|
"%s%cbar%ccur%cmail5",
|
||||||
|
MU_PROGRAM,
|
||||||
|
tmpdir,
|
||||||
|
MU_TESTMAILDIR2,
|
||||||
|
G_DIR_SEPARATOR,
|
||||||
|
G_DIR_SEPARATOR,
|
||||||
|
G_DIR_SEPARATOR,
|
||||||
|
MU_TESTMAILDIR2,
|
||||||
|
G_DIR_SEPARATOR,
|
||||||
|
G_DIR_SEPARATOR,
|
||||||
|
G_DIR_SEPARATOR);
|
||||||
|
output = NULL;
|
||||||
|
g_assert (g_spawn_command_line_sync (cmdline, &output, NULL, NULL, NULL));
|
||||||
|
g_assert_cmpstr (output, !=, NULL);
|
||||||
|
|
||||||
|
len = strlen(output);
|
||||||
|
/* g_print ("\n[%s](%u)\n", output, len); */
|
||||||
|
g_assert_cmpuint (len,==,165);
|
||||||
|
|
||||||
|
|
||||||
|
g_free (output);
|
||||||
|
g_free (cmdline);
|
||||||
|
g_free (tmpdir);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_mu_view_attach (void)
|
test_mu_view_attach (void)
|
||||||
{
|
{
|
||||||
@ -546,9 +621,11 @@ main (int argc, char *argv[])
|
|||||||
test_mu_extract_by_name);
|
test_mu_extract_by_name);
|
||||||
|
|
||||||
g_test_add_func ("/mu-cmd/test-mu-view-01", test_mu_view_01);
|
g_test_add_func ("/mu-cmd/test-mu-view-01", test_mu_view_01);
|
||||||
|
g_test_add_func ("/mu-cmd/test-mu-view-multi",
|
||||||
|
test_mu_view_multi);
|
||||||
|
g_test_add_func ("/mu-cmd/test-mu-view-multi-separate",
|
||||||
|
test_mu_view_multi_separate);
|
||||||
g_test_add_func ("/mu-cmd/test-mu-view-attach", test_mu_view_attach);
|
g_test_add_func ("/mu-cmd/test-mu-view-attach", test_mu_view_attach);
|
||||||
|
|
||||||
|
|
||||||
g_test_add_func ("/mu-cmd/test-mu-mkdir-01", test_mu_mkdir_01);
|
g_test_add_func ("/mu-cmd/test-mu-mkdir-01", test_mu_mkdir_01);
|
||||||
|
|
||||||
g_log_set_handler (NULL,
|
g_log_set_handler (NULL,
|
||||||
|
|||||||
7
src/tests/testdir2/bar/cur/mail5
Normal file
7
src/tests/testdir2/bar/cur/mail5
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
Date: Mon, 13 Jun 2011 14:57:25 -0400
|
||||||
|
From: xyz@123.xx
|
||||||
|
Subject: abc
|
||||||
|
To: foo@bar.cx
|
||||||
|
Message-id: <abc@def>
|
||||||
|
|
||||||
|
123
|
||||||
Reference in New Issue
Block a user