(mime-method-to-verify-application/pgp-signature): Don't use temporary
[elisp/semi.git] / mime-pgp.el
index 58215e1..0eb5ae8 100644 (file)
 ;;;
 ;;; It is based on draft-kazu-pgp-mime-00.txt (PGP-kazu).
 
-(defun mime-method-for-application/pgp (beg end cal)
-  (let* ((cnum (mime-raw-point-to-entity-number beg))
+(defun mime-method-for-application/pgp (start end cal)
+  (let* ((entity-number (mime-raw-point-to-entity-number start))
         (p-win (or (get-buffer-window mime-preview-buffer)
                    (get-largest-window)))
-        (new-name (format "%s-%s" (buffer-name) cnum))
+        (new-name (format "%s-%s" (buffer-name) entity-number))
         (the-buf (current-buffer))
         (mother mime-preview-buffer)
         (mode major-mode)
         text-decoder)
     (set-buffer (get-buffer-create new-name))
     (erase-buffer)
-    (insert-buffer-substring the-buf beg end)
+    (insert-buffer-substring the-buf start end)
     (cond ((progn
             (goto-char (point-min))
-            (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE-+$" nil t)
-            )
+            (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE-+$" nil t))
           (funcall (pgp-function 'verify))
           (goto-char (point-min))
           (delete-region
            (point-min)
            (and
             (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE-+\n\n")
-            (match-end 0))
-           )
+            (match-end 0)))
           (delete-region
            (and (re-search-forward "^-+BEGIN PGP SIGNATURE-+")
                 (match-beginning 0))
-           (point-max)
-           )
+           (point-max))
           (goto-char (point-min))
           (while (re-search-forward "^- -" nil t)
             (replace-match "-")
@@ -92,8 +89,7 @@
           )
          ((progn
             (goto-char (point-min))
-            (re-search-forward "^-+BEGIN PGP MESSAGE-+$" nil t)
-            )
+            (re-search-forward "^-+BEGIN PGP MESSAGE-+$" nil t))
           (as-binary-process (funcall (pgp-function 'decrypt)))
           (goto-char (point-min))
           (delete-region (point-min)
 
 (set-atype 'mime-acting-condition
           '((type . application)(subtype . pgp)
-            (method . mime-method-for-application/pgp)
-            ))
+            (method . mime-method-for-application/pgp)))
 
 (set-atype 'mime-acting-condition
           '((type . text)(subtype . x-pgp)
-            (method . mime-method-for-application/pgp)
-            ))
+            (method . mime-method-for-application/pgp)))
 
 
 ;;; @ Internal method for multipart/signed
   "Internal method to verify multipart/signed."
   (mime-raw-play-entity
    ;; entity-info of signature
-   (mime-raw-reversed-entity-number-to-entity-info
-    ;; reversed-entity-number of signature
-    (cons 1 (reverse (mime-raw-point-to-entity-number start)))
-    mime-raw-message-info)
+   (mime-raw-entity-node-id-to-entity-info
+    ;; entity-node-id of signature
+    (cons 1 (mime-raw-point-to-entity-node-id start)))
    (cdr (assq 'mode cal)) ; play-mode
    ))
 
 (set-atype 'mime-acting-condition
           '((type . multipart)(subtype . signed)
-            (method . mime-method-to-verify-multipart/signed)
-            ))
+            (method . mime-method-to-verify-multipart/signed)))
 
 
 ;;; @ Internal method for application/pgp-signature
@@ -181,20 +173,18 @@ It should be ISO 639 2 letter language code such as en, ja, ...")
                 (t "Bad signature")))
          ))))
 
-(defun mime-method-to-verify-application/pgp-signature (beg end cal)
+(defun mime-method-to-verify-application/pgp-signature (start end cal)
   "Internal method to check PGP/MIME signature."
   (let* ((encoding (cdr (assq 'encoding cal)))
-        (cnum (mime-raw-point-to-entity-number beg))
-        (rcnum (reverse cnum))
-        (rmcnum (cdr rcnum))
-        (knum (car rcnum))
+        (entity-node-id (mime-raw-point-to-entity-node-id start))
+        (mother-node-id (cdr entity-node-id))
+        (knum (car entity-node-id))
         (onum (if (> knum 0)
                   (1- knum)
                 (1+ knum)))
         (raw-buf (current-buffer))
-        (oinfo (mime-raw-reversed-entity-number-to-entity-info
-                (cons onum rmcnum) mime-raw-message-info))
-        kbuf
+        (oinfo (mime-raw-entity-node-id-to-entity-info
+                (cons onum mother-node-id) mime-raw-message-info))
         (basename (expand-file-name "tm" mime-temp-directory))
         (orig-file (make-temp-name basename))
         (sig-file (concat orig-file ".sig"))
@@ -210,21 +200,18 @@ It should be ISO 639 2 letter language code such as en, ja, ...")
       (while (re-search-forward "\n" nil t)
        (replace-match "\r\n")
        )
-      (as-binary-output-file (write-region (point-min)(point-max) orig-file))
+      (write-region-as-binary (point-min)(point-max) orig-file)
       (kill-buffer (current-buffer))
       )
     (save-excursion (mime-show-echo-buffer))
     (save-excursion
       (let ((p-min (save-excursion
-                    (goto-char beg)
+                    (goto-char start)
                     (and (search-forward "\n\n")
                          (match-end 0))
                     )))
-       (set-buffer (setq kbuf (get-buffer-create mime-temp-buffer-name)))
-       (insert-buffer-substring raw-buf p-min end)
+       (mime-write-decoded-region p-min end sig-file encoding)
        )
-      (mime-decode-region (point-min)(point-max) encoding)
-      (as-binary-output-file (write-region (point-min)(point-max) sig-file))
       (or (mime-pgp-check-signature mime-echo-buffer-name orig-file)
          (let (pgp-id)
            (save-excursion
@@ -254,31 +241,28 @@ It should be ISO 639 2 letter language code such as en, ja, ...")
       (let ((other-window-scroll-buffer mime-echo-buffer-name))
        (scroll-other-window 8)
        )
-      (kill-buffer kbuf)
       (delete-file orig-file)
       (delete-file sig-file)
       )))
 
 (set-atype 'mime-acting-condition
           '((type . application)(subtype . pgp-signature)
-            (method . mime-method-to-verify-application/pgp-signature)
-            ))
+            (method . mime-method-to-verify-application/pgp-signature)))
 
 
 ;;; @ Internal method for application/pgp-encrypted
 ;;;
 ;;; It is based on RFC 2015 (PGP/MIME).
 
-(defun mime-method-to-decrypt-application/pgp-encrypted (beg end cal)
-  (let* ((cnum (mime-raw-point-to-entity-number beg))
-        (rcnum (reverse cnum))
-        (rmcnum (cdr rcnum))
-        (knum (car rcnum))
+(defun mime-method-to-decrypt-application/pgp-encrypted (start end cal)
+  (let* ((entity-node-id (mime-raw-point-to-entity-node-id start))
+        (mother-node-id (cdr entity-node-id))
+        (knum (car entity-node-id))
         (onum (if (> knum 0)
                   (1- knum)
                 (1+ knum)))
-        (oinfo (mime-raw-reversed-entity-number-to-entity-info
-                (cons onum rmcnum) mime-raw-message-info))
+        (oinfo (mime-raw-entity-node-id-to-entity-info
+                (cons onum mother-node-id) mime-raw-message-info))
         (obeg (mime-entity-info-point-min oinfo))
         (oend (mime-entity-info-point-max oinfo))
         )
@@ -287,20 +271,19 @@ It should be ISO 639 2 letter language code such as en, ja, ...")
 
 (set-atype 'mime-acting-condition
           '((type . application)(subtype . pgp-encrypted)
-            (method . mime-method-to-decrypt-application/pgp-encrypted)
-            ))
+            (method . mime-method-to-decrypt-application/pgp-encrypted)))
 
 
 ;;; @ Internal method for application/pgp-keys
 ;;;
 ;;; It is based on RFC 2015 (PGP/MIME).
 
-(defun mime-method-to-add-application/pgp-keys (beg end cal)
-  (let* ((cnum (mime-raw-point-to-entity-number beg))
-        (new-name (format "%s-%s" (buffer-name) cnum))
+(defun mime-method-to-add-application/pgp-keys (start end cal)
+  (let* ((entity-number (mime-raw-point-to-entity-number start))
+        (new-name (format "%s-%s" (buffer-name) entity-number))
         (encoding (cdr (assq 'encoding cal)))
         str)
-    (setq str (buffer-substring beg end))
+    (setq str (buffer-substring start end))
     (switch-to-buffer new-name)
     (setq buffer-read-only nil)
     (erase-buffer)
@@ -316,8 +299,7 @@ It should be ISO 639 2 letter language code such as en, ja, ...")
 
 (set-atype 'mime-acting-condition
           '((type . application)(subtype . pgp-keys)
-            (method . mime-method-to-add-application/pgp-keys)
-            ))
+            (method . mime-method-to-add-application/pgp-keys)))
 
         
 ;;; @ end