From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/52927 Path: main.gmane.org!not-for-mail From: Benjamin Rutt Newsgroups: gmane.emacs.gnus.general Subject: [patch] message-fetch-field, message-remove-header called improperly Date: Thu, 29 May 2003 14:43:51 -0400 Sender: ding-owner@lists.math.uh.edu Message-ID: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1054234377 22094 80.91.224.249 (29 May 2003 18:52:57 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Thu, 29 May 2003 18:52:57 +0000 (UTC) Original-X-From: ding-owner+M1471@lists.math.uh.edu Thu May 29 20:52:53 2003 Return-path: Original-Received: from malifon.math.uh.edu ([129.7.128.13]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19LSMR-0004oF-00 for ; Thu, 29 May 2003 20:42:47 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by malifon.math.uh.edu with smtp (Exim 3.20 #1) id 19LSO5-0000kt-00; Thu, 29 May 2003 13:44:29 -0500 Original-Received: from sclp3.sclp.com ([64.157.176.121]) by malifon.math.uh.edu with smtp (Exim 3.20 #1) id 19LSNv-0000kl-00 for ding@lists.math.uh.edu; Thu, 29 May 2003 13:44:19 -0500 Original-Received: (qmail 24934 invoked by alias); 29 May 2003 18:44:19 -0000 Original-Received: (qmail 24929 invoked from network); 29 May 2003 18:44:18 -0000 Original-Received: from mail.cis.ohio-state.edu (HELO cis.ohio-state.edu) (164.107.115.5) by sclp3.sclp.com with SMTP; 29 May 2003 18:44:18 -0000 Original-Received: from gamma.cis.ohio-state.edu (daemon@gamma.cis.ohio-state.edu [164.107.112.13]) by cis.ohio-state.edu (8.11.6/8.11.6) with ESMTP id h4TIhp713601 for ; Thu, 29 May 2003 14:43:51 -0400 (EDT) Original-Received: (from rutt@localhost) by gamma.cis.ohio-state.edu (8.11.6/8.11.6) id h4TIhpJ03921; Thu, 29 May 2003 14:43:51 -0400 (EDT) X-Authentication-Warning: gamma.cis.ohio-state.edu: rutt set sender to rutt@cis.ohio-state.edu using -f Original-To: ding@gnus.org Mail-Followup-To: ding@gnus.org User-Agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.3.50 (usg-unix-v) Precedence: bulk Xref: main.gmane.org gmane.emacs.gnus.general:52927 X-Report-Spam: http://spam.gmane.org/gmane.emacs.gnus.general:52927 I believe that `message-fetch-field' and `message-remove-header' should only be called when the message buffer has been narrowed to the headers. I have found that this is not always the case in message.el. As a result, there are a few flaws in some callers of the above said functions, and I've attached a patch below. In some cases (e.g. if a header-like line is present in the body, which it is sometimes when people are discussing mail and newsreaders like on the gnus lists), calling `message-remove-header' un-narrowed could destroy some part of the body of the message, which is clearly wrong. And similarly, calling `message-fetch-field' un-narrowed means that some body lines which look like headers might be mis-interpreted as header lines (e.g. see `message-change-subject'). The following functions have been fixed: `message-change-subject' `message-reduce-to-to-cc' `message-generate-unsubscribed-mail-followup-to' `message-insert-importance-low' `message-insert-importance-high' `message-insert-or-toggle-importance' `message-insert-disposition-notification-to' And finally, the docstring was enhanced in `message-fetch-field' to remind the elisp programmer that it must be called from a buffer narrowed to the headers. The fact that un-narrowed `message-fetch-field' calls keep showing up in gnus code on newsgroups and in message.el means that the users of that method are not aware enough of the narrowing issue. I think the doc patch helps. Here is the patch against current CVS head message.el: Index: message.el =================================================================== RCS file: /usr/local/cvsroot/gnus/lisp/message.el,v retrieving revision 6.345 diff -c -r6.345 message.el *** message.el 28 May 2003 21:35:28 -0000 6.345 --- message.el 29 May 2003 18:53:59 -0000 *************** *** 1533,1539 **** (looking-at message-unix-mail-delimiter)))) (defun message-fetch-field (header &optional not-all) ! "The same as `mail-fetch-field', only remove all newlines." (let* ((inhibit-point-motion-hooks t) (case-fold-search t) (value (mail-fetch-field header nil (not not-all)))) --- 1533,1540 ---- (looking-at message-unix-mail-delimiter)))) (defun message-fetch-field (header &optional not-all) ! "The same as `mail-fetch-field', only remove all newlines. ! The buffer is expected to be narrowed to just the header of the message." (let* ((inhibit-point-motion-hooks t) (case-fold-search t) (value (mail-fetch-field header nil (not not-all)))) *************** *** 1664,1670 **** (zerop (string-width new-subject)) (string-match "^[ \t]*$" new-subject)))) (save-excursion ! (let ((old-subject (message-fetch-field "Subject"))) (cond ((not old-subject) (error "No current subject")) ((not (string-match --- 1665,1674 ---- (zerop (string-width new-subject)) (string-match "^[ \t]*$" new-subject)))) (save-excursion ! (let ((old-subject ! (save-restriction ! (message-narrow-to-headers) ! (message-fetch-field "Subject")))) (cond ((not old-subject) (error "No current subject")) ((not (string-match *************** *** 1850,1868 **** (defun message-reduce-to-to-cc () "Replace contents of To: header with contents of Cc: or Bcc: header." (interactive) ! (let ((cc-content (message-fetch-field "cc")) (bcc nil)) (if (and (not cc-content) ! (setq cc-content (message-fetch-field "bcc"))) (setq bcc t)) (cond (cc-content (save-excursion (message-goto-to) (message-delete-line) (insert (concat "To: " cc-content "\n")) ! (message-remove-header (if bcc ! "bcc" ! "cc"))))))) ;;; End of functions adopted from `message-utils.el'. --- 1854,1879 ---- (defun message-reduce-to-to-cc () "Replace contents of To: header with contents of Cc: or Bcc: header." (interactive) ! (let ((cc-content ! (save-restriction (message-narrow-to-headers) ! (message-fetch-field "cc"))) (bcc nil)) (if (and (not cc-content) ! (setq cc-content ! (save-restriction ! (message-narrow-to-headers) ! (message-fetch-field "bcc")))) (setq bcc t)) (cond (cc-content (save-excursion (message-goto-to) (message-delete-line) (insert (concat "To: " cc-content "\n")) ! (save-restriction ! (message-narrow-to-headers) ! (message-remove-header (if bcc ! "bcc" ! "cc")))))))) ;;; End of functions adopted from `message-utils.el'. *************** *** 2512,2522 **** Cc: header are also put into the MFT." (interactive "P") ! (message-remove-header "Mail-Followup-To") ! (let* ((cc (and include-cc (message-fetch-field "Cc"))) ! (tos (if cc ! (concat (message-fetch-field "To") "," cc) ! (message-fetch-field "To")))) (message-goto-mail-followup-to) (insert (concat tos ", " user-mail-address)))) --- 2523,2536 ---- Cc: header are also put into the MFT." (interactive "P") ! (let* (cc tos) ! (save-restriction ! (message-narrow-to-headers) ! (message-remove-header "Mail-Followup-To") ! (setq cc (and include-cc (message-fetch-field "Cc"))) ! (setq tos (if cc ! (concat (message-fetch-field "To") "," cc) ! (message-fetch-field "To")))) (message-goto-mail-followup-to) (insert (concat tos ", " user-mail-address)))) *************** *** 2779,2785 **** "Insert header to mark message as important." (interactive) (save-excursion ! (message-remove-header "Importance") (message-goto-eoh) (insert "Importance: high\n"))) --- 2793,2801 ---- "Insert header to mark message as important." (interactive) (save-excursion ! (save-restriction ! (message-narrow-to-headers) ! (message-remove-header "Importance")) (message-goto-eoh) (insert "Importance: high\n"))) *************** *** 2787,2793 **** "Insert header to mark message as unimportant." (interactive) (save-excursion ! (message-remove-header "Importance") (message-goto-eoh) (insert "Importance: low\n"))) --- 2803,2811 ---- "Insert header to mark message as unimportant." (interactive) (save-excursion ! (save-restriction ! (message-narrow-to-headers) ! (message-remove-header "Importance")) (message-goto-eoh) (insert "Importance: low\n"))) *************** *** 2800,2813 **** (let ((valid '("high" "normal" "low")) (new "high") cur) ! (when (setq cur (message-fetch-field "Importance")) ! (message-remove-header "Importance") ! (setq new (cond ((string= cur "high") ! "low") ! ((string= cur "low") ! "normal") ! (t ! "high")))) (message-goto-eoh) (insert (format "Importance: %s\n" new))))) --- 2818,2833 ---- (let ((valid '("high" "normal" "low")) (new "high") cur) ! (save-restriction ! (message-narrow-to-headers) ! (when (setq cur (message-fetch-field "Importance")) ! (message-remove-header "Importance") ! (setq new (cond ((string= cur "high") ! "low") ! ((string= cur "low") ! "normal") ! (t ! "high"))))) (message-goto-eoh) (insert (format "Importance: %s\n" new))))) *************** *** 2816,2825 **** Note that this should not be used in newsgroups." (interactive) (save-excursion ! (message-remove-header "Disposition-Notification-To") (message-goto-eoh) (insert (format "Disposition-Notification-To: %s\n" ! (or (message-fetch-field "From") (message-make-from)))))) (defun message-elide-region (b e) "Elide the text in the region. --- 2836,2851 ---- Note that this should not be used in newsgroups." (interactive) (save-excursion ! (save-restriction ! (message-narrow-to-headers) ! (message-remove-header "Disposition-Notification-To")) (message-goto-eoh) (insert (format "Disposition-Notification-To: %s\n" ! (or (save-excursion ! (save-restriction ! (message-narrow-to-headers) ! (message-fetch-field "From"))) ! (message-make-from)))))) (defun message-elide-region (b e) "Elide the text in the region.