🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #264607

Re: Using logical opeartors in Dialog Filters

#264607
From: VanguardLH
Date: Mon, 18 Jan 2021 23:48
210 lines
12299 bytes
Sqwertz <sqwertzme@gmail.invalid> wrote:

> Can somebody remind me how to use logical operators in Dialog
> filters?  Something such as:
> 
> !delete From asshole and message-id assnews.com
> 
> -sw

!delete From {<criteria1>} -@Header:{<header>: <notcriteria2>}
                           +@Header:{<header>: <addcriteria3>}
                           
The +@ means to include matching criteria from another header, and -@
means to exclude matching criteria from another header.  You can use a
header name (or use Header: if not one of the pre-defined ones) to
preface the first conditional.  If you use a pre-defined header name,
add a space between its name and the criteria inside the braces.  For
additional header criteria, you can use the pre-defined header names.
If you're testing on a non-predefined header name, you have to use
+@Header:{^headername: ...}.  That is, it's not a standard overview
header, so you have to use Header and in the criteria specify the header
name.  

From {joker}
+@From:{joker}
+@Header:(^From: joker}


As I was told, the +@ and -@ syntax are taken from the Hamster NNTP
server's syntax.  Alas, you can't use From, Subject, Message-ID, or
other pre-defined header names when using inclusion or exclusion, and
instead have to use +@Header:{headername: criteria}.  You need to not
only use +@ or -@ followed by "Header" (to denote the include/exclude is
looking for a header), but also need to add the colon (and no space)
unlike using the pre-defined headers where you give the name and then a
space character.  The header name and criteria must be enclosed in
braces.  So, for example, you could use +@Header:{^From: ...} instead of
From criteria (where criteria is optionally braced, but I include them
to better delineate the criteria, especially if more headers are added.

To me, I remember +@ as AND and -@ as AND NOT.  To do OR'ing, just
define multiple rules, one for each condition.  Note that Dialog does 2
passes when filtering.  The first pass only exercises those rules that
use the pre-defined headers, like From, Subject, Message-ID, etc.  Any
message in the 1st pass gets flagged.  For any non-flagged messages, it
then runs through its 2nd pass to test on all the other headers.  This
way, it first tests on the overview headers that are always available
when messages are downloaded.  On the 2nd pass, it tests on non-overview
headers on the messages not flagged in the 1st pass.  If you have rules
that test on both overview and non-overview headers, they have to wait
until the 2nd pass.

Overview headers (available when message is downloaded):
  From
  Subject
  Date
  Message-ID
  Newsgroups
  Organization
  Lines
  References
  Xref
  (those returned by sending LIST OVERVIEW.FMT command to server)
Non-overview headers (only available when download complete message):
  Path
  Content-Type
  NNTP-Posting-Host
  X-headers
  User-Agent
  and lots more (anything not an overview header)
  
What constitutes an overview header may not be true across different
NNTP server.  Since I won't know which headers are considered overview
headers by different NNTP servers, I configure Dialog to download the
complete message.  That gives my ALL headers and the body, not just
whatever are the overview headers at a particular server.

For your example:

!delete From {^asshole\s*<} +@Message-ID:{<(\S|_)+@((\S|_)+\.)assnews\.com>$}
or
!delete From {(\W|_)*asshole(\W|_)*<} +@Header:{^Message-ID: <(\S|_)+@((\S|_)+\.)assnews\.com>$}

Dialog provide a regex tester where you can enter the regex string and a
sample string to see if the regex matches.  Unless you are specifying
the header name in the search criteria, don't include it in the test
regex string since you're just testing the regex, not that the string
came from a particular header.

I had to assume the "asshole" string started at column one, and not as a
substring, like "HassleHoleman".  If not, you'll have to figure out how
to delimite the "asshole" substring to prevent false positives.  For
example, if they use asshole, _/asshole/_, or something that can be
delimited by non-word characters around the asshole substring, I'd
probably use "(\W|_)*asshole(\W|_)\s*<" to look for non-word characters
around the "asshole" substring.  I also assumed "asshole" was part of
the poster's name (in the comment field) and not inside the address
field (between the angle brackets); that is, "asshole <tipsy@ddd.com>"
and not "tipsy <asshole@invalid.com>".

The ^ anchors the string identifying the header name (Message-ID) to
column 1 where all headers must start.  Headers are supposed to have one
space to delimit the header name from its value, but I've seen where
more than one space was used hence the use of \s+.  The (\W|_)+ means
means to find one, or more, non-space characters after the mandatory
space delimiter for the header name, after the < character that starts
the MID's value,  and before the @ character (the left token cannot be
blank or missing), and that "assnews.com" was a domain in the right
token of the MID.  The period for .com is escaped (backslashed) to make
sure to match on the period character instead of intrepreted as a
masking character that means any 1 character in that position (which
could be something other than just a period).  The angle brackets are
included because they are included in the MID value.  The $ anchors the
string to the end of the line, so "assnews.com> is at the end, not
somewhere before the end.  Since you don't mention if just the domain is
specified in the right token of the MID value or maybe a hostname is
included, I added the ((\W|_)\.)* to allow [sub]hosts to be included,
like xxx.assnews.com, abc.xxx.assnews.com, or just assnews.com.

The above is off the top of my head.  It's what I remember.  Helps to
know just exactly what is the header(s) and string values on which you
want to define the filters.

The problem when testing on headers, especially when you have to use the
generic +@Header:{...} syntax, is the search doesn't stop at the end of
the physical line.  That's because headers can span multiple physical
lines.  The header line has the header name start in column 1, followed
by a colon and space, and then its value.  The value can continue on
another line by adding a minimum of 1 leading space character.
Specifying the header name just means what to look at starting in column
1, not when the header ends.  The result is the search can continue
looking forward past the matching header, across subsequent headers, and
even into the body of the message.  You won't know what is the next
header to add it to the string to make sure the search stops at the next
header.  Maybe there's a way in regex to stop the search on the first
line it encounters after the matching header line that has a space in
column 1.  The pre-defined headers (From, Subject, etc) seem to know to
look only within a header value even if it spans multiple lines.  The
generic +@Header syntax doesn't know when to stop, only when to start.
As a consequence, I've had +@Header:{header: value} keep searching and
finding the substring of value in the body of the message.

The only way I know of, so far, to limit a header string search is to
specify the (?-s) prefix switch on the criteria string.  That says to
only scan one physical line.  However, that means it won't scan a
multi-line header's value to the 2nd continuation line, or later.

For example, Altopia allows its users to insert whatever they want as
the string for the injection node (identifying from which server a post
originated).  The /rule/ is that those who inject are /supposed/ to
append alt.net to their own string, but they don't force the requirement
by using a scanner to ensure posts submitted to alt.net actually end
with that string in the PATH header.  Because Altopia allows its users
to lie regarding what is the injection node, I don't accept any posts
submitted from there or sent through there (because the user can lie by
making a multi-host inject node string that makes it look like the post
was submitted to a prior server).

Message-ID {<\S+@(\S+\.)?alt\.net>} +@Header:{(?-s)^Path: \S+\balt\.net(!?\.?POSTED)?(!not-for-mail)?$}

That looks for Altopia's server adding its own MID header (only if the
poster's client didn't add one), and if the injection node in the PATH
header shows it came from Altopia, but the (?-s) switch ensures the scan
is only in one physical line.  For this header, I think PATH can only
span one physical line, so the switch may not be necessary.  However,
Dialog can only scan overview headers by default -- unless you configure
it to download complete messages (all headers + body) where all headers
means both overview and non-overview headers; else, Dialog (and other
NNTP clients) can only test on overview headers.

On overview headers, the NNTP clients seem to know they should continue
a search past the matching header line for its continuation lines, and
then stop when the next header (non-blank string starting in column 1
and followed by a colon and space).  For non-overview headers,
especially when having to use +@Header:{...} or -@Header:{...}, Dialog
(and maybe others) don't know to only include continuation lines, and
NOT keep scanning into further headers or into the body.  For a rule of
"From {criteria}", the scan ends at the last continuation line, if any.
For a rule of +@Header:{^From: criteria}, the scan starts at the From
header line, and proceeds through every header thereafter and into the
body of the message; i.e., doesn't know when to stop, and why I have to
something use the (?-s) switch (aka modifier) before the regex criteria.
I don't know of a way to stop the generic header scan when the next (and
unknown) header starts, or the blank line (just a newline) is
encountered that delimits the header and body sections.

Regex is one of those languages that keeps burgeoning every time you
want to learn some more.  When you think you can't do something, someone
more expert chuckles and might show you how.  So far, I've use (?-s) to
just make sure the scan is from the start of the matching header line
(or start of its value string) to the end of the line, and not go
further because it won't stop at the logical end of the header.

As I recall, there used to be a poster named BernD, or similar, that was
far more expert on how Dialog works, including how to write the Pascal
code for the scripting functions.  While I got some scripts from an
online library, and adapted some to my own use, the context or scope of
those scripts is not defined anywhere, so they can use variables that
defined outside the script that you would have no means of discovering
without digging into the Delphi code for the program.  I think it was
him that told me the syntax for Dialog's rules are similar to those the
Hamster server uses.  Its site was a subpage under http://home.arcor.de,
but it's gone, and I don't know if there is an active site for
supporting the Hamster program.  Wikipedia says the home site is at:

http://www.tglsoft.de/freeware_hamster.html

You'll need to run it through Google Translate since the site is written
in the author's native language of German.  I didn't see a link to
documentation for Hamster.  Maybe it's lurking elsewhere.
Technical Details
Message-ID: <ie3bbwuzo6wp.dlg@v.nguard.lh>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!apf1.newsdeef.eu!not-for-mail
References: <lo1iu4iamqxs$.dlg@sqwertz.com>

Show Full Headers
Complete Article Headers
Message-ID: <ie3bbwuzo6wp.dlg@v.nguard.lh>
Subject: Re: Using logical opeartors in Dialog Filters
Date: Mon, 18 Jan 2021 17:48:47 -0600
From: VanguardLH <V@nguard.LH>
References: <lo1iu4iamqxs$.dlg@sqwertz.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!apf1.newsdeef.eu!not-for-mail
Newsgroups: news.software.readers
User-Agent: 40tude_Dialog/2.0.15.41
Mime-Version: 1.0
Lines: 210
Keywords: VanguardLH VLH811
Content-Type: text/plain; charset="us-ascii"
Organization: Usenet Elder
Cancel-Lock: sha1:tNEvjSudxw7KfEmmeiU8CZkeGF0=
Content-Transfer-Encoding: 7bit
X-Trace: individual.net MfvHzzGZiyadwOMa0T+60Aj7T086PnpquIySPqFIKOTlOSwxy/