-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmkmsgsqu.pas
1887 lines (1590 loc) · 45.8 KB
/
mkmsgsqu.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{ $O+,F+,I-,S-,R-,V-,X+}
Unit MKMsgSqu;
{$IfDef FPC}
{$PackRecords 1}
{$EndIf}
Interface
Uses MKGlobT, MKMsgAbs, GeneralP;
{ $I FILEMODE.INC}
{--- begin FILEMODE.INC ---}
{$IfDef SPEED}
Uses
BseDOS;
Const
fmReadOnly = Open_Access_ReadOnly;
fmReadWrite = Open_Access_ReadWrite;
fmDenyNone = Open_Share_DenyNone;
{$Else}
Const
fmReadOnly = 0; {FileMode constants}
fmWriteOnly = 1;
fmReadWrite = 2;
fmDenyAll = 16;
fmDenyWrite = 32;
fmDenyRead = 48;
fmDenyNone = 64;
fmNoInherit = 128;
{$EndIf}
{--- end FILEMODE.INC ---}
Const
SqHdrId = $AFAE4453;
SqLinkNext = 0;
SqLinkPrev = 1;
SqNullFrame = 0;
SqFrameMsg = 0;
SqFrameFree = 1;
SqFrameRLE = 2;
SqFrameLZW = 3;
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; {Future use}
End;
Type 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;
Type 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: OldAddrType; {Origin address}
Dest: OldAddrType; {Destination address}
DateWritten: LongInt; {Date/Time msg written}
DateArrived: LongInt; {Date/Time 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;
Type SqIdxType = Record
Ofs: LongInt; {Offset of frame header}
UMsgId: LongInt; {Unique message id}
Hash: LongInt; {Hash of MsgTo name}
End;
Const
{$IFDEF OS2}
SqIdxArraySize = 16384;
{$ELSE}
SqIdxArraySize = 5400; {5200}
{$ENDIF}
Type SqIdxArrayType = Array[1..SqIdxArraySize] of SqIdxType;
Type SqIdxPtrType = ^SqIdxArrayType;
Type 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
SqTxtBufferSize = 34000; {34000}
Type SqInfoType = Record
FN: String[80];
MsgChars: Array[1..SqTxtBufferSize] of Char;
Error: Word;
FreeLoaded: Boolean;
SqdFile: File;
SqIFile: File;
SqBase: SqBaseType;
SqBaseExtra: Array[1..100] of Char;
SqdOpened: Boolean;
SqiOpened: Boolean;
SqiAlloc: Word;
Locked: Boolean;
HighestFree: Word;
Frame: SqFrameHdrType;
MsgHdr: SqMsgHdrType;
Extra: Array[1..100] of Char;
TxtCtr: Word;
CurrIdx: Word;
StrDate: String[8];
StrTime: String[8];
CurrentFramePos: LongInt;
CurrentUID: LongInt;
SName: String[35];
SHandle: String[35];
HName: LongInt;
HHandle: LongInt;
End;
Type SqMsgObj = Object(AbsMsgObj)
SqInfo: ^SqInfoType;
SqIdx: ^SqIdxArrayType;
IndexRead: Boolean;
FreeArray: ^FreeArrayType;
Constructor Init; {Initialize}
Destructor Done; Virtual; {Done cleanup and dispose}
function GetID: Byte; Virtual;
Function OpenMsgBase: Word; Virtual; {Open message base}
Function CloseMsgBase: Word; Virtual; {Close message base}
Function CreateMsgBase(MaxMsg: Word; MaxDays: Word): Word; Virtual;
Function MsgBaseExists: Boolean; Virtual;
Procedure SetMsgPath(FN: String); Virtual; {Set filepath and name - no extension}
Function SqdOpen: Word; Virtual; {Open squish data file}
Function SqiOpen: Word; 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;
FramePos: LongInt); Virtual; {Link frame after other frame}
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}
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 SetRead(RS: Boolean): boolean; virtual;
Function IsRead: Boolean; Virtual; {Is current msg received}
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: String; Virtual;
Procedure GetOrig(Var Addr: AddrType); Virtual;
Procedure SetOrig(Var Addr: AddrType); Virtual;
Procedure GetDest(Var Addr: AddrType); Virtual;
Procedure SetDest(Var Addr: AddrType); Virtual;
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}
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}
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 IsHold: Boolean; Virtual; {Is current msg hold}
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 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 setHold(sh : Boolean); virtual; {set hold status}
Procedure InitMsgHdr; Virtual; {Set up message}
Procedure MsgTxtStartUp; Virtual;
Procedure SetMailType(MT: MsgMailType); Virtual; {Set message base type}
Function GetSubArea: Word; Virtual; {Get sub area number}
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}
Function IsEchoed: Boolean; Virtual; {Is current msg unmoved echomail msg}
Function GetLastRead: LongInt; Virtual; {Get last read for user num}
Procedure SetLastRead(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; { *** }
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}
Function GetRealMsgNum: LongInt; Virtual;
End;
Type SqMsgPtr = ^SqMsgObj;
procedure GetSquishInfo(fn: string; var cur, msgs: longint);
Implementation
Uses MKFile, MKString, MKDos, Dos {, Global};
Const
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;
SqMsgRead = $80000000;
Constructor SqMsgObj.Init;
begin
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;
with SqInfo^ do begin
SqdOpened := False;
SqiOpened := False;
FN := '';
Error := 0;
Locked := False;
FreeLoaded:=false;
SqiAlloc := 0;
end;
End;
Destructor SqMsgObj.Done;
Begin
If SqInfo^.SqdOpened Then SqdClose;
If SqInfo^.SqiOpened Then SqiClose;
If SqInfo^.SqIAlloc > 0 Then
If SqIdx <> Nil Then
FreeMem(SqIdx, SqInfo^.SqiAlloc * SizeOf(SqIdxType));
Dispose(FreeArray);
Dispose(SqInfo);
End;
function SqMsgObj.GetID: Byte;
begin
GetID:=msgSquish;
end;
Procedure SqMsgObj.SetMsgPath(FN: String);
Begin
SqInfo^.FN := FExpand(FN);
If Pos('.SQD', UpStr(SqInfo^.FN)) > 0 Then
SqInfo^.FN := Copy(SqInfo^.FN,1,Pos('.SQD', UpStr(SqInfo^.FN)) - 1);
End;
Function SqMsgObj.OpenMsgBase: Word;
Var
Error: Word;
Begin
Error := SqiOpen;
If Error = 0 Then
Begin
Error := SqdOpen;
If (Error = 0) then
Begin
ReadIdx;
OpenMsgBase := 0;
End
Else
Begin
SqiClose;
OpenMsgBase := Error;
End;
End
Else
OpenMsgBase := Error;
End;
Function SqMsgObj.SqdOpen: Word;
Var
{$IFDEF VirtualPascal}
NumRead: LongInt;
{$ELSE}
NumRead: Word;
{$ENDIF}
Begin
If Not SqInfo^.SqdOpened Then
Begin
Assign(SqInfo^.SqdFile, SqInfo^.FN + '.sqd');
FileMode := fmReadWrite + fmDenyNone;
If Not shReset(SqInfo^.SqdFile, 1) Then
SqdOpen := MKFileError
Else
Begin
SqInfo^.SqdOpened := True;
SqdOpen := 0;
If Not shRead(SqInfo^.SqdFile, SqInfo^.SqBase, 2, NumRead) Then
SqdOpen := MKFileError
Else
Begin
If SqInfo^.SqBase.Len = 0 Then
SqInfo^.SqBase.Len := SqBSize;
If SqInfo^.SqBase.Len > (SizeOf(SqBaseType) + 100) Then
SqdOpen := 1001
Else
Begin
SqBSize := SqInfo^.SqBase.Len;
ReadBase;
End;
End;
End;
End
Else
SqdOpen := 0;
End;
Function SqMsgObj.SqiOpen: Word;
Begin
If Not SqInfo^.SqiOpened Then
Begin
Assign(SqInfo^.SqiFile, SqInfo^.FN + '.sqi');
FileMode := fmReadWrite + fmDenyNone;
If Not shReset(SqInfo^.SqiFile, SizeOf(SqIdxType)) Then
SqiOpen := MKFileError
Else
Begin
SqInfo^.SqiOpened := True;
SqiOpen := 0;
End;
End
Else
SqiOpen := 0;
End;
Function SqMsgObj.CloseMsgBase: Word;
Begin
SqdClose;
SqiClose;
CloseMsgBase := 0;
End;
Function SqMsgObj.CreateMsgBase(MaxMsg: Word; MaxDays: Word): Word;
Var
i: Word;
Begin
If Not SqInfo^.SqdOpened Then
Begin
i := PosLastChar(DirSep, SqInfo^.FN);
If i > 0 Then
Begin
If MakePath(Copy(SqInfo^.FN, 1, i)) Then;
End;
FillChar(SqInfo^.SqBase, SizeOf(SqInfo^.SqBase), 0);
SqInfo^.SqBase.Len := 256;
SqInfo^.SqBase.SqHdrSize := SqFSize;
SqInfo^.SqBase.UID := 1;
SqInfo^.SqBase.NumMsg := 0;
SqInfo^.SqBase.Base := SqInfo^.FN;
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);
If SaveFile(SqInfo^.FN + '.sqi', SqInfo^.SqBase, 0) = 0 Then;
If SaveFile(SqInfo^.FN + '.sql', SqInfo^.SqBase, 0) = 0 Then;
End
Else
CreateMsgBase := 176;
End;
Function SqMsgObj.MsgBaseExists: Boolean;
Begin
MsgBaseExists := FileExist(SqInfo^.FN + '.sqd');
End;
Procedure SqMsgObj.SqdClose;
Begin
If SqInfo^.SqdOpened Then
Close(SqInfo^.SqdFile);
If IOResult <> 0 Then;
SqInfo^.SqdOpened := False;
End;
Function SqMsgObj.LockMsgBase: Boolean; {Lock msg base}
Begin
If Not SqInfo^.Locked Then Begin
SqInfo^.Locked := shLock(SqInfo^.SqdFile, 0, 1) = 0;
LockMsgBase := SqInfo^.Locked;
ReadBase;
ReadIdx;
SqInfo^.FreeLoaded:=false;
end;
end;
Function SqMsgObj.UnLockMsgBase: Boolean; {Unlock msg base}
Begin
If SqInfo^.Locked Then
Begin
WriteBase;
WriteIdx;
SqInfo^.Locked := Not UnLockFile(SqInfo^.SqdFile, 0, 1) < 2;
UnLockMsgBase := Not SqInfo^.Locked;
End;
End;
Procedure SqMsgObj.SqiClose;
Begin
If SqInfo^.SqiOpened Then
Close(SqInfo^.SqiFile);
If IoResult <> 0 Then;
SqInfo^.SqiOpened := False;
End;
Procedure SqMsgObj.ReadBase;
Var
{$IFDEF VirtualPascal}
NumRead: LongInt;
{$ELSE}
NumRead: Word;
{$ENDIF}
Begin
Seek(SqInfo^.SqdFile, 0);
If Not shRead(SqInfo^.SqdFile, SqInfo^.SqBase, SqBSize, NumRead) Then
SqInfo^.Error := MKFileError;
If SqInfo^.SqBase.SqHdrSize = 0 Then
SQInfo^.SqBase.SqHdrSize := SqFSize;
SqFSize := SqInfo^.SqBase.SqHdrSize;
End;
Procedure SqMsgObj.WriteBase;
Begin
Seek(SqInfo^.SqdFile, 0);
If Not shWrite(SqInfo^.SqdFile, SqInfo^.SqBase, SQBSize) Then
SqInfo^.Error := MKFileError;
End;
Procedure SqMsgObj.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 SqMsgObj.GetFrom: String; {Get message from}
Var
s: String;
Begin
Move(SqInfo^.MsgHdr.MsgFrom, s, SqFromSize);
{ s := SqInfo^.MsgHdr.MsgFrom;}
GetFrom := Az2Str(s, SqFromSize);
End;
Function SqMsgObj.GetTo: String; {Get message to}
Var
s: String;
Begin
Move(SqInfo^.MsgHdr.MsgTo, s, SqToSize);
{ s := SqInfo^.MsgHdr.MsgTo;}
GetTo := Az2Str(s, SqToSize);
End;
Function SqMsgObj.GetSubj: String; {Get message subject}
Var
s: String;
Begin
Move(SqInfo^.MsgHdr.Subj, s, SqSubjSize);
{ SqInfo^.MsgHdr.Subj := s;}
GetSubj := Az2Str(s, SqSubjSize);
End;
Procedure SqMsgObj.SetFrom(Str: String); {Set message from}
Begin
Str2Az(Str, 35, SqInfo^.MsgHdr.MsgFrom);
End;
Procedure SqMsgObj.SetTo(Str: String); {Set message to}
Begin
Str2Az(Str,35, SqInfo^.MsgHdr.MsgTo);
End;
Procedure SqMsgObj.SetSubj(Str: String); {Set message subject}
Begin
Str2Az(Str,72, SqInfo^.MSgHdr.Subj);
End;
Function SqMsgObj.GetDate: String; {Get message date mm-dd-yy}
Var
TmpDate: LongInt;
Begin
TmpDate := (SqInfo^.MsgHdr.DateWritten shr 16) +
((SqInfo^.MsgHdr.DateWritten and $ffff) shl 16);
GetDate := DateStr(TmpDate);
End;
Function SqMsgObj.GetTime: String; {Get message time hh:mm}
Var
TmpDate: LongInt;
Begin
TmpDate := (SqInfo^.MsgHdr.DateWritten shr 16) +
((SqInfo^.MsgHdr.DateWritten and $ffff) shl 16);
GetTime := TimeStr(TmpDate);
End;
Procedure SqMsgObj.SetDate(Str: String);
Begin
SqInfo^.StrDate := Copy(Str,1,8);
End;
Procedure SqMsgObj.SetTime(Str: String);
Begin
SqInfo^.StrTime := Copy(Str,1,8);
End;
Procedure SqMsgObj.GetOrig(Var Addr: AddrType);
begin
move(SqInfo^.MsgHdr.Orig, Addr, sizeof(SqInfo^.MsgHdr.Orig));
Addr.domain := '';
end;
Procedure SqMsgObj.SetOrig(Var Addr: AddrType);
Begin
move(Addr, SqInfo^.MsgHdr.Orig, sizeof(SqInfo^.MsgHdr.Orig));
End;
Procedure SqMsgObj.GetDest(Var Addr: AddrType);
Begin
move(SqInfo^.MsgHdr.Dest, Addr, sizeof(SqInfo^.MsgHdr.Dest));
addr.domain := '';
End;
Procedure SqMsgObj.SetDest(Var Addr: AddrType);
Begin
move(Addr, SqInfo^.MsgHdr.Dest, sizeof(SqInfo^.MsgHdr.Dest));
End;
Function SqMsgObj.SqHashName(Name: String): LongInt;
Var
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;
End;
Procedure SqMsgObj.ReadFrame(FPos: LongInt); {Read frame at FPos}
Begin
ReadVarFrame(SqInfo^.Frame, FPos);
End;
Procedure SqMsgObj.ReadVarFrame(Var Frame: SqFrameHdrType; FPos: LongInt); {Read frame at FPos}
Var
{$IFDEF VirtualPascal}
NumRead: LongInt;
{$ELSE}
NumRead: Word;
{$ENDIF}
Begin
Seek(SqInfo^.SqdFile, FPos);
SqInfo^.Error := IoResult;
If SqInfo^.Error = 0 Then
Begin
If Not shRead(SqInfo^.SqdFile, Frame, SizeOf(SqFrameHdrType), NumRead) Then
SqInfo^.Error := MKFileError;
End;
End;
Procedure SqMsgObj.WriteFrame(FPos: LongInt); {Read frame at FPos}
Begin
WriteVarFrame(SqInfo^.Frame, FPos);
End;
Procedure SqMsgObj.WriteVarFrame(Var Frame: SqFrameHdrType; FPos: LongInt); {Write frame at FPos}
Begin
Seek(SqInfo^.SqdFile, FPos);
SqInfo^.Error := IoResult;
If SqInfo^.Error = 0 Then
Begin
If Not shWrite(SqInfo^.SqdFile, Frame, SizeOf(SqFrameHdrType)) Then
SqInfo^.Error := MKFileError;
End;
End;
Procedure SqMsgObj.UnlinkFrame(Var Frame: SqFrameHdrType);
Var
TmpFrame: SqFrameHdrType;
Begin
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;
End;
Procedure SqMsgObj.LoadFree;
Var
i: Word;
TmpFrame: SqFrameHdrType;
TmpPos: LongInt;
Begin
SqInfo^.FreeLoaded:=true;
FillChar(FreeArray^,Sizeof(FreeArray^),0);
i := 0;
TmpPos := SqInfo^.SqBase.FirstFree;
While ((TmpPos <> 0) and (i < MaxFree)) Do
Begin
ReadVarFrame(TmpFrame, TmpPos);
Inc(i);
FreeArray^[i].FreeSize := TmpFrame.FrameLength;
FreeArray^[i].FreePos := TmpPos;
TmpPos := TmpFrame.NextFrame;
End;
SqInfo^.HighestFree := i;
End;
Procedure SqMsgObj.FindFrame(Var FL: LongInt; Var FramePos: LongInt);
Var
TmpFrame: SqFrameHdrType;
BestFoundPos: LongInt;
BestFoundSize: LongInt;
BestIdx: Word;
i: Word;
Begin
If SqInfo^.FreeLoaded=false 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;
FramePos := BestFoundPos;
If FramePos <> 0 Then
Begin
ReadVarFrame(TmpFrame, FramePos);
FreeArray^[BestIdx].FreePos := 0;
FreeArray^[BestIdx].FreeSize := 0;
End;
If FramePos = 0 Then
Begin
FL := 0;
FramePos := SqInfo^.SqBase.EndFrame;
End
Else
Begin
UnLinkFrame(TmpFrame);
If TmpFrame.PrevFrame = 0 Then
SqInfo^.SqBase.FirstFree := TmpFrame.NextFrame;
If TmpFrame.NextFrame = 0 Then
SqInfo^.SqBase.LastFree := TmpFrame.PrevFrame;
FL := TmpFrame.FrameLength;
End;
End;
Procedure SqMsgObj.LinkFrameNext(Var Frame: SqFrameHdrType; OtherFrame: LongInt;
FramePos: LongInt);
Var
TmpFrame: SqFrameHdrType;
Begin
If OtherFrame <> 0 Then
Begin
ReadVarFrame(TmpFrame, OtherFrame);
TmpFrame.NextFrame := FramePos;
Frame.PrevFrame := OtherFrame;
WriteVarFrame(TmpFrame, OtherFrame);
End;
End;
Procedure SqMsgObj.KillMsg(MsgNum: LongInt);
Var
i: Word;
KillPos: LongInt;
IndexPos: LongInt;
KillFrame: SqFrameHdrType;
TmpFrame: SqFrameHdrType;
CurrMove: LongInt;
AlreadyLocked: Boolean;
FreeCtr: Word;
Begin
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;
{ NumMove := SqInfo^.SqBase.NumMsg + 1 - IndexPos;
NumMove := NumMove * SizeOf(SqIdxType);
Move(SqIdx^[IndexPos + 1], SqIdx^[IndexPos], NumMove); }
End;
End;
If Not AlreadyLocked Then
If UnlockMsgBase Then;
End;
Procedure SqMsgObj.ReadMsgHdr(FPos: LongInt); {Read msg hdr for frame at FPos}
Var
{$IFDEF VirtualPascal}
NumRead: LongInt;
{$ELSE}
NumRead: Word;
{$ENDIF}
Begin
Seek(SqInfo^.SqdFile, FPos + SqFSize);
SqInfo^.Error := IoResult;
If SqInfo^.Error = 0 Then
Begin
If Not shRead(SqInfo^.SqdFile, SqInfo^.MsgHdr, SizeOf(SqMsgHdrType), NumRead) Then
SqInfo^.Error := MKFileError;
End;
End;
Procedure SqMsgObj.WriteMsgHdr(FPos: LongInt); {Read msg hdr for frame at FPos}
Var
NumRead: Word;
Begin
Seek(SqInfo^.SqdFile, FPos + SqFSize);
SqInfo^.Error := IoResult;
If SqInfo^.Error = 0 Then
Begin
If Not shWrite(SqInfo^.SqdFile, SqInfo^.MsgHdr, SizeOf(SqMsgHdrType)) Then
SqInfo^.Error := MKFileError;
End;
End;
Procedure SqMsgObj.WriteText(FPos: LongInt); {Write text buffer for frame at Fpos}
Begin
Seek(SqInfo^.SqdFile, FPos + SqFSize + SqMSize);
SqInfo^.Error := IoResult;
If SqInfo^.Error = 0 Then
Begin
If Not shWrite(SqInfo^.SqdFile, SqInfo^.MsgChars, SqInfo^.TxtCtr) Then
SqInfo^.Error := MKFileError;
End;
End;
Function SqMsgObj.GetBeginFrame: LongInt; {Get beginning frame pos}
Begin
GetBeginFrame := SqInfo^.SqBase.BeginFrame;
End;
Function SqMsgObj.GetNextFrame: LongInt; {Get next frame pos}
Begin
GetNextFrame := SqInfo^.Frame.NextFrame;
End;
Procedure SqMsgObj.ReadText(FPos: LongInt);
Begin
Seek(SqInfo^.SqdFile, FPos + SqFSize + SqMSize);
SqInfo^.Error := IoResult;