Index: pgg-gpg.el =================================================================== RCS file: /usr/local/cvsroot/gnus/lisp/pgg-gpg.el,v retrieving revision 7.27 diff -u -r7.27 pgg-gpg.el --- pgg-gpg.el 1 Mar 2007 23:43:33 -0000 7.27 +++ pgg-gpg.el 25 Jul 2007 10:14:45 -0000 @@ -124,8 +124,9 @@ (let* ((status (match-string 1)) (symbol (intern-soft (concat "pgg-gpg-status-" status)))) - (if (member status pgg-gpg-pending-status-list) - (setq pgg-gpg-pending-status-list nil)) + (if (not (member status pgg-gpg-pending-status-list)) + (setq pgg-gpg-pending-status-list + (cons status pgg-gpg-pending-status-list))) (if (and symbol (fboundp symbol)) (funcall symbol process (buffer-substring @@ -150,23 +151,29 @@ (set-buffer (get-buffer-create pgg-output-buffer)) (buffer-disable-undo) (erase-buffer) - (if (equal status "finished\n") - (let ((output-file-name - (with-current-buffer (process-buffer process) - pgg-gpg-output-file-name))) - (when (file-exists-p output-file-name) - (let ((coding-system-for-read (if pgg-text-mode - 'raw-text - 'binary))) - (insert-file-contents output-file-name)) - (delete-file output-file-name)))) + (let ((output-file-name + (with-current-buffer (process-buffer process) + pgg-gpg-output-file-name))) + (when (file-exists-p output-file-name) + (let ((coding-system-for-read (if pgg-text-mode + 'raw-text + 'binary))) + (insert-file-contents output-file-name)) + (delete-file output-file-name))) (kill-buffer (process-buffer process))))) +(defun pgg-gpg-status-list-received (status-list) + (catch 'pgg-gpg-status-list-received + (while status-list + (if (not (member (car status-list) pgg-gpg-pending-status-list)) + (throw 'pgg-gpg-status-list-received nil)) + (setq status-list (cdr status-list))) + t)) + (defun pgg-gpg-wait-for-status (process status-list) (with-current-buffer (process-buffer process) - (setq pgg-gpg-pending-status-list status-list) (while (and (eq (process-status process) 'run) - pgg-gpg-pending-status-list) + (not (pgg-gpg-status-list-received status-list))) (accept-process-output process 1)))) (defun pgg-gpg-wait-for-completion (process) @@ -282,7 +289,7 @@ "Decrypt the current region between START and END." (let* ((args '("--decrypt")) (process (pgg-gpg-start-process args))) - (process-send-region process start end) + (pgg-gpg-send-region process start end) (pgg-gpg-wait-for-status process '("BEGIN_DECRYPTION")) (pgg-gpg-wait-for-completion process) (save-excursion @@ -346,6 +353,19 @@ (goto-char (point-max)) (not (null (re-search-backward "^\\[GNUPG:] IMPORT_RES\\>" nil t)))))) + +(defun pgg-gpg-send-region (process start end) + "Send region to process line-by-line, as GnuPG may intersperse +it with output." + (goto-char start) + (while (< (point) end) + (let ((bol (point))) + (end-of-line) + (let ((line (buffer-substring bol (point)))) + (forward-line) + (process-send-string process (concat line "\n")) + (if (accept-process-output process 0 1) + (while (accept-process-output process 0.3))))))) (provide 'pgg-gpg)