Re: Checking from an external file?

Philip Rhoades via Courier-maildrop <[email protected]> Sun, 18 May 2025 17:40:10 +1000
Newsgroups gmane.mail.maildrop
Message-ID <[email protected]>
Milan,

Thanks so much for responding - see inline comments:


On 2025-05-18 16:29, Milan Obuch wrote:
> On Sun, 18 May 2025 10:50:33 +1000
> Philip Rhoades via Courier-maildrop
> <[email protected]> wrote:
> 
>> People,
>> 
>> Part of my .mailfilter looks like this:
>> 
>> # .spam ^Subject: Uppper {{{3
>> if ( /^Subject:  INQ /:h \
>>      || /^Subject:  \(/:h \
>>      || /^Subject: (Top|Luxury) Watches/:h \
>>      || /^Subject: 180/:h \
>>      || /^Subject: 4mJ/:h \
>>      || /^Subject: =?UTF/:h \
>>      || /^Subject: ? eat this.../:h \
>>      || /^Subject: \*\*/:h \
>>      || /^Subject: \.You/:h \
>>      || /^Subject: \[CONFINDENTIAL\]/:h \
>>      || /^Subject: \[Mayo Clinic Research\]/:h \
>>      || /^Subject: A .*(reverse|Daily).*(payment|Sprinkle)/:h \
>>      || /^Subject: Action Required/:h \
>>      || /^Subject: ACH/:h \
>>      || /^Subject: ACTIVEZ/:h \
>> 
>> etc.
>> 
>> Is it possible to have a separate file with all the lines in so that
>> section of .mailfilter could be reduced to something like:
>> 
>> # .spam ^Subject: Uppper {{{3
>> if ( /^Subject:  "/home/phr/Maildir/spam_upper.txt" /:h )
>> 
>> ?
>> 
> 
> Why not?
> 
> I am doing something similar with List-Id header, simplified version
> here:


I will have a closer look at this code to understand it better but see 
below.


>   if (/^List-Id: *(.*)/)
>    {ListId = $MATCH1
>     if ($ListId =~ /.*\<(.*)\>/)
>      ListId = $MATCH1
>     if (gdbmopen('.list.db','R'))
>      echo 'gdbmopen error R1'
>     else
>      {MAILDIR = gdbmfetch($ListId)
>       gdbmclose
>       if ($MAILDIR)
>        {exception {to "$HOME/Maildir/$MAILDIR/"
>                   }
>        }
>      }
>    }


I think I get the idea but I might need to experiment with a test user 
to properly understand it.


> File .list.db contains mappings from mailing list header to maildir
> folder, it is created from .list text file, containing List-Id and
> maildir folder name delimited by spaces/tabs, which, for this list, is
> 
> courier-maildrop.lists.sourceforge.net 
> .Software.Courier.courier-maildrop


Right.


> This file is converted into .list.db with following code:
> 
>    {if (gdbmopen('.list.db','N'))
>      echo 'gdbmopen error N1'
>     else
>      {foreach (`cat $HOME/.list`) =~ /\S+\s+\S+/
>        {$MATCH =~ /(\S+)\s+(\S+)/;
>         if (gdbmstore($MATCH1,$MATCH2))
>          echo "gdbm $MATCH1 => $MATCH2 problem!"
>        }
>       gdbmclose
>      }
>    }


Right.


> (yes, in maildrop - it is triggered when .list file is changed)


Right - I am a bit anxious about a db - I guess I preferred just text 
files for simplicity etc but this might work . .


> I have 101 lines in my .list file, so while its handling looks somewhat
> complex, it is simpler to maintain long-term... and when I created
> this, I was willing to spend some time to learn things and automatize
> mail processing when possible.


Yes, I am too - however one reason for looking into this idea was 
because when I added 2,534 lines to my .mailfilter file, I got a core 
dump . . even with verbose = 5 I can't see why . . I thought looking up 
a separate file might help sort out problems.


> Also, this maildrop recipe could be made global, so you could customise
> your filtering experience per maildir/user, just by creating .list file
> in your home directory.


Nice!

P.
-- 
Philip Rhoades

PO Box 896
Cowra  NSW  2794
Australia
E-mail:  [email protected]