+;; Extract plaintext from cleartext signature. IMO, this kind of task
+;; should be done by GnuPG rather than Elisp, but older PGP backends
+;; (such as Mailcrypt, PGG, and gpg.el) discard the output from GnuPG.
+(defun mml2015-extract-cleartext-signature ()
+ ;; Daiki Ueno in
+ ;; <54a15d860801080142l70b95d7dkac4bf51a86196011@mail.gmail.com>: ``I still
+ ;; believe that the right way is to use the plaintext output from GnuPG as
+ ;; it is, and mml2015-extract-cleartext-signature is just a kludge for
+ ;; misdesigned libraries like PGG, which have no ability to do that. So, I
+ ;; think it should not have descriptive documentation.''
+ ;;
+ ;; This function doesn't handle NotDashEscaped correctly. EasyPG handles it
+ ;; correctly.
+ ;; http://thread.gmane.org/gmane.emacs.gnus.general/66062/focus=66082
+ ;; http://thread.gmane.org/gmane.emacs.gnus.general/65087/focus=65109
+ (goto-char (point-min))
+ (forward-line)
+ ;; We need to be careful not to strip beyond the armor headers.
+ ;; Previously, an attacker could replace the text inside our
+ ;; markup with trailing garbage by injecting whitespace into the
+ ;; message.
+ (while (looking-at "Hash:") ; The only header allowed in cleartext
+ (forward-line)) ; signatures according to RFC2440.
+ (when (looking-at "[\t ]*$")
+ (forward-line))
+ (delete-region (point-min) (point))
+ (if (re-search-forward "^-----BEGIN PGP SIGNATURE-----" nil t)
+ (delete-region (match-beginning 0) (point-max)))
+ (goto-char (point-min))
+ (while (re-search-forward "^- " nil t)
+ (replace-match "" t t)
+ (forward-line 1)))
+