1 #include "gmime-extra.h"
6 _gzfile_maybe_filter (GMimeStream *file_stream)
11 if ((bytes_read = g_mime_stream_read (file_stream, buf, sizeof (buf))) < 0)
14 if (g_mime_stream_reset (file_stream))
17 /* check for gzipped input */
18 if (bytes_read >= 2 && buf[0] == 0x1f && (unsigned char) buf[1] == 0x8b) {
19 GMimeStream *gzstream;
20 GMimeFilter *gzfilter;
22 gzfilter = g_mime_filter_gzip_new (GMIME_FILTER_GZIP_MODE_UNZIP, 0);
26 gzstream = g_mime_stream_filter_new (file_stream);
30 /* ignore filter id */
31 (void) g_mime_stream_filter_add ((GMimeStreamFilter *) gzstream, gzfilter);
32 g_object_unref (gzfilter);
33 g_object_unref (file_stream);
41 g_mime_stream_gzfile_new (int fd)
43 GMimeStream *file_stream;
45 file_stream = g_mime_stream_fs_new (fd);
49 return _gzfile_maybe_filter (file_stream);
53 g_mime_stream_gzfile_open (const char *filename)
55 GMimeStream *file_stream;
57 file_stream = g_mime_stream_fs_open (filename, 0, 0, NULL);
61 return _gzfile_maybe_filter (file_stream);
65 g_mime_stream_stdout_new ()
67 GMimeStream *stream_stdout = NULL;
68 GMimeStream *stream_buffered = NULL;
70 stream_stdout = g_mime_stream_pipe_new (STDOUT_FILENO);
74 g_mime_stream_pipe_set_owner (GMIME_STREAM_PIPE (stream_stdout), FALSE);
76 stream_buffered = g_mime_stream_buffer_new (stream_stdout, GMIME_STREAM_BUFFER_BLOCK_WRITE);
78 g_object_unref (stream_stdout);
80 return stream_buffered;
84 * copy a glib string into a talloc context, and free it.
87 g_string_talloc_strdup (void *ctx, char *g_string)
89 char *new_str = talloc_strdup (ctx, g_string);
96 g_mime_certificate_get_valid_userid (GMimeCertificate *cert)
98 /* output user id only if validity is FULL or ULTIMATE. */
99 const char *uid = g_mime_certificate_get_user_id (cert);
103 GMimeValidity validity = g_mime_certificate_get_id_validity (cert);
105 if (validity == GMIME_VALIDITY_FULL || validity == GMIME_VALIDITY_ULTIMATE)
111 g_mime_certificate_get_valid_email (GMimeCertificate *cert)
113 /* output e-mail address only if validity is FULL or ULTIMATE. */
114 const char *email = g_mime_certificate_get_email(cert);
118 GMimeValidity validity = g_mime_certificate_get_id_validity (cert);
120 if (validity == GMIME_VALIDITY_FULL || validity == GMIME_VALIDITY_ULTIMATE)
126 g_mime_certificate_get_fpr16 (GMimeCertificate *cert)
128 const char *fpr = g_mime_certificate_get_fingerprint (cert);
130 if (! fpr || strlen (fpr) < 16)
133 return fpr + (strlen (fpr) - 16);
137 g_mime_message_get_address_string (GMimeMessage *message, GMimeAddressType type)
139 InternetAddressList *list = g_mime_message_get_addresses (message, type);
141 return internet_address_list_to_string (list, NULL, 0);
145 g_mime_message_get_date_string (void *ctx, GMimeMessage *message)
147 GDateTime *parsed_date = g_mime_message_get_date (message);
150 char *date = g_mime_utils_header_format_date (parsed_date);
151 return g_string_talloc_strdup (ctx, date);
153 return talloc_strdup (ctx, "Thu, 01 Jan 1970 00:00:00 +0000");
157 InternetAddressList *
158 g_mime_message_get_reply_to_list (GMimeMessage *message)
160 return g_mime_message_get_reply_to (message);
164 g_mime_message_get_from_string (GMimeMessage *message)
166 return g_mime_object_get_header (GMIME_OBJECT (message), "From");
170 g_mime_message_get_reply_to_string (void *ctx, GMimeMessage *message)
172 InternetAddressList *list = g_mime_message_get_reply_to (message);
174 return g_string_talloc_strdup (ctx, internet_address_list_to_string (list, NULL, 0));
178 g_mime_parser_set_scan_from (GMimeParser *parser, gboolean flag)
180 g_mime_parser_set_format (parser, flag ? GMIME_FORMAT_MBOX : GMIME_FORMAT_MESSAGE);
183 /* In GMime 3.0, status GOOD and VALID both imply something about the
184 * validity of the UIDs attached to the signing key. This forces us to
185 * use following somewhat relaxed definition of a "good" signature to
186 * preserve current notmuch semantics.
190 g_mime_signature_status_good (GMimeSignatureStatus status)
192 return ((status & (GMIME_SIGNATURE_STATUS_RED | GMIME_SIGNATURE_STATUS_ERROR_MASK)) == 0);
196 g_mime_signature_status_bad (GMimeSignatureStatus status)
198 return (status & GMIME_SIGNATURE_STATUS_RED);
202 g_mime_signature_status_error (GMimeSignatureStatus status)
204 return (status & GMIME_SIGNATURE_STATUS_ERROR_MASK);
208 g_mime_utils_header_decode_date_unix (const char *date)
210 GDateTime *parsed_date = g_mime_utils_header_decode_date (date);
214 ret = g_date_time_to_unix (parsed_date);
215 g_date_time_unref (parsed_date);