X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=util%2Fgmime-extra.c;h=01fe9e35f979851c1184124a9fee248e42181e5b;hp=f1538587bf5a429e0d1cedc11279ae9353f84a06;hb=67dbd24ece883e9cb0258fce289e40ca276b729d;hpb=1e7dbf7abcf58407a5171e9030056f2ff9bec15a 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