Fix line-ending issues with MIME and Outlook

Outlook seems to expect CRLF in S/MIME signed+encrypted mails, so we add those
somewhere in the process of encoding the mail.  Furthermore, Outlook is sending
MIME messages with CRLF line endings, and we have to take care of that when
looking for the end headers.

The changes proposed here are preliminary and subject to further testing.
This commit is contained in:
Daniel - 2020-12-12 18:05:57 +01:00
parent 106d13519c
commit 56c9f940ce
No known key found for this signature in database
GPG Key ID: 1C7071A75BB72D64
2 changed files with 46 additions and 5 deletions

31
init.el
View File

@ -613,7 +613,9 @@
db/system-open
db/switch-to-dark-theme
db/switch-to-light-theme
keyboard-quit-context+))
keyboard-quit-context+
db/convert-lf-to-crlf-in-buffer
db/convert-crlf-to-lf-in-buffer))
(use-package db-hydras
:commands (hydra-toggle/body
@ -1661,7 +1663,17 @@
(add-to-list 'mm-inlined-types "application/pgp$")
(add-to-list 'mm-inline-media-tests
'("application/pgp$" mm-inline-text identity))
(add-to-list 'mm-automatic-display "application/pgp$")))
(add-to-list 'mm-automatic-display "application/pgp$")
;; When copying MIME buffers, we are looking for the start of the
;; header by searching ^\n; however, if we received mail from
;; Outlook, there's an ^\r\n seperating header and body, which is
;; not found by `mm-copy-to-buffer', leaving the target buffer empty
;; and the mail as well. Replacing all \r\n with \n before copying
;; buffers seems to help.
(advice-add 'mm-copy-to-buffer
:before #'db/convert-crlf-to-lf-in-buffer)))
(setq message-forward-as-mime t)
@ -1687,9 +1699,7 @@
:init (setq mm-encrypt-option nil
mm-sign-option nil))
(setq mml-smime-use 'epg
;;mml2015-encrypt-to-self t
mml2015-display-key-image nil
(setq mml2015-display-key-image nil
gnus-message-replysign t
gnus-message-replyencrypt t
gnus-message-replysignencrypted t
@ -1697,6 +1707,17 @@
mml-secure-openpgp-sign-with-sender t
mml-secure-smime-sign-with-sender t)
(use-package mml-smime
:init (setq mml-smime-use 'epg)
: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
;; before, well, signing? Seems to work at least in the case where
;; we are sending S/MIME encrypted and signed messages
(advice-add 'mml-smime-epg-sign
:after #'db/convert-lf-to-crlf-in-buffer) ))
;; Archiving
;; We store messages in the current group, so there is

View File

@ -404,6 +404,26 @@ regardless of the currently selected window."
(let ((debug-on-quit nil))
(signal 'quit nil)))))
(defun db/convert-lf-to-crlf-in-buffer (&rest _stuff)
"Convert all LF to CRLF in current buffer.
Does not replace CRLF with CRCRLF, and so on."
(save-mark-and-excursion
(save-restriction
(widen)
(goto-char (point-min))
(while (re-search-forward "\n" nil 'noerror)
(unless (looking-back "\r\n" 2)
(replace-match "\r\n"))))))
(defun db/convert-crlf-to-lf-in-buffer (&rest _stuff)
"Convert all CRLF to LF in current buffer."
(save-mark-and-excursion
(save-restriction
(widen)
(goto-char (point-min))
(while (re-search-forward "\r\n" nil 'noerror)
(replace-match "\n")))))
;;; Extend Input Methods