From 94010ec90c3b0b98cba6bc232c1b7673bfab7c1e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petr=20P=C3=ADsa=C5=99?= Date: Mon, 31 Dec 2012 11:08:23 +0100 Subject: [PATCH] `show' can print details about message list item In this context, you can pass message ID as argument to show details stored in the the message list. This action does not download the message. --- TODO | 1 + src/shigofumi.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 68 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index 95a3236..d949881 100644 --- a/TODO +++ b/TODO @@ -17,3 +17,4 @@ * Test message conversion * Test message re-signing * Test message composition by editor +* Test list item details diff --git a/src/shigofumi.c b/src/shigofumi.c index 1ef6a27..9b83e32 100644 --- a/src/shigofumi.c +++ b/src/shigofumi.c @@ -4027,12 +4027,76 @@ static int shi_save_stamp(int argc, const char **argv) { } +/* Return message of current message list identified by message ID expressed + * as string. In case of error return NULL. */ +static const struct isds_message *locate_message_by_id(const char *id_locale) { + char *id = NULL; + const struct isds_list *item; + const struct isds_message *message = NULL; + + if (NULL == id_locale) return NULL; + + id = locale2utf8(id_locale); + if (id == NULL) { + fprintf(stderr, _("Could not convert message ID `%s' to UTF-8\n"), + id_locale); + return NULL; + } + + if (NULL == messages) { + fprintf(stderr, _("No message list loaded\n")); + return NULL; + } + + /* Find message */ + for (item = messages; NULL != item; item = item->next) { + if (NULL == item->data) continue; + message = (const struct isds_message *) item->data; + if (NULL == message->envelope || NULL == message->envelope->dmID) + continue; + if (!strcmp(id, message->envelope->dmID)) { + break; + } + } + if (NULL == item) { + fprintf(stderr, _("List does not contain message `%s'\n"), id_locale); + return NULL; + } + + return message; +} + + +static void shi_show_list_usage(const char *command) { + oprintf(_( +"Usage: %s [MESSAGE_ID]\n" +"If no MESSAGE_ID is given, show current message list.\n" +"If MESSAGE_ID is specified, show details about message with the MESSAGE_ID\n" +"on the current message list.\n"), + command); +} + + static int shi_show_list(int argc, const char **argv) { - if (!messages) { + if (NULL == messages) { fprintf(stderr, _("No message list loaded\n")); return -1; } + if (argc > 2 || (2 == argc && NULL == argv[1])) { + shi_show_list_usage((argv[0] == NULL) ? NULL : argv[0]); + return -1; + } + + if (argc == 2) { + /* Show details about one message */ + const struct isds_message *message = locate_message_by_id(argv[1]); + if (NULL == message) return -1; + format_message(message); + return 0; + } + + /* Show all list */ oprintf((messages_are_outgoing) ? ngettext("You have %'lu outgoing message\n", "You have %'lu outgoing messages\n", total_messages) : @@ -4643,8 +4707,8 @@ struct command message_commands[] = { }; struct command list_commands[] = { - { "show", shi_show_list, N_("show current message list"), NULL, - ARGTYPE_NONE }, + { "show", shi_show_list, N_("show current message list or list item details"), + shi_show_list_usage, ARGTYPE_NONE }, COMMON_COMMANDS }; -- 2.11.4.GIT