mysticbbs/mystic/mutil_echoimport.pas

443 lines
13 KiB
ObjectPascal
Raw Normal View History

2013-03-22 20:18:14 -07:00
Unit MUTIL_EchoImport;
{$I M_OPS.PAS}
Interface
Procedure uEchoImport;
Implementation
Uses
DOS,
2013-09-17 19:28:47 -07:00
Classes,
2013-03-22 20:18:14 -07:00
m_FileIO,
m_Strings,
2013-09-17 19:28:47 -07:00
m_DateTime,
2013-04-12 21:57:02 -07:00
AView,
2013-08-29 03:04:20 -07:00
BBS_Records,
BBS_DataBase,
2013-03-22 20:18:14 -07:00
BBS_MsgBase_ABS,
BBS_MsgBase_JAM,
BBS_MsgBase_Squish,
mUtil_Common,
mUtil_Status,
2013-05-23 17:45:01 -07:00
mUtil_EchoCore,
mUtil_EchoFix;
2013-03-22 20:18:14 -07:00
// Also create SavePKTMsgToFile and change export to use it... and for
// downlinks too
Procedure SavePKTMsgToBase (Var MB: PMsgBaseABS; Var PKT: TPKTReader; Netmail: Boolean);
Var
Count : LongInt;
Begin
MB^.StartNewMsg;
If NetMail Then
MB^.SetMailType (mmtNetMail)
Else
MB^.SetMailType (mmtEchoMail);
MB^.SetLocal (False);
MB^.SetOrig (PKT.Orig);
MB^.SetDest (PKT.Dest);
MB^.SetPriv ((PKT.MsgHDR.Attribute AND pktPrivate <> 0) OR NetMail);
MB^.SetCrash (PKT.MsgHDR.Attribute AND pktCrash <> 0);
MB^.SetRcvd (PKT.MsgHDR.Attribute AND pktReceived <> 0);
//MB^.SetSent (PKT.MsgHDR.Attribute AND pktSent <> 0);
MB^.SetSent (False); // force to send to downlinks?
MB^.SetHold (PKT.MsgHDR.Attribute AND pktHold <> 0);
MB^.SetKillSent (PKT.MsgHDR.Attribute AND pktKillSent <> 0);
MB^.SetFrom (PKT.MsgFrom);
MB^.SetTo (PKT.MsgTo);
MB^.SetSubj (PKT.MsgSubj);
MB^.SetDate (PKT.MsgDate);
MB^.SetTime (PKT.MsgTime);
For Count := 1 to PKT.MsgLines Do Begin
If {strip seenbys and } Copy(PKT.MsgText[Count]^, 1, 9) = 'SEEN-BY: ' Then
Continue;
MB^.DoStringLn(PKT.MsgText[Count]^);
End;
MB^.WriteMsg;
End;
Procedure uEchoImport;
Var
2013-04-19 23:26:51 -07:00
TotalEcho : LongInt;
TotalNet : LongInt;
TotalDupes : LongInt;
DupeIndex : LongInt;
DupeMBase : RecMessageBase;
CreateBases : Boolean;
PKT : TPKTReader;
Dupes : TPKTDupe;
Status : LongInt;
ForwardList : Array[1..50] of String[35];
ForwardSize : Byte = 0;
2013-04-12 21:57:02 -07:00
Procedure ImportPacketFile (PktFN: String);
2013-03-22 20:18:14 -07:00
Var
2013-04-12 21:57:02 -07:00
MsgBase : PMsgBaseABS;
CurTag : String;
MBase : RecMessageBase;
Count : LongInt;
2013-03-22 20:18:14 -07:00
Begin
2013-04-12 21:57:02 -07:00
If Not PKT.Open(PktFN) Then Begin
Log (3, '!', ' ' + JustFile(PktFN) + ' is not valid PKT');
2013-03-22 20:18:14 -07:00
2013-04-12 21:57:02 -07:00
Exit;
End;
2013-03-22 20:18:14 -07:00
2013-04-12 21:57:02 -07:00
If Not IsValidAKA(PKT.Dest.Zone, PKT.Dest.Net, PKT.Dest.Node) Then Begin
Log (3, '!', ' ' + JustFile(PktFN) + ' does not match an AKA');
2013-03-22 20:18:14 -07:00
2013-04-12 21:57:02 -07:00
PKT.Close;
2013-03-22 20:18:14 -07:00
2013-04-12 21:57:02 -07:00
Exit;
End;
2013-03-22 20:18:14 -07:00
2013-04-12 21:57:02 -07:00
ProcessStatus ('Importing ' + JustFile(PktFN), False);
2013-03-22 20:18:14 -07:00
2013-04-12 21:57:02 -07:00
BarOne.Reset;
2013-03-22 20:18:14 -07:00
2013-04-12 21:57:02 -07:00
CurTag := '';
MsgBase := NIL;
Status := 20;
2013-03-22 20:18:14 -07:00
2013-04-12 21:57:02 -07:00
While PKT.GetMessage Do Begin
If Status MOD 20 = 0 Then
2013-05-20 02:35:04 -07:00
BarOne.Update (PKT.MsgFile.FilePosRaw, PKT.MsgFile.FileSizeRaw);
2013-03-22 20:18:14 -07:00
2013-04-12 21:57:02 -07:00
Inc (Status);
2013-03-22 20:18:14 -07:00
2013-04-12 21:57:02 -07:00
If PKT.MsgArea = 'NETMAIL' Then Begin
2013-03-22 20:18:14 -07:00
2013-05-23 17:45:01 -07:00
If Not ProcessedByAreaFix(PKT) Then
If GetMBaseByNetZone (PKT.PKTHeader.DestZone, MBase) Then Begin
For Count := 1 to ForwardSize Do
2013-09-19 15:14:39 -07:00
If strUpper(strStripB(strWordGet(1, ForwardList[Count], ';'), ' ')) = strUpper(PKT.MsgTo) Then
PKT.MsgTo := strStripB(strWordGet(2, ForwardList[Count], ';'), ' ');
2013-04-19 23:26:51 -07:00
2013-05-23 17:45:01 -07:00
CurTag := '';
2013-03-22 20:18:14 -07:00
2013-05-23 17:45:01 -07:00
If MsgBase <> NIL Then Begin
MsgBase^.CloseMsgBase;
2013-03-22 20:18:14 -07:00
2013-05-23 17:45:01 -07:00
Dispose (MsgBase, Done);
2013-03-22 20:18:14 -07:00
2013-05-23 17:45:01 -07:00
MsgBase := NIL;
End;
2013-03-22 20:18:14 -07:00
2013-05-23 17:45:01 -07:00
MessageBaseOpen(MsgBase, MBase);
2013-03-22 20:18:14 -07:00
2013-05-23 17:45:01 -07:00
SavePKTMsgToBase(MsgBase, PKT, True);
2013-03-22 20:18:14 -07:00
2013-05-23 17:45:01 -07:00
Log (2, '+', ' Netmail from ' + PKT.MsgFrom + ' to ' + PKT.MsgTo);
2013-03-22 20:18:14 -07:00
2013-05-23 17:45:01 -07:00
Inc (TotalNet);
End Else
Log (3, '!', ' No NETMAIL base for zone ' + strI2S(PKT.PKTHeader.DestZone));
2013-04-12 21:57:02 -07:00
End Else Begin
If Dupes.IsDuplicate(PKT.MsgCRC) Then Begin
Log (3, '!', ' Duplicate message found in ' + PKT.MsgArea);
2013-03-22 20:18:14 -07:00
2013-04-12 21:57:02 -07:00
If DupeIndex <> -1 Then Begin
If (MsgBase <> NIL) and (CurTag <> '-DUPEMSG-') Then Begin
MsgBase^.CloseMsgBase;
2013-03-22 20:18:14 -07:00
2013-04-12 21:57:02 -07:00
Dispose (MsgBase, Done);
2013-03-22 20:18:14 -07:00
2013-04-12 21:57:02 -07:00
MsgBase := NIL;
CurTag := '-DUPEMSG-';
End;
2013-03-22 20:18:14 -07:00
2013-04-12 21:57:02 -07:00
If MsgBase = NIL Then
MessageBaseOpen (MsgBase, DupeMBase);
2013-03-23 08:22:51 -07:00
2013-04-12 21:57:02 -07:00
SavePKTMsgToBase (MsgBase, PKT, False);
End;
2013-03-23 08:22:51 -07:00
2013-04-12 21:57:02 -07:00
Inc (TotalDupes);
End Else Begin
If CurTag <> PKT.MsgArea Then Begin
If Not GetMBaseByTag(PKT.MsgArea, MBase) Then Begin
Log (2, '!', ' Area ' + PKT.MsgArea + ' does not exist');
If Not CreateBases Then Continue;
If FileExist(bbsCfg.MsgsPath + PKT.MsgArea + '.sqd') or
FileExist(bbsCfg.MsgsPath + PKT.MsgArea + '.jhr') Then Continue;
2013-04-12 21:57:02 -07:00
FillChar (MBase, SizeOf(MBase), #0);
MBase.Index := GenerateMBaseIndex;
MBase.Name := PKT.MsgArea;
MBase.QWKName := PKT.MsgArea;
MBase.NewsName := PKT.MsgArea;
MBase.FileName := PKT.MsgArea;
MBase.EchoTag := PKT.MsgArea;
MBase.Path := bbsCfg.MsgsPath;
2013-04-12 21:57:02 -07:00
MBase.NetType := 1;
MBase.ColQuote := bbsCfg.ColorQuote;
MBase.ColText := bbsCfg.ColorText;
MBase.ColTear := bbsCfg.ColorTear;
MBase.ColOrigin := bbsCfg.ColorOrigin;
MBase.ColKludge := bbsCfg.ColorKludge;
MBase.Origin := bbsCfg.Origin;
2013-04-12 21:57:02 -07:00
MBase.BaseType := INI.ReadInteger(Header_ECHOIMPORT, 'base_type', 0);
MBase.ListACS := INI.ReadString (Header_ECHOIMPORT, 'acs_list', '');
MBase.ReadACS := INI.ReadString (Header_ECHOIMPORT, 'acs_read', '');
MBase.PostACS := INI.ReadString (Header_ECHOIMPORT, 'acs_post', '');
MBase.NewsACS := INI.ReadString (Header_ECHOIMPORT, 'acs_news', '');
MBase.SysopACS := INI.ReadString (Header_ECHOIMPORT, 'acs_sysop', 's255');
MBase.Header := INI.ReadString (Header_ECHOIMPORT, 'header', 'msghead');
MBase.RTemplate := INI.ReadString (Header_ECHOIMPORT, 'read_template', 'ansimrd');
MBase.ITemplate := INI.ReadString (Header_ECHOIMPORT, 'index_template', 'ansimlst');
MBase.MaxMsgs := INI.ReadInteger(Header_ECHOIMPORT, 'max_msgs', 500);
MBase.MaxAge := INI.ReadInteger(Header_ECHOIMPORT, 'max_msgs_age', 365);
MBase.DefNScan := INI.ReadInteger(Header_ECHOIMPORT, 'new_scan', 1);
MBase.DefQScan := INI.ReadInteger(Header_ECHOIMPORT, 'qwk_scan', 1);
MBase.NetAddr := 1;
For Count := 1 to 30 Do
If bbsCfg.NetAddress[Count].Zone = PKT.PKTHeader.DestZone Then Begin
2013-04-12 21:57:02 -07:00
MBase.NetAddr := Count;
Break;
End;
2013-03-23 08:22:51 -07:00
2013-04-12 21:57:02 -07:00
If INI.ReadString(Header_ECHOIMPORT, 'use_autosig', '1') = '1' Then
MBase.Flags := MBase.Flags OR MBAutoSigs;
2013-03-22 20:18:14 -07:00
2013-04-12 21:57:02 -07:00
If INI.ReadString(Header_ECHOIMPORT, 'use_realname', '0') = '1' Then
MBase.Flags := MBase.Flags OR MBRealNames;
2013-03-22 20:18:14 -07:00
2013-04-12 21:57:02 -07:00
If INI.ReadString(Header_ECHOIMPORT, 'kill_kludge', '1') = '1' Then
MBase.Flags := MBase.Flags OR MBKillKludge;
2013-03-22 20:18:14 -07:00
2013-04-12 21:57:02 -07:00
// ADD DOWNLINK INFORMATION HERE INTO ECHONODES??
2013-03-22 20:18:14 -07:00
2013-04-12 21:57:02 -07:00
AddMessageBase(MBase);
End;
2013-03-22 20:18:14 -07:00
2013-04-12 21:57:02 -07:00
If MsgBase <> NIL Then Begin
MsgBase^.CloseMsgBase;
2013-03-22 20:18:14 -07:00
2013-04-12 21:57:02 -07:00
Dispose (MsgBase, Done);
2013-03-22 20:18:14 -07:00
2013-04-12 21:57:02 -07:00
MsgBase := NIL;
End;
2013-03-22 20:18:14 -07:00
2013-04-12 21:57:02 -07:00
MessageBaseOpen(MsgBase, MBase);
2013-03-22 20:18:14 -07:00
2013-04-12 21:57:02 -07:00
CurTag := PKT.MsgArea;
2013-03-22 20:18:14 -07:00
End;
2013-04-12 21:57:02 -07:00
SavePKTMsgToBase (MsgBase, PKT, False);
2013-03-22 20:18:14 -07:00
2013-04-12 21:57:02 -07:00
Dupes.AddDuplicate(PKT.MsgCRC);
2013-03-22 20:18:14 -07:00
2013-04-12 21:57:02 -07:00
Inc (TotalEcho);
2013-03-22 20:18:14 -07:00
2013-09-19 15:14:39 -07:00
Log (2, '+', ' Added Msg #' + strI2S(MsgBase^.GetHighMsgNum) + ' to ' + strStripPipe(MBase.Name));
2013-03-22 20:18:14 -07:00
End;
End;
End;
If MsgBase <> NIL Then Begin
MsgBase^.CloseMsgBase;
Dispose (MsgBase, Done);
MsgBase := NIL;
End;
2013-04-12 21:57:02 -07:00
PKT.Close;
2013-03-22 20:18:14 -07:00
2013-04-12 21:57:02 -07:00
FileErase (PktFN);
2013-03-22 20:18:14 -07:00
2013-04-12 21:57:02 -07:00
BarOne.Update (1, 1);
End;
Procedure ImportPacketBundle (PktBundle: String);
Var
PKTMatched : Boolean;
DirInfo : SearchRec;
NodeFile : File of RecEchoMailNode;
EchoNode : RecEchoMailNode;
ArcType : String[4];
2013-09-17 19:28:47 -07:00
Count : LongInt;
BundleList : TStringList;
2013-04-12 21:57:02 -07:00
Begin
PKTMatched := False;
Assign (NodeFile, bbsCfg.DataPath + 'echonode.dat');
2013-04-12 21:57:02 -07:00
If ioReset(NodeFile, Sizeof(RecEchoMailNode), fmRWDN) Then Begin
While Not Eof(NodeFile) Do Begin
Read (NodeFile, EchoNode);
For Count := 1 to 30 Do Begin
If strUpper(JustFileName(PktBundle)) = strUpper(GetFTNArchiveName(EchoNode.Address, bbsCfg.NetAddress[Count])) Then Begin
2013-04-12 21:57:02 -07:00
PKTMatched := True;
ArcType := EchoNode.ArcType;
Break;
End;
End;
End;
Close (NodeFile);
End;
If Not PKTMatched Then Begin
Case GetArchiveType(bbsCfg.InboundPath + PktBundle) of
2013-04-12 21:57:02 -07:00
'A' : ArcType := 'ARJ';
'R' : ArcType := 'RAR';
'Z' : ArcType := 'ZIP';
'L' : ArcType := 'LZH';
Else
Log (2, '!', ' Cannot find arctype for ' + PktBundle + '; skipping');
Exit;
End;
End;
ProcessStatus ('Extracting ' + PktBundle, False);
ExecuteArchive (TempPath, bbsCfg.InboundPath + PktBundle, ArcType, '*', 2);
2013-04-12 21:57:02 -07:00
2013-09-17 19:28:47 -07:00
BundleList := TStringList.Create;
2013-04-12 21:57:02 -07:00
FindFirst (TempPath + '*', AnyFile, DirInfo);
While DosError = 0 Do Begin
If DirInfo.Attr And Directory = 0 Then Begin
2013-09-17 19:28:47 -07:00
If strUpper(JustFileExt(DirInfo.Name)) = 'PKT' Then
BundleList.Add(FormatDate(DateDos2DT(DirInfo.Time), 'YYYYMMDDHHIISS') + ' ' + DirInfo.Name);
2013-04-12 21:57:02 -07:00
End;
FindNext (DirInfo);
End;
FindClose (DirInfo);
2013-09-17 19:28:47 -07:00
BundleList.Sort;
If BundleList.Count = 0 Then
2013-04-12 21:57:02 -07:00
Log (2, '!', ' Unable to extract bundle; skipping')
2013-09-17 19:28:47 -07:00
Else Begin
For Count := 1 to BundleList.Count Do
ImportPacketFile (TempPath + strWordGet(2, BundleList.Strings[Count - 1], ' '));
FileErase (bbsCfg.InboundPath + PktBundle);
2013-09-17 19:28:47 -07:00
End;
BundleList.Free;
2013-03-22 20:18:14 -07:00
End;
Var
2013-09-17 19:28:47 -07:00
DirInfo : SearchRec;
Count : LongInt;
FileExt : String;
PktList : TStringList;
FileName : String;
2013-03-22 20:18:14 -07:00
Begin
TotalEcho := 0;
TotalNet := 0;
TotalDupes := 0;
ProcessName ('Importing EchoMail', True);
ProcessResult (rWORKING, False);
DirClean (TempPath, '');
If Not DirExists(bbsCfg.InboundPath) Then Begin
2013-03-22 20:18:14 -07:00
ProcessStatus ('Inbound directory does not exist', True);
ProcessResult (rFATAL, True);
Exit;
End;
2013-03-23 08:22:51 -07:00
// read INI values
CreateBases := INI.ReadBoolean(Header_ECHOIMPORT, 'auto_create', False);
DupeIndex := INI.ReadInteger(Header_ECHOIMPORT, 'dupe_msg_index', -1);
Count := INI.ReadInteger(Header_ECHOIMPORT, 'dupe_db_size', 32000);
2013-04-19 23:26:51 -07:00
// Read in forward list from INI
FillChar (ForwardList, SizeOf(ForwardList), #0);
Ini.SetSequential(True);
Repeat
FileExt := INI.ReadString(Header_ECHOIMPORT, 'forward', '');
If FileExt = '' Then Break;
Inc (ForwardSize);
2013-09-19 15:14:39 -07:00
ForwardList[ForwardSize] := strStripB(FileExt, ' ');
2013-04-19 23:26:51 -07:00
Until ForwardSize = 50;
INI.SetSequential(False);
Dupes := TPKTDupe.Create(Count);
2013-04-12 21:57:02 -07:00
PKT := TPKTReader.Create;
If DupeIndex <> -1 Then
If Not GetMBaseByIndex (DupeIndex, DupeMBase) Then
DupeIndex := -1;
2013-03-23 08:22:51 -07:00
2013-09-17 19:28:47 -07:00
PktList := TStringList.Create;
FindFirst (bbsCfg.InboundPath + '*', AnyFile, DirInfo);
2013-03-22 20:18:14 -07:00
While DosError = 0 Do Begin
2013-09-17 19:28:47 -07:00
If DirInfo.Attr And Directory = 0 Then
PktList.Add(FormatDate(DateDos2DT(DirInfo.Time), 'YYYYMMDDHHIISS') + ' ' + DirInfo.Name);
2013-03-22 20:18:14 -07:00
FindNext (DirInfo);
End;
FindClose (DirInfo);
2013-09-17 19:28:47 -07:00
PktList.Sort;
For Count := 1 to PktList.Count Do Begin
FileName := strWordGet(2, PktList.Strings[Count - 1], ' ');
FileExt := Copy(strUpper(JustFileExt(FileName)), 1, 2);
If FileExt = 'PK' Then
ImportPacketFile(bbsCfg.InboundPath + FileName)
Else
If (FileExt = 'SU') or
(FileExt = 'MO') or
(FileExt = 'TU') or
(FileExt = 'WE') or
(FileExt = 'TH') or
(FileExt = 'FR') or
(FileExt = 'SA') Then
ImportPacketBundle(FileName)
Else
Log (2, '!', ' Unknown inbound file ' + FileName);
End;
2013-04-12 21:57:02 -07:00
PKT.Free;
Dupes.Free;
2013-09-17 19:28:47 -07:00
PktList.Free;
2013-03-22 20:18:14 -07:00
ProcessStatus ('Total |15' + strI2S(TotalEcho) + ' |07echo |15' + strI2S(TotalNet) + ' |07net |15' + strI2S(TotalDupes) + ' |07dupe', True);
ProcessResult (rDONE, True);
2013-09-12 14:57:03 -07:00
FileErase (bbsCfg.SemaPath + fn_SemFileEchoIn);
2013-09-17 19:28:47 -07:00
End;
2013-03-22 20:18:14 -07:00
2013-04-22 10:38:35 -07:00
End.