From: Mark Lillibridge <mark.lillibridge@hp.com>
To: emacs-devel@gnu.org
Subject: need help tracking down a subtle bug with unrmail/mail-strip-quoted-names
Date: Thu, 23 Dec 2010 19:32:15 -0800 [thread overview]
Message-ID: <qmh4oa3977k.fsf@hp.com> (raw)
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 <kromanna@sn.no> (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)))
next reply other threads:[~2010-12-24 3:32 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-24 3:32 Mark Lillibridge [this message]
2010-12-24 8:14 ` need help tracking down a subtle bug with unrmail/mail-strip-quoted-names Andreas Schwab
2010-12-24 17:52 ` Mark Lillibridge
2010-12-27 23:56 ` Mark Lillibridge
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=qmh4oa3977k.fsf@hp.com \
--to=mark.lillibridge@hp.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).