[gnu.emacs] emacs RMAIL --> MH

crew@polya.Stanford.EDU (Roger Crew) (02/01/89)

Does anyone have anything to convert mail files in
Babyl format of emacs' RMAIL to something usable by mh?

For that matter, does someone have a description of what Babyl format
is supposed to be.  This is something that should be included in the
gnu-emacs documentation but, as far as I can tell, isn't (as of 18.52).

--
Roger Crew					``Beam Wesley into the sun!''
Usenet:    {arpa gateways, decwrl, uunet, rutgers}!polya.stanford.edu!crew
Internet:  crew@polya.Stanford.EDU

mende@athos.rutgers.edu (Bob Mende Pie) (02/01/89)

In article <6536@polya.Stanford.EDU> crew@polya.Stanford.EDU (Roger Crew)
writes:

> For that matter, does someone have a description of what Babyl format
> is supposed to be.  This is something that should be included in the
> gnu-emacs documentation but, as far as I can tell, isn't (as of 18.52).

  I got this a long time ago... I hope it helps...


From: rlk@think.COM (Robert Krawitz)
Subject: Re: RMAIL/Babyl format
Date: 30 Nov 87 15:56:46 GMT

Let's see if I remember my BNF for babyl files; this corresponds to
version 5:

File := <header>
	<message>*	; Some say there must be at least one message.

Header := Babyl Options:\n
	  <header-option>*
	  |^_

Header-option := <header-token>	; See note [5]
		 : *
		 <value>

header-token := [^\000-\017:\177-\377]*	; Not these characters [tab is OK]
header-value := ditto, if a list, each element separated by a comma and
		a space.

message := \^L\n
	   [01],	; See note [1] below
	   ( <attribute>,)*	; Note space before and comma after token
	   ,
	   ( <label>,)*		; ditto, see note [4] below
	   \n
	   <header>*	; See note [1] and [2] below
	   *** EOOH ***\n
	   <header>*	; See note [2] below
	   \n
	   <body>
	   \^_

attribute := unseen |
	     last |	; Not all programs implement this.  It
			; generally only gets used internally, and
			; isn't written out to a file.
	     >last |	; Babyl uses this for a deleted message at the
			; end.  It shouldn't be written out to a file.
	     deleted |
	     recent |	; Not all programs implement this.  It refers
			; to a message in the last batch of new mail;
			; thus it probably shouldn't be written out to
			; a file during a normal save although it
			; makes sense to write it out in an emergency save.
	     filed |
	     answered |
	     forwarded |
	     redistributed |
	     badheader |	; Not all programs implement this
	     filed		; Not all programs implement this

label := [^\000-\020,\177-\377]*	; No control chars,
			; whitespace, commas, rubout, or high bit set

header := [^\000-\020:\177-\377]*:
	  <header-line>
	  <header-line>*

header-line := [ \t][^\n]*\n	; Continuation lines must be indented

body := (.*\n)*		; See note [3] below


[1] A zero means that the headers have not been cleaned up,
reprocessed, toggled, or whatever.  In this case there should be no
headers before the EOOH line.  A one means that the headers have been
reprocessed.  In this case, the original headers will typically be
before the EOOH line and the reformatted or whatever subset of headers
that the user should see will be after it.  Note that in this case
it's permissible to garbage collect all headers before the EOOH line.
No one's defined what it means to garbage collect SOME of the headers
before this line, or what that means.

[2] It's apparently permissible to add headers of the program's own
choosing before the EOOH line.  Or at least, Rmail does so (it caches
a summary line) and nothing seems to object.  There's no particular
guarantee that something else won't step all over it, though.  Headers
after the EOOH line can be reformatted as the program wishes (e. g.
indent the header lines to the same distance, canonicalize machine
names) for display to the user.  It's generally best for programs that
read a babyl file to look at the headers before the EOOH line if they
exist, since these should be untouched by the user.  Remember, the
user can edit anything after the EOOH line.

[3] A \^_ at the beginning of a line should be quoted somehow.  The
normal way seems to be to decompose it into 2 characters: a ^ and a _.
Strictly speaking, it doesn't always have to be, since the following
text would have to be parsable as a message, but some programs don't
try to use that much intelligence.  Oh well.

[4] Labels, or keywords as they are often called, are generally
defined by the user, although it's not entirely impermissible for a
program to use these for its own purpose (e. g. a keyword named
RemindMe might be used to automatically find important messages).
Some people also want these used to cache other state implemented by
certain programs; this use is undefined.  Note that all keywords used
should be inserted in a header-option named Keywords:.  Can a keyword
have the same name as an attribute?  Who knows?  It's probably not a
good idea, since some programs use the concept of <labels> =
<keywords> + <attributes>.  Sigh.

[5] Some tokens are standardized in meaning.  Common tokens are Mail
inboxes, babyl file version number, which is currently 5, labels used
in messages, window format for Zmail, anything else you want to be
associated with a file.  Be warned that labels should be a complete
list of all user-defined keywords used in the file, so if you add a
new label to a message, you should add it to this list.  You should
also have a Babyl version: 5 file attribute (look in a babyl file for
details).

Anyone know if there actually is a "formal" standard?  This was done
quickly from memory and a Zmail manual, but there are at least three
programs around that use Babyl files (zmail, babyl, and emacs/rmail)
and someone at SIPB was going to write a command-based mail reader
similar to Unix Mail but operating on babyl files, and someone (of
course not me :-)) should probably write xbabyl :-)

References:

ITS/Tops-20 INFO file on babyl (who wrote it?  ECC?  GZ?)

Zmail manual (the MIT version was written by RMS; ECC wrote the
section on Babyl file format)


					/Bob...
-- 

mdb@amadeus.silvlis.com (Mark D. Baushke) (02/04/89)

>  From: crew@polya.Stanford.EDU (Roger Crew)
>  Newsgroups: comp.mail.mh,gnu.emacs
>  Followup-To: gnu.emacs
>  Date: 1 Feb 89 03:44:14 GMT
>
>  Does anyone have anything to convert mail files in
>  Babyl format of emacs' RMAIL to something usable by mh?
>
>  For that matter, does someone have a description of what Babyl format
>  is supposed to be.  This is something that should be included in the
>  gnu-emacs documentation but, as far as I can tell, isn't (as of 18.52).

The following lisp functions deal with rmail Babyl files as an add-on
to the standard rmail.el. I wrote the function rmail-to-mbox-all when
I finally switched to MH 6.6 + mh-e.el.

	M-x rmail-to-mbox-all RET temp-mail RET

After you write all of your messages into a file (for example
"temp-mail"), use "inc -file temp-mail" to incorporate it into
whaterver folder you desire.

Enjoy!
------------------------------------------------------------------------------
Mark D. Baushke                 Internet:    mdb%silvlis.com@sun.com
Silvar-Lisco, Inc.              Nameservers: mdb@silvlis.com
1080 Marsh Road                 Usenet:      {pyramid,sgi,sun}!silvlis!mdb
Menlo Park, CA 94025-1053       Telephone:   +1 415 853-6411 / +1 415 969-8328


;;;;;;;;;;;;;;;;;;;;;;;;;;; -*- Mode: Emacs-Lisp -*- ;;;;;;;;;;;;;;;;;;;;;;;;;;
;; rmail-extras.el --- reduce the size of RMAIL files by removing junk
;;  	    	       put all messages of an RMAIL file back into a
;;		       UN*X-style mail file again.
;; Copyright  (c)  1988, 1989  by  Mark D. Baushke,  All Rights Reserved.
;; 
;; Author          : Mark D. Baushke <mdb@silvlis.com>
;; Created On      : Sat Jan 16 00:20:04 1988
;; Last Modified By: Mark D. Baushke
;; Last Modified On: Sun Aug 28 18:50:37 1988
;; Update Count    : 13
;; Status          : Works for me
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; This file may be used as part of GNU Emacs.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY.  No author or distributor
;; accepts responsibility to anyone for the consequences of using it
;; or for whether it serves any particular purpose or works at all,
;; unless he says so in writing.  Refer to the GNU Emacs General Public
;; License for full details.

;; Everyone is granted permission to copy, modify and redistribute
;; GNU Emacs, but only under the conditions described in the
;; GNU Emacs General Public License.   A copy of this license is
;; supposed to have been given to you along with GNU Emacs so you
;; can know your rights and responsibilities.  It should be in a
;; file named COPYING.  Among other things, the copyright notice
;; and this notice must be preserved on all copies.

(require 'rmail)

(defconst rmail-deletable-headers
  "^via:\\|^mail-from:\\|^origin:\\|^status:\\|^received:\\|^from \\|^errors-to:"
  "\
*Gubbish header fields one may delete with impunity.")

(defun rmail-verbose-headers ()
  "Get to the verbose mail header."
  (if (search-forward "\n\n" nil t)
      (save-restriction
        (narrow-to-region (point-min) (point))
	(let ((buffer-read-only nil))
	  (while (let ((case-fold-search t))
		   (goto-char (point-min))
		   (re-search-forward rmail-deletable-headers nil t))
	    (beginning-of-line)
	    (delete-region (point)
			   (progn (re-search-forward "\n[^ \t]")
				  (forward-char -1)
				  (point))))))))

(defun rmail-shrink-header ()
  "Shrink original message header like pruned header."
  (interactive)
  (rmail-maybe-set-message-counters)
  (narrow-to-region (rmail-msgbeg rmail-current-message) (point-max))
  (let ((buffer-read-only nil))
    (goto-char (point-min))
    (forward-line 1)
    (if (= (following-char) ?1)
	(progn (delete-char 1)
	       (insert ?0)
	       (forward-line 1)
	       (if (looking-at "Summary-Line:")
		   (forward-line 1))
	       (insert "*** EOOH ***\n")
	       (forward-char -1)
	       (search-forward "\n*** EOOH ***\n")
	       (forward-line -1)
	       (let ((temp (point)))
		 (and (search-forward "\n\n" nil t)
		      (delete-region temp (point))))
      ))
    (goto-char (point-min))
    (search-forward "\n*** EOOH ***\n")
    (goto-char (point))
    (if rmail-deletable-headers (rmail-verbose-headers))
    (rmail-reformat-message (point-min) (point-max))))

(defun rmail-compress-all ()
  "Shrink all of the messages."
  (interactive)
  (let ((msgnum 1)
	(origmsg (rmail-what-message)))
    (while (>= rmail-total-messages msgnum)
      (message "Compressing messages...%d" msgnum)
      (rmail-show-message msgnum)
      (rmail-shrink-header)
      (setq msgnum (1+ msgnum))
      )
    (message "Compressing messages...done")
    (rmail-show-message origmsg)))

(defun rmail-delete-n (&optional n)
  "Delete the next n messages and move to next nondeleted one.
Deleted messages stay in the file until the \\[rmail-expunge] command is given."
  (interactive "p")
  (while (>= n 1)
    (message "Deleteing messages...%d" (rmail-what-message))
    (rmail-set-attribute "deleted" t)
    (setq n (1- n))
    (rmail-next-message 1)
    )
  (message "Deleteing messages...done"))

(defun rmail-undelete-n (&optional n)
  "unDelete the next n messages and move to last nondeleted one."
  (interactive "p")
  (while (>= n 1)
    (message "Deleteing messages...%d" (rmail-what-message))
    (rmail-set-attribute "deleted" nil)
    (setq n (1- n))
    (rmail-next-message 1)
    )
  (message "Deleteing messages...done"))

(defun rmail-to-mbox-all (file-name)
  "Write all messages in Shrink all of the messages."
  (interactive
   (list
    (read-file-name
     (concat "Output message to Unix mail file"
	     (if rmail-last-file
		 (concat " (default "
			 (file-name-nondirectory rmail-last-file)
			 "): " )
	       ": "))			
     (and rmail-last-file (file-name-directory rmail-last-file))
     rmail-last-file)))
  (setq file-name (expand-file-name file-name))
  (setq rmail-last-file file-name)
  (let ((msgnum 1)
	(origmsg (rmail-what-message)))
    (while (>= rmail-total-messages msgnum)
      (message "Writing messages...%d" msgnum)
      (rmail-show-message msgnum)
      (rmail-output file-name)
      (setq msgnum (1+ msgnum))
      )
    (message "Writing messages...done")
    (rmail-show-message origmsg)))
--
------------------------------------------------------------------------------
Mark D. Baushke                 Internet:    mdb%silvlis.com@sun.com
Silvar-Lisco, Inc.              Nameservers: mdb@silvlis.com
1080 Marsh Road                 Usenet:      {pyramid,sgi,sun}!silvlis!mdb
Menlo Park, CA 94025-1053       Telephone:   +1 415 853-6411 / +1 415 969-8328