]> git.notmuchmail.org Git - notmuch/blob - util/gmime-extra.c
01fe9e35f979851c1184124a9fee248e42181e5b
[notmuch] / util / gmime-extra.c
1 #include "gmime-extra.h"
2
3 GMimeStream *
4 g_mime_stream_stdout_new()
5 {
6     GMimeStream *stream_stdout = NULL;
7     GMimeStream *stream_buffered = NULL;
8
9     stream_stdout = g_mime_stream_pipe_new (STDOUT_FILENO);
10     if (!stream_stdout)
11         return NULL;
12
13     g_mime_stream_pipe_set_owner (GMIME_STREAM_PIPE (stream_stdout), FALSE);
14
15     stream_buffered = g_mime_stream_buffer_new (stream_stdout, GMIME_STREAM_BUFFER_BLOCK_WRITE);
16
17     g_object_unref (stream_stdout);
18
19     return stream_buffered;
20 }
21
22 /**
23  * copy a glib string into a talloc context, and free it.
24  */
25 static char*
26 g_string_talloc_strdup (void *ctx, char *g_string)
27 {
28     char *new_str = talloc_strdup (ctx, g_string);
29     g_free (g_string);
30     return new_str;
31 }
32
33 #if (GMIME_MAJOR_VERSION < 3)
34
35 char *
36 g_mime_message_get_date_string (void *ctx, GMimeMessage *message)
37 {
38     char *date = g_mime_message_get_date_as_string (message);
39     return g_string_talloc_strdup (ctx, date);
40 }
41
42 #else /* GMime >= 3.0 */
43
44 char *
45 g_mime_message_get_date_string (void *ctx, GMimeMessage *message)
46 {
47     GDateTime* parsed_date = g_mime_message_get_date (message);
48     if (parsed_date) {
49         char *date = g_mime_utils_header_format_date (parsed_date);
50         return g_string_talloc_strdup (ctx, date);
51     } else {
52         return talloc_strdup(ctx, "Thu, 01 Jan 1970 00:00:00 +0000");
53     }
54 }
55 #endif