Gnus development mailing list
 help / color / mirror / Atom feed
* Help needed for a rmail-Gnus Mule problem
@ 2000-07-10 18:19 François Pinard
  0 siblings, 0 replies; only message in thread
From: François Pinard @ 2000-07-10 18:19 UTC (permalink / raw)


Hi, people.

I've been using the piece of code below for a good while, and despite
very, very useful for me, that code is irritating because of those (usual)
pesky \201's in all over in Latin-1 messages.  Even worse, these \201's
multiply like rabbits when I successively migrate a message between folders.

My feeling is that both RMAIL mode and Gnus are converting the file to
Mule, probably one message at a time in each case.  I wonder if someone
knowledgeable in Mule matters could not give me a hand with this: I'm lost!

By the way, the code might be useful to people handling Babyl (or RMAIL
mode) files.  For one, I keep a lot of archives in Babyl format.  The code
automatically triggers Gnus to read such files, and deletions from the
Gnus summary are later reflected in the Babyl files when exiting the summary.

I hope I include all pieces.  The code is a bit hairy, so please, be gentle
and don't laugh too loud! :-) Constructive criticisms always welcome!




;; FIXME: Rather depend on uniquification of names.
(defvar fp-rmail-display-with-gnus-counter 0
  "To make sure no two servers are simultaneously opened with the same name.")

;; FIXME: Something breaks when more than one Babyl in Gnus.  So use a lock.
(defvar fp-rmail-babyl-file-with-gnus-lock nil
  "Gnus summary buffer visiting a Babyl file, or nil if none.
To make sure only one Babyl file is visited in Gnus at a time.")

(defun fp-rmail-display-babyl-file-with-gnus (&optional article)
  "Display the whole Babyl file with Gnus, using a nndoc ephemeral server."
  (when (and fp-rmail-babyl-file-with-gnus-lock
	     (buffer-file-name fp-rmail-babyl-file-with-gnus-lock))
    (error "Gnus already displaying a Babyl file."))
  (let ((config (current-window-configuration))
	(rmail-buffer (current-buffer)))
    (fp-maybe-start-gnus)
    (let ((group (format "nndoc:%s-%d"
			 (file-name-nondirectory buffer-file-name)
			 (incf fp-rmail-display-with-gnus-counter))))
      (if (save-restriction
	    (widen)
	    (gnus-group-read-ephemeral-group
	     group `(nndoc ,group (nndoc-address ,rmail-buffer)
			   (nndoc-article-type babyl))
	     t (cons rmail-buffer config)))
	  (progn
	    (setq fp-rmail-babyl-file-with-gnus-lock (current-buffer))
	    (make-local-variable 'gnus-summary-prepare-exit-hook)
	    (add-hook 'gnus-summary-prepare-exit-hook
		      'fp-gnus-exit-babyl-file-group-routine)
	    (when article
	      (gnus-summary-goto-article article)))
	(set-buffer rmail-buffer)
	(gnus-error 3 "Babyl group couldn't be entered")))))

(defun fp-gnus-exit-babyl-file-group-routine ()
  "Reposition the Babyl file according to the current article in Gnus.
If not `Q', delete in the Babyl file what has not been kept on the Gnus side."
  (let ((current gnus-current-article)
	(unreads gnus-newsgroup-unreads)
	(ticked gnus-newsgroup-marked)
	message counter total)
    (save-excursion
      (set-buffer nndoc-address)
      (setq message 0
	    counter 0
	    total rmail-total-messages)
      (if (eq last-command-char ?Q)
	  (progn
	    (rmail-show-message current)
	    (save-buffer))
	(while (< message total)
	  (setq message (1+ message))
	  (unless (or (memq message unreads) (memq message ticked))
	    (message "Deleting message %d" message)
	    (rmail-show-message message t)
	    (rmail-delete-message)
	    (setq counter (1+ counter))))
	(rmail-show-message current)
	(cond ((zerop counter)
	       (save-buffer)
	       (message "All %d messages kept" total))
	      (t (rmail-expunge)
		 (setq total rmail-total-messages)
		 (save-buffer)
		 (if (> total 0)
		     (message "Deleted %d messages, keeping %d" counter total)
		   (delete-file buffer-file-name)
		   (message "Deleted file `%s'" buffer-file-name))
		 ;; Messages have been renumbered through expunging, article
		 ;; numbers from the summary are not dependable anymore.
		 ;; Dead summaries could become deadly if ever revived.
		 ;; To play safe, merely kill the Babyl buffer if expunged.
		 (kill-buffer (current-buffer))))
	(setq fp-rmail-babyl-file-with-gnus-lock nil)))))




(defvar fp-rmail-currently-visited-list nil)

(defun fp-rmail-mode-routine ()
  ;; [...]
  (local-set-key "!" 'fp-rmail-display-with-gnus)
  ;; [...]
  ;;; Immediately switch to Gnus, yet on initial visit only.
  (unless (member buffer-file-name fp-rmail-currently-visited-list)
    (push buffer-file-name fp-rmail-currently-visited-list)
    (let ((modified (buffer-modified-p)))
      (fp-rmail-display-babyl-file-with-gnus)
      ;; FIXME: I wonder what modified the buffer unconditionally.
      (set-buffer-modified-p modified))))
(add-hook 'rmail-mode-hook 'fp-rmail-mode-routine)

(defun fp-rmail-display-with-gnus (&optional flag)
  "Display the whole Babyl file with Gnus, using a nndoc ephemeral server.
With a flag argument, display only the current message instead, using nnone."
  (interactive "P")
  (if flag
      (fp-rmail-display-babyl-message-with-gnus)
    (fp-rmail-display-babyl-file-with-gnus rmail-current-message)))

(defun fp-rmail-display-babyl-message-with-gnus ()
  "Display current message with Gnus, using a nnone ephemeral server."
  ; [... not provided, not required, and probably not much useful...]
  nil)



(defun fp-maybe-start-gnus ()
  "Have Gnus started, if not already."
  (save-window-excursion
    (unless (gnus-alive-p)
      (gnus))))
(autoload 'gnus-alive-p "gnus-util")

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2000-07-10 18:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-07-10 18:19 Help needed for a rmail-Gnus Mule problem François Pinard

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).