-- Transport Mechanism Mail Server - public DEFS for mailboxes --

-- [Indigo]<Grapevine>MS>MailboxDefs.mesa

-- Andrew Birrell  September 14, 1982 2:15 pm --

DIRECTORY
  BodyDefs USING [ItemLength, RName, Timestamp],
  HeapDefs USING [ObjectNumber],
  ProtocolDefs USING [Handle, Remark];


MailboxDefs: DEFINITIONS =
  BEGIN

  MBXHandle: TYPE [SIZE[POINTER]];

  -- Writer (single operation) --

  MBXWrite: PROCEDURE [
    who: BodyDefs.RName, obj: HeapDefs.ObjectNumber, postmark: BodyDefs.Timestamp]
    RETURNS [done: BOOLEAN];
  -- Claims the mailbox, returning FALSE if this isn't
  -- possible, appends the item to the mailbox,
  -- increments the reference count on the object
  -- number, then frees the mailbox for others --

  WaitForUnlocked: PROC;
  -- returns if some mailbox has been unlocked since last call of this --

  -- Reader (one only per Mailbox) --

  Poll: PROC [who: BodyDefs.RName] RETURNS [found: BOOLEAN];
  -- determines whether there is mail for the R-Name --

  Open: PROC [who: BodyDefs.RName]
    RETURNS [found: BOOLEAN, count: CARDINAL, mbx: MBXHandle];
  -- Claims the mailbox, or returns FALSE.  Count is the
  -- number of messages in the mailbox. --

  NextMessage: PROC [mbx: MBXHandle]
    RETURNS [msgExists, archived, deleted: BOOLEAN];

  ReadTOC: PROC [mbx: MBXHandle, text: ProtocolDefs.Remark];

  InaccessibleArchive: ERROR;
  -- may be raised by SendBody, SendText, DeleteMessage, FlushAndClose,
  -- FlushCacheAndRemail, and Remail, and by Archive.

  SendBody: PROC [mbx: MBXHandle, str: ProtocolDefs.Handle];
  -- Sends the complete body object on the given stream.

  SendText: PROC [
    mbx: MBXHandle, sendLength: PROC [BodyDefs.ItemLength], str: UNSPECIFIED,
    sendBytes: PROC [UNSPECIFIED, POINTER, CARDINAL]];
  -- This procedure is for the MTP server.
  -- If the body has a Text item, calls "sendLength", then
  -- make multiple calls of "sendBytes".

  WriteTOC: PROC [mbx: MBXHandle, text: ProtocolDefs.Remark];

  DeleteMessage: PROC [mbx: MBXHandle];

  FlushAndClose: PROC [mbx: MBXHandle];

  Close: PROC [mbx: MBXHandle];

  FlushCacheAndRemail: PROC [who: BodyDefs.RName];

  Remail: PROC [who: BodyDefs.RName, valid: BOOLEAN];

  Archive: PROC [who: BodyDefs.RName, keep: CARDINAL];
  -- archives specified mailbox, keeping "keep" messages un-archived --
  -- May raise InaccessibleArchive if all archive servers are down --

  END.