Mercurial > emacs
annotate lisp/gnus-kill.el @ 17740:edebe056f7bc
Doc fix: CR is \015, not \013.
author | Paul Eggert <eggert@twinsun.com> |
---|---|
date | Sun, 11 May 1997 18:43:55 +0000 |
parents | 3b9f64eb097b |
children |
rev | line source |
---|---|
13401 | 1 ;;; gnus-kill.el --- kill commands for Gnus |
15511 | 2 ;; Copyright (C) 1995,96 Free Software Foundation, Inc. |
13401 | 3 |
4 ;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet> | |
5 ;; Lars Magne Ingebrigtsen <larsi@ifi.uio.no> | |
6 ;; Keywords: news | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
14169 | 21 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
13401 | 24 |
25 ;;; Commentary: | |
26 | |
27 ;;; Code: | |
28 | |
29 (require 'gnus) | |
15511 | 30 (eval-when-compile (require 'cl)) |
13401 | 31 |
32 (defvar gnus-kill-file-mode-hook nil | |
33 "*A hook for Gnus kill file mode.") | |
34 | |
35 (defvar gnus-kill-expiry-days 7 | |
36 "*Number of days before expiring unused kill file entries.") | |
37 | |
38 (defvar gnus-kill-save-kill-file nil | |
39 "*If non-nil, will save kill files after processing them.") | |
40 | |
41 (defvar gnus-winconf-kill-file nil) | |
42 | |
43 | |
44 | |
45 (defmacro gnus-raise (field expression level) | |
15511 | 46 `(gnus-kill ,field ,expression |
47 (function (gnus-summary-raise-score ,level)) t)) | |
13401 | 48 |
49 (defmacro gnus-lower (field expression level) | |
15511 | 50 `(gnus-kill ,field ,expression |
51 (function (gnus-summary-raise-score (- ,level))) t)) | |
13401 | 52 |
53 ;;; | |
54 ;;; Gnus Kill File Mode | |
55 ;;; | |
56 | |
57 (defvar gnus-kill-file-mode-map nil) | |
58 | |
15511 | 59 (unless gnus-kill-file-mode-map |
60 (gnus-define-keymap | |
61 (setq gnus-kill-file-mode-map (copy-keymap emacs-lisp-mode-map)) | |
62 "\C-c\C-k\C-s" gnus-kill-file-kill-by-subject | |
63 "\C-c\C-k\C-a" gnus-kill-file-kill-by-author | |
64 "\C-c\C-k\C-t" gnus-kill-file-kill-by-thread | |
65 "\C-c\C-k\C-x" gnus-kill-file-kill-by-xref | |
66 "\C-c\C-a" gnus-kill-file-apply-buffer | |
67 "\C-c\C-e" gnus-kill-file-apply-last-sexp | |
68 "\C-c\C-c" gnus-kill-file-exit)) | |
13401 | 69 |
70 (defun gnus-kill-file-mode () | |
71 "Major mode for editing kill files. | |
72 | |
73 If you are using this mode - you probably shouldn't. Kill files | |
74 perform badly and paint with a pretty broad brush. Score files, on | |
75 the other hand, are vastly faster (40x speedup) and give you more | |
76 control over what to do. | |
77 | |
78 In addition to Emacs-Lisp Mode, the following commands are available: | |
79 | |
80 \\{gnus-kill-file-mode-map} | |
81 | |
82 A kill file contains Lisp expressions to be applied to a selected | |
83 newsgroup. The purpose is to mark articles as read on the basis of | |
84 some set of regexps. A global kill file is applied to every newsgroup, | |
85 and a local kill file is applied to a specified newsgroup. Since a | |
86 global kill file is applied to every newsgroup, for better performance | |
87 use a local one. | |
88 | |
89 A kill file can contain any kind of Emacs Lisp expressions expected | |
90 to be evaluated in the Summary buffer. Writing Lisp programs for this | |
91 purpose is not so easy because the internal working of Gnus must be | |
92 well-known. For this reason, Gnus provides a general function which | |
93 does this easily for non-Lisp programmers. | |
94 | |
95 The `gnus-kill' function executes commands available in Summary Mode | |
96 by their key sequences. `gnus-kill' should be called with FIELD, | |
97 REGEXP and optional COMMAND and ALL. FIELD is a string representing | |
98 the header field or an empty string. If FIELD is an empty string, the | |
99 entire article body is searched for. REGEXP is a string which is | |
100 compared with FIELD value. COMMAND is a string representing a valid | |
101 key sequence in Summary mode or Lisp expression. COMMAND defaults to | |
102 '(gnus-summary-mark-as-read nil \"X\"). Make sure that COMMAND is | |
103 executed in the Summary buffer. If the second optional argument ALL | |
104 is non-nil, the COMMAND is applied to articles which are already | |
105 marked as read or unread. Articles which are marked are skipped over | |
106 by default. | |
107 | |
108 For example, if you want to mark articles of which subjects contain | |
109 the string `AI' as read, a possible kill file may look like: | |
110 | |
111 (gnus-kill \"Subject\" \"AI\") | |
112 | |
113 If you want to mark articles with `D' instead of `X', you can use | |
114 the following expression: | |
115 | |
116 (gnus-kill \"Subject\" \"AI\" \"d\") | |
117 | |
118 In this example it is assumed that the command | |
119 `gnus-summary-mark-as-read-forward' is assigned to `d' in Summary Mode. | |
120 | |
121 It is possible to delete unnecessary headers which are marked with | |
122 `X' in a kill file as follows: | |
123 | |
124 (gnus-expunge \"X\") | |
125 | |
126 If the Summary buffer is empty after applying kill files, Gnus will | |
127 exit the selected newsgroup normally. If headers which are marked | |
128 with `D' are deleted in a kill file, it is impossible to read articles | |
129 which are marked as read in the previous Gnus sessions. Marks other | |
130 than `D' should be used for articles which should really be deleted. | |
131 | |
132 Entry to this mode calls emacs-lisp-mode-hook and | |
133 gnus-kill-file-mode-hook with no arguments, if that value is non-nil." | |
134 (interactive) | |
135 (kill-all-local-variables) | |
136 (use-local-map gnus-kill-file-mode-map) | |
137 (set-syntax-table emacs-lisp-mode-syntax-table) | |
138 (setq major-mode 'gnus-kill-file-mode) | |
139 (setq mode-name "Kill") | |
140 (lisp-mode-variables nil) | |
141 (run-hooks 'emacs-lisp-mode-hook 'gnus-kill-file-mode-hook)) | |
142 | |
143 (defun gnus-kill-file-edit-file (newsgroup) | |
144 "Begin editing a kill file for NEWSGROUP. | |
145 If NEWSGROUP is nil, the global kill file is selected." | |
146 (interactive "sNewsgroup: ") | |
147 (let ((file (gnus-newsgroup-kill-file newsgroup))) | |
148 (gnus-make-directory (file-name-directory file)) | |
149 ;; Save current window configuration if this is first invocation. | |
150 (or (and (get-file-buffer file) | |
151 (get-buffer-window (get-file-buffer file))) | |
152 (setq gnus-winconf-kill-file (current-window-configuration))) | |
153 ;; Hack windows. | |
154 (let ((buffer (find-file-noselect file))) | |
155 (cond ((get-buffer-window buffer) | |
156 (pop-to-buffer buffer)) | |
157 ((eq major-mode 'gnus-group-mode) | |
158 (gnus-configure-windows 'group) ;Take all windows. | |
159 (pop-to-buffer buffer)) | |
160 ((eq major-mode 'gnus-summary-mode) | |
161 (gnus-configure-windows 'article) | |
162 (pop-to-buffer gnus-article-buffer) | |
163 (bury-buffer gnus-article-buffer) | |
164 (switch-to-buffer buffer)) | |
165 (t ;No good rules. | |
166 (find-file-other-window file)))) | |
167 (gnus-kill-file-mode))) | |
168 | |
169 ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>. | |
170 (defun gnus-kill-set-kill-buffer () | |
171 (let* ((file (gnus-newsgroup-kill-file gnus-newsgroup-name)) | |
172 (buffer (find-file-noselect file))) | |
173 (set-buffer buffer) | |
174 (gnus-kill-file-mode) | |
175 (bury-buffer buffer))) | |
176 | |
15511 | 177 (defun gnus-kill-file-enter-kill (field regexp &optional dont-move) |
13401 | 178 ;; Enter kill file entry. |
179 ;; FIELD: String containing the name of the header field to kill. | |
180 ;; REGEXP: The string to kill. | |
181 (save-excursion | |
182 (let (string) | |
183 (or (eq major-mode 'gnus-kill-file-mode) | |
184 (gnus-kill-set-kill-buffer)) | |
15511 | 185 (unless dont-move |
186 (goto-char (point-max))) | |
13401 | 187 (insert (setq string (format "(gnus-kill %S %S)\n" field regexp))) |
188 (gnus-kill-file-apply-string string)))) | |
189 | |
190 (defun gnus-kill-file-kill-by-subject () | |
191 "Kill by subject." | |
192 (interactive) | |
193 (gnus-kill-file-enter-kill | |
194 "Subject" | |
195 (if (vectorp gnus-current-headers) | |
196 (regexp-quote | |
197 (gnus-simplify-subject (mail-header-subject gnus-current-headers))) | |
15511 | 198 "") t)) |
13401 | 199 |
200 (defun gnus-kill-file-kill-by-author () | |
201 "Kill by author." | |
202 (interactive) | |
203 (gnus-kill-file-enter-kill | |
204 "From" | |
205 (if (vectorp gnus-current-headers) | |
206 (regexp-quote (mail-header-from gnus-current-headers)) | |
15511 | 207 "") t)) |
13401 | 208 |
209 (defun gnus-kill-file-kill-by-thread () | |
210 "Kill by author." | |
14569
e6770e6ff02d
(gnus-kill-file-kill-by-thread): Correct interactive declaration.
Erik Naggum <erik@naggum.no>
parents:
14169
diff
changeset
|
211 (interactive) |
13401 | 212 (gnus-kill-file-enter-kill |
213 "References" | |
214 (if (vectorp gnus-current-headers) | |
215 (regexp-quote (mail-header-id gnus-current-headers)) | |
216 ""))) | |
217 | |
218 (defun gnus-kill-file-kill-by-xref () | |
219 "Kill by Xref." | |
220 (interactive) | |
221 (let ((xref (and (vectorp gnus-current-headers) | |
222 (mail-header-xref gnus-current-headers))) | |
223 (start 0) | |
224 group) | |
225 (if xref | |
226 (while (string-match " \\([^ \t]+\\):" xref start) | |
227 (setq start (match-end 0)) | |
228 (if (not (string= | |
229 (setq group | |
230 (substring xref (match-beginning 1) (match-end 1))) | |
231 gnus-newsgroup-name)) | |
232 (gnus-kill-file-enter-kill | |
15511 | 233 "Xref" (concat " " (regexp-quote group) ":") t))) |
234 (gnus-kill-file-enter-kill "Xref" "" t)))) | |
13401 | 235 |
236 (defun gnus-kill-file-raise-followups-to-author (level) | |
237 "Raise score for all followups to the current author." | |
238 (interactive "p") | |
239 (let ((name (mail-header-from gnus-current-headers)) | |
240 string) | |
241 (save-excursion | |
242 (gnus-kill-set-kill-buffer) | |
243 (goto-char (point-min)) | |
244 (setq name (read-string (concat "Add " level | |
245 " to followup articles to: ") | |
246 (regexp-quote name))) | |
247 (setq | |
248 string | |
249 (format | |
250 "(gnus-kill %S %S '(gnus-summary-temporarily-raise-by-thread %S))\n" | |
251 "From" name level)) | |
252 (insert string) | |
253 (gnus-kill-file-apply-string string)) | |
15511 | 254 (gnus-message |
255 6 "Added temporary score file entry for followups to %s." name))) | |
13401 | 256 |
257 (defun gnus-kill-file-apply-buffer () | |
258 "Apply current buffer to current newsgroup." | |
259 (interactive) | |
260 (if (and gnus-current-kill-article | |
261 (get-buffer gnus-summary-buffer)) | |
262 ;; Assume newsgroup is selected. | |
263 (gnus-kill-file-apply-string (buffer-string)) | |
15511 | 264 (ding) (gnus-message 2 "No newsgroup is selected."))) |
13401 | 265 |
266 (defun gnus-kill-file-apply-string (string) | |
267 "Apply STRING to current newsgroup." | |
268 (interactive) | |
269 (let ((string (concat "(progn \n" string "\n)"))) | |
270 (save-excursion | |
271 (save-window-excursion | |
272 (pop-to-buffer gnus-summary-buffer) | |
273 (eval (car (read-from-string string))))))) | |
274 | |
275 (defun gnus-kill-file-apply-last-sexp () | |
276 "Apply sexp before point in current buffer to current newsgroup." | |
277 (interactive) | |
278 (if (and gnus-current-kill-article | |
279 (get-buffer gnus-summary-buffer)) | |
280 ;; Assume newsgroup is selected. | |
281 (let ((string | |
282 (buffer-substring | |
283 (save-excursion (forward-sexp -1) (point)) (point)))) | |
284 (save-excursion | |
285 (save-window-excursion | |
286 (pop-to-buffer gnus-summary-buffer) | |
287 (eval (car (read-from-string string)))))) | |
15511 | 288 (ding) (gnus-message 2 "No newsgroup is selected."))) |
13401 | 289 |
290 (defun gnus-kill-file-exit () | |
291 "Save a kill file, then return to the previous buffer." | |
292 (interactive) | |
293 (save-buffer) | |
294 (let ((killbuf (current-buffer))) | |
295 ;; We don't want to return to article buffer. | |
296 (and (get-buffer gnus-article-buffer) | |
297 (bury-buffer gnus-article-buffer)) | |
298 ;; Delete the KILL file windows. | |
299 (delete-windows-on killbuf) | |
300 ;; Restore last window configuration if available. | |
301 (and gnus-winconf-kill-file | |
302 (set-window-configuration gnus-winconf-kill-file)) | |
303 (setq gnus-winconf-kill-file nil) | |
304 ;; Kill the KILL file buffer. Suggested by tale@pawl.rpi.edu. | |
305 (kill-buffer killbuf))) | |
306 | |
307 ;; For kill files | |
308 | |
309 (defun gnus-Newsgroup-kill-file (newsgroup) | |
310 "Return the name of a kill file for NEWSGROUP. | |
311 If NEWSGROUP is nil, return the global kill file instead." | |
312 (cond ((or (null newsgroup) | |
313 (string-equal newsgroup "")) | |
314 ;; The global kill file is placed at top of the directory. | |
15511 | 315 (expand-file-name gnus-kill-file-name gnus-kill-files-directory)) |
13401 | 316 (gnus-use-long-file-name |
317 ;; Append ".KILL" to capitalized newsgroup name. | |
318 (expand-file-name (concat (gnus-capitalize-newsgroup newsgroup) | |
319 "." gnus-kill-file-name) | |
15511 | 320 gnus-kill-files-directory)) |
13401 | 321 (t |
322 ;; Place "KILL" under the hierarchical directory. | |
323 (expand-file-name (concat (gnus-newsgroup-directory-form newsgroup) | |
324 "/" gnus-kill-file-name) | |
15511 | 325 gnus-kill-files-directory)))) |
13401 | 326 |
327 (defun gnus-expunge (marks) | |
328 "Remove lines marked with MARKS." | |
329 (save-excursion | |
330 (set-buffer gnus-summary-buffer) | |
15511 | 331 (gnus-summary-limit-to-marks marks 'reverse))) |
332 | |
333 (defun gnus-apply-kill-file-unless-scored () | |
334 "Apply .KILL file, unless a .SCORE file for the same newsgroup exists." | |
335 (cond ((file-exists-p (gnus-score-file-name gnus-newsgroup-name)) | |
336 ;; Ignores global KILL. | |
337 (if (file-exists-p (gnus-newsgroup-kill-file gnus-newsgroup-name)) | |
338 (gnus-message 3 "Note: Ignoring %s.KILL; preferring .SCORE" | |
339 gnus-newsgroup-name)) | |
340 0) | |
341 ((or (file-exists-p (gnus-newsgroup-kill-file nil)) | |
342 (file-exists-p (gnus-newsgroup-kill-file gnus-newsgroup-name))) | |
343 (gnus-apply-kill-file-internal)) | |
344 (t | |
345 0))) | |
13401 | 346 |
347 (defun gnus-apply-kill-file-internal () | |
348 "Apply a kill file to the current newsgroup. | |
349 Returns the number of articles marked as read." | |
350 (let* ((kill-files (list (gnus-newsgroup-kill-file nil) | |
351 (gnus-newsgroup-kill-file gnus-newsgroup-name))) | |
352 (unreads (length gnus-newsgroup-unreads)) | |
353 (gnus-summary-inhibit-highlight t) | |
354 beg) | |
355 (setq gnus-newsgroup-kill-headers nil) | |
356 ;; If there are any previously scored articles, we remove these | |
357 ;; from the `gnus-newsgroup-headers' list that the score functions | |
358 ;; will see. This is probably pretty wasteful when it comes to | |
359 ;; conses, but is, I think, faster than having to assq in every | |
360 ;; single score function. | |
361 (let ((files kill-files)) | |
362 (while files | |
363 (if (file-exists-p (car files)) | |
364 (let ((headers gnus-newsgroup-headers)) | |
365 (if gnus-kill-killed | |
366 (setq gnus-newsgroup-kill-headers | |
367 (mapcar (lambda (header) (mail-header-number header)) | |
368 headers)) | |
369 (while headers | |
370 (or (gnus-member-of-range | |
371 (mail-header-number (car headers)) | |
372 gnus-newsgroup-killed) | |
373 (setq gnus-newsgroup-kill-headers | |
374 (cons (mail-header-number (car headers)) | |
375 gnus-newsgroup-kill-headers))) | |
376 (setq headers (cdr headers)))) | |
377 (setq files nil)) | |
378 (setq files (cdr files))))) | |
379 (if (not gnus-newsgroup-kill-headers) | |
380 () | |
381 (save-window-excursion | |
382 (save-excursion | |
383 (while kill-files | |
384 (if (not (file-exists-p (car kill-files))) | |
385 () | |
15511 | 386 (gnus-message 6 "Processing kill file %s..." (car kill-files)) |
13401 | 387 (find-file (car kill-files)) |
388 (gnus-add-current-to-buffer-list) | |
389 (goto-char (point-min)) | |
390 | |
391 (if (consp (condition-case nil (read (current-buffer)) | |
392 (error nil))) | |
393 (gnus-kill-parse-gnus-kill-file) | |
394 (gnus-kill-parse-rn-kill-file)) | |
395 | |
15511 | 396 (gnus-message |
397 6 "Processing kill file %s...done" (car kill-files))) | |
13401 | 398 (setq kill-files (cdr kill-files))))) |
399 | |
400 (gnus-set-mode-line 'summary) | |
401 | |
402 (if beg | |
403 (let ((nunreads (- unreads (length gnus-newsgroup-unreads)))) | |
404 (or (eq nunreads 0) | |
15511 | 405 (gnus-message 6 "Marked %d articles as read" nunreads)) |
13401 | 406 nunreads) |
407 0)))) | |
408 | |
409 ;; Parse a Gnus killfile. | |
410 (defun gnus-score-insert-help (string alist idx) | |
411 (save-excursion | |
412 (pop-to-buffer "*Score Help*") | |
413 (buffer-disable-undo (current-buffer)) | |
414 (erase-buffer) | |
415 (insert string ":\n\n") | |
416 (while alist | |
15511 | 417 (insert (format " %c: %s\n" (caar alist) (nth idx (car alist)))) |
13401 | 418 (setq alist (cdr alist))))) |
419 | |
420 (defun gnus-kill-parse-gnus-kill-file () | |
421 (goto-char (point-min)) | |
422 (gnus-kill-file-mode) | |
423 (let (beg form) | |
424 (while (progn | |
425 (setq beg (point)) | |
426 (setq form (condition-case () (read (current-buffer)) | |
427 (error nil)))) | |
428 (or (listp form) | |
429 (error "Illegal kill entry (possibly rn kill file?): %s" form)) | |
430 (if (or (eq (car form) 'gnus-kill) | |
431 (eq (car form) 'gnus-raise) | |
432 (eq (car form) 'gnus-lower)) | |
433 (progn | |
434 (delete-region beg (point)) | |
435 (insert (or (eval form) ""))) | |
436 (save-excursion | |
437 (set-buffer gnus-summary-buffer) | |
438 (condition-case () (eval form) (error nil))))) | |
439 (and (buffer-modified-p) | |
440 gnus-kill-save-kill-file | |
441 (save-buffer)) | |
442 (set-buffer-modified-p nil))) | |
443 | |
444 ;; Parse an rn killfile. | |
445 (defun gnus-kill-parse-rn-kill-file () | |
446 (goto-char (point-min)) | |
447 (gnus-kill-file-mode) | |
448 (let ((mod-to-header | |
449 '((?a . "") | |
450 (?h . "") | |
451 (?f . "from") | |
452 (?: . "subject"))) | |
453 (com-to-com | |
454 '((?m . " ") | |
455 (?j . "X"))) | |
456 pattern modifier commands) | |
457 (while (not (eobp)) | |
458 (if (not (looking-at "[ \t]*/\\([^/]*\\)/\\([ahfcH]\\)?:\\([a-z=:]*\\)")) | |
459 () | |
460 (setq pattern (buffer-substring (match-beginning 1) (match-end 1))) | |
461 (setq modifier (if (match-beginning 2) (char-after (match-beginning 2)) | |
462 ?s)) | |
463 (setq commands (buffer-substring (match-beginning 3) (match-end 3))) | |
464 | |
465 ;; The "f:+" command marks everything *but* the matches as read, | |
466 ;; so we simply first match everything as read, and then unmark | |
467 ;; PATTERN later. | |
468 (and (string-match "\\+" commands) | |
469 (progn | |
470 (gnus-kill "from" ".") | |
471 (setq commands "m"))) | |
472 | |
473 (gnus-kill | |
474 (or (cdr (assq modifier mod-to-header)) "subject") | |
475 pattern | |
476 (if (string-match "m" commands) | |
477 '(gnus-summary-mark-as-unread nil " ") | |
478 '(gnus-summary-mark-as-read nil "X")) | |
479 nil t)) | |
480 (forward-line 1)))) | |
481 | |
482 ;; Kill changes and new format by suggested by JWZ and Sudish Joseph | |
483 ;; <joseph@cis.ohio-state.edu>. | |
484 (defun gnus-kill (field regexp &optional exe-command all silent) | |
485 "If FIELD of an article matches REGEXP, execute COMMAND. | |
486 Optional 1st argument COMMAND is default to | |
487 (gnus-summary-mark-as-read nil \"X\"). | |
488 If optional 2nd argument ALL is non-nil, articles marked are also applied to. | |
489 If FIELD is an empty string (or nil), entire article body is searched for. | |
490 COMMAND must be a lisp expression or a string representing a key sequence." | |
491 ;; We don't want to change current point nor window configuration. | |
492 (let ((old-buffer (current-buffer))) | |
493 (save-excursion | |
494 (save-window-excursion | |
495 ;; Selected window must be summary buffer to execute keyboard | |
496 ;; macros correctly. See command_loop_1. | |
497 (switch-to-buffer gnus-summary-buffer 'norecord) | |
498 (goto-char (point-min)) ;From the beginning. | |
499 (let ((kill-list regexp) | |
500 (date (current-time-string)) | |
501 (command (or exe-command '(gnus-summary-mark-as-read | |
502 nil gnus-kill-file-mark))) | |
503 kill kdate prev) | |
504 (if (listp kill-list) | |
505 ;; It is a list. | |
506 (if (not (consp (cdr kill-list))) | |
16427 | 507 ;; It's of the form (regexp . date). |
13401 | 508 (if (zerop (gnus-execute field (car kill-list) |
509 command nil (not all))) | |
510 (if (> (gnus-days-between date (cdr kill-list)) | |
511 gnus-kill-expiry-days) | |
512 (setq regexp nil)) | |
513 (setcdr kill-list date)) | |
514 (while (setq kill (car kill-list)) | |
515 (if (consp kill) | |
516 ;; It's a temporary kill. | |
517 (progn | |
518 (setq kdate (cdr kill)) | |
519 (if (zerop (gnus-execute | |
520 field (car kill) command nil (not all))) | |
521 (if (> (gnus-days-between date kdate) | |
522 gnus-kill-expiry-days) | |
523 ;; Time limit has been exceeded, so we | |
524 ;; remove the match. | |
525 (if prev | |
526 (setcdr prev (cdr kill-list)) | |
527 (setq regexp (cdr regexp)))) | |
528 ;; Successful kill. Set the date to today. | |
529 (setcdr kill date))) | |
530 ;; It's a permanent kill. | |
531 (gnus-execute field kill command nil (not all))) | |
532 (setq prev kill-list) | |
533 (setq kill-list (cdr kill-list)))) | |
534 (gnus-execute field kill-list command nil (not all)))))) | |
535 (switch-to-buffer old-buffer) | |
536 (if (and (eq major-mode 'gnus-kill-file-mode) regexp (not silent)) | |
537 (gnus-pp-gnus-kill | |
538 (nconc (list 'gnus-kill field | |
539 (if (consp regexp) (list 'quote regexp) regexp)) | |
540 (if (or exe-command all) (list (list 'quote exe-command))) | |
541 (if all (list t) nil)))))) | |
542 | |
543 (defun gnus-pp-gnus-kill (object) | |
544 (if (or (not (consp (nth 2 object))) | |
545 (not (consp (cdr (nth 2 object)))) | |
546 (and (eq 'quote (car (nth 2 object))) | |
15511 | 547 (not (consp (cdadr (nth 2 object)))))) |
13401 | 548 (concat "\n" (prin1-to-string object)) |
549 (save-excursion | |
550 (set-buffer (get-buffer-create "*Gnus PP*")) | |
551 (buffer-disable-undo (current-buffer)) | |
552 (erase-buffer) | |
553 (insert (format "\n(%S %S\n '(" (nth 0 object) (nth 1 object))) | |
15511 | 554 (let ((klist (cadr (nth 2 object))) |
13401 | 555 (first t)) |
556 (while klist | |
557 (insert (if first (progn (setq first nil) "") "\n ") | |
558 (prin1-to-string (car klist))) | |
559 (setq klist (cdr klist)))) | |
560 (insert ")") | |
561 (and (nth 3 object) | |
562 (insert "\n " | |
563 (if (and (consp (nth 3 object)) | |
564 (not (eq 'quote (car (nth 3 object))))) | |
565 "'" "") | |
566 (prin1-to-string (nth 3 object)))) | |
567 (and (nth 4 object) | |
568 (insert "\n t")) | |
569 (insert ")") | |
570 (prog1 | |
571 (buffer-substring (point-min) (point-max)) | |
572 (kill-buffer (current-buffer)))))) | |
573 | |
574 (defun gnus-execute-1 (function regexp form header) | |
575 (save-excursion | |
576 (let (did-kill) | |
577 (if (null header) | |
578 nil ;Nothing to do. | |
579 (if function | |
580 ;; Compare with header field. | |
581 (let (value) | |
582 (and header | |
583 (progn | |
584 (setq value (funcall function header)) | |
585 ;; Number (Lines:) or symbol must be converted to string. | |
586 (or (stringp value) | |
587 (setq value (prin1-to-string value))) | |
588 (setq did-kill (string-match regexp value))) | |
15511 | 589 (cond ((stringp form) ;Keyboard macro. |
590 (execute-kbd-macro form)) | |
591 ((gnus-functionp form) | |
592 (funcall form)) | |
593 (t | |
594 (eval form))))) | |
13401 | 595 ;; Search article body. |
596 (let ((gnus-current-article nil) ;Save article pointer. | |
597 (gnus-last-article nil) | |
598 (gnus-break-pages nil) ;No need to break pages. | |
599 (gnus-mark-article-hook nil)) ;Inhibit marking as read. | |
15511 | 600 (gnus-message |
601 6 "Searching for article: %d..." (mail-header-number header)) | |
13401 | 602 (gnus-article-setup-buffer) |
603 (gnus-article-prepare (mail-header-number header) t) | |
604 (if (save-excursion | |
605 (set-buffer gnus-article-buffer) | |
606 (goto-char (point-min)) | |
607 (setq did-kill (re-search-forward regexp nil t))) | |
608 (if (stringp form) ;Keyboard macro. | |
609 (execute-kbd-macro form) | |
610 (eval form)))))) | |
611 did-kill))) | |
612 | |
613 (defun gnus-execute (field regexp form &optional backward ignore-marked) | |
614 "If FIELD of article header matches REGEXP, execute lisp FORM (or a string). | |
615 If FIELD is an empty string (or nil), entire article body is searched for. | |
616 If optional 1st argument BACKWARD is non-nil, do backward instead. | |
617 If optional 2nd argument IGNORE-MARKED is non-nil, articles which are | |
618 marked as read or ticked are ignored." | |
619 (save-excursion | |
620 (let ((killed-no 0) | |
621 function article header) | |
15511 | 622 (cond |
623 ;; Search body. | |
624 ((or (null field) | |
625 (string-equal field "")) | |
626 (setq function nil)) | |
627 ;; Get access function of header field. | |
628 ((fboundp | |
629 (setq function | |
630 (intern-soft | |
631 (concat "mail-header-" (downcase field))))) | |
632 (setq function `(lambda (h) (,function h)))) | |
633 ;; Signal error. | |
634 (t | |
635 (error "Unknown header field: \"%s\"" field))) | |
13401 | 636 ;; Starting from the current article. |
15511 | 637 (while (or |
638 ;; First article. | |
639 (and (not article) | |
640 (setq article (gnus-summary-article-number))) | |
641 ;; Find later articles. | |
642 (setq article | |
643 (gnus-summary-search-forward | |
644 (not ignore-marked) nil backward))) | |
13401 | 645 (and (or (null gnus-newsgroup-kill-headers) |
646 (memq article gnus-newsgroup-kill-headers)) | |
15511 | 647 (vectorp (setq header (gnus-summary-article-header article))) |
13401 | 648 (gnus-execute-1 function regexp form header) |
649 (setq killed-no (1+ killed-no)))) | |
15511 | 650 ;; Return the number of killed articles. |
13401 | 651 killed-no))) |
652 | |
15511 | 653 (provide 'gnus-kill) |
654 | |
655 ;;; gnus-kill.el ends here |