From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mark Lillibridge Newsgroups: gmane.emacs.devel Subject: need help tracking down a subtle bug with unrmail/mail-strip-quoted-names Date: Thu, 23 Dec 2010 19:32:15 -0800 Message-ID: Reply-To: mark.lillibridge@hp.com NNTP-Posting-Host: lo.gmane.org X-Trace: dough.gmane.org 1293162089 25907 80.91.229.12 (24 Dec 2010 03:41:29 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 24 Dec 2010 03:41:29 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Dec 24 04:41:25 2010 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PVyWy-0005y8-HY for ged-emacs-devel@m.gmane.org; Fri, 24 Dec 2010 04:41:24 +0100 Original-Received: from localhost ([127.0.0.1]:51580 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PVyWx-0005rc-PL for ged-emacs-devel@m.gmane.org; Thu, 23 Dec 2010 22:41:23 -0500 Original-Received: from [140.186.70.92] (port=32945 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PVyOL-0001Qr-CU for emacs-devel@gnu.org; Thu, 23 Dec 2010 22:32:31 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PVyOJ-0004yt-25 for emacs-devel@gnu.org; Thu, 23 Dec 2010 22:32:29 -0500 Original-Received: from gundega.hpl.hp.com ([192.6.19.190]:59603) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PVyOI-0004y1-Pd for emacs-devel@gnu.org; Thu, 23 Dec 2010 22:32:27 -0500 Original-Received: from mailhub-pa1.hpl.hp.com (mailhub-pa1.hpl.hp.com [15.25.115.25]) by gundega.hpl.hp.com (8.14.3/8.14.3/HPL-PA Relay) with ESMTP id oBO3WITd020018 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Thu, 23 Dec 2010 19:32:18 -0800 Original-Received: from ts-rhel5 (ts-rhel5.hpl.hp.com [15.25.118.27]) by mailhub-pa1.hpl.hp.com (8.14.3/8.14.3/HPL-PA Hub) with ESMTP id oBO3WFKs007452; Thu, 23 Dec 2010 19:32:15 -0800 X-Scanned-By: MIMEDefang 2.69 on 15.0.48.190 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:133928 Archived-At: I've been working on tracking down the cause of a bug with unrmail (versions 23.1, 24) and have reached the point where I need some help. The original symptoms were that unrmail only processes some messages in certain BABYL files. Making a long story short, messages with nested from lines like: From: Knut Are Romann-Aas (by way of justicek@edge.ercnet.com (Kim cause unrmail to stop after processing them. (This is a very serious bug as it causes the loss of mail in practice.) The relevant code in unrmail from mail/unrmail.el appears to be: (defun unrmail (file to-file) ... (with-temp-buffer ... (let ((temp-buffer (get-buffer-create " unrmail")) (from-buffer (current-buffer))) ;; Process the messages one by one. (while (re-search-forward "^\^_\^l" nil t) ... (with-current-buffer temp-buffer ... (save-restriction (narrow-to-region (point-min) (save-excursion (search-forward "\n\n" nil 'move) (point))) ;; Fetch or construct what we should use in the `From ' line. (setq mail-from (or (let ((from (mail-fetch-field "Mail-From"))) ;; mail-mbox-from (below) returns a ;; string that ends in a newline, but ;; but mail-fetch-field does not, so ;; we append a newline here. (if from (format "%s\n" from))) (mail-mbox-from))) ) ;; Write it to the output file, suitably encoded. (let ((coding-system-for-write coding)) (write-region (point-min) (point-max) to-file t 'nomsg))))) (kill-buffer temp-buffer)) (message "Writing messages to %s...done" to-file))) Point seems to incorrectly change to 1 when the with-current-buffer call finishes iff the bug occurs. If I turn the call to (mail-mbox-from) to "dummy", the bug goes away (all messages are processed). The relevant code from that function from mail-utils.el: (defun mail-mbox-from () "Return an mbox \"From \" line for the current message. The buffer should be narrowed to just the header." (let ((from (or (mail-fetch-field "from") (mail-fetch-field "really-from") (mail-fetch-field "sender") "unknown")) (date (mail-fetch-field "date"))) (format "From %s %s\n" (mail-strip-quoted-names from) (or (and date (ignore-errors (current-time-string (date-to-time date)))) (current-time-string))))) If I turn (mail-strip-quoted-names from) into "dummy" again, the bug goes away. The relevant code for that function (same file) is: (defun mail-strip-quoted-names (address) (if (null address) nil (if mail-use-rfc822 (progn (require 'rfc822) (mapconcat 'identity (rfc822-addresses address) ", ")) (let (pos) ;; Detect nested comments. (if (string-match "[ \t]*(\\([^)\\]\\|\\\\.\\|\\\\\n\\)*(" address) ;; Strip nested comments. (with-current-buffer (get-buffer-create " *temp*") ... (erase-buffer)) ... ... ; code not involving buffers ) In particular, if I replace the call in unrmail to mail-mbox-from (really changing the relevant setq to setq mail-from "dummy" and adding the following line) with the following: (with-current-buffer (get-buffer-create " *temp*") (erase-buffer)) it causes the bug at the first message. However, the following variant does not cause the bug for any message: (with-current-buffer (get-buffer-create " *temp*") "dummy") This is the point where I need help; I don't just understand why erasing a temporary buffer should move point in a different buffer. - Thanks, Mark PS, in case it makes it clearer, the revised code looks like: (defun unrmail (file to-file) ... (with-temp-buffer ... (let ((temp-buffer (get-buffer-create " unrmail")) (from-buffer (current-buffer))) ;; Process the messages one by one. (while (re-search-forward "^\^_\^l" nil t) ... (with-current-buffer temp-buffer ... (save-restriction (narrow-to-region (point-min) (save-excursion (search-forward "\n\n" nil 'move) (point))) (with-current-buffer (get-buffer-create " *temp*") (erase-buffer)) ) ... ;; Write it to the output file, suitably encoded. (let ((coding-system-for-write coding)) (write-region (point-min) (point-max) to-file t 'nomsg)) ) ; end with-current-buffer ; POINT BECOMES 1 HERE for some reason )) (kill-buffer temp-buffer)) (message "Writing messages to %s...done" to-file)))