mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-22 02:48:08 +01:00
util/crypto: _n_m_crypto_potential_payload returns whether part is the payload
Our _notmuch_message_crypto_potential_payload implementation could only return a failure if bad arguments were passed to it. It is an internal function, so if that happens it's an entirely internal bug for notmuch. It will be more useful for this function to return whether or not the part is in fact a cryptographic payload, so we dispense with the status return. If some future change suggests adding a status return back, there are only a handful of call sites, and no pressure to retain a stable API, so it could be changed easily. But for now, go with the simpler function. We will use this return value in future patches, to make different decisions based on whether a part is the cryptographic payload or not. But for now, we just leave the places where it gets invoked marked with (void) to show that the result is ignored. Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
This commit is contained in:
parent
8b25643d08
commit
ab0ae8b1c0
4 changed files with 16 additions and 20 deletions
|
@ -407,7 +407,6 @@ _index_mime_part (notmuch_message_t *message,
|
||||||
_notmuch_message_add_term (message, "tag", "encrypted");
|
_notmuch_message_add_term (message, "tag", "encrypted");
|
||||||
|
|
||||||
for (i = 0; i < g_mime_multipart_get_count (multipart); i++) {
|
for (i = 0; i < g_mime_multipart_get_count (multipart); i++) {
|
||||||
notmuch_status_t status;
|
|
||||||
GMimeObject *child;
|
GMimeObject *child;
|
||||||
if (GMIME_IS_MULTIPART_SIGNED (multipart)) {
|
if (GMIME_IS_MULTIPART_SIGNED (multipart)) {
|
||||||
/* Don't index the signature, but index its content type. */
|
/* Don't index the signature, but index its content type. */
|
||||||
|
@ -436,11 +435,7 @@ _index_mime_part (notmuch_message_t *message,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
child = g_mime_multipart_get_part (multipart, i);
|
child = g_mime_multipart_get_part (multipart, i);
|
||||||
status = _notmuch_message_crypto_potential_payload (msg_crypto, child, part, i);
|
(void) _notmuch_message_crypto_potential_payload (msg_crypto, child, part, i);
|
||||||
if (status)
|
|
||||||
_notmuch_database_log (notmuch_message_get_database (message),
|
|
||||||
"Warning: failed to mark the potential cryptographic payload (%s).\n",
|
|
||||||
notmuch_status_to_string (status));
|
|
||||||
_index_mime_part (message, indexopts, child, msg_crypto);
|
_index_mime_part (message, indexopts, child, msg_crypto);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -578,7 +573,7 @@ _index_encrypted_mime_part (notmuch_message_t *message,
|
||||||
}
|
}
|
||||||
g_object_unref (decrypt_result);
|
g_object_unref (decrypt_result);
|
||||||
}
|
}
|
||||||
status = _notmuch_message_crypto_potential_payload (msg_crypto, clear, GMIME_OBJECT (encrypted_data), GMIME_MULTIPART_ENCRYPTED_CONTENT);
|
_notmuch_message_crypto_potential_payload (msg_crypto, clear, GMIME_OBJECT (encrypted_data), GMIME_MULTIPART_ENCRYPTED_CONTENT);
|
||||||
_index_mime_part (message, indexopts, clear, msg_crypto);
|
_index_mime_part (message, indexopts, clear, msg_crypto);
|
||||||
g_object_unref (clear);
|
g_object_unref (clear);
|
||||||
|
|
||||||
|
|
|
@ -293,8 +293,6 @@ _mime_node_create (mime_node_t *parent, GMimeObject *part, int numchild)
|
||||||
static bool
|
static bool
|
||||||
_mime_node_set_up_part (mime_node_t *node, GMimeObject *part, int numchild)
|
_mime_node_set_up_part (mime_node_t *node, GMimeObject *part, int numchild)
|
||||||
{
|
{
|
||||||
notmuch_status_t status;
|
|
||||||
|
|
||||||
/* Deal with the different types of parts */
|
/* Deal with the different types of parts */
|
||||||
if (GMIME_IS_PART (part)) {
|
if (GMIME_IS_PART (part)) {
|
||||||
node->part = part;
|
node->part = part;
|
||||||
|
@ -335,9 +333,7 @@ _mime_node_set_up_part (mime_node_t *node, GMimeObject *part, int numchild)
|
||||||
node_verify (node, part);
|
node_verify (node, part);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
status = _notmuch_message_crypto_potential_payload (node->ctx->msg_crypto, part, node->parent ? node->parent->part : NULL, numchild);
|
(void) _notmuch_message_crypto_potential_payload (node->ctx->msg_crypto, part, node->parent ? node->parent->part : NULL, numchild);
|
||||||
if (status)
|
|
||||||
fprintf (stderr, "Warning: failed to record potential crypto payload (%s).\n", notmuch_status_to_string (status));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
#include "crypto.h"
|
#include "crypto.h"
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
|
#include "error_util.h"
|
||||||
#define unused(x) x __attribute__ ((unused))
|
#define unused(x) x __attribute__ ((unused))
|
||||||
|
|
||||||
#define ARRAY_SIZE(arr) (sizeof (arr) / sizeof (arr[0]))
|
#define ARRAY_SIZE(arr) (sizeof (arr) / sizeof (arr[0]))
|
||||||
|
@ -135,19 +136,20 @@ _notmuch_message_crypto_potential_sig_list (_notmuch_message_crypto_t *msg_crypt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
notmuch_status_t
|
bool
|
||||||
_notmuch_message_crypto_potential_payload (_notmuch_message_crypto_t *msg_crypto, GMimeObject *part, GMimeObject *parent, int childnum)
|
_notmuch_message_crypto_potential_payload (_notmuch_message_crypto_t *msg_crypto, GMimeObject *part, GMimeObject *parent, int childnum)
|
||||||
{
|
{
|
||||||
const char *protected_headers = NULL;
|
const char *protected_headers = NULL;
|
||||||
const char *forwarded = NULL;
|
const char *forwarded = NULL;
|
||||||
const char *subject = NULL;
|
const char *subject = NULL;
|
||||||
|
|
||||||
if (! msg_crypto || ! part)
|
if ((! msg_crypto) || (! part))
|
||||||
return NOTMUCH_STATUS_NULL_POINTER;
|
INTERNAL_ERROR ("_notmuch_message_crypto_potential_payload() got NULL for %s\n",
|
||||||
|
msg_crypto? "part" : "msg_crypto");
|
||||||
|
|
||||||
/* only fire on the first payload part encountered */
|
/* only fire on the first payload part encountered */
|
||||||
if (msg_crypto->payload_encountered)
|
if (msg_crypto->payload_encountered)
|
||||||
return NOTMUCH_STATUS_SUCCESS;
|
return false;
|
||||||
|
|
||||||
/* the first child of multipart/encrypted that matches the
|
/* the first child of multipart/encrypted that matches the
|
||||||
* encryption protocol should be "control information" metadata,
|
* encryption protocol should be "control information" metadata,
|
||||||
|
@ -159,7 +161,7 @@ _notmuch_message_crypto_potential_payload (_notmuch_message_crypto_t *msg_crypto
|
||||||
if (ct && enc_type) {
|
if (ct && enc_type) {
|
||||||
const char *part_type = g_mime_content_type_get_mime_type (ct);
|
const char *part_type = g_mime_content_type_get_mime_type (ct);
|
||||||
if (part_type && strcmp (part_type, enc_type) == 0)
|
if (part_type && strcmp (part_type, enc_type) == 0)
|
||||||
return NOTMUCH_STATUS_SUCCESS;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +171,7 @@ _notmuch_message_crypto_potential_payload (_notmuch_message_crypto_t *msg_crypto
|
||||||
* envelope: */
|
* envelope: */
|
||||||
if ((msg_crypto->decryption_status != NOTMUCH_MESSAGE_DECRYPTED_FULL) &&
|
if ((msg_crypto->decryption_status != NOTMUCH_MESSAGE_DECRYPTED_FULL) &&
|
||||||
(msg_crypto->sig_list == NULL))
|
(msg_crypto->sig_list == NULL))
|
||||||
return NOTMUCH_STATUS_SUCCESS;
|
return false;
|
||||||
|
|
||||||
/* Verify that this payload has headers that are intended to be
|
/* Verify that this payload has headers that are intended to be
|
||||||
* exported to the larger message: */
|
* exported to the larger message: */
|
||||||
|
@ -196,7 +198,7 @@ _notmuch_message_crypto_potential_payload (_notmuch_message_crypto_t *msg_crypto
|
||||||
msg_crypto->payload_subject = talloc_strdup (msg_crypto, subject);
|
msg_crypto->payload_subject = talloc_strdup (msg_crypto, subject);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NOTMUCH_STATUS_SUCCESS;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -90,8 +90,11 @@ _notmuch_message_crypto_successful_decryption (_notmuch_message_crypto_t *msg_cr
|
||||||
|
|
||||||
/* call potential_payload during a depth-first-search on a message
|
/* call potential_payload during a depth-first-search on a message
|
||||||
* when encountering a message part that is not part of the envelope.
|
* when encountering a message part that is not part of the envelope.
|
||||||
|
*
|
||||||
|
* Returns true if part is the root of the cryptographic payload of
|
||||||
|
* this message.
|
||||||
*/
|
*/
|
||||||
notmuch_status_t
|
bool
|
||||||
_notmuch_message_crypto_potential_payload (_notmuch_message_crypto_t *msg_crypto, GMimeObject *part, GMimeObject *parent, int childnum);
|
_notmuch_message_crypto_potential_payload (_notmuch_message_crypto_t *msg_crypto, GMimeObject *part, GMimeObject *parent, int childnum);
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue