procmail
[Top] [All Lists]

Re: Need a formula for forwarding and rejecting email from lists

2006-07-09 03:10:46
Bart Schaefer wrote:

The reply to Ruud's post *is* the message he's already deleted.

Guess I couldn't figure that out from the small amount quoted.  I
thought it was from the orig post.

The ISP's code that you quoted, if you quoted it accurately, *is*
wrong; it works only by accident.  So apparently you're getting your
whole $10 per month worth, maybe less; if it were me, I'd expect them
to really break something eventually.

I'll let them know.  But aside from the Procmail issues, they have been
very good for 10 years now and saved me a lot of money compared to
many webhosters.  I'm not so sure they have very good tech support, but
luckily I haven't had to use them much except for setting up SSH.  The
important things to me are UNIX, SSH, FTP, Perl and high
uptime/storage/bandwidth with low cost - I get all of that and more.

However ...

Assuming that the egrep+sed that assign to GOOD and BAD are correct,
you have four problems.  The first is that you don't need the { braces
} in the places where you've put them, so get rid of them.  An
open-brace is only meaningful to procmail if it appears as the first
non-whitespace character of the action line of a recipe.

That's what I get from copying bad code and not fully grasping it.  :(

The second and third are both in this line (and also in the BAD
condition later):

* GOOD ?? ^[a-zA-Z].*$        # trying to test if GOOD has some characters

Second: You can't put a comment on a condition line.  Everything after
the "*" is part of the condition, including the whitespace (unless the
line ends with whitespace followed by a backslash, which is a special
case).

The comment on the line was only for the benefit of the post to let you
know what I was trying to do (not actually on line) - sorry for the
confusion.

Third: Even if you remove the comment, what you're testing is that
GOOD begins with an alphabetic character.  That's not the same as
testing whether it has "some" characters.  Procmail regular
expressions are a subset of perl's (except for the \/ and ^^
operators) and as you claim to know perl, you ought to be able to
figure this one out yourself.  The trailing .*$ can be dropped, you
don't care what the string ends with.

No problem - I just wanted to make sure that the grep found a line.
One character is enough, but I could make a check for an '@' I
suppose - to verify I got an address.

The fourth problem is that a recipe may have exactly one action line.
In the BAD recipe, you are trying to both assign to EXITCODE and also
forward the message, which is *two* actions.  Further, a plain
assignment is not a valid action, so you can't set EXITCODE where you
are attempting to do so.  You need

That's the kind of help I was hoping for (and the below example).  Thanks
immensely.

# Maybe fix the regular expression below
 :0
 * BAD ?? ^[a-zA-Z].*$
 {
    # Brace as the action line begins a block, so now the assignment is OK
    EXITCODE=76
    # Now we need to begin a new recipe to get a new action line.
    # This recipe has no condition lines, the outer recipe took care of that.
    :0
    ! $BAD
    # That's done, so now we can close the block
}

And that's way more help than your attitude deserves.

I'm sorry if you somehow read between the lines and ascribed an attitude
to my post - none was intended.  I spend sometimes hours a day helping
others with Perl issues, so I'm aware of posters with attitude - I was
trying to save myself the time of becoming an expert in Procmail to handle
a hopefully one-time issue.

----------------------------------------

So that leaves me with this which I will give a try (if no more obvious
bugs are present):

GOOD = `egrep -is "^$RECIP" legit.lst | sed -n "s/^$RECIP //i;p"`
BAD = `egrep -is "^$RECIP" bad.lst | sed -n "s/^$RECIP //i;p"`

:0
* GOOD ?? ^[a-zA-Z].*@
! $GOOD

:0
* BAD ?? ^[a-zA-Z].*@
{
    EXITCODE=67
    :0
    ! $BAD
}

----------------------------------------

Well, I had trouble playing with grep/sed, so I did it in Perl instead
and it seems to be working OK.  GOOD and BAD end up with just the
forwarding address from the good and bad files.

GOOD = `/usr/bin/perl checkbad good $RECIP`
BAD = `/usr/bin/perl checkbad bad $RECIP`

:0
* GOOD ?? ^[a-zA-Z].*@
! $GOOD

:0
* BAD ?? ^[a-zA-Z].*@
{
        EXITCODE=67
        :0
        ! $BAD
}

To drop the forwarding on the bad, can I just drop the {} grouping and
just use the EXITCODE=67 (when I feel it's all working well) ?

Thanks again Bart - I really appreciate your time and taking the trouble.



____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail