+ if (!msg_crypto || !payload)
+ return NOTMUCH_STATUS_NULL_POINTER;
+
+ /* only fire on the first payload part encountered */
+ if (msg_crypto->payload_encountered)
+ return NOTMUCH_STATUS_SUCCESS;
+
+ /* the first child of multipart/encrypted that matches the
+ * encryption protocol should be "control information" metadata,
+ * not payload. So we skip it. (see
+ * https://tools.ietf.org/html/rfc1847#page-8) */
+ if (parent && GMIME_IS_MULTIPART_ENCRYPTED (parent) && childnum == GMIME_MULTIPART_ENCRYPTED_VERSION) {
+ const char *enc_type = g_mime_object_get_content_type_parameter (parent, "protocol");
+ GMimeContentType *ct = g_mime_object_get_content_type (payload);
+ if (ct && enc_type) {
+ const char *part_type = g_mime_content_type_get_mime_type (ct);
+ if (part_type && strcmp (part_type, enc_type) == 0)
+ return NOTMUCH_STATUS_SUCCESS;
+ }