-
Notifications
You must be signed in to change notification settings - Fork 6
/
ftn.e
1191 lines (1015 loc) · 34.4 KB
/
ftn.e
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
MODULE 'dos/dos','dos/dostags','dos/datetime'
MODULE '*stringlist','*axobjects'
#ifndef EVO_3_4_0
FATAL 'This should only be compiled with E-VO Amiga E Compiler'
#endif
DEF confNames=NIL:PTR TO stringlist
DEF msgBasePaths=NIL:PTR TO stringlist
DEF tempDir[255]:STRING
DEF inboundDir[255]:STRING
DEF inboundInsecureDir[255]:STRING
DEF outboundDir[255]:STRING
DEF floPath[255]:STRING
ENUM ERR_NOCFG,ERR_WRITE_MAILSTAT,ERR_READ_MESSAGES_DAT,ERR_READ_MAILSTAT,ERR_READ_HEADERFILE
CONST RESULT_SUCCESS=-1,RESULT_FAILURE=0
OBJECT ftnHeader
msgdate[21]:ARRAY OF CHAR
to[37]:ARRAY OF CHAR
from[37]:ARRAY OF CHAR
subject[73]:ARRAY OF CHAR
confId[255]:ARRAY OF CHAR
ENDOBJECT
PROC exec(fileName:PTR TO CHAR)
DEF r
r:=SystemTagList(fileName,[SYS_INPUT,0,SYS_OUTPUT,0,SYS_ASYNCH,FALSE,NIL]:LONG)
IF r=-1
WriteF('Error executing \s\n\n',fileName)
ENDIF
ENDPROC r
PROC replacestr(sourcestring,searchtext,replacetext)
DEF newstring,tempstring,oldpos, pos,len
newstring:=String(255)
tempstring:=String(255)
len:=StrLen(searchtext) /* not estrlen since this is likely to be a hard coded constant */
pos:=InStr(sourcestring,searchtext)
IF pos<>-1
oldpos:=0
WHILE pos<>-1
IF pos<>oldpos
MidStr(tempstring,sourcestring,oldpos,pos-oldpos)
StrAdd(newstring,tempstring)
ENDIF
StrAdd(newstring,replacetext)
pos:=pos+len
oldpos:=pos
pos:=InStr(sourcestring,searchtext,oldpos)
ENDWHILE
pos:=EstrLen(sourcestring)
IF pos<>oldpos
MidStr(tempstring,sourcestring,oldpos,pos-oldpos)
StrAdd(newstring,tempstring)
ENDIF
StrCopy(sourcestring,newstring)
ENDIF
DisposeLink(newstring)
DisposeLink(tempstring)
ENDPROC
PROC trimRight(src:PTR TO CHAR,dest:PTR TO CHAR)
DEF n,v=0
StrCopy(dest,src)
n:=EstrLen(dest)
IF n>0 THEN v:=dest[n-1]
WHILE (n>0) AND (v=" ")
SetStr(dest,n-1)
n:=EstrLen(dest)
IF n>0 THEN v:=dest[n-1]
ENDWHILE
ENDPROC
PROC fillStrCopy(src:PTR TO CHAR,dest:PTR TO CHAR,len)
DEF i
FOR i:=0 TO len-1
dest[i]:=0
ENDFOR
AstrCopy(dest,src,len)
ENDPROC
PROC saveMh(fh,mailHeader)
DEF result,size
size:=SIZEOF mailHeader
result:=Write(fh,mailHeader,size)
ENDPROC result
PROC getMsgBasePath(confName,msgBasePath:PTR TO CHAR)
DEF i
FOR i:=0 TO confNames.count()-1
IF StrCmp(confNames.item(i),confName)
StrCopy(msgBasePath,msgBasePaths.item(i),ALL)
ENDIF
ENDFOR
ENDPROC
PROC createMessagePacket(originNode,destNode,originNet,destNet,originZone,destZone,originPoint,destPoint,attr,cost,packetPass:PTR TO CHAR,msgPktFileHandle, srcFilename:PTR TO CHAR,confId:PTR TO CHAR,tearLine:PTR TO CHAR, originLine:PTR TO CHAR,tzOffset:PTR TO CHAR,netMail,floFilename:PTR TO CHAR)
DEF fh2
DEF tempStr[255]:STRING
DEF tempStr2[255]:STRING
DEF fromName[255]:STRING
DEF toName[255]:STRING
DEF subject[255]:STRING
DEF msgDateTime[255]:STRING
DEF msgbuf:PTR TO CHAR, msgsz
DEF mhdr[14]:ARRAY OF CHAR
DEF null[1]:ARRAY OF CHAR
DEF phdr[58]:ARRAY OF CHAR
DEF status,p,i
DEF year,month,day,hour,minute,second
DEF monthCodes[40]:STRING
DEF msgId[10]:STRING
DEF originStr[100]:STRING
DEF netInfo[255]:STRING
DEF flofh
IF originPoint<>0
StringF(originStr,'\d:\d/\d.\d',originZone,originNet,originNode,originPoint)
ELSE
StringF(originStr,'\d:\d/\d',originZone,originNet,originNode)
ENDIF
formatLongDateTime2(getSystemTime(),msgDateTime,",")
StrCopy(tempStr,msgDateTime,2)
month:=Val(tempStr)
StrCopy(tempStr,msgDateTime+3,2)
day:=Val(tempStr)
StrCopy(tempStr,msgDateTime+6,2)
year:=Val(tempStr)
IF year<38 THEN year:=year+2000 ELSE year:=year+1900
StrCopy(tempStr,msgDateTime+9,2)
hour:=Val(tempStr)
StrCopy(tempStr,msgDateTime+12,2)
minute:=Val(tempStr)
StrCopy(tempStr,msgDateTime+15,2)
second:=Val(tempStr)
fh2:=Open(srcFilename,MODE_OLDFILE)
IF fh2<>0
ReadStr(fh2,fromName)
IF EstrLen(fromName)>35 THEN SetStr(fromName,35)
ReadStr(fh2,toName)
IF EstrLen(toName)>35 THEN SetStr(toName,35)
ReadStr(fh2,subject)
IF EstrLen(subject)>71 THEN SetStr(toName,71)
ReadStr(fh2,msgDateTime)
ReadStr(fh2,msgId)
p:=Seek(fh2,0,OFFSET_END)
msgsz:=Seek(fh2,p,OFFSET_BEGINNING)-p
msgbuf:=New(msgsz)
Read(fh2,msgbuf,msgsz)
Close(fh2)
IF netMail
IF (p:=InStr(toName,'@'))>=0
SetStr(toName,p)
StrCopy(netInfo,toName+p+1)
IF (p:=InStr(netInfo,':'))>0
->extract and remove zone info
StrCopy(tempStr,netInfo,p)
destZone:=Val(tempStr)
StrCopy(netInfo,netInfo+p+1)
ELSE
destZone:=0
ENDIF
IF (p:=InStr(netInfo,'/'))>0
->extract and remove net info
StrCopy(tempStr,netInfo,p)
destNet:=Val(tempStr)
StrCopy(netInfo,netInfo+p+1)
IF (p:=InStr(netInfo,'/'))>0
->extract and remove node info
StrCopy(tempStr,netInfo,p)
destNode:=Val(tempStr)
StrCopy(netInfo,netInfo+p+1)
destPoint:=Val(netInfo)
ELSE
destNode:=Val(netInfo)
destPoint:=0
ENDIF
ELSE
destZone:=0
destNode:=0
destNet:=0
destPoint:=0
ENDIF
ELSE
destZone:=originZone
destNode:=originNode
destNet:=originNet
destPoint:=originPoint
ENDIF
ENDIF
IF (destNode=0) OR (destNet=0)
Dispose(msgbuf)
RETURN FALSE
ENDIF
IF msgPktFileHandle>0
IF Seek(msgPktFileHandle,0,OFFSET_CURRENT)=0
->create packet header
phdr[0]:=originNode AND 255
phdr[1]:=Shr(originNode,8) AND 255
phdr[2]:=destNode AND 255
phdr[3]:=Shr(destNode,8) AND 255
phdr[4]:=year AND 255
phdr[5]:=Shr(year,8) AND 255
phdr[6]:=month AND 255
phdr[7]:=Shr(month,8) AND 255
phdr[8]:=day AND 255
phdr[9]:=Shr(day,8) AND 255
phdr[10]:=hour AND 255
phdr[11]:=Shr(hour,8) AND 255
phdr[12]:=minute AND 255
phdr[13]:=Shr(minute,8) AND 255
phdr[14]:=second AND 255
phdr[15]:=Shr(second,8) AND 255
phdr[16]:=0 ->baud low
phdr[17]:=0 ->baud hi
phdr[18]:=2 ->type
phdr[19]:=0 ->type
phdr[20]:=originNet AND 255
phdr[21]:=Shr(originNet,8) AND 255
phdr[22]:=destNet AND 255
phdr[23]:=Shr(destNet,8) AND 255
phdr[24]:=0 ->prodCode
phdr[25]:=1 ->prodVersionMajor
phdr[26]:=0;phdr[27]:=0;phdr[28]:=0;phdr[29]:=0; ->password
phdr[30]:=0;phdr[31]:=0;phdr[32]:=0;phdr[33]:=0; ->password
AstrCopy(phdr+26,packetPass,9)
phdr[34]:=originZone AND 255
phdr[35]:=Shr(originZone,8) AND 255
phdr[36]:=destZone AND 255
phdr[37]:=Shr(destZone,8) AND 255
phdr[38]:=0 ->reserved
phdr[39]:=0 ->reserved
phdr[40]:=0 ->capvalid
phdr[41]:=1 ->capvalid
phdr[42]:=1 ->prodcodehi
phdr[43]:=0 ->prodversionminor
phdr[44]:=1 ->capword
phdr[45]:=0 ->capword
phdr[46]:=originZone AND 255
phdr[47]:=Shr(originZone,8) AND 255
phdr[48]:=destZone AND 255
phdr[49]:=Shr(destZone,8) AND 255
phdr[50]:=originPoint AND 255
phdr[51]:=Shr(originPoint,8) AND 255
phdr[52]:=destPoint AND 255
phdr[53]:=Shr(destPoint,8) AND 255
phdr[54]:=0
phdr[55]:=0
phdr[56]:=0
phdr[57]:=0
->write packet header
Write(msgPktFileHandle,phdr,58)
ENDIF
status:=" "
->write message header
mhdr[0]:=2
mhdr[1]:=0
mhdr[2]:=originNode AND 255
mhdr[3]:=Shr(originNode,8) AND 255
mhdr[4]:=destNode AND 255
mhdr[5]:=Shr(destNode,8) AND 255
mhdr[6]:=originNet AND 255
mhdr[7]:=Shr(originNet,8) AND 255
mhdr[8]:=destNet AND 255
mhdr[9]:=Shr(destNet,8) AND 255
mhdr[10]:=attr AND 255
mhdr[11]:=Shr(attr,8) AND 255
mhdr[12]:=cost AND 255
mhdr[13]:=Shr(cost,8) AND 255
Write(msgPktFileHandle,mhdr,14)
null[0]:=0
StrCopy(monthCodes,'JanFebMarAprMayJunJulAugSepOctNovDec')
StrCopy(tempStr,msgDateTime,2)
month:=Val(tempStr)-1
StringF(tempStr,'\s[2] \s[3] \s[2] \s[2]:\s[2]:\s[2]',msgDateTime+3,monthCodes+(month*3),msgDateTime+6,msgDateTime+9,msgDateTime+12,msgDateTime+15)
Write(msgPktFileHandle,tempStr,19)
Write(msgPktFileHandle,null,1)
Write(msgPktFileHandle,toName,EstrLen(toName))
Write(msgPktFileHandle,null,1)
Write(msgPktFileHandle,fromName,EstrLen(fromName))
Write(msgPktFileHandle,null,1)
Write(msgPktFileHandle,subject,EstrLen(subject))
Write(msgPktFileHandle,null,1)
IF StrLen(confId)>0
StringF(tempStr,'AREA:\s\b',confId)
Write(msgPktFileHandle,tempStr,EstrLen(tempStr))
ENDIF
StringF(tempStr,'\cCHRS: LATIN-1 2\b',1)
Write(msgPktFileHandle,tempStr,EstrLen(tempStr))
IF StrLen(msgId)>0
StringF(tempStr,'\cMSGID: \s \z\h[8]\b',1,originStr,Val(msgId))
Write(msgPktFileHandle,tempStr,EstrLen(tempStr))
ENDIF
StringF(tempStr,'\cTZUTC: \s\b',1,IF StrLen(tzOffset)=0 THEN '0000' ELSE tzOffset)
Write(msgPktFileHandle,tempStr,EstrLen(tempStr))
FOR i:=0 TO msgsz-1
IF msgbuf[i]=10 THEN msgbuf[i]:=13
ENDFOR
Write(msgPktFileHandle,msgbuf,msgsz)
->write tear line
IF StrLen(tearLine)>0
StringF(tempStr,'--- \s\b',tearLine)
Write(msgPktFileHandle,tempStr,EstrLen(tempStr))
ENDIF
->write origin line
IF StrLen(originLine)>0
StringF(tempStr,' * Origin: \s (\s)\b',originLine,originStr)
Write(msgPktFileHandle,tempStr,EstrLen(tempStr))
ENDIF
IF (netMail=FALSE)
->write seen by line
StringF(tempStr,'SEEN-BY: \d/\d \d/\d\b',originNet,originNode,destNet,destNode)
Write(msgPktFileHandle,tempStr,EstrLen(tempStr))
StringF(tempStr,'\cPATH: \d/\d\b',1,originNet,originNode)
Write(msgPktFileHandle,tempStr,EstrLen(tempStr))
ENDIF
->nul terminate
StrCopy(tempStr,'')
Write(msgPktFileHandle,tempStr,1)
flofh:=Open(floFilename,MODE_READWRITE)
IF flofh<>0
Seek(flofh,0,OFFSET_END)
NameFromFH(msgPktFileHandle,tempStr2,255)
StringF(tempStr,'^\s\s\n',floPath,FilePart(tempStr2))
Write(flofh,tempStr,StrLen(tempStr))
Close(flofh)
ENDIF
ENDIF
Dispose(msgbuf)
ENDIF
ENDPROC TRUE
PROC createEchoMessagesPacket(originNode,destNode,originNet,destNet,originZone,destZone,originPoint,destPoint,attr,cost,packetPass,tearLine:PTR TO CHAR, originLine:PTR TO CHAR,tzOffset:PTR TO CHAR,netMailConf:PTR TO CHAR,floFilename:PTR TO CHAR)
DEF i,n,fh=0
DEF msgOutPath[255]:STRING
DEF fBlock:PTR TO fileinfoblock
DEF fLock
DEF msgFile[255]:STRING
DEF null[2]:ARRAY OF CHAR
DEF tempStr[255]:STRING
DEF msgPacketFilename[255]:STRING
DEF netMail,res
IF(fBlock:=AllocDosObject(DOS_FIB,NIL))
FOR i:=0 TO msgBasePaths.count()-1
netMail:=FALSE
StrCopy(tempStr,confNames.item(i))
UpperStr(tempStr)
IF StrCmp(tempStr,netMailConf) THEN netMail:=TRUE ELSE netMail:=FALSE
IF netMail=FALSE
WriteF(' Processing echomail for \s\n',confNames.item(i))
StringF(msgOutPath,'\sEXT-OUT',msgBasePaths.item(i))
IF(fLock:=Lock(msgOutPath,ACCESS_READ))
IF(Examine(fLock,fBlock))
WHILE(ExNext(fLock,fBlock))
StringF(msgFile,'\s/\s',msgOutPath,fBlock.filename)
IF fh=0
n:=getSystemTime()
REPEAT
StringF(msgPacketFilename,'\s\z\h[8].PKT',outboundDir,n)
LowerStr(msgPacketFilename)
n++
UNTIL FileLength(msgPacketFilename)=-1
fh:=Open(msgPacketFilename,MODE_NEWFILE)
ENDIF
IF fh<>0
WriteF(' processing \s\n',msgFile)
res:=res OR createMessagePacket(originNode,destNode,originNet,destNet,originZone,destZone,originPoint,destPoint,attr,cost,packetPass,fh,msgFile,confNames.item(i),tearLine,originLine,tzOffset,FALSE,floFilename)
SetProtection(msgFile,FIBF_OTR_DELETE)
DeleteFile(msgFile)
ENDIF
ENDWHILE
ENDIF
UnLock(fLock)
ENDIF
ENDIF
ENDFOR
FreeDosObject(DOS_FIB,fBlock)
ENDIF
IF fh>0
IF res
null[0]:=0
null[1]:=0
Write(fh,null,2)
ENDIF
Close(fh)
ENDIF
ENDPROC
PROC createNetMailMessagesPackets(originNode,originNet,originZone,originPoint,attr,cost,packetPass,tzOffset:PTR TO CHAR,netMailConf:PTR TO CHAR,floFilename:PTR TO CHAR)
DEF i,n,fh=0
DEF msgOutPath[255]:STRING
DEF fBlock:PTR TO fileinfoblock
DEF fLock
DEF msgFile[255]:STRING
DEF null[2]:ARRAY OF CHAR
DEF tempStr[255]:STRING
DEF msgPacketFilename[255]:STRING
DEF netMail
IF(fBlock:=AllocDosObject(DOS_FIB,NIL))
FOR i:=0 TO msgBasePaths.count()-1
netMail:=FALSE
StrCopy(tempStr,confNames.item(i))
UpperStr(tempStr)
IF StrCmp(tempStr,netMailConf) THEN netMail:=TRUE ELSE netMail:=FALSE
IF netMail
WriteF(' Processing netmail for \s\n',confNames.item(i))
StringF(msgOutPath,'\sEXT-OUT',msgBasePaths.item(i))
IF(fLock:=Lock(msgOutPath,ACCESS_READ))
IF(Examine(fLock,fBlock))
WHILE(ExNext(fLock,fBlock))
StringF(msgFile,'\s/\s',msgOutPath,fBlock.filename)
IF fh=0
n:=getSystemTime()
REPEAT
StringF(msgPacketFilename,'\s\z\h[8].PKT',outboundDir,n)
LowerStr(msgPacketFilename)
n++
UNTIL FileLength(msgPacketFilename)=-1
fh:=Open(msgPacketFilename,MODE_NEWFILE)
ENDIF
IF fh<>0
WriteF(' processing \s\n',msgFile)
IF createMessagePacket(originNode,0,originNet,0,originZone,0,originPoint,0,attr,cost,packetPass,fh,msgFile,'','','',tzOffset,TRUE,floFilename)
null[0]:=0
null[1]:=0
Write(fh,null,2)
ENDIF
Close(fh)
fh:=0
SetProtection(msgFile,FIBF_OTR_DELETE)
DeleteFile(msgFile)
ENDIF
ENDWHILE
ENDIF
UnLock(fLock)
ENDIF
ENDIF
ENDFOR
FreeDosObject(DOS_FIB,fBlock)
ENDIF
ENDPROC
PROC formatLongDateTime2(cDateVal,outDateStr,seperatorChar)
DEF d : PTR TO datestamp
DEF dt : datetime
DEF datestr[10]:STRING
DEF timestr[10]:STRING
DEF dateVal
dateVal:=cDateVal-21600
d:=dt.stamp
d.tick:=(dateVal-Mul(Div(dateVal,60),60))
d.tick:=Mul(d.tick,50)
dateVal:=Div(dateVal,60)
d.days:=Div((dateVal),1440)-2922 ->-2922 days between 1/1/70 and 1/1/78
d.minute:=dateVal-(Mul(d.days+2922,1440))
dt.format:=FORMAT_USA
dt.flags:=0
dt.strday:=0
dt.strdate:=datestr
dt.strtime:=timestr
IF DateToStr(dt)
StringF(outDateStr,'\s\c\s',datestr,seperatorChar,timestr)
RETURN TRUE
ENDIF
ENDPROC FALSE
->returns system time converted to c time format
PROC getSystemTime()
DEF currDate: datestamp
DEF startds:PTR TO datestamp
DEF s1,s2,s3,s4
startds:=DateStamp(currDate)
s1:=startds.days+2922
s1:=Mul(1440,s1)
s1:=Mul(60,s1)
s2:=Mul(60,startds.minute)
s3:=startds.tick/50
s4:=Mul(Mul(startds.days+2922,1440),60)+(startds.minute*60)+(startds.tick/50)
->2922 days between 1/1/70 and 1/1/78
ENDPROC s4+21600
PROC getEncodedDate(dateStr:PTR TO CHAR)
DEF dt:datetime
DEF tempStr[30]:STRING
DEF strDate[20]:STRING
DEF strTime[20]:STRING
DEF dval
StrCopy(strDate,TrimStr(dateStr),9)
strDate[2]:="-"
strDate[6]:="-"
StrCopy(tempStr,dateStr)
RightStr(strTime,tempStr,8)
dt.format:=FORMAT_DOS
dt.flags:=0
dt.strday:=0
dt.strdate:=strDate
dt.strtime:=strTime
IF StrToDate(dt)=0 THEN RETURN 0
dval:=Mul(Mul(dt.stamp.days+2922,1440),60)+(dt.stamp.minute*60)+(dt.stamp.tick/50)
->2922 days between 1/1/70 and 1/1/78
ENDPROC dval+21600
PROC readString(fileHandle,buffer,maxLength)
DEF char,cnt,i
cnt:=0
FOR i:=0 TO maxLength-1 DO buffer[i]:=0
REPEAT
char:=FgetC(fileHandle)
IF (char=-1) OR (char=0) THEN RETURN
buffer[cnt]:=char
cnt++
UNTIL (cnt=maxLength)
ENDPROC
PROC findBodyLength(fileHandle)
DEF cnt,char
cnt:=0
REPEAT
char:=FgetC(fileHandle)
IF char<>-1 THEN cnt++
UNTIL char<=0
Seek(fileHandle,-cnt,OFFSET_CURRENT)
ENDPROC cnt
PROC writeMailLine(fh2,lineBuff:PTR TO CHAR)
DEF i,lineLen,ansi=FALSE
DEF lastSpace,s,partlen
IF (StrCmp(TrimStr(lineBuff),'SEEN-BY: ',9)=FALSE) AND (StrCmp(TrimStr(lineBuff),'AREA: ',6)=FALSE) AND (lineBuff[0]<>1)
lineLen:=EstrLen(lineBuff)
FOR i:=0 TO lineLen-1 DO IF lineBuff[i]=27 THEN ansi:=TRUE
IF (ansi=FALSE) AND (lineLen>75)
partlen:=0
lastSpace:=-1
s:=0
FOR i:=0 TO lineLen-1
IF lineBuff[i]=" " THEN lastSpace:=i
IF partlen>=75
IF lastSpace>=0
lineBuff[lastSpace]:=10
partlen:=i-lastSpace-1
lastSpace:=-1
ELSE
Write(fh2,lineBuff+s,i-s)
Write(fh2,'\n',1)
s:=i
partlen:=0
ENDIF
ENDIF
partlen++
ENDFOR
StrAdd(lineBuff,'\n')
Write(fh2,lineBuff+s,lineLen-s+1)
ELSE
StrAdd(lineBuff,'\n')
Write(fh2,lineBuff,lineLen+1)
ENDIF
ENDIF
ENDPROC
PROC addNetText(textStr:PTR TO CHAR,zone,net,node,point)
DEF netText[100]:STRING
IF zone=0
StringF(netText,'@\d/\d',net,node)
ELSE
IF point<>0
StringF(netText,'@\d:\d/\d.\d',zone,net,node,point)
ELSE
StringF(netText,'@\d:\d/\d',zone,net,node)
ENDIF
ENDIF
StrAdd(textStr,netText)
ENDPROC
PROC processPacketFile(filename:PTR TO CHAR,netMailConf:PTR TO CHAR) HANDLE
DEF ftnh: ftnHeader
DEF ms: mailStat
DEF mh: mailHeader
DEF buf=0:PTR TO CHAR
DEF buf2=0:PTR TO CHAR,bufsz
DEF mf=0,fh=0,fh2=0
DEF n,c,i
DEF tempStr[255]:STRING
DEF lineBuff:PTR TO CHAR
DEF newMsgNum
DEF fname[255]:STRING
DEF msgBase[255]:STRING
DEF ftnConfId[255]:STRING
DEF lastConfId[255]:STRING
DEF needToSave
DEF cnt,maxCnt
DEF priv=FALSE
DEF netMail=FALSE
DEF originZone,destZone,originNet,destNet,originNode,destNode,originPoint,destPoint
WriteF('processing packet \s\n',filename)
needToSave:=FALSE
StrCopy(lastConfId,'######')
mf:=Open(filename,MODE_OLDFILE)
IF mf<>0
buf:=New(58)
n:=Fread(mf,buf,58,1)
IF n>0
originZone:=buf[46]+Shl(buf[47],8)
destZone:=buf[48]+Shl(buf[49],8)
originPoint:=buf[50]+Shl(buf[51],8)
destPoint:=buf[52]+Shl(buf[53],8)
Dispose(buf)
buf:=New(35)
c:=0
REPEAT
n:=Fread(mf,buf,2,1)
IF (buf[0]=2) AND (buf[1]=0)
n:=Fread(mf,buf+2,32,1)
buf[34]:=0
IF n>0
IF buf[10] AND 1 THEN priv:=TRUE ELSE priv:=FALSE
originNode:=buf[2]+Shl(buf[3],8)
destNode:=buf[4]+Shl(buf[5],8)
originNet:=buf[6]+Shl(buf[7],8)
destNet:=buf[8]+Shl(buf[9],8)
AstrCopy(ftnh.msgdate,buf+14,21)
readString(mf,ftnh.to,36)
readString(mf,ftnh.from,36)
readString(mf,ftnh.subject,72)
bufsz:=findBodyLength(mf)
buf2:=New(bufsz+1)
Fread(mf,buf2,bufsz,1)
StrCopy(tempStr,'')
n:=0
WHILE (n<bufsz) AND (buf2[n]<>0) AND (buf2[n]<>10) AND (buf2[n]<>13)
StrAdd(tempStr,buf2+n,1)
n++
ENDWHILE
WHILE (n<bufsz) AND ((buf2[n]=0) OR (buf2[n]=10) OR (buf2[n]=13)) DO n++
IF StrCmp(tempStr,'AREA:',5)
AstrCopy(ftnh.confId,tempStr+5)
ELSE
AstrCopy(ftnh.confId,'')
ENDIF
netMail:=FALSE
IF StrLen(ftnh.confId)=0
AstrCopy(ftnh.confId,netMailConf)
netMail:=TRUE
ENDIF
WriteF('id: \d\n',c)
WriteF('conf: \s\n',ftnh.confId)
WriteF('to: \s\n',ftnh.to)
WriteF('from: \s\n',ftnh.from)
WriteF('subject: \s\n',ftnh.subject)
WriteF('\n')
UpperStr(ftnh.confId)
IF StrCmp(ftnh.confId,lastConfId)=FALSE
IF fh>0
Close(fh)
fh:=0
ENDIF
IF needToSave
ms.highMsgNum:=newMsgNum+1
StringF(fname,'\sMailStats',msgBase)
fh:=Open(fname,MODE_NEWFILE)
IF fh<>0
Write(fh,ms,SIZEOF mailStat)
Close(fh)
fh:=0
ELSE
WriteF('Error saving MailStats\n\n')
Raise(ERR_WRITE_MAILSTAT)
ENDIF
needToSave:=FALSE
ENDIF
getMsgBasePath(ftnh.confId,msgBase)
IF StrLen(msgBase)=0
WriteF('FTN conf \s not configured, skipping messages for this conf\n\n',ftnh.confId)
StrCopy(ftnConfId,'######')
ELSE
StrCopy(ftnConfId,ftnh.confId)
StringF(fname,'\sMailStats',msgBase)
IF fh>0 THEN Close(fh)
fh:=Open(fname,MODE_READWRITE)
IF fh<>0
IF Read(fh,ms,SIZEOF mailStat)=0
ms.lowestKey:=1
ms.lowestNotDel:=1
ms.highMsgNum:=1
ms.pad[0]:=0;ms.pad[1]:=0;ms.pad[2]:=0;ms.pad[3]:=0;ms.pad[4]:=0;ms.pad[5]:=0
Write(fh,ms,SIZEOF mailStat)
Close(fh)
fh:=0
ELSE
Close(fh)
fh:=0
ENDIF
ELSE
WriteF('Error opening MailStats (\s)\n\n',fname)
Raise(ERR_READ_MAILSTAT)
ENDIF
newMsgNum:=ms.highMsgNum-1
StringF(fname,'\sHeaderFile',msgBase)
fh:=Open(fname,MODE_READWRITE)
IF fh<>0
Seek(fh,0,OFFSET_END)
ELSE
WriteF('Error opening HeaderFile\n\n')
Raise(ERR_READ_HEADERFILE)
ENDIF
ENDIF
ENDIF
StrCopy(lastConfId,ftnh.confId)
IF StrCmp(ftnh.confId,ftnConfId)
newMsgNum++
IF priv THEN mh.status:="R" ELSE mh.status:="P"
mh.msgNumb:=newMsgNum
trimRight(ftnh.to,tempStr)
fillStrCopy(tempStr,mh.toName,31)
trimRight(ftnh.from,tempStr)
IF netMail THEN addNetText(tempStr,originZone,originNet,originNode,originPoint)
fillStrCopy(tempStr,mh.fromName,31)
trimRight(ftnh.subject,tempStr)
fillStrCopy(tempStr,mh.subject,31)
mh.msgDate:=getEncodedDate(ftnh.msgdate)
mh.recv:=0
mh.extMsgNum:=0
IF saveMh(fh,mh)<>110
WriteF('Error saving mail header for message \d\n',newMsgNum)
ENDIF
needToSave:=TRUE
StringF(fname,'\s\d',msgBase,newMsgNum)
fh2:=Open(fname,MODE_NEWFILE)
IF fh2<>0
i:=n
n:=0
WHILE i<bufsz
IF buf2[i]<>10
buf2[n]:=buf2[i]
n++
ENDIF
i++
ENDWHILE
FOR i:=0 TO n-1
IF buf2[i]=13 THEN buf2[i]:=10
ENDFOR
StrCopy(tempStr,'')
cnt:=0
maxCnt:=0
FOR i:=0 TO n-1
IF buf2[i]=10
IF cnt>maxCnt THEN maxCnt:=cnt
cnt:=0
ELSE
cnt++
ENDIF
ENDFOR
IF cnt>maxCnt THEN maxCnt:=cnt
lineBuff:=String(maxCnt+1)
i:=0
WHILE (i<n)
IF (buf2[i]<>10)
StrAdd(lineBuff,buf2+i,1)
i++
ELSE
writeMailLine(fh2,lineBuff)
StrCopy(lineBuff,'')
i++
ENDIF
ENDWHILE
IF StrLen(lineBuff)>0
writeMailLine(fh2,lineBuff)
ENDIF
DisposeLink(lineBuff)
Close(fh2)
fh2:=0
ELSE
WriteF('Error saving message body for message \d\n\n',newMsgNum)
ENDIF
Dispose(buf2)
buf2:=0
ELSE
Seek(mf,bufsz,OFFSET_CURRENT)
ENDIF
ENDIF
n:=1
c++
ELSEIF (buf[0]=0) AND (buf[1]=0)
->double null indicates no more data
n:=0
ELSE
WriteF('Error reading message header from \s invalid message type found\n\n',filename)
Raise(ERR_READ_MESSAGES_DAT)
ENDIF
UNTIL (n=0) OR (CtrlC())
Close(fh)
fh:=0
IF needToSave
ms.highMsgNum:=newMsgNum+1
StringF(fname,'\sMailStats',msgBase)
fh:=Open(fname,MODE_NEWFILE)
IF fh<>0
Write(fh,ms,SIZEOF mailStat)
Close(fh)
fh:=0
ELSE
WriteF('Error saving MailStats\n\n')
Raise(ERR_WRITE_MAILSTAT)
ENDIF
needToSave:=FALSE
ENDIF
ENDIF
IF mf>0 THEN Close(mf)
mf:=0
RETURN TRUE
ELSE
WriteF('Error opening \s\n\n',filename)
Raise(ERR_READ_MESSAGES_DAT)
ENDIF
EXCEPT DO
IF fh>0 THEN Close(fh)
IF fh2>0 THEN Close(fh2)
IF mf>0 THEN Close(mf)
IF buf<>0 THEN Dispose(buf)
IF buf2<>0 THEN Dispose(buf2)
ENDPROC
PROC processPackets(scanPath:PTR TO CHAR,netMailConf:PTR TO CHAR)
DEF packetFilename[255]:STRING
DEF fname[255]:STRING
DEF fBlock:PTR TO fileinfoblock
DEF tempStr[255]:STRING
DEF fLock
IF(fBlock:=AllocDosObject(DOS_FIB,NIL))
IF(fLock:=Lock(scanPath,ACCESS_READ))
IF(Examine(fLock,fBlock))
WHILE(ExNext(fLock,fBlock))
StrCopy(fname,fBlock.filename)
RightStr(tempStr,fname,4)
UpperStr(tempStr)
IF StrCmp(tempStr,'.PKT')
StringF(packetFilename,'\s\s',scanPath,fBlock.filename)
WriteF(' processing \s\n',packetFilename)
IF processPacketFile(packetFilename,netMailConf)
SetProtection(packetFilename,FIBF_OTR_DELETE)
DeleteFile(packetFilename)
ENDIF
ENDIF
ENDWHILE
ENDIF
UnLock(fLock)
ENDIF
FreeDosObject(DOS_FIB,fBlock)
ENDIF
ENDPROC
PROC processBundles(unpackCommand:PTR TO CHAR, scanPath:PTR TO CHAR, netMailConf:PTR TO CHAR)
DEF cleanUp[255]:STRING
DEF unpack[255]:STRING
DEF fname[255]:STRING
DEF fBlock:PTR TO fileinfoblock
DEF tempStr[255]:STRING
DEF bundleFilename[255]:STRING
DEF fLock
IF(fBlock:=AllocDosObject(DOS_FIB,NIL))
IF(fLock:=Lock(scanPath,ACCESS_READ))
IF(Examine(fLock,fBlock))
WHILE(ExNext(fLock,fBlock))
IF fBlock.direntrytype < 0
StrCopy(fname,fBlock.filename)
RightStr(tempStr,fname,4)
UpperStr(tempStr)
IF StrCmp(tempStr,'.PKT')=FALSE
StringF(bundleFilename,'\s\s',scanPath,fBlock.filename)
WriteF('processing bundle \s\n',bundleFilename)
StrCopy(unpack,unpackCommand)
replacestr(unpack,'{filename}',bundleFilename)
exec(unpack)
processPackets(tempDir,netMailConf)
StringF(cleanUp,'delete \s ALL',tempDir)
exec(cleanUp)
SetProtection(bundleFilename,FIBF_OTR_DELETE)
DeleteFile(bundleFilename)
ENDIF
ENDIF
ENDWHILE
ENDIF