/
FUNCS.prg
1294 lines (834 loc) · 23.3 KB
/
FUNCS.prg
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
/// <exclude/>
FUNCTION __CheckUUEncode (c AS STRING) AS DWORD STRICT
LOCAL nRet AS DWORD
LOCAL cTemp AS STRING
LOCAL cBefore AS STRING
nRet := At2(UUE_START_NEWS, c)
IF nRet > 0
IF nRet == 1
cBefore := CRLF
ELSE
cBefore := SubStr(c, nRet-2, 2)
ENDIF
IF cBefore == CRLF
cTemp := SubStr(c, nRet + SLen(UUE_START_NEWS), 5)
cTemp := AllTrim(cTemp)
IF SLen(cTemp) == 3 .AND. Val(cTemp) > 599
NOP
ELSE
nRet := 0
ENDIF
ELSE
nRet := 0
ENDIF
ENDIF
RETURN nRet
/// <exclude />
FUNCTION __DecodeB64(cPath AS STRING, cFile AS STRING, cMail AS STRING) AS DWORD STRICT
LOCAL nRet AS DWORD
LOCAL hfOut AS PTR
LOCAL cFName AS STRING
LOCAL i AS DWORD
LOCAL nPos AS DWORD
// LOCAL nStop AS DWORD
LOCAL cTemp AS STRING
// LOCAL nSize AS DWORD
// this method strips out preceeding and affixed double CRs
// it assumes there are NOT extra ones. The decode will fail, otherwise.
// the 'correctly" formed attachment segment to decode will have the following
// structure: XXXXXXXCRLFXXXXXXXXCRLFXXXXXXCRLF etc. No double CRLFs
cFName := __GetFullPath(cPath, cFile)
cTemp := cMail
// strip all preceeding CRLFs from the front of the string
i := 1
DO WHILE SubStr(cTemp, i, 2) = CRLF
i += 2
ENDDO
IF i > 1
cTemp := SubStr2(cTemp, i)
ENDIF
// Now see if there is another double CRLF...
nPos := At2(TEMP_DECODE_BOUND, cTemp)
IF nPos > 0
cTemp := SubStr(cTemp, 1, nPos-1)
// but the string MUST end in a CRLF or decoding won't work properly
IF !(Right(cTemp,2) == CRLF)
cTemp += CRLF
ENDIF
ENDIF
hfOut := FCreate(cFName)
IF hfOut != F_ERROR
nRet := DWORD(DecodeBase64(cTemp, hfOut))
FClose(hfOut)
ENDIF
RETURN nRet
/// <exclude />
FUNCTION __DecodeQP (cMailPart AS STRING, hfOut AS PTR) AS DWORD STRICT
LOCAL nRet AS DWORD
LOCAL cPart AS STRING
LOCAL cDecode AS STRING
LOCAL nFound AS DWORD
LOCAL nOldPos AS DWORD
LOCAL lEOF AS LOGIC
LOCAL lDecode AS LOGIC
nOldPos := 1
lEof := .F.
DO WHILE !lEOF
nFound := At3("=", cMailPart, nOldPos-1)
IF nFound > 0
cDecode := SubStr(cMailPart, nFound+1, 2)
IF cDecode == CRLF
lDecode := FALSE
ELSE
lDecode := TRUE
ENDIF
cPart := SubStr(cMailPart, nOldPos, nFound-nOldPos )
IF lDecode
cPart += Chr(Val("0x"+cDecode))
ENDIF
ELSE
cPart := SubStr(cMailPart, nOldPos)
lEOF := TRUE
ENDIF
nRet += FWrite(hfOut, cPart )
nOldPos := nFound + 3
ENDDO
RETURN nRet
/// <exclude />
FUNCTION __DecodeQPrintable(cPath AS STRING, cFile AS STRING, cMail AS STRING) AS DWORD STRICT
LOCAL nRet AS DWORD
LOCAL nSize AS DWORD
LOCAL nPos AS DWORD
LOCAL hfOut AS PTR
IF SLen(cMail) = 0
RETURN 0
ENDIF
IF SLen(cFile) = 0
RETURN 0
ENDIF
cFile := __GetFullPath(cPath, cFile)
hfOut := FCreate(cFile)
IF hfOut != F_ERROR
nPos := At2(TEMP_DECODE_BOUND, cMail)
IF nPos > 0
nSize := SLen(TEMP_DECODE_BOUND)
cMail := SubStr2(cMail, nPos + nSize)
ENDIF
nRet := __DecodeQP(cMail, hfOut)
FClose(hfOut)
ENDIF
RETURN nRet
/// <exclude />
FUNCTION __DecodeUU(cText AS STRING, hfOut AS PTR) AS DWORD STRICT
LOCAL cLine AS STRING
LOCAL nRet AS DWORD
LOCAL nPos AS DWORD
LOCAL nNewPos AS DWORD
LOCAL cbErr AS CODEBLOCK
cbErr := ErrorBlock( {|e|_Break(e)} )
BEGIN SEQUENCE
nPos := 1
nNewPos := At3(CRLF, cText, nPos)
DO WHILE nNewPos > nPos
cLine := SubStr3(cText, nPos, nNewPos - nPos + 2)
nPos := nNewPos + 2
IF cLine = UUE_END
EXIT
ENDIF
nRet += UUDecodeLine(cLine, hfOut)
nNewPos := At3(CRLF, cText, nPos)
ENDDO
RECOVER
NOP
END SEQUENCE
ErrorBlock(cbErr)
RETURN nRet
INTERNAL FUNCTION __FixDate (pft AS _WINFILETIME) AS VOID STRICT
LOCAL stRemote IS _WINSYSTEMTIME
LOCAL stLocal IS _WINSYSTEMTIME
LOCAL nDiff AS DWORD
FileTimeToSystemTime(pft, @stRemote)
GetSystemTime(@stLocal)
IF stRemote:wYear != stLocal:wYear - 1
RETURN
ENDIF
#IFDEF __DEBUG__
// AltD()
#ENDIF
IF stRemote:wMonth < stLocal:wMonth
RETURN
ENDIF
nDiff := stRemote:wMonth - stLocal:wMonth
DO CASE
CASE nDiff == 0
// Same month
IF stRemote:wDay != stLocal:wDay
RETURN
ENDIF
CASE nDiff == 1
// New month at FTP Server
IF stRemote:wDay != 1
RETURN
ENDIF
OTHERWISE
RETURN
ENDCASE
IF IFXGetTimeDiff(@stRemote, @stLocal) > 0
stRemote:wYear := stLocal:wYear
SystemTimeToFileTime(@stRemote, pft)
ENDIF
RETURN
/// <exclude />
FUNCTION __GetDate(pTime AS _WINFILETIME) AS DATE STRICT
LOCAL dRet AS DATE
LOCAL ftLocal IS _WINFILETIME
LOCAL sysTime IS _WINSYSTEMTIME
IF FileTimeToLocalFileTime(pTime, @ftLocal)
pTime := @ftLocal
ENDIF
IF FileTimeToSystemTime(pTime, @sysTime)
dRet := ConDate(sysTime:wYear, sysTime:wMonth, sysTime:wDay)
ENDIF
RETURN dRet
/// <exclude />
FUNCTION __GetFileData(pData AS _WINWIN32_FIND_DATA) AS ARRAY STRICT
LOCAL aTemp AS ARRAY
LOCAL cTemp AS STRING
//LOCAL nPos AS DWORD
aTemp := ArrayCreate(F_ATTR)
cTemp := Psz2String(@pData:cFileName)
aTemp[F_NAME] := cTemp
IF pData:nFileSizeHigh > 0
aTemp[F_SIZE] := pData:nFileSizeLow + (pData:nFileSizeHigh * 1.0 * MAXDWORD)
ELSE
aTemp[F_SIZE] := pData:nFileSizeLow
ENDIF
aTemp[F_DATE] := __GetDate(@pData:ftLastWriteTime)
aTemp[F_TIME] := __GetTime(@pData:ftLastWriteTime)
IF pData:dwFileAttributes = 0
IF At2(".", cTemp) = 0
pData:dwFileAttributes := FA_DIRECTORY
ENDIF
ENDIF
aTemp[F_ATTR] := FAttr2String(pData:dwFileAttributes)
RETURN aTemp
/// <exclude />
FUNCTION __GetFileName(cFile AS STRING) AS STRING STRICT
LOCAL dwPos AS DWORD
IF (dwPos := RAt2("\", cFile)) = 0
IF (dwPos := RAt2(":", cFile)) = 0
RETURN cFile
ENDIF
ENDIF
RETURN SubStr2(cFile, dwPos + 1)
/// <exclude />
FUNCTION __GetFullPath(cPath AS STRING, cFile AS STRING) AS STRING STRICT
LOCAL dwPos AS DWORD
IF SLen(cPath) > 0
//
// File and path name specified, check, if
// file name contains path
//
IF (dwPos := RAt("\", cFile)) > 0
cFile := SubStr2(cFile, dwPos + 1)
ENDIF
IF Right(cPath, 1) != "\"
RETURN cPath + "\" + cFile
ENDIF
RETURN cPath + cFile
ENDIF
RETURN cFile
/// <exclude />
FUNCTION __GetTime(pTime AS _WINFILETIME) AS STRING STRICT
LOCAL cRet AS STRING
//LOCAL ftLocal IS _WINFILETIME
//LOCAL sysTime IS _WINSYSTEMTIME
LOCAL wDate, wTime AS WORD
LOCAL nHours, nMins, nSecs AS DWORD
// Dos Time Structure is 16 bits:
// hhhhhmmmmmmsssss
// 1111110000000000
// 5432109876543210
IF FileTimeToDosDateTime(pTime, @wDate, @wTime)
nSecs := _AND(wTime , 0b11111)
nMins := _AND(wTime >> 5,0b111111)
nHours := _AND(wTime >> 11, 0b11111)
cRet := ConTime(nHours, nMins, nSecs)
ENDIF
RETURN cRet
/// <exclude />
FUNCTION __GetTimeZoneDiff() AS STRING STRICT
LOCAL tzi IS _WINTIME_ZONE_INFORMATION
LOCAL dwZone AS DWORD
LOCAL nDiff AS INT
LOCAL cRet AS STRING
dwZone := GetTimeZoneInformation(@tzi)
DO CASE
CASE dwZone == TIME_ZONE_ID_STANDARD
nDiff := tzi:Bias/60
CASE dwZone == TIME_ZONE_ID_DAYLIGHT
nDiff := (tzi:Bias/60) + (tzi:DaylightBias/60)
OTHERWISE
nDiff := 0
ENDCASE
IF nDiff > 0
nDiff *= 100
cRet := " -" + StrZero(nDiff, 4, 0)
ELSE
nDiff *= -100
cRet := " +" + StrZero(nDiff, 4, 0)
ENDIF
RETURN cRet
/// <exclude />
FUNCTION __GetToken(cText AS STRING, cStart AS STRING, cStop AS STRING, lStopNotRequired := FALSE AS LOGIC) AS STRING STRICT
LOCAL cRet AS STRING
LOCAL dwPos AS DWORD
LOCAL dwStop AS DWORD
// this function returns all the text between the cStart and cStop strings
// mostly used to decode HTML or email tags: <something>, or "something"
IF cStart == NULL_STRING
dwPos := 1
ELSE
dwPos := AtC(cStart, cText)
ENDIF
IF dwPos > 0
IF (dwStop := At3(cStop, cText, dwPos)) > 0
dwPos += SLen(cStart)
cRet := SubStr3(cText, dwPos, dwStop-dwPos)
ELSEIF lStopNotRequired
// return until CRLF or end of text
dwPos += SLen(cStart)
IF (dwStop := At3(CRLF, cText, dwPos)) > 0
cRet := SubStr3(cText, dwPos, dwStop-dwPos)
ELSE
cRet := SubStr2(cText, dwPos)
ENDIF
ENDIF
ENDIF
RETURN cRet
/// <exclude />
FUNCTION __GoodFileName(cAttachName AS STRING) AS STRING STRICT
LOCAL sb AS System.Text.StringBuilder
// The following characters are not allowed in a filename: \ / ? : * " > < |
// Replace them with [ ] $ = + ^ ) ( !
sb := System.Text.StringBuilder{}
FOREACH VAR ch IN cAttachName
LOCAL c AS CHAR
SWITCH ch
CASE c'/'
c := c'['
CASE c'\\'
c := c']'
CASE c'?'
c := c'$'
CASE c':'
c := c'='
CASE c'*'
c := c'+'
CASE c'"'
c := c'^'
CASE c'>'
c := ')'
CASE c'<'
c := c'('
CASE c'|'
c := c'!'
OTHERWISE
c := ch
END SWITCH
sb:Append(c)
NEXT
RETURN sb:ToString()
/// <exclude />
FUNCTION __SaveAs(cPath AS STRING, cFile AS STRING, cMail AS STRING) AS DWORD STRICT
LOCAL nRet AS DWORD
LOCAL cFName AS STRING
LOCAL nPos AS DWORD
LOCAL cTemp AS STRING
LOCAL nSize AS DWORD
cFName := cPath + cFile
cTemp := cMail
nPos := At2(CRLF + CRLF, cTemp)
IF nPos > 0
nSize := 4
cTemp := SubStr2(cTemp, nPos + nSize)
ENDIF
IF MemoWrit(cFName, cTemp)
nRet := SLen(cTemp)
ENDIF
RETURN nRet
/// <exclude />
FUNCTION __StrList2Array(cList AS STRING, cDelimiter := ", " AS STRING) AS ARRAY STRICT
LOCAL dwPos AS DWORD
LOCAL dwStart AS DWORD
LOCAL dwLen AS DWORD
LOCAL aRet AS ARRAY
aRet := {}
dwLen := SLen(cDelimiter)
IF SLen(cList) == 0 .OR. dwLen = 0
RETURN aRet
ENDIF
dwStart := 1
dwPos := 0
DO WHILE TRUE
IF (dwPos := At3(cDelimiter, cList, dwPos)) > 0
AAdd(aRet, AllTrim(SubStr3(cList, dwStart, dwPos-dwStart)))
dwStart := dwPos + dwLen
ELSE
AAdd(aRet, AllTrim(SubStr2(cList, dwStart)))
EXIT
ENDIF
ENDDO
RETURN aRet
/// <exclude />
FUNCTION __UUDecodeMail (cPath AS STRING, cFile AS STRING, cMail AS STRING) AS DWORD STRICT
LOCAL nPos AS DWORD
LOCAL nStop AS DWORD
LOCAL nRet AS DWORD
LOCAL hfOut AS PTR
IF SLen(cMail) = 0
RETURN 0
ENDIF
nPos := __CheckUUEncode(cMail)
IF nPos = 0
RETURN 0
ENDIF
nPos += SLen(UUE_START_EMAIL)
nStop := At3(CRLF, cMail, nPos)
IF nStop = 0
RETURN 0
ENDIF
IF SLen(cFile) == 0
cFile := SubStr3(cMail, nPos, nStop - nPos)
ENDIF
cFile := __GoodFileName(cFile)
cFile := __GetFullPath(cPath, cFile)
hfOut := FCreate(cFile)
nPos := nStop + 2
cMail := SubStr2(cMail, nPos)
IF hfOut != F_ERROR
nRet := __DecodeUU(cMail, hfOut)
FClose(hfOut)
ENDIF
RETURN nRet
/// <include file="Internet.xml" path="doc/CharSetFromContentType/*" />
FUNCTION CharSetFromContentType(cContent AS STRING) AS STRING
LOCAL cChars AS STRING
cChars := __GetToken(cContent, TEMP_CHARSET, ";", TRUE)
cChars := StrTran (cChars, e"\"") // added this line KB 20-5-2010 because sometimes the charset is between quotes
IF cChars == NULL_STRING
cChars := CHARSET_ISO1
ENDIF
RETURN cChars
/// <include file="Internet.xml" path="doc/CheckHostIP/*" />
FUNCTION CheckHostIP(cHost AS STRING) AS STRING STRICT
//
// Takes a IP or address string and returns IP string
//
LOCAL dwPos AS DWORD
LOCAL cRet AS STRING
dwPos := At2(".", cHost)
IF dwPos > 0 .AND. Val( Left(cHost, dwPos-1) ) > 0
cRet := cHost
ELSE
cRet := GetIPAddress(cHost)
ENDIF
RETURN cRet
//GLOBAL csWSA IS _WINRTL_CRITICAL_SECTION
/// <include file="Internet.xml" path="doc/DecodeMailTimeStamp/*" />
FUNCTION DecodeMailTimeStamp(cDate AS STRING, dDate REF DATE, cTime REF STRING) AS LOGIC STRICT
LOCAL aMonth AS ARRAY
LOCAL cTemp AS STRING
LOCAL dwPos AS DWORD
LOCAL dwDay AS DWORD
LOCAL dwMonth AS DWORD
LOCAL dwYear AS DWORD
IF SLen(cDate) = 0
RETURN FALSE
ENDIF
aMonth := {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}
IF (dwPos := At2(", ", cDate)) = 0
dwPos := 1
ELSE
dwPos += 1
cDate := SubStr2(cDate, dwPos)
ENDIF
cDate := AllTrim(cDate)
IF(dwPos := At2(" ", cDate)) = 0
RETURN FALSE
ENDIF
cTemp := SubStr3(cDate, 1, dwPos - 1)
cDate := SubStr2(cDate, dwPos + 1)
dwDay := Val(cTemp)
IF (dwPos := At2(" ", cDate)) = 0
RETURN FALSE
ENDIF
cTemp := SubStr3(cDate, 1, dwPos - 1)
cDate := SubStr2(cDate, dwPos + 1)
cTemp := StrTran(cTemp, " ", "")
IF (dwMonth := AScan(aMonth, cTemp)) = 0
RETURN FALSE
ENDIF
IF (dwPos := At2(" ", cDate)) = 0
RETURN FALSE
ENDIF
cTemp := SubStr3(cDate, 1, dwPos - 1)
cDate := SubStr2(cDate, dwPos + 1)
dwYear := Val(cTemp)
dDate := ConDate(dwYear, dwMonth, dwDay)
IF (dwPos := At2(" ", cDate)) = 0
RETURN FALSE
ENDIF
cTemp := SubStr3(cDate, 1, dwPos - 1)
cTime := StrTran(cTemp, " ", "")
RETURN SLen(cTime) = 8
/// <include file="Internet.xml" path="doc/GetHostByIP/*" />
FUNCTION GetHostByIP(cAddr AS STRING) AS STRING STRICT
//
// Takes a IP string and returns a address string
//
LOCAL IPAddr AS STRING
LOCAL i,i1,j AS DWORD
LOCAL cRet AS STRING
LOCAL DIM bAddr[4] AS BYTE
LOCAL pHostEnt AS _WInHostEnt
IPAddr := AllTrim(cAddr) + "."
i:= At2(".", IPAddr)
IF (i != 0)
bAddr[1] := Val(Left(IPAddr, i-1))
FOR j := 2 TO 4
i1 := At3(".", IPAddr, i+1)
IF (i == 0)
RETURN("")
ENDIF
bAddr[j] := Val(SubStr(IPAddr, i+1, i1-i-1))
i := i1
NEXT
ELSE
RETURN("")
ENDIF
pHostEnt := gethostbyaddr(@bAddr[1], 4, PF_INET)
IF (pHostEnt != NULL_PTR)
cRet := Psz2String(pHostEnt:h_name)
ELSE
cRet := ""
ENDIF
RETURN(cRet)
/// <include file="Internet.xml" path="doc/GetIPAddress/*" />
FUNCTION GetIPAddress(cHost AS STRING) AS STRING STRICT
LOCAL cRet AS STRING
LOCAL pHostEnt AS _WInHostEnt
LOCAL inaddr IS _winin_addr
LOCAL pDword AS DWORD PTR
IF SLen(cHost) > 0
IF (pHostEnt := gethostbyname(String2Psz(cHost))) != NULL_PTR
// h_addr_list is a CHAR PTR PTR and must be deferenced twice
// to get the 4 bytes of the IP Address
pDword := pHostEnt:h_addr_list
pDword := PTR(_CAST, pDword[1])
inaddr:s_un:s_addr := pDword[1]
cRet := Psz2String(inet_ntoa(Inaddr))
ENDIF
ENDIF
RETURN cRet
FUNCTION GetMailTimeStamp(lForceUK AS LOGIC) AS STRING STRICT
LOCAL cRet AS STRING
LOCAL d AS DATE
LOCAL cTime AS STRING
LOCAL nTmp AS DWORD
// Changed to use hardcoded DOW and MOY strings
// in stead of switching the Nation DLLs
d := Today()
IF lForceUK
nTmp := DoW(d)
cRet := SubStr("SunMonTueWedThuFriSat",(3u*nTmp)-2,3)
ELSE
cRet := SubStr3( CDoW(d), 1, 3)
ENDIF
cRet += ", "
cRet += StrZero(Day(d), 2, 0)
cRet += " "
IF lForceUk
nTmp := Month(d)
cRet += SubStr("JanFebMarAprMayJunJulAugSepOctNovDec",(3u*nTmp)-2,3)
ELSE
cRet += AllTrim(SubStr(CMonth(d),1,3))
ENDIF
cRet += " "
cRet += AllTrim(Str(Year(d)))
cTime := Time()
cRet := cRet + " " + cTime + __GetTimeZoneDiff() //" +0100"
RETURN cRet
/// <include file="Internet.xml" path="doc/GetUseNetMsgID/*" />
FUNCTION GetUseNetMsgID(cUnique AS STRING, cDomain AS STRING) AS STRING STRICT
LOCAL cRet AS STRING
LOCAL cHost AS STRING
LOCAL d AS DATE
LOCAL nTemp,i,n AS DWORD
LOCAL pHostEnt AS _WInHostEnt
cHost := HostName()
IF SLen(cHost) > 0
pHostEnt := gethostbyname(String2Psz(cHost))
IF pHostEnt != NULL_PTR
cHost := Psz2String(pHostEnt:h_name)
ENDIF
ENDIF
IF SLen(cUnique) = 0
d := Today()
cUnique := NTrim(Month(d))
cUnique += NTrim(Day(d))
cUnique += NTrim(GetTickCount())
ENDIF
n := SLen(cDomain)
IF n = 0
cDomain := cHost
ELSE
FOR i := 1 TO n
nTemp += Asc(SubStr(cDomain, i, 1))
NEXT
cUnique := NTrim(nTemp) + cUnique
ENDIF
cRet := "<" + cUnique + "@" + cDomain + ">"
RETURN cRet
/// <include file="Internet.xml" path="doc/HostName/*" />
FUNCTION HostName() AS STRING STRICT
LOCAL cRet AS STRING
LOCAL pBuffer AS PSZ
pBuffer := MemAlloc(260)
IF pBuffer != NULL_PSZ
IF gethostname(pBuffer, 260) = 0
cRet := Psz2String(pBuffer)
ENDIF
MemFree(pBuffer)
ENDIF
RETURN cRet
/// <include file="Internet.xml" path="doc/IFXFtpFindFirstFile/*" />
FUNCTION IFXFtpFindFirstFile(hConnect AS PTR,;
lpszFile AS PSZ,;
lpfd AS _WINWIN32_FIND_DATA, ;
dwFlags AS DWORD, ;
dwContext AS DWORD ) AS PTR STRICT
LOCAL hFind AS PTR
hFind := FtpFindFirstFile (hConnect, lpszFile, lpfd, dwFlags, dwContext)
IF hFind != NULL_PTR
__FixDate(@lpfd:ftLastWriteTime)
ENDIF
RETURN hFind
INTERNAL FUNCTION IFXGetTimeDiff(pstRemote AS _WINSYSTEMTIME, pstLocal AS _WINSYSTEMTIME) AS INT STRICT
LOCAL nMinute AS INT
LOCAL nHours AS INT
LOCAL nDays AS INT
LOCAL nRet AS INT
IF pstRemote:wDay == pstLocal:wDay
nHours := INT( pstRemote:wHour) - INT(pstLocal:wHour )
nMinute := INT(pstRemote:wMinute) - INT(pstLocal:wMinute)
nRet := nHours * 60 + nMinute
ELSE
IF pstRemote:wDay > pstLocal:wDay
IF pstLocal:wDay == 1
//
// Changed to next month
//
nDays := -1
ELSE
nDays := 1
ENDIF
ELSE
IF pstRemote:wDay == 1
//
// Changed to next month
//
nDays := 1
ELSE
nDays := -1
ENDIF
ENDIF
nHours := INT(pstRemote:wHour) - INT(pstLocal:wHour)
nMinute := INT(pstRemote:wMinute) - INT(pstLocal:wMinute)
nRet := (nDays * 60 * 24) + nHours * 60 + nMinute
ENDIF
RETURN nRet
/// <include file="Internet.xml" path="doc/IFXInternetFindNextFile/*" />
FUNCTION IFXInternetFindNextFile(hFind AS PTR, lpfd AS _WINWIN32_FIND_DATA) AS LOGIC STRICT