From 53488566285cebb76fae3f8af223e41562e4eb27 Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Mon, 5 Apr 2021 15:11:44 +0200 Subject: [PATCH] Only convert LF to CRLF when encrypting with S/MIME MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When only signing with S/MIME, `message-encode-message-body` complained about not being able to find \n\n. However, we only need the conversion when encrypting with S/MIME, and apparently the LF → CRLF conversion hack is working in that case. However, I think there should be some way to fix this properly within Gnus, maybe via some configuration … I think I have to write to the Gnus Usenet group for this. --- init.el | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/init.el b/init.el index 4172884..121e75a 100644 --- a/init.el +++ b/init.el @@ -1750,11 +1750,23 @@ :config (progn ;; Outlook seems to expect \r\n in PKCS#7 encrypted containers, but ;; Gnus is only sending \n; so let's artificially replace \n by \r\n - ;; after, well, signing? Seems to work at least in the case where - ;; we are sending S/MIME encrypted and signed messages. + ;; after, well, signing? But only if we are encrypting with S/MIME, + ;; as otherwise the search for \n\n in `message-encode-message-body' + ;; will break. However, I think this is not the right way to do it + ;; … isn't there some way to specify the encoding of the the + ;; relevant MML buffers to be some nasty cp1252 or something? + + ;; A previous version of this worked, but the following has not been + ;; tested with Outlook proper. + + (defun db/smime-add-crlf-when-pkcs7 (cont) + "If CONT signifies encryption with smime, replace all \n with \r\n." + (when (and (eq (car cont) 'part) + (string= "smime" (or (cdr (assq 'encrypt cont)) ""))) + (db/convert-lf-to-crlf-in-buffer))) (advice-add 'mml-smime-epg-sign - :after #'db/convert-lf-to-crlf-in-buffer) )) + :after #'db/smime-add-crlf-when-pkcs7))) ;; Archiving