diff --git a/lib/mu-msg-crypto.c b/lib/mu-msg-crypto.c index 35002e2a..74fd8ede 100644 --- a/lib/mu-msg-crypto.c +++ b/lib/mu-msg-crypto.c @@ -293,6 +293,7 @@ mu_msg_mime_sig_infos (GMimeMultipartSigned *sigmpart, MuMsgOptions opts, } + void mu_msg_part_free_sig_infos (GSList *siginfos) { @@ -302,6 +303,46 @@ mu_msg_part_free_sig_infos (GSList *siginfos) } +/* + * - if there's any signature with MU_MSG_PART_SIG_STATUS_(ERROR|FAIL), + * the verdict is MU_MSG_PART_SIG_STATUS_ERROR + * - if not, if there's any signature with MU_MSG_PART_SIG_STATUS_BAD + * the verdict is MU_MSG_PART_SIG_STATUS_BAD + * - if not, if there's any signature with MU_MSG_PART_SIG_STATUS_GOOD + * the verdict is MU_MSG_PART_SIG_STATUS_GOOD + * - if not, the verdic is MU_MSG_PART_SIG_STATUS_UNKNOWN + */ +MuMsgPartSigStatus +mu_msg_mime_sig_infos_verdict (GSList *sig_infos) +{ + GSList *cur; + MuMsgPartSigStatus status; + + status = MU_MSG_PART_SIG_STATUS_UNKNOWN; + + for (cur = sig_infos; cur; cur = g_slist_next (cur)) { + MuMsgPartSigInfo *siginfo; + siginfo = (MuMsgPartSigInfo*)cur->data; + + /* if there's an error/failure, the verdict is error */ + if (siginfo->status & MU_MSG_PART_SIG_STATUS_ERROR || + siginfo->status & MU_MSG_PART_SIG_STATUS_FAIL) + return MU_MSG_PART_SIG_STATUS_ERROR; + + if (siginfo->status & MU_MSG_PART_SIG_STATUS_BAD) + status = MU_MSG_PART_SIG_STATUS_BAD; + + if ((siginfo->status & MU_MSG_PART_SIG_STATUS_GOOD) && + status == MU_MSG_PART_SIG_STATUS_UNKNOWN) + status = MU_MSG_PART_SIG_STATUS_GOOD; + } + + return status; +} + + + + const char* mu_msg_part_sig_status_to_string (MuMsgPartSigStatus status) { diff --git a/lib/mu-msg-crypto.h b/lib/mu-msg-crypto.h index f1e73273..e9a6afc0 100644 --- a/lib/mu-msg-crypto.h +++ b/lib/mu-msg-crypto.h @@ -79,6 +79,24 @@ typedef struct _MuMsgPartSigInfo MuMsgPartSigInfo; const char* mu_msg_part_sig_status_to_string (MuMsgPartSigStatus status); +/** + * summarize the signatures to one status: + * + * - if there's any signature with MU_MSG_PART_SIG_STATUS_(ERROR|FAIL), + * the verdict is MU_MSG_PART_SIG_STATUS_ERROR + * - if not, if there's any signature with MU_MSG_PART_SIG_STATUS_BAD + * the verdict is MU_MSG_PART_SIG_STATUS_BAD + * - if not, if there's any signature with MU_MSG_PART_SIG_STATUS_GOOD + * the verdict is MU_MSG_PART_SIG_STATUS_GOOD + * - if not, the verdic is MU_MSG_PART_SIG_STATUS_UNKNOWN + * + * @param sig_infos + * + * @return the status + */ +MuMsgPartSigStatus mu_msg_mime_sig_infos_verdict (GSList *sig_infos); + + /** * convert the bitwise-OR'ed statuses to a string * diff --git a/lib/mu-msg-sexp.c b/lib/mu-msg-sexp.c index 5977a780..e252b88b 100644 --- a/lib/mu-msg-sexp.c +++ b/lib/mu-msg-sexp.c @@ -22,6 +22,7 @@ #include "mu-msg.h" #include "mu-msg-iter.h" #include "mu-msg-part.h" +#include "mu-msg-crypto.h" #include "mu-maildir.h" static void @@ -238,6 +239,22 @@ elvis (const char *s1, const char *s2) return s1 ? s1 : s2; } +static const char* +sig_verdict (GSList *sig_infos) +{ + switch (mu_msg_mime_sig_infos_verdict (sig_infos)) { + case MU_MSG_PART_SIG_STATUS_GOOD: + return ":signature good"; + case MU_MSG_PART_SIG_STATUS_BAD: + return ":signature bad"; + case MU_MSG_PART_SIG_STATUS_ERROR: + return ":signature error"; /* ugly */ + default: + return ""; + } +} + + static void each_part (MuMsg *msg, MuMsgPart *part, PartInfo *pinfo) { @@ -266,13 +283,14 @@ each_part (MuMsg *msg, MuMsgPart *part, PartInfo *pinfo) tmp = g_strdup_printf ("%s(:index %d :name %s :mime-type \"%s/%s\"%s%s " - ":attachment %s :size %i)", + ":attachment %s :size %i %s)", elvis (pinfo->parts, ""), part->index, name, elvis (part->type, "application"), elvis (part->subtype, "octet-stream"), tmpfile ? " :temp" : "", tmpfile ? tmpfile : "", mu_msg_part_looks_like_attachment (part, TRUE) ? "t" : "nil", - (int)part->size); + (int)part->size, + sig_verdict (part->sig_infos)); g_free (pinfo->parts); pinfo->parts = tmp;