diff --git a/man/mu-view.1 b/man/mu-view.1 index 9f5895f2..f7b62387 100644 --- a/man/mu-view.1 +++ b/man/mu-view.1 @@ -25,6 +25,11 @@ any). instead of displaying the full message, output a summary based upon the first lines of the message. +\fB\-\-separate\fR +add an ascii \\014 (0x0c, or \fIform-feed\fR) between messages when displaying +multiple messages. + + .SH BUGS Please report bugs if you find them: diff --git a/src/mu-cmd.c b/src/mu-cmd.c index b475284d..c0850e19 100644 --- a/src/mu-cmd.c +++ b/src/mu-cmd.c @@ -35,6 +35,8 @@ #include "mu-contacts.h" #include "mu-runtime.h" +#define VIEW_SEPARATOR '\f' /* form-feed */ + static void each_part (MuMsg *msg, MuMsgPart *part, gchar **attach) @@ -129,6 +131,34 @@ view_msg (MuMsg *msg, const gchar *fields, gboolean summary, 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 mu_cmd_view (MuConfig *opts) { @@ -144,21 +174,16 @@ mu_cmd_view (MuConfig *opts) return MU_EXITCODE_ERROR; } - ; - 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); + for (i = 1; opts->params[i]; ++i) { + + 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; } diff --git a/src/mu-config.c b/src/mu-config.c index a14cc08c..578bfee8 100644 --- a/src/mu-config.c +++ b/src/mu-config.c @@ -241,10 +241,12 @@ config_options_group_view (MuConfig *opts) GOptionEntry entries[] = { {"summary", 0, 0, G_OPTION_ARG_NONE, &opts->summary, "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} }; - og = g_option_group_new("cfind", "options for the 'cfind' command", + og = g_option_group_new("view", "options for the 'view' command", "", NULL, NULL); g_option_group_add_entries(og, entries); diff --git a/src/mu-config.h b/src/mu-config.h index bd92c77a..a6ada7d5 100644 --- a/src/mu-config.h +++ b/src/mu-config.h @@ -102,7 +102,12 @@ struct _MuConfig { char *bookmark; /* use bookmark */ char *formatstr; /* output type * (plain,links,xml,json,sexp) */ - + + /* options for view */ + gboolean separate; /* add separator between + * multiple messages in mu + * view */ + /* output to a maildir with symlinks */ char *linksdir; /* maildir to output symlinks */ gboolean clearlinks; /* clear a linksdir before filling */ diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index 262b7506..29ab71bb 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -115,6 +115,7 @@ EXTRA_DIST= \ testdir2/bar/cur/mail2 \ testdir2/bar/cur/mail3 \ testdir2/bar/cur/mail4 \ + testdir2/bar/cur/mail5 \ testdir2/Foo/cur/mail5 \ testdir2/Foo/cur/arto.eml diff --git a/src/tests/test-mu-cmd.c b/src/tests/test-mu-cmd.c index 402d9ee0..fb11781b 100644 --- a/src/tests/test-mu-cmd.c +++ b/src/tests/test-mu-cmd.c @@ -115,7 +115,7 @@ test_mu_index (void) store = mu_store_new (xpath, NULL, NULL); g_assert (store); - g_assert_cmpuint (mu_store_count (store), ==, 6); + g_assert_cmpuint (mu_store_count (store), ==, 7); mu_store_destroy (store); 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 test_mu_view_attach (void) { @@ -546,9 +621,11 @@ main (int argc, char *argv[]) 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-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-mkdir-01", test_mu_mkdir_01); g_log_set_handler (NULL, diff --git a/src/tests/testdir2/bar/cur/mail5 b/src/tests/testdir2/bar/cur/mail5 new file mode 100644 index 00000000..8ab972a7 --- /dev/null +++ b/src/tests/testdir2/bar/cur/mail5 @@ -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: + +123