-
Notifications
You must be signed in to change notification settings - Fork 1
/
mailfilter.cl
124 lines (106 loc) · 3.57 KB
/
mailfilter.cl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
(in-package :user)
;; Set this to `t' and run `folderfilter -d +inbox' to see which rules fire
;; for a particular message.
;;
(defparameter *ruletest-debug* nil)
;; This variable governs the order of folders in the *Inboxes* buffer, and
;; allows headers for it to be specified.
;;
(defparameter *mailstatus-inbox-folder-order*
'("gmail"
"spam"
"junk"
:newline
(:header "*********** TODO inboxes ********************")
"a"
"q"
"home"
"tget"
"fin"
"todo"
"sa"
"pbx"
"adrian"
"medical"
"someday"
"pend"
:newline
(:header "*********** Hobby inboxes********************")
"music"
"photo"
"fun"
"travel"
:newline
(:header "*********** Mailing list inboxes ************")
"zfs"
"emacs"
"git"
"blink"
"gnus"
"cygwin"
"mh"
"nmh"
"ps"
))
(defvar *whitelist*
'(("suzanne")))
(defvar *me* '("layer" "Layer"))
(defmacro ruletest (number folder form)
(when (not (numberp number))
(error "ruletest: `number' should be a number: ~s." number))
`(progn
(when (not (stringp ,folder))
(error "ruletest: `folder' should be a string: ~s." ,folder))
(if* ,form
then (when *ruletest-debug*
(format t " rule ~A: returning ~A~%" ,number ,folder))
(return ,folder)
else (when *ruletest-debug*
(format t " rule ~A: no match~%" ,number)))))
(defclassification (minfo)
(let* ((headers (msginfo-headers minfo))
(subject (msginfo-subject minfo))
(bhid (or (msginfo-bhid minfo)
(extract-bhid-from-subject subject)))
(spam-flag (get-header "X-Spam-Flag" headers :null-string t)))
(add-header "X-Touched-By-Incfilter" "v1.0 lisp")
;; This is for an as yet unused way of sorting my inbox. Not sure
;; where it will go or even if it will work...
#+ignore ;; never completed... don't do it
(when (not (get-header "X-Priority" headers))
(add-header "X-DKL-Priority" "50"))
(ruletest 50 "+inbox-spam" (string= spam-flag "YES"))
(ruletest 60 "+inbox-gmail"
(or (to-one-of "someone.*@gmail.com")
(to-one-of "someoneelse.*@gmail.com")))
(let ((dest-folder (and subject (message-in-conversation-p subject bhid))))
#+ignore ;; debugging
(format t "conversation ~a ~a~% => ~s~%"
subject bhid
dest-folder)
(when dest-folder
(ruletest 70 dest-folder dest-folder)))
(ruletest 100 "+inbox" (from-one-of *whitelist*))
(ruletest 110 "+inbox-ps" (to-one-of "[email protected]"))
(ruletest 120 "+inbox-blink" (to-one-of "[email protected]"))
(ruletest 130 "+inbox-emacs" (to-one-of "[email protected]"))
(ruletest 140 "+inbox-nmh" (to-one-of "nmh.*@nongnu.org"))
(ruletest 150 "+inbox-samba" (to-one-of "[email protected]"))
(ruletest 160 "+inbox-gnus" (to-one-of "[email protected]"))
(ruletest 170 "+inbox-cygwin"
(or (to-one-of "[email protected]")
(to-one-of "[email protected]")
(to-one-of "[email protected]")))
(ruletest 180 "+inbox-zfs"
(or (to-one-of "[email protected]")
(to-one-of "[email protected]")))
(ruletest 190 "+inbox-junk"
(and (to-one-of "[email protected]")
(subject-match "\\[[^[]*PATCH")))
(ruletest 200 "+inbox-git" (to-one-of "[email protected]"))
"+inbox"))
;;; For Gnu Emacs.
;;; Local Variables: ***
;;; eval: (put 'ruletest 'fi:common-lisp-indent-hook 2) ***
;;; eval: (put 'defclassification 'fi:common-lisp-indent-hook 1) ***
;;; End: ***