unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Alexander Adolf <alexander.adolf@condition-alpha.com>
To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org
Subject: Re: [PATCH] emacs/smime: render decrypted MIME entities in notmuch-show
Date: Tue, 12 Apr 2022 18:21:27 +0200	[thread overview]
Message-ID: <68e03382493db20b12786d19f79edfaf@condition-alpha.com> (raw)
In-Reply-To: <87tuazb3ag.fsf@tethera.net>

[-- Attachment #1: Type: text/plain, Size: 268 bytes --]

Hello David,

David Bremner <david@tethera.net> writes:

> [...]
> I'm not sure it's less effort, 
> [...]

Neither am I... ;-))

It might perhaps seem easier to run the tests I have added to the
attached, updated patch in your complete environment?

  --alexander




[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-emacs-smime-render-decrypted-MIME-entities-in-notmuc.patch --]
[-- Type: text/x-patch, Size: 8180 bytes --]

From ba6f00bbd1803f5cccfafdb262f17b79b6c95252 Mon Sep 17 00:00:00 2001
From: Alexander Adolf <alexander.adolf@condition-alpha.com>
Date: Fri, 25 Mar 2022 14:13:28 +0100
Subject: [PATCH] emacs/smime: render decrypted MIME entities in notmuch-show

When processing encrypted S/MIME messages, after decryption the "last
resort" handler notmuch-show-insert-part-*/* was called, because there
was no application/pkcs7-mime handler, resulting in the decrypted
contents not being displayed.

This commit adds a new function
notmuch-show-insert-part-application/pkcs7-mime (and an alias
notmuch-show-insert-part-application/x-pkcs7-mime for the legacy MIME
type) to render the S/MIME protected part after decryption.
---
 emacs/notmuch-show.el                         | 17 +++++++
 test/T450-emacs-show.sh                       | 11 +++-
 .../crypto/smime-encrypted-signed-multipart   | 51 +++++++++++++++++++
 ...much-show-smime-encrypted-signed-multipart | 15 ++++++
 4 files changed, 93 insertions(+), 1 deletion(-)
 create mode 100644 test/corpora/crypto/smime-encrypted-signed-multipart
 create mode 100644 test/emacs-show.expected-output/notmuch-show-smime-encrypted-signed-multipart

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 7c1f02c9..b7edfc98 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -712,6 +712,23 @@ will return nil if the CID is unknown or cannot be retrieved."
 (defun notmuch-show-insert-part-application/pgp-encrypted (_msg _part _content-type _nth _depth _button)
   t)
 
+(defun notmuch-show-insert-part-application/pkcs7-mime (msg part _content-type _nth depth _button)
+  "Render S/MIME protected content after decryption.
+
+An alias for this function is also defined to handle entities
+using the legacy application/x-pkcs7-mime MIME type."
+  (let* ((encstatus (car (plist-get part :encstatus)))
+	 (inner-part (car (plist-get part :content))))
+    ;; Insert a button detailing the encryption status.
+    (notmuch-crypto-insert-encstatus-button encstatus)
+    (if (not (string= (plist-get encstatus :status) "bad"))
+        ;; Show all decrypted parts.
+        (notmuch-show-insert-bodypart msg inner-part depth))))
+
+;; Support for the legacy "x-" type.
+(fset 'notmuch-show-insert-part-application/x-pkcs7-mime
+  'notmuch-show-insert-part-application/pkcs7-mime)
+
 (defun notmuch-show-insert-part-multipart/* (msg part _content-type _nth depth _button)
   (let ((inner-parts (plist-get part :content))
 	(start (point)))
diff --git a/test/T450-emacs-show.sh b/test/T450-emacs-show.sh
index 057ad37e..5c4bdd7e 100755
--- a/test/T450-emacs-show.sh
+++ b/test/T450-emacs-show.sh
@@ -49,7 +49,7 @@ test_emacs '(let ((notmuch-crypto-process-mime nil))
 	(test-visible-output))'
 test_expect_equal_file $EXPECTED/notmuch-show-process-crypto-mime-parts-off OUTPUT
 
-test_begin_subtest "process cryptographic MIME parts"
+test_begin_subtest "process cryptographic MIME parts (PGP)"
 test_emacs '(let ((notmuch-crypto-process-mime t))
 	(notmuch-show "id:20091117203301.GV3165@dottiness.seas.harvard.edu")
 	(test-visible-output))'
@@ -245,4 +245,13 @@ test_emacs "(test-log-error
 	        (notmuch-show \"$tid\")))"
 test_expect_equal "$(cat MESSAGES)" "COMPLETE"
 
+# more crypto tests, using S/MIME from here on:
+add_gpgsm_home
+
+test_begin_subtest "process cryptographic MIME parts (S/MIME)"
+test_emacs '(let ((notmuch-crypto-process-mime t))
+	(notmuch-show "id:575ddaaf0b234fd85e077cfb4d44d467@notmuchmail.org")
+	(test-visible-output))'
+test_expect_equal_file $EXPECTED/notmuch-show-smime-encrypted-signed-multipart OUTPUT
+
 test_done
diff --git a/test/corpora/crypto/smime-encrypted-signed-multipart b/test/corpora/crypto/smime-encrypted-signed-multipart
new file mode 100644
index 00000000..f0bd6c51
--- /dev/null
+++ b/test/corpora/crypto/smime-encrypted-signed-multipart
@@ -0,0 +1,51 @@
+Message-Id: <575ddaaf0b234fd85e077cfb4d44d467@notmuchmail.org>
+From: test_suite@notmuchmail.org
+To: test_suite@notmuchmail.org
+Subject: notmuch-show S/MIME test
+Date: Tue, 12 Apr 2022 16:57:30 +0200
+MIME-Version: 1.0
+Content-Type: application/pkcs7-mime;
+ smime-type=enveloped-data;
+ name=smime.p7m
+Content-Transfer-Encoding: base64
+Content-Disposition: attachment; filename=smime.p7m
+
+MIAGCSqGSIb3DQEHA6CAMIACAQAxggFFMIIBQQIBADApMB0xGzAZBgNVBAMTEk5vdG11Y2ggVGVz
+dCBTdWl0ZQIIb3SMlL0MZ6kwDQYJKoZIhvcNAQEBBQAEggEAeCEItxJpxL5frDmEeuMRpi8TcCCw
+WHraQ//IDMkA6fcbDIA8hfJpRNpiL5AvqQBipPELtb95rHKxOes7fUPMbT5FVA7dm72hur5N9VRj
+kN8Jgs6BjpXRKBA4S5eEzu9J2DJYnTWueZUItKlUzXUXg9AWwyEOKtlXfpOEGZ8FSTNQaE4thipO
+hmElscsz1tGmw2+8E1dFeXZyHArruqMAxzqOtiM6G3Y5dj1i8V+s6BSRLzep0JQZ0T/Jq5LE5T+E
+rYpgjopj1IT7IOwOP6B+YuhkalXjX7ursH9CNsDg+YjvWPn8RblAH5BRKLHNo1jMm9JLPFH9/0qJ
+IJAD0U2q4jCABgkqhkiG9w0BBwEwHQYJYIZIAWUDBAEqBBBbgb0RK4lPMIDflJo1B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5gcMk8zlZDZeTVN3ZgJCpWSywpABE2GIPSH4kgiiBH8RHD4hV
+7kPAQqc9AXrvvXXN9Gzouy2FmWTOvnb3d63OjG01ZDIgVwaE6dfCZRgKN3P3Jx+/mQboJzhiQJbw
+M/cFlSwo/GuUjt1fhTq7Vtr8PLXnAORvTrXYTbpB2ozPxdVDHLfKYpta98s+61vVuoRO4yaLk+oP
+IuSI/j9wgPJkUOuN6oGjZ7fr2y/alw2F8JbmG/0eZxRE3JuvnUfwTRJeijMvaKS1Vk8BUoLAADys
+JLSbQhXdzvZGk5avYwv7IAkXASMRwODE3AQQzThdv7ONbleBxDPXMpAvRQAAAAAAAAAAAAA=
\ No newline at end of file
diff --git a/test/emacs-show.expected-output/notmuch-show-smime-encrypted-signed-multipart b/test/emacs-show.expected-output/notmuch-show-smime-encrypted-signed-multipart
new file mode 100644
index 00000000..556bd937
--- /dev/null
+++ b/test/emacs-show.expected-output/notmuch-show-smime-encrypted-signed-multipart
@@ -0,0 +1,15 @@
+test_suite@notmuchmail.org (0 mins. ago) (encrypted inbox)
+Subject: notmuch-show S/MIME test
+To: test_suite@notmuchmail.org
+Date: Tue, 12 Apr 2022 16:57:30 +0200
+
+[ smime.p7m: application/pkcs7-mime ]
+[ Decryption successful ]
+[ multipart/signed ]
+[ Good signature by: <test_suite@notmuchmail.org> ]
+[ multipart/mixed ]
+[ multipart/mixed ]
+[ text/plain ]
+The password is "12345678". But don't tell anyone!
+[ test.dtd: application/octet-stream ]
+[ smime.p7s: application/pkcs7-signature ]
-- 
2.35.1


[-- Attachment #3: Type: text/plain, Size: 0 bytes --]



  reply	other threads:[~2022-04-12 16:21 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-25 13:43 [PATCH] emacs/smime: render decrypted MIME entities in notmuch-show Alexander Adolf
2022-03-29 13:18 ` David Bremner
2022-04-06 20:23   ` Alexander Adolf
2022-04-07 12:25     ` David Bremner
2022-04-07 13:02       ` Alexander Adolf
2022-04-07 14:01         ` David Bremner
2022-04-11 15:35           ` Alexander Adolf
2022-04-11 23:36             ` David Bremner
2022-04-12 16:21               ` Alexander Adolf [this message]
2022-04-13 23:56                 ` David Bremner
2022-05-11 15:41                   ` Alexander Adolf
2022-05-16 16:17                   ` Alexander Adolf
2022-05-18 10:29                     ` David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=68e03382493db20b12786d19f79edfaf@condition-alpha.com \
    --to=alexander.adolf@condition-alpha.com \
    --cc=david@tethera.net \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).