Ejemplo n.º 1
0
notmuch_status_t
show_message_body (notmuch_message_t *message,
                   const notmuch_show_format_t *format,
                   notmuch_show_params_t *params)
{
    notmuch_status_t ret;
    show_message_state_t state;
    mime_node_t *root, *part;

    ret = mime_node_open (NULL, message, params->cryptoctx, params->decrypt,
                          &root);
    if (ret)
        return ret;

    /* The caller of show_message_body has already handled the
     * outermost envelope, so skip it. */
    state.part_count = MAX (params->part, 1);

    part = mime_node_seek_dfs (root, state.part_count);
    if (part)
        show_message_part (part, &state, format, TRUE);

    talloc_free (root);

    return NOTMUCH_STATUS_SUCCESS;
}
Ejemplo n.º 2
0
static int
notmuch_reply_format_sprinter(void *ctx,
			      notmuch_config_t *config,
			      notmuch_query_t *query,
			      notmuch_show_params_t *params,
			      notmuch_bool_t reply_all,
			      sprinter_t *sp)
{
    GMimeMessage *reply;
    notmuch_messages_t *messages;
    notmuch_message_t *message;
    mime_node_t *node;
    unsigned count;
    notmuch_status_t status;

    status = notmuch_query_count_messages_st (query, &count);
    if (print_status_query ("notmuch reply", query, status))
	return 1;

    if (count != 1) {
	fprintf (stderr, "Error: search term did not match precisely one message.\n");
	return 1;
    }

    status = notmuch_query_search_messages_st (query, &messages);
    if (print_status_query ("notmuch reply", query, status))
	return 1;

    message = notmuch_messages_get (messages);
    if (mime_node_open (ctx, message, &(params->crypto), &node) != NOTMUCH_STATUS_SUCCESS)
	return 1;

    reply = create_reply_message (ctx, config, message, reply_all);
    if (!reply)
	return 1;

    sp->begin_map (sp);

    /* The headers of the reply message we've created */
    sp->map_key (sp, "reply-headers");
    format_headers_sprinter (sp, reply, TRUE);
    g_object_unref (G_OBJECT (reply));
    reply = NULL;

    /* Start the original */
    sp->map_key (sp, "original");
    format_part_sprinter (ctx, sp, node, TRUE, TRUE, FALSE);

    /* End */
    sp->end (sp);
    notmuch_message_destroy (message);

    return 0;
}
Ejemplo n.º 3
0
static int
notmuch_reply_format_default(void *ctx,
			     notmuch_config_t *config,
			     notmuch_query_t *query,
			     notmuch_show_params_t *params,
			     notmuch_bool_t reply_all,
			     unused (sprinter_t *sp))
{
    GMimeMessage *reply;
    notmuch_messages_t *messages;
    notmuch_message_t *message;
    mime_node_t *root;
    notmuch_status_t status;

    status = notmuch_query_search_messages_st (query, &messages);
    if (print_status_query ("notmuch reply", query, status))
	return 1;

    for (;
	 notmuch_messages_valid (messages);
	 notmuch_messages_move_to_next (messages))
    {
	message = notmuch_messages_get (messages);

	reply = create_reply_message (ctx, config, message, reply_all);

	/* If reply creation failed, we're out of memory, so don't
	 * bother trying any more messages.
	 */
	if (!reply) {
	    notmuch_message_destroy (message);
	    return 1;
	}

	show_reply_headers (reply);

	g_object_unref (G_OBJECT (reply));
	reply = NULL;

	if (mime_node_open (ctx, message, &(params->crypto), &root) == NOTMUCH_STATUS_SUCCESS) {
	    format_part_reply (root);
	    talloc_free (root);
	}

	notmuch_message_destroy (message);
    }
    return 0;
}
Ejemplo n.º 4
0
static notmuch_status_t
show_message (void *ctx,
              const notmuch_show_format_t *format,
              notmuch_message_t *message,
              int indent,
              notmuch_show_params_t *params)
{
    void *local = talloc_new (ctx);
    mime_node_t *root, *part;
    notmuch_status_t status;

    status = mime_node_open (local, message, &(params->crypto), &root);
    if (status)
        goto DONE;
    part = mime_node_seek_dfs (root, (params->part < 0 ? 0 : params->part));
    if (part)
        status = format->part (local, part, indent, params);
DONE:
    talloc_free (local);
    return status;
}