From f3173f4bd94c327c6f8feaa192e52d7972976b0c Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Tue, 2 May 2000 22:02:54 +0000 Subject: [PATCH] Implement CLOSE-FOLDER method for file folders, by discarding the messages in the folder. The messages are automatically reloaded when needed. --- v7/src/imail/imail-file.scm | 24 ++++++++++++++++++------ v7/src/imail/imail-rmail.scm | 14 +++++++------- v7/src/imail/imail-umail.scm | 17 ++++++++++------- 3 files changed, 35 insertions(+), 20 deletions(-) diff --git a/v7/src/imail/imail-file.scm b/v7/src/imail/imail-file.scm index ba81d03d6..fac6cf89b 100644 --- a/v7/src/imail/imail-file.scm +++ b/v7/src/imail/imail-file.scm @@ -1,6 +1,6 @@ ;;; -*-Scheme-*- ;;; -;;; $Id: imail-file.scm,v 1.12 2000/05/02 21:42:07 cph Exp $ +;;; $Id: imail-file.scm,v 1.13 2000/05/02 22:02:33 cph Exp $ ;;; ;;; Copyright (c) 1999-2000 Massachusetts Institute of Technology ;;; @@ -58,9 +58,16 @@ ;;;; Folder (define-class () - (messages define standard initial-value '()) + (messages define standard + accessor %file-folder-messages + initial-value 'UNKNOWN) (modification-time define standard initial-value #f)) +(define (file-folder-messages folder) + (if (eq? 'UNKNOWN (%file-folder-messages folder)) + (%revert-folder folder)) + (%file-folder-messages folder)) + (define (file-folder-pathname folder) (file-url-pathname (folder-url folder))) @@ -71,8 +78,13 @@ (folder-not-modified! folder)) (define-method %close-folder ((folder )) - folder - unspecific) + (without-interrupts + (lambda () + (let ((messages (%file-folder-messages folder))) + (if (not (eq? 'UNKNOWN messages)) + (begin + (set-file-folder-messages! folder 'UNKNOWN) + (for-each detach-message messages))))))) (define-method %folder-valid? ((folder )) (file-exists? (file-folder-pathname folder))) @@ -103,7 +115,7 @@ (set-message-index! message 0) (list message))))) (message-modified! message))))) - + (define-method expunge-deleted-messages ((folder )) (without-interrupts (lambda () @@ -125,7 +137,7 @@ (loop (cdr messages) (fix:+ index 1) (cons (car messages) messages*)))))))) - + (define-method search-folder ((folder ) criteria) (cond ((string? criteria) (let ((n (folder-length folder))) diff --git a/v7/src/imail/imail-rmail.scm b/v7/src/imail/imail-rmail.scm index 6fb28bad8..78fcbd980 100644 --- a/v7/src/imail/imail-rmail.scm +++ b/v7/src/imail/imail-rmail.scm @@ -1,6 +1,6 @@ ;;; -*-Scheme-*- ;;; -;;; $Id: imail-rmail.scm,v 1.19 2000/04/27 02:16:41 cph Exp $ +;;; $Id: imail-rmail.scm,v 1.20 2000/05/02 22:02:49 cph Exp $ ;;; ;;; Copyright (c) 1999-2000 Massachusetts Institute of Technology ;;; @@ -38,10 +38,15 @@ ;;;; Server operations (define-method %open-folder ((url )) - (read-rmail-file (file-url-pathname url))) + (if (not (file-readable? (file-url-pathname url))) + (error:bad-range-argument url 'OPEN-FOLDER)) + (make-rmail-folder url)) (define-method %new-folder ((url )) + (if (file-exists? (file-url-pathname url)) + (error:bad-range-argument url 'NEW-FOLDER)) (let ((folder (make-rmail-folder url))) + (set-file-folder-messages! folder '()) (set-rmail-folder-header-fields! folder (compute-rmail-folder-header-fields folder)) @@ -77,11 +82,6 @@ ;;;; Read RMAIL file -(define (read-rmail-file pathname) - (let ((folder (make-rmail-folder (make-rmail-url pathname)))) - (%revert-folder folder) - folder)) - (define-method %revert-folder ((folder )) (call-with-binary-input-file (file-folder-pathname folder) (lambda (port) diff --git a/v7/src/imail/imail-umail.scm b/v7/src/imail/imail-umail.scm index c16bb6beb..4aacbde9e 100644 --- a/v7/src/imail/imail-umail.scm +++ b/v7/src/imail/imail-umail.scm @@ -1,6 +1,6 @@ ;;; -*-Scheme-*- ;;; -;;; $Id: imail-umail.scm,v 1.13 2000/05/02 21:09:08 cph Exp $ +;;; $Id: imail-umail.scm,v 1.14 2000/05/02 22:02:54 cph Exp $ ;;; ;;; Copyright (c) 1999-2000 Massachusetts Institute of Technology ;;; @@ -38,13 +38,21 @@ ;;;; Server operations (define-method %open-folder ((url )) - (read-umail-file (file-url-pathname url))) + (if (not (file-readable? (file-url-pathname url))) + (error:bad-range-argument url 'OPEN-FOLDER)) + (make-umail-folder url)) (define-method %new-folder ((url )) + (if (file-exists? (file-url-pathname url)) + (error:bad-range-argument url 'NEW-FOLDER)) (let ((folder (make-umail-folder url))) + (set-file-folder-messages! folder '()) (save-folder folder) folder)) +(define (read-umail-file pathname) + (make-umail-folder (make-umail-url pathname))) + ;;;; Folder (define-class ( (constructor (url))) ()) @@ -60,11 +68,6 @@ ;;;; Read unix mail file -(define (read-umail-file pathname) - (let ((folder (make-umail-folder (make-umail-url pathname)))) - (%revert-folder folder) - folder)) - (define-method %revert-folder ((folder )) (set-file-folder-messages! folder -- 2.25.1