mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-25 04:18:08 +01:00
cli: generalize use of GMIME_SIGNATURE_{ERROR,STATUS} to gmime-3
The ERROR enum is merged into to the STATUS enum, and the set of flags is different.
This commit is contained in:
parent
f4a989484f
commit
c7b9bdb81e
3 changed files with 88 additions and 12 deletions
|
@ -320,22 +320,21 @@ show_text_part_content (GMimeObject *part, GMimeStream *stream_out,
|
||||||
g_object_unref(stream_filter);
|
g_object_unref(stream_filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get signature status string (GMime 2.6) */
|
|
||||||
static const char*
|
static const char*
|
||||||
signature_status_to_string (GMimeSignatureStatus x)
|
signature_status_to_string (GMimeSignatureStatus status)
|
||||||
{
|
{
|
||||||
switch (x) {
|
if (g_mime_signature_status_bad (status))
|
||||||
case GMIME_SIGNATURE_STATUS_GOOD:
|
|
||||||
return "good";
|
|
||||||
case GMIME_SIGNATURE_STATUS_BAD:
|
|
||||||
return "bad";
|
return "bad";
|
||||||
case GMIME_SIGNATURE_STATUS_ERROR:
|
|
||||||
|
if (g_mime_signature_status_error (status))
|
||||||
return "error";
|
return "error";
|
||||||
}
|
|
||||||
|
if (g_mime_signature_status_good (status))
|
||||||
|
return "good";
|
||||||
|
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Print signature flags */
|
/* Print signature flags */
|
||||||
struct key_map_struct {
|
struct key_map_struct {
|
||||||
GMimeSignatureError bit;
|
GMimeSignatureError bit;
|
||||||
|
@ -358,6 +357,7 @@ do_format_signature_errors (sprinter_t *sp, struct key_map_struct *key_map,
|
||||||
sp->end (sp);
|
sp->end (sp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if (GMIME_MAJOR_VERSION < 3)
|
||||||
static void
|
static void
|
||||||
format_signature_errors (sprinter_t *sp, GMimeSignature *signature)
|
format_signature_errors (sprinter_t *sp, GMimeSignature *signature)
|
||||||
{
|
{
|
||||||
|
@ -376,6 +376,30 @@ format_signature_errors (sprinter_t *sp, GMimeSignature *signature)
|
||||||
|
|
||||||
do_format_signature_errors (sp, key_map, ARRAY_SIZE(key_map), errors);
|
do_format_signature_errors (sp, key_map, ARRAY_SIZE(key_map), errors);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
static void
|
||||||
|
format_signature_errors (sprinter_t *sp, GMimeSignature *signature)
|
||||||
|
{
|
||||||
|
GMimeSignatureError errors = g_mime_signature_get_errors (signature);
|
||||||
|
|
||||||
|
if (!(errors & GMIME_SIGNATURE_STATUS_ERROR_MASK))
|
||||||
|
return;
|
||||||
|
|
||||||
|
struct key_map_struct key_map[] = {
|
||||||
|
{ GMIME_SIGNATURE_STATUS_KEY_REVOKED, "key-revoked"},
|
||||||
|
{ GMIME_SIGNATURE_STATUS_KEY_EXPIRED, "key-expired"},
|
||||||
|
{ GMIME_SIGNATURE_STATUS_SIG_EXPIRED, "sig-expired" },
|
||||||
|
{ GMIME_SIGNATURE_STATUS_KEY_MISSING, "key-missing"},
|
||||||
|
{ GMIME_SIGNATURE_STATUS_CRL_MISSING, "crl-missing"},
|
||||||
|
{ GMIME_SIGNATURE_STATUS_CRL_TOO_OLD, "crl-too-old"},
|
||||||
|
{ GMIME_SIGNATURE_STATUS_BAD_POLICY, "bad-policy"},
|
||||||
|
{ GMIME_SIGNATURE_STATUS_SYS_ERROR, "sys-error"},
|
||||||
|
{ GMIME_SIGNATURE_STATUS_TOFU_CONFLICT, "tofu-conflict"},
|
||||||
|
};
|
||||||
|
|
||||||
|
do_format_signature_errors (sp, key_map, ARRAY_SIZE(key_map), errors);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Signature status sprinter (GMime 2.6) */
|
/* Signature status sprinter (GMime 2.6) */
|
||||||
static void
|
static void
|
||||||
|
@ -405,7 +429,7 @@ format_part_sigstatus_sprinter (sprinter_t *sp, mime_node_t *node)
|
||||||
sp->string (sp, signature_status_to_string (status));
|
sp->string (sp, signature_status_to_string (status));
|
||||||
|
|
||||||
GMimeCertificate *certificate = g_mime_signature_get_certificate (signature);
|
GMimeCertificate *certificate = g_mime_signature_get_certificate (signature);
|
||||||
if (status == GMIME_SIGNATURE_STATUS_GOOD) {
|
if (g_mime_signature_status_good (status)) {
|
||||||
if (certificate) {
|
if (certificate) {
|
||||||
sp->map_key (sp, "fingerprint");
|
sp->map_key (sp, "fingerprint");
|
||||||
sp->string (sp, g_mime_certificate_get_fingerprint (certificate));
|
sp->string (sp, g_mime_certificate_get_fingerprint (certificate));
|
||||||
|
@ -443,7 +467,7 @@ format_part_sigstatus_sprinter (sprinter_t *sp, mime_node_t *node)
|
||||||
|
|
||||||
if (notmuch_format_version <= 3) {
|
if (notmuch_format_version <= 3) {
|
||||||
GMimeSignatureError errors = g_mime_signature_get_errors (signature);
|
GMimeSignatureError errors = g_mime_signature_get_errors (signature);
|
||||||
if (errors != GMIME_SIGNATURE_ERROR_NONE) {
|
if (g_mime_signature_status_error (errors)) {
|
||||||
sp->map_key (sp, "errors");
|
sp->map_key (sp, "errors");
|
||||||
sp->integer (sp, errors);
|
sp->integer (sp, errors);
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,6 +84,20 @@ g_mime_message_get_reply_to_string (void *ctx, GMimeMessage *message)
|
||||||
return talloc_strdup(ctx, g_mime_message_get_reply_to (message));
|
return talloc_strdup(ctx, g_mime_message_get_reply_to (message));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
g_mime_signature_status_good (GMimeSignatureStatus status) {
|
||||||
|
return (status == GMIME_SIGNATURE_STATUS_GOOD);
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
g_mime_signature_status_bad (GMimeSignatureStatus status) {
|
||||||
|
return (status == GMIME_SIGNATURE_STATUS_BAD);
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
g_mime_signature_status_error (GMimeSignatureError error) {
|
||||||
|
return (error != GMIME_SIGNATURE_ERROR_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
#else /* GMime >= 3.0 */
|
#else /* GMime >= 3.0 */
|
||||||
|
|
||||||
|
@ -125,5 +139,32 @@ g_mime_message_get_reply_to_string (void *ctx, GMimeMessage *message)
|
||||||
return g_string_talloc_strdup (ctx, internet_address_list_to_string (list, NULL, 0));
|
return g_string_talloc_strdup (ctx, internet_address_list_to_string (list, NULL, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
g_mime_parser_set_scan_from (GMimeParser *parser, gboolean flag)
|
||||||
|
{
|
||||||
|
g_mime_parser_set_format (parser, flag ? GMIME_FORMAT_MBOX : GMIME_FORMAT_MESSAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* In GMime 3.0, status GOOD and VALID both imply something about the
|
||||||
|
* validity of the UIDs attached to the signing key. This forces us to
|
||||||
|
* use following somewhat relaxed definition of a "good" signature to
|
||||||
|
* preserve current notmuch semantics.
|
||||||
|
*/
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
g_mime_signature_status_good (GMimeSignatureStatus status) {
|
||||||
|
return ((status & (GMIME_SIGNATURE_STATUS_RED | GMIME_SIGNATURE_STATUS_ERROR_MASK)) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
g_mime_signature_status_bad (GMimeSignatureStatus status) {
|
||||||
|
return (status & GMIME_SIGNATURE_STATUS_RED);
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
g_mime_signature_status_error (GMimeSignatureStatus status) {
|
||||||
|
return (status & GMIME_SIGNATURE_STATUS_ERROR_MASK);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -13,7 +13,6 @@ GMimeStream *g_mime_stream_stdout_new(void);
|
||||||
#define GMIME_ADDRESS_TYPE_CC GMIME_RECIPIENT_TYPE_CC
|
#define GMIME_ADDRESS_TYPE_CC GMIME_RECIPIENT_TYPE_CC
|
||||||
#define GMIME_ADDRESS_TYPE_BCC GMIME_RECIPIENT_TYPE_BCC
|
#define GMIME_ADDRESS_TYPE_BCC GMIME_RECIPIENT_TYPE_BCC
|
||||||
|
|
||||||
|
|
||||||
#else /* GMime >= 3.0 */
|
#else /* GMime >= 3.0 */
|
||||||
typedef GMimeAddressType GMimeRecipientType;
|
typedef GMimeAddressType GMimeRecipientType;
|
||||||
|
|
||||||
|
@ -39,6 +38,9 @@ typedef GMimeAddressType GMimeRecipientType;
|
||||||
#define internet_address_to_string(ia,encode) internet_address_to_string (ia,NULL,encode)
|
#define internet_address_to_string(ia,encode) internet_address_to_string (ia,NULL,encode)
|
||||||
#define internet_address_list_parse_string(str) internet_address_list_parse (NULL,str)
|
#define internet_address_list_parse_string(str) internet_address_list_parse (NULL,str)
|
||||||
typedef GMimeAddressType GMimeRecipientType;
|
typedef GMimeAddressType GMimeRecipientType;
|
||||||
|
|
||||||
|
typedef GMimeSignatureStatus GMimeSignatureError;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,6 +63,7 @@ char *g_mime_message_get_date_string (void *ctx, GMimeMessage *message);
|
||||||
|
|
||||||
InternetAddressList * g_mime_message_get_from (GMimeMessage *message);
|
InternetAddressList * g_mime_message_get_from (GMimeMessage *message);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return string for From: address
|
* return string for From: address
|
||||||
* (owned by gmime)
|
* (owned by gmime)
|
||||||
|
@ -73,4 +76,12 @@ InternetAddressList * g_mime_message_get_reply_to_list (GMimeMessage *message);
|
||||||
* return talloc allocated reply-to string
|
* return talloc allocated reply-to string
|
||||||
*/
|
*/
|
||||||
char * g_mime_message_get_reply_to_string (void *ctx, GMimeMessage *message);
|
char * g_mime_message_get_reply_to_string (void *ctx, GMimeMessage *message);
|
||||||
|
|
||||||
|
void g_mime_parser_set_scan_from (GMimeParser *parser, gboolean flag);
|
||||||
|
|
||||||
|
gboolean g_mime_signature_status_good (GMimeSignatureStatus status);
|
||||||
|
|
||||||
|
gboolean g_mime_signature_status_bad (GMimeSignatureStatus status);
|
||||||
|
|
||||||
|
gboolean g_mime_signature_status_error (GMimeSignatureError status);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue