1Please read the README file in this directory first.
2.ex
3.Id $Id: procmailsc.man,v 1.15 2001/08/04 06:08:22 guenther Exp $
4.TH PROCMAILSC 5 \*(Dt BuGless
5.na
6.SH NAME
7procmailsc \- procmail weighted scoring technique
8.SH SYNOPSIS
9.RB [ * ]
10.B "w^x condition"
11.ad
12.SH DESCRIPTION
13In addition to the traditional true or false conditions you can specify
14on a recipe, you can use a weighted scoring technique to decide if
15a certain recipe matches or not.  When weighted scoring is used in a
16recipe, then the final score for that recipe must be positive for it
17to match.
18
19A certain condition can contribute to the score if you allocate it
20a `weight'
21.RB ( w )
22and an `exponent'
23.RB ( x ).
24You do this by preceding the condition (on the same line) with:
25.RS
26.B w^x
27.RE
28Whereas both
29.B w
30and
31.B x
32are real numbers between @MIN32@.0 and @MAX32@.0 inclusive.
33
34.SH "Weighted regular expression conditions"
35The first time the regular expression is found, it will add
36.I w
37to the score.  The second time it is found,
38.I w*x
39will be added.  The third time it is found,
40.I w*x*x
41will be added.  The fourth time
42.I w*x*x*x
43will be added.  And so forth.
44
45This can be described by the following concise formula:
46.Sx 4
47                     n
48     n   k\-1        x \- 1
49w * Sum x    = w * \-\-\-\-\-\-\-
50    k=1             x \- 1
51.Ex
52It represents the total added score for this condition if
53.B n
54matches are found.
55
56Note that the following case distinctions can be made:
57.TP 8
58x=0
59Only the first match will contribute w to the score.  Any subsequent
60matches are ignored.
61.TP
62x=1
63Every match will contribute the same w to the score.  The score grows
64linearly with the number of matches found.
65.TP
660<x<1
67Every match will contribute less to the score than the previous one.
68The score will asymptotically approach a certain value (see the
69.B NOTES
70section below).
71.TP
721<x
73Every match will contribute more to the score than the previous one.
74The score will grow exponentially.
75.TP
76x<0
77Can be utilised to favour odd or even number of matches.
78.PP
79If the regular expression is negated (i.e., matches if it isn't found),
80then
81.B n
82obviously can either be zero or one.
83.SH "Weighted program conditions"
84If the program returns an exitcode of EXIT_SUCCESS (=@EX_OK@), then the total
85added score will be
86.BR w .
87If it returns any other exitcode (indicating failure), the total added
88score will be
89.BR x .
90.PP
91If the exitcode of the program is negated, then, the exitcode will
92be considered as if it were a virtual number of matches.  Calculation
93of the added score then proceeds as if it had been a normal regular
94expression with
95.B n=`exitcode'
96matches.
97.SH "Weighted length conditions"
98If the length of the actual mail is
99.B M
100then:
101.Sx 1
102* w^x  > L
103.Ex
104will generate an additional score of:
105.Sx 4
106           @POW@
107    /  M  \e
108w * | \-\-\- |
109    \e  L  /
110.Ex
111And:
112.Sx 1
113* w^x  < L
114.Ex
115will generate an additional score of:
116.Sx 4
117           @POW@
118    /  L  \e
119w * | \-\-\- |
120    \e  M  /
121.Ex
122.PP
123In both cases, if L=M, this will add w to the score.  In the former case
124however, larger mails will be favoured, in the latter case, smaller
125mails will be favoured.  Although x can be varied to fine-tune the
126steepness of the function, typical usage sets x=1.
127.SH MISCELLANEOUS
128You can query the final score of all the conditions on a recipe from the
129environment variable
130.BR $= .
131This variable is set
132.I every
133time just after procmail has parsed all conditions on a recipe (even if the
134recipe is not being executed).
135.SH EXAMPLES
136The following recipe will ditch all mails having more than 150 lines in the
137body.
138The first condition contains an empty regular expression which, because
139it always matches, is used to give our score a negative offset.
140The second condition then matches every line in the mail, and consumes
141up the previous negative offset we gave (one point per line).  In the end,
142the score will only be positive if the mail contained more than 150 lines.
143.Sx 5
144:0 @BODY_GREP@@PASS_HEAD@
145* \-150^0
146*    1^1  ^.*$
147/dev/null
148.Ex
149Suppose you have a priority folder which you always read first.  The next
150recipe picks out the priority mail and files them in this special folder.
151The first condition is a regular one, i.e., it doesn't contribute to the
152score, but simply has to be satisfied.  The other conditions describe things
153like: john and claire usually have something important to say, meetings
154are usually important, replies are favoured a bit, mails about Elvis
155(this is merely an example :\-) are favoured (the more he is mentioned, the
156more the mail is favoured, but the maximum extra score due to Elvis will
157be 4000, no matter how often he is mentioned), lots of quoted lines are
158disliked, smileys are appreciated (the score for those will reach a maximum
159of 3500), those three people usually don't send
160interesting mails, the mails should preferably be small (e.g., 2000 bytes long
161mails will score \-100, 4000 bytes long mails do \-800).
162As you see, if some of the uninteresting people send mail, then the mail
163still has a chance of landing in the priority folder, e.g., if it is about
164a meeting, or if it contains at least two smileys.
165.Sx 11
166:0 @HEAD_GREP@@BODY_GREP@
167*         !^Precedence:.*(junk|bulk)
168* 2000^0   ^From:.*(john@home|claire@work)
169* 2000^0   ^Subject:.*meeting
170*  300^0   ^Subject:.*Re:
171* 1000^.75 elvis|presley
172* \-100^1   ^>
173*  350^.9  :\-\e)
174* \-500^0   ^From:.*(boss|jane|henry)@work
175* \-100^3   > 2000
176priority_folder
177.Ex
178If you are subscribed to a mailinglist, and just would like to read
179the quality mails, then the following recipes could do the trick.
180First we make sure that the mail is coming from the mailinglist.
181Then we check if it is from certain persons of whom we value
182the opinion, or about a subject we absolutely want to know everything
183about.  If it is, file it.  Otherwise, check if the ratio of quoted lines
184to original lines is at most 1:2.  If it exceeds that, ditch the mail.
185Everything that survived the previous test, is filed.
186.Sx 15
187:0
188^@FROM@mailinglist-request@some.where
189{
190  :0:
191  * ^(From:.*(paula|bill)|Subject:.*skiing)
192  mailinglist
193
194  :0 @BODY_GREP@@PASS_HEAD@
195  *  20^1 ^>
196  * \-10^1 ^[^>]
197  /dev/null
198
199  :0:
200  mailinglist
201}
202.Ex
203For further examples you should look in the
204.BR procmailex (5)
205man page.
206.SH CAVEATS
207Because this speeds up the search by an order of magnitude,
208the procmail internal egrep will always search for the leftmost
209.I shortest
210match, unless it is determining what to assign to
211.BR @MATCHVAR@ ,
212in which case it searches the leftmost
213.I longest
214match.
215E.g. for the leftmost
216.I shortest
217match, by itself, the regular expression:
218.TP
219.B .*
220will always match a zero length string at the same spot.
221.TP
222.B .+
223will always match one character (except newlines of course).
224.SH "SEE ALSO"
225.na
226.nh
227.BR procmail (1),
228.BR procmailrc (5),
229.BR procmailex (5),
230.BR sh (1),
231.BR csh (1),
232.BR egrep (1),
233.BR grep (1),
234.hy
235.ad
236.SH BUGS
237If, in a length condition, you specify an
238.B x
239that causes an overflow, procmail is at the mercy of the
240.BR pow (3)
241function in your mathematical library.
242.PP
243Floating point numbers in `engineering' format (e.g., 12e5) are not accepted.
244.SH MISCELLANEOUS
245As soon as `plus infinity' (@MAX32@) is reached, any subsequent
246.I weighted
247conditions will simply be skipped.
248.PP
249As soon as `minus infinity' (@MIN32@) is reached, the condition will
250be considered as `no match' and the recipe will terminate early.
251.SH NOTES
252If in a regular expression weighted formula
253.BR 0<x<1 ,
254the total added score for this condition will asymptotically approach:
255.Sx 3
256   w
257\-\-\-\-\-\-\-
258 1 \- x
259.Ex
260In order to reach half the maximum value you need
261.Sx 3
262     \- ln 2
263n = \-\-\-\-\-\-\-\-
264       ln x
265.Ex
266matches.
267