mysticbbs/mystic/mutil_echoexport.pas

524 lines
15 KiB
ObjectPascal
Raw Normal View History

// ====================================================================
// Mystic BBS Software Copyright 1997-2013 By James Coyle
// ====================================================================
//
// This file is part of Mystic BBS.
//
// Mystic BBS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Mystic BBS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Mystic BBS. If not, see <http://www.gnu.org/licenses/>.
//
// ====================================================================
2013-03-17 03:49:52 -07:00
Unit MUTIL_EchoExport;
{$I M_OPS.PAS}
Interface
Procedure uEchoExport;
Implementation
Uses
DOS,
m_Strings,
m_FileIO,
m_DateTime,
mUtil_Common,
mUtil_Status,
2013-03-18 22:48:11 -07:00
mUtil_EchoCore,
2013-08-29 03:04:20 -07:00
BBS_Records,
BBS_DataBase,
2013-08-29 03:04:20 -07:00
BBS_MsgBase_ABS,
BBS_MsgBase_JAM,
BBS_MsgBase_Squish;
2013-03-17 03:49:52 -07:00
2013-09-06 13:32:58 -07:00
// Adds packet name into a FLO-type file if it does not exist already
2013-03-18 22:48:11 -07:00
Procedure AddToFLOQueue (FloName, PacketFN: String);
Var
T : Text;
Str : String;
Begin
FileMode := 66;
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
{$I-} ReWrite(T); {$I+}
Reset(T);
2013-03-22 20:17:33 -07:00
End;
2013-03-18 22:48:11 -07:00
While Not Eof(T) Do Begin
ReadLn (T, Str);
2013-03-31 22:08:13 -07:00
If (strUpper(Str) = strUpper(PacketFN)) or (strUpper(Copy(Str, 2, 255)) = strUpper(PacketFN)) Then Begin
2013-03-18 22:48:11 -07:00
Close (T);
Exit;
End;
End;
Append (T);
WriteLn (T, '^' + PacketFN);
Close (T);
End;
(*
2013-03-17 03:49:52 -07:00
Procedure BundleMessages;
Var
F : File;
PH : RecPKTHeader;
DirInfo : SearchRec;
NodeIndex : LongInt;
EchoNode : RecEchoMailNode;
PKTName : String;
BundleName : String;
2013-03-31 22:08:13 -07:00
BundlePath : String;
2013-09-27 18:00:25 -07:00
BundleSize : Cardinal;
Temp : String;
2013-03-17 03:49:52 -07:00
FLOName : String;
OrigAddr : RecEchoMailAddr;
2013-10-03 18:37:13 -07:00
CheckInc : Boolean;
2013-03-17 03:49:52 -07:00
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-31 22:08:13 -07:00
BundlePath := GetFTNOutPath(EchoNode);
2013-10-03 18:37:13 -07:00
CheckInc := False;
2013-03-31 22:08:13 -07:00
DirCreate (BundlePath);
2013-10-03 18:37:13 -07:00
If Not (EchoNode.LPKTPtr in [48..57, 97..122]) Then
EchoNode.LPKTPtr := 48;
2013-09-29 17:25:56 -07:00
2013-10-03 18:37:13 -07:00
If EchoNode.LPKTDay <> DayOfWeek(CurDateDos) Then Begin
EchoNode.LPKTDay := DayOfWeek(CurDateDos);
EchoNode.LPKTPtr := 48;
End Else
CheckInc := True;
2013-09-24 01:40:46 -07:00
2013-10-03 18:37:13 -07:00
FLOName := BundlePath + GetFTNFlowName(EchoNode.Address);
BundleName := BundlePath + GetFTNArchiveName(OrigAddr, EchoNode.Address) + '.' + Copy(strLower(DayString[DayOfWeek(CurDateDos)]), 1, 2) + Char(EchoNode.LPKTPtr);
2013-09-27 18:00:25 -07:00
2013-10-03 18:37:13 -07:00
If CheckInc And Not FileExist(BundleName) Then Begin
BundleName := GetFTNBundleExt(True, BundleName);
2013-09-27 18:00:25 -07:00
2013-10-03 18:37:13 -07:00
EchoNode.LPKTPtr := Byte(BundleName[Length(BundleName)]);
End;
2013-09-27 18:00:25 -07:00
2013-10-03 18:37:13 -07:00
SaveEchoMailNode(EchoNode);
2013-09-24 01:40:46 -07:00
2013-03-31 22:08:13 -07:00
Case EchoNode.MailType of
0 : FLOName := FLOName + '.flo';
1 : FLOName := FLOName + '.clo';
2 : FLOName := FLOName + '.dlo';
2013-09-06 13:32:58 -07:00
3 : FLOName := FLOName + '.hlo';
2013-03-31 22:08:13 -07:00
End;
2013-03-17 03:49:52 -07:00
ExecuteArchive (TempPath, BundleName, EchoNode.ArcType, TempPath + PKTName, 1);
FileErase (TempPath + PKTName);
AddToFLOQueue (FLOName, BundleName);
2013-03-17 03:49:52 -07:00
End;
FindNext (DirInfo);
End;
FindClose (DirInfo);
End;
*)
Procedure BundleMessages;
Var
F : File;
PH : RecPKTHeader;
DirInfo : SearchRec;
NodeIndex : LongInt;
EchoNode : RecEchoMailNode;
PKTName : String;
BundleName : String;
BundlePath : String;
BundleSize : Cardinal;
Temp : String;
FLOName : String;
OrigAddr : RecEchoMailAddr;
CheckInc : Boolean;
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;
BundlePath := GetFTNOutPath(EchoNode);
FLOName := BundlePath + GetFTNFlowName(EchoNode.Address);
CheckInc := False;
DirCreate (BundlePath);
Case EchoNode.MailType of
0 : FLOName := FLOName + '.flo';
1 : FLOName := FLOName + '.clo';
2 : FLOName := FLOName + '.dlo';
3 : FLOName := FLOName + '.hlo';
End;
If EchoNode.ArcType = '' Then Begin
FileReName (TempPath + PKTName, BundlePath + PKTName);
AddToFLOQueue (FLOName, BundlePath + PKTName);
End Else Begin
If Not (EchoNode.LPKTPtr in [48..57, 97..122]) Then
EchoNode.LPKTPtr := 48;
If EchoNode.LPKTDay <> DayOfWeek(CurDateDos) Then Begin
EchoNode.LPKTDay := DayOfWeek(CurDateDos);
EchoNode.LPKTPtr := 48;
End Else
CheckInc := True;
BundleName := BundlePath + GetFTNArchiveName(OrigAddr, EchoNode.Address) + '.' + Copy(strLower(DayString[DayOfWeek(CurDateDos)]), 1, 2) + Char(EchoNode.LPKTPtr);
If CheckInc And Not FileExist(BundleName) Then Begin
BundleName := GetFTNBundleExt(True, BundleName);
EchoNode.LPKTPtr := Byte(BundleName[Length(BundleName)]);
End;
SaveEchoMailNode(EchoNode);
ExecuteArchive (TempPath, BundleName, EchoNode.ArcType, TempPath + PKTName, 1);
FileErase (TempPath + PKTName);
AddToFLOQueue (FLOName, BundleName);
End;
End;
FindNext (DirInfo);
End;
FindClose (DirInfo);
End;
2013-03-17 03:49:52 -07:00
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-31 22:08:13 -07:00
TempStr3 : String;
2013-03-17 03:49:52 -07:00
Begin
2013-04-19 23:26:51 -07:00
// if msg originated from this echomail address then do not export
2013-05-06 17:07:39 -07:00
If (EchoNode.Address.Zone = MsgBase^.GetOrigAddr.Zone) and
(EchoNode.Address.Net = MsgBase^.GetOrigAddr.Net) and
(EchoNode.Address.Node = MsgBase^.GetOrigAddr.Node) and
(EchoNode.Address.Point = MsgBase^.GetOrigAddr.Point) Then Exit;
2013-03-17 03:49:52 -07:00
2013-09-21 09:53:04 -07:00
// if netmail is TO someone on this system do not export
If MBase.NetType = 3 Then
If IsValidAKA(MsgBase^.GetDestAddr.Zone, MsgBase^.GetDestAddr.Net, MsgBase^.GetDestAddr.Node, MsgBase^.GetDestAddr.Point) Then
2013-09-21 09:53:04 -07:00
Exit;
2013-09-29 17:25:56 -07:00
Log (2, '+', ' Export #' + strI2S(MsgBase^.GetMsgNum) + ' to ' + Addr2Str(EchoNode.Address));
2013-03-17 03:49:52 -07:00
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
2013-03-31 22:08:13 -07:00
TempStr3 := GetFTNOutPath(EchoNode);
DirCreate (TempStr3);
2013-03-18 22:48:11 -07:00
2013-03-31 22:08:13 -07:00
TempStr1 := TempStr3 + GetFTNFlowName(EchoNode.Address);
TempStr2 := TempStr3 + GetFTNFlowName(EchoNode.Address);
Case EchoNode.MailType of
1 : Begin
TempStr1 := TempStr1 + '.cut';
TempStr2 := TempStr2 + '.clo';
End;
2 : Begin
TempStr1 := TempStr1 + '.dut';
TempStr2 := TempStr2 + '.dlo';
End;
3 : Begin
TempStr1 := TempStr1 + '.hut';
TempStr2 := TempStr2 + '.hlo';
End;
Else
TempStr1 := TempStr1 + '.out';
TempStr2 := TempStr2 + '.flo';
End;
2013-03-18 22:48:11 -07:00
Assign (F, TempStr1);
2013-04-27 17:02:29 -07:00
// 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.OrigZone := MsgBase^.GetOrigAddr.Zone;
PH.OrigNet := MsgBase^.GetOrigAddr.Net;
PH.OrigNode := MsgBase^.GetOrigAddr.Node;
PH.OrigPoint := MsgBase^.GetOrigAddr.Point;
PH.DestZone := EchoNode.Address.Zone;
PH.DestNet := EchoNode.Address.Net;
PH.DestNode := EchoNode.Address.Node;
PH.DestPoint := EchoNode.Address.Point;
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.ProdCode := 254;
// Map current V2 values to V2+ values
PH.ProdCode2 := PH.ProdCode;
PH.OrigZone2 := PH.OrigZone;
PH.DestZone2 := PH.DestZone;
PH.Compat := $0000000000000001;
2013-03-17 03:49:52 -07:00
BlockWrite (F, PH, SizeOf(PH));
End;
FillChar (MH, SizeOf(MH), 0);
2013-09-17 23:16:08 -07:00
MH.MsgType := 2;
If MBase.NetType = 3 Then Begin
MH.DestNode := MsgBase^.GetDestAddr.Node;
MH.DestNet := MsgBase^.GetDestAddr.Net;
End Else Begin
MH.DestNode := EchoNode.Address.Node;
MH.DestNet := EchoNode.Address.Net;
End;
2013-03-31 22:08:13 -07:00
MH.OrigNode := MsgBase^.GetOrigAddr.Node;
MH.OrigNet := MsgBase^.GetOrigAddr.Net;
2013-09-27 18:00:25 -07:00
2013-05-25 10:56:32 -07:00
TempStr1 := FormatDate(DT, 'DD NNN YY HH:II:SS') + #0;
2013-03-18 22:48:11 -07:00
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
2013-09-21 09:53:04 -07:00
If MBase.NetType = 3 Then Begin
2013-09-29 17:25:56 -07:00
WriteStr (#1 + 'INTL ' + Addr2Str(MsgBase^.GetDestAddr) + ' ' + Addr2Str(MsgBase^.GetOrigAddr), #13);
2013-09-21 09:53:04 -07:00
End;
2013-03-22 20:17:33 -07:00
2013-05-06 17:07:39 -07:00
WriteStr (#1 + 'TID: ' + mysSoftwareID + ' ' + mysVersion, #13);
2013-03-17 03:49:52 -07:00
MsgBase^.MsgTxtStartUp;
While Not MsgBase^.EOM Do
WriteStr (MsgBase^.GetString(79), #13);
2013-09-18 13:41:07 -07:00
If MBase.NetType <> 3 Then Begin
// SEEN-BY needs to include yourself and ANYTHING it is sent to (downlinks)
// so we need to cycle through nodes for this mbase and add ALL of them
2013-03-22 20:17:33 -07:00
2013-09-18 13:41:07 -07:00
TempStr1 := 'SEEN-BY: ' + strI2S(MsgBase^.GetOrigAddr.Net) + '/' + strI2S(MsgBase^.GetOrigAddr.Node) + ' ';
2013-03-18 22:48:11 -07:00
2013-09-18 13:41:07 -07:00
If MsgBase^.GetOrigAddr.Net <> EchoNode.Address.Net Then
TempStr1 := TempStr1 + strI2S(EchoNode.Address.Net) + '/';
2013-03-18 22:48:11 -07:00
2013-09-18 13:41:07 -07:00
TempStr1 := TempStr1 + strI2S(EchoNode.Address.Node);
2013-03-18 22:48:11 -07:00
2013-09-18 13:41:07 -07:00
WriteStr (TempStr1, #13);
WriteStr (#1 + 'PATH: ' + strI2S(MsgBase^.GetOrigAddr.Net) + '/' + strI2S(MsgBase^.GetOrigAddr.Node), #13);
2013-09-29 17:25:56 -07:00
End;// Else
// WriteStr (#1 + 'Via ' + Addr2Str(MsgBase^.GetOrigAddr) + ' @' + FormatDate(CurDateDT, 'YYYYMMDD.HHIISS') + '.UTC ' + mysSoftwareID + ' ' + mysVersion, #13);
2013-03-17 03:49:52 -07:00
2013-09-20 07:21:35 -07:00
WriteStr (#0#0, #0);
Close (F);
2013-03-17 03:49:52 -07:00
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(bbsCfg.OutboundPath) Then Begin
2013-03-17 03:49:52 -07:00
ProcessStatus ('Outbound directory does not exist', True);
ProcessResult (rFATAL, True);
Exit;
End;
Assign (MBaseFile, bbsCfg.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-22 20:17:33 -07:00
// uncomment islocal if/when we build downlinks on import instead
// of export
2013-03-18 22:48:11 -07:00
If {MsgBase^.IsLocal And } Not MsgBase^.IsSent Then Begin
2013-04-06 20:58:41 -07:00
Log (3, '!', ' Found msg for export');
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);
2013-03-31 22:08:13 -07:00
If MBase.NetType = 3 Then Begin
2013-04-19 23:26:51 -07:00
If GetNodeByRoute(MsgBase^.GetDestAddr, EchoNode) Then
If EchoNode.Active Then Begin
2013-03-31 22:08:13 -07:00
ExportMessage;
2013-04-19 23:26:51 -07:00
Break;
End;
2013-03-31 22:08:13 -07:00
End Else
2013-03-17 03:49:52 -07:00
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);
2013-09-12 14:57:03 -07:00
FileErase (bbsCfg.SemaPath + fn_SemFileEchoOut);
2013-03-17 03:49:52 -07:00
End;
2013-09-18 13:41:07 -07:00
End.