Fixed the last change.
[elisp/wanderlust.git] / wl / wl-mime.el
index 393ec98..37afaf2 100644 (file)
@@ -152,7 +152,7 @@ It calls following-method selected from variable
         (mime-header-encode-method-alist
          (append
           '((wl-draft-eword-encode-address-list
-             .  (To Cc Bcc Resent-To Resent-Cc Bcc Resent-Bcc)))
+             .  (To Cc Bcc Resent-To Resent-Cc Resent-Bcc From)))
           (if (boundp 'mime-header-encode-method-alist)
               (symbol-value 'mime-header-encode-method-alist))))
         mime-view-ignored-field-list   ; all header.
@@ -273,25 +273,26 @@ It calls following-method selected from variable
                 (yes-or-no-p
                  (format "Do you really want to delete part %s? "
                          (wl-mime-node-id-to-string node-id))))
-       (with-temp-buffer
-         (insert-buffer orig-buf)
-         (delete-region header-start body-end)
-         (goto-char header-start)
-         (insert "Content-Type: text/plain; charset=US-ASCII\n\n")
-         (insert "** This part has been removed by Wanderlust **\n\n")
-         (elmo-folder-append-buffer folder t))
-
-       (elmo-folder-append-messages
-        (wl-folder-get-elmo-folder wl-trash-folder)
-        folder (list number) nil)
-       (elmo-folder-delete-messages folder (list number))
-
-       (when (file-exists-p (elmo-cache-get-path msgid))
-         (delete-file (elmo-cache-get-path msgid)))
-
-       (mime-preview-quit)
-       (wl-summary-toggle-disp-msg 'off)
-       (wl-summary-sync nil "update")))))
+       (when (with-temp-buffer
+               (insert-buffer orig-buf)
+               (delete-region header-start body-end)
+               (goto-char header-start)
+               (insert "Content-Type: text/plain; charset=US-ASCII\n\n")
+               (insert "** This part has been removed by Wanderlust **\n\n")
+               (elmo-folder-append-buffer folder t))
+
+         (elmo-folder-move-messages
+          folder (list number)
+          (wl-folder-get-elmo-folder wl-trash-folder))
+         (when (and (elmo-cache-get-path msgid)
+                    (file-exists-p (elmo-cache-get-path msgid)))
+           (delete-file (elmo-cache-get-path msgid)))
+
+         (mime-preview-quit)
+         (wl-summary-delete-messages-on-buffer (list number))
+         (wl-summary-toggle-disp-msg 'off)
+         (setq wl-message-buffer nil)
+         (wl-summary-sync nil "update"))))))
 
 (defun wl-message-decrypt-pgp-nonmime ()
   "Decrypt PGP encrypted region"
@@ -311,49 +312,59 @@ It calls following-method selected from variable
            (message "Cannot find pgp encrypted region")))
       (message "Cannot find pgp encrypted region"))))
 
-(defun wl-message-verify-pgp-nonmime ()
-  "Verify PGP signed region"
-  (interactive)
+(defun wl-message-verify-pgp-nonmime (&optional arg)
+  "Verify PGP signed region.
+With ARG, ask coding system and encode the region with it before verifying."
+  (interactive "P")
   (require 'pgg)
   (save-excursion
     (beginning-of-line)
-    (if (and (or (re-search-forward "^-+END PGP SIGNATURE-+$" nil t)
-                (re-search-backward "^-+END PGP SIGNATURE-+$" nil t))
-            (re-search-backward "^-+BEGIN PGP SIGNED MESSAGE-+$" nil t))
-       (let (status m-beg)
-         (let* ((beg (point))
-                (situation (mime-preview-find-boundary-info))
-                (p-end (aref situation 1))
-                (entity (aref situation 2))
-                (count 0))
-           (goto-char p-end)
-           (while (< beg (point))
-             (if (re-search-backward "^-+BEGIN PGP SIGNED MESSAGE-+$" nil t)
-                 (setq count (+ count 1))
-               (defbug)))
-           (with-temp-buffer
-             (set-buffer-multibyte nil)
-             (insert (mime-entity-body entity))
-             (goto-char (point-max))
-             (while (> count 0)
-               (if (re-search-backward "^-+BEGIN PGP SIGNED MESSAGE-+$" nil t)
-                   (setq count (- count 1))
-                 (debug)))
-             (let ((r-beg (point))
-                   (r-end (re-search-forward "^-+END PGP SIGNATURE-+$" nil t)))
-               (if r-end
-                   (setq status (pgg-verify-region r-beg r-end nil 'fetch))
-                 (debug)))))
-         (mime-show-echo-buffer)
-         (set-buffer mime-echo-buffer-name)
-         (set-window-start
-          (get-buffer-window mime-echo-buffer-name)
-          (point-max))
-         (setq m-beg (point))
-         (insert-buffer-substring
-          (if status pgg-output-buffer pgg-errors-buffer))
-         (decode-coding-region m-beg (point) wl-cs-autoconv))
-      (message "Cannot find pgp signed region"))))
+    (let ((msg-buf (current-buffer))
+         beg end status m-beg)
+      (if (and (when (or (re-search-forward "^-+END PGP SIGNATURE-+$" nil t)
+                        (re-search-backward "^-+END PGP SIGNATURE-+$" nil t))
+                (setq end (match-end 0)))
+              (setq beg (re-search-backward "^-+BEGIN PGP SIGNED MESSAGE-+$" nil t)))
+         (progn
+           (if arg
+               (with-temp-buffer
+                 (insert-buffer-substring msg-buf beg end)
+                 (set-mark (point-min))
+                 (goto-char (point-max))
+                 (call-interactively 'encode-coding-region)
+                 (setq status (pgg-verify-region (point-min) (point-max) nil 'fetch)))
+             (let* ((situation (mime-preview-find-boundary-info))
+                    (p-end (aref situation 1))
+                    (entity (aref situation 2))
+                    (count 0))
+               (goto-char p-end)
+               (while (< beg (point))
+                 (if (re-search-backward "^-+BEGIN PGP SIGNED MESSAGE-+$" nil t)
+                     (setq count (+ count 1))
+                   (debug)))
+               (with-temp-buffer
+                 (insert (mime-entity-body entity))
+                 (goto-char (point-max))
+                 (while (> count 0)
+                   (if (re-search-backward "^-+BEGIN PGP SIGNED MESSAGE-+$" nil t)
+                       (setq count (- count 1))
+                     (debug)))
+                 (let ((r-beg (point))
+                       (r-end (re-search-forward "^-+END PGP SIGNATURE-+$" nil t)))
+                   (if r-end
+                       (setq status (pgg-verify-region r-beg r-end nil 'fetch))
+                     (debug))))))
+           (mime-show-echo-buffer)
+           (set-buffer mime-echo-buffer-name)
+           (set-window-start
+            (get-buffer-window mime-echo-buffer-name)
+            (point-max))
+           (setq m-beg (point))
+           (insert-buffer-substring
+            (if status pgg-output-buffer pgg-errors-buffer))
+           (encode-coding-region m-beg (point) buffer-file-coding-system)
+           (decode-coding-region m-beg (point) wl-cs-autoconv))
+       (message "Cannot find pgp signed region")))))
 
 ;; XXX: encrypted multipart isn't represented as multipart
 (defun wl-mime-preview-application/pgp (parent-entity entity situation)
@@ -427,12 +438,12 @@ With ARG, ask destination folder."
   (interactive "P")
   (let ((raw-buf (wl-summary-get-original-buffer))
        (view-buf wl-message-buffer)
-       children message-entity content-type target)
+       children message-entity content-type target-name target)
     (save-excursion
       (setq target wl-summary-buffer-elmo-folder)
       (when (or arg (not (elmo-folder-writable-p target)))
-       (let ((fld (wl-summary-read-folder wl-default-folder "to extract to")))
-         (setq target (wl-folder-get-elmo-folder fld))))
+       (setq target-name (wl-summary-read-folder wl-default-folder "to extract to"))
+       (setq target (wl-folder-get-elmo-folder target-name)))
       (wl-summary-set-message-buffer-or-redisplay)
       (with-current-buffer view-buf
        (setq message-entity (get-text-property (point-min) 'mime-view-entity)))
@@ -443,7 +454,9 @@ With ARG, ask destination folder."
        (message "Bursting...done"))
       (if (elmo-folder-plugged-p target)
          (elmo-folder-check target)))
-    (wl-summary-sync-update)))
+    (when (or (not target-name)
+             (string= wl-summary-buffer-folder-name target-name))
+      (save-excursion (wl-summary-sync-update)))))
 
 ;; internal variable.
 (defvar wl-mime-save-directory nil "Last saved directory.")