1 /* notmuch - Not much of an email program, (just index and search)
3 * Copyright © 2009 Carl Worth
4 * Copyright © 2009 Keith Packard
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see http://www.gnu.org/licenses/ .
19 * Authors: Carl Worth <cworth@cworth.org>
20 * Keith Packard <keithp@keithp.com>
23 #include "notmuch-client.h"
25 typedef struct show_message_state {
27 } show_message_state_t;
30 show_message_part (mime_node_t *node,
31 show_message_state_t *state,
32 const notmuch_show_format_t *format,
35 /* Formatters expect the envelope for embedded message parts */
36 GMimeObject *part = node->envelope_part ?
37 GMIME_OBJECT (node->envelope_part) : node->part;
41 fputs (format->part_sep, stdout);
43 /* Format this part */
44 if (format->part_start)
45 format->part_start (part, &(state->part_count));
47 if (node->decrypt_attempted && format->part_encstatus)
48 format->part_encstatus (node->decrypt_success);
50 if (node->verify_attempted && format->part_sigstatus)
51 #ifdef GMIME_ATLEAST_26
52 format->part_sigstatus (node->sig_list);
54 format->part_sigstatus (node->sig_validity);
57 format->part_content (part);
59 if (node->envelope_part) {
60 fputs (format->header_start, stdout);
61 if (format->header_message_part)
62 format->header_message_part (GMIME_MESSAGE (node->part));
63 fputs (format->header_end, stdout);
65 fputs (format->body_start, stdout);
68 /* Recurse over the children */
69 state->part_count += 1;
70 for (i = 0; i < node->nchildren; i++)
71 show_message_part (mime_node_child (node, i), state, format, i == 0);
73 /* Finish this part */
74 if (node->envelope_part)
75 fputs (format->body_end, stdout);
78 format->part_end (part);
82 show_message_body (notmuch_message_t *message,
83 const notmuch_show_format_t *format,
84 notmuch_show_params_t *params)
87 show_message_state_t state;
88 mime_node_t *root, *part;
90 ret = mime_node_open (NULL, message, params->cryptoctx, params->decrypt,
95 /* The caller of show_message_body has already handled the
96 * outermost envelope, so skip it. */
97 state.part_count = MAX (params->part, 1);
99 part = mime_node_seek_dfs (root, state.part_count);
101 show_message_part (part, &state, format, TRUE);
105 return NOTMUCH_STATUS_SUCCESS;