-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmkmsgjam.pas
1734 lines (1501 loc) · 43.6 KB
/
mkmsgjam.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-}
Unit MKMsgJam; {JAM Msg Object Unit}
{$IfDef FPC}
{$PackRecords 1}
{$EndIf}
Interface
Uses DOS, GeneralP, MKGlobT, MKMsgAbs, MKMisc;
Type JamHdrType = Record
Signature: Array[1..4] of Char;
Created: LongInt;
ModCounter: LongInt;
ActiveMsgs: LongInt;
PwdCRC: LongInt;
BaseMsgNum: LongInt;
Extra: Array[1..1000] of Char;
End;
Type JamMsgHdrType = Record
Signature: Array[1..4] of Char;
Rev: Word;
Resvd: Word;
SubFieldLen: LongInt;
TimesRead: LongInt;
MsgIdCrc: LongInt;
ReplyCrc: LongInt;
ReplyTo: LongInt;
ReplyFirst: LongInt;
ReplyNext: LongInt;
DateWritten: LongInt;
DateRcvd: LongInt;
DateArrived: LongInt;
MsgNum: LongInt;
Attr1: LongInt;
Attr2: LongInt;
TextOfs: LongInt;
TextLen: LongInt;
PwdCrc: LongInt;
Cost: LongInt;
End;
Type JamIdxType = Record
MsgToCrc: LongInt;
HdrLoc: LongInt;
End;
Type JamLastType = Record
NameCrc: LongInt;
UserNum: LongInt;
LastRead: LongInt;
HighRead: LongInt;
End;
Const
JamIdxBufSize = 500;
JamSubBufSize = 4000;
JamTxtBufSize = 4000;
TxtSubBufSize = 2000; {Note actual size is one greater}
type
JamIdxArrayType = Array[0..JamIdxBufSize] of JamIdxType;
JamSubBuffer = Array[1..JamSubBufSize] of Char;
JamTxtBufType = Array[0..JamTxtBufSize] Of Char;
HdrType = record
JamHdr: JamMsgHdrType;
SubBuf: JamSubBuffer;
end;
Type JamMsgType = Record
HdrFile: File;
TxtFile: File;
IdxFile: File;
MsgPath: String[128];
BaseHdr: JamHdrType;
Dest: AddrType;
Orig: AddrType;
MsgFrom: String[65];
MsgTo: String[65];
MsgSubj: String[100];
MsgDate: String[8];
MsgTime: String[5];
CurrMsgNum: LongInt;
NameCrc: LongInt;
HdlCrc: LongInt;
TxtPos: LongInt; {TxtPos < 0 means get from sub text}
TxtEnd: LongInt;
TxtBufStart: LongInt;
{$IFDEF VirtualPascal}
TxtRead: LongInt;
{$ELSE}
TxtRead: Word;
{$ENDIF}
MailType: MsgMailType;
BufFile: File;
LockCount: LongInt;
IdxStart: LongInt;
{$IFDEF VirtualPascal}
IdxRead: LongInt;
{$ELSE}
IdxRead: Word;
{$ENDIF}
TxtSubBuf: Array[0..TxtSubBufSize] of Char; {temp storage for text on subfields}
TxtSubChars: Integer;
End;
Type JamMsgObj = Object (AbsMsgObj)
JM: ^JamMsgType;
MsgHdr: ^HdrType;
JamIdx: ^JamIdxArrayType;
TxtBuf: ^JamTxtBufType;
Error: Word;
Constructor Init; {Initialize}
Destructor Done; Virtual; {Done}
function SetRead(RS: Boolean): boolean; virtual;
Function IsRead: Boolean; Virtual; {Is current msg received}
Procedure SetMsgPath(St: String); Virtual; {Set netmail path}
Function GetHighMsgNum: LongInt; Virtual; {Get highest netmail msg number in area}
Function LockMsgBase: Boolean; Virtual; {Lock the message base}
Function UnLockMsgBase: Boolean; Virtual; {Unlock the message base}
Procedure SetDest(Var Addr: AddrType); Virtual; {Set Zone/Net/Node/Point for Dest}
Procedure SetOrig(Var Addr: AddrType); Virtual; {Set Zone/Net/Node/Point for Orig}
Procedure SetFrom(Name: String); Virtual; {Set message from}
Procedure SetTo(Name: String); Virtual; {Set message to}
Procedure SetSubj(Str: String); Virtual; {Set message subject}
Procedure SetCost(SCost: Word); Virtual; {Set message cost}
Procedure SetRefer(SRefer: LongInt); Virtual; {Set message reference}
Procedure SetSeeAlso(SAlso: LongInt); Virtual; {Set message see also}
Function GetNextSeeAlso: LongInt; Virtual;
Procedure SetNextSeeAlso(SAlso: LongInt); Virtual;
Procedure SetDate(SDate: String); Virtual; {Set message date}
Procedure SetTime(STime: String); Virtual; {Set message time}
Procedure SetLocal(LS: Boolean); Virtual; {Set local status}
Procedure SetRcvd(RS: Boolean); Virtual; {Set received status}
Procedure SetPriv(PS: Boolean); Virtual; {Set priveledge vs public status}
Procedure SetCrash(SS: Boolean); Virtual; {Set crash netmail status}
Procedure SetKillSent(SS: Boolean); Virtual; {Set kill/sent netmail status}
Procedure SetSent(SS: Boolean); Virtual; {Set sent netmail status}
Procedure SetFAttach(SS: Boolean); Virtual; {Set file attach status}
Procedure SetReqRct(SS: Boolean); Virtual; {Set request receipt status}
Procedure SetReqAud(SS: Boolean); Virtual; {Set request audit status}
Procedure SetRetRct(SS: Boolean); Virtual; {Set return receipt status}
Procedure SetFileReq(SS: Boolean); Virtual; {Set file request status}
procedure setHold(sh : Boolean); virtual; {Set hold status}
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}
Procedure DoKludgeLn(Str: String); Virtual; {Add ^AKludge line to msg}
Function WriteMsg: Word; Virtual;
Function GetChar: Char; Virtual;
Procedure AddTxtSub(St: String);
Procedure InitMsgHdr; Virtual; {set up msg for reading}
Function GetString: String; Virtual; {Get wordwrapped string}
Procedure SeekFirst(MsgNum: LongInt); Virtual; {Seek msg number}
Procedure SeekNext; Virtual; {Find next matching msg}
Procedure SeekPrior; Virtual; {Seek prior matching msg}
Function GetFrom: String; Virtual; {Get from name on current msg}
Function GetTo: String; Virtual; {Get to name on current msg}
Function GetSubj: String; Virtual; {Get subject on current msg}
Function GetCost: Word; Virtual; {Get cost of current msg}
Function GetDate: String; Virtual; {Get date of current msg}
Function GetTime: String; Virtual; {Get time of current msg}
Function GetRefer: LongInt; Virtual; {Get reply to of current msg}
Function GetSeeAlso: LongInt; Virtual; {Get see also of current msg}
Function GetMsgNum: LongInt; Virtual; {Get message number}
Procedure GetOrig(Var Addr: AddrType); Virtual; {Get origin address}
Procedure GetDest(Var Addr: AddrType); Virtual; {Get destination address}
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 SetDeleted(tr: boolean); virtual;
Function IsEchoed: Boolean; Virtual; {Msg should be echoed}
Function GetMsgLoc: LongInt; Virtual; {Msg location}
Procedure SetMsgLoc(ML: LongInt); Virtual; {Msg location}
Procedure StartNewMsg; Virtual;
Function OpenMsgBase: Word; Virtual;
Function CloseMsgBase: Word; Virtual;
Function MsgBaseExists: Boolean; Virtual; {Does msg base exist}
Function CreateMsgBase(MaxMsg: Word; MaxDays: Word): Word; Virtual;
Function SeekFound: Boolean; 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}
Function NumberOfMsgs: LongInt; Virtual; {Number of messages}
Function GetLastRead: LongInt; Virtual; {Get last read for user num}
Procedure SetLastRead(LR: LongInt); Virtual; {Set last read}
Procedure MsgTxtStartUp; Virtual; {Do message text start up tasks}
Function GetTxtPos: LongInt; Virtual; {Get indicator of msg text position}
Procedure SetTxtPos(TP: LongInt); Virtual; {Set text position}
Procedure SetAttr1(Mask: LongInt; St: Boolean); {Set attribute 1}
Function ReadIdx: Word;
Function WriteIdx: Word;
Procedure AddSubField(id: Word; Data: String);
Function FindLastRead(Var LastFile: File; UNum: LongInt): LongInt;
Function ReReadIdx(Var IdxLoc : LongInt) : Word;
Function GetRealMsgNum: LongInt; Virtual;
function GetID: Byte; virtual;
End;
Type JamMsgPtr = ^JamMsgObj;
Function JamStrCrc(St: String): LongInt;
Implementation
Uses MKFile, MKString, MKDos, Crc32;
Const
Jam_Local = $00000001;
Jam_InTransit = $00000002;
Jam_Priv = $00000004;
Jam_Rcvd = $00000008;
Jam_Sent = $00000010;
Jam_KillSent = $00000020;
Jam_AchvSent = $00000040;
Jam_Hold = $00000080;
Jam_Crash = $00000100;
Jam_Imm = $00000200;
Jam_Direct = $00000400;
Jam_Gate = $00000800;
Jam_Freq = $00001000;
Jam_FAttch = $00002000;
Jam_TruncFile = $00004000;
Jam_KillFile = $00008000;
Jam_RcptReq = $00010000;
Jam_ConfmReq = $00020000;
Jam_Orphan = $00040000;
Jam_Encrypt = $00080000;
Jam_Compress = $00100000;
Jam_Escaped = $00200000;
Jam_FPU = $00400000;
Jam_TypeLocal = $00800000;
Jam_TypeEcho = $01000000;
Jam_TypeNet = $02000000;
Jam_NoDisp = $20000000;
Jam_Locked = $40000000;
Jam_Deleted = $80000000;
Type SubFieldType = Record
LoId: Word;
HiId: Word;
DataLen: LongInt;
Data: Array[1..1000] of Char;
End;
function JamMsgObj.GetID: Byte;
begin
GetID:=msgJAM;
end;
Constructor JamMsgObj.Init;
Begin
New(JM);
New(JamIdx);
New(MsgHdr);
New(TxtBuf);
If ((JM = Nil) Or (JamIdx = Nil) or (MsgHdr = Nil) or (TxtBuf = Nil)) Then
Begin
If JM <> Nil Then
Dispose(JM);
If JamIdx <> Nil Then
Dispose(JamIdx);
If MsgHdr <> Nil Then
Dispose(MsgHdr);
If TxtBuf <> Nil Then
Dispose(TxtBuf);
Fail;
Exit;
End
Else
Begin;
FillChar(JM^, SizeOf(JM^), #0);
JM^.MsgPath := '';
JM^.IdxStart := -30;
JM^.IdxRead := 0;
Error := 0;
End;
End;
Destructor JamMsgObj.Done;
Begin
If JM <> Nil Then Dispose(JM);
If JamIdx <> Nil Then Dispose(JamIdx);
If MsgHdr <> Nil Then Dispose(MsgHdr);
If TxtBuf <> Nil Then Dispose(TxtBuf);
End;
Function JamStrCrc(St: String): LongInt;
Var
i: Word;
crc: LongInt;
Begin
Crc := -1;
For i := 1 to Length(St) Do
Crc := Updc32(Ord(LoCase(St[i])), Crc);
JamStrCrc := Crc;
End;
Procedure JamMsgObj.SetMsgPath(St: String);
Begin
JM^.MsgPath := Copy(St, 1, 124);
End;
Function JamMsgObj.GetHighMsgNum: LongInt;
Begin
GetHighMsgNum := JM^.BaseHdr.BaseMsgNum + FileSize(JM^.IdxFile) - 1;
End;
Procedure JamMsgObj.SetDest(Var Addr: AddrType);
Begin
JM^.Dest := Addr;
End;
Procedure JamMsgObj.SetOrig(Var Addr: AddrType);
Begin
JM^.Orig := Addr;
End;
Procedure JamMsgObj.SetFrom(Name: String);
Begin
JM^.MsgFrom := Name;
End;
Procedure JamMsgObj.SetTo(Name: String);
Begin
JM^.MsgTo := Name;
End;
Procedure JamMsgObj.SetSubj(Str: String);
Begin
JM^.MsgSubj := Str;
End;
Procedure JamMsgObj.SetCost(SCost: Word);
Begin
MsgHdr^.JamHdr.Cost := SCost;
End;
Procedure JamMsgObj.SetRefer(SRefer: LongInt);
Begin
MsgHdr^.JamHdr.ReplyTo := SRefer;
End;
Procedure JamMsgObj.SetSeeAlso(SAlso: LongInt);
Begin
MsgHdr^.JamHdr.ReplyFirst := SAlso;
End;
Procedure JamMsgObj.SetDate(SDate: String);
Begin
JM^.MsgDate := SDate;
End;
Procedure JamMsgObj.SetTime(STime: String);
Begin
JM^.MsgTime := STime;
End;
Procedure JamMsgObj.SetAttr1(Mask: LongInt; St: Boolean);
Begin
If St Then
MsgHdr^.JamHdr.Attr1 := MsgHdr^.JamHdr.Attr1 Or Mask
Else
MsgHdr^.JamHdr.Attr1 := MsgHdr^.JamHdr.Attr1 And (Not Mask);
End;
Procedure JamMsgObj.SetLocal(LS: Boolean);
Begin
SetAttr1(Jam_Local, LS);
End;
Procedure JamMsgObj.SetRcvd(RS: Boolean);
Begin
SetAttr1(Jam_Rcvd, RS);
End;
Procedure JamMsgObj.SetPriv(PS: Boolean);
Begin
SetAttr1(Jam_Priv, PS);
End;
Procedure JamMsgObj.SetCrash(SS: Boolean);
Begin
SetAttr1(Jam_Crash, SS);
End;
Procedure JamMsgObj.SetKillSent(SS: Boolean);
Begin
SetAttr1(Jam_KillSent, SS);
End;
Procedure JamMsgObj.SetSent(SS: Boolean);
Begin
SetAttr1(Jam_Sent, SS);
End;
Procedure JamMsgObj.SetFAttach(SS: Boolean);
Begin
SetAttr1(Jam_FAttch, SS);
End;
Procedure JamMsgObj.SetReqRct(SS: Boolean);
Begin
SetAttr1(Jam_RcptReq, SS);
End;
Procedure JamMsgObj.SetReqAud(SS: Boolean);
Begin
SetAttr1(Jam_ConfmReq, SS);
End;
Procedure JamMsgObj.SetRetRct(SS: Boolean);
Begin
End;
Procedure JamMsgObj.SetFileReq(SS: Boolean);
Begin
SetAttr1(Jam_Freq, SS);
End;
procedure JamMsgObj.SetHold(sh : Boolean);
begin
SetAttr1(Jam_Hold, sh);
end;
Procedure JamMsgObj.DoString(Str: String);
Var
i: Word;
Begin
i := 1;
While i <= Length(Str) Do
Begin
DoChar(Str[i]);
Inc(i);
End;
End;
Procedure JamMsgObj.DoChar(Ch: Char);
Var
TmpStr: String;
NumWrite: Word;
Begin
Case ch of
#13: Wrapped := False;
#10:;
Else
Wrapped := True;
End;
If (JM^.TxtPos - JM^.TxtBufStart) >= JamTxtBufSize Then
Begin
If JM^.TxtBufStart = 0 Then
Begin
GetDir(0, TmpStr);
TmpStr := GetTempName(TmpStr);
Assign(JM^.BufFile, TmpStr);
FileMode := fmReadWrite + fmDenyNone;
ReWrite(JM^.BufFile, 1);
End;
NumWrite := JM^.TxtPos - JM^.TxtBufStart;
BlockWrite(JM^.BufFile, TxtBuf^, NumWrite);
Error := IoResult;
JM^.TxtBufStart := FileSize(JM^.BufFile);
End;
TxtBuf^[JM^.TxtPos - JM^.TxtBufStart] := Ch;
Inc(JM^.TxtPos);
End;
Procedure JamMsgObj.DoStringLn(Str: String);
Begin
DoString(Str);
DoChar(#13);
End;
Procedure JamMsgObj.DoKludgeLn(Str: String);
Var
TmpStr: String;
Begin
If Str[1] = #1 Then
Str := Copy(Str,2,255);
If Copy(Str,1,3) = 'PID' Then
Begin
TmpStr := StripLead(Copy(Str,4,255),':');
TmpStr := Copy(StripBoth(TmpStr, ' '),1,40);
AddSubField(7, TmpStr);
End
Else If Copy(Str,1,5) = 'MSGID' Then
Begin
TmpStr := StripLead(Copy(Str,6,255),':');
TmpStr := Copy(StripBoth(TmpStr,' '),1,100);
AddSubField(4, TmpStr);
MsgHdr^.JamHdr.MsgIdCrc := JamStrCrc(TmpStr);
End
Else If Copy(Str,1,4) = 'INTL' Then {ignore}
Begin
End
Else If Copy(Str,1,4) = 'TOPT' Then {ignore}
Begin
End
Else If Copy(Str,1,4) = 'FMPT' Then {ignore}
Begin
End
Else If Copy(Str,1,5) = 'REPLY' Then
Begin
TmpStr := StripLead(Copy(Str,8,255),':');
TmpStr := Copy(StripBoth(TmpStr,' '),1,100);
AddSubField(5, TmpStr);
MsgHdr^.JamHdr.ReplyCrc := JamStrCrc(TmpStr);
End
Else If Copy(Str,1,4) = 'PATH' Then
Begin
TmpStr := StripLead(Copy(Str,5,255),':');
TmpStr := StripBoth(TmpStr,' ');
AddSubField(2002, TmpStr);
End
Else
Begin
AddSubField(2000, StripBoth(Str,' '));
End;
End;
Procedure JamMsgObj.AddSubField(id: Word; Data: String);
Type SubFieldType = Record
LoId: Word;
HiId: Word;
DataLen: LongInt;
Data: Array[1..256] of Char;
End;
Var
SubField: ^SubFieldType;
Begin
SubField := @MsgHdr^.SubBuf[MsgHdr^.JamHdr.SubFieldLen + 1];
If (MsgHdr^.JamHdr.SubFieldLen + 8 + Length(Data) < JamSubBufSize) Then
Begin
Inc(MsgHdr^.JamHdr.SubFieldLen, 8 + Length(Data));
SubField^.LoId := Id;
SubField^.HiId := 0;
SubField^.DataLen := Length(Data);
Move(Data[1], SubField^.Data[1], Length(Data));
End;
End;
Function JamMsgObj.WriteMsg: Word;
Var
{$IFDEF WINDOWS}
DT: TDateTime;
{$ELSE}
DT: DateTime;
{$ENDIF}
WriteError: Word;
{$IFDEF VirtualPascal}
i: LongInt;
{$ELSE}
{$IfDef SPEED}
i: LongWord;
{$Else}
i: Word;
{$EndIf}
{$ENDIF}
TmpIdx: JamIdxType;
Begin
WriteError := 0;
If Wrapped Then
Begin
DoChar(#13);
DoChar(#10);
End;
If WriteError = 0 Then
Begin
MsgHdr^.JamHdr.Signature[1] := 'J';{Set signature}
MsgHdr^.JamHdr.Signature[2] := 'A';
MsgHdr^.JamHdr.Signature[3] := 'M';
MsgHdr^.JamHdr.Signature[4] := #0;
Case JM^.MailType of
mmtNormal: SetAttr1(Jam_TypeLocal, True);
mmtEchoMail: SetAttr1(Jam_TypeEcho, True);
mmtNetMail: SetAttr1(Jam_TypeNet, True);
End;
MsgHdr^.JamHdr.Rev := 1;
MsgHdr^.JamHdr.DateArrived := ToUnixDate(GetDosDate); {Get date processed}
DT.Year := Str2Long(Copy(JM^.MsgDate, 7, 2)); {Convert date written}
DT.Month := Str2Long(Copy(JM^.MsgDate, 1, 2));
DT.Day := Str2Long(Copy(JM^.MsgDate, 4, 2));
If DT.Year < 80 Then
Inc(DT.Year, 2000)
Else
Inc(DT.Year, 1900);
DT.Sec := 0;
DT.Hour := Str2Long(Copy(JM^.MsgTime, 1, 2));
DT.Min := Str2Long(Copy(JM^.MsgTime, 4, 2));
MsgHdr^.JamHdr.DateWritten := DTToUnixDate(DT);
End;
If WriteError = 0 Then
Begin {Lock message base for update}
If Not LockMsgBase Then
WriteError := 5;
End;
If WriteError = 0 Then
Begin {Handle message text}
MsgHdr^.JamHdr.TextOfs := FileSize(JM^.TxtFile);
MsgHdr^.JamHdr.MsgNum := GetHighMsgNum + 1;
MsgHdr^.Jamhdr.TextLen := JM^.TxtPos;
If JM^.TxtBufStart > 0 Then
Begin {Write text using buffer file}
i := JM^.TxtPos - JM^.TxtBufStart;
BlockWrite(JM^.BufFile, TxtBuf^, i); {write buffer to file}
WriteError := IoResult;
If WriteError = 0 Then {seek start of buffer file}
Begin
Seek(JM^.BufFile, 0);
WriteError := IoResult;
End;
If WriteError = 0 Then {seek end of text file}
Begin
Seek(JM^.TxtFile, FileSize(JM^.TxtFile));
WriteError := IoResult;
End;
While ((Not Eof(JM^.BufFile)) and (WriteError = 0)) Do
Begin {copy buffer file to text file}
BlockRead(JM^.BufFile, TxtBuf^, SizeOf(TxtBuf^), i);
WriteError := IoResult;
If WriteError = 0 Then
Begin
JM^.TxtBufStart := FilePos(JM^.TxtFile);
JM^.TxtRead := i;
BlockWrite(JM^.TxtFile, TxtBuf^, i);
Error := IoResult;
End;
End;
Close(JM^.BufFile);
Error := IoResult;
Erase(JM^.BufFile);
Error := IoResult;
End
Else
Begin {Write text using TxtBuf only}
Seek(JM^.Txtfile, FileSize(JM^.TxtFile));
WriteError := IoResult;
If WriteError = 0 Then
Begin
BlockWrite(JM^.TxtFile, TxtBuf^, JM^.TxtPos);
WriteError := IoResult;
JM^.TxtRead := JM^.TxtPos;
End;
End;
If WriteError = 0 Then {Add index record}
Begin
TmpIdx.HdrLoc := FileSize(JM^.HdrFile);
TmpIdx.MsgToCrc := JamStrCrc(JM^.MsgTo);
Seek(JM^.IdxFile, FileSize(JM^.IdxFile));
WriteError := IoResult;
End;
If WriteError = 0 Then {write index record}
Begin
BlockWrite(JM^.IdxFile, TmpIdx, 1);
WriteError := IoResult;
End;
If WriteError = 0 Then
Begin {Add subfields as needed}
If Length(JM^.MsgTo) > 0 Then
AddSubField(3, JM^.MsgTo);
If Length(JM^.MsgFrom) > 0 Then
AddSubField(2, JM^.MsgFrom);
If Length(JM^.MsgSubj) > 0 Then
Begin
If IsFileReq Then
AddSubField(11, JM^.MsgSubj)
Else
AddSubField(6, JM^.MsgSubj);
End;
If ((JM^.Dest.Zone <> 0) or (JM^.Dest.Net <> 0) or
(JM^.Dest.Node <> 0) or (JM^.Dest.Point <> 0)) Then
AddSubField(1, AddrStr(JM^.Dest));
If ((JM^.Orig.Zone <> 0) or (JM^.Orig.Net <> 0) or
(JM^.Orig.Node <> 0) or (JM^.Orig.Point <> 0)) Then
AddSubField(0, AddrStr(JM^.Orig));
Seek(JM^.HdrFile, FileSize(JM^.HdrFile)); {Seek to end of .jhr file}
WriteError := IoResult;
End;
If WriteError = 0 Then
Begin {write msg header}
BlockWrite(JM^.HdrFile, MsgHdr^, SizeOf(MsgHdr^.JamHdr) +
MsgHdr^.JamHdr.SubFieldLen);
WriteError := IoResult;
End;
If WriteError = 0 Then
Begin {update msg base header}
Inc(JM^.BaseHdr.ActiveMsgs);
Inc(JM^.BaseHdr.ModCounter);
End;
If UnLockMsgBase Then; {unlock msg base}
End;
WriteMsg := WriteError; {return result of writing msg}
End;
Function JamMsgObj.GetChar: Char;
{$IfDef SPEED}
Var
NR: LongWord;
{$EndIf}
Begin
If JM^.TxtPos < 0 Then
Begin
GetChar := JM^.TxtSubBuf[JM^.TxtSubChars + JM^.TxtPos];
Inc(JM^.TxtPos);
If JM^.TxtPos >= 0 Then
JM^.TxtPos := MsgHdr^.JamHdr.TextOfs;
End
Else
Begin
If ((JM^.TxtPos < JM^.TxtBufStart) Or
(JM^.TxtPos >= JM^.TxtBufStart + JM^.TxtRead)) Then
Begin
JM^.TxtBufStart := JM^.TxtPos - 80;
If JM^.TxtBufStart < 0 Then
JM^.TxtBufStart := 0;
Seek(JM^.TxtFile, JM^.TxtBufStart);
Error := IoResult;
If Error = 0 Then
Begin
{$IfDef SPEED}
BlockRead(JM^.TxtFile, TxtBuf^, SizeOf(TxtBuf^), NR);
JM^.TxtRead := NR;
{$Else}
BlockRead(JM^.TxtFile, TxtBuf^, SizeOf(TxtBuf^), JM^.TxtRead);
{$EndIf}
Error := IoResult;
End;
End;
GetChar := TxtBuf^[JM^.TxtPos - JM^.TxtBufStart];
Inc(JM^.TxtPos);
End;
EOM := (((JM^.TxtPos < MsgHdr^.JamHdr.TextOfs) Or
(JM^.TxtPos > JM^.TxtEnd)) And (JM^.TxtPos >= 0));
End;
Procedure JamMsgObj.AddTxtSub(St: String);
Var
i: Word;
Begin
For i := 1 to Length(St) Do
Begin
If JM^.TxtSubChars <= TxtSubBufSize Then
Begin
JM^.TxtSubBuf[JM^.TxtSubChars] := St[i];
Inc(JM^.TxtSubChars);
End;
End;
If JM^.TxtSubChars <= TxtSubBufSize Then
Begin
JM^.TxtSubBuf[JM^.TxtSubChars] := #13;
Inc(JM^.TxtSubChars);
End;
End;
Procedure JamMsgObj.InitMsgHdr;
Var
SubCtr: LongInt;
SubPtr: ^SubFieldType;
{$IFDEF VirtualPascal}
NumRead: LongInt;
{$ELSE}
{$IfDef SPEED}
NumRead: LongWord;
{$Else}
NumRead: Word;
{$EndIf}
{$ENDIF}
{$IFDEF WINDOWS}
DT: TDateTime;
{$ELSE}
DT: DateTime;
{$ENDIF}
IdxLoc: LongInt;
TmpStr: String;
TmpAddr: AddrType;
Begin
Error := 0;
Wrapped := False;
JM^.MsgFrom := '';
JM^.MsgTo := '';
JM^.MsgSubj := '';
JM^.TxtSubChars := 0;
If SeekFound Then begin
ReReadIdx(IdxLoc);
Seek(JM^.HdrFile, JamIdx^[IdxLoc - JM^.IdxStart].HdrLoc);
BlockRead(JM^.HdrFile, MsgHdr^, SizeOf(MsgHdr^), NumRead);
Error := IoResult;
If Error = 0 Then begin
UnixToDt(MsgHdr^.JamHdr.DateWritten, DT);
JM^.MsgDate := FormattedDate(Dt, 'MM-DD-YY');
JM^.MsgTime := FormattedDate(Dt, 'HH:II');
SubCtr := 1;
While ((SubCtr <= MsgHdr^.JamHdr.SubFieldLen) and
(SubCtr < JamSubBufSize)) Do begin
SubPtr := @MsgHdr^.SubBuf[SubCtr];
Inc(SubCtr, SubPtr^.DataLen + 8);
Case(SubPtr^.LoId) Of
0: Begin {Orig}
FillChar(TmpAddr, SizeOf(TmpAddr), #0);
FillChar(JM^.Orig, SizeOf(JM^.Orig), #0);
TmpStr[0] := Chr(SubPtr^.DataLen and $ff);
If Ord(TmpStr[0]) > 128 Then
TmpStr[0] := #128;
Move(SubPtr^.Data, TmpStr[1], Ord(TmpStr[0]));
ParseAddr(TmpStr, JM^.Orig);
End;
1: Begin {Dest}
FillChar(TmpAddr, SizeOf(TmpAddr), #0);
FillChar(JM^.Dest, SizeOf(JM^.Dest), #0);
TmpStr[0] := Chr(SubPtr^.DataLen and $ff);
If Ord(TmpStr[0]) > 128 Then
TmpStr[0] := #128;
Move(SubPtr^.Data, TmpStr[1], Ord(TmpStr[0]));
ParseAddr(TmpStr, JM^.Dest);
End;
2: Begin {MsgFrom}
JM^.MsgFrom[0] := Chr(SubPtr^.DataLen and $ff);
If Ord(JM^.MsgFrom[0]) > 65 Then
JM^.MsgFrom[0] := #65;
Move(SubPtr^.Data, JM^.MsgFrom[1], Ord(JM^.MsgFrom[0]));
End;
3: Begin {MsgTo}
JM^.MsgTo[0] := Chr(SubPtr^.DataLen and $ff);
If Ord(JM^.MsgTo[0]) > 65 Then
JM^.MsgTo[0] := #65;
Move(SubPtr^.Data, JM^.MsgTo[1], Ord(JM^.MsgTo[0]));
End;
4: Begin {MsgId}
TmpStr[0] := Chr(SubPtr^.DataLen and $ff);
If Ord(TmpStr[0]) > 240 Then
TmpSTr[0] := #240;
Move(SubPtr^.Data, TmpStr[1], Ord(TmpStr[0]));
AddTxtSub(#1'MSGID: ' + TmpStr);
End;
5: Begin {Reply}
TmpStr[0] := Chr(SubPtr^.DataLen and $ff);
If Ord(TmpStr[0]) > 240 Then
TmpSTr[0] := #240;
Move(SubPtr^.Data, TmpStr[1], Ord(TmpStr[0]));
AddTxtSub(#1'REPLY: ' + TmpStr);
End;
6: Begin {MsgSubj}
JM^.MsgSubj[0] := Chr(SubPtr^.DataLen and $ff);
If Ord(JM^.MsgSubj[0]) > 100 Then
JM^.MsgSubj[0] := #100;
Move(SubPtr^.Data, JM^.MsgSubj[1], Ord(JM^.MsgSubj[0]));
End;
7: Begin {PID}
TmpStr[0] := Chr(SubPtr^.DataLen and $ff);
If Ord(TmpStr[0]) > 240 Then
TmpSTr[0] := #240;
Move(SubPtr^.Data, TmpStr[1], Ord(TmpStr[0]));
AddTxtSub(#1'PID: ' + TmpStr);
End;
8: Begin {VIA}
TmpStr[0] := Chr(SubPtr^.DataLen and $ff);
If Ord(TmpStr[0]) > 240 Then
TmpSTr[0] := #240;
Move(SubPtr^.Data, TmpStr[1], Ord(TmpStr[0]));
AddTxtSub(#1'Via ' + TmpStr);
End;
9: Begin {File attached}
If IsFAttach Then
Begin
JM^.MsgSubj[0] := Chr(SubPtr^.DataLen and $ff);
If Ord(JM^.MsgSubj[0]) > 100 Then
JM^.MsgSubj[0] := #100;
Move(SubPtr^.Data, JM^.MsgSubj[1], Ord(JM^.MsgSubj[0]));
End
End;
11: Begin {File request}
If IsFileReq Then
Begin
JM^.MsgSubj[0] := Chr(SubPtr^.DataLen and $ff);
If Ord(JM^.MsgSubj[0]) > 100 Then
JM^.MsgSubj[0] := #100;
Move(SubPtr^.Data, JM^.MsgSubj[1], Ord(JM^.MsgSubj[0]));
End
End;
2000: Begin {Unknown kludge}
TmpStr[0] := Chr(SubPtr^.DataLen and $ff);
If Ord(TmpStr[0]) > 240 Then
TmpSTr[0] := #240;
Move(SubPtr^.Data, TmpStr[1], Ord(TmpStr[0]));
AddTxtSub(#1 + TmpStr);
End;
2001: Begin {SEEN-BY}
TmpStr[0] := Chr(SubPtr^.DataLen and $ff);
If Ord(TmpStr[0]) > 240 Then
TmpSTr[0] := #240;
Move(SubPtr^.Data, TmpStr[1], Ord(TmpStr[0]));
AddTxtSub(#1'SEEN-BY: ' + TmpStr);
End;
2002: Begin {PATH}
TmpStr[0] := Chr(SubPtr^.DataLen and $ff);
If Ord(TmpStr[0]) > 240 Then
TmpSTr[0] := #240;
Move(SubPtr^.Data, TmpStr[1], Ord(TmpStr[0]));
AddTxtSub(#1'PATH: ' + TmpStr);
End;
2003: Begin {FLAGS}
TmpStr[0] := Chr(SubPtr^.DataLen and $ff);
If Ord(TmpStr[0]) > 240 Then
TmpSTr[0] := #240;
Move(SubPtr^.Data, TmpStr[1], Ord(TmpStr[0]));
AddTxtSub(#1'FLAGS: ' + TmpStr);
End;
End;
End;
End;
End;
End;
Procedure JamMsgObj.MsgTxtStartUp;
Begin
Wrapped := False;
EOM:=False;
JM^.TxtEnd := MsgHdr^.JamHdr.TextOfs + MsgHdr^.JamHdr.TextLen - 1;
If JM^.TxtSubChars > 0 Then
JM^.TxtPos := - JM^.TxtSubChars
Else
JM^.TxtPos := MsgHdr^.JamHdr.TextOfs;
End;
Function JamMsgObj.GetString: String;