Article View: news.software.readers
Article #261403Re: Request help with 40tude dialog program syntax
From: Stijn De Jong
Date: Sat, 31 Dec 2016 20:01
Date: Sat, 31 Dec 2016 20:01
183 lines
6862 bytes
6862 bytes
Op Sat, 31 Dec 2016 20:50:46 +0100, Stijn De Jong schreef:
> This is the code I am using which sets the identity.
> http://dialog.datalist.org/scripts/CheckingIdentity.html
>
> This is the code I am using which removes the headers:
> http://dialog.datalist.org/scripts/RemoveHeaders.html
>
> All I'm trying to do is meld the two, where the outgoing headers to be
> removed depend on the identity of the sender.
At the risk of confusing the issue, here is the current code that was used
to send this message, which has no syntax errors, and which sort of works
but which allows only a single static setting for the remove headers
variable.
All I'm trying to do is add the simple decision below:
if identity = id1 then
Remove_Headers='User-Agent: ,Message-ID: ';
else if identity = id2 then
Remove_Headers='User-Agent: ,Content-Transfer-Encoding: ';
else
Remove_Headers='User-Agent: ,Mime-Version: ';
------- cut here for the current working code --------
program OnBeforeSendingMessage;
RemoveFromEmails = true;
RemoveFromNews = true;
procedure RemoveHeaders ( Message : TStringlist;
IsEmail : boolean
);
var i : integer;
k : integer;
s : string;
CommaPos : integer;
DelHeader : TStringlist;
RemoveH : String;
begin
RemoveH := Remove_Headers;
i := 0;
if ((IsEmail=true) and (RemoveFromEmails=true)) or
((IsEmail=false) and (RemoveFromNews=true)) then begin
If ( RemoveH <> '' ) then begin
try
DelHeader := TStringlist.Create;
if ansipos ( ',', RemoveH) = 0 then begin
DelHeader.Add ( LowerCase ( TrimLeft( RemoveH )));
end // if
else begin
CommaPos := 0;
for k := 1 to length ( RemoveH ) do begin
If RemoveH[k] = ',' then begin
DelHeader.Add ( LowerCase ( TrimLeft (copy ( RemoveH,
CommaPos + 1, k - ( CommaPos + 1 )))));
CommaPos := k;
end; // if
if k = length ( RemoveH ) then
DelHeader.Add ( LowerCase ( TrimLeft (copy ( RemoveH,
CommaPos + 1, k - CommaPos ))));
end; // for
end; // else
s:=Message.text;
while (Message.Strings[i]<>'') do begin
k := 0;
while k <= ( DelHeader.Count - 1 ) do begin
if pos( DelHeader[k], LowerCase ( Message.Strings[i] )) = 1
then begin
delete ( s, pos(DelHeader[k], LowerCase (s) ), length (
Message.Strings[i] ) + 2 );
i := i - 1;
k := DelHeader.Count - 1;
message.text := s;
end; // if
k := k + 1;
end; // while
i := i + 1;
end; //while
message.text:=s;
finally
DelHeader.Free;
end; // try - finally
end; // if
end; // if
end; // RemoveHeaders
function StrMatch(str: String; pattern: String):Boolean;
var
patternSize : Integer;
subStr : String;
compareRes : Integer;
begin
patternSize := Length(pattern);
subStr := Copy(str, 1, patternSize);
compareRes := CompareStr(pattern, subStr);
if (compareRes = 0) then
result := true
else
result := false;
end;
function From2Identity(from: String): String;
begin
if (StrMatch(from, 'First1 Last1 <email1@domain.com>')) then
result := 'id1'
else if (StrMatch(from, 'First2 Last2 <email2@domain.com>')) then
result := 'id2'
else
result := 'unknown';
end;
function NewsGroup2Identity(newsgroup: String): String;
begin
if (StrMatch(newsgroup, 'news.software.readers') or
StrMatch(newsgroup, 'alt.free.newsservers')) then
result := 'id1'
else
result := 'id2';
end;
// The server identity doesn't seem to play any role in the decision.
// So I'm not sure why this is needed (but it's required).
function Server2Identity(server: String): String;
begin
if (CompareStr(server, 'aioe') = 0) then
result := 'id1'
else
result := 'id2';
end;
function BadIdentity(): boolean;
begin
result := false;
end;
function CheckIdentity(var message: TStringlist; servername: string;
isEmail: boolean):boolean;
var
fromIdentity : String;
newsgroupIdentity : String;
serverIdentity : String;
i : Integer;
begin
if (not IsEmail) then
begin
for i := 0 to Message.Count - 1 do
begin
if (strMatch(Message[i], 'From:')) then
fromIdentity := Copy(Message[i], 7, Length(Message[i]) - 6);
if (strMatch(Message[i], 'Newsgroups:')) then
newsgroupIdentity := Copy(Message[i], 13, Length(Message[i]) - 12);
end;
fromIdentity := From2Identity(fromIdentity);
newsgroupIdentity := NewsGroup2Identity(newsgroupIdentity);
serverIdentity := Server2Identity(servername);
// The lines below write to the log file ./40tude/logs/20161231.log
WriteToLog(' fromIdentity = ' + fromIdentity, 7);
WriteToLog(' newsgroupIdentity = ' + newsgroupIdentity, 7);
WriteToLog(' serverIdentity = ' + serverIdentity, 7);
if ((CompareStr(fromIdentity, newsgroupIdentity) = 0) and
(CompareStr(newsgroupIdentity, serverIdentity) = 0)) then
result := true
else
result := BadIdentity();
end
else
result := true;
end;
function OnBeforeSendingMessage(var Message : TStringlist;
Servername : string;
IsEmail : boolean
):boolean;
begin
// Added the result line below:
result := CheckIdentity(message, servername, isEmail);
RemoveHeaders(Message,IsEmail);
result:=true;
end;
// ----------------------------------------------------------------------
begin
end.
------- cut here for the current working code --------
Technical Details
Message-ID:
<o492qg$a9k$1@gioia.aioe.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.(126883).mbox.7z!not-for-mailReferences:
<o491jh$7jr$1@gioia.aioe.org> <o4926s$933$1@gioia.aioe.org>Show Full Headers
Complete Article Headers
Message-ID: <o492qg$a9k$1@gioia.aioe.org> Subject: Re: Request help with 40tude dialog program syntax Date: Sat, 31 Dec 2016 21:01:15 +0100 From: Stijn De Jong <stijndekoning@nlnet.nl> References: <o491jh$7jr$1@gioia.aioe.org> <o4926s$933$1@gioia.aioe.org> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.(126883).mbox.7z!not-for-mail Newsgroups: news.software.readers,alt.windows7.general Organization: Aioe.org NNTP Server Lines: 183 NNTP-Posting-Host: L2rGmi1oKYWfLo4MQZsu9Q.user.gioia.aioe.org X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.2 X-Received-Body-CRC: 3635926785 X-Received-Bytes: 6796