From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Wolfgang Jenkner Newsgroups: gmane.emacs.bugs Subject: bug#8988: 24.0.50; [PATCH] pop3-open-server fails to parse response to CAPA Date: Sun, 03 Jul 2011 04:33:11 +0200 Message-ID: <85sjqo5bj7.fsf@iznogoud.viz> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1309661078 18400 80.91.229.12 (3 Jul 2011 02:44:38 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 3 Jul 2011 02:44:38 +0000 (UTC) Cc: larsi@gnus.org To: 8988@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Jul 03 04:44:33 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QdCfg-0005Gs-B9 for geb-bug-gnu-emacs@m.gmane.org; Sun, 03 Jul 2011 04:44:32 +0200 Original-Received: from localhost ([::1]:39596 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QdCfe-00051k-Uh for geb-bug-gnu-emacs@m.gmane.org; Sat, 02 Jul 2011 22:44:31 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:45309) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QdCfF-00050v-3E for bug-gnu-emacs@gnu.org; Sat, 02 Jul 2011 22:44:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QdCfD-0000pK-EI for bug-gnu-emacs@gnu.org; Sat, 02 Jul 2011 22:44:04 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:44147) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QdCfC-0000pC-Qi for bug-gnu-emacs@gnu.org; Sat, 02 Jul 2011 22:44:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1QdCfC-0004lR-7v; Sat, 02 Jul 2011 22:44:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Wolfgang Jenkner Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 03 Jul 2011 02:44:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 8988 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.130966104018298 (code B ref -1); Sun, 03 Jul 2011 02:44:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 3 Jul 2011 02:44:00 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QdCfA-0004l4-2i for submit@debbugs.gnu.org; Sat, 02 Jul 2011 22:44:00 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QdCf8-0004kt-22 for submit@debbugs.gnu.org; Sat, 02 Jul 2011 22:43:59 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QdCf1-0000oB-BC for submit@debbugs.gnu.org; Sat, 02 Jul 2011 22:43:52 -0400 Original-Received: from lists.gnu.org ([140.186.70.17]:45892) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QdCf0-0000o0-Uo for submit@debbugs.gnu.org; Sat, 02 Jul 2011 22:43:51 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:45237) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QdCez-0004y2-FG for bug-gnu-emacs@gnu.org; Sat, 02 Jul 2011 22:43:50 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QdCex-0000nm-NJ for bug-gnu-emacs@gnu.org; Sat, 02 Jul 2011 22:43:49 -0400 Original-Received: from mx12.lb01.inode.at ([62.99.145.14]:39765 helo=mx.inode.at) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QdCex-0000na-3D for bug-gnu-emacs@gnu.org; Sat, 02 Jul 2011 22:43:47 -0400 Original-Received: from [85.127.18.8] (port=9744 helo=iznogoud.viz) by smartmx-12.inode.at with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1QdCes-0004ZC-K7; Sun, 03 Jul 2011 04:43:43 +0200 Original-Received: from wolfgang by iznogoud.viz with local (Exim 4.76 (FreeBSD)) (envelope-from ) id 1QdCeq-00069p-8J; Sun, 03 Jul 2011 04:43:40 +0200 Mail-Followup-To: bug-gnu-emacs@gnu.org, larsi@gnus.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (berkeley-unix) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Sat, 02 Jul 2011 22:44:02 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:47812 Archived-At: When I evaluate (progn (load "pop3.el") (trace-function-background 'open-protocol-stream) (let ((pop3-stream-type 'starttls)) (ignore-errors (pop3-open-server "pop.gmx.com" 110)))) buffer *trace-output* contains ====================================================================== 1 -> open-protocol-stream: name="POP" buffer=# host="pop.gmx.com" service=110 parameters=(:type starttls :capability-command "CAPA " :end-of-command "^\\.? \\|^\\(-ERR\\|+OK \\).* " :success "^\\+OK.* " :return-list t :starttls-function (lambda (capabilities) (and (string-match "\\bSTLS\\b" capabilities) "STLS "))) 1 <- open-protocol-stream: (nil :greeting "+OK POP server ready H migmx003 " :capabilities "+OK Capability list follows " :type plain :error "Server does not support TLS") However, in the shell $ telnet pop.gmx.com 110 Trying 212.227.17.187... Connected to pop.gmx.com. Escape character is '^]'. +OK POP server ready H migmx007 CAPA +OK Capability list follows TOP USER UIDL STLS SASL PLAIN IMPLEMENTATION trinity . QUIT +OK POP server signing off Connection closed by foreign host. $ So it seems that "+OK Capability list follows" arrived in a separate chunk and was matched by the second alternative of the regexp specified for :end-of-command in pop3-open-server before the actual capability list followed and the regexp's first alternative had a chance to match. (I haven't tested this theory, though, since it seems valid as a theoretical possibility anyway :-) I include ChangeLog entries and patches for lisp/gnus/pop3.el and lisp/net/network-stream.el (I could also send a bzr bundle, but given that most of lisp/gnus is merged from the main Gnus repository this doesn't seem too practical). Wolfgang 2011-07-03 Wolfgang Jenkner * net/network-stream.el (open-network-stream) (network-stream-open-starttls, network-stream-open-tls) (network-stream-open-shell): New parameter :end-of-capability, like :end-of-command but matches the end of the response to a :capability-command query. 2011-07-03 Wolfgang Jenkner * pop3.el (pop3-open-server): Use :end-of-capability. === modified file 'lisp/net/network-stream.el' --- lisp/net/network-stream.el 2011-06-27 00:11:22 +0000 +++ lisp/net/network-stream.el 2011-07-02 23:38:45 +0000 @@ -98,6 +98,10 @@ :end-of-command specifies a regexp matching the end of a command. +:end-of-capability specifies a regexp matching the end of the + response to the command specified for :capability-command. + It defaults to the regexp specified for :end-of-command. + :success specifies a regexp matching a message indicating a successful STARTTLS negotiation. For instance, the default should be \"^3\" for an NNTP connection. @@ -129,6 +133,10 @@ asynchronously, if possible." (unless (featurep 'make-network-process) (error "Emacs was compiled without networking support")) + ;; (unless (plist-get parameters :end-of-capability) + ;; (setq parameters (plist-put parameters + ;; :end-of-capability + ;; (plist-get parameters :end-of-command)))) (let ((type (plist-get parameters :type)) (return-list (plist-get parameters :return-list))) (if (and (not return-list) @@ -203,11 +211,12 @@ (success-string (plist-get parameters :success)) (capability-command (plist-get parameters :capability-command)) (eoc (plist-get parameters :end-of-command)) + (eo-capa (or (plist-get parameters :end-of-capability) eoc)) ;; Return (STREAM GREETING CAPABILITIES RESULTING-TYPE) (stream (make-network-process :name name :buffer buffer :host host :service service)) (greeting (network-stream-get-response stream start eoc)) - (capabilities (network-stream-command stream capability-command eoc)) + (capabilities (network-stream-command stream capability-command eo-capa)) (resulting-type 'plain) (builtin-starttls (and (fboundp 'gnutls-available-p) (gnutls-available-p))) @@ -250,7 +259,7 @@ ;; Requery capabilities for protocols that require it; i.e., ;; EHLO for SMTP. (when (plist-get parameters :always-query-capabilities) - (network-stream-command stream capability-command eoc))) + (network-stream-command stream capability-command eo-capa))) (when (string-match success-string (network-stream-command stream starttls-command eoc)) ;; The server said it was OK to begin STARTTLS negotiations. @@ -271,7 +280,7 @@ (network-stream-get-response stream start eoc))) ;; Re-get the capabilities, which may have now changed. (setq capabilities - (network-stream-command stream capability-command eoc)))) + (network-stream-command stream capability-command eo-capa)))) ;; If TLS is mandatory, close the connection if it's unencrypted. (when (and (or require-tls @@ -320,7 +329,8 @@ 'open-gnutls-stream 'open-tls-stream) name buffer host service)) - (eoc (plist-get parameters :end-of-command))) + (eoc (plist-get parameters :end-of-command)) + (eo-capa (or (plist-get parameters :end-of-capability) eoc))) (if (null stream) (list nil nil nil 'plain) ;; If we're using tls.el, we have to delete the output from @@ -335,13 +345,14 @@ (let* ((capability-command (plist-get parameters :capability-command))) (list stream (network-stream-get-response stream start eoc) - (network-stream-command stream capability-command eoc) + (network-stream-command stream capability-command eo-capa) 'tls)))))) (defun network-stream-open-shell (name buffer host service parameters) (require 'format-spec) (let* ((capability-command (plist-get parameters :capability-command)) (eoc (plist-get parameters :end-of-command)) + (eo-capa (or (plist-get parameters :end-of-capability) eoc)) (start (with-current-buffer buffer (point))) (stream (let ((process-connection-type nil)) (start-process name buffer shell-file-name @@ -353,7 +364,7 @@ ?p service)))))) (list stream (network-stream-get-response stream start eoc) - (network-stream-command stream capability-command eoc) + (network-stream-command stream capability-command eo-capa) 'plain))) (provide 'network-stream) === modified file 'lisp/gnus/pop3.el' --- lisp/gnus/pop3.el 2011-05-30 22:11:52 +0000 +++ lisp/gnus/pop3.el 2011-07-02 23:38:45 +0000 @@ -306,7 +306,12 @@ (t (or pop3-stream-type 'network))) :capability-command "CAPA\r\n" - :end-of-command "^\\.\r?\n\\|^\\(-ERR\\|+OK \\).*\n" + :end-of-command "^\\(-ERR\\|+OK \\).*\n" + ;; As it happens, the regexp above also matches the first + ;; line of the response to CAPA, which might arrive in + ;; a separate chunk, with the actual capabilities + ;; following later. + :end-of-capability "^\\.\r?\n" :success "^\\+OK.*\n" :return-list t :starttls-function