Debian Codegraph @

CRM114_Mailfilter_HOWTO.txt

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 #
2 # CRM114_Mailfilter_HOWTO.txt - The CRM114 & Mailfilter HOWTO
3 #
4 # Copyright 2003-2009 William S. Yerazunis.
5 # This file is under GPLv3, as described in COPYING.
6 #
7 The CRM114 & Mailfilter HOWTO
8
9 -Bill Yerazunis, 2003-09-18
10 (last update 2009-03-02)
11
12
13 This is the CRM114 Mailfilter HOWTO. It describes how to set up CRM114
14 and Mailfilter to filter your incoming mail, as of the version
15 CRM114-20060209-ReaverSecondBreakfast.
16
17 This HOWTO doesn't describe _how_ CRM114, Mailfilter, Mailtrainer, or
18 Mailreaver works. This just will set you up enough so that you can
19 start using CRM114 and Mailfilter to filter your mail. It assumes you
20 are running on a Linux box; getting the system running on *BSD, MacOS,
21 or Windows will require considerably more work than we describe here
22 (and is a subject for future HOWTOs).
23
24 ------------------------------------------------------
25
26 Remember, the CRM114 package is released under the GPL (license
27 is enclosed in any of the downloads). There is NO WARRANTY
28 WHATSOEVER for this software to be useful in any way; it's going
29 to tamper with your incoming mail and you can easily imagine the
30 dangers in that.
31
32 ----------------------------------------------------------
33
34 That said, I hope CRM114, Mailreaver, and Mailreaver is useful to you;
35 it's been very useful to me. It's been keeping my mailbox clear of
36 clutter for since 2002; I'm convinced it has better performance than
37 I-the-human at killing spam without accidentally deleting important
38 mail. I've tested myself, and I-the-human is only about 99.7% or
39 99.8% accurate at best; CRM114 is considerably more accurate than that
40 - easily two or three times more accurate. (as of December 2003, it
41 was 99.95% accurate (N+1 statistics) on my incoming mail stream to a
42 non-business account.
43
44 Something to Remember:
45
46 CRM114 is a *language* designed to write text filters and
47 classifiers in. It makes it easy to tweak code.
48
49 Mailfilter is just _one_ of the possible filters; there are many
50 more out there and if Mailfilter doesn't do what you want, it's
51 easy to create one that does.
52
53 Mailreaver is another one of the filters, with different (and
54 better, I hope) designs, that can use Mailtrainer (yet another
55 filter) to build even better statistics files.
56
57 There are yet other filters written in CRM114; you can read all
58 about them on the web page:
59
60 crm114.sourceforge.net
61
62 (and if you create one, and want to share it, put it on a web
63 page and send me an email so I can add a pointer.)
64
65 - Bill Yerazunis ([email protected])
66
67 -------------------------------------------------------------------
68
69 Step 0: Scientes Inamicae (Know Thy Enemy)
70
71 These are the major steps in using CRM114 Mailfilter. The steps are
72 pretty simple:
73
74 1) Downloading what you need
75
76 (it's just 1 or 2 megabytes in a single .gz file)
77
78 2) Setting up the executables
79
80 (not more than ten commands to type, even if you're building
81 from the fresh source)
82
83 3) Configuring Mailfilter or Mailreaver
84
85 (editing one file, most likely change is ONE line, and we tell
86 you which one)
87
88 3) Setting up the needed auxilliary files
89
90 (not more than 2 files to edit of no more than 5 lines each,
91 plus typing one or two commands)
92
93 5) Engaging Mailfilter
94
95 (if you are using Procmail, this is cut-and-paste about ten lines,
96 otherwise it's create one file containing one line, and typing
97 up to three commands)
98
99 6) Training CRM114 and Mailfilter
100
101 (whenever you get an error, you send it back to yourself,
102 using your current mail tool. How hard can that be? Now, you
103 can also use mailtrainer to bulk-train in whole directories
104 of your old spam and good email.)
105
106 7) Adding Priority Lists, Whitelists, and Blacklists
107
108 Mailfilter supports whitelists, blacklists, term rewriting, and
109 some other features. You can use these for "guaranteed delivery"
110 from people you really trust - or really hate.
111
112 8) Useful Utilities
113
114 Details on the cssutil, cssdiff, and cssmerge utilities. You
115 don't need to know this, but you may find it useful.
116
117
118
119 -------------------------------------------------------------------------
120
121 Step 1: Downloading.
122
123 Get yourself a copy of a CRM114 kit. The kits can always be found by
124 visiting the CRM114 homepage at:
125
126 http://crm114.sourceforge.net
127
128 You will need at least the statically-linked binary kit (compiled to
129 run on any i386 or better Linux box); for best performance it is
130 suggested you get the source kit and compile it on the processor you
131 will be running CRM114 on. If you do not have root privs on the box
132 you will be running CRM114 on, it is suggested you stay with the
133 statically linked binaries (this is because the recommended "TRE" REGEX
134 library requires either root to install, or major workaround mojo).
135
136 The kits are named:
137
138 crm114-<version>.i386.tar.gz (statically linked binaries)
139 and
140 crm114-<version>.src.tar.gz (complete source code + tests)
141
142 These kit .gz files are fairly small; usually less than one megabyte
143 (currently around 800 Kbytes) so they will download quickly.
144
145 You will need to decide if you will be starting off with a pre-learned
146 set of .css files (.css means CRM114 Sparse Spectra) or if you will be
147 creating your own .css files from your own samples of spam and
148 nonspam. You can think of a .css file as being a "cerebral memory" of
149 what a particular kind of mail (good or spam) looks like; .css files
150 are how CRM114 remembers what spam and good mail look like. With empty
151 .css files a CRM114 system acts like a total amnesiac - it has absolutely
152 no conception of "good" or "bad".
153
154 In general, the pre-learned .css files will give you an initially more
155 accurate filter, but after some use and training the self-created
156 filter files will catch up with pre-learned files, and then the
157 two filters will achieve about equal accuracy. However, there may
158 be some "glitches" in the mid-term while some edge cases in the
159 prelearned files are _unlearned_.
160
161 If you decide not to take our advice, you will also need to download a
162 set of pretrained .css files like these:
163
164 crm114-<version>.css.tar.gz
165
166 The .css files are rather large; this download may approach 50 megabytes.
167 (currently it's 8+ megabytes)
168
169 Download the kits you will need (at least one of .src.tar.gz or
170 .i386.tar.gz or .i386.rpm) and then proceed to "Step 2: Setting Up the
171 Executables"
172
173
174
175 --------------------------------------------------------------------------
176
177
178
179
180 Step 2: Setting Up the Executables
181
182 In this step, you will install four binaries into your system.
183 The four binaries are:
184
185 crm - the CRM114 "compute engine". It's called "crm" because "crm114"
186 is too hard to type.
187 cssutil - the .css file check/verify/edit program
188 cssdiff - the .css file diff program
189 cssmerge - the .css file merging program
190
191 One important point: do NOT install CRM114 or any of it's utilites
192 setuid or sgid to root. If you do, that's just an invitation for
193 someone to utterly hose your system without even trying. We're not
194 talking an intentional attack, just an inadvertent command or script
195 gone wierd could do it.
196
197 This is also why we recommend using a _static_ linking of the
198 executable, so that a LD_LIBRARY_PATH attack can't falsely insert
199 a subversive version of a library.
200
201 -----
202
203 There are three ways you can set up these executables. You can:
204
205 a) install with a .rpm kit
206
207 b) install with a .i386.tar.gz (tarball of statically linked binaries)
208
209 c) install with a .src.tar.gz (tarball of complete source)
210
211 Note 1:
212 If you do not have root on the machine you are installing on, you
213 may have some problems during the installation. You may want to
214 reconsider using the statically linked binaries instead of compiling
215 from sources.
216
217 -----
218
219 Step 2 Method A: Installing from .i386.tar.gz
220
221 First, untar the binary release. Type:
222
223 tar -zxvf crm114-<version>.i386.tar.gz
224
225 You should now become root. If you do not have root on your machine,
226 you _can_ execute CRM114 programs directly from your home directory,
227 by changing your $PATH appropriately; see your shell man page for how
228 to do this for your particular shell (it varies with the shell, so
229 I can't tell you here how to do it) and skip to the end of this step.
230 Or- you can run the binary explicitly from your current directory
231 by invoking it as ./crm114_tre.
232
233 If you're installing, become root, then type:
234
235 cd crm114-<version>
236
237 make install_binary_only
238
239 This will install the pre-built binaries of CRM1114 and the utilities
240 into /usr/bin. This is the default install location for CRM114. If
241 you want them installed in a different place, edit the Makefile and
242 change BINDIR (near the top of the Makefile) to a different
243 directory.
244
245 Note that if you type "make clean" you'll _delete_ your prebuilt
246 binaries, so don't do that!
247
248 Now, you can test your work. Type
249
250 crm -v
251
252 which will cause CRM114 to print out the version of itself you
253 just installed.
254
255 You can also run a quick "Hello, world!" by typing:
256
257 crm '-{ output /Hello, world! This is CRM114 version :*:_crm_version: .\n/}'
258
259 then hit ^D (end-of-file on *nix). You;ll get back a response like:
260
261 Hello, world! This is CRM114 version 20040118-BlameEric .
262
263
264 Congratulations! You've now completed the installation of CRM114 and
265 utilities from prebuilt binaries. Proceed to "Step 3: Setting Up Needed
266 Files.
267
268 -----
269
270 Step 2 Method B: Compiling from .src.tar.gz (source)
271
272 This method is the most complex. Start by uncompressing and untarring the
273 big .src.tar.gz with the command:
274
275 tar -zxvf crm114-<version>.src.tar.gz
276
277 Now cd down into the crm114-<version> directory. You will see many files
278 here.
279
280 You now have a choice: you can build CRM114 with either the GNU regex
281 libraries (not recommended, as GNU regex can't handle embedded NULL
282 bytes and has other issues), or with the TRE regex library
283 (recommended; this is what you get with the precompiled binary kit).
284
285 By default, you will use the TRE regex library; however, this means
286 you have to build and install TRE. You can either grab the most
287 recent version from the TRE homepage at http://laurikari.net/tre, OR
288 you can use the version that is pre-packaged with your CRM114
289 download. (The pre-packaged version is tested against CRM114 and will
290 have all appropriate patches installed, while the fresh one may have
291 new features. Take your choice- it's good stuff either way)
292
293 Fortunately, building and installing TRE is easy. The TRE regex
294 library will peacefully coexist on the same system as the GNU regex
295 library.
296
297 Caution: if you are building from sources, you should install
298 the TRE regex library ***first***. TRE is the recommended regex
299 library for CRM114 (fewer bugs and more features than Gnu Regex).
300
301 To install TRE, become root, then type this ( BIG BIG WARNING - DO NOT
302 FORGET to tell configure to "--enable-static" ) :
303
304 cd crm114-<version>
305
306 cd tre-<tre_version_number>
307
308 ./configure --enable-static
309
310 make
311
312 make install
313
314 You have now installed the TRE regex library as /usr/local/lib/libtre .
315
316 If you make a mistake and need to rerun the make commands, be aware
317 that in some versions of TRE, a 'make clean' command will delete test
318 files that are needed when running the build process again.
319 Unfortunately, the safest course of action is to delete the TRE source
320 directory and restore it from the tar ball.
321
322 Depending on your choices in static versus dynamic linking, you _may_
323 need to also add /usr/local/lib to /etc/ld.so.conf, and then run
324 ldconfig as root. Or not. If, during the next steps, you get
325 annoying messages on the order of "can't find ltre" then this is
326 the thing to try.
327
328 Once TRE is built and installed you can compile CRM114 and the
329 accompanying utilities (cssutil, cssdiff, and cssmerge). By default,
330 CRM114 installs into /usr/bin (_not_ /usr/local/bin - if you want to
331 change this, change the definition of BINDIR near the top of the
332 file "Makefile"). Cssutil gives you some insight into the state of a
333 .css file, cssdiff lets you check the differences between two .css
334 files, and cssmerge lets you merge two css files.
335
336
337 Change directory back up to the CRM114 directory, then become root,
338 then (noting that no .configure step is necessary; the CRM114
339 Makefile is self-contained and presupplied) type:
340
341 cd ..
342
343 make
344
345 This will compile and link the CRM114 executable and the utilities.
346 You can test this executable if you want. Just type:
347
348 make megatest
349
350 which will run for about a minute and exercise most of the code paths
351 inside CRM114. This tests the version of CRM114 in your local
352 directory. Note that this only works if you've installed the TRE
353 engine. The GNU regex engine has enough "fascinating behaviors" that
354 it will get a lot of things wrong; the GNU regex package also doesn't
355 handle approximate regexes at all, and since those are in the test
356 set, you'll error out on each of those as well.
357
358 If "megatest" reports any differences between the supplied
359 "megatest_knowngood.log" and your own results, OTHER than on lines tht
360 say "OK_IF_blahblahblah" results, please file a bug report to me and
361 we'll figure out what went wrong.
362
363 If you are happy with the executable, type
364
365 make install
366
367 This will install the executable into /usr/bin/crm (by default). If
368 you want another install location, you can change it in the Makefile.
369 You can now check to see that the install version by:
370
371 crm -v
372
373 and CRM114 will report back the version of the install.
374
375 You can also run a quick "Hello, world!" by typing:
376
377 crm '-{ output /Hello, world! This is CRM114 version :*:_crm_version: .\n/}'
378
379 then hit ^D (end-of-file on *nix). You;ll get back a response like:
380
381 Hello, world! This is CRM114 version 20040118-BlameEric .
382
383
384 Congratulations! You've now completed the installation of CRM114 and
385 utilities from source. Move on to the next step - "Step 3: Setting Up
386 Your .CSS Files" .
387
388
389
390 ------------------------------------------------------------------------
391 ------------------------------------------------------------------------
392
393 Step 3: Configuring Mailfilter or Mailreaver
394
395 In this step you will tell Mailfilter or MailReaver what you want it
396 to do with your mail. All of the options are controlled by editing
397 one file, named "mailfilter.cf" . Mailfilter and MailReaver use most
398 of the same flags (and all of the same important ones) so both use
399 the same mailfilter.cf file.
400
401 By default, both Mailfilter and Mailreaver look for the file
402 mailfilter.cf in the initial directory. If you want to change that,
403 use "--fileprefix=/some/where/else/" on the command line, so these
404 filters will look for mailfilter.cf (and the other runtime filtering
405 files!) in the "/some/where/else/" directory. This --fileprefix mode
406 is handy when you are setting up many users. (remember to use a final
407 closing slash on the directory name or you will end up nowhere)
408
409 The format of mailfilter.cf itself is pretty simple.
410
411 0) blank lines are OK.
412 1) comments start with a # in column 1.
413 2) Anything not a comment is a var setting, in the format:
414
415 :var_to_set: /Value_to_set_goes_here/
416
417 All of the user-settable configuration vars have setup lines in
418 mailfilter.cf, and you only need to change three lines for a "default"
419 average setup: one is a password you make up, and the other two have
420 only a few possibilities each, and we list those possibilities for
421 you.
422
423 The Three Things you MUST do in mailfilter.cf :
424
425 1: First, you MUST change the secret password. This is defined near
426 the top of the file. Your password may contain a-z, A-Z, 0-9, but
427 no blanks or punctuation (at least for now). You _must_ set this
428 password to something not easily guessable. If you don't set it,
429 you won't be able to use mailfilter's remote commanding facility.
430
431 2: Second, you MUST set whether to use base64 decodes, or not, and if
432 so, which decoder your system supports. Just type the options into
433 BASH, one at a time (like "mewdecode <cr>") and use the first one
434 that doesn't give you an error message.
435
436 3: Third: you MUST set the cache_dupe_command according to whether
437 your system supports linking (as in, has an "ln" command; *NIX
438 does, but Windows doesn't) or whether full copies of texts need to
439 be used in the reaver.
440
441 Other than that, everything else in the mailfilter.cf file can be left
442 alone, at least for initial testing.
443
444 At first, you will probably want to leave the "log_to_allmail.txt"
445 enabled while you get used to CRM114. Likewise, leave
446 "log_rejections" set to yes as well; that way you can easily see (with
447 "less" or "tail") just what is being rejected. Once you get more
448 experience with CRM114, you can set these to "no" and not use up disk
449 space in these "extra safety" logs.
450
451 You can skim-read the rest of mailfilter.cf . There are three
452 typical cases for most users:
453
454 1) If you ARE using Procmail or another filtering MDA:
455
456 --> You probably will NOT need to change any of the other options.
457
458 2) If you ARE NOT using Procmail, but your mail reading program can
459 sort out email into folders based on whether the SUBJECT header
460 contains the telltale string "ADV:" (most mail readers can do this):
461
462 --> You probably will NOT need to change any of the other options.
463
464 3) You are NOT using Procmail, and your mail reading program is "dumb"
465 (cannot sort email into folders based on subject line):
466
467 --> You probably will want to define a separate account that will
468 recieve all spam caught (otherwise, you'll just get all your spam
469 delivered as usual, with additional headers telling you it was
470 spam).
471
472 To do this, look down to ":general_fails_to:". Insert the full
473 [email protected] mail address where you want your spam to be
474 sent.
475
476
477 Note on mime decoders: There are a number of them available; the defaults
478 given in mailfilter.cf may or may not be valid on your system. Further,
479 it may have a different path than the default given in mailfilter.cf.
480 Yet further, you may want to load your own, like "normalizemime" (see
481 the crm114.sourceforge.net web page for details on the download).
482
483 You can also configure the verboseness (or not) of your filtered
484 results. You can go from "no changes" (not even a statistical label
485 in the headers) to complete results including an expansion of any
486 base64 texts and HTML decommented strings.
487
488 Feel free to change things to get the look and feel you want; after
489 all, what good is open source if you don't change it? :-)
490
491 HOWEVER, Please don't muck with variables that aren't in the
492 mailfilter.cf file. "You make a mess, you clean it up." :-(
493
494 After making these changes, write out "mailfilter.cf". You may
495 later go back and change the configuration options, but the options
496 as already set are good for most users. You do not need to do anything
497 to "load in" the new options, as CRM114 reads them in fresh from the
498 file during initialization for each email.
499
500 Now, proceed to "Step 4: Setting Up Other Needed Files" .
501
502
503 --------------------------------------------------------------------
504 --------------------------------------------------------------------
505
506
507 Step 4: Setting Up Other Needed Files
508
509 Now that the crm114 language is working, you need to set up your
510 .css files, your rewrites.mfp file, and your priolist.mfp file.
511
512 All of these files need to exist (either by being there, or by
513 being symlinked to) the directory where CRM114 will "run in"
514 when an actual mail comes in. Usually this is your per-user
515 directory on the mail server (if your mail server is also your
516 home directory, then it's there.). If this is inconvenient,
517 you can use the --fileprefix option on the command line to
518 tell CRM114 to "change over" to a different directory. The files
519 that need to be in the home (or --fileprefix) directory are:
520
521 rewrites.mfp
522 spam.css
523 nonspam.css
524 priolist.mfp
525 blacklist.mfp [ only for mailfilter; mailreaver ignores it ]
526 whitelist.mfp [ only for mailfilter; mailreaver ignores it ]
527
528 Here's a quick overview of these files; we'll get into the details
529 further on. If you are in a hurry, you can have *empty* files
530 for all four of the .mfp files and things will still work reasonably
531 well (and you can upgrade later). You DO need to create the
532 proper-sized .css files, though, or you won't be able to classify
533 email at all (depending on your setup, it may be discarded,
534 may be returned to sender, or may actually just get mangled and
535 forwarded. None of these are a good thing, in the long run)
536
537 --- Summary of each file ---
538
539 [[ rewrites.mfp ]]
540
541 The rewrites.mfp file controls how to "rewrite" incoming email so
542 that your incoming email conforms more closely to what might be
543 considered "archetypal". The rewrites.mfp setup is optional;
544 if you build your own .css files (either from empty files, or
545 from corpora) you can actually replace rewrites.mfp with an
546 empty file; you just won't be able to share your .css files with
547 anyone else.
548
549 [[ spam.css and nonspam.css ]]
550
551 The .css files themselves ( CRM114 Sparse Spectra files) are the
552 "memory" that crm114 uses to statistically describe the words and
553 phrases that characterize various kinds of mail. Although it depends
554 on the classifier you are using, by default the .css files are in a
555 hashed binary format and it is not easy (or sometimes, even possible!)
556 to reconstruct your email from the .css files. However, it *is*
557 possible to determine from the .css files if certain words or phrases
558 have ever been trained into your classifier, so .css files do have
559 some possible security implications.
560
561 DMCA note: CRM114 statitics files are "effectively encrypted"
562 according to the provisions of the DMCA - all parties are hereby
563 notified that the copyright owner/author of any particular statistics
564 file (.css , .cfc, .cor, .cwc, .chp, or other) is the creator of that
565 file, not the author(s) of CRM114 itelf, and said creator may invoke the
566 draconian punishments of the DMCA on any party attempting to extract
567 the encoded information without prior approval. So there.
568
569 [[ priolist.mfp ]]
570
571 The priolist.mfp file is a sequential list of tests to be run; each
572 test starts with a + or a - (thumbs up or thumbs down), then a regex
573 pattern; if the pattern matches, the mail is either accepted
574 unconditionally or sent to the spam bucket unconditionally. Then, The
575 blacklist.mfp, and whitelist.mfp are "match this, you're spam" and
576 "match this, you're good" regex pattern sets. If this seems
577 redundant, you're right; all you need is priolist.mfp, but enough
578 folks have historically requested "blacklists" and "whitelists" as an
579 explicit marketing checkoff that we've put them into mailfilter.crm.
580 Priolist.mfp is the preferred method of doing blacklists and
581 whitelists now; if a P.H.B. asks "does it have blacklists and
582 whitelists", you can now say "yes, and they're even _prioritized_
583 blacklists and whitelists!".
584
585
586
587 Step 4 Part 1 - Setting up the Rewrites file.
588
589 To set up the rewrites.mfp file, edit the file "rewrites.mfp" and
590 replace the placeholders (in this case, "wsy", "merl.com", and
591 "mail.merl.com") with your corresponding username, domain name, and
592 mail server information. These rewrite rules will be used to "scrub"
593 your sample text of user-specific strings. (note that this is only
594 strictly necessary if you want to use the pre-built .css files.
595 However, it is in general recommended, so that you can "share/merge"
596 your .css files with your friends.)
597
598 Note the "arrowheads" in the file. They look like this:
599
600 >->
601
602 or
603
604 >-->
605
606 This is a rewrite operator. Anything that matches the regex on the
607 left-hand side of the arrowhead will be replaced with the text on
608 the right-hand side of the arrowhead. (the "arrowheads" that have
609 one hyphen in them will rewrite only if the entire left-hand match
610 is found on a single line; if you use two hyphens, to make a ">-->"
611 instead of ">->" then the left-hand match can be multi-lined.)
612
613 Example: if your name was Agent Smith, your email account
614 [email protected], and your mail router was mail.matrix.net at
615 IP address 192.168.10.5, then the rewrites.mfp file should look like:
616
617 [email protected]>->MyEmailAddress
618 [[:space:]]Agent Smith>-> MyEmailName
619 mail.matrix.net>->MyLocalMailRouter
620 192.168.10.5>->MyLocalMailRouterIP
621
622 The idea is to turn your email headers into headers that don't refer
623 to any of your own actual name, address, etc, but contain only the
624 strings "MyEmailAddress", "MyEmailName", "MyLocalMailRouter", and
625 "MyLocalMailRouterIP".
626
627 If you have more than one incoming email name , email address, server,
628 router, etc, add lines in rewrites.mfp for each email name, email
629 address, server, router, and so forth. This is something you really
630 _should_ do, if you have more than one email path leading to the
631 account that leads to an account that is being filtered by CRM114 (if
632 you don't, a lot of learning will have to be repeated for each path,
633 which will cost you accuracy and use up valuable feature slots in the
634 .css files that you could use in more valuable ways otherwise. On the
635 other hand, if you have multiple email addresses that all channel
636 through one CRM114 fileset, and the addresses recieve very different
637 ratios of spam and nonspam (or, very differnt *types* of spam), then
638 it _might_ be to your advantage to not use rewrites.mfp, (just replace
639 it with an empty file), so that the extra statistical information of
640 the incoming email address is not lost)
641
642 If all this confuses you to no end, just make rewrites.mfp be an
643 empty file and everything should decently well.
644
645 -----
646
647 Step 4 Part 2 - Setting up the .CSS files
648
649
650 You have a choice here. You can either build your own files from your
651 own spam and nonspam email, or you can use the pre-learned .css files
652 available from crm114.sourceforge.net . We recommend that you build
653 your own files dynamically, as that will result in the best final
654 accuracy.
655
656 In either case your .css files should be in the same directory as your
657 mailfilter will "run" in (as we mentioned above, default is your home
658 directory on your mailserver). The particular directory that the
659 mailfilter "runs" in is variable and depends on your local setup.
660 Assuming you will use the ".forward" hook, there are two likely
661 situations.
662
663 If your mail service runs on your local machine (say, you have just
664 one machine - and I do hope you have a firewall in that case), then
665 mailfilter will almost certainly "run" in your home directory- the
666 directory you're in when you log in.
667
668 If your mail service runs on a mail server (not your local machine),
669 then you will probably have a "home directory" on that machine as well,
670 and that's the directory that the mail filter will run in.
671
672 If neither of these is the case, you should ask your system
673 administrator what the correct directory is.
674
675 -----
676
677 Step 4 Part 2 Method A - Build Your Own Empty .CSS Files
678
679 This method will give you the best final accuracy, but you will
680 spend more time training.
681
682 This is the recommended method for users wanting the best accuracy.
683
684 To start from scratch, you need to create empty .css files. The
685 cssutil program will do that for you. Just type:
686
687 cssutil -b -r spam.css
688
689 cssutil -b -r nonspam.css
690
691 and you will have created _empty_ spam.css and nonspam.css files in
692 your current directory (that is, the files are full-size, but contain
693 no information. They'll be full of binary zeroes).
694
695 Once you have these empty files you will have a high (50% or so)
696 error rate for the first few hours, till you have 'taught' CRM114
697 what your particular mix of spam and nonspam looks like. Proceed
698 below to "Step 4: Configuring Mailfilter".
699
700 Many people want to "preload" their spam collection into CRM114. This
701 used to be a bad idea. CRM114 is optimized for TOE learning - "Train
702 Only Errors" learning; testing something like a quarter of a million
703 test cases has proven that it is better to train only errors, and
704 _only_ _as_ _they_ _occur_, than to preload a bulk database into
705 CRM114.
706
707 Note that the previous paragraph says "used to be". The new program
708 "mailtrainer.crm" can do rapid TOE or DSTTTR training and build your
709 .css files out of stored spam and good mail collections. You can read
710 all about mailtrainer.crm in Appendix 1 of this document.
711
712 If you're wondering, the statistics from the "torture test" (about
713 40,000 messages) are that training _only_ errors, in realtime, will
714 give about 2.1 times better accuracy than force-training a big corpus,
715 even if the messages are the same messages and presented in the same
716 order. The "why" is mathematically complicated, but there's an
717 intuitive description in the FAQ.
718
719 Again: you will achieve the best possible accuracy if you let CRM114
720 itself make errors that you correct in real time.
721
722 -----
723
724 Step 4 Part 2 Method B - Pre-LEARNed files:
725
726 This is the simplest method, but less accurate than method A.
727
728 If you choose to use the pre-learned .css files, you need to download
729 the appropriate crm114 .css.tar.gz file, and then you can just type:
730
731 tar -zxvf crm114-<version_number>.css.tar.gz
732
733 and you'll get the two files "spam.css" and "nonspam.css" in your
734 current directory.
735
736 Note that the download is fairly large - between 8 and 50 megabytes,
737 and although this will give you a good starting point for your own
738 statistics, you will have a better (smaller, faster) final
739 configuration if you build your own .css files from scratch.
740
741
742 -----
743
744 Step 4 Part 2 Method C - BETA TEST - Using mailtrainer.crm to
745 Build .CSS Files
746
747 New in 20060101 is the "mailtrainer.crm" program. This program
748 accepts two directories of "archetype" good and spam email, and runs
749 an interative training procedure to produce some very high quality
750 .css files from these examples. The example files need to be
751 "SMTP Virgin" - that is, exactly what was recieved at SMTP time
752 by your mail server, with _nothing_ changed. (any changes
753 will affect accuracy, probably negatively)
754
755 The mailtrainer training will typically take something like 1 to 10
756 minutes per 1000 messages in your training set. Mailtrainer.crm will
757 create your spam.css and nonspam.css files automatically.
758
759 Mailtrainer.crm will also read your mailfilter.cf configuration file,
760 and rewrites.mfp, so be sure to set up those files _first_ (if you're
761 doing things in order, you're in good shape).
762
763 The full description of how to use mailtrainer.crm is in Appendix 1 at
764 the end of this document. So, jump there, read Appendix 1, run
765 mailtrainer.crm, and then proceed to the next section- checking your
766 .css files.
767
768 -----
769
770 Step 4 Part 2 Method D - ALPHA TEST -- MAKEFILE Build And
771 Preload .CSS Files From Fresh Spam and Nonspam
772
773 CAUTION - this applies ONLY to kits 20060606 and later!!! DO NOT DO
774 THIS if you are running a pre-20060606 makefile! It will hose you!
775
776
777 If you, by any chance, happen to have un-altered examples of spam and
778 nonspam, you can use these to pre-build a set of .css files. (As of
779 versions 20060606 and later ONLY. Previous versions had a bad
780 implementation of this that took different arguments and tended to
781 produce bloated .css files that didn't function well. Post 20060606,
782 the mailtrainer system is used and that works very well indeed)
783
784 You also need to be sure your emails are "SMTP Virgin" - that is, they
785 are exactly as recieved at SMTP time, not with headers or footers
786 added or taken out by your mail delivery agent or your mail reading
787 program. (if this isn't true, the headers will be rather bogus and
788 you will lose significant accuracy and you should use method A above
789 instead).
790
791 If you are OK with this, here's what to do:
792
793 1) Put copies (or symlinks/hardlinks) to all of your example
794 spam into a subdirectory named spam.dir in the local directory.
795
796 2) Put copies (or symlinks/hardlinks) to all of your example
797 good email into a subdirectory named good.dir in the local directory.
798
799 3) IF you want to train from scratch (not necessarily good or bad,
800 but your option... choose well):
801
802 rm -rf spam.css
803
804 rm -rf nonspam.css
805
806 4) Invoke the mailtrainer
807
808 make cssfiles
809
810 to build your new spam.css and nonspam.css files.
811
812 That's all. It'll take a few minutes to run but mailtrainer will give
813 you running status so it's not like things have hung.
814
815 Again, let me emphasize that doing this is ONLY recommended on full
816 installs post 20060606 . Versions prior to that will hose you if
817 you do this.
818
819 --------
820
821 Step 4 Part 3 - Checking your installation
822
823 Once you have set up mailfilter.cf, rewrites.mfp, the *list.mfp files,
824 and the .css files, you can test your configuration by typing the
825 following (The '^D' at the end is a control-D, which is an END-OF-FILE
826 on Linux. Other systems may use a different END-OF-FILE character):
827
828 ./mailfilter.crm
829 This is a test. Just type a few lines of text
830 that you might ordinarily get, like a short rant on why
831 Perl is useless for big projects, or why Linux is
832 superior or inferior to NetBSD.
833 ^D
834
835 or (to use mailreaver instead)
836
837 ./mailreaver.crm
838 This is a test. Just type a few lines of text
839 that you might ordinarily get, like a short rant on why
840 Perl is useless for big projects, or why Linux is
841 superior or inferior to NetBSD.
842 ^D
843
844
845 If you have set up Mailfilter for Procmail-style filtering you will
846 always get a small report back saying something like either of these
847 (the actual numbers and some minor text strings will change, but you
848 should have something that _vaguely_ looks like the following):
849
850 From foo@bar Thu Sep 18 19:20:35 2003
851 X-CRM114-Status: Good ( pR: 12.630237 )
852
853 ** ACCEPT: CRM114 PASS SBPH/BCR TEST**
854 Probabilistic match quality: 1.000000, pR: 12.630237
855 P(succ): 1.000000e-00, P(fail): 2.342950e-13
856 Features: 336, S hits : 4313, F hits : 5901
857
858 or:
859
860 From foo@bar Thu Sep 18 19:19:39 2003
861 X-CRM114-Status: SPAM ( pR: -2.866484 )
862
863 ** REJECT: CRM114 FAIL SBPH/BCR TEST**
864 Probabilistic match quality: 0.001358, pR: -2.866484
865 P(succ): 1.358082e-03, P(fail): 9.986419e-01
866 Features: 144, S hits : 2337, F hits : 3313
867
868 If you are using "mail to spamtrap account" filtering, then you will
869 either get an "accept" report back (the first report above is an
870 "accept") or the text you typed in will be mailed to your spamtrap
871 address. If you don't get a report back, check the spamtrap address
872 and see if your test text ended up there.
873
874 If all the numbers are zero, or the result is "UNSURE", that's OK,
875 it just means there isn't enough statistical information in the .css
876 files yet to actually decide if it's spam or not. This is a good
877 situation.
878
879 If you don't get _either_ of the above, something is broken, either in
880 your installation of CRM114 or in your configuration file. You need
881 to fix the problem before you engage Mailfilter.
882
883 If your installation and configuration passes the above test,
884 congratulations! You have now configured mailfilter.crm .
885
886 -----
887
888 Step 4 Part 4 - OPTIONAL - CHECKING YOUR .CSS FILES
889
890 For all three (four?) methods of setting up your .css files, you can
891 check that the .css files are reasonable. Use the "cssutil" utility.
892
893 Note: this works fine for the default classifiers like Markov, OSB,
894 and OSB Unique, but _not_ for Winnow, Hyperspace, or Corellative
895 classifiers; for OSBF classifiers use osbf-util instead of cssutil.
896
897 Type in:
898
899 cssutil -b -r spam.css
900
901 cssutil -b -r nonspam.css
902
903 You should get back a report something like this:
904
905 Sparse spectra file spam.css statistics:
906
907 Total available buckets : 1048576
908 Total buckets in use : 506987
909 Total hashed datums in file : 1605968
910 Average datums per bucket : 3.17
911 Maximum length of overflow chain : 39
912 Average length of overflow chain : 1.84
913 Average packing density : 0.48
914
915 Note that the packing density is 0.48; this means that this .css file
916 is about half full of features. Once the packing density gets above
917 about 0.9, you will notice that CRM114 will take longer to process
918 text. The penalty is small below packing densities below about 0.95
919 and only about a factor of 2 at 0.97 .
920
921 Note - do NOT believe "ls -la" with respect to .css files! Because
922 CRM114 uses memory mapping instead of file I/O (because it's much
923 faster to go through the page-fault tables than through the file I/O
924 system), the m-time (time last modified) and c-time (time created)
925 never change, only the a-time (time last accessed), and that even the
926 a-time only changes if your file system had the proper compile-time
927 options to keep track of the a-time, and that defaults to "not keep
928 track". Believe in what cssutil tells you- if new features show up
929 after learning (because the bucket counts change), you _are_ learning
930 and "ls -la" is lying to you! Conversely, if the bucket counts
931 do NOT change, you have a file redirection or file protection
932 problem and your system is NOT learning. That's bad and you need
933 to figure out the problem and fix it.
934
935
936 You can also see how easy it will be for CRM114 to differentiate
937 spam from nonspam with your .css files. The utility "cssdiff" will
938 compare the statistical features of two .css files. (again, only
939 for Markov, OSB, and OSB Unique classifiers) Try it:
940
941 cssdiff spam.css nonspam.css
942
943 and you'll get back a report like:
944
945 Sparse spectra file spam.css has 1048577 bins total
946 Sparse spectra file nonspam.css has 1048577 bins total
947
948 File 1 total features : 1605968
949 File 2 total features : 1045152
950
951 Similarities between files : 142039
952 Differences between files : 1279964
953
954 File 1 dominates file 2 : 1463929
955 File 2 dominates file 1 : 903113
956
957 Note that there's a big difference between the two files; in this case
958 there are about 10 times as many differences between the two files as
959 there are similarities. That's pretty much typical- and it's a good sign
960 that your filtering should be quite accurate.
961
962 Now, move on to "Step 4: Configuring Mailfilter".
963
964 ----------------------------------------------------------------------------
965 ----------------------------------------------------------------------------
966
967 Step 5: Engaging Mailfilter
968
969 There are two common ways to engage Mailfilter.crm on your incoming
970 mail stream: you can use Procmail recipes and have Mailfilter run as a
971 procmail subprocess, or you can use the .forward hook of Sendmail (and
972 Sendmail clones which also support .forward)
973
974 In the first method (recommended), you use Procmail's ability to
975 execute a program as part of a Procmail recipe to run CRM114, which
976 adds headers as needed to let Procmail or your mail-reading program do
977 the sorting.
978
979 In the .forward method, you (or your system manager) must add a link
980 from an execution command of crm114 to the directory /etc/smrsh. This
981 is because sendmail will NOT run any program that isn't "approved" by
982 the system manager (by linking it into /etc/smrsh/whatever). The output
983 of mailfilter is then directly appended to your /var/spool/mail file
984 (or possibly forwarded to your spam-bucket account).
985
986 -----
987
988 Step 5 Method A: For Procmail and Maildrop Users
989
990 For Procmail users just add a procmail recipe to .procmailrc to run
991 CRM114 and mailfilter whenever your other procmail rules fail to
992 decide what to do.
993
994 Here's a sample Procmail recipe set. Notice that we actually have TWO
995 recipes - one to actually run crm114 and mailfilter, the other to
996 then sort the mail based on the result.
997
998 #
999 #
1000
1001 :0fw: .msgid.lock
1002 | /usr/bin/crm -u /home/my_user_directory mailfilter.crm
1003
1004 :0:
1005 * ^X-CRM114-Status: SPAM.*
1006 mail/crm-spam
1007
1008 That's all that Procmail users should need. Mailfilter should now be
1009 active - send yourself a test message and see where it ends up.
1010
1011 To use mailreaver instead of mailfilter, just put "mailreaver.crm"
1012 in instead of "mailfilter.crm" .
1013
1014 If you get the test message, proceed to "Step 6: Training CRM114".
1015
1016 -----
1017
1018 ( note: Sub-Method A-one)
1019
1020 If you use an MUA that can highlight on headers, you can use something
1021 like this in your procmail (from Philipp Weiss):
1022
1023 in .procmailrc
1024
1025 CRMSCORE=`$HOME/bin/crmstats.sh`
1026 :0fw: .formail.crm114.lock
1027 | formail -I "X-CRM114-Score: $CRMSCORE"
1028
1029 where ~/bin/crmstats.sh is a simple script:
1030
1031 #!/bin/bash
1032 grep -a -v "^X-CRM114" | \
1033 /usr/bin/crm -u $HOME/.crm114 mailfilter.crm --stats_only
1034
1035
1036 ------
1037
1038 (note: Sub-Method A-two)
1039
1040 If you're using maildrop ( http://www.courier-mta.org/maildrop.html ), you
1041 can put this in your ~/.mailfilter (from Stefan Seyfried and Joost van Baal)
1042
1043 CRMSCORE=`grep -a -v "^X-CRM114" | crm -u $HOME/.crm114/ /usr/share/crm114/ma\ilfilter.crm --stats_only`
1044
1045 xfilter "formail -I \"X-CRM114-Score: $CRMSCORE\""
1046
1047 if ($CRMSCORE < -1)
1048 {
1049 xfilter "formail -I \"X-CRM114-Spam: yes\""
1050 }
1051
1052 log "Spam: $CRMSCORE"
1053
1054 if (/^X-CRM114-Spam: yes/)
1055 {
1056 to Mail/spam/inbox
1057 }
1058
1059 ----------------------------------------------------------------------------
1060 ----------------------------------------------------------------------------
1061
1062
1063 Advanced Topic: Huge Emails and Denial Of Service Avoidance
1064
1065 CRM114 has a number of built-in anti-Denial-of-Service (anti-DoS)
1066 features; one of them is that it will not grow buffers beyond a
1067 certain limit, No Matter What. This default maximum is altered
1068 with the -w parameter.
1069
1070 However, you may find that you actually recieve emails bigger than
1071 this limit. In these cases, it is effective to simply filter on
1072 the first few tens of kilobytes of incoming text; that will speed
1073 things up a lot.
1074
1075 [[ Obsolescence note: CRM114 builds prior to about 20050601 need the
1076 method described below. After that, mailfilter has the built-in
1077 option :decision_length: in mailfilter.cf which defaults to 16000 chars ]]
1078
1079 This is easy to do with "head". head -c 10000 gives the first 10,000
1080 characters of input, which is usually adequate for CRM114 to get a
1081 good decision on. This can be directly piped in right in the procmail
1082 command:
1083
1084 :0fw: .msgid.lock
1085 | head -c 10000 | /usr/bin/crm -u /home/my_user_directory mailfilter.crm
1086
1087 :0:
1088 * ^X-CRM114-Status: SPAM.*
1089 mail/crm-spam
1090
1091
1092
1093 -----
1094
1095 Step 5 Method B: The .forward hook file
1096
1097 For .forward hook users you should be aware that you should NOT put a
1098 direct link to crm in /etc/smrsh; since crm can do arbitrary things,
1099 (such as SYSCALL to invoke any command, it'd be like putting BASH
1100 there) you ought to attempt to control the damage as much as possible.
1101
1102 1) add a link from /etc/smrsh to crm114's executable binary in
1103 /usr/bin by becoming root and typing:
1104
1105 cat > /etc/smrsh/crmfilter
1106 /usr/bin/crm mailfilter.crm >> /var/spool/mail/your_account_name_here
1107 ^D
1108
1109 2) add a .forward file to your account by typing:
1110
1111 cat > .forward
1112 |/etc/smrsh/crmfilter
1113 ^D
1114
1115 That's all. The mailfilter should now be active - send yourself a test
1116 message and see where it ends up.
1117
1118 ----
1119
1120 Once you have engaged CRM114 mailfilter, you now get to train it to
1121 recognize spam and nonspam. Proceed to "Step 6: Training CRM114".
1122
1123 Note: CRM114 contains a design decision that you may have to play
1124 with. Instead of doing memory management games, which both consume
1125 significant runtime CPU as well as present a major denial-of-service
1126 opportunity, CRM114 has an upper limit on the window size and it simply
1127 won't exceed that limit (it gives an error message if an incoming
1128 message tries to exceed the limit)
1129
1130 You -can- change the maximum memory limit at runtime with the -w nnnnn
1131 flag; for example, if you want 100 megabytes of memory available, you can
1132 set that with
1133
1134 ... -w 100000000
1135
1136 to set 100,000,000 bytes as the hard limit ceiling on per-buffer memory
1137 usage. Actual usage may be about five times that number, as CRM114 does
1138 a buffer-shuffling dance to minimize time spent reclaiming and
1139 compactifying memory.
1140
1141 ---------------------------------------------------------------------------
1142
1143
1144 Step 6: Training CRM114 and Mailfilter
1145
1146 One of the great strengths of CRM114 Mailfilter is that it has no
1147 preconcieved notions of "spam" and "nonspam". It _learns_ what you
1148 consider spam, and what you consider nonspam.
1149
1150 For the first few days CRM114 will make a lot of mistakes sorting
1151 spam and nonspam. It is _very_ important that you train each mistake
1152 back into CRM114, otherwise it will never learn what you consider spam
1153 or nonspam.
1154
1155 You should train in the mistake as quickly as possible. Start one
1156 morning and try to train every hour for the first few hours at least.
1157 Don't think you're training a computer- pretend you're housebreaking a
1158 new puppy.
1159
1160 You train mistakes right from your mail reader. There are several ways
1161 to do this. Note that you can use mailfilter.crm _or_ mailreaver.crm
1162 interchangeably here; the instructions say "mailfilter.crm" but
1163 mailreaver.crm works exactly the same way from the user point of view.
1164
1165 * Mail-to-Myself with In-Line Commands to retrain (Method A)
1166 * shell commands to retrain (Method B)
1167 * Mutt direct interface (Method C)
1168 * Some Other Interface (Method D)
1169
1170
1171
1172 Whatever Way You Train : try to train _approximately_ equal amounts of spam and
1173 nonspam. If you are within 50% one way or the other, performance will
1174 be very good.
1175
1176 If you are running mailfilter.crm:
1177
1178 Train only errors! This is called TOE training. (TOE :== Train Only
1179 Errors) It's not necessary to train near-misses; experiments show that
1180 the performance increase on training near misses is miniscule at best,
1181 and may be negative at times.
1182
1183 If you are running mailreaver.crm:
1184
1185 Some messages may come through with a header that says "I am unsure
1186 about this message. Please train it either way." - so do exactly
1187 that. This is one reason mailreaver learns faster than mailtrainer,
1188 and why it's also more accurate.
1189
1190 It's best for at least the first day or so that you check your mail at
1191 least every hour or so and send training information back to CRM114.
1192 This will help it rapidly converge on a good set of statistics for
1193 your particular mix of spam and nonspam.
1194
1195 It will take several days worth of errors for CRM114's mailfilter to
1196 approach 95% accuracy, and around two weeks to a month to reach 99+
1197 per cent accuracy. I usually exceed 99.9% accuracy (less than one
1198 error per thousand).
1199
1200
1201
1202 Step 6 Method A: Mail-to-Myself
1203
1204 The first way is to use the in-line command feature. Just forward
1205 the mistake back to yourself, with full headers (except edit out any
1206 CRM114-added headers or text).
1207
1208 Just before the first line of the text to be "learned" as spam or
1209 nonspam insert a COMMAND line. Everything from the command
1210 line to the end of the message will be learned (so edit the text
1211 to remove things you _don't_ want considered indicative of spam/nonspam
1212 nature).
1213
1214 The command line looks like this:
1215
1216 command <yoursecretpassword> spam
1217 or
1218 command <yoursecretpassword> nonspam (for mailfilter.crm)
1219 command <yoursecretpassword> good (for mailreaver.crm)
1220
1221 The "c" in "command" must be in column 1, and you must put your
1222 secret password into the command line. Don't use the <> brackets,
1223 use JUST your secret password.
1224
1225 Examples: If your secret password was "Ihatespam", then the command line
1226 to learn something as spam would be:
1227
1228 command Ihatespam spam
1229
1230 and the command to learn something as nonspam would be:
1231
1232 command Ihatespam nonspam (for mailfilter.crm users)
1233 or
1234 command Ihatespam good (for mailreaver.crm users)
1235
1236 [[ Mailreaver users: if you have the cache enabled (which is the
1237 default) and the message you mail to yourself contains an intact SFID
1238 (Spam Filter ID), either in the Message-Id: field or in the
1239 X-CRM114-CacheID: field, then you don't need to worry about editing
1240 the text so that extra headers, footers, etc. are removed. The
1241 cached version of the message is saved during the first time the
1242 message was seen by mailreaver, and so headers, footers, etc. that
1243 are added by your MDA or MUA or other stuff will NOT affect
1244 accuracy. ]]
1245
1246
1247 If you are a mailreaver user, you also have a priority system you can
1248 access, either by editing your priolist.mfp file directly or by
1249 sending youself email in the following forms (where mypwd is the
1250 command passworda_regex_pattern is what will be used for priority
1251 matching. Priority matches can occur in both the headers and body of
1252 the text.)
1253
1254 command mypwd maxprio +a_regex_pattern - sets a maximum priority GOOD
1255 command mypwd maxprio -a_regex_pattern - sets a maximum priority SPAM
1256 command mypwd minprio +a_regex_pattern - sets a maximum priority GOOD
1257 command mypwd minprio -a_regex_pattern - sets a maximum priority SPAM
1258 command mypwd delprio a_regex_pattern - deletes the first priority
1259 list entry that fully matches
1260 the regex pattern
1261
1262
1263
1264
1265
1266 Step 6 Method B: Shell commands to retrain
1267
1268 >> For mailfilter users (mailreaver is different - skip to below! <<
1269
1270 The second way to train in spam and nonspam is to use mailfilter.crm's
1271 shell command line options. When you find a spam that was mistakenly
1272 accepted as good mail, pipe it through mailfilter.crm with the
1273 "--learnspam" flag set, like this:
1274
1275 bash> mailfilter.crm --learnspam < the_spam.txt
1276
1277 Likewise, if you get an email that was falsely classified as a spam,
1278 pipe it through mailfilter with the "--learnnonspam" flag set, like
1279 this:
1280
1281 bash> mailfilter.crm --learnnonspam < the_NON_spam.txt
1282
1283 (yes, if you have a scriptable mail reader, you can put these
1284 functions right on the menu bars somewhere. Yes, that's a hint. :) )
1285
1286 [[ If you are using mailreaver.crm instead of mailfilter.crm, and
1287 cacheing is enabled, you don't even need to pipe in the full text in,
1288 all that's needed is either the intact X-CRM114-CacheID: line or the
1289 Message-ID line containing an intact sfid. That's another reason to
1290 switch to mailreaver! :) ]]
1291
1292 >> For mailreaver.crm users <<
1293
1294 You're in luck, assuming you have taken the default and left cacheing
1295 turned on. All you need to pipe into mailreaver for training is any
1296 text or text fragment containing an intact X-CRM114-CacheID: line or
1297 the Message-ID line containing an intact sfid; mailreaver will go get
1298 the exact incoming text of the message and train it, so you don't need
1299 to worry about munged headers.
1300
1301 The command looks like this:
1302
1303 crm mailreaver.crm [options] < some_text.txt
1304
1305 The command options you have available in mailreaver command line are:
1306
1307 --spam - train the incoming text as SPAM (if there's a
1308 recognizable cacheid, use the cached msg).
1309
1310 --good - train the incoming text as GOOD (if there's a
1311 recognizable cacheid, use the cached msg).
1312
1313 --cache - default is to train using the text stored
1314 in the reavercache. Use --cache=NO to *not*
1315 use the cached version, if for some reason you
1316 don't want to.
1317
1318 --dontstore - default is that every incoming message that isn't
1319 a training message (that is, --spam or --good) is
1320 put into the cache. Use --dontstore to not put
1321 into the cache (for example, "seekrit" users who
1322 aren't allowed to train or who might get msgs
1323 that you don't want archived).
1324
1325 --stats_only - Don't do a full report or forwarding, just
1326 report the pR value on stdout. This is a value
1327 between (roughly) -1000 and +1000 where negative
1328 values indicate spammyness and positive values
1329 indicate goodness. For a simple test, just look
1330 at the first nonblank character. If it's a "-"
1331 sign, the input was spam. Because there's no
1332 other output, --stats_only forces --dontstore.
1333
1334 --outbound This message is "outbound" - that is, known to
1335 be good. If it would classify as spam, train
1336 and cache it. Otherwise, no action.
1337
1338 --undo To the extent possible, undo a training with this
1339 text (cached will be used if possible). --undo
1340 requires either --spam or --good as well.
1341
1342 --fileprefix=dir Assume that the config file "mailfilter.cf"
1343 and the .css files are in directory "dir".
1344 Remember to use a final closing slash on the
1345 directory name, e.g. /my/home/dir1/ instead
1346 of /my/home/dir1. Otherwise, the filename will
1347 be spliced together from the last component
1348 of your --fileprefix and the nominal names,
1349 and you almost certainly don't want that.
1350
1351 --config=file Don't use mailfilter.cf as the configuration
1352 file; instead use the file so noted.
1353
1354
1355
1356
1357 Part 6 Method C: For Mutt Users
1358
1359 (Contributed by Mathieu Doidy and Joost van Baal:)
1360
1361 In your ~/.muttrc, put:
1362
1363 macro index \es "<pipe-entry>crmlearn --learnspam\n<save-entry>=spam/done\n" \"crm114 learn as spam, save in spam/done"
1364 macro index \eh "<pipe-entry>crmlearn --learnnonspam\n" "crm114 learn as ham"
1365
1366 where crmlearn is this script
1367
1368 grep -a -v "^X-CRM114" | \
1369 /usr/share/crm114/mailfilter.crm -u $HOME/.crm114/ $1 | \
1370 grep -a "^X-CRM114"
1371
1372 Now you have two new macros in the Mutt index menu:
1373
1374 * esc-s will tag a message, falsely classified as ham, as spam,
1375 * esc-h will tag a message, falsely classified as spam, as ham.
1376
1377
1378
1379 Part 6 Method D: Some Other Method
1380
1381
1382 There are at least five other ways to retrain CRM114. Some interface
1383 with common mail readers, some are command line tricks.
1384
1385 Rather than catalog them here (which would quickly go out of date) you
1386 should go to the CRM114 web page (crm114.sourceforge.net) and browse
1387 the list of applications under "Cool Stuff".
1388
1389 Some of these are plugins, some are web-based MUAs, and some
1390 are entirely new mail filters.
1391
1392
1393 What To Do if CRM114 says "LEARNING UNNECESSARY..."
1394 ---------------------------------------------------
1395
1396 Occasionally, some CRM114 configurations may refuse to learn an
1397 errror, claiming that it "got it right the first time" (yes, this is a
1398 subtle bug that is not allowing itself to be found, but there is
1399 reason to believe it has to do with the interaction of mail clients
1400 and headers and that some mail readers are lying to the user when they
1401 claim they are forwarding with full headers).
1402
1403 While we applaud this self confidence, the error is still there, so
1404 you need to "force" the learning. You can do this either from BASH or
1405 from the mail-to-yourself command line. For BASH, add "--force" to
1406 the command line; for mail-to-yourself commands, just add "force"
1407
1408 From BASH, add --force to the command line:
1409
1410 # mailfilter.crm < the_error_text --learnspam --force
1411
1412 for mail-to-yourself, add "force" to the command line:
1413
1414 command mysecretpassword spam force
1415
1416 (and similarly for nonspam).
1417
1418
1419
1420 The training files "spamtext.txt" and "nonspamtext.txt"
1421 ------------------------------------------------------
1422
1423 [[ Note: this section is becoming obsoleted by the
1424 reavercache, which does more, better, and easier. ]]
1425
1426 Whenever CRM114 learns a new spam or nonspam, it not only modifies
1427 the .css files, but it also keeps the source text of that learning
1428 in the files "spamtext.txt" or "nonspamtext.txt".
1429
1430 These two files can be considered the "source code" of your .css
1431 files; they're all you really need to rebuild your .css files if/when
1432 you upgrade CRM114 and the .css file is changed but the algorithm is
1433 similar. For example, upgrading from Markovian filtering (the
1434 default) to Winnow or OSBF is "incompatible", and you might want to
1435 start with these files as a kickstart.
1436
1437 ... but not necessarily; some filtering is radically different than
1438 Markovian; as we add new filters as technology moves forward,
1439 sometimes we will be able to kickstart, and sometimes we can't.
1440
1441 - for upgrades that can use the current .css files, we will say so;
1442
1443 - for upgrades that cannot use the current .css files, but *can*
1444 get kickstarted from spamtext.txt and nonspamtext.txt, we will
1445 say so;
1446
1447 - for upgrades that are radically different enough that you must
1448 relearn from scratch, we will say so (and have you rename your
1449 old spamtext and nonspamtext files so that they will not be
1450 accidentally reused.
1451
1452 If your mail system is so short of disk that you cannot afford to keep
1453 these (relatively) small files, then you may either delete them or
1454 symlink these files to /dev/null; you don't absolutely *need* them.
1455 These files are quite small though- I have been running CRM114 for
1456 nearly five years now and my *total* example text sizes are 678 Kbytes
1457 for nonspam and 893 Kbytes for spam (after something like five years
1458 of daily use and about a gigabyte of email).
1459
1460
1461
1462 -----------------------------------------------------------------------
1463
1464
1465
1466 Step 7: Adding Priority Lists, Whitelists, and Blacklists
1467
1468 If you really want, you can add white, black, and priority lists
1469 to CRM114. Most people don't need them, but there are always
1470 exceptions.
1471
1472 [[ Note to mailreaver.crm users - mailreaver.crm uses ONLY
1473 the priolist.mfp, and does NOT support whitelist.mfp or
1474 blacklist.mfp. This really is no loss of functionality,
1475 because anything you can do with a whitelist or blacklist,
1476 you can also do with a priolist, and more besides. ]]
1477
1478 For example, your lawyer, your boss, and your paramour all probably
1479 rate being on your "whitelist", so whatever they send to you is always
1480 marked "nonspam". Likewise, your ex-girlfriend/boyfriend, your
1481 nagging acquaintance, and the stalker from the library should all get
1482 blacklisted.
1483
1484 Whitelisting, blacklisting, and prio-listing are all based on regex
1485 matching. If the regex you put in the file "whitelist.mfp" matches
1486 the incoming mail _anywhere_, the mail will be marked "good" no matter
1487 how it scores statistically. Similarly, if the mail matches any regex
1488 in "blacklist.mfp", the mail will be marked as "spam", no matter how
1489 it compares statistically.
1490
1491
1492 Note that sometimes this can cause considerable confusion, for example
1493 "ac.com" in a whitelist will not just match "billing.ac.com", but also
1494 "drac.complete.viagra.sales.com" (the match being the 'ac.com' in
1495 "drac.complete"). To prevent this, use ^ and $ to "anchor" the start
1496 and end of the regex, if possible.
1497
1498 Lastly (well, actually firstly, because prio-listing happens before
1499 whitelisting or blacklisting) any mail that matches any regex in
1500 priolist.mfp . The format of priolist.mfp is that the first character
1501 on the line is a + or a -, which indicates "whitelist" or "blacklist",
1502 and the rest of the line is a regex. These regexes are tested
1503 in the order given in the file. An empty file is perfectly acceptable.
1504
1505 For examples of how to set up the whitelist, blacklist, and priolist
1506 files, see the included "whitelist.mfp.example", "blacklist.mfp.example",
1507 and "priolist.mfp.example".
1508
1509 Note: for my accuracy tests, I *turn off* whitelists, blacklists,
1510 and prio-lists.
1511
1512 Be sure to test any whitelist, blacklist, or other list that you
1513 add, otherwise you may get a rude surprise some day.
1514
1515
1516 ----------------------------------------------------------------
1517
1518
1519 Step 8: Useful Utilities
1520
1521 You don't _need_ to know the stuff in this section to set up and use
1522 CRM114 and mailfilter or mailreaver, but it might be useful to you- or
1523 at least satisfy some of your curiosity.
1524
1525 There are three utilities for dealing with the .css files (these
1526 are the files that contain the "learned information").
1527
1528 The utilities are:
1529
1530 cssutil - gives you a readout of the characteristics of the
1531 information in a .css file
1532
1533 cssdiff - gives you a summary of the differences between two
1534 .css files (handy for seeing learning!)
1535
1536 cssmerge - merges two .css files into one; handy for importing
1537 new data into a .css file. Note that this is
1538 a destructive operation on the first .css file named!
1539
1540
1541 The cssutil utility:
1542
1543
1544 Usage is
1545
1546 cssutil somefile.css
1547
1548 which will give you statistics on the file somefile.css. You can
1549 then rescale, clip, and otherwise manage your .css files. It is especially
1550 useful to check the "Average Packing Density" of the .css files
1551 you use; when it approaches .7 to .8, you may want to consider enlarging your
1552 .css file. To do that, see below on "Enlarging a .css file"
1553
1554 Here's the -h help:
1555
1556 Usage: cssutil [-b -r] [-s css-size] cssfile
1557 -h - print this help
1558 -b - brief; print only summary
1559 -r - report then exit (no menu)
1560 -s css-size - if no cssfile found, create new
1561 cssfile with this many buckets.
1562 -S css-size - same as -s, but round up to next
1563 2^n + 1 boundary.
1564
1565
1566
1567
1568 The cssdiff utility
1569 -------------------
1570
1571 To get the difference between two .css files, use
1572
1573 ./cssdiff somefile.css anotherfile.css
1574
1575 which writes out a summary of how two different .css files are.
1576
1577
1578
1579 The cssmerge utility
1580 --------------------
1581
1582 To merge two .css files, use cssmerge .
1583
1584 ./cssmerge outfile.css infile.css
1585
1586 Note that this is _destructive_ to outfile.css, so make a copy
1587 somewhere else first. You _CAN_ merge two .css files of different
1588 length. You can also expand (or contract) a .css file this way:
1589 rename the old file, and allow a new one to be created with learnspam
1590 or learnnonspam while using the '-s nnnnnnnnn' s(lots) flag to set the
1591 number of feature slots desired in the new file. Then cssmerge your
1592 old file into the fresh new file, and all is well.
1593
1594 Here's the cssmerge help:
1595
1596 Usage: cssmerge <out-cssfile> <in-cssfile> [-v] [-s]
1597 <out-cssfile> will be created if it doesn't exist.
1598 <in-cssfile> must already exist.
1599 -v -verbose reporting
1600 -s NNNN -new file length, if needed
1601
1602
1603
1604
1605
1606 Enlarging a .css file
1607 ---------------------
1608
1609 One of the advantages of CRM114 is that the .css files are relatively
1610 small and of fixed size; they don't grow out of control and never need
1611 trimming if you use <microgroom>, which is the default.
1612
1613 The disadvantage of this is that if your spam/nonspam discrimination
1614 is too convoluted, it won't be able to sort them out ( in trek-speak
1615 this is a high-order nonlinearity in the discrimination function ).
1616 The fix in this situation is to increase the dimensionality of the
1617 feature space. The number of dimensions is about 1/12 the number of
1618 bytes in the .css files; this works well at about a million dimensions
1619 (12 megabytes) for most people.
1620
1621 But if you're not most people, you may need to (eventually) increase it.
1622 You can tell when this is necessary- running
1623
1624 cssutil
1625
1626 will give you a utilization and percentage of slots full; when that gets
1627 up near 95 percent, you may be running low on space and old features
1628 will be erased to make room for new features (that is, your feature set
1629 will dynamically evolve in real time to find what works.) However, that's
1630 slow and may cause a slight loss of accuracy.
1631
1632 One way to fix this is to "increase the dimensionality of the
1633 discrimination hyperspace" (no, I am not making that phrase up).
1634 It means to add new slots to the .css files.
1635
1636 The easiest way to do this is to
1637 1) use cssutil to create a temporary, empty, larger .css file
1638 2) merge the data from the old, small .css file onto the new big file.
1639 3) copy the new big file over the old, small file.
1640
1641 You can even combine steps 1 and 2, because newer versions of cssmerge
1642 will create a new file if needed (the -s N flag sets the number of slots
1643 in the new file; -S N does the same thing but rounds up to a 2^N+1
1644 boundary, which is recommended ).
1645
1646 For example, here's how to increase the size of the spam.css file
1647 from 1,000,001 slots (the default) to 2,000,001 slots. Just type:
1648
1649 cssmerge temporary.css spam.css -s 2000001
1650 mv temporary.css spam.css
1651
1652 The newly replaced spam.css will have all of the features of the old
1653 spam.css file, but will be 2000001 slots long instead of the default
1654 1000001 slots.
1655
1656 --------------------------------------------------------------------
1657 --------------------------------------------------------------------
1658
1659 APPENDIX 1
1660 Using mailtrainer.crm
1661
1662
1663 New (as of 20060117) is the training program mailtrainer.crm . This
1664 program will take directories of spam and nonspam files, and iterate over
1665 them to build (or improve) a set of .css files for you.
1666
1667
1668 ***** WARNING WARNING WARNING *****
1669 Mailtrainer.crm (and the documentation for it) is BETA QUALITY.
1670 There are very likely some very amusing bugs. Be warned !!!
1671 Archive your data and your .css files before using mailtrainer.crm.
1672 Really!
1673 ***** WARNING WARNING WARNING *****
1674
1675
1676 Mailtrainer by default uses whatever settings are in your current
1677 mailfilter.cf file, so you'll get .css files that are optimized for
1678 your standard setup including mime decoding, normalization, classifier
1679 flags, etc.
1680
1681 However, this means you *must* set up your mailfilter.cf file FIRST,
1682 before you run mailtrainer.
1683
1684 Mailtrainer.crm uses DSTTTTR (Double Sided Thick Threshold Training with
1685 Testing Refutation) which is something I didn't come up with (Fidelis
1686 is on my list of suspects for this). The good news is that this can
1687 more than double accuracy of OSB and similar classifiers.
1688
1689 It is safe to run mailtrainer.crm repeatedly on a .css fileset and
1690 training data; if the data doesn't need to be trained in, it won't be
1691 (unlike the old "make cssfiles" command, which forces everything in
1692 whether it is useful or not). This is a big improvement and minimizes
1693 .css file bloating. "make cssfiles" has now been fixed to use
1694 mailtrainer.crm.
1695
1696 The example files in each of the spam and good directories need to be
1697 one example per file. The closer these files are to what
1698 mailfilter.crm wil see in real life the better your training will be.
1699 Preferably the headers and text will be complete, intact, and
1700 unmutilated. The closer these examples are to what SMTP will
1701 show "on the wire" the better.
1702
1703 If you use a mail reader that puts your "good" and "spam" emails
1704 as separate files in two different directories (or can hack up a script
1705 to do that) then you could even run mailtrainer.crm automatically
1706 every night to optimize the .css files to your current profile.
1707 If you do this, your script needs to gaurd against situations where
1708 you haven't checked your mail in a few days and errors crept in; for
1709 safety your script should only add the files to the training directories
1710 until you have hand-checked them (or at least tacitly agreed).
1711
1712 If you find you've made a mistake, don't worry. It's recoverable.
1713 Just put the misplaced files into the correct directory and rerun
1714 mailtrainer.crm . That will re-optimize the .css files (though some
1715 low-value features may be swept away).
1716
1717 Alternatively, if you start out keeping each and every file that
1718 you've trained, you can just delete the erroneous spam.css and nonspam.css
1719 files and re-run mailtrainer.crm to get correct .css files.
1720
1721 It's OK to have the spam and good directories just be full of links
1722 (either symlinks or hardlinks) to the actual spam and good mail files
1723 (that's what I do).
1724
1725 NOTE: mailfilter.crm doesn't (yet) understand how to build and maintain
1726 the spam and good email directories.
1727
1728 NOTE 2: It is at this point unknown whether it's a good idea or a bad
1729 idea to run mailtrainer on the probably good and probably bad emails
1730 (which end up in the reaver cache as .../prob_good/whatever and
1731 .../prob_spam/whatever, or just on those that are in the thick
1732 threshold zone. If anyone gets good data on this, let me know please.
1733
1734
1735 ----- Mailtrainer Options ---
1736
1737 The mailtrainer.crm options are as follows. You *must* provide --spam
1738 and --good; the other flags are optional.
1739
1740 Required:
1741 --spam=/directory/full/of/spam/files/one/per/file
1742 --good=/directory/full/of/good/files/one/per/file
1743 These define the directories or files to be
1744 learned. If these end with a slash, it means a
1745 directory and all of the files within are used,
1746 otherwise, it's taken as a file. If the
1747 filename contains a wildcard, be sure to enclose
1748 it in singlequotes 'like.this' or else BASH will
1749 do bad things to it. Note that this is
1750 (currrently) incompatible with the --random
1751 shuffling of training order.
1752
1753 Optional:
1754 --help - quick synopsys of mailtrainer options.
1755
1756 --thick=N - thickness for thick-threshold training- this
1757 overrides the thickness in your mailfilter.cf file.
1758 Omit it if you want to use the in-file value.
1759 (10 works well for most classifiers; use 0.1
1760 or less for Hyperspace)
1761
1762 --streak=N - how many successive correct classifications
1763 before we conclude we're done. Default is 10000.
1764 This number should be larger than the total number
1765 of sample emails.
1766
1767 --repeat=N - how many passes should we go through this corpus
1768 before we conclude we're done. Default is 1
1769
1770 --worst=N - run the entire training set, then train
1771 only the N worst offenders, and repeat. This is
1772 excruciatingly slow but produces very compact
1773 .css files. Use this only if your host machine
1774 is dreadfully short of memory. Default is NOT
1775 to use worst-offender training. N=5% of your total
1776 corpus works pretty well, but N=1 will produce
1777 the most compact .css files.
1778
1779 --random - randomize the training set rather than taking the
1780 files in sequential alternating order (one from good,
1781 then one from spam). Note that this is (currently)
1782 incompatible with a wildcard for selection of good
1783 versus spam files.
1784
1785 --reload - if we run out of one kind of file (good or spam)
1786 before the other, "reload" (start from the first
1787 file again) in that category. Default is to
1788 simply use only the remaining category for the
1789 remainder of the training pass.
1790
1791 --verbose - Verbose. Print out more stuff.
1792
1793 --fileprefix=directory - use the mailfilter.cf, rewrites.mfp,
1794 and .css files in 'directory', rather
1795 than in the current directory.
1796
1797 --goodcss=somecssfile.css - use this 'good' cssfile instead of
1798 the default "nonspam.css"
1799
1800 --spamcss=somecssfile.css - use this 'spam' cssfile instead of
1801 the default "spam.css"
1802
1803 --collapse - collapse the flying output down to scroll less on a TTY.
1804
1805 --report_header="some text" - put this at the head of the report
1806
1807 --rfile="somefilename.txt" - append (not overwrite!) log to this file.
1808
1809 --validate=regex_no_slashes - Any file with a name that matches
1810 the regex supplied is not used for training; instead
1811 it's held back and used for validation of the
1812 new .css files. The result will give you an
1813 idea of how well your .css files will work.
1814 Do NOT put slashes around the regex!
1815
1816
1817 Example 1:
1818
1819 - We want to create new .css files for our mail filter
1820 - We already have presorted directories of good and spam email
1821 - We have already set up mailfilter.cf and rewrites.mfp to define
1822 our preferred configuration,
1823
1824 Then we can use the following incantation to build some nice .css
1825 files (not perfect, but not bad). This incantation can all be on one
1826 line (remove the '\' backslash characters if you put it on one line),
1827 and don't forget the trailing slash for directory names; otherwise
1828 mailtrainer will try to train the directory listing itself (and fail,
1829 because a directory can't be read like a normal file).
1830
1831 Note that you *must* set up your mailfilter.cf and rewrites.mfp files
1832 first, before doing this, otherwise you'll generate bad .css files,
1833 or possibly get an error!
1834
1835 crm mailtrainer.crm \
1836 --good=/your/good/files_dir/ \
1837 --spam=/your/spam/files_dir/ \
1838 --repeat=5 \
1839 --random
1840
1841
1842 Example 2:
1843
1844 - We want to run mailtrainer.crm against a bunch of examples in the
1845 directory ../SA2/spam/ and ../SA2/good/. (This happens to be where
1846 the TREC test set is on my computer- your location will be different)
1847 - We want to quit when we get 4000 tests in a row correct, or if
1848 we go through the entire corpus 5 times.
1849 - We want to use DSTTTR, with a training thickness of 5 pR
1850 units.
1851 - We want to "validate" our training - that is, to hold back some fraction
1852 of the training set as test cases. In our case here, we decide we want to
1853 use any file name that contains a "*3.*" . These files will be
1854 saved up and used as a test corpus instead of for training.
1855
1856 Here's the command (this can all be on one line as well; if so,
1857 remove the backslashes):
1858
1859 crm mailtrainer.crm \
1860 --spam=../SA2/spam/ \
1861 --good=../SA2/good/ \
1862 --repeat=5 \
1863 --streak=4000 \
1864 --validate=[3][.] \
1865 --thick=5.0
1866
1867 This will take about eight minutes to run on the TREC 2005 SA corpus
1868 of about 6000 messages; 1000 messages a minute is a good estimate
1869 for 5 passes of DSTTTTR training.
1870
1871
1872 Notes:
1873
1874 * If the .css statistics files don't exist, they will be created for
1875 you, in the format set up by the mailfilter.cf file. So- be SURE to
1876 set up mailfilter.cf first!
1877
1878 * If the first test file comes back with a pR of 0.0000 exactly, it is
1879 assumed that these are empty .css statistics files, and that ONE file
1880 will be trained in to each .css file that returns a 0.0000, simply to
1881 get the system "off center" enough that normal training can occur. If
1882 there is anything already in the files, this won't happen.
1883
1884 * When running N-fold validation, if the filenames are named as in the
1885 SA2 corpus in a form of 00123.456789 , there's an easy trick to
1886 partition the data into 10 roughly equal sets. Just use a validation
1887 regex like [0][.] for the first run, [1][.] for the second run, [2][.]
1888 for the third, and so on. Notice that this a CRM114-style regex, and
1889 _not_ a BASH-style file globbing as "*3.*" would be. If you use a
1890 globbing regex like "*3.*" , then BASH will suck it in and expand it
1891 in-line to all of the individual filenames and that won't work. A
1892 regex like [chars] is invisible to BASH and so will pass unscathed.
1893
1894 * If you want to run N-fold validation, you must remember to delete
1895 and rebuild a fresh set of .css files after each run, otherwise you
1896 will not get valid results.
1897
1898 * N-fold validation does NOT run training at all on the validation set,
1899 so if you decide you like the results, you can do still better by
1900 running mailtrainer.crm once again, but DO NOT specify --validate.
1901 That will train in the validation test set as well, and hopefully
1902 improve your accuracy still more.
1903
1904
1905
1906 ---------------------------------------------------------------------
1907
1908 That's all! If you have errors or updates (or find bugs!) please
1909 let me know; the best way is to join the CRM114-general mailing list; it's
1910 on the webpage:
1911
1912 http://crm114.sourceforge.net
1913
1914 and ask there. The reason for using the mailing list rather than
1915 personal email is that personal email isn't archived, but the mailing
1916 list _is_ both archived and read widely, so we not only create a
1917 background archive of solutions but you will get a better answer back
1918 faster than if you sent the email to me alone.
1919
1920 Enjoy, and good luck.
1921
1922 -Bill Yerazunis