;;; -*-Scheme-*-
;;;
-;;; $Id: imail-rmail.scm,v 1.45 2000/06/29 22:01:50 cph Exp $
+;;; $Id: imail-rmail.scm,v 1.46 2000/06/30 02:57:22 cph Exp $
;;;
;;; Copyright (c) 1999-2000 Massachusetts Institute of Technology
;;;
(call-with-binary-input-file pathname
(lambda (port)
(set-rmail-folder-header-fields! folder (read-rmail-prolog port))
- (let loop ()
- (let ((message (read-rmail-message port)))
- (if message
- (begin
- (append-message message (folder-url folder))
- (loop))))))))))
+ (let loop ((line #f))
+ (call-with-values (lambda () (read-rmail-message port line))
+ (lambda (message line)
+ (if message
+ (begin
+ (append-message message (folder-url folder))
+ (loop line)))))))))))
(define (read-rmail-prolog port)
- (if (not (string-prefix? "BABYL OPTIONS:" (read-required-line port)))
+ (if (not (rmail-prolog-start-line? (read-required-line port)))
(error "Not an RMAIL file:" port))
(lines->header-fields (read-lines-to-eom port)))
-(define (read-rmail-message port)
- (let ((line (read-line port)))
+(define (read-rmail-message port read-ahead-line)
+ (let ((line (or read-ahead-line (read-line port))))
(cond ((eof-object? line)
- #f)
- ((and (fix:= 1 (string-length line))
- (char=? rmail-message:start-char (string-ref line 0)))
- (read-rmail-message-1 port))
+ (values #f #f))
+ ((rmail-prolog-start-line? line)
+ (discard-to-eom port)
+ (read-rmail-message port #f))
+ ((rmail-message-start-line? line)
+ (values (read-rmail-message-1 port) #f))
+ ((umail-delimiter? line)
+ (read-umail-message line port
+ (lambda (line)
+ (or (rmail-prolog-start-line? line)
+ (rmail-message-start-line? line)
+ (umail-delimiter? line)))))
(else
(error "Malformed RMAIL file:" port)))))
;;;; Syntactic Markers
+(define (rmail-prolog-start-line? line)
+ (string-prefix? "BABYL OPTIONS:" line))
+
+(define (rmail-prolog-end-line? line)
+ (string-prefix? "\037" line))
+
+(define (rmail-message-start-line? line)
+ (string=? "\f" line))
+
(define rmail-message:headers-separator
"*** EOOH ***")
(if (or (eof-object? string)
(eof-object? (read-char port)))
(error "EOF while reading RMAIL message body:" port))
- string))
\ No newline at end of file
+ string))
+
+(define (discard-to-eom port)
+ (input-port/discard-chars port rmail-message:end-char-set)
+ (input-port/discard-char port))
\ No newline at end of file
;;; -*-Scheme-*-
;;;
-;;; $Id: imail-umail.scm,v 1.34 2000/06/20 19:46:56 cph Exp $
+;;; $Id: imail-umail.scm,v 1.35 2000/06/30 02:57:23 cph Exp $
;;;
;;; Copyright (c) 1999-2000 Massachusetts Institute of Technology
;;;
(error "Malformed unix mail file:" port))
(let loop ((from-line from-line) (index 0) (messages '()))
(call-with-values
- (lambda () (read-umail-message from-line port))
+ (lambda ()
+ (read-umail-message from-line
+ port
+ umail-delimiter?))
(lambda (message from-line)
(attach-message! message folder index)
(let ((messages (cons message messages)))
(loop from-line (+ index 1) messages)
(reverse! messages)))))))))))))))
-(define (read-umail-message from-line port)
- (let read-headers ((header-lines '()))
+(define (read-umail-message from-line port delimiter?)
+ (let loop ((lines '()))
(let ((line (read-line port)))
(cond ((eof-object? line)
- (values (read-umail-message-1 from-line
- (reverse! header-lines)
- '())
- #f))
- ((string-null? line)
- (let read-body ((body-lines '()))
- (let ((line (read-line port)))
- (cond ((eof-object? line)
- (values (read-umail-message-1 from-line
- (reverse! header-lines)
- (reverse! body-lines))
- #f))
- ((umail-delimiter? line)
- (values (read-umail-message-1 from-line
- (reverse! header-lines)
- (reverse! body-lines))
- line))
- (else
- (read-body (cons line body-lines)))))))
+ (values (read-umail-message-1 from-line (reverse! lines)) #f))
+ ((delimiter? line)
+ (values (read-umail-message-1 from-line (reverse! lines)) line))
(else
- (read-headers (cons line header-lines)))))))
-
-(define (read-umail-message-1 from-line header-lines body-lines)
+ (loop (cons line lines)))))))
+
+(define (read-umail-message-1 from-line lines)
+ (let loop ((lines lines) (header-lines '()))
+ (if (pair? lines)
+ (if (string-null? (car lines))
+ (read-umail-message-2 from-line
+ (reverse! header-lines)
+ (cdr lines))
+ (loop (cdr lines) (cons (car lines) header-lines)))
+ (read-umail-message-2 from-line (reverse! header-lines) '()))))
+
+(define (read-umail-message-2 from-line header-lines body-lines)
(call-with-values
(lambda ()
(parse-imail-header-fields (lines->header-fields header-lines)))
IMAIL To-Do List
-$Id: todo.txt,v 1.102 2000/06/29 22:02:34 cph Exp $
+$Id: todo.txt,v 1.103 2000/06/30 02:57:24 cph Exp $
Bug fixes
---------
-* RMAIL file reader must recognize when the tail of the file contains
- umail messages.
-
MIME conformance
----------------