Across-the-board rename so the unit prefix matches the repo
name (mb = msgbase). Brings naming into line with
fpc-ftn-transport's tt.* prefix and avoids the historical
"ma" abbreviation that meant nothing to new readers.
Files renamed via git mv:
src/ma.{api,events,kludge,lock,paths,types}.pas
-> src/mb.{...}.pas
src/formats/ma.fmt.{jam,squish,hudson,msg,pcboard,ezycom,
goldbase,wildcat,wcutil}{,.uni}.pas
-> src/formats/mb.fmt.*.pas
All `unit ma.X` declarations and `uses ma.X` clauses rewritten
to `mb.X` across src/, examples/, tests/.
Suite: 47/47 (read 7, hwm 11, lock 4, pack 4, write 5,
wildcat 5, consumer_round1 5, batch's gone w/ PKT relocation,
plus testutil).
Consumer impact: anyone with `uses ma.api;` etc. needs to
update to `uses mb.api;`. No semantic changes; a search/replace
on the consumer's source tree is the only migration step.
NR's notes (~/.MSGAPI_MSGS.md round 3) align this against
their already-pinned 8130b40; the next NR pin bump rolls in
both this rename and any further work in one step.
105 lines
2.7 KiB
ObjectPascal
105 lines
2.7 KiB
ObjectPascal
{
|
|
example_write.pas - post one test message to any supported base
|
|
via the unified API.
|
|
|
|
usage: example_write <format> <path> <from> <to> <subject> <body>
|
|
|
|
Example:
|
|
example_write jam /tmp/testarea Sysop All Hello 'Hello, world'
|
|
|
|
For Hudson/GoldBase/MSG the path is a directory; for JAM/Squish
|
|
it is <dir>/<areaname> (no extension); for PKT it is the full
|
|
*.pkt filename; for EzyCom it is the base directory and board 1
|
|
is used by default.
|
|
}
|
|
|
|
program example_write;
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
uses
|
|
SysUtils,
|
|
mb.types, mb.events, mb.api,
|
|
mb.fmt.hudson, mb.fmt.hudson.uni,
|
|
mb.fmt.jam, mb.fmt.jam.uni,
|
|
mb.fmt.squish, mb.fmt.squish.uni,
|
|
mb.fmt.msg, mb.fmt.msg.uni,
|
|
mb.fmt.pcboard, mb.fmt.pcboard.uni,
|
|
mb.fmt.ezycom, mb.fmt.ezycom.uni,
|
|
mb.fmt.goldbase, mb.fmt.goldbase.uni;
|
|
|
|
function ParseFormat(const S: string; out AFormat: TMsgBaseFormat): boolean;
|
|
begin
|
|
Result := True;
|
|
case LowerCase(S) of
|
|
'hudson': AFormat := mbfHudson;
|
|
'jam': AFormat := mbfJam;
|
|
'squish': AFormat := mbfSquish;
|
|
'msg': AFormat := mbfMsg;
|
|
'pcboard': AFormat := mbfPCBoard;
|
|
'ezycom': AFormat := mbfEzyCom;
|
|
'goldbase': AFormat := mbfGoldBase;
|
|
else
|
|
Result := False;
|
|
end;
|
|
end;
|
|
|
|
procedure Usage;
|
|
begin
|
|
WriteLn('Usage: example_write <format> <path> <from> <to> <subject> <body>');
|
|
WriteLn(' formats: hudson jam squish msg pcboard ezycom goldbase');
|
|
Halt(2);
|
|
end;
|
|
|
|
var
|
|
fmtName, path, whoFrom, whoTo, subject, body: string;
|
|
fmt: TMsgBaseFormat;
|
|
base: TMessageBase;
|
|
msg: TUniMessage;
|
|
begin
|
|
if ParamCount < 6 then Usage;
|
|
fmtName := ParamStr(1);
|
|
path := ParamStr(2);
|
|
whoFrom := ParamStr(3);
|
|
whoTo := ParamStr(4);
|
|
subject := ParamStr(5);
|
|
body := ParamStr(6);
|
|
|
|
if not ParseFormat(fmtName, fmt) then Usage;
|
|
|
|
try
|
|
base := MessageBaseOpen(fmt, path, momReadWrite);
|
|
except
|
|
on E: Exception do begin
|
|
WriteLn('error: ', E.Message);
|
|
Halt(1);
|
|
end;
|
|
end;
|
|
|
|
if not base.Open then begin
|
|
WriteLn('error: Open returned False (missing files? lock busy?)');
|
|
base.Free;
|
|
Halt(1);
|
|
end;
|
|
|
|
msg.Attributes.Clear;
|
|
msg.Attributes.SetValue('from', whoFrom);
|
|
msg.Attributes.SetValue('to', whoTo);
|
|
msg.Attributes.SetValue('subject', subject);
|
|
msg.Attributes.SetDate('date.written', Now);
|
|
msg.Attributes.SetBool('attr.local', true);
|
|
msg.Attributes.SetAddr('addr.orig', MakeFTNAddress(1, 1, 1, 0));
|
|
msg.Attributes.SetAddr('addr.dest', MakeFTNAddress(1, 1, 2, 0));
|
|
msg.Body := body + #13;
|
|
|
|
try
|
|
if base.WriteMessage(msg) then
|
|
WriteLn('wrote message #', msg.Attributes.GetInt('msg.num'))
|
|
else
|
|
WriteLn('error: WriteMessage returned False');
|
|
finally
|
|
base.Close;
|
|
base.Free;
|
|
end;
|
|
end.
|