/* 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 https://www.gnu.org/licenses/ .
*
* Author: Carl Worth <cworth@cworth.org>
*/
#include "notmuch-client.h"
#include "gmime-filter-reply.h"
#include "sprinter.h"
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 ? "" : " ", tag);
first = 0;
}
return result;
}
/* Get a nice, single-line summary of message. */
static const char *
_get_one_line_summary (const void *ctx, notmuch_message_t *message)
{
const char *from;
time_t date;
const char *relative_date;
const char *tags;
from = notmuch_message_get_header (message, "from");
date = notmuch_message_get_date (message);
relative_date = notmuch_time_relative_date (ctx, date);
tags = _get_tags_as_string (ctx, message);
return talloc_asprintf (ctx, "%s (%s) (%s)",
from, relative_date, tags);
}
static const char *_get_disposition(GMimeObject *meta)
{
GMimeContentDisposition *disposition;
disposition = g_mime_object_get_content_disposition (meta);
if (!disposition)
return NULL;
return g_mime_content_disposition_get_disposition (disposition);
}
/* Emit a sequence of key/value pairs for the metadata of message.
* The caller should begin a map before calling this. */
static void
format_message_sprinter (sprinter_t *sp, notmuch_message_t *message)
{
/* Any changes to the JSON or S-Expression format should be
* reflected in the file devel/schemata. */
void *local = talloc_new (NULL);
notmuch_tags_t *tags;
time_t date;
const char *relative_date;
sp->map_key (sp, "id");
sp->string (sp, notmuch_message_get_message_id (message