🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #261516

Re: Ping Bernd Rose: How do you set and define a variable in 40Tude Dialog

#261516
From: Stijn De Jong
Date: Mon, 02 Jan 2017 01:49
224 lines
8282 bytes
Op Sun, 1 Jan 2017 21:01:12 +0100, Bernd Rose schreef:

> Program Test;
> var sTest:string;
> Begin
>  sTest:='XXX';
>  sTest:='YYY';
>  WriteLn(sTest);
> End.
> 
> Will print 'YYY'. (As expected.)

Thanks Bernd for the syntax help in setting variables in 40tude language.

That snipped works just fine standalone:
http://i.imgsafe.org/99dc6c0dbe.jpg

Program setRemoveHeadersString;
var Remove_Headers:string;
Begin
  Remove_Headers := 'X-Scoring: ,X-Hamster-Info: ';
  Remove_Headers := 'X-Scoring: ';
  WriteLn(Remove_Headers);
 End.

Integrating the snippet into the OnBeforeSendingMessage utility is the task
at hand, where an integration requires insertion into the if/then/else.

I spent a few hours more and finally gave up as my conclusion is that the
syntax is just too daunting for a novice to overcome without prior
knowledge of (probably quite a few) programming languages.

I paste below where I gave up so that others may pick up if they like from
where I left off. What I pasted is syntactically correct. There are no
errors. But it doesn't work either. So it ends up doing absolutely nothing.

To explain the confusingly long script below, it's simply these two scripts
put together:
1. Determine Identity (either work or personal):
   http://dialog.datalist.org/scripts/CheckingIdentity.html
2. Remove Headers:
   http://dialog.datalist.org/scripts/RemoveHeaders.html

The goal was simply to meld the two above so that the headers change
depending on the identity (either work or personal).
--------------- cut here -------------
// The goal is different headers for work use versus for personal use.
// This script has no syntax errors.
// Modify the following values to fit your setup
// 1. Remove_Headers (one for work and one for personal)
// 2. Identity (one for work and one for personal)
// 3. Newsgroups (work newsgroups can be different than personal ones)
// 4. Servers (work servers can be different than personal servers)
//
program OnBeforeSendingMessage;

var Remove_Headers:string;
Begin
  // These are just default values.
  // The real values are set in an if-then-else statement later.
  Remove_Headers := 'X-Scoring: ,X-Hamster-Info: ';
  Remove_Headers := 'X-Scoring: ';
  WriteLn(Remove_Headers);
 End.  
    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(var Remove_Headers TStringlist; from: String;):
String;
begin   
  if (StrMatch(from, 'First1 Last1 <email1@example.com>')) then
    result := 'id1'   
    Remove_Headers='User-Agent: ,Message-ID: '
  else if (StrMatch(from, 'First2 Last2 <email2@example.com>')) then
    result := 'id2' 
    Remove_Headers='Message-ID: ,Mime-Version: '
  else
    result := 'unknow'; 
WriteLn(Remove_Headers);
end;

function NewsGroup2Identity(newsgroup: String): String;
begin
  if (StrMatch(newsgroup, 'news.software.readers') or
      StrMatch(newsgroup, 'alt.os.linux')) then
    result := 'id1'
  else
    result := 'id2';
end;    
// The server identity doesn't seem to play any role in the decisions
though...
function Server2Identity(server: String): String;
begin
  if (CompareStr(server, 'aioe_119') = 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);
    WriteToLog('  fromIdentity = ' + fromIdentity, 7);
    WriteToLog('  newsgroupIdentity = ' + newsgroupIdentity, 7);
    WriteToLog('  serverIdentity = ' + serverIdentity, 7); 
    WriteToLog('  Remove_Headers = ' + Remove_Headers,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:    
  RemoveHeaders(Message,IsEmail);   
  WriteLn(Remove_Headers);
  result := CheckIdentity(message, servername, isEmail);
  result:=true;
end;
// ----------------------------------------------------------------------
begin
end.
--------------- cut here -------------
Technical Details
Message-ID: <o4cbjs$4pc$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
References: <o4bg7v$t51$1@gioia.aioe.org> <1xmerwn6hkw2o.dlg@b.rose.tmpbox.news.arcor.de>

Show Full Headers
Complete Article Headers
Message-ID: <o4cbjs$4pc$1@gioia.aioe.org>
Subject: Re: Ping Bernd Rose: How do you set and define a variable in 40Tude Dialog
Date: Mon, 2 Jan 2017 02:49:30 +0100
From: Stijn De Jong <stijndekoning@nlnet.nl>
References: <o4bg7v$t51$1@gioia.aioe.org> <1xmerwn6hkw2o.dlg@b.rose.tmpbox.news.arcor.de>
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.os.linux
Organization: Aioe.org NNTP Server
Lines: 224
NNTP-Posting-Host: uO0akXCexOOsyLm/h0ChCQ.user.gioia.aioe.org
X-Complaints-To: abuse@aioe.org
X-Notice: Filtered by postfilter v. 0.8.2
X-Received-Body-CRC: 2302869254
X-Received-Bytes: 8224