1 ;;; mml2015.el --- MIME Security with Pretty Good Privacy (PGP)
2 ;; Copyright (C) 2000 Free Software Foundation, Inc.
4 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu>
5 ;; Keywords: PGP MIME MML
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published
11 ;; by the Free Software Foundation; either version 2, or (at your
12 ;; option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful, but
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 ;; General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
26 ;; Installation: put the following statements in ~/.gnus:
28 ;; (require 'gnus-art)
30 ;; You may have to make sure that the directory where this file lives
31 ;; is mentioned in `load-path'.
33 ;; Insert an attribute, postprocess=pgp-sign (or pgp-encrypt), into
34 ;; the mml tag to be signed (or encrypted).
38 (eval-when-compile (require 'cl))
40 (defvar mml2015-decrypt-function 'mailcrypt-decrypt)
41 (defvar mml2015-verify-function 'mailcrypt-verify)
42 (defvar mml2015-encrypt-function 'mml2015-mailcrypt-encrypt)
43 (defvar mml2015-sign-function 'mml2015-mailcrypt-sign)
46 (defun mml2015-decrypt (handle ctl)
47 (let (child handles result)
48 (unless (setq child (mm-find-part-by-type (cdr handle)
49 "application/octet-stream"))
50 (error "Corrupted pgp-encrypted part."))
52 (mm-insert-part child)
53 (setq result (funcall mml2015-decrypt-function))
55 (error "Decrypting error."))
56 (setq handles (mm-dissect-buffer t)))
57 (mm-destroy-parts handle)
58 (if (listp (car handles))
62 (defun mml2015-fix-micalg (alg)
63 (if (and alg (string-match "^pgp-" alg))
64 (substring alg (match-end 0))
68 (defun mml2015-verify (handle ctl)
70 (unless (setq part (mm-find-raw-part-by-type
71 ctl "application/pgp-signature" t))
72 (error "Corrupted pgp-signature part."))
74 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n")
75 (insert (format "Hash: %s\n\n"
76 (or (mml2015-fix-micalg
77 (mail-content-type-get ctl 'micalg))
80 (goto-char (point-max))
83 (unless (setq part (mm-find-part-by-type
84 (cdr handle) "application/pgp-signature"))
85 (error "Corrupted pgp-signature part."))
87 (unless (funcall mml2015-verify-function)
88 (error "Verify error.")))))
90 (autoload 'mc-sign-generic "mc-toplev")
92 (defun mml2015-mailcrypt-sign (cont)
93 (mc-sign-generic (message-options-get 'message-sender)
96 (funcall mml-boundary-function (incf mml-multipart-number)))
97 (scheme-alist (funcall (or mc-default-scheme
98 (cdr (car mc-schemes)))))
100 (goto-char (point-min))
101 (unless (re-search-forward (cdr (assq 'signed-begin-line scheme-alist)))
102 (error "Cannot find signed begin line." ))
103 (goto-char (match-beginning 0))
105 (unless (looking-at "Hash:[ \t]*\\([a-zA-Z0-9]+\\)")
106 (error "Cannot not find PGP hash." ))
107 (setq hash (match-string 1))
108 (unless (re-search-forward "^$" nil t)
109 (error "Cannot not find PGP message." ))
111 (delete-region (point-min) (point))
112 (insert (format "Content-Type: multipart/signed; boundary=\"%s\";\n"
114 (insert (format "\tmicalg=pgp-%s; protocol=\"application/pgp-signature\"\n"
117 (insert (format "--%s\n" boundary))
118 (unless (re-search-forward (cdr (assq 'signed-end-line scheme-alist)))
119 (error "Cannot find signature part." ))
120 (goto-char (match-beginning 0))
121 (unless (re-search-backward "^-+BEGIN" nil t)
122 (error "Cannot find signature part." ))
123 (goto-char (match-beginning 0))
124 (insert (format "--%s\n" boundary))
125 (insert "Content-Type: application/pgp-signature\n\n")
126 (goto-char (point-max))
127 (insert (format "--%s--\n" boundary))
128 (goto-char (point-max))))
130 (autoload 'mc-encrypt-generic "mc-toplev")
132 (defun mml2015-mailcrypt-encrypt (cont)
134 (or (message-options-get 'message-recipients)
135 (message-options-set 'message-recipients
136 (mc-cleanup-recipient-headers
137 (read-string "Recipients: ")))))
139 (funcall mml-boundary-function (incf mml-multipart-number))))
140 (goto-char (point-min))
141 (insert (format "Content-Type: multipart/encrypted; boundary=\"%s\";\n"
143 (insert "\tprotocol=\"application/pgp-encrypted\"\n\n")
144 (insert (format "--%s\n" boundary))
145 (insert "Content-Type: application/pgp-encrypted\n\n")
146 (insert "Version: 1\n\n")
147 (insert (format "--%s\n" boundary))
148 (insert "Content-Type: application/octet-stream\n\n")
149 (goto-char (point-max))
150 (insert (format "--%s--\n" boundary))
151 (goto-char (point-max))))
154 (defun mml2015-encrypt (cont)
155 (funcall mml2015-encrypt-function cont))
158 (defun mml2015-sign (cont)
159 (funcall mml2015-sign-function cont))
162 (defun mml2015-setup ()
167 ;;; mml2015.el ends here