From: kevin@edscom.demon.co.uk (Kevin Broadey)
Subject: Improved FCC handling for sendmail
Organization: EDS-Scicon, Milton Keynes, UK
Date: Fri, 21 Aug 1992 13:13:17 GMT

Here's a modification to the sendmail.el file from emacs 18.57 that
makes FCC: handling when sending mail the same as when posting
articles from GNUS.

I have mail-archive-file-name set to "~/SMAIL" and use RMAIL to read
it (C-u M-x rmail ~/SMAIL RET).

The problem I had was that when I did C-c C-s (mail-send) in the
*mail* buffer I got "Buffer is read-only: #<buffer SMAIL>".

This is because `mail-do-fcc' spotted that a buffer was already
visiting the file, so switched to it and tried to append without
checking the buffer-read-only flag.

The fix uses code lifted from gnus.el.  Many thanks to whoever wrote it.

Following is the diffs between my file and the original.  You need to do

    (cat sendmail.diffs; echo '1,$p') | ed - sendmail.el > sendmail.new

to make the new version.

Enjoy.

== sendmail.diffs =============================================================
303a

(defun mail-convert-region-to-rmail (start end)
  "Convert region from START to END in current buffer to Rmail message format."
    ;; Convert region directly into Babyl format.
    ;; Suggested by Rob Austein <sra@lcs.mit.edu>
    ;; Plagiarised by Kevin Broadey <kbroadey@edscom.demon.co.uk>
    ;; from gnus-convert-article-to-rmail in gnus.el.
  (let ((buffer-read-only nil))
    (save-excursion
      (save-restriction
	(narrow-to-region start end)
	(goto-char (point-min))
	(insert "\^L\n0, unseen,,\n*** EOOH ***\n")
	(while (search-forward "\n\^_" nil t) ;single char
	  (replace-match "\n^_"))	;2 chars: "^" and "_"
	(goto-char (point-max))
	(insert "\^_")))))
.
296,299c
		(set-buffer buffer)
		(if (eq major-mode 'rmail-mode)
		    ;; buffer is in RMAIL mode - be clever with messages.
		    (let ((buffer-read-only nil)
			  (curmsg rmail-current-message))
		      (widen)
		      (narrow-to-region (point-max) (point-max))
		      (insert-buffer-substring curbuf beg end)
		      (mail-convert-region-to-rmail (point-min) (point-max))
		      (goto-char (point-min))
		      (widen)
		      (search-backward "\^_")
		      (narrow-to-region (point) (point-max))
		      (goto-char (1+ (point-min)))
		      (rmail-count-new-messages t)
		      (rmail-show-message curmsg))
		  ;; Else not in rmail-mode - tag message on at end.
		  (if (or (not buffer-read-only)
			  (y-or-n-p
			   (format "Buffer %s is read-only. Append anyway? "
				   (buffer-name buffer))))
		      (let ((buffer-read-only nil))
			(save-excursion
			  (save-restriction
			    (goto-char (point-max))
			    (insert-buffer-substring curbuf beg end))))
		    )))
.
19a
;; 21-08-92  Kevin Broadey  EDS-Scicon
;; File Carbon Copy feature: Change mail-do-fcc to spot when the buffer
;; visiting the FCC file is in RMAIL mode and make it append the message in
;; BABYL format, updating rmail's variables as well.  Also, ask whether to
;; append to a read-only buffer instead of bombing out.
;;
;; This has been unashamedly lifted from the GNUS `gnus-output-to-rmail'
;; function.
.
===============================================================================
--
Kevin Broadey <kbroadey@edscom.demon.co.uk>
EDS-Scicon, Wavendon Tower, Wavendon, Milton Keynes, MK17 8LX, England.
Phone: +44 908 284198 (direct) or +44 908 585858 ext 4198
These opinions are mine: others available on request.
Newsgroups: gnu.emacs.gnus