-- File: GVMailParseImpl.mesa
-- Contents: Implementation of GVMailParse veneer on top of MailParse, for Cedar

-- last editted by
-- Willie-Sue, January 21, 1983 10:41 am
-- Rick, XXX

DIRECTORY
MailParse,
GVMailParse,
ConvertUnsafe USING [ToRope],
Rope USING [Lower];

GVMailParseImpl: CEDAR PROGRAM
IMPORTS MailParse, ConvertUnsafe, Rope
EXPORTS GVMailParse =

BEGIN
OPEN GVMailParse;

ParseError: PUBLIC ERROR [code: ParseErrorCode] = CODE;

InitializeParse: PUBLIC PROC[next: PROC RETURNS [CHARACTER],
backup: PROC, notifyTruncation: BOOLEANFALSE] RETURNS [ParseHandle] = TRUSTED
{ RETURN[MailParse.InitializeParse[next, backup, notifyTruncation]] };

FinalizeParse: PUBLIC PROC[pH: ParseHandle] = TRUSTED{ MailParse.FinalizeParse[pH] };

-- returns the field name, without the terminating colon
-- uses a local string only
GetFieldName: PUBLIC PROC[pH: ParseHandle] RETURNS [found: BOOLEAN, fieldNameOut: ROPE] = TRUSTED
BEGIN
fno: STRING← [100];  -- is this enough??
found← MailParse.GetFieldName[pH, fno
   ! MailParse.ParseError => ERROR ParseError[code]];
fieldNameOut← ConvertUnsafe.ToRope[LONG[fno]];
END;

GetFieldBody: PUBLIC PROC[pH: ParseHandle, suppressWhiteSpace: BOOLEANFALSE]
RETURNS[fieldBodyOut: ROPE] = TRUSTED
BEGIN
fbo: STRING← [512];
MailParse.GetFieldBody[pH, fbo, suppressWhiteSpace
  ! MailParse.ParseError => ERROR ParseError[code]];
fieldBodyOut← ConvertUnsafe.ToRope[LONG[fbo]];
END;

ParseNameList: PUBLIC PROC[
pH: ParseHandle,
process: PROC[ROPE, ROPE, ROPE, NameInfo] RETURNS [BOOLEAN],
write: PROC[CHAR] ← NIL, suppressWhiteSpace: BOOLEANFALSE] = TRUSTED
BEGIN
cProcess: PROC[s1,s2,s3: STRING, n1: NameInfo] RETURNS [BOOLEAN] = TRUSTED
BEGIN
FOR i: CARDINAL IN [0..s2.length) DO s2[i]← Rope.Lower[s2[i]]; ENDLOOP;
RETURN[process[ConvertUnsafe.ToRope[LONG[s1]], ConvertUnsafe.ToRope[LONG[s2]],
ConvertUnsafe.ToRope[LONG[s3]], n1]];
END;
MailParse.ParseNameList[pH, cProcess, write, suppressWhiteSpace
    ! MailParse.ParseError => ERROR ParseError[code]];
END;

GetListOrGroupName: PUBLIC PROC[pH: ParseHandle] RETURNS[ROPE] = TRUSTED
BEGIN
n: STRING← [512];
MailParse.GetListOrGroupName[pH, n];
RETURN[ConvertUnsafe.ToRope[LONG[n]]];
END;

GetTag: PUBLIC PROC[pH: ParseHandle] RETURNS[ROPE] = TRUSTED
BEGIN
n: STRING← [512];
MailParse.GetTag[pH, n];
RETURN[ConvertUnsafe.ToRope[LONG[n]]];
END;

END.