+;; epg wrapper
+
+(defvar epg-user-id-alist)
+
+(autoload 'epg-make-context "epg")
+(autoload 'epg-passphrase-callback-function "epg")
+(autoload 'epa-select-keys "epa")
+(autoload 'epg-list-keys "epg")
+(autoload 'epg-context-set-armor "epg")
+(autoload 'epg-context-set-textmode "epg")
+(autoload 'epg-context-set-signers "epg")
+(autoload 'epg-context-set-passphrase-callback "epg")
+(autoload 'epg-key-sub-key-list "epg")
+(autoload 'epg-sub-key-capability "epg")
+(autoload 'epg-sub-key-validity "epg")
+(autoload 'epg-sub-key-fingerprint "epg")
+(autoload 'epg-sign-string "epg")
+(autoload 'epg-encrypt-string "epg")
+(autoload 'epg-configuration "epg-config")
+(autoload 'epg-expand-group "epg-config")
+
+(defun mml1991-epg-sign (cont)
+ (let ((inhibit-redisplay t)
+ headers cte)
+ ;; Don't sign headers.
+ (goto-char (point-min))
+ (when (re-search-forward "^$" nil t)
+ (setq headers (buffer-substring (point-min) (point)))
+ (save-restriction
+ (narrow-to-region (point-min) (point))
+ (setq cte (mail-fetch-field "content-transfer-encoding")))
+ (forward-line 1)
+ (delete-region (point-min) (point))
+ (when cte
+ (setq cte (intern (downcase cte)))
+ (mm-decode-content-transfer-encoding cte)))
+ (let* ((pair (mml-secure-epg-sign 'OpenPGP 'clear))
+ (signature (car pair)))
+ (delete-region (point-min) (point-max))
+ (mm-with-unibyte-current-buffer
+ (insert signature)
+ (goto-char (point-min))
+ (while (re-search-forward "\r+$" nil t)
+ (replace-match "" t t))
+ (when cte
+ (mm-encode-content-transfer-encoding cte))
+ (goto-char (point-min))
+ (when headers
+ (insert headers))
+ (insert "\n"))
+ t)))
+
+(defun mml1991-epg-encrypt (cont &optional sign)
+ (goto-char (point-min))
+ (when (re-search-forward "^$" nil t)
+ (let ((cte (save-restriction
+ (narrow-to-region (point-min) (point))
+ (mail-fetch-field "content-transfer-encoding"))))
+ ;; Strip MIME headers since it will be ASCII armored.
+ (forward-line 1)
+ (delete-region (point-min) (point))
+ (when cte
+ (mm-decode-content-transfer-encoding (intern (downcase cte))))))
+ (let ((cipher (mml-secure-epg-encrypt 'OpenPGP cont sign)))
+ (delete-region (point-min) (point-max))
+ (insert "\n" cipher))
+ t)
+