From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/64959 Path: news.gmane.org!not-for-mail From: Michael Sperber Newsgroups: gmane.emacs.gnus.general Subject: pgg-gpg doesn't work at all [fix included] Date: Wed, 25 Jul 2007 12:15:48 +0200 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1185380270 27916 80.91.229.12 (25 Jul 2007 16:17:50 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 25 Jul 2007 16:17:50 +0000 (UTC) Cc: Daiki Ueno , Sascha Wilde To: ding@gnus.org Original-X-From: ding-owner+M13469@lists.math.uh.edu Wed Jul 25 18:17:48 2007 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from util0.math.uh.edu ([129.7.128.18]) by lo.gmane.org with esmtp (Exim 4.50) id 1IDjYZ-0008To-7V for ding-account@gmane.org; Wed, 25 Jul 2007 18:17:47 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by util0.math.uh.edu with smtp (Exim 4.63) (envelope-from ) id 1IDjYF-0000J5-Vh; Wed, 25 Jul 2007 11:17:28 -0500 Original-Received: from mx1.math.uh.edu ([129.7.128.32]) by util0.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1IDdua-00078Z-NS for ding@lists.math.uh.edu; Wed, 25 Jul 2007 05:16:08 -0500 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx1.math.uh.edu with esmtp (Exim 4.67) (envelope-from ) id 1IDduY-0006lc-UF for ding@lists.math.uh.edu; Wed, 25 Jul 2007 05:16:08 -0500 Original-Received: from main.gmane.org ([80.91.229.2] helo=ciao.gmane.org) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1IDduX-0000gb-00 for ; Wed, 25 Jul 2007 12:16:05 +0200 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1IDduR-0006zF-6h for ding@gnus.org; Wed, 25 Jul 2007 12:15:59 +0200 Original-Received: from p54a0f93a.dip.t-dialin.net ([84.160.249.58]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 25 Jul 2007 12:15:59 +0200 Original-Received: from sperber by p54a0f93a.dip.t-dialin.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 25 Jul 2007 12:15:59 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 124 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: p54a0f93a.dip.t-dialin.net User-Agent: Gnus/5.110006 (No Gnus v0.6) XEmacs/21.5-b28 (darwin) Cancel-Lock: sha1:8Qvd42Q5056SIYI3TbOKuhFZv5Q= X-Spam-Score: -2.6 (--) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:64959 Archived-At: --=-=-= Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Hi there, I've long been frustrated by GnuPG decryption not working from Gnus. (It just wouldn't accept the passphrase I entered.) I finally tracked down the reasons for it: pgg-gpg runs gpg with --command-fd, and then dumps the data to be decryped its way. The problem is that gpg (1.4.7) doesn't buffer the data: After it's received enough lines, it asks for the passphrase. If the data is sufficiently large, this will be before the end of the data. However, pgg-gpg merrily throws more data at it---which won't wash as a passphrase. (This is really a GnuPG problem at its heart, I believe.) Also because of this, the handling of the pending status list doesn't work. Moreover, for me, gpg exits abnormally even when it's done its job right. I've included an abominable fix, which sends the data line-by-line, and, of course, slows everything down. But at least it works for decryption. Suggestions for improvement welcome. -- Cheers =8-} Mike Friede, Völkerverständigung und überhaupt blabla --=-=-= Content-Disposition: inline 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) --=-=-=--