mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-24 20:08:10 +01:00
cli: replace use of g_mime_message_get_date_as_string
This function goes away in gmime-3.0. Also, the memory management is apparently error prone, witness the memory leak in notmuch-reply.
This commit is contained in:
parent
a58c75fdf6
commit
67dbd24ece
4 changed files with 46 additions and 7 deletions
|
@ -61,7 +61,7 @@ format_part_reply (GMimeStream *stream, mime_node_t *node)
|
||||||
recipients_string);
|
recipients_string);
|
||||||
g_free (recipients_string);
|
g_free (recipients_string);
|
||||||
g_mime_stream_printf (stream, "> Subject: %s\n", g_mime_message_get_subject (message));
|
g_mime_stream_printf (stream, "> Subject: %s\n", g_mime_message_get_subject (message));
|
||||||
g_mime_stream_printf (stream, "> Date: %s\n", g_mime_message_get_date_as_string (message));
|
g_mime_stream_printf (stream, "> Date: %s\n", g_mime_message_get_date_string (node, message));
|
||||||
g_mime_stream_printf (stream, ">\n");
|
g_mime_stream_printf (stream, ">\n");
|
||||||
} else if (GMIME_IS_PART (node->part)) {
|
} else if (GMIME_IS_PART (node->part)) {
|
||||||
GMimeContentType *content_type = g_mime_object_get_content_type (node->part);
|
GMimeContentType *content_type = g_mime_object_get_content_type (node->part);
|
||||||
|
|
|
@ -204,7 +204,6 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,
|
||||||
InternetAddressList *recipients;
|
InternetAddressList *recipients;
|
||||||
char *recipients_string;
|
char *recipients_string;
|
||||||
const char *reply_to_string;
|
const char *reply_to_string;
|
||||||
char *date_string;
|
|
||||||
|
|
||||||
sp->begin_map (sp);
|
sp->begin_map (sp);
|
||||||
|
|
||||||
|
@ -252,9 +251,7 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,
|
||||||
sp->string (sp, g_mime_object_get_header (GMIME_OBJECT (message), "References"));
|
sp->string (sp, g_mime_object_get_header (GMIME_OBJECT (message), "References"));
|
||||||
} else {
|
} else {
|
||||||
sp->map_key (sp, "Date");
|
sp->map_key (sp, "Date");
|
||||||
date_string = g_mime_message_get_date_as_string (message);
|
sp->string (sp, g_mime_message_get_date_string (sp, message));
|
||||||
sp->string (sp, date_string);
|
|
||||||
g_free (date_string);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sp->end (sp);
|
sp->end (sp);
|
||||||
|
@ -532,9 +529,8 @@ format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node,
|
||||||
if (recipients_string)
|
if (recipients_string)
|
||||||
g_mime_stream_printf (stream, "Cc: %s\n", recipients_string);
|
g_mime_stream_printf (stream, "Cc: %s\n", recipients_string);
|
||||||
g_free (recipients_string);
|
g_free (recipients_string);
|
||||||
date_string = g_mime_message_get_date_as_string (message);
|
date_string = g_mime_message_get_date_string (node, message);
|
||||||
g_mime_stream_printf (stream, "Date: %s\n", date_string);
|
g_mime_stream_printf (stream, "Date: %s\n", date_string);
|
||||||
g_free (date_string);
|
|
||||||
g_mime_stream_printf (stream, "\fheader}\n");
|
g_mime_stream_printf (stream, "\fheader}\n");
|
||||||
|
|
||||||
g_mime_stream_printf (stream, "\fbody{\n");
|
g_mime_stream_printf (stream, "\fbody{\n");
|
||||||
|
|
|
@ -18,3 +18,38 @@ g_mime_stream_stdout_new()
|
||||||
|
|
||||||
return stream_buffered;
|
return stream_buffered;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* copy a glib string into a talloc context, and free it.
|
||||||
|
*/
|
||||||
|
static char*
|
||||||
|
g_string_talloc_strdup (void *ctx, char *g_string)
|
||||||
|
{
|
||||||
|
char *new_str = talloc_strdup (ctx, g_string);
|
||||||
|
g_free (g_string);
|
||||||
|
return new_str;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if (GMIME_MAJOR_VERSION < 3)
|
||||||
|
|
||||||
|
char *
|
||||||
|
g_mime_message_get_date_string (void *ctx, GMimeMessage *message)
|
||||||
|
{
|
||||||
|
char *date = g_mime_message_get_date_as_string (message);
|
||||||
|
return g_string_talloc_strdup (ctx, date);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else /* GMime >= 3.0 */
|
||||||
|
|
||||||
|
char *
|
||||||
|
g_mime_message_get_date_string (void *ctx, GMimeMessage *message)
|
||||||
|
{
|
||||||
|
GDateTime* parsed_date = g_mime_message_get_date (message);
|
||||||
|
if (parsed_date) {
|
||||||
|
char *date = g_mime_utils_header_format_date (parsed_date);
|
||||||
|
return g_string_talloc_strdup (ctx, date);
|
||||||
|
} else {
|
||||||
|
return talloc_strdup(ctx, "Thu, 01 Jan 1970 00:00:00 +0000");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -3,4 +3,12 @@
|
||||||
#include <gmime/gmime.h>
|
#include <gmime/gmime.h>
|
||||||
|
|
||||||
GMimeStream *g_mime_stream_stdout_new(void);
|
GMimeStream *g_mime_stream_stdout_new(void);
|
||||||
|
|
||||||
|
#include <talloc.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return talloc allocated date string
|
||||||
|
*/
|
||||||
|
char *g_mime_message_get_date_string (void *ctx, GMimeMessage *message);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue