* mu-cmd.c, test-mu-cmd.c: add attachment info to 'mu view' + unit test
This commit is contained in:
38
src/mu-cmd.c
38
src/mu-cmd.c
@ -32,11 +32,44 @@
|
||||
#include "mu-contacts.h"
|
||||
#include "mu-runtime.h"
|
||||
|
||||
|
||||
static void
|
||||
each_part (MuMsg *msg, MuMsgPart *part, gchar **attach)
|
||||
{
|
||||
if (mu_msg_part_looks_like_attachment (part, TRUE) &&
|
||||
(part->file_name)) {
|
||||
|
||||
char *tmp = *attach;
|
||||
|
||||
*attach = g_strdup_printf ("%s%s'%s'",
|
||||
*attach ? *attach : "",
|
||||
*attach ? ", " : "",
|
||||
part->file_name);
|
||||
g_free (tmp);
|
||||
}
|
||||
}
|
||||
|
||||
/* return comma-sep'd list of attachments */
|
||||
gchar *
|
||||
get_attach_str (MuMsg *msg)
|
||||
{
|
||||
gchar *attach;
|
||||
|
||||
attach = NULL;
|
||||
mu_msg_part_foreach (msg, (MuMsgPartForeachFunc)each_part, &attach);
|
||||
|
||||
return attach;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* we ignore fields for now */
|
||||
static gboolean
|
||||
view_msg (MuMsg *msg, const gchar *fields, size_t summary_len)
|
||||
{
|
||||
const char *field;
|
||||
gchar *attachs;
|
||||
time_t date;
|
||||
|
||||
if ((field = mu_msg_get_from (msg)))
|
||||
@ -54,6 +87,11 @@ view_msg (MuMsg *msg, const gchar *fields, size_t summary_len)
|
||||
if ((date = mu_msg_get_date (msg)))
|
||||
g_print ("Date: %s\n", mu_str_date_s ("%c", date));
|
||||
|
||||
if ((attachs = get_attach_str (msg))) {
|
||||
g_print ("Attachment(s): %s\n", attachs);
|
||||
g_free (attachs);
|
||||
}
|
||||
|
||||
if (!(field = mu_msg_get_body_text (msg)))
|
||||
return TRUE; /* no body -- nothing more to do */
|
||||
|
||||
|
||||
@ -451,6 +451,36 @@ test_mu_view_01 (void)
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
test_mu_view_attach (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%cFoo%ccur%cmail5",
|
||||
MU_PROGRAM,
|
||||
tmpdir,
|
||||
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] (%d)\n", output, len); */
|
||||
g_assert (len == 170);
|
||||
|
||||
g_free (output);
|
||||
g_free (cmdline);
|
||||
g_free (tmpdir);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static void
|
||||
@ -514,6 +544,9 @@ 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-attach", test_mu_view_attach);
|
||||
|
||||
|
||||
g_test_add_func ("/mu-cmd/test-mu-mkdir-01", test_mu_mkdir_01);
|
||||
|
||||
g_log_set_handler (NULL,
|
||||
|
||||
Reference in New Issue
Block a user