🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #262893

Re: 40tude find & replace 4 characters before sending message!!!!!!

#262893
From: VanguardLH
Date: Mon, 10 Sep 2018 22:01
112 lines
6352 bytes
Bernd Rose wrote:

> VanguardLH wrote:
> 
>>> The following is what I use for the OnBeforeSavingMessage event.  Just
>>> use it for clues on how to walk through lines in the body of the
>>> message.
>>> 
>>> //Remove PGP signature from newsgroup messages
>>> 
>>> program OnBeforeSavingMessage;
>>> const pgp_sig_start='
>> 
>> Hmm, not sure why my post got truncated. 
> 
> For all people except you, it didn't. ;-)  Your /inbound/ PGP removal 
> searches for a string which happens to be inside your script. Because
> the script doesn't check position of the string inside the line, it
> deletes starting from "pgp_sig_start" declaration. (Plus 1 line back.)
> Your "broken signature"-check also replaces not only the PGP-Sig, but 
> other occurrences of the PGP-Sig inside the texts, as well... (Cf.:
> "if pos ... > 0" instead of "if pos ... = 1".)

Don't remember if I got this script from the Datalist script library for
Dialog or from elsewhere.  I didn't write it.

Seems the script is wrong, as you pointed out.  It finds the first line
*containing* "-----BEGIN PGP SIGNED" as a /substring/.  It should check
that substring starts at column 1.  I thought the PGP sig block was
always at the end of the message, so just delete everything from and
after the "-----BEGIN PGP SIGNATURE----" line.

Examples:
http://www.heavensgate.com/misc/bg2pgp.txt
https://philzimmermann.com/text/PGP_10thAnniversary.txt

Those have a PGP message block delimiter line as the first line in the
message and starting at column 1.  Seems I only need to check if the
first line's entire string is the PGP message block delimiter line, not
by having to check all the lines in the message.  

One example doesn't have a following "Hash: <type>" line, so I should
delete it only if a prior delete got rid of the PGP message block
delimiter line.

Looking for the pgp_sig_start substring anywhere within message.text
also seems wrong.  That will look for the substring anywhere in the
message, not for it to start in column 1 and not only after the PGP
message block delimiter line.  I don't know if the delete() string
command can be modified to look for the position of a concatenation of
EOL + pgp_sig_start (or, if EOL isn't recorded at the end of strings
then maybe NUL + pgp_sig_start if strings are NUL terminated).  That
position + 1 (one character after the EOL or NUL) would mark the string
position where the PGP sig block started.

https://www.rossde.com/PGP/pgp_signatures.html

That shows the "-----BEGIN PGP SIGNED MESSAGE-----" delimiter line is
always in line 1 (starting in column 1) and the PGP sig block is always
at the end of the message.  

I'm assuming in Delphi that message.strings[] is an array of strings
(don't know if terminated by EOL or NUL) where each string is a line in
the message with an index value starting at 0 (not 1).  Seems the whole
"delete PGP sig" function should be conditional on first finding the PGP
message block delimiter line, and that every line from and after the
starting PGP sig delimiter can get deleted.  Maybe the following works:

// Check if line 0 starts a PGP message block.
if message.strings(0) = '-----BEGIN PGP SIGNED MESSAGE-----' then 
  begin
    // Delete PGP message block delimiter line.
    message.delete(0);
    // Replace with a comment that PGP sig was removed.
    message.insert(0, '*****PGP SIGNATURE REMOVED*****');  // Optional.
    // If present as the next line, delete the Hash specifier.
    if message.strings(1) = 'Hash: ' then 
      message,delete(1);    
    // Delete the PGP signature block at the end.
    sig_found := 0;
    for i := 1 to message.count - 1 do
      begin
        if message.strings(i) = '-----BEGIN PGP SIGNATURE-----' then
          sig_found := 1;
        // If sig start delimiter line found, delete it and the rest.
        if sig_found then message.delete(i);
          end;
      end;
  end;

The 'if' checks if the first line is the PGP message block delimiter
line; else, there's no point in checking if the next line is a Hash line
and also no point looking for a PGP sig block.  Everything rests on
finding that required delimiter line that delineates the start of the
PGP message block.  

The for-loop checks for if and when the PGP sig block starts.  While I
could've added another for-loop inside that for-loop to do the deletes,
I didn't see much impact in retesting each further line.  I could
possibly short-circuit the 'if' by doing a boolean AND between the
string (line) value and sig_found assuming Pascal/Delphi supports short
circuiting of Boolean operators (e.g., FALSE AND ..., don't need to test
anything beyond FALSE since the entire Boolean will be FALSE).

If there can be mixed content where the PGP message block starts later
in the message (not in the first line) then I'll have to use the
for-loop to walk through lines in the message.  If there can be
non-signed content after the PGP sig block, yeah, then I have to find
the length of just the sig block and delete just those lines.

I don't do Delphi, so I've probably made mistakes.  I haven't touched
Pascal for over 40 years and that was before it got objectified.
Technical Details
Message-ID: <182ueh96l574y$.dlg@v.nguard.lh>
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: <pn1qed$28a6$1@adenine.netfront.net> <1537aq73i3hah.dlg@v.nguard.lh> <pn241i$bot$1@adenine.netfront.net> <1cnxz2t8qh6sh.dlg@v.nguard.lh> <vlqix6ao91mv$.dlg@v.nguard.lh> <ocdihblxtfe$.dlg@b.rose.tmpbox.news.arcor.de>

Show Full Headers
Complete Article Headers
Message-ID: <182ueh96l574y$.dlg@v.nguard.lh>
Subject: Re: 40tude find & replace 4 characters before sending message!!!!!!
Date: Mon, 10 Sep 2018 17:01:17 -0500
From: VanguardLH <V@nguard.LH>
References: <pn1qed$28a6$1@adenine.netfront.net> <1537aq73i3hah.dlg@v.nguard.lh> <pn241i$bot$1@adenine.netfront.net> <1cnxz2t8qh6sh.dlg@v.nguard.lh> <vlqix6ao91mv$.dlg@v.nguard.lh> <ocdihblxtfe$.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
Organization: Usenet Elder
Lines: 112
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Trace: individual.net 1Xxh/tycl8mC4dW6UUigagnV1gAUvE/LWvI7+KJD3mc+xaiWsU
Keywords: VanguardLH VLH811
Cancel-Lock: sha1:YLwO33kG01bekVQRWsUoge2ysU8=
User-Agent: 40tude_Dialog/2.0.15.41
X-Received-Bytes: 6241
X-Received-Body-CRC: 3873420216