mysticbbs/mystic/mutil_echoexport.pas

335 lines
8.8 KiB
ObjectPascal
Raw Normal View History

2013-03-17 03:49:52 -07:00
Unit MUTIL_EchoExport;
{$I M_OPS.PAS}
Interface
Procedure uEchoExport;
Implementation
Uses
DOS,
MKCRAP,
m_Strings,
m_FileIO,
m_DateTime,
mUtil_Common,
mUtil_Status,
2013-03-18 22:48:11 -07:00
mUtil_EchoCore,
2013-03-17 03:49:52 -07:00
bbs_Common,
bbs_MsgBase_ABS,
bbs_MsgBase_JAM,
bbs_MsgBase_Squish;
2013-03-18 22:48:11 -07:00
Procedure AddToFLOQueue (FloName, PacketFN: String);
Var
T : Text;
Str : String;
Begin
FileMode := 66;
2013-03-18 23:24:54 -07:00
log(3, '+', 'flo add: ' + floname + ' ' + packetfn);
2013-03-18 22:48:11 -07:00
Assign (T, FloName);
2013-03-18 23:24:54 -07:00
{$I-} Reset (T); {$I+}
2013-03-18 22:48:11 -07:00
2013-03-18 23:24:54 -07:00
If IoResult <> 0 Then Begin
log(3, '+', 'flo reset failed');
{$I-} ReWrite(T); {$I+}
If IoResult <> 0 Then Begin
log(3, '+', 'unable to rewrite flo');
end;
Reset(T);
end;
2013-03-18 22:48:11 -07:00
While Not Eof(T) Do Begin
ReadLn (T, Str);
If strUpper(Str) = '^' + strUpper(PacketFN) Then Begin
Close (T);
Exit;
End;
End;
log(3, '+', 'flo close and append');
2013-03-18 23:24:54 -07:00
// Close (T);
2013-03-18 22:48:11 -07:00
Append (T);
WriteLn (T, '^' + PacketFN);
Close (T);
End;
2013-03-17 03:49:52 -07:00
Procedure BundleMessages;
Var
F : File;
T : Text;
PH : RecPKTHeader;
DirInfo : SearchRec;
NodeIndex : LongInt;
EchoNode : RecEchoMailNode;
PKTName : String;
BundleName : String;
FLOName : String;
OrigAddr : RecEchoMailAddr;
Begin
FindFirst (TempPath + '*', AnyFile, DirInfo);
While DosError = 0 Do Begin
If DirInfo.Attr AND Directory = 0 Then Begin
NodeIndex := strS2I(JustFileExt(DirInfo.Name));
PKTName := JustFileName(DirInfo.Name) + '.pkt';
GetNodeByIndex(NodeIndex, EchoNode);
FileReName (TempPath + DirInfo.Name, TempPath + PKTName);
Assign (F, TempPath + PKTName);
Reset (F, 1);
BlockRead (F, PH, SizeOf(PH));
Close (F);
OrigAddr.Zone := PH.OrigZone;
OrigAddr.Net := PH.OrigNet;
OrigAddr.Node := PH.OrigNode;
2013-03-18 22:48:11 -07:00
// if echonode.echomail.crash etc change char F in FLO extension
2013-03-17 03:49:52 -07:00
FLOName := bbsConfig.OutboundPath + GetFTNFlowName(EchoNode.Address) + '.flo';
BundleName := bbsConfig.OutboundPath + GetFTNArchiveName(OrigAddr, EchoNode.Address) + '.' + DayString[DayOfWeek(CurDateDos)];
BundleName[Length(BundleName)] := '0';
ExecuteArchive (BundleName, EchoNode.ArcType, TempPath + PKTName, 1);
FileErase (TempPath + PKTName);
2013-03-18 22:48:11 -07:00
AddToFLOQueue (FLOName, BundleName);
2013-03-17 03:49:52 -07:00
End;
FindNext (DirInfo);
End;
FindClose (DirInfo);
End;
Procedure uEchoExport;
Var
2013-03-18 22:48:11 -07:00
TotalEcho : LongInt;
TotalNet : LongInt;
MBaseFile : File of RecMessageBase;
MBase : RecMessageBase;
ExportFile : File of RecEchoMailExport;
ExportIndex : RecEchoMailExport;
EchoNode : RecEchoMailNode;
PKTBase : String;
MsgBase : PMsgBaseABS;
2013-03-17 03:49:52 -07:00
Procedure ExportMessage;
Var
PH : RecPKTHeader;
MH : RecPKTMessageHdr;
DT : DateTime;
Temp : Word;
F : File;
Procedure WriteStr (Str: String; EndChar: Char);
Var
L : Byte;
Begin
L := Length(Str);
Move (Str[1], Str[0], L);
Str[L] := EndChar;
BlockWrite (F, Str[0], L + 1);
End;
Var
2013-03-18 22:48:11 -07:00
TempStr1 : String;
TempStr2 : String;
2013-03-17 03:49:52 -07:00
Begin
2013-03-18 22:48:11 -07:00
If (EchoNode.Address.Zone = MsgBase^.GetOrigAddr.Zone) and
(EchoNode.Address.Net = MsgBase^.GetOrigAddr.Net) and
(EchoNode.Address.Node = MsgBase^.GetOrigAddr.Node) Then Exit;
2013-03-17 03:49:52 -07:00
Log (2, '+', ' Export Msg #' + strI2S(MsgBase^.GetMsgNum) + ' to ' + strAddr2Str(EchoNode.Address));
2013-03-18 22:48:11 -07:00
GetDate (DT.Year, DT.Month, DT.Day, Temp);
GetTime (DT.Hour, DT.Min, DT.Sec, Temp);
If MBase.NetType = 3 Then Begin
TempStr1 := bbsConfig.OutboundPath + GetFTNFlowName(EchoNode.Address) + '.out';
TempStr2 := bbsConfig.OutboundPath + GetFTNFlowName(EchoNode.Address) + '.flo';
// change extensions based on crash etc from echonode
Assign (F, TempStr1);
AddToFloQueue (TempStr2, TempStr1);
2013-03-17 03:49:52 -07:00
2013-03-18 22:48:11 -07:00
Inc (TotalNet);
End Else Begin
Assign (F, TempPath + PKTBase + '.' + strI2S(EchoNode.Index));
Inc (TotalEcho);
End;
2013-03-17 03:49:52 -07:00
If ioReset(F, 1, fmRWDN) Then Begin
2013-03-18 22:48:11 -07:00
ioSeek (F, FileSize(F) - 2); // we want to overwrite packet term chars
2013-03-17 03:49:52 -07:00
End Else Begin
ioReWrite (F, 1, fmRWDN);
FillChar (PH, SizeOf(PH), 0);
PH.OrigNode := bbsConfig.NetAddress[MBase.NetAddr].Node;
PH.DestNode := EchoNode.Address.Node;
PH.Year := DT.Year;
PH.Month := DT.Month;
PH.Day := DT.Day;
PH.Hour := DT.Hour;
PH.Minute := DT.Min;
PH.Second := DT.Sec;
PH.PKTType := 2;
PH.OrigNet := bbsConfig.NetAddress[MBase.NetAddr].Net;
PH.DestNet := EchoNode.Address.Net;
PH.ProdCode := 254; // RESEARCH THIS
PH.OrigZone := bbsConfig.NetAddress[MBase.NetAddr].Zone;
PH.DestZone := EchoNode.Address.Zone;
//Password : Array[1..8] of Char; // RESEARCH THIS
BlockWrite (F, PH, SizeOf(PH));
End;
FillChar (MH, SizeOf(MH), 0);
2013-03-18 22:48:11 -07:00
MH.MsgType := 2;
2013-03-17 03:49:52 -07:00
MH.OrigNode := bbsConfig.NetAddress[MBase.NetAddr].Node;
MH.DestNode := EchoNode.Address.Node;
MH.OrigNet := bbsConfig.NetAddress[MBase.NetAddr].Net;
MH.DestNet := EchoNode.Address.Net;
2013-03-18 22:48:11 -07:00
TempStr1 := FormattedDate(DT, 'DD NNN YY HH:MM:SS') + #0;
Move (TempStr1[1], MH.DateTime[0], 20);
2013-03-17 03:49:52 -07:00
If MsgBase^.IsLocal Then MH.Attribute := MH.Attribute OR pktLocal;
If MsgBase^.IsCrash Then MH.Attribute := MH.Attribute OR pktCrash;
If MsgBase^.IsKillSent Then MH.Attribute := MH.Attribute OR pktKillSent;
If MsgBase^.IsRcvd Then MH.Attribute := MH.Attribute OR pktReceived;
If MsgBase^.IsPriv Then MH.Attribute := MH.Attribute OR pktPrivate;
BlockWrite (F, MH, SizeOf(MH));
WriteStr (MsgBase^.GetTo, #0);
WriteStr (MsgBase^.GetFrom, #0);
WriteStr (MsgBase^.GetSubj, #0);
2013-03-18 22:48:11 -07:00
If MBase.NetType <> 3 Then
WriteStr ('AREA:' + MBase.EchoTag, #13);
2013-03-17 03:49:52 -07:00
WriteStr (#1 + 'INTL ' + strAddr2Str(EchoNode.Address) + ' ' + strAddr2Str(bbsConfig.NetAddress[MBase.NetAddr]), #13);
WriteStr (#1 + 'TID: Mystic BBS ' + mysVersion, #13);
MsgBase^.MsgTxtStartUp;
While Not MsgBase^.EOM Do
WriteStr (MsgBase^.GetString(79), #13);
2013-03-18 22:48:11 -07:00
TempStr1 := 'SEEN-BY: ' + strI2S(bbsConfig.NetAddress[MBase.NetAddr].Net) + '/' + strI2S(bbsConfig.NetAddress[MBase.NetAddr].Node) + ' ';
If bbsConfig.NetAddress[MBase.NetAddr].Net <> EchoNode.Address.Net Then
TempStr1 := TempStr1 + strI2S(EchoNode.Address.Net) + '/';
TempStr1 := TempStr1 + strI2S(EchoNode.Address.Node);
WriteStr (TempStr1, #13);
WriteStr (#1 + 'PATH: ' + strI2S(bbsConfig.NetAddress[MBase.NetAddr].Net) + '/' + strI2S(bbsConfig.NetAddress[MBase.NetAddr].Node), #13);
WriteStr (#0#0, #0);
2013-03-17 03:49:52 -07:00
Close (F);
End;
Begin
2013-03-18 22:48:11 -07:00
TotalEcho := 0;
TotalNet := 0;
PKTBase := GetFTNPKTName;
2013-03-17 03:49:52 -07:00
2013-03-18 22:48:11 -07:00
ProcessName ('Exporting EchoMail', True);
2013-03-17 03:49:52 -07:00
ProcessResult (rWORKING, False);
DirClean (TempPath, '');
If Not DirExists(bbsConfig.OutboundPath) Then Begin
ProcessStatus ('Outbound directory does not exist', True);
ProcessResult (rFATAL, True);
Exit;
End;
2013-03-18 22:48:11 -07:00
Assign (MBaseFile, bbsConfig.DataPath + 'mbases.dat');
2013-03-17 03:49:52 -07:00
If ioReset(MBaseFile, SizeOf(RecMessageBase), fmRWDN) Then Begin
While Not Eof(MBaseFile) Do Begin
Read (MBaseFile, MBase);
BarOne.Update (FilePos(MBaseFile), FileSize(MBaseFile));
If MBase.NetType = 0 Then Continue;
If MBase.EchoTag = '' Then Begin
Log (1, '!', ' WARNING: No TAG for ' + strStripPipe(MBase.Name));
Continue;
End;
ProcessStatus (strStripPipe(MBase.Name), False);
If Not MessageBaseOpen(MsgBase, MBase) Then Continue;
MsgBase^.SeekFirst(1);
While MsgBase^.SeekFound Do Begin
MsgBase^.MsgStartUp;
2013-03-18 22:48:11 -07:00
If {MsgBase^.IsLocal And } Not MsgBase^.IsSent Then Begin
2013-03-17 03:49:52 -07:00
Assign (ExportFile, MBase.Path + MBase.FileName + '.lnk');
If ioReset(ExportFile, SizeOf(RecEchoMailExport), fmRWDN) Then Begin
While Not Eof(ExportFile) Do Begin
Read (ExportFile, ExportIndex);
If GetNodeByIndex(ExportIndex, EchoNode) Then
If EchoNode.Active Then
ExportMessage;
End;
Close (ExportFile);
End;
MsgBase^.SetSent(True);
MsgBase^.ReWriteHdr;
End;
MsgBase^.SeekNext;
End;
MsgBase^.CloseMsgBase;
Dispose (MsgBase, Done);
End;
Close (MBaseFile);
End;
BundleMessages;
2013-03-18 22:48:11 -07:00
ProcessStatus ('Total |15' + strI2S(TotalEcho) + ' |07echo |15' + strI2S(TotalNet) + ' |07net', True);
2013-03-17 03:49:52 -07:00
ProcessResult (rDONE, True);
End;
End.