X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=util%2Fgmime-extra.c;h=bc1e3c4d94bb75b04c7b24c8e8816770a7e83434;hp=350f75ea8a4ce1bd640e3ade4de00b8701c6bc4c;hb=5d510221d17862a252955d98046508bebcd14573;hpb=c7b9bdb81e49321170dc6f0a522301f28e791521 diff --git a/util/gmime-extra.c b/util/gmime-extra.c index 350f75ea..bc1e3c4d 100644 --- a/util/gmime-extra.c +++ b/util/gmime-extra.c @@ -1,4 +1,5 @@ #include "gmime-extra.h" +#include GMimeStream * g_mime_stream_stdout_new() @@ -32,6 +33,21 @@ g_string_talloc_strdup (void *ctx, char *g_string) #if (GMIME_MAJOR_VERSION < 3) +const char * +g_mime_certificate_get_valid_userid (GMimeCertificate *cert) +{ + /* output user id only if validity is FULL or ULTIMATE. */ + /* note that gmime 2.6 is using the term "trust" here, which + * is WRONG. It's actually user id "validity". */ + const char *name = g_mime_certificate_get_name (cert); + if (name == NULL) + return name; + GMimeCertificateTrust trust = g_mime_certificate_get_trust (cert); + if (trust == GMIME_CERTIFICATE_TRUST_FULLY || trust == GMIME_CERTIFICATE_TRUST_ULTIMATE) + return name; + return NULL; +} + char * g_mime_message_get_address_string (GMimeMessage *message, GMimeRecipientType type) { @@ -99,8 +115,35 @@ g_mime_signature_status_error (GMimeSignatureError error) { return (error != GMIME_SIGNATURE_ERROR_NONE); } +gint64 +g_mime_utils_header_decode_date_unix (const char *date) { + return (gint64) g_mime_utils_header_decode_date (date, NULL); +} + #else /* GMime >= 3.0 */ +const char * +g_mime_certificate_get_valid_userid (GMimeCertificate *cert) +{ + /* output user id only if validity is FULL or ULTIMATE. */ + const char *uid = g_mime_certificate_get_user_id (cert); + if (uid == NULL) + return uid; + GMimeValidity validity = g_mime_certificate_get_id_validity (cert); + if (validity == GMIME_VALIDITY_FULL || validity == GMIME_VALIDITY_ULTIMATE) + return uid; + return NULL; +} + +const char* +g_mime_certificate_get_fpr16 (GMimeCertificate *cert) { + const char *fpr = g_mime_certificate_get_fingerprint (cert); + if (!fpr || strlen (fpr) < 16) + return fpr; + + return fpr + (strlen (fpr) - 16); +} + char * g_mime_message_get_address_string (GMimeMessage *message, GMimeAddressType type) { @@ -166,5 +209,19 @@ g_mime_signature_status_error (GMimeSignatureStatus status) { return (status & GMIME_SIGNATURE_STATUS_ERROR_MASK); } +gint64 +g_mime_utils_header_decode_date_unix (const char *date) { + GDateTime* parsed_date = g_mime_utils_header_decode_date (date); + time_t ret; + + if (parsed_date) { + ret = g_date_time_to_unix (parsed_date); + g_date_time_unref (parsed_date); + } else { + ret = 0; + } + + return ret; +} #endif