1. mbox
    1. Description
    2. Library Procedures
      1. Message Predicates and Accessors
      2. Parsing Procedures: Preliminaries
      3. Parsing Procedures: mbox-string
      4. Parsing Procedures: mbox
    3. Requires
    4. Version History
    5. License



The mbox library contains procedures for parsing of mbox database files, RFC 4155. It is intended to conform closely to the ABNF grammar in the RFC.

Library Procedures

Message Predicates and Accessors

The parsing procedures in this library return a list of message objects. The following procedures are available for manipulating the message objects:

[procedure] (message? X) => BOOL

Returns #t if the given argument is a message object, #f otherwise.

[procedure] (message-envelope X) => ENVELOPE

Returns the envelope part of a message. The envelope is an s-expression of the following form:

((time-seconds R) [(ctime ...) | (abbrtime ...)] (address ADDRESS))

The time-seconds field contains the time when the message was received, in seconds since 1900. The ctime or abbrtime fields contain the components of the date/time string. The address fields is an s-expression of the form:

 ((local-part STRING) (domain STRING))
[procedure] (message-headers X) => (LAMBDA () => HEADERS)

Returns the headers part of a message. This is a procedure of no arguments that when invoked, returns the parsed list of headers in an alist where the key is the header name (as a symbol), and the value is the parsed header contents.

[procedure] (message-body X) => (LAMBDA ([P]) => BODY)

Returns the body part of a message. This is a procedure of a single argument, that when invoked, uses the given argument procedure to parse the message body, and returns the result.

Parsing Procedures: Preliminaries

The parsing procedures in mbox come in two flavors: generic and specialized for operations on strings.

The <Mbox> typeclass defined in module mbox provides generic parsing procedures. Please see the typeclass library for information on type classes. The <Mbox> typeclass is intended to provide abstraction over different kinds of input sequences, e.g. character lists, strings, streams, etc. <Mbox> inherits from <CoreABNF>, which provides the core parsing primitives used to build the mbox grammar parser (see the abnf and internet-message libraries for more information).

The procedures in module mbox-string operate on strings. They do not require the instantiaton of type classes and are meant to provide "turn key" parsing.

Parsing Procedures: mbox-string

[procedure] (mbox-file->messages FILENAME-OR-PORT) => MESSAGE LIST

Given a filename or port, parses the given file as an mbox database, and returns a list of message objects. The contents of the message are represented as a string.

Parsing Procedures: mbox

The <Mbox> typeclass has the following definition:

(define-class <Mbox> (<InetMessage> M) 
  mbox-file->messages )

The following example illustrates the creation of an instance of <Mbox> typeclass specialized for byte blobs (see byte-blob).

(require-extension typeclass input-classes byte-blob)

(require-library abnf internet-message mbox)
(import (only abnf <CoreABNF>  <Token> <CharLex> 
	      CharLex->CoreABNF Input->Token 
	(only internet-message <InetMessage> CoreABNF->InetMessage)
	(only mbox <Mbox> Input+.CoreABNF->Mbox)

(define byte-blob-<Input>
  (make-<Input> byte-blob-empty? 
		(compose byte->char byte-blob-car)

(define byte-blob-<Token>
  (Input->Token byte-blob-<Input>))

(define byte-blob-<CharLex>
  (Token->CharLex byte-blob-<Token>))

(define byte-blob-<CoreABNF>
  (CharLex->CoreABNF byte-blob-<CharLex>))

(define byte-blob-<InetMessage>
  (CoreABNF->InetMessage byte-blob-<CoreABNF> ))

(define byte-blob-<Input+>
  (make-<Input+> byte-blob-<Input> 
		 (compose blob->byte-blob string->blob)

(define byte-blob-<Mbox>
  (Input+.CoreABNF->Mbox byte-blob-<Input+>


Version History


 Copyright 2010-2017 Ivan Raikov.
 This program is free software: you can redistribute it and/or
 modify it under the terms of the GNU General Public License as
 published by the Free Software Foundation, either version 3 of the
 License, or (at your option) any later version.
 This program is distributed in the hope that it will be useful, but
 WITHOUT ANY WARRANTY; without even the implied warranty of
 General Public License for more details.
 A full copy of the GPL license can be found at