procmail
[Top] [All Lists]

avoiding a lot of duplicate code

1997-09-25 09:12:58
I'm in the process of making a first-pass at hooking up scorring to my
spamcheck.rc file and I'm finding that there is a lot of code that I'm
duplicating.  Any time I start to duplicate something I start to
wonder if there is a better way.

Here's an overview of what I'm doing:

SPAMCHECK_10=214748365 # 10% of procmail's internal max weight
#...
SPAMCHECK_75=1610612738 # 3/4
SPAMCHECK_80=1717986920
SPAMCHECK_90=1932735285
SPAMCHECK_100=2147483647

spamcheck_score=0       # no opinion

SPAMCHECK_INVMESSAGEID_SCORE=${SPAMCHECK_INVMESSAGEID_SCORE:-${SPAMCHECK_90}}
spamcheck_contribution=${SPAMCHECK_INVMESSAGID_SCORE}
spamcheck_reason="INVMESSAGEID - Invalid Message-Id"
:0
* ! ^Message-Id:[       ]*<[^   <>@]+(_at_)[^   <>@]+>[         ]*$
* $${spamcheck_score}^0
* $${spamcheck_contribution}^0
{
  spamcheck_score=$=
  spamcheck_is_spam=yes
  :0fwh
  | formail -A "X-SpamCheck-Reason: $spamcheck_reason (s=$spamcheck_score 
c=$spamcheck_contribution)"
}

# ... lots more ...

SPAMCHECK_FREE_SCORE=${SPAMCHECK_FREE_SCORE:-${SPAMCHECK_80}}
spamcheck_contribution=${SPAMCHECK_FREE_SCORE}
spamcheck_reason="FREE - Text FREE detected"
:0BD
* H ?? !^(In-Reply-To:|References:|Subject:[    ]*Re(\[[0-9]+\])?:).+
* ^[^>]*FREE
* $${spamcheck_score}^0
* $${spamcheck_contribution}^0
{
  spamcheck_score=$=
  spamcheck_is_spam=yes
  :0fwh
  | formail -A "X-SpamCheck-Reason: $spamcheck_reason (s=$spamcheck_score 
c=$spamcheck_contribution)"
}

SPAMCHECK_THRESHHOLD=${SPAMCHECK_THRESHHOLD:-${SPAMCHECK_75}}

:0
* $-${SPAMCHECK_THRESHHOLD}^0
* $${spamcheck_score}^0
{
   # do SPAM processing
}

# ...and record that the message passed through here
:0fwh
| formail -A"X-SpamCheck: Dan's SPAM Detector" \
          -A"X-SpamCheck-Version: 0.3" \
          -A"X-SpamCheck-Score: $spamcheck_score"


I'd like to avoid duplicating as much of 
   * $${spamcheck_score}^0
   * $${spamcheck_contribution}^0
   {
     spamcheck_score=$=
     spamcheck_is_spam=yes
     :0fwh
     | formail -A "X-SpamCheck-Reason: $spamcheck_reason (s=$spamcheck_score 
c=$spamcheck_contribution)"
   }
as is possible.  I think I can put everything between {}s in it's own
.rc file which would result in { INCLUDERC=spamcheck-reason.rc }, but
it would be nice to avoid that if possible.

And I just realized that I need to reverse the order of 
   * $${spamcheck_score}^0
   * $${spamcheck_contribution}^0
if I want non-SPAM evidence to reduce an accumulated score that is
already at it's maximum, correct?

Thanks,
   Dan
------------------- message is author's opinion only ------------------
J. Daniel Smith <DanS(_at_)bristol(_dot_)com>        
http://www.bristol.com/~DanS
Bristol Technology B.V.                   +31 33 450 50 50, ...51 (FAX)
Amersfoort, The Netherlands               {info,jobs}(_at_)bristol(_dot_)com

<Prev in Thread] Current Thread [Next in Thread>
  • avoiding a lot of duplicate code, J. Daniel Smith <=