GenerateOwnMID
From 40tude Dialog Wiki
Introduction
This OnBeforeSending-script generates a Message-ID for outgoing postings containing the current date and time, the shortened name of newsgroup[s] you post to and a counter. Using this script, your MIDs will look like <070405.114702.dcs4-d.2.dlg@news.nicohaase.de>.
Important: You have to set your own FQDN to use this script. It does not work with the option "Dialog generates Message-ID" without having set the "Generate from"-field.
To avoid dupes, you can set uniqueLevel to 0, 1 or 2 - description see below.
For the latest version of GOM, you need a DLL-file which provides some features like generating the random element of the MID. This DLL-file is available at [1]. This file must be saved in the root of your Dialog-installation.
If you use another script that could need the correct MID (like Cancel-Lock), you should call SetMID ( message ) as the first function which changes the posting.
Install & setup the script
Please note that this script is an include-file!. You have to copy the following script inside a new custom script (for example "generateOwnMID") and safe it. Please don't compile this custom script! After that you have to add the following lines to your OnBeforeSending-Script:
{$I generateOwnMID.ds}
and
result := result and SetMID ( Message, isEmail );
This may look like this:
program OnBeforeSendingMessage;
{$I generateOwnMID.ds}
function OnBeforeSendingMessage(var Message: TStringlist; Servername: string; IsEmail: boolean):boolean;
begin
result:=true;
result := result and SetMID( Message, isEmail );
//possibly some other calls to scripts
end;
begin
end.
Just compile this OnBeforeSending-Script now to get your include-file to work. The setup of the script is shown inside the script. Please take a look at this to customize the script to your own fits. Please note that whenever you reconfigure the GenerateOwnMID custom script, you have to recompile the OnBeforeSending-Script to apply the changes.
The Include-File
Please be sure that this is the only content in the include-file!
procedure GOM_initMID ( var DialogOrdner : string;
var checkFQDN : boolean;
var uniqueLevel : integer
);
begin
DialogOrdner := 'c:\programme\40tude dialog\';
// enter the folder you stored dialog to here
checkFQDN := true;
// check the FQDN the Message-ID is generated of
// do NOT change this if you don't know why! there are some FQDNs
// that should not be used. these are checked in the script
// and a new MID is not generated if you use one of these FQDNs.
// setting this to "false" can generate errors from your newsserver
// if you try to send a posting with a MID that has already been used!
uniqueLevel := 0;
// Set how unique your MID should be. If you use the same
// FQDN at more than one computer, MID-duplicates
// *could* appear.
// Levels:
// 0
// MID will contain date, group-initials and counter
// 1
// MID will also contain the actual time
// 2
// MID will also contain a random number
end;
function GOM_MessageBox( hWnd : Cardinal; lpText, lpCaption : PChar; uType : longword ) : Integer;
external 'MessageBoxA@user32.dll stdcall';
function GOM_split(fText: String;fSep: Char):TStringList; external 'split@dExt.dll';
function GOM_random (max : integer ) : integer; external 'randomNumber@dExt.dll';
procedure GOM_dateicheck ( dateiname: string ); external 'legeDateiAn@dExt.dll';
function GOM_CutGenerations ( NGName : String; Trenner : String ) : PChar; external 'CutGenerations@dExt.dll';
function GOM_checkOwnFQDN ( fqdn : string; checkFQDN : boolean ) : boolean;
begin
result := true;
if ( checkFQDN ) then
begin
if ( pos ( '.arcor-online.net', fqdn ) = 1) then result := false;
if ( fqdn = '40tude.net' ) then result := false;
end;
if ( not ( result ) ) then
begin
GOM_messagebox ( 0, 'Wichtig: Die Message-ID wird nicht geändert! Dazu musst du einen anderen FQDN einstellen; mit dem derzeitigen FQDN '
+ fqdn + ' sind Duplikate nicht ausgeschlossen!', 'Message-ID wird nicht verändert', 0 );
end;
end;
function SetMID ( var Message: TStringList; isEmail: boolean ) : boolean;
var zaehler : integer;
empfaengerGruppe : string;
neueMIDgruppen : string;
alteMID : string;
alteMIDlist : TStringList;
neueMIDfqdn : string;
neueMID : string;
FileStringList : TStringList;
checkFQDN : boolean;
DialogOrdner : string;
uniqueLevel : integer;
begin
GOM_initMID ( DialogOrdner, checkFQDN, uniqueLevel );
if (DirectoryExists(DialogOrdner) = false) then
begin
GOM_MessageBox(0, 'Der Ordner ' + DialogOrdner + ' existiert nicht! Bitte änder die Verzeichniseinstellung '
+ 'im Script (Kompilieren des OnBeforeSendingMessage-Scriptes nicht vergessen!) oder leg den Ordner an, damit '
+ 'GenerateOwnMID richtig arbeiten kann. Diese Nachricht wird in der Outbox gespeichert und kann nach Behebung '
+ 'des Fehlers problemlos versandt werden.', 'Fehler in GenerateOwnMID: Ordner existiert nicht', 0);
Result := false;
end
else
begin
if ( isEmail ) then neueMIDgruppen := 'mail'
else
begin
for zaehler := 0 to Message.count - 1 do
begin
if pos('Newsgroups:', Message.strings[zaehler]) = 1 then
begin
empfaengerGruppe := Message.strings[zaehler];
empfaengerGruppe := trim ( Copy ( empfaengergruppe, Length ( 'Newsgroups: ' ), Length ( empfaengergruppe ) ) );
neueMIDgruppen := GOM_CutGenerations ( empfaengerGruppe, '' );
// GOM_CutGenerations ( empfaengerGruppe, '', tempRueck );
break;
end;
end;
end;
GOM_dateicheck ( DialogOrdner + 'midcounter.ini' );
FileStringList := TStringList.create;
FileStringList.LoadFromFile(DialogOrdner + 'midcounter.ini');
for zaehler := 0 to Message.count - 1 do
begin
if pos('Message-ID:', Message.strings[zaehler]) = 1 then
begin
alteMID := Message.strings[zaehler];
alteMID := Copy( alteMID, 12, Length(alteMID) - 11 );
alteMIDlist := GOM_split ( alteMID, '@' );
neueMIDfqdn := Copy( alteMIDlist.strings[1], 1, Length ( alteMIDlist.strings[1] ) - 1 );
if ( not ( GOM_checkOwnFQDN ( neueMIDfqdn, checkFQDN ) ) ) then break;
if ( FileStringList.Values[neueMIDgruppen] = '' ) then
begin
FileStringList.Add (neueMIDgruppen + '=0' );
end;
FileStringList.Values[neueMIDgruppen] := inttostr ( strtoint ( FileStringList.Values[neueMIDgruppen] ) + 1 );
neueMID := '<' + FormatDateTime('ddmmYY', DATE);
if ( uniqueLevel >= 1 ) then neueMID := neueMID + '.' + FormatDateTime('hhnnss', TIME);
neueMID := neueMID + '.' + neueMIDgruppen + '.' + FileStringList.Values[neueMIDgruppen];
if ( uniqueLevel = 2 ) then neueMID := neueMID + '.' + inttostr ( GOM_random ( 99 ) + 1 );
neueMID := neueMID + '.dlg@' + neueMIDfqdn + '>';
Message.strings[zaehler] := 'Message-ID: ' + neueMID;
break;
end;
end;
FileStringList.SaveToFile(DialogOrdner + 'midcounter.ini');
result := true;
end;
end;
(C) Nico Haase 2005