mysticbbs/mystic/bbs_msgbase_squish.pas

1578 lines
47 KiB
ObjectPascal
Raw Normal View History

2012-02-13 16:50:48 -08:00
Unit BBS_MsgBase_Squish;
2012-09-26 13:49:06 -07:00
{$I M_OPS.PAS}
2012-02-13 16:50:48 -08:00
Interface
Uses
BBS_MsgBase_Abs,
BBS_Common,
DOS;
Const
SqHdrId = $AFAE4453;
SqLinkNext = 0;
SqLinkPrev = 1;
SqNullFrame = 0;
SqFrameMsg = 0;
SqFrameFree = 1;
2012-09-23 23:38:25 -07:00
// SqFrameRLE = 2;
// SqFrameLZW = 3;
2012-02-13 16:50:48 -08:00
SqFromSize = 36;
SqToSize = 36;
SqSubjSize = 72;
SqMaxReply = 10;
Type
SqBaseType = Record
Len : Word; { Length of this record }
Rsvd1 : Word; { Future use }
NumMsg : LongInt; { Number of messages }
HighMsg : LongInt; { Highest msg }
SkipMsg : LongInt; { # of msgs to keep in beginning of area }
HighWater : LongInt; { High water UMsgId }
Uid : LongInt; { Next UMsgId }
Base : String[79]; { Base name of Squish file }
BeginFrame : LongInt; { Offset of first frame in file }
LastFrame : LongInt; { Offset of last frame in file }
FirstFree : LongInt; { Offset of first free frame in file }
LastFree : LongInt; { Offset of last free frame in file }
EndFrame : LongInt; { Pointer to end of file }
MaxMsg : LongInt; { Maximum number of messages }
KeepDays : Word; { Maximum age of messages }
SqHdrSize : Word; { Size of frame header }
Rsvd2 : Array[1..124] of Byte;
End;
SqFrameHdrType = Record
Id : LongInt; { Must equal SqHdrId }
NextFrame : LongInt; { Next msg frame }
PrevFrame : LongInt; { Prior msg frame }
FrameLength : LongInt; { Length of this frame not counting header }
MsgLength : LongInt; { Length of message }
ControlLength : LongInt; { Length of control information }
FrameType : Word; { Type of message frame }
Rsvd : Word; { Future use }
End;
SqMsgHdrType = Record
Attr : LongInt; { Msg attribute }
MsgFrom : String[SqFromSize - 1]; { Nul Term from name }
MsgTo : String[SqToSize - 1]; { Nul term to name }
Subj : String[SqSubjSize - 1]; { Nul term subject }
Orig : RecEchoMailAddr; { Origin address }
Dest : RecEchoMailAddr; { Destination address }
DateWritten : LongInt; { Date msg written }
DateArrived : LongInt; { Date msg arrived here }
UtcOffset : Word; { Minutes offset from UTC }
ReplyTo : LongInt; { Original msg }
Replies : Array[1..SqMaxReply] of LongInt; { Replies }
AzDate : String[19]; { AsciiZ "Fido" style date }
End;
SqIdxType = Record
Ofs : LongInt; { Offset of frame header }
UMsgId : LongInt; { Unique message id }
Hash : LongInt; { Hash of MsgTo name }
End;
Const
SqIdxArraySize = 5200; {5200}
Type
SqIdxArrayType = Array[1..SqIdxArraySize] of SqIdxType;
SqIdxPtrType = ^SqIdxArrayType;
FreeListType = Record
FreePos : LongInt;
FreeSize : LongInt;
End;
Const
MaxFree = 500;
Type
FreeArrayType = Array[1..MaxFree] of FreeListType;
Const
SqBSize : Word = SizeOf(SqBaseType);
SqFSize : Word = SizeOf(SqFrameHdrType);
SqMSize : Word = SizeOf(SqMsgHdrType);
SqISize : Word = SizeOf(SqIdxType);
Const
2012-04-02 01:05:00 -07:00
SqTxtBufferSize = 16000;
2012-02-13 16:50:48 -08:00
{handle 200 lines x 80 chars EASILY }
Type
SqInfoType = Record
FN : String[80];
MsgChars : Array[1..SqTxtBufferSize] of Char;
Error : Word;
SqdFile : File;
SqIFile : File;
SqBase : SqBaseType;
SqBaseExtra : Array[1..100] of Char;
SqdOpened : Boolean;
SqiOpened : Boolean;
SqiAlloc : Word;
Locked : Boolean;
FreeLoaded : Boolean;
HighestFree : Word;
Frame : SqFrameHdrType;
MsgHdr : SqMsgHdrType;
Extra : Array[1..100] of Char;
TxtCtr : Word;
MsgDone : Boolean;
CurrIdx : Word;
StrDate : String[8];
StrTime : String[8];
CurrentFramePos : LongInt;
CurrentUID : LongInt;
SName : String[35];
SHandle : String[35];
HName : LongInt;
HHandle : LongInt;
End;
Type
PMsgBaseSquish = ^TMsgBaseSquish;
TMsgBaseSquish = Object(TMsgBaseAbs)
2012-04-02 01:05:00 -07:00
SqInfo : ^SqInfoType;
SqIdx : ^SqIdxArrayType;
FreeArray : ^FreeArrayType;
2012-02-13 16:50:48 -08:00
2012-04-02 01:05:00 -07:00
Procedure EditMsgInit; Virtual;
Procedure EditMsgSave; Virtual;
2012-02-13 16:50:48 -08:00
2012-09-26 13:49:06 -07:00
Constructor Init; {Initialize}
Destructor Done; Virtual; {Done cleanup and dispose}
Function OpenMsgBase: Boolean; Virtual; {Open message base}
Procedure CloseMsgBase; Virtual; {Close message base}
Function CreateMsgBase(MaxMsg: Word; MaxDays: Word): Boolean; Virtual;
Function MsgBaseExists: Boolean; Virtual;
Procedure SetMsgPath(FN: String); Virtual; {Set filepath and name - no extension}
Function SqdOpen: Boolean; Virtual; {Open squish data file}
Function SqiOpen: Boolean; Virtual; {Open squish index file}
Procedure SqdClose; Virtual; {Close squish data file}
Procedure SqiClose; Virtual; {Close squish index file}
Function LockMsgBase: Boolean; Virtual; {Lock msg base}
Function UnLockMsgBase: Boolean; Virtual; {Unlock msg base}
Procedure ReadBase; Virtual; {Read base data record}
Procedure WriteBase; Virtual; {Write base data record}
Function GetBeginFrame: LongInt; Virtual; {Get beginning frame pos}
Function GetHighWater: LongInt; Virtual; {Get high water umsgid}
Function GetHighMsgNum: LongInt; Virtual; {Get highest msg number}
Procedure ReadFrame(FPos: LongInt); Virtual; {Read frame at FPos}
Procedure ReadVarFrame(Var Frame: SqFrameHdrType; FPos: LongInt); Virtual; {Read frame at FPos into Frame}
Procedure WriteFrame(FPos: LongInt); Virtual; {Write frame at FPos}
Procedure WriteVarFrame(Var Frame: SqFrameHdrType; FPos: LongInt); Virtual;
Procedure UnlinkFrame(Var Frame: SqFrameHdrType); Virtual; {Unlink frame from linked list}
Procedure LinkFrameNext(Var Frame: SqFrameHdrType; OtherFrame: LongInt;
2012-02-13 16:50:48 -08:00
FramePos: LongInt); Virtual; {Link frame after other frame}
2012-09-26 13:49:06 -07:00
Procedure KillMsg(MsgNum: LongInt); {Kill msg msgnum}
Procedure KillExcess; {Kill msg in excess of limit}
Procedure FindFrame(Var FL: LongInt; Var FramePos: LongInt); Virtual;
Function GetNextFrame: LongInt; Virtual; {Get next frame pos}
Procedure ReadMsgHdr(FPos: LongInt); Virtual; {Read msg hdr for frame at FPos}
Procedure WriteMsgHdr(FPos: LongInt); Virtual; {Read msg hdr for frame at FPos}
Procedure WriteText(FPos: LongInt); Virtual; {Write text buffer for frame at Fpos}
Function SqHashName(Name: String): LongInt; Virtual; {Convert name to hash value}
Procedure StartNewMsg; Virtual; {Initialize msg header}
Function GetFrom: String; Virtual; {Get message from}
Function GetTo: String; Virtual; {Get message to}
Function GetSubj: String; Virtual; {Get message subject}
Function GetTextLen: LongInt; Virtual; {Get text length}
Procedure SetFrom(Str: String); Virtual; {Set message from}
Procedure SetTo(Str: String); Virtual; {Set message to}
Procedure SetSubj(Str: String); Virtual; {Set message subject}
Procedure SetDate(Str: String); Virtual; {Set message date}
Procedure SetTime(Str: String); Virtual; {Set message time}
Function GetDate: String; Virtual; {Get message date mm-dd-yy}
Function GetTime: String; Virtual; {Get message time hh:mm}
Function GetRefer: LongInt; Virtual; {Get reply to of current msg}
Procedure SetRefer(Num: LongInt); Virtual; {Set reply to of current msg}
Function GetSeeAlso: LongInt; Virtual; {Get see also msg}
Procedure SetSeeAlso(Num: LongInt); Virtual; {Set see also msg}
Procedure ReadText(FPos: LongInt); Virtual;
Function GetChar: Char; Virtual;
Function GetString(MaxLen: Word): String; Virtual;
Procedure GetOrig(Var Addr: RecEchoMailAddr); Virtual;
Procedure SetOrig(Var Addr: RecEchoMailAddr); Virtual;
Procedure GetDest(Var Addr: RecEchoMailAddr); Virtual;
Procedure SetDest(Var Addr: RecEchoMailAddr); Virtual;
Function EOM: Boolean; Virtual;
2012-02-13 16:50:48 -08:00
(*
Function WasWrap: Boolean; Virtual;
*)
2012-09-26 13:49:06 -07:00
Procedure InitText; Virtual;
Procedure DoString(Str: String); Virtual; {Add string to message text}
Procedure DoChar(Ch: Char); Virtual; {Add character to message text}
Procedure DoStringLn(Str: String); Virtual; {Add string and newline to msg text}
Function WriteMsg: Word; Virtual; {Write msg to msg base}
Procedure ReadIdx; Virtual;
Procedure WriteIdx; Virtual;
Procedure SeekFirst(MsgNum: LongInt); Virtual; {Seeks to 1st msg >= MsgNum}
Function GetMsgNum: LongInt; Virtual;
Procedure SeekNext; Virtual;
Procedure SeekPrior; Virtual;
Function SeekFound: Boolean; Virtual;
Function GetIdxFramePos: LongInt; Virtual;
Function GetIdxHash: LongInt; Virtual;
Function IsLocal: Boolean; Virtual; {Is current msg local}
Function IsCrash: Boolean; Virtual; {Is current msg crash}
Function IsKillSent: Boolean; Virtual; {Is current msg kill sent}
Function IsSent: Boolean; Virtual; {Is current msg sent}
Function IsFAttach: Boolean; Virtual; {Is current msg file attach}
2012-04-02 01:05:00 -07:00
// Function IsReqRct: Boolean; Virtual; {Is current msg request receipt}
// Function IsReqAud: Boolean; Virtual; {Is current msg request audit}
// Function IsRetRct: Boolean; Virtual; {Is current msg a return receipt}
2012-09-26 13:49:06 -07:00
Function IsFileReq: Boolean; Virtual; {Is current msg a file request}
Function IsRcvd: Boolean; Virtual; {Is current msg received}
Function IsPriv: Boolean; Virtual; {Is current msg priviledged/private}
Function IsDeleted: Boolean; Virtual; {Is current msg deleted}
Procedure SetAttr(St: Boolean; Mask: LongInt); Virtual; {Set attribute}
Procedure SetLocal(St: Boolean); Virtual; {Set local status}
Procedure SetRcvd(St: Boolean); Virtual; {Set received status}
Procedure SetPriv(St: Boolean); Virtual; {Set priveledge vs public status}
Procedure SetCrash(St: Boolean); Virtual; {Set crash netmail status}
Procedure SetHold (ST: Boolean); Virtual;
Procedure SetKillSent(St: Boolean); Virtual; {Set kill/sent netmail status}
Procedure SetSent(St: Boolean); Virtual; {Set sent netmail status}
Procedure SetFAttach(St: Boolean); Virtual; {Set file attach status}
Procedure SetReqRct(St: Boolean); Virtual; {Set request receipt status}
Procedure SetReqAud(St: Boolean); Virtual; {Set request audit status}
Procedure SetRetRct(St: Boolean); Virtual; {Set return receipt status}
Procedure SetFileReq(St: Boolean); Virtual; {Set file request status}
Procedure MsgStartUp; Virtual; {Set up message}
Procedure MsgTxtStartUp; Virtual; {Set up for msg text}
Procedure SetMailType(MT: MsgMailType); Virtual; {Set message base type}
2012-09-20 10:52:58 -07:00
// Function GetSubArea: Word; Virtual; {Get sub area number}
2012-09-26 13:49:06 -07:00
Procedure ReWriteHdr; Virtual; {Rewrite msg header after changes}
Procedure DeleteMsg; Virtual; {Delete current message}
Procedure LoadFree; Virtual; {Load freelist into memory}
Function NumberOfMsgs: LongInt; Virtual; {Number of messages}
Procedure SetEcho(ES: Boolean); Virtual; {Set echo status}
2012-09-20 10:52:58 -07:00
// Function IsEchoed: Boolean; Virtual; {Is current msg unmoved echomail msg}
2012-09-26 13:49:06 -07:00
Function GetLastRead(UNum: LongInt): LongInt; Virtual; {Get last read for user num}
Procedure SetLastRead(UNum: LongInt; LR: LongInt); Virtual; {Set last read}
Function GetMsgLoc: LongInt; Virtual; {To allow reseeking to message}
Procedure SetMsgLoc(ML: LongInt); Virtual; {Reseek to message}
Function IdxHighest: LongInt; Virtual; { *** }
Procedure YoursFirst(Name: String; Handle: String); Virtual; {Seek your mail}
Procedure YoursNext; Virtual; {Seek next your mail}
Function YoursFound: Boolean; Virtual; {Message found}
Function GetMsgDisplayNum: LongInt; Virtual; {Get msg number to display}
Function GetTxtPos: LongInt; Virtual; {Get indicator of msg text position}
Procedure SetTxtPos(TP: LongInt); Virtual; {Set text position}
End;
2012-02-13 16:50:48 -08:00
Implementation
Uses
mkcrap,
m_Strings,
m_DateTime,
m_FileIO;
Const
2012-04-02 01:05:00 -07:00
SqMsgPriv = $00001;
SqMsgCrash = $00002;
SqMsgRcvd = $00004;
SqMsgSent = $00008;
SqMsgFile = $00010;
SqMsgFwd = $00020;
SqMsgOrphan = $00040;
SqMsgKill = $00080;
SqMsgLocal = $00100;
SqMsgHold = $00200;
SqMsgXX2 = $00400;
SqMsgFreq = $00800;
SqMsgRrq = $01000;
SqMsgCpt = $02000;
SqMsgArq = $04000;
SqMsgUrg = $08000;
SqMsgScanned = $10000;
2012-02-13 16:50:48 -08:00
Constructor TMsgBaseSquish.Init;
Begin
2012-04-02 01:05:00 -07:00
New (SqInfo);
New (FreeArray);
If ((SqInfo = nil) or (FreeArray = nil)) Then Begin
If SqInfo <> Nil Then Dispose(SqInfo);
If FreeArray <> Nil Then Dispose(FreeArray);
Fail;
Exit;
End;
SqInfo^.SqdOpened := False;
SqInfo^.SqiOpened := False;
SqInfo^.FN := '';
SqInfo^.Error := 0;
SqInfo^.Locked := False;
SqInfo^.FreeLoaded := False;
SqInfo^.SqiAlloc := 0;
2012-02-13 16:50:48 -08:00
End;
Destructor TMsgBaseSquish.Done;
Begin
2012-04-02 01:05:00 -07:00
If SqInfo^.SqdOpened Then SqdClose;
If SqInfo^.SqiOpened Then SqiClose;
2012-09-26 13:49:06 -07:00
2012-04-02 01:05:00 -07:00
If SqInfo^.SqIAlloc > 0 Then
If SqIdx <> Nil Then
2012-09-26 13:49:06 -07:00
FreeMem (SqIdx, SqInfo^.SqiAlloc * SizeOf(SqIdxType));
2012-04-02 01:05:00 -07:00
2012-09-26 13:49:06 -07:00
Dispose (FreeArray);
Dispose (SqInfo);
2012-02-13 16:50:48 -08:00
End;
2012-09-26 13:49:06 -07:00
Procedure TMsgBaseSquish.SetMsgPath (FN: String);
2012-02-13 16:50:48 -08:00
Begin
2012-09-20 10:52:58 -07:00
SqInfo^.FN := FExpand(FN);
If Pos('.', SqInfo^.FN) > 0 Then
SqInfo^.FN := Copy(SqInfo^.FN,1,Pos('.', SqInfo^.FN) - 1);
2012-02-13 16:50:48 -08:00
End;
Function TMsgBaseSquish.OpenMsgBase: Boolean;
Begin
2012-09-20 10:52:58 -07:00
If SqiOpen Then Begin
OpenMsgBase := SqdOpen;
ReadIdx;
End Else
OpenMsgBase := False;
2012-02-13 16:50:48 -08:00
End;
Function TMsgBaseSquish.SqdOpen: Boolean;
Var
2012-09-20 10:52:58 -07:00
NumRead: LongInt;
2012-02-13 16:50:48 -08:00
Begin
2012-09-20 10:52:58 -07:00
If Not SqInfo^.SqdOpened Then Begin
Assign(SqInfo^.SqdFile, SqInfo^.FN + '.sqd');
FileMode := 66; {ReadWrite + DenyNone}
If Not ioReset(SqInfo^.SqdFile, 1, fmreadwrite + fmdenynone) Then
SqdOpen := False
Else Begin
SqInfo^.SqdOpened := True;
SqdOpen := True;
If Not ioBlockRead(SqInfo^.SqdFile, SqInfo^.SqBase, 2, NumRead) Then
SqdOpen := False
Else Begin
If SqInfo^.SqBase.Len = 0 Then
SqInfo^.SqBase.Len := SqBSize;
If SqInfo^.SqBase.Len > (SizeOf(SqBaseType) + 100) Then
SqdOpen := False
Else Begin
SqBSize := SqInfo^.SqBase.Len;
ReadBase;
End;
End;
End;
End Else
SqdOpen := True;
End;
2012-02-13 16:50:48 -08:00
Function TMsgBaseSquish.SqiOpen: Boolean;
Begin
2012-09-26 13:49:06 -07:00
If Not SqInfo^.SqiOpened Then Begin
Assign (SqInfo^.SqiFile, SqInfo^.FN + '.sqi');
If Not ioReset(SqInfo^.SqiFile, SizeOf(SqIdxType), fmReadWrite + fmDenyNone) Then
SqiOpen := False
Else Begin
SqInfo^.SqiOpened := True;
SqiOpen := True;
End;
End Else
SqiOpen := True;
End;
2012-02-13 16:50:48 -08:00
Procedure TMsgBaseSquish.CloseMsgBase;
Begin
SqdClose;
SqiClose;
2012-09-20 10:52:58 -07:00
FileMode := fmRWDN; { shouldn't be needed... }
2012-02-13 16:50:48 -08:00
End;
2012-09-26 13:49:06 -07:00
Function TMsgBaseSquish.CreateMsgBase (MaxMsg: Word; MaxDays: Word): Boolean;
2012-02-13 16:50:48 -08:00
Begin
If Not SqInfo^.SqdOpened Then Begin
FillChar(SqInfo^.SqBase, SizeOf(SqInfo^.SqBase), 0);
2012-09-20 10:52:58 -07:00
2012-02-13 16:50:48 -08:00
SqInfo^.SqBase.Len := 256;
SqInfo^.SqBase.SqHdrSize := SqFSize;
SqInfo^.SqBase.UID := 1;
SqInfo^.SqBase.NumMsg := 0;
SqInfo^.SqBase.Base := SqInfo^.FN;
2012-09-20 10:52:58 -07:00
2012-02-13 16:50:48 -08:00
Str2Az(SqInfo^.FN, 78, SqInfo^.SqBase.Base);
SqInfo^.SqBase.MaxMsg := MaxMsg;
SqInfo^.SqBase.KeepDays := MaxDays;
SqInfo^.SqBase.EndFrame := SqInfo^.SqBase.Len;
CreateMsgBase := (SaveFile(SqInfo^.FN + '.sqd', SqInfo^.SqBase, SqInfo^.SqBase.Len) = 0);
2012-09-20 10:52:58 -07:00
SaveFile (SqInfo^.FN + '.sqi', SqInfo^.SqBase, 0);
SaveFile (SqInfo^.FN + '.sql', SqInfo^.SqBase, 0);
2012-02-13 16:50:48 -08:00
End Else
CreateMsgBase := False;
End;
Function TMsgBaseSquish.MsgBaseExists: Boolean;
Begin
MsgBaseExists := FileExist(SqInfo^.FN + '.sqd');
End;
Procedure TMsgBaseSquish.SqdClose;
Begin
If SqInfo^.SqdOpened Then Close(SqInfo^.SqdFile);
2012-09-20 10:52:58 -07:00
2012-02-13 16:50:48 -08:00
If IOResult <> 0 Then;
2012-09-20 10:52:58 -07:00
2012-02-13 16:50:48 -08:00
SqInfo^.SqdOpened := False;
End;
Function TMsgBaseSquish.LockMsgBase: Boolean; {Lock msg base}
Begin
If Not SqInfo^.Locked Then Begin
sqinfo^.locked := true;
{ SqInfo^.Locked := shLock(SqInfo^.SqdFile, 0, 1) = 0;}
LockMsgBase := SqInfo^.Locked;
ReadBase;
ReadIdx;
SqInfo^.FreeLoaded := False;
End;
End;
Function TMsgBaseSquish.UnLockMsgBase: Boolean; {Unlock msg base}
Begin
If SqInfo^.Locked Then Begin
WriteBase;
WriteIdx;
sqinfo^.locked := false;
// SqInfo^.Locked := Not UnLockFile(SqInfo^.SqdFile, 0, 1) < 2;
UnLockMsgBase := Not SqInfo^.Locked;
End;
End;
Procedure TMsgBaseSquish.SqiClose;
Begin
If SqInfo^.SqiOpened Then Close(SqInfo^.SqiFile);
If IoResult <> 0 Then;
SqInfo^.SqiOpened := False;
End;
Procedure TMsgBaseSquish.ReadBase;
Var
NumRead: LongInt;
Begin
Seek (SqInfo^.SqdFile, 0);
If Not ioBlockRead(SqInfo^.SqdFile, SqInfo^.SqBase, SqBSize, NumRead) Then
SqInfo^.Error := ioCode;
If SqInfo^.SqBase.SqHdrSize = 0 Then
SQInfo^.SqBase.SqHdrSize := SqFSize;
SqFSize := SqInfo^.SqBase.SqHdrSize;
End;
Procedure TMsgBaseSquish.WriteBase;
Var
Res : LongInt;
Begin
Seek (SqInfo^.SqdFile, 0);
If Not ioBlockWrite(SqInfo^.SqdFile, SqInfo^.SqBase, SQBSize, Res) Then
SqInfo^.Error := ioCode;
End;
Procedure TMsgBaseSquish.StartNewMsg; {Initialize msg header}
Begin
FillChar (SqInfo^.MsgHdr, SizeOf(SqInfo^.MsgHdr), 0);
FillChar (SqInfo^.Frame, SizeOf(SqInfo^.Frame), 0);
SqInfo^.TxtCtr := 0;
SqInfo^.StrDate := '';
SqInfo^.StrTime := '';
End;
Function TMsgBaseSquish.GetFrom: String; {Get message from}
Begin
2012-09-20 10:52:58 -07:00
GetFrom := strWide2Str(SqInfo^.MsgHdr.MsgFrom, 35);
2012-02-13 16:50:48 -08:00
End;
Function TMsgBaseSquish.GetTo: String; {Get message to}
Begin
2012-09-20 10:52:58 -07:00
GetTo := strWide2Str(SqInfo^.MsgHdr.MsgTo, 35);
2012-02-13 16:50:48 -08:00
End;
Function TMsgBaseSquish.GetSubj: String; {Get message subject}
Begin
2012-09-20 10:52:58 -07:00
GetSubj := strWide2Str(SqInfo^.MsgHdr.Subj, 72);
2012-02-13 16:50:48 -08:00
End;
Function TMsgBaseSquish.GetTextLen: LongInt; {Get text length}
Begin
{ GetTextLen := SqInfo^.TxtCtr;}
2012-09-20 10:52:58 -07:00
GetTextLen := SqInfo^.Frame.MsgLength - 320;
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.SetFrom(Str: String); {Set message from}
Begin
2012-09-20 10:52:58 -07:00
Str2Az(Str, 35, SqInfo^.MsgHdr.MsgFrom);
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.SetTo(Str: String); {Set message to}
Begin
2012-09-20 10:52:58 -07:00
Str2Az(Str,35, SqInfo^.MsgHdr.MsgTo);
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.SetSubj(Str: String); {Set message subject}
Begin
2012-09-20 10:52:58 -07:00
Str2Az(Str,72, SqInfo^.MSgHdr.Subj);
2012-02-13 16:50:48 -08:00
End;
Function TMsgBaseSquish.GetDate: String; {Get message date mm-dd-yy}
Var
2012-09-20 10:52:58 -07:00
TmpDate: LongInt;
2012-02-13 16:50:48 -08:00
Begin
2012-09-20 10:52:58 -07:00
TmpDate := (SqInfo^.MsgHdr.DateWritten shr 16) + ((SqInfo^.MsgHdr.DateWritten and $ffff) shl 16);
GetDate := DateDos2Str(TmpDate, 1);
2012-02-13 16:50:48 -08:00
End;
Function TMsgBaseSquish.GetTime: String; {Get message time hh:mm}
Var
2012-09-20 10:52:58 -07:00
TmpDate: LongInt;
2012-02-13 16:50:48 -08:00
Begin
2012-09-20 10:52:58 -07:00
TmpDate := (SqInfo^.MsgHdr.DateWritten shr 16) + ((SqInfo^.MsgHdr.DateWritten and $ffff) shl 16);
GetTime := TimeDos2Str(TmpDate, False);
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.SetDate(Str: String);
Begin
2012-09-20 10:52:58 -07:00
SqInfo^.StrDate := Copy(Str,1,8);
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.SetTime(Str: String);
Begin
2012-09-20 10:52:58 -07:00
SqInfo^.StrTime := Copy(Str,1,8);
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.GetOrig(Var Addr: RecEchoMailAddr);
Begin
2012-09-20 10:52:58 -07:00
Addr := SqInfo^.MsgHdr.Orig;
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.SetOrig(Var Addr: RecEchoMailAddr);
Begin
2012-09-20 10:52:58 -07:00
SqInfo^.MsgHdr.Orig := Addr;
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.GetDest(Var Addr: RecEchoMailAddr);
Begin
2012-09-20 10:52:58 -07:00
Addr := SqInfo^.MsgHdr.Dest;
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.SetDest(Var Addr: RecEchoMailAddr);
Begin
2012-09-20 10:52:58 -07:00
SqInfo^.MsgHdr.Dest := Addr;
2012-02-13 16:50:48 -08:00
End;
Function TMsgBaseSquish.SqHashName(Name: String): LongInt;
Var
2012-09-20 10:52:58 -07:00
Hash : LongInt;
Tmp : LongInt;
Counter : Word;
Begin
Hash := 0;
Counter := 1;
While Counter <= Length(Name) Do Begin
Hash := (Hash shl 4) + Ord(LoCase(Name[Counter]));
Tmp := Hash and $F0000000;
If (Tmp <> 0) Then Hash := (Hash or (Tmp shr 24)) or Tmp;
Inc (Counter);
End;
SqHashName := Hash and $7fffffff;
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.ReadFrame(FPos: LongInt); {Read frame at FPos}
Begin
2012-09-20 10:52:58 -07:00
ReadVarFrame (SqInfo^.Frame, FPos);
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.ReadVarFrame(Var Frame: SqFrameHdrType; FPos: LongInt); {Read frame at FPos}
Var
2012-09-20 10:52:58 -07:00
NumRead : LongInt;
2012-02-13 16:50:48 -08:00
Begin
2012-09-20 10:52:58 -07:00
Seek (SqInfo^.SqdFile, FPos);
SqInfo^.Error := IoResult;
If SqInfo^.Error = 0 Then Begin
If Not ioBlockRead (SqInfo^.SqdFile, Frame, SizeOf(SqFrameHdrType), NumRead) Then
SqInfo^.Error := ioCode;
End;
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.WriteFrame(FPos: LongInt); {Read frame at FPos}
Begin
2012-09-20 10:52:58 -07:00
WriteVarFrame(SqInfo^.Frame, FPos);
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.WriteVarFrame(Var Frame: SqFrameHdrType; FPos: LongInt); {Write frame at FPos}
Var
Res : LongInt;
Begin
2012-09-20 10:52:58 -07:00
Seek (SqInfo^.SqdFile, FPos);
SqInfo^.Error := IoResult;
If SqInfo^.Error = 0 Then Begin
If Not ioBlockWrite(SqInfo^.SqdFile, Frame, SizeOf(SqFrameHdrType), Res) Then
SqInfo^.Error := ioCode;
End;
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.UnlinkFrame(Var Frame: SqFrameHdrType);
Var
2012-09-20 10:52:58 -07:00
TmpFrame: SqFrameHdrType;
2012-02-13 16:50:48 -08:00
Begin
2012-09-20 10:52:58 -07:00
If Frame.PrevFrame <> 0 Then Begin
ReadVarFrame(TmpFrame, Frame.PrevFrame);
TmpFrame.NextFrame := Frame.NextFrame;
WriteVarFrame(TmpFrame, Frame.PrevFrame);
End;
If Frame.NextFrame <> 0 Then Begin
ReadVarFrame(TmpFrame, Frame.NextFrame);
TmpFrame.PrevFrame := Frame.PrevFrame;
WriteVarFrame(TmpFrame, Frame.NextFrame);
End;
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.LoadFree;
Var
2012-09-26 13:49:06 -07:00
Count : Word;
2012-02-13 16:50:48 -08:00
TmpFrame : SqFrameHdrType;
TmpPos : LongInt;
Begin
2012-09-26 13:49:06 -07:00
For Count := 1 to MaxFree Do Begin
FreeArray^[Count].FreePos := 0;
FreeArray^[Count].FreeSize := 0;
2012-09-20 10:52:58 -07:00
End;
SqInfo^.FreeLoaded := True;
2012-09-26 13:49:06 -07:00
Count := 0;
TmpPos := SqInfo^.SqBase.FirstFree;
2012-09-20 10:52:58 -07:00
2012-09-26 13:49:06 -07:00
While ((TmpPos <> 0) and (Count < MaxFree)) Do Begin
ReadVarFrame (TmpFrame, TmpPos);
Inc (Count);
FreeArray^[Count].FreeSize := TmpFrame.FrameLength;
FreeArray^[Count].FreePos := TmpPos;
TmpPos := TmpFrame.NextFrame;
2012-09-20 10:52:58 -07:00
End;
2012-09-26 13:49:06 -07:00
SqInfo^.HighestFree := Count;
2012-02-13 16:50:48 -08:00
End;
2012-09-20 10:52:58 -07:00
Procedure TMsgBaseSquish.FindFrame (Var FL: LongInt; Var FramePos: LongInt);
2012-02-13 16:50:48 -08:00
Var
2012-09-20 10:52:58 -07:00
TmpFrame : SqFrameHdrType;
BestFoundPos : LongInt;
BestFoundSize : LongInt;
BestIdx : Word;
i : Word;
Begin
If Not SqInfo^.FreeLoaded Then LoadFree;
BestFoundPos := 0;
BestFoundSize := 0;
For i := 1 to SqInfo^.HighestFree Do Begin
If (FreeArray^[i].FreeSize > FL) Then Begin
If ((BestFoundSize = 0) or (FreeArray^[i].FreeSize < BestFoundSize)) Then Begin
BestFoundSize := FreeArray^[i].FreeSize;
BestFoundPos := FreeArray^[i].FreePos;
BestIdx := i;
End;
End
End;
2012-02-13 16:50:48 -08:00
2012-09-20 10:52:58 -07:00
FramePos := BestFoundPos;
2012-02-13 16:50:48 -08:00
2012-09-20 10:52:58 -07:00
If FramePos <> 0 Then Begin
ReadVarFrame(TmpFrame, FramePos);
2012-02-13 16:50:48 -08:00
2012-09-20 10:52:58 -07:00
FreeArray^[BestIdx].FreePos := 0;
FreeArray^[BestIdx].FreeSize := 0;
End;
2012-02-13 16:50:48 -08:00
2012-09-20 10:52:58 -07:00
If FramePos = 0 Then Begin
FL := 0;
FramePos := SqInfo^.SqBase.EndFrame;
End Else Begin
UnLinkFrame(TmpFrame);
2012-02-13 16:50:48 -08:00
2012-09-20 10:52:58 -07:00
If TmpFrame.PrevFrame = 0 Then SqInfo^.SqBase.FirstFree := TmpFrame.NextFrame;
If TmpFrame.NextFrame = 0 Then SqInfo^.SqBase.LastFree := TmpFrame.PrevFrame;
FL := TmpFrame.FrameLength;
End;
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.LinkFrameNext(Var Frame: SqFrameHdrType; OtherFrame: LongInt; FramePos: LongInt);
Var
2012-09-20 10:52:58 -07:00
TmpFrame: SqFrameHdrType;
2012-02-13 16:50:48 -08:00
Begin
2012-09-20 10:52:58 -07:00
If OtherFrame <> 0 Then Begin
ReadVarFrame (TmpFrame, OtherFrame);
2012-02-13 16:50:48 -08:00
2012-09-20 10:52:58 -07:00
TmpFrame.NextFrame := FramePos;
Frame.PrevFrame := OtherFrame;
2012-02-13 16:50:48 -08:00
2012-09-20 10:52:58 -07:00
WriteVarFrame (TmpFrame, OtherFrame);
End;
2012-02-13 16:50:48 -08:00
End;
2012-09-26 13:49:06 -07:00
Procedure TMsgBaseSquish.KillMsg (MsgNum: LongInt);
2012-02-13 16:50:48 -08:00
Var
2012-09-26 13:49:06 -07:00
i : Word;
KillPos : LongInt;
IndexPos : LongInt;
KillFrame : SqFrameHdrType;
TmpFrame : SqFrameHdrType;
CurrMove : LongInt;
AlreadyLocked : Boolean;
FreeCtr : Word;
2012-02-13 16:50:48 -08:00
Begin
2012-09-26 13:49:06 -07:00
AlreadyLocked := SqInfo^.Locked;
If Not AlreadyLocked Then
If LockMsgBase Then;
If SqIdx = Nil Then
SqInfo^.Error := 999
Else Begin
i := 1;
While ((i <= SqInfo^.SqBase.NumMsg) and (MsgNum <> SqIdx^[i].UMsgId)) Do
Inc(i);
If MsgNum = SqIdx^[i].UMsgId Then Begin
IndexPos := i;
KillPos := SqIdx^[i].Ofs;
ReadVarFrame (KillFrame, KillPos);
If KillFrame.PrevFrame = 0 Then
SqInfo^.SqBase.BeginFrame := KillFrame.NextFrame;
If KillFrame.NextFrame = 0 Then
SqInfo^.SqBase.LastFrame := KillFrame.PrevFrame;
KillFrame.FrameType := sqFrameFree;
UnLinkFrame (KillFrame);
If ((SqInfo^.SqBase.FirstFree = 0) or (SqInfo^.SqBase.LastFree = 0)) Then Begin
SqInfo^.SqBase.FirstFree := KillPos;
SqInfo^.SqBase.LastFree := KillPos;
KillFrame.PrevFrame := 0;
KillFrame.NextFrame := 0;
End Else Begin
KillFrame.NextFrame := 0;
KillFrame.PrevFrame := SqInfo^.SqBase.LastFree;
ReadVarFrame (TmpFrame, SqInfo^.SqBase.LastFree);
TmpFrame.NextFrame := KillPos;
WriteVarFrame(TmpFrame, SqInfo^.SqBase.LastFree);
SqInfo^.SqBase.LastFree := KillPos;
End;
WriteVarFrame(KillFrame, KillPos);
FreeCtr := 1;
While ((FreeCtr < MaxFree) and (FreeArray^[FreeCtr].FreePos <> 0)) Do
Inc(FreeCtr);
If FreeArray^[FreeCtr].FreePos = 0 Then Begin
FreeArray^[FreeCtr].FreePos := KillPos;
FreeArray^[FreeCtr].FreeSize := KillFrame.FrameLength;
End;
If FreeCtr > SqInfo^.HighestFree Then
SqInfo^.HighestFree := FreeCtr;
Dec (SqInfo^.SqBase.NumMsg);
Dec (SqInfo^.SqBase.HighMsg);
CurrMove := IndexPos;
While CurrMove <= SqInfo^.SqBase.NumMsg Do Begin
SqIdx^[CurrMove] := SqIdx^[CurrMove + 1];
Inc (CurrMove);
End;
End;
End;
If Not AlreadyLocked Then
If UnlockMsgBase Then;
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.ReadMsgHdr(FPos: LongInt); {Read msg hdr for frame at FPos}
Var
NumRead: LongInt;
Begin
2012-09-26 13:49:06 -07:00
Seek (SqInfo^.SqdFile, FPos + SqFSize);
2012-02-13 16:50:48 -08:00
SqInfo^.Error := IoResult;
2012-09-26 13:49:06 -07:00
2012-02-13 16:50:48 -08:00
If SqInfo^.Error = 0 Then Begin
If Not ioBlockRead(SqInfo^.SqdFile, SqInfo^.MsgHdr, SizeOf(SqMsgHdrType), NumRead) Then
2012-09-26 13:49:06 -07:00
SqInfo^.Error := ioCode;
2012-02-13 16:50:48 -08:00
End;
End;
Procedure TMsgBaseSquish.WriteMsgHdr(FPos: LongInt); {Read msg hdr for frame at FPos}
Var
Res : LongInt;
Begin
2012-09-26 13:49:06 -07:00
Seek (SqInfo^.SqdFile, FPos + SqFSize);
2012-02-13 16:50:48 -08:00
SqInfo^.Error := IoResult;
2012-09-26 13:49:06 -07:00
2012-02-13 16:50:48 -08:00
If SqInfo^.Error = 0 Then Begin
If Not ioBlockWrite(SqInfo^.SqdFile, SqInfo^.MsgHdr, SizeOf(SqMsgHdrType), Res) Then
2012-09-26 13:49:06 -07:00
SqInfo^.Error := ioCode;
2012-02-13 16:50:48 -08:00
End;
End;
Procedure TMsgBaseSquish.WriteText(FPos: LongInt); {Write text buffer for frame at Fpos}
Var
Res : LongInt;
Begin
2012-09-26 13:49:06 -07:00
Seek (SqInfo^.SqdFile, FPos + SqFSize + SqMSize);
2012-02-13 16:50:48 -08:00
SqInfo^.Error := IoResult;
2012-09-26 13:49:06 -07:00
2012-02-13 16:50:48 -08:00
If SqInfo^.Error = 0 Then Begin
If Not ioBlockWrite(SqInfo^.SqdFile, SqInfo^.MsgChars, SqInfo^.TxtCtr, Res) Then
2012-09-26 13:49:06 -07:00
SqInfo^.Error := ioCode;
2012-02-13 16:50:48 -08:00
End;
End;
Function TMsgBaseSquish.GetBeginFrame: LongInt; {Get beginning frame pos}
Begin
2012-09-26 13:49:06 -07:00
GetBeginFrame := SqInfo^.SqBase.BeginFrame;
2012-02-13 16:50:48 -08:00
End;
Function TMsgBaseSquish.GetNextFrame: LongInt; {Get next frame pos}
Begin
2012-09-26 13:49:06 -07:00
GetNextFrame := SqInfo^.Frame.NextFrame;
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.ReadText(FPos: LongInt);
Begin
2012-09-26 13:49:06 -07:00
Seek(SqInfo^.SqdFile, FPos + SqFSize + SqMSize);
SqInfo^.Error := IoResult;
If SqInfo^.Error = 0 Then Begin
If SqInfo^.Frame.MsgLength > SqTxtBufferSize Then
BlockRead(SqInfo^.SqdFile, SqInfo^.MsgChars, SqTxtBufferSize)
Else
BlockRead(SqInfo^.SqdFile, SqInfo^.MsgChars, SqInfo^.Frame.MsgLength);
SqInfo^.Error := IoResult;
End;
SqInfo^.TxtCtr := 1 + SqInfo^.Frame.ControlLength;
SqInfo^.MsgDone := False;
LastSoft := False;
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.InitText;
Begin
2012-09-26 13:49:06 -07:00
SqInfo^.TxtCtr := 0;
2012-02-13 16:50:48 -08:00
End;
2012-09-26 13:49:06 -07:00
Procedure TMsgBaseSquish.DoString (Str: String);
2012-02-13 16:50:48 -08:00
Var
2012-09-26 13:49:06 -07:00
Count : Word;
2012-02-13 16:50:48 -08:00
Begin
2012-09-26 13:49:06 -07:00
For Count := 1 to Length(Str) Do
DoChar(Str[Count]);
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.DoChar (Ch: Char); {Add character to message text}
Begin
2012-09-26 13:49:06 -07:00
If SqInfo^.TxtCtr < SqTxtBufferSize Then Begin
Inc (SqInfo^.TxtCtr);
SqInfo^.MsgChars[SqInfo^.TxtCtr] := Ch;
End;
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.DoStringLn(Str: String); {Add string and newline to msg text}
Begin
2012-09-26 13:49:06 -07:00
DoString (Str);
DoChar (#13);
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.KillExcess;
Var
AlreadyLocked: Boolean;
Begin
AlreadyLocked := SqInfo^.Locked;
If Not AlreadyLocked Then
If LockMsgBase Then;
If SqIdx = Nil Then
SqInfo^.error := 999
Else Begin
If ((SqInfo^.SqBase.MaxMsg > 0) and
(SqInfo^.SqBase.MaxMsg > SqInfo^.SqBase.SkipMsg)) Then Begin
While (SqInfo^.SqBase.NumMsg > SqInfo^.SqBase.MaxMsg) Do
KillMsg(SqIdx^[SqInfo^.SqBase.SkipMsg + 1].UMsgId);
End;
End;
If Not AlreadyLocked Then
If UnlockMsgBase Then;
End;
Function TMsgBaseSquish.WriteMsg: Word; {Write msg to msg base}
Var
2012-09-26 13:49:06 -07:00
MsgSize : LongInt;
FrameSize : LongInt;
FramePos : LongInt;
TmpFrame : SqFrameHdrType;
TmpDate : LongInt;
TmpDT : DateTime;
TmpStr : String;
AlreadyLocked : Boolean;
Begin
DoChar(#0);
2012-02-13 16:50:48 -08:00
2012-09-26 13:49:06 -07:00
TmpDT.Year := strS2I(Copy(SqInfo^.StrDate,7,2));
2012-02-13 16:50:48 -08:00
2012-09-26 13:49:06 -07:00
If TmpDT.Year > 79 Then
Inc (TmpDT.Year, 1900)
Else
Inc (TmpDT.Year, 2000);
2012-02-13 16:50:48 -08:00
2012-09-26 13:49:06 -07:00
TmpDT.Month := strS2I(Copy(SqInfo^.StrDate,1,2));
TmpDT.Day := strS2I(Copy(SqInfo^.StrDate,4,2));
TmpDt.Hour := strS2I(Copy(SqInfo^.StrTime,1,2));
TmpDt.Min := strS2I(Copy(SqInfo^.StrTime, 4,2));
TmpDt.Sec := 0;
TmpStr := FormattedDate(TmpDT, 'DD NNN YY ') + Copy(SqInfo^.StrTime, 1, 5) + ':00';
2012-02-13 16:50:48 -08:00
2012-09-26 13:49:06 -07:00
PackTime (TmpDT, TmpDate);
2012-02-13 16:50:48 -08:00
2012-09-26 13:49:06 -07:00
SqInfo^.MsgHdr.DateWritten := (TmpDate shr 16) + ((TmpDate and $ffff) shl 16);
2012-02-13 16:50:48 -08:00
2012-09-26 13:49:06 -07:00
TmpDate := CurDateDos;
2012-02-13 16:50:48 -08:00
2012-09-26 13:49:06 -07:00
SqInfo^.MsgHdr.DateArrived := (TmpDate shr 16) + ((TmpDate and $ffff) shl 16);
2012-02-13 16:50:48 -08:00
2012-09-26 13:49:06 -07:00
Str2AZ(TmpStr, 20, SqInfo^.MsgHdr.AZDate);
2012-02-13 16:50:48 -08:00
2012-09-26 13:49:06 -07:00
AlreadyLocked := SqInfo^.Locked;
2012-02-13 16:50:48 -08:00
2012-09-26 13:49:06 -07:00
If Not AlreadyLocked Then
If LockMsgBase Then;
2012-02-13 16:50:48 -08:00
2012-09-26 13:49:06 -07:00
If SqInfo^.Locked Then Begin
MsgSize := SqInfo^.TxtCtr + SqMSize;
FrameSize := MsgSize;
2012-02-13 16:50:48 -08:00
2012-09-26 13:49:06 -07:00
FindFrame (FrameSize, FramePos);
If SqInfo^.SqBase.LastFrame <> 0 Then Begin
ReadVarFrame (TmpFrame, SqInfo^.SqBase.LastFrame);
TmpFrame.NextFrame := FramePos;
WriteVarFrame(TmpFrame, SqInfo^.SqBase.LastFrame);
TmpFrame.PrevFrame := SqInfo^.SqBase.LastFrame;
End Else Begin
SqInfo^.SqBase.BeginFrame := FramePos;
TmpFrame.PrevFrame := 0;
End;
TmpFrame.Id := SqHdrId;
TmpFrame.FrameType := SqFrameMsg;
SqInfo^.SqBase.LastFrame := FramePos;
TmpFrame.NextFrame := 0;
TmpFrame.FrameLength := FrameSize;
TmpFrame.MsgLength := MsgSize;
TmpFrame.ControlLength := 0;
If TmpFrame.FrameLength = 0 Then Begin
TmpFrame.FrameLength := TmpFrame.MsgLength + 0; {slack to minimize free frames}
SqInfo^.SqBase.EndFrame := FramePos + SqFSize + TmpFrame.FrameLength;
End;
2012-02-13 16:50:48 -08:00
2012-09-26 13:49:06 -07:00
If SqInfo^.SqBase.NumMsg >= SqInfo^.SqiAlloc Then Begin
WriteIdx;
ReadIdx;
End;
If SqIdx = Nil Then Begin
SqInfo^.Error := 999;
WriteMsg := 999;
End Else Begin
WriteVarFrame (TmpFrame, FramePos);
WriteMsgHdr (FramePos);
WriteText (FramePos);
Inc (SqInfo^.SqBase.NumMsg);
SqIdx^[SqInfo^.SqBase.NumMsg].Ofs := FramePos;
SqIdx^[SqInfo^.SqBase.NumMsg].UMsgId := SqInfo^.SqBase.UID;
SqIdx^[SqInfo^.SqBase.NumMsg].Hash := SqHashName(strWide2Str(SqInfo^.MsgHdr.MsgTo, 35));
Inc(SqInfo^.SqBase.UId);
SqInfo^.SqBase.HighMsg := SqInfo^.SqBase.NumMsg;
KillExcess;
SqInfo^.CurrIdx := SqInfo^.SqBase.NumMsg;
WriteMsg := 0;
End;
If Not AlreadyLocked Then
If UnLockMsgBase Then;
End Else
WriteMsg := 5;
2012-02-13 16:50:48 -08:00
End;
2012-09-26 13:49:06 -07:00
Function TMsgBaseSquish.GetString (MaxLen: Word): String;
2012-02-13 16:50:48 -08:00
Var
2012-09-26 13:49:06 -07:00
WPos : Word;
WLen : Byte;
StrDone : Boolean;
StartSoft : Boolean;
CurrLen : Word;
TmpCh : Char;
Begin
StrDone := False;
CurrLen := 0;
WPos := 0;
WLen := 0;
StartSoft := LastSoft;
LastSoft := True;
While ((Not StrDone) And (CurrLen < MaxLen) And (Not SqInfo^.MsgDone)) Do Begin
TmpCh := GetChar;
Case TmpCh of
#00,
#13 : Begin
StrDone := True;
LastSoft := False;
End;
#10,
#141: ;
#32 : Begin
If ((CurrLen <> 0) or (Not StartSoft)) Then Begin
Inc (CurrLen);
WLen := CurrLen;
GetString[CurrLen] := TmpCh;
WPos := SqInfo^.TxtCtr;
End Else
StartSoft := False;
End;
Else
Inc(CurrLen);
GetString[CurrLen] := TmpCh;
End;
End;
2012-02-13 16:50:48 -08:00
2012-09-26 13:49:06 -07:00
If StrDone Then Begin
GetString[0] := Chr(CurrLen);
End Else
If SqInfo^.MsgDone Then Begin
GetString[0] := Chr(CurrLen);
End Else Begin
If WLen = 0 Then Begin
GetString[0] := Chr(CurrLen);
Dec(SqInfo^.TxtCtr);
End Else Begin
GetString[0] := Chr(WLen);
SqInfo^.TxtCtr := WPos;
End;
End;
2012-02-13 16:50:48 -08:00
End;
Function TMsgBaseSquish.EOM: Boolean;
Begin
2012-04-02 01:05:00 -07:00
EOM := (SqInfo^.TxtCtr >= SqInfo^.Frame.MsgLength) or (SqInfo^.MsgChars[SqInfo^.TxtCtr] = #0);
2012-02-13 16:50:48 -08:00
End;
Function TMsgBaseSquish.GetChar: Char;
Begin
2012-09-26 13:49:06 -07:00
If (SqInfo^.TxtCtr >= SqInfo^.Frame.MsgLength) or (SqInfo^.MsgChars[SqInfo^.TxtCtr] = #0) Then Begin
GetChar := #0;
SqInfo^.MsgDone := True;
End Else Begin
GetChar := SqInfo^.MsgChars[SqInfo^.TxtCtr];
2012-02-13 16:50:48 -08:00
2012-09-26 13:49:06 -07:00
Inc(SqInfo^.TxtCtr);
End;
End;
2012-02-13 16:50:48 -08:00
Function TMsgBaseSquish.GetHighWater: LongInt; {Get high water umsgid}
Begin
2012-09-26 13:49:06 -07:00
GetHighWater := LongInt(SqInfo^.SqBase.HighWater);
2012-02-13 16:50:48 -08:00
End;
Function TMsgBaseSquish.GetHighMsgNum: LongInt; {Get highest msg number}
Begin
2012-09-26 13:49:06 -07:00
GetHighMsgNum := LongInt(SqInfo^.SqBase.Uid) - 1;
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.ReadIdx;
Var
2012-09-26 13:49:06 -07:00
NumRead: LongInt;
Begin
If SqInfo^.SqiAlloc > 0 Then
If SqIdx <> Nil Then
FreeMem(SqIdx, SqInfo^.SqiAlloc * SizeOf(SqIdxType));
SqInfo^.SqiAlloc := FileSize(SqInfo^.SqiFile) + 100;
If SqInfo^.SqiAlloc > SqIdxArraySize Then
SqInfo^.SqiAlloc := SqIdxArraySize;
GetMem (SqIdx, SqInfo^.SqiAlloc * SizeOf(SqIdxType));
If SqIdx = nil Then
SqInfo^.Error := 999
Else Begin
Seek(SqInfo^.SqiFile, 0);
If IoResult = 0 Then Begin
If Not ioBlockRead(SqInfo^.SqiFile, SqIdx^, SqInfo^.SqiAlloc, NumRead) Then
SqInfo^.Error := ioCode;
End Else
SqInfo^.Error := 300;
End;
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.WriteIdx;
Var
Res : LongInt;
Begin
2012-09-26 13:49:06 -07:00
If SqIdx = nil Then
SqInfo^.Error := 999
Else Begin
Seek (SqInfo^.SqiFile, 0);
Truncate (SqInfo^.SqiFile);
If IoResult = 0 Then Begin
If Not ioBlockWrite(SqInfo^.SqiFile, SqIdx^, SqInfo^.SqBase.NumMsg, Res) Then
SqInfo^.Error := ioCode;
End Else
SqInfo^.Error := 300;
End;
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.SeekFirst(MsgNum: LongInt);
Begin
2012-09-26 13:49:06 -07:00
SqInfo^.CurrIdx := 1;
ReadIdx;
While ((SqInfo^.CurrIdx <= SqInfo^.SqBase.NumMsg) and (MsgNum > LongInt(SqIdx^[SqInfo^.CurrIdx].UMsgId))) Do
SeekNext;
2012-02-13 16:50:48 -08:00
End;
Function TMsgBaseSquish.IdxHighest: LongInt;
Var
2012-09-26 13:49:06 -07:00
i : Word;
Tmp : LongInt;
Begin
Tmp := 0;
i := 1;
While i <= SqInfo^.SqBase.NumMsg Do Begin
If SqIdx^[i].UMsgId > Tmp Then Tmp := SqIdx^[i].UMsgId;
Inc(i);
End;
IdxHighest := Tmp;
2012-02-13 16:50:48 -08:00
End;
Function TMsgBaseSquish.GetMsgNum: LongInt;
Begin
2012-09-26 13:49:06 -07:00
If ((SqInfo^.CurrIdx <= SqInfo^.SqBase.NumMsg) and (SqInfo^.CurrIdx > 0)) Then
GetMsgNum := LongInt(SqIdx^[SqInfo^.CurrIdx].UMsgId)
Else
GetMsgNum := -1;
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.SeekNext;
Begin
2012-09-26 13:49:06 -07:00
Inc(SqInfo^.CurrIdx);
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.SeekPrior;
2012-09-26 13:49:06 -07:00
Begin
If SqInfo^.CurrIdx > 1 Then
Dec(SqInfo^.CurrIdx)
Else
SqInfo^.CurrIdx := 0;
End;
2012-02-13 16:50:48 -08:00
Function TMsgBaseSquish.SeekFound: Boolean;
2012-09-26 13:49:06 -07:00
Begin
SeekFound := GetMsgNum >= 0;
End;
2012-02-13 16:50:48 -08:00
Function TMsgBaseSquish.GetIdxFramePos: LongInt;
2012-09-26 13:49:06 -07:00
Begin
If SqInfo^.CurrIdx <= SqInfo^.SqBase.NumMsg Then
GetIdxFramePos := SqIdx^[SqInfo^.CurrIdx].Ofs
Else
GetIdxFramePos := -1;
End;
2012-02-13 16:50:48 -08:00
Function TMsgBaseSquish.GetIdxHash: LongInt;
2012-09-26 13:49:06 -07:00
Begin
If SqInfo^.CurrIdx <= SqInfo^.SqBase.NumMsg Then
GetIdxHash := SqIdx^[SqInfo^.CurrIdx].Hash
Else
GetIdxHash := 0;
End;
2012-02-13 16:50:48 -08:00
Function TMsgBaseSquish.IsLocal: Boolean; {Is current msg local}
Begin
2012-09-26 13:49:06 -07:00
IsLocal := ((SqInfo^.MsgHdr.Attr and SqMsgLocal) <> 0);
2012-02-13 16:50:48 -08:00
End;
Function TMsgBaseSquish.IsCrash: Boolean; {Is current msg crash}
Begin
2012-09-26 13:49:06 -07:00
IsCrash := ((SqInfo^.MsgHdr.Attr and SqMsgCrash) <> 0);
2012-02-13 16:50:48 -08:00
End;
Function TMsgBaseSquish.IsKillSent: Boolean; {Is current msg kill sent}
Begin
2012-09-26 13:49:06 -07:00
IsKillSent := ((SqInfo^.MsgHdr.Attr and SqMsgKill) <> 0);
2012-02-13 16:50:48 -08:00
End;
Function TMsgBaseSquish.IsSent: Boolean; {Is current msg sent}
Begin
2012-09-26 13:49:06 -07:00
IsSent := ((SqInfo^.MsgHdr.Attr and SqMsgSent) <> 0);
2012-02-13 16:50:48 -08:00
End;
Function TMsgBaseSquish.IsFAttach: Boolean; {Is current msg file attach}
Begin
2012-09-26 13:49:06 -07:00
IsFAttach := ((SqInfo^.MsgHdr.Attr and SqMsgFile) <> 0);
2012-02-13 16:50:48 -08:00
End;
Function TMsgBaseSquish.IsFileReq: Boolean; {Is current msg a file request}
Begin
2012-09-26 13:49:06 -07:00
IsFileReq := ((SqInfo^.MsgHdr.Attr and SqMsgFreq) <> 0);
2012-02-13 16:50:48 -08:00
End;
Function TMsgBaseSquish.IsRcvd: Boolean; {Is current msg received}
Begin
2012-09-26 13:49:06 -07:00
IsRcvd := ((SqInfo^.MsgHdr.Attr and SqMsgRcvd) <> 0);
2012-02-13 16:50:48 -08:00
End;
Function TMsgBaseSquish.IsPriv: Boolean; {Is current msg priviledged/private}
Begin
2012-09-26 13:49:06 -07:00
IsPriv := ((SqInfo^.MsgHdr.Attr and SqMsgPriv) <> 0);
2012-02-13 16:50:48 -08:00
End;
2012-09-20 10:52:58 -07:00
//Function TMsgBaseSquish.IsEchoed: Boolean;
//Begin
// IsEchoed := ((SqInfo^.MsgHdr.Attr and SqMsgScanned) = 0);
//End;
2012-02-13 16:50:48 -08:00
Function TMsgBaseSquish.IsDeleted: Boolean; {Is current msg deleted}
Begin
2012-09-26 13:49:06 -07:00
IsDeleted := False;
2012-02-13 16:50:48 -08:00
End;
Function TMsgBaseSquish.GetRefer: LongInt; {Get reply to of current msg}
Begin
2012-09-26 13:49:06 -07:00
GetRefer := LongInt(SqInfo^.MsgHdr.ReplyTo);
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.SetRefer(Num: LongInt); {Set reply to of current msg}
Begin
2012-09-26 13:49:06 -07:00
SqInfo^.MsgHdr.ReplyTo := LongInt(Num);
2012-02-13 16:50:48 -08:00
End;
Function TMsgBaseSquish.GetSeeAlso: LongInt; {Get see also msg}
Begin
2012-09-26 13:49:06 -07:00
GetSeeAlso := LongInt(SqInfo^.MsgHdr.Replies[1]);
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.SetSeeAlso(Num: LongInt); {Set see also msg}
Begin
2012-09-26 13:49:06 -07:00
SqInfo^.MsgHdr.Replies[1] := LongInt(Num);
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.SetAttr(St: Boolean; Mask: LongInt); {Set attribute}
Begin
2012-09-26 13:49:06 -07:00
If St Then
SqInfo^.MsgHdr.Attr := SqInfo^.MsgHdr.Attr or Mask
Else
SqInfo^.MsgHdr.Attr := SqInfo^.MsgHdr.Attr and (Not Mask);
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.SetLocal(St: Boolean); {Set local status}
Begin
2012-09-26 13:49:06 -07:00
SetAttr(St, SqMsgLocal);
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.SetRcvd(St: Boolean); {Set received status}
Begin
2012-09-26 13:49:06 -07:00
SetAttr(St, SqMsgRcvd);
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.SetPriv(St: Boolean); {Set priveledge vs public status}
Begin
2012-09-26 13:49:06 -07:00
SetAttr(St, SqMsgPriv);
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.SetEcho(ES: Boolean);
Begin
2012-09-26 13:49:06 -07:00
SetAttr(Not ES, SqMsgScanned);
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.SetCrash(St: Boolean); {Set crash netmail status}
Begin
2012-09-26 13:49:06 -07:00
SetAttr(St, SqMsgCrash);
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.SetHold (ST: Boolean);
Begin
2012-09-26 13:49:06 -07:00
SetAttr (ST, SqMsgHold);
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.SetKillSent(St: Boolean); {Set kill/sent netmail status}
Begin
2012-09-26 13:49:06 -07:00
SetAttr(St, SqMsgKill);
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.SetSent(St: Boolean); {Set sent netmail status}
Begin
2012-09-26 13:49:06 -07:00
SetAttr(St, SqMsgSent);
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.SetFAttach(St: Boolean); {Set file attach status}
Begin
2012-09-26 13:49:06 -07:00
SetAttr(St, SqMsgFile);
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.SetReqRct(St: Boolean); {Set request receipt status}
Begin
2012-09-26 13:49:06 -07:00
SetAttr(St, SqMsgRrq);
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.SetReqAud(St: Boolean); {Set request audit status}
Begin
2012-09-26 13:49:06 -07:00
SetAttr(St, SqMsgarq);
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.SetRetRct(St: Boolean); {Set return receipt status}
Begin
2012-09-26 13:49:06 -07:00
SetAttr(St, SqMsgCpt);
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.SetFileReq(St: Boolean); {Set file request status}
Begin
2012-09-26 13:49:06 -07:00
SetAttr(St, SqMsgFreq);
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.MsgStartUp;
Begin
2012-09-26 13:49:06 -07:00
SqInfo^.CurrentFramePos := GetIdxFramePos;
SqInfo^.CurrentUID := SqIdx^[SqInfo^.CurrIdx].UMsgId;
ReadFrame (SqInfo^.CurrentFramePos);
ReadMsgHdr (SqInfo^.CurrentFramePos);
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.MsgTxtStartUp;
Begin
2012-09-26 13:49:06 -07:00
ReadText(SqInfo^.CurrentFramePos);
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.SetMailType(MT: MsgMailType);
Begin
End;
Procedure TMsgBaseSquish.ReWriteHdr;
Var
2012-09-26 13:49:06 -07:00
AlreadyLocked : Boolean;
I : LongInt;
2012-02-13 16:50:48 -08:00
Begin
2012-09-26 13:49:06 -07:00
AlreadyLocked := SqInfo^.Locked;
2012-02-13 16:50:48 -08:00
2012-09-26 13:49:06 -07:00
If Not AlreadyLocked Then
If LockMsgBase Then;
2012-02-13 16:50:48 -08:00
2012-09-26 13:49:06 -07:00
WriteFrame (SqInfo^.CurrentFramePos);
WriteMsgHdr (SqInfo^.CurrentFramePos);
2012-02-13 16:50:48 -08:00
2012-09-26 13:49:06 -07:00
i := 1;
2012-02-13 16:50:48 -08:00
2012-09-26 13:49:06 -07:00
While ((i <= SqInfo^.SqBase.NumMsg) and (SqInfo^.CurrentFramePos <> SqIdx^[i].Ofs)) Do
Inc(i);
2012-02-13 16:50:48 -08:00
2012-09-26 13:49:06 -07:00
If SqIdx^[i].Ofs = SqInfo^.CurrentFramePos Then Begin
If IsRcvd Then
SqIdx^[i].Hash := 0
Else
SqIdx^[i].Hash := SqHashName(SqInfo^.MsgHdr.MsgTo);
End;
2012-02-13 16:50:48 -08:00
2012-09-26 13:49:06 -07:00
If Not AlreadyLocked Then
If UnLockMsgBase Then;
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.DeleteMsg;
Begin
KillMsg(SqInfo^.CurrentUID);
End;
Function TMsgBaseSquish.NumberOfMsgs: LongInt;
Var
2012-09-26 13:49:06 -07:00
TmpBase: SqBaseType;
2012-02-13 16:50:48 -08:00
Begin
2012-09-26 13:49:06 -07:00
If LoadFile(SqInfo^.FN + '.sqd', TmpBase, SizeOf(TmpBase)) = 0 Then
NumberOfMsgs := TmpBase.NumMsg
Else
NumberOfMsgs := 0;
2012-02-13 16:50:48 -08:00
End;
2012-09-26 13:49:06 -07:00
Function TMsgBaseSquish.GetLastRead (UNum: LongInt) : LongInt;
2012-02-13 16:50:48 -08:00
Begin
2012-09-26 13:49:06 -07:00
If LoadFilePos(SqInfo^.FN + '.sql', Result, 4, UNum * 4) <> 0 Then
Result := 0;
2012-02-13 16:50:48 -08:00
End;
2012-09-26 13:49:06 -07:00
Procedure TMsgBaseSquish.SetLastRead (UNum: LongInt; LR: LongInt);
2012-02-13 16:50:48 -08:00
Begin
2012-09-26 13:49:06 -07:00
If ((UNum + 1) * SizeOf(LR)) > GetFileSize(SqInfo^.FN + '.sql') Then
ExtendFile (SqInfo^.FN + '.sql', (UNum + 1) * SizeOf(LR));
SaveFilePos (SqInfo^.FN + '.sql', LR, SizeOf(LR), UNum * SizeOf(LR));
2012-02-13 16:50:48 -08:00
End;
Function TMsgBaseSquish.GetMsgLoc: LongInt;
Begin
2012-09-26 13:49:06 -07:00
GetMsgLoc := GetMsgNum;
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.SetMsgLoc(ML: LongInt);
Begin
2012-09-26 13:49:06 -07:00
SeekFirst(ML);
2012-02-13 16:50:48 -08:00
End;
2012-09-26 13:49:06 -07:00
Procedure TMsgBaseSquish.YoursFirst (Name: String; Handle: String);
2012-02-13 16:50:48 -08:00
Begin
2012-09-26 13:49:06 -07:00
SqInfo^.CurrIdx := 0;
ReadIdx;
SqInfo^.SName := strUpper(Name);
SqInfo^.SHandle := strUpper(Handle);
SqInfo^.HName := SqHashName(Name);
SqInfo^.HHandle := SqHashName(Handle);
YoursNext;
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.YoursNext;
Var
2012-09-26 13:49:06 -07:00
WasFound: Boolean;
Begin
WasFound := False;
Inc (SqInfo^.CurrIdx);
While ((SqInfo^.CurrIdx <= SqInfo^.SqBase.NumMsg) and (Not WasFound)) Do Begin
While ((SqIdx^[SqInfo^.CurrIdx].Hash <> SqInfo^.HName) And (SqIdx^[SqInfo^.CurrIdx].Hash <> SqInfo^.HHandle) And (SqInfo^.CurrIdx <= SqInfo^.SqBase.NumMsg)) Do
Inc(SqInfo^.CurrIdx);
If SqInfo^.CurrIdx <= SqInfo^.SqBase.NumMsg Then Begin
MsgStartUp;
If ((Not IsRcvd) and ((strUpper(GetTo) = SqInfo^.SName) or (strUpper(GetTo) = SqInfo^.SHandle))) Then
WasFound := True
Else
Inc (SqInfo^.CurrIdx);
End;
End;
2012-02-13 16:50:48 -08:00
End;
Function TMsgBaseSquish.YoursFound: Boolean;
Begin
2012-09-26 13:49:06 -07:00
YoursFound := SqInfo^.CurrIdx <= SqInfo^.SqBase.NumMsg;
2012-02-13 16:50:48 -08:00
End;
Function TMsgBaseSquish.GetMsgDisplayNum: LongInt;
Begin
2012-09-26 13:49:06 -07:00
GetMsgDisplayNum := SqInfo^.CurrIdx;
2012-02-13 16:50:48 -08:00
End;
Function TMsgBaseSquish.GetTxtPos: LongInt;
Begin
2012-09-26 13:49:06 -07:00
GetTxtPos := SqInfo^.TxtCtr;
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.SetTxtPos(TP: LongInt);
Begin
2012-09-26 13:49:06 -07:00
SqInfo^.TxtCtr := TP;
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.EditMsgInit;
Begin
2012-09-26 13:49:06 -07:00
SqInfo^.TxtCtr := 0;
2012-02-13 16:50:48 -08:00
End;
Procedure TMsgBaseSquish.EditMsgSave;
Begin
(*
DeleteMsg;
Dec(SqInfo^.CurrentUID);
Dec(SqInfo^.SqBase.UId);
WriteMsg;
*)
2012-09-26 13:49:06 -07:00
ReWriteHdr;
2012-02-13 16:50:48 -08:00
End;
End.