🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.help
Article #189217

Re: Auto-folding a reply from a Babyl file

#189217
From: Jamie Zawinski
Date: Sat, 06 Apr 1991 22:13
105 lines
4668 bytes
It sounds to me like what you are describing is what the FCC: field does.

The function which handles this field (mail-do-fcc) will append the text to
the end of a buffer if the file in question is currently being visited.
However, it doesn't correctly deal with FCCing to files that are currently
being browsed in RMAIL mode.  Here is a version of mail-do-fcc that does
the right thing with both the RMAIL and VM mail readers.

The BABYL handling was mostly written by Dale Worley; the VM handling is by me.

If you use VM, you must load VM before compiling this function.  If you don't
use VM, don't worry about it.  (But VM is much better than RMAIL...)

	-- Jamie

(defun mail-do-fcc (header-end)
  (let (fcc-list
	(rmailbuf (current-buffer))
	(tembuf (generate-new-buffer " rmail output"))
	(case-fold-search t))
    (save-excursion
      (goto-char (point-min))
      (while (re-search-forward "^FCC:[ \t]*" header-end t)
	(setq fcc-list (cons (buffer-substring (point)
					       (progn
						 (end-of-line)
						 (skip-chars-backward " \t")
						 (point)))
			     fcc-list))
	(delete-region (match-beginning 0)
		       (progn (forward-line 1) (point))))
      (set-buffer tembuf)
      (erase-buffer)
      (insert "\nFrom " (user-login-name) " "
	      (current-time-string) "\n")
      (insert-buffer-substring rmailbuf)
      ;; Make sure messages are separated.
      (goto-char (point-max))
      (insert ?\n)
      (goto-char 2)
      ;; ``Quote'' "^From " as ">From "
      ;;  (note that this isn't really quoting, as there is no requirement
      ;;   that "^[>]+From " be quoted in the same transparent way.)
      (let ((case-fold-search nil))
	(while (search-forward "\nFrom " nil t)
	  (forward-char -5)
	  (insert ?>)))
      (while fcc-list
	(let ((buffer (get-file-buffer (car fcc-list))))
	  (if buffer
	      ;; File is present in a buffer => append to that buffer.
	      (let ((curbuf (current-buffer))
		    (beg (point-min)) (end (point-max)))
		(save-excursion
		  (set-buffer buffer)
		  (cond ((eq major-mode 'rmail-mode)
			 ;; Append as a message to an RMAIL file
			 (let ((b (point-min))
			       (e (point-max))
			       (buffer-read-only nil))
			   (unwind-protect
				(progn
				  (widen)
				  (goto-char (point-max))
				  ;; This forces RMAIL's message counters to be
				  ;; recomputed when the next RMAIL operation is
				  ;; done on the buffer.
				  ;; See rmail-maybe-set-message-counters.
				  (setq rmail-total-messages nil)
				  (insert "\C-l\n0, unseen,,\n*** EOOH ***")
				  ;; ## should only insert From: if there
				  ;; ## isn't one, but punt for now. -jwz.
				  ;; (insert "\nFrom: " (user-login-name))
				  (insert "\nDate: " (current-time-string))
				  ;; insert a comma after the day-of-week.
				  (beginning-of-line) (forward-word 2) (insert ?,)
				  (end-of-line)
				  (insert "\n")
				  (insert-buffer-substring rmailbuf)
			      (insert "\n\C-_"))
			  (narrow-to-region b e)
			  (rmail-maybe-set-message-counters)
			  )))
			((eq major-mode 'vm-mode)
			 (let ((buffer-read-only nil))
			   (vm-save-restriction
			     (widen)
			     (goto-char (point-max))
			     (insert-buffer-substring curbuf beg end)
			     (vm-increment vm-messages-not-on-disk)
			     (vm-set-buffer-modified-p t)
			     (vm-clear-modification-flag-undos)
			     (vm-check-for-killed-summary)
			     (vm-assimilate-new-messages)
			     (vm-update-summary-and-mode-line))))
			(t
			 ;; Append to an ordinary file as a Unix mail message
			 (goto-char (point-max))
			 (insert-buffer-substring curbuf beg end)))))
	    ;; Else append to the file directly.
	    ;; (It's OK if it is an RMAIL file -- the message will be converted
	    ;; when the file is read in.)
	    (write-region (point-min) (point-max) (car fcc-list) t)))
	(setq fcc-list (cdr fcc-list))))
    (kill-buffer tembuf)))
Technical Details
Message-ID: <JWZ.91Apr6171337@thalidomide.lucid.com>
Path: arc1-ca.pugleaf.net!gmdzi!unido!fauern!ira.uka.de!sol.ctr.columbia.edu!samsung!olivea!bu.edu!stanford.edu!lucid.com!campeau!jwz
References: <9104061447.AA03907@icule.UUCP>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 103b8b,65c836edbdc6faec
X-Google-Attributes: gid103b8b,public
X-Google-ArrivalTime: 1991-04-07 04:09:33 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!fauern!ira.uka.de!sol.ctr.columbia.edu!samsung!olivea!bu.edu!stanford.edu!lucid.com!campeau!jwz
From: jwz@lucid.com (Jamie Zawinski)
Newsgroups: gnu.emacs.help
Subject: Re: Auto-folding a reply from a Babyl file
Message-ID: <JWZ.91Apr6171337@thalidomide.lucid.com>
Date: 6 Apr 91 22:13:37 GMT
References: <9104061447.AA03907@icule.UUCP>
Sender: usenet@lucid.com
Organization: Lucid, Inc., Menlo Park, CA
Lines: 105
In-Reply-To: pinard%icule.UUCP@LARRY.MCRCIM.MCGILL.EDU's message of 6 Apr 91 14:47:18 GMT