-- Transport mechanism: Maintain: commonly used commands

-- [Indigo]<Grapevine>Maintain>MaintainCommon.mesa

-- Andrew Birrell 14-Jan-82 13:23:52

DIRECTORY
Ascii		USING[ CR ],
BodyDefs	USING[ Password ],
MaintainPrivate	USING[ CantCheckName, CheckMailName, CopyName, Failed,
		       Handle, ReadPassword, ReadWord, Update ],
NameInfoDefs	USING[ IsMemberDirect ],
String		USING[ EquivalentString ];

MaintainCommon: PROGRAM
IMPORTS MaintainPrivate, NameInfoDefs, String
EXPORTS MaintainPrivate =

BEGIN

OPEN MaintainPrivate;

CreateIndividual: PUBLIC PROC[handle: MaintainPrivate.Handle] = 
  BEGIN
  OPEN handle;
  pwstring: STRING = [32];
  pw: BodyDefs.Password;
  ReadWord[glass, ": "L, individual];
  CopyName[from: individual, to: dName];
  pw ← ReadPassword[glass, " with password: "L, pwstring];
  Update[handle: handle, op: CreateIndividual, name: individual, key: pw];
  glass.WriteChar[Ascii.CR];
  glass.WriteString["--> Add Mailbox"L];
  AddMailbox[handle];
  END;

AddMailbox: PUBLIC PROC[handle: MaintainPrivate.Handle] = 
  BEGIN
  OPEN handle, handle.glass;
  ReadWord[glass, " at server: "L, name];
  IF NOT String.EquivalentString[name, "Maxc"L]
  THEN SELECT NameInfoDefs.IsMemberDirect["MailDrop.ms"L, name] FROM
         allDown => SIGNAL CantCheckName[name];
         no, notGroup =>
           IF handle.verifying
           THEN { WriteString[" ... """L]; WriteString[name];
                  WriteString[""" is not a valid mailbox site"L];
                  ERROR MaintainPrivate.Failed[] }
           ELSE WriteString[" (bad site)"L];
         yes => NULL;  -- name is an ok inbox site --
       ENDCASE => ERROR;
  ReadWord[glass, " for individual: "L, individual];
  CopyName[from: individual, to: dName];
  Update[handle: handle, op: AddMailBox, name: individual, value: name];
  END;


AddMember: PUBLIC PROC[handle: MaintainPrivate.Handle] = 
  BEGIN
  OPEN handle;
  ReadWord[glass, ": "L, name];
  CheckMailName[name];
  ReadWord[glass, " to group: "L, group];
  CopyName[from: group, to: dName];
  Update[handle: handle, op: AddMember, name: group, value: name]
  END;

RemoveMember: PUBLIC PROC[handle: MaintainPrivate.Handle] =
  BEGIN
  OPEN handle;
  ReadWord[glass, ": "L, name];
  ReadWord[glass, " from group: "L, group];
  CopyName[from: group, to: dName];
  Update[handle: handle, op: DeleteMember, name: group, value: name]
  END;

END.