-- file: SearchMail.Mesa
-- edited by Brotz, December 19, 1980 2:20 PM

DIRECTORY
Ascii,
Editor,
exD: FROM "ExceptionDefs",
inD: FROM "InteractorDefs",
intCommon: FROM "IntCommon",
IODefs,
ovD: FROM "OverviewDefs",
tsD: FROM "TOCSelectionDefs",
vmD: FROM "VirtualMgrDefs";

SearchMail: PROGRAM
IMPORTS Editor, exD, inD, intC: intCommon, IODefs, tsD, vmD =

BEGIN


SearchForPatternInMailFile: PROCEDURE =
BEGIN
vm: vmD.DisplayMessagePtr;
toc: inD.TOCTextNbrPtr = intC.tocTextNbr;
index: vmD.TOCIndex;
mess: messageText inD.Nbr;
mnp: inD.MessageTextNbrPtr = @mess;
found, foundAny: BOOLEAN ← FALSE;
pattern: STRING ← [inD.maxBracketStringLength];

MyTerminator: PROCEDURE [char: CHARACTER] RETURNS [BOOLEAN] =
{RETURN[char = Ascii.CR]};

IF ~intC.haveMailFile THEN {exD.DisplayException[exD.noCurrentFile]; RETURN};
IODefs.WriteLine["Search pattern: "L];
[] ← IODefs.ReadString[pattern, MyTerminator];
IODefs.WriteChar[Ascii.CR];
vm ← vmD.AllocateDisplayMessageObject[];
mnp.message ← LOOPHOLE[vm];
tsD.DeconsiderAll[toc];
tsD.ResetTOCSelection[];
inD.UpdateTOCThumbLine[];
FOR index IN [1 .. vmD.GetFirstFreeTOCIndex[]) DO
IF vmD.VirtualizeMessage[index, vm] = ovD.ok THEN
BEGIN
[found, , ] ← Editor.FindOperation[pattern, 0, vmD.GetMessageSize[vm], mnp];
IF found THEN
BEGIN
IF foundAny THEN IODefs.WriteString[", "]
ELSE IODefs.WriteString["Messages containing pattern: "L];
foundAny ← TRUE;
tsD.AddRange[index, index + 1];
inD.Consider[index, index, toc];
IODefs.WriteDecimal[index];
IODefs.WriteString[" "L];
END;
END;
ENDLOOP;
inD.UpdateTOCThumbLine[];
IF ~foundAny THEN IODefs.WriteLine["No matches found."L]
ELSE IODefs.WriteChar[Ascii.CR];
vmD.FreeVirtualMessageObject[vm];
END; -- of SearchForPatternInMailFile --


SearchForPatternInMailFile[];

END. -- of SearchMail --