/* notmuch - Not much of an email program, (just index and search)
*
* Copyright © 2009 Carl Worth
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/ .
*
* Author: Carl Worth <cworth@cworth.org>
*/
#include "notmuch-client.h"
static void
format_message_text (unused (const void *ctx),
notmuch_message_t *message,
int indent);
static void
format_headers_text (const void *ctx,
notmuch_message_t *message);
static void
format_headers_message_part_text (GMimeMessage *message);
static void
format_part_start_text (GMimeObject *part,
int *part_count);
static void
format_part_content_text (GMimeObject *part);
static void
format_part_end_text (GMimeObject *part);
static const notmuch_show_format_t format_text = {
"",
"\fmessage{ ", format_message_text,
"\fheader{\n", format_headers_text, format_headers_message_part_text, "\fheader}\n",
"\fbody{\n",
format_part_start_text,
NULL,
NULL,
format_part_content_text,
format_part_end_text,
"",
"\fbody}\n",
"\fmessage}\n", "",
""
};
static void
format_message_json (const void *ctx,
notmuch_message_t *message,
unused (int indent));
static void
format_headers_json (const void *ctx,
notmuch_message_t *message);
static void
format_headers_message_part_json (GMimeMessage *message);
static void
format_part_start_json (unused (GMimeObject *part),
int *part_count);
static void
format_part_encstatus_json (int status);
static void
format_part_sigstatus_json (const GMimeSignatureValidity* validity);
static void
format_part_content_json (GMimeObject *part);
static void
format_part_end_json (GMimeObject *part);
static const notmuch_show_format_t format_json = {
"[",
"{", format_message_json,
"\"headers\": {", format_headers_json, format_headers_message_part_json, "}",
", \"body\": [",
format_part_start_json,
format_part_encstatus_json,
format_part_sigstatus_json,
format_part_content_json,
format_part_end_json,
", ",
"]",
"}", ", ",
"]"
};
static void
format_message_mbox (const void *ctx,
notmuch_message_t *message,
unused (int indent));
static const notmuch_show_format_t format_mbox = {
"",
"", format_message_mbox,
"", NULL, NULL, "",
"",
NULL,
NULL,
NULL,
NULL,
NULL,
"",
"",
"", "",
""
};
static void
format_part_content_raw (GMimeObject *part);
static const notmuch_show_format_t format_raw = {
"",
"", NULL,
"", NULL, format_headers_message_part_text, "\n",
"",
NULL,
NULL,
NULL,
format_part_content_raw,
NULL,
"",
"",
"", "",
""
};
static const char *
_get_tags_as_string (const void *ctx, notmuch_message_t *message)
{
notmuch_tags_t *tags;
int first = 1;
const char *tag;
char *result;
result = talloc_strdup (ctx, "");
if (result == NULL)
return NULL;
for (tags = notmuch_message_get_tags (message);
notmuch_tags_valid (tags);
notmuch_tags_move_to_next (tags))
{
tag = notmuch_tags_get (tags);
result = talloc_asprintf_append (result, "%s%s",
first ?