Mercurial > emacs
comparison lisp/gnus/gnus-logic.el @ 88155:d7ddb3e565de
sync with trunk
author | Henrik Enberg <henrik.enberg@telia.com> |
---|---|
date | Mon, 16 Jan 2006 00:03:54 +0000 |
parents | a26d9b55abb6 |
children |
comparison
equal
deleted
inserted
replaced
88154:8ce476d3ba36 | 88155:d7ddb3e565de |
---|---|
1 ;;; gnus-logic.el --- advanced scoring code for Gnus | 1 ;;; gnus-logic.el --- advanced scoring code for Gnus |
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000 | 2 |
3 ;; Free Software Foundation, Inc. | 3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, |
4 ;; 2005 Free Software Foundation, Inc. | |
4 | 5 |
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> | 6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> |
6 ;; Keywords: news | 7 ;; Keywords: news |
7 | 8 |
8 ;; This file is part of GNU Emacs. | 9 ;; This file is part of GNU Emacs. |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 ;; GNU General Public License for more details. | 19 ;; GNU General Public License for more details. |
19 | 20 |
20 ;; You should have received a copy of the GNU General Public License | 21 ;; You should have received a copy of the GNU General Public License |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | 22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
23 ;; Boston, MA 02111-1307, USA. | 24 ;; Boston, MA 02110-1301, USA. |
24 | 25 |
25 ;;; Commentary: | 26 ;;; Commentary: |
26 | 27 |
27 ;;; Code: | 28 ;;; Code: |
28 | 29 |
57 (eval-and-compile | 58 (eval-and-compile |
58 (autoload 'parse-time-string "parse-time")) | 59 (autoload 'parse-time-string "parse-time")) |
59 | 60 |
60 (defun gnus-score-advanced (rule &optional trace) | 61 (defun gnus-score-advanced (rule &optional trace) |
61 "Apply advanced scoring RULE to all the articles in the current group." | 62 "Apply advanced scoring RULE to all the articles in the current group." |
62 (let ((headers gnus-newsgroup-headers) | 63 (let (new-score score multiple) |
63 gnus-advanced-headers score) | 64 (dolist (gnus-advanced-headers gnus-newsgroup-headers) |
64 (while (setq gnus-advanced-headers (pop headers)) | 65 (when (setq multiple (gnus-advanced-score-rule (car rule))) |
65 (when (gnus-advanced-score-rule (car rule)) | 66 (setq new-score (or (nth 1 rule) |
66 ;; This rule was successful, so we add the score to | 67 gnus-score-interactive-default-score)) |
67 ;; this article. | 68 (when (numberp multiple) |
69 (setq new-score (* multiple new-score))) | |
70 ;; This rule was successful, so we add the score to this | |
71 ;; article. | |
68 (if (setq score (assq (mail-header-number gnus-advanced-headers) | 72 (if (setq score (assq (mail-header-number gnus-advanced-headers) |
69 gnus-newsgroup-scored)) | 73 gnus-newsgroup-scored)) |
70 (setcdr score | 74 (setcdr score |
71 (+ (cdr score) | 75 (+ (cdr score) new-score)) |
72 (or (nth 1 rule) | |
73 gnus-score-interactive-default-score))) | |
74 (push (cons (mail-header-number gnus-advanced-headers) | 76 (push (cons (mail-header-number gnus-advanced-headers) |
75 (or (nth 1 rule) | 77 new-score) |
76 gnus-score-interactive-default-score)) | |
77 gnus-newsgroup-scored) | 78 gnus-newsgroup-scored) |
78 (when trace | 79 (when trace |
79 (push (cons "A file" rule) | 80 (push (cons "A file" rule) |
81 ;; Must be synced with `gnus-score-edit-file-at-point'. | |
80 gnus-score-trace))))))) | 82 gnus-score-trace))))))) |
81 | 83 |
82 (defun gnus-advanced-score-rule (rule) | 84 (defun gnus-advanced-score-rule (rule) |
83 "Apply RULE to `gnus-advanced-headers'." | 85 "Apply RULE to `gnus-advanced-headers'." |
84 (let ((type (car rule))) | 86 (let ((type (car rule))) |
114 gnus-advanced-headers | 116 gnus-advanced-headers |
115 (if (string-match "^\\([0-9]+\\)-$" (symbol-name type)) | 117 (if (string-match "^\\([0-9]+\\)-$" (symbol-name type)) |
116 ;; 1- type redirection. | 118 ;; 1- type redirection. |
117 (string-to-number | 119 (string-to-number |
118 (substring (symbol-name type) | 120 (substring (symbol-name type) |
119 (match-beginning 0) (match-end 0))) | 121 (match-beginning 1) (match-end 1))) |
120 ;; ^^^ type redirection. | 122 ;; ^^^ type redirection. |
121 (length (symbol-name type)))))) | 123 (length (symbol-name type)))))) |
122 (when gnus-advanced-headers | 124 (when gnus-advanced-headers |
123 (gnus-advanced-score-rule (nth 1 rule))))) | 125 (gnus-advanced-score-rule (nth 1 rule))))) |
124 ;; Plain scoring rule. | 126 ;; Plain scoring rule. |
127 ;; Bug-out time! | 129 ;; Bug-out time! |
128 (t | 130 (t |
129 (error "Unknown advanced score type: %s" rule))))) | 131 (error "Unknown advanced score type: %s" rule))))) |
130 | 132 |
131 (defun gnus-advanced-score-article (rule) | 133 (defun gnus-advanced-score-article (rule) |
132 ;; `rule' is a semi-normal score rule, so we find out | 134 ;; `rule' is a semi-normal score rule, so we find out what function |
133 ;; what function that's supposed to do the actual | 135 ;; that's supposed to do the actual processing. |
134 ;; processing. | |
135 (let* ((header (car rule)) | 136 (let* ((header (car rule)) |
136 (func (assoc (downcase header) gnus-advanced-index))) | 137 (func (assoc (downcase header) gnus-advanced-index))) |
137 (if (not func) | 138 (if (not func) |
138 (error "No such header: %s" rule) | 139 (error "No such header: %s" rule) |
139 ;; Call the score function. | 140 ;; Call the score function. |
160 (error "No such string match type: %s" type))))) | 161 (error "No such string match type: %s" type))))) |
161 | 162 |
162 (defun gnus-advanced-integer (index match type) | 163 (defun gnus-advanced-integer (index match type) |
163 (if (not (memq type '(< > <= >= =))) | 164 (if (not (memq type '(< > <= >= =))) |
164 (error "No such integer score type: %s" type) | 165 (error "No such integer score type: %s" type) |
165 (funcall type match (or (aref gnus-advanced-headers index) 0)))) | 166 (funcall type (or (aref gnus-advanced-headers index) 0) match))) |
166 | 167 |
167 (defun gnus-advanced-date (index match type) | 168 (defun gnus-advanced-date (index match type) |
168 (let ((date (apply 'encode-time (parse-time-string | 169 (let ((date (apply 'encode-time (parse-time-string |
169 (aref gnus-advanced-headers index)))) | 170 (aref gnus-advanced-headers index)))) |
170 (match (apply 'encode-time (parse-time-string match)))) | 171 (match (apply 'encode-time (parse-time-string match)))) |
187 'gnus-request-head) | 188 'gnus-request-head) |
188 ((string= "body" header) | 189 ((string= "body" header) |
189 'gnus-request-body) | 190 'gnus-request-body) |
190 (t 'gnus-request-article))) | 191 (t 'gnus-request-article))) |
191 ofunc article) | 192 ofunc article) |
192 ;; Not all backends support partial fetching. In that case, | 193 ;; Not all backends support partial fetching. In that case, we |
193 ;; we just fetch the entire article. | 194 ;; just fetch the entire article. |
194 (unless (gnus-check-backend-function | 195 (unless (gnus-check-backend-function |
195 (intern (concat "request-" header)) | 196 (intern (concat "request-" header)) |
196 gnus-newsgroup-name) | 197 gnus-newsgroup-name) |
197 (setq ofunc request-func) | 198 (setq ofunc request-func) |
198 (setq request-func 'gnus-request-article)) | 199 (setq request-func 'gnus-request-article)) |
199 (setq article (mail-header-number gnus-advanced-headers)) | 200 (setq article (mail-header-number gnus-advanced-headers)) |
200 (gnus-message 7 "Scoring article %s..." article) | 201 (gnus-message 7 "Scoring article %s..." article) |
201 (when (funcall request-func article gnus-newsgroup-name) | 202 (when (funcall request-func article gnus-newsgroup-name) |
202 (goto-char (point-min)) | 203 (goto-char (point-min)) |
203 ;; If just parts of the article is to be searched and the | 204 ;; If just parts of the article is to be searched and the |
204 ;; backend didn't support partial fetching, we just narrow | 205 ;; backend didn't support partial fetching, we just narrow to |
205 ;; to the relevant parts. | 206 ;; the relevant parts. |
206 (when ofunc | 207 (when ofunc |
207 (if (eq ofunc 'gnus-request-head) | 208 (if (eq ofunc 'gnus-request-head) |
208 (narrow-to-region | 209 (narrow-to-region |
209 (point) | 210 (point) |
210 (or (search-forward "\n\n" nil t) (point-max))) | 211 (or (search-forward "\n\n" nil t) (point-max))) |
225 (funcall search-func match nil t) | 226 (funcall search-func match nil t) |
226 (widen))))))) | 227 (widen))))))) |
227 | 228 |
228 (provide 'gnus-logic) | 229 (provide 'gnus-logic) |
229 | 230 |
231 ;;; arch-tag: 9651a100-4a59-4b69-a55b-e511e67c0f8d | |
230 ;;; gnus-logic.el ends here | 232 ;;; gnus-logic.el ends here |