From: Benjamin Rutt <rutt+news@cis.ohio-state.edu>
Subject: [patch] message-fetch-field, message-remove-header called improperly
Date: Thu, 29 May 2003 14:43:51 -0400 [thread overview]
Message-ID: <wc3he7dk2zc.fsf@gamma.cis.ohio-state.edu> (raw)
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.
next reply other threads:[~2003-05-29 18:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-05-29 18:43 Benjamin Rutt [this message]
2003-06-06 21:07 ` [patch] message-fetch-field, message-remove-header called Kai Großjohann
2003-06-06 23:40 ` Simon Josefsson
2003-06-07 1:03 ` Benjamin Rutt
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=wc3he7dk2zc.fsf@gamma.cis.ohio-state.edu \
--to=rutt+news@cis.ohio-state.edu \
/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.
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 NNTP newsgroup(s).