aboutsummaryrefslogtreecommitdiffhomepage
path: root/show-message.c
diff options
context:
space:
mode:
authorGravatar Jameson Graef Rollins <jrollins@finestructure.net>2011-05-25 18:01:18 -0700
committerGravatar Carl Worth <cworth@cworth.org>2011-05-27 16:22:00 -0700
commit2e653db38fc38dee92b2ee0564e27921132e7232 (patch)
treed8bdc5eca6bc2beb6949f375a2e6683b0136ffe6 /show-message.c
parent8b18efe171ef80cbb238a9446137c39908755d2d (diff)
Add decryption of PGP/MIME-encrypted parts with --decrypt.
This adds support for decrypting PGP/MIME-encrypted parts to notmuch-show and notmuch-reply. The --decrypt option implies --verify. Once decryption (and possibly signature verification) is done, a new part_encstatus formatter is emitted, the part_sigstatus formatter is emitted, and the entire multipart/encrypted part is replaced by the contents of the encrypted part. At the moment only a json part_encstatus formatting function is available, even though decryption is done for all formats. Emacs support to follow.
Diffstat (limited to 'show-message.c')
-rw-r--r--show-message.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/show-message.c b/show-message.c
index c90f310c..37252b22 100644
--- a/show-message.c
+++ b/show-message.c
@@ -58,7 +58,34 @@ show_message_part (GMimeObject *part,
GMimeMultipart *multipart = GMIME_MULTIPART (part);
GError* err = NULL;
- if (GMIME_IS_MULTIPART_SIGNED (part))
+ if (GMIME_IS_MULTIPART_ENCRYPTED (part) && params->decrypt)
+ {
+ if ( g_mime_multipart_get_count (multipart) != 2 ) {
+ /* this violates RFC 3156 section 4, so we won't bother with it. */
+ fprintf (stderr,
+ "Error: %d part(s) for a multipart/encrypted message (should be exactly 2)\n",
+ g_mime_multipart_get_count (multipart));
+ } else {
+ GMimeMultipartEncrypted *encrypteddata = GMIME_MULTIPART_ENCRYPTED (part);
+ GMimeObject *decryptedpart = g_mime_multipart_encrypted_decrypt (encrypteddata, params->cryptoctx, &err);
+ if (decryptedpart) {
+ if ((selected || state->in_zone) && format->part_encstatus)
+ format->part_encstatus (1);
+ const GMimeSignatureValidity *sigvalidity = g_mime_multipart_encrypted_get_signature_validity (encrypteddata);
+ if (!sigvalidity)
+ fprintf (stderr, "Failed to verify signed part: %s\n", (err ? err->message : "no error explanation given"));
+ if ((selected || state->in_zone) && format->part_sigstatus)
+ format->part_sigstatus (sigvalidity);
+ /* swap the part with the decrypted part */
+ part = decryptedpart;
+ } else {
+ fprintf (stderr, "Failed to decrypt part: %s\n", (err ? err->message : "no error explanation given"));
+ if ((selected || state->in_zone) && format->part_encstatus)
+ format->part_encstatus (0);
+ }
+ }
+ }
+ else if (GMIME_IS_MULTIPART_SIGNED (part))
{
if ( g_mime_multipart_get_count (multipart) != 2 ) {
/* this violates RFC 3156 section 5, so we won't bother with it. */