Skip to content

Commit

Permalink
* mu-cmd.c, test-mu-cmd.c: add attachment info to 'mu view' + unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
djcb committed May 21, 2011
1 parent c84baa1 commit e780431
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/mu-cmd.c
Expand Up @@ -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)))
Expand All @@ -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 */

Expand Down
33 changes: 33 additions & 0 deletions src/tests/test-mu-cmd.c
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit e780431

Please sign in to comment.