1 #include "gmime-extra.h"
5 g_mime_stream_stdout_new()
7 GMimeStream *stream_stdout = NULL;
8 GMimeStream *stream_buffered = NULL;
10 stream_stdout = g_mime_stream_pipe_new (STDOUT_FILENO);
14 g_mime_stream_pipe_set_owner (GMIME_STREAM_PIPE (stream_stdout), FALSE);
16 stream_buffered = g_mime_stream_buffer_new (stream_stdout, GMIME_STREAM_BUFFER_BLOCK_WRITE);
18 g_object_unref (stream_stdout);
20 return stream_buffered;
24 * copy a glib string into a talloc context, and free it.
27 g_string_talloc_strdup (void *ctx, char *g_string)
29 char *new_str = talloc_strdup (ctx, g_string);
34 #if (GMIME_MAJOR_VERSION < 3)
37 g_mime_certificate_get_valid_userid (GMimeCertificate *cert)
39 /* output user id only if validity is FULL or ULTIMATE. */
40 /* note that gmime 2.6 is using the term "trust" here, which
41 * is WRONG. It's actually user id "validity". */
42 const char *name = g_mime_certificate_get_name (cert);
45 GMimeCertificateTrust trust = g_mime_certificate_get_trust (cert);
46 if (trust == GMIME_CERTIFICATE_TRUST_FULLY || trust == GMIME_CERTIFICATE_TRUST_ULTIMATE)
52 g_mime_message_get_address_string (GMimeMessage *message, GMimeRecipientType type)
54 InternetAddressList *list = g_mime_message_get_recipients (message, type);
55 return internet_address_list_to_string (list, 0);
58 inline InternetAddressList *
59 g_mime_message_get_addresses (GMimeMessage *message, GMimeRecipientType type)
61 return g_mime_message_get_recipients (message, type);
65 g_mime_message_get_date_string (void *ctx, GMimeMessage *message)
67 char *date = g_mime_message_get_date_as_string (message);
68 return g_string_talloc_strdup (ctx, date);
72 g_mime_message_get_from (GMimeMessage *message)
74 return internet_address_list_parse_string (g_mime_message_get_sender (message));
78 g_mime_message_get_from_string (GMimeMessage *message) {
79 return g_mime_message_get_sender (message);
83 g_mime_message_get_reply_to_list (GMimeMessage *message)
87 reply_to = g_mime_message_get_reply_to (message);
88 if (reply_to && *reply_to)
89 return internet_address_list_parse_string (reply_to);
95 * return talloc allocated reply-to string
98 g_mime_message_get_reply_to_string (void *ctx, GMimeMessage *message)
100 return talloc_strdup(ctx, g_mime_message_get_reply_to (message));
104 g_mime_signature_status_good (GMimeSignatureStatus status) {
105 return (status == GMIME_SIGNATURE_STATUS_GOOD);
109 g_mime_signature_status_bad (GMimeSignatureStatus status) {
110 return (status == GMIME_SIGNATURE_STATUS_BAD);
114 g_mime_signature_status_error (GMimeSignatureError error) {
115 return (error != GMIME_SIGNATURE_ERROR_NONE);
119 g_mime_utils_header_decode_date_unix (const char *date) {
120 return (gint64) g_mime_utils_header_decode_date (date, NULL);
123 #else /* GMime >= 3.0 */
126 g_mime_certificate_get_valid_userid (GMimeCertificate *cert)
128 /* output user id only if validity is FULL or ULTIMATE. */
129 const char *uid = g_mime_certificate_get_user_id (cert);
132 GMimeValidity validity = g_mime_certificate_get_id_validity (cert);
133 if (validity == GMIME_VALIDITY_FULL || validity == GMIME_VALIDITY_ULTIMATE)
139 g_mime_certificate_get_fpr16 (GMimeCertificate *cert) {
140 const char *fpr = g_mime_certificate_get_fingerprint (cert);
141 if (!fpr || strlen (fpr) < 16)
144 return fpr + (strlen (fpr) - 16);
148 g_mime_message_get_address_string (GMimeMessage *message, GMimeAddressType type)
150 InternetAddressList *list = g_mime_message_get_addresses (message, type);
151 return internet_address_list_to_string (list, NULL, 0);
155 g_mime_message_get_date_string (void *ctx, GMimeMessage *message)
157 GDateTime* parsed_date = g_mime_message_get_date (message);
159 char *date = g_mime_utils_header_format_date (parsed_date);
160 return g_string_talloc_strdup (ctx, date);
162 return talloc_strdup(ctx, "Thu, 01 Jan 1970 00:00:00 +0000");
166 InternetAddressList *
167 g_mime_message_get_reply_to_list(GMimeMessage *message)
169 return g_mime_message_get_reply_to (message);
173 g_mime_message_get_from_string (GMimeMessage *message)
175 return g_mime_object_get_header (GMIME_OBJECT (message), "From");
179 g_mime_message_get_reply_to_string (void *ctx, GMimeMessage *message)
181 InternetAddressList *list = g_mime_message_get_reply_to (message);
182 return g_string_talloc_strdup (ctx, internet_address_list_to_string (list, NULL, 0));
186 g_mime_parser_set_scan_from (GMimeParser *parser, gboolean flag)
188 g_mime_parser_set_format (parser, flag ? GMIME_FORMAT_MBOX : GMIME_FORMAT_MESSAGE);
191 /* In GMime 3.0, status GOOD and VALID both imply something about the
192 * validity of the UIDs attached to the signing key. This forces us to
193 * use following somewhat relaxed definition of a "good" signature to
194 * preserve current notmuch semantics.
198 g_mime_signature_status_good (GMimeSignatureStatus status) {
199 return ((status & (GMIME_SIGNATURE_STATUS_RED | GMIME_SIGNATURE_STATUS_ERROR_MASK)) == 0);
203 g_mime_signature_status_bad (GMimeSignatureStatus status) {
204 return (status & GMIME_SIGNATURE_STATUS_RED);
208 g_mime_signature_status_error (GMimeSignatureStatus status) {
209 return (status & GMIME_SIGNATURE_STATUS_ERROR_MASK);
213 g_mime_utils_header_decode_date_unix (const char *date) {
214 GDateTime* parsed_date = g_mime_utils_header_decode_date (date);
218 ret = g_date_time_to_unix (parsed_date);
219 g_date_time_unref (parsed_date);