DO
msgID: ROPE;
msList: LIST OF ROPE;
headers: REF TEXT;
contents: ViewerTools.TiogaContents;
last: INT;
char0: CHAR;
isActive: BOOL ← FALSE; -- Will be TRUE if message is in Active message set
[msgID, msList, headers] ← WalnutOps.NextMsg[enum];
IF msgID=NIL THEN EXIT;
numRead ← numRead+1;
IF msList#NIL AND msList.rest=NIL AND msList.first.Equal["deleted", FALSE] THEN LOOP;
contents ← WalnutOps.GetMsg[handle, msgID].contents;
createEntry.msg ← msgID;
last ← contents.contents.Length[] - 1;
char0 ← IF last>=0 THEN contents.contents.Fetch[0] ELSE '~;
IF ( contents.formatting.Length[] # 0 )
AND ( char0 = '\r
OR char0 = '\l )
THEN {
IF contents.contents.Fetch[last] = '\000
THEN
-- NUL for padding
{ contents.contents ← Rope.Substr[contents.contents, 1, last-1];
contents.formatting ← Rope.Concat["\000", contents.formatting]
}
ELSE
IF char0 = '\r
OR char0 = '\l
THEN
contents.contents ← Rope.Substr[contents.contents, 1];
};
createEntry.textLen ← contents.contents.Length[];
createEntry.formatLen ← contents.formatting.Length[];
[]←WalnutStream.WriteEntry[logStream, createEntry];
[]←WalnutStream.WriteMsgBody[logStream, contents];
IF WalnutOps.GetHasBeenRead[handle, msgID]
THEN {
beenReadEntry.msg ← msgID;
[]←WalnutStream.WriteEntry[logStream, beenReadEntry];
};
FOR mL:
LIST
OF
ROPE ← msList, mL.rest
WHILE mL#
NIL
DO
SELECT
TRUE
FROM
mL.first.Equal["active", FALSE] => { isActive ← TRUE; LOOP; };
mL.first.Equal["deleted", FALSE] => LOOP; -- should not happen, but harmless
mL.rest=
NIL
AND ~isActive => {
moveEntry.from ← "Active";
moveEntry.to ← mL.first;
moveEntry.msg ← msgID;
[]←WalnutStream.WriteEntry[logStream, moveEntry];
};
ENDCASE => {
addEntry.to ← mL.first;
addEntry.msg ← msgID;
[]←WalnutStream.WriteEntry[logStream, addEntry];
};
ENDLOOP;
numWritten ← numWritten+1;
IF doReportID THEN cmd.out.PutF["%g\n", rope[msgID]]
ELSE IF numRead MOD 10=0 THEN cmd.out.PutRope["! "]
ELSE cmd.out.PutRope["."];
ENDLOOP;