diff options
| author | David Bremner <david@tethera.net> | 2017-05-04 08:48:44 -0400 |
|---|---|---|
| committer | David Bremner <david@tethera.net> | 2017-07-14 17:58:09 -0300 |
| commit | 67dbd24ece883e9cb0258fce289e40ca276b729d (patch) | |
| tree | 6c0c67d663156dbf2966a39061081e553c967645 /util | |
| parent | a58c75fdf6120aa3861e95a4a61fa268dee6a690 (diff) | |
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.
Diffstat (limited to 'util')
| -rw-r--r-- | util/gmime-extra.c | 35 | ||||
| -rw-r--r-- | util/gmime-extra.h | 8 |
2 files changed, 43 insertions, 0 deletions
diff --git a/util/gmime-extra.c b/util/gmime-extra.c index f1538587..01fe9e35 100644 --- a/util/gmime-extra.c +++ b/util/gmime-extra.c @@ -18,3 +18,38 @@ g_mime_stream_stdout_new() 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 diff --git a/util/gmime-extra.h b/util/gmime-extra.h index e0432a94..6e2f6ca5 100644 --- a/util/gmime-extra.h +++ b/util/gmime-extra.h @@ -3,4 +3,12 @@ #include <gmime/gmime.h> 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 |
