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