comparison lisp/gnus/gnus-kill.el @ 108:360340f9fd5f r20-1b6

Import from CVS: tag r20-1b6
author cvs
date Mon, 13 Aug 2007 09:18:39 +0200
parents 4be1180a9e89
children
comparison
equal deleted inserted replaced
107:523141596bda 108:360340f9fd5f
203 (gnus-kill-set-kill-buffer)) 203 (gnus-kill-set-kill-buffer))
204 (unless dont-move 204 (unless dont-move
205 (goto-char (point-max))) 205 (goto-char (point-max)))
206 (insert (setq string (format "(gnus-kill %S %S)\n" field regexp))) 206 (insert (setq string (format "(gnus-kill %S %S)\n" field regexp)))
207 (gnus-kill-file-apply-string string)))) 207 (gnus-kill-file-apply-string string))))
208 208
209 (defun gnus-kill-file-kill-by-subject () 209 (defun gnus-kill-file-kill-by-subject ()
210 "Kill by subject." 210 "Kill by subject."
211 (interactive) 211 (interactive)
212 (gnus-kill-file-enter-kill 212 (gnus-kill-file-enter-kill
213 "Subject" 213 "Subject"
214 (if (vectorp gnus-current-headers) 214 (if (vectorp gnus-current-headers)
215 (regexp-quote 215 (regexp-quote
216 (gnus-simplify-subject (mail-header-subject gnus-current-headers))) 216 (gnus-simplify-subject (mail-header-subject gnus-current-headers)))
217 "") 217 "")
218 t)) 218 t))
219 219
220 (defun gnus-kill-file-kill-by-author () 220 (defun gnus-kill-file-kill-by-author ()
221 "Kill by author." 221 "Kill by author."
222 (interactive) 222 (interactive)
223 (gnus-kill-file-enter-kill 223 (gnus-kill-file-enter-kill
224 "From" 224 "From"
225 (if (vectorp gnus-current-headers) 225 (if (vectorp gnus-current-headers)
226 (regexp-quote (mail-header-from gnus-current-headers)) 226 (regexp-quote (mail-header-from gnus-current-headers))
227 "") t)) 227 "") t))
228 228
229 (defun gnus-kill-file-kill-by-thread () 229 (defun gnus-kill-file-kill-by-thread ()
230 "Kill by author." 230 "Kill by author."
231 (interactive) 231 (interactive)
232 (gnus-kill-file-enter-kill 232 (gnus-kill-file-enter-kill
233 "References" 233 "References"
234 (if (vectorp gnus-current-headers) 234 (if (vectorp gnus-current-headers)
235 (regexp-quote (mail-header-id gnus-current-headers)) 235 (regexp-quote (mail-header-id gnus-current-headers))
236 ""))) 236 "")))
237 237
238 (defun gnus-kill-file-kill-by-xref () 238 (defun gnus-kill-file-kill-by-xref ()
239 "Kill by Xref." 239 "Kill by Xref."
240 (interactive) 240 (interactive)
241 (let ((xref (and (vectorp gnus-current-headers) 241 (let ((xref (and (vectorp gnus-current-headers)
242 (mail-header-xref gnus-current-headers))) 242 (mail-header-xref gnus-current-headers)))
243 (start 0) 243 (start 0)
244 group) 244 group)
245 (if xref 245 (if xref
246 (while (string-match " \\([^ \t]+\\):" xref start) 246 (while (string-match " \\([^ \t]+\\):" xref start)
247 (setq start (match-end 0)) 247 (setq start (match-end 0))
248 (when (not (string= 248 (when (not (string=
249 (setq group 249 (setq group
250 (substring xref (match-beginning 1) (match-end 1))) 250 (substring xref (match-beginning 1) (match-end 1)))
251 gnus-newsgroup-name)) 251 gnus-newsgroup-name))
252 (gnus-kill-file-enter-kill 252 (gnus-kill-file-enter-kill
253 "Xref" (concat " " (regexp-quote group) ":") t))) 253 "Xref" (concat " " (regexp-quote group) ":") t)))
254 (gnus-kill-file-enter-kill "Xref" "" t)))) 254 (gnus-kill-file-enter-kill "Xref" "" t))))
255 255
256 (defun gnus-kill-file-raise-followups-to-author (level) 256 (defun gnus-kill-file-raise-followups-to-author (level)
257 "Raise score for all followups to the current author." 257 "Raise score for all followups to the current author."
262 (gnus-kill-set-kill-buffer) 262 (gnus-kill-set-kill-buffer)
263 (goto-char (point-min)) 263 (goto-char (point-min))
264 (setq name (read-string (concat "Add " level 264 (setq name (read-string (concat "Add " level
265 " to followup articles to: ") 265 " to followup articles to: ")
266 (regexp-quote name))) 266 (regexp-quote name)))
267 (setq 267 (setq
268 string 268 string
269 (format 269 (format
270 "(gnus-kill %S %S '(gnus-summary-temporarily-raise-by-thread %S))\n" 270 "(gnus-kill %S %S '(gnus-summary-temporarily-raise-by-thread %S))\n"
271 "From" name level)) 271 "From" name level))
272 (insert string) 272 (insert string)
273 (gnus-kill-file-apply-string string)) 273 (gnus-kill-file-apply-string string))
274 (gnus-message 274 (gnus-message
275 6 "Added temporary score file entry for followups to %s." name))) 275 6 "Added temporary score file entry for followups to %s." name)))
276 276
277 (defun gnus-kill-file-apply-buffer () 277 (defun gnus-kill-file-apply-buffer ()
278 "Apply current buffer to current newsgroup." 278 "Apply current buffer to current newsgroup."
279 (interactive) 279 (interactive)
385 (if gnus-kill-killed 385 (if gnus-kill-killed
386 (setq gnus-newsgroup-kill-headers 386 (setq gnus-newsgroup-kill-headers
387 (mapcar (lambda (header) (mail-header-number header)) 387 (mapcar (lambda (header) (mail-header-number header))
388 headers)) 388 headers))
389 (while headers 389 (while headers
390 (unless (gnus-member-of-range 390 (unless (gnus-member-of-range
391 (mail-header-number (car headers)) 391 (mail-header-number (car headers))
392 gnus-newsgroup-killed) 392 gnus-newsgroup-killed)
393 (push (mail-header-number (car headers)) 393 (push (mail-header-number (car headers))
394 gnus-newsgroup-kill-headers)) 394 gnus-newsgroup-kill-headers))
395 (setq headers (cdr headers)))) 395 (setq headers (cdr headers))))
408 (goto-char (point-min)) 408 (goto-char (point-min))
409 409
410 (if (consp (ignore-errors (read (current-buffer)))) 410 (if (consp (ignore-errors (read (current-buffer))))
411 (gnus-kill-parse-gnus-kill-file) 411 (gnus-kill-parse-gnus-kill-file)
412 (gnus-kill-parse-rn-kill-file)) 412 (gnus-kill-parse-rn-kill-file))
413 413
414 (gnus-message 414 (gnus-message
415 6 "Processing kill file %s...done" (car kill-files))) 415 6 "Processing kill file %s...done" (car kill-files)))
416 (setq kill-files (cdr kill-files))))) 416 (setq kill-files (cdr kill-files)))))
417 417
418 (gnus-set-mode-line 'summary) 418 (gnus-set-mode-line 'summary)
419 419
437 437
438 (defun gnus-kill-parse-gnus-kill-file () 438 (defun gnus-kill-parse-gnus-kill-file ()
439 (goto-char (point-min)) 439 (goto-char (point-min))
440 (gnus-kill-file-mode) 440 (gnus-kill-file-mode)
441 (let (beg form) 441 (let (beg form)
442 (while (progn 442 (while (progn
443 (setq beg (point)) 443 (setq beg (point))
444 (setq form (ignore-errors (read (current-buffer))))) 444 (setq form (ignore-errors (read (current-buffer)))))
445 (unless (listp form) 445 (unless (listp form)
446 (error "Illegal kill entry (possibly rn kill file?): %s" form)) 446 (error "Illegal kill entry (possibly rn kill file?): %s" form))
447 (if (or (eq (car form) 'gnus-kill) 447 (if (or (eq (car form) 'gnus-kill)
479 ?s)) 479 ?s))
480 (setq commands (buffer-substring (match-beginning 3) (match-end 3))) 480 (setq commands (buffer-substring (match-beginning 3) (match-end 3)))
481 481
482 ;; The "f:+" command marks everything *but* the matches as read, 482 ;; The "f:+" command marks everything *but* the matches as read,
483 ;; so we simply first match everything as read, and then unmark 483 ;; so we simply first match everything as read, and then unmark
484 ;; PATTERN later. 484 ;; PATTERN later.
485 (when (string-match "\\+" commands) 485 (when (string-match "\\+" commands)
486 (gnus-kill "from" ".") 486 (gnus-kill "from" ".")
487 (setq commands "m")) 487 (setq commands "m"))
488 488
489 (gnus-kill 489 (gnus-kill
490 (or (cdr (assq modifier mod-to-header)) "subject") 490 (or (cdr (assq modifier mod-to-header)) "subject")
491 pattern 491 pattern
492 (if (string-match "m" commands) 492 (if (string-match "m" commands)
493 '(gnus-summary-mark-as-unread nil " ") 493 '(gnus-summary-mark-as-unread nil " ")
494 '(gnus-summary-mark-as-read nil "X")) 494 '(gnus-summary-mark-as-read nil "X"))
495 nil t)) 495 nil t))
496 (forward-line 1)))) 496 (forward-line 1))))
497 497
498 ;; Kill changes and new format by suggested by JWZ and Sudish Joseph 498 ;; Kill changes and new format by suggested by JWZ and Sudish Joseph
499 ;; <joseph@cis.ohio-state.edu>. 499 ;; <joseph@cis.ohio-state.edu>.
500 (defun gnus-kill (field regexp &optional exe-command all silent) 500 (defun gnus-kill (field regexp &optional exe-command all silent)
501 "If FIELD of an article matches REGEXP, execute COMMAND. 501 "If FIELD of an article matches REGEXP, execute COMMAND.
502 Optional 1st argument COMMAND is default to 502 Optional 1st argument COMMAND is default to
503 (gnus-summary-mark-as-read nil \"X\"). 503 (gnus-summary-mark-as-read nil \"X\").
504 If optional 2nd argument ALL is non-nil, articles marked are also applied to. 504 If optional 2nd argument ALL is non-nil, articles marked are also applied to.
512 ;; macros correctly. See command_loop_1. 512 ;; macros correctly. See command_loop_1.
513 (switch-to-buffer gnus-summary-buffer 'norecord) 513 (switch-to-buffer gnus-summary-buffer 'norecord)
514 (goto-char (point-min)) ;From the beginning. 514 (goto-char (point-min)) ;From the beginning.
515 (let ((kill-list regexp) 515 (let ((kill-list regexp)
516 (date (current-time-string)) 516 (date (current-time-string))
517 (command (or exe-command '(gnus-summary-mark-as-read 517 (command (or exe-command '(gnus-summary-mark-as-read
518 nil gnus-kill-file-mark))) 518 nil gnus-kill-file-mark)))
519 kill kdate prev) 519 kill kdate prev)
520 (if (listp kill-list) 520 (if (listp kill-list)
521 ;; It is a list. 521 ;; It is a list.
522 (if (not (consp (cdr kill-list))) 522 (if (not (consp (cdr kill-list)))
530 (while (setq kill (car kill-list)) 530 (while (setq kill (car kill-list))
531 (if (consp kill) 531 (if (consp kill)
532 ;; It's a temporary kill. 532 ;; It's a temporary kill.
533 (progn 533 (progn
534 (setq kdate (cdr kill)) 534 (setq kdate (cdr kill))
535 (if (zerop (gnus-execute 535 (if (zerop (gnus-execute
536 field (car kill) command nil (not all))) 536 field (car kill) command nil (not all)))
537 (when (> (gnus-days-between date kdate) 537 (when (> (gnus-days-between date kdate)
538 gnus-kill-expiry-days) 538 gnus-kill-expiry-days)
539 ;; Time limit has been exceeded, so we 539 ;; Time limit has been exceeded, so we
540 ;; remove the match. 540 ;; remove the match.
549 (setq kill-list (cdr kill-list)))) 549 (setq kill-list (cdr kill-list))))
550 (gnus-execute field kill-list command nil (not all)))))) 550 (gnus-execute field kill-list command nil (not all))))))
551 (switch-to-buffer old-buffer) 551 (switch-to-buffer old-buffer)
552 (when (and (eq major-mode 'gnus-kill-file-mode) regexp (not silent)) 552 (when (and (eq major-mode 'gnus-kill-file-mode) regexp (not silent))
553 (gnus-pp-gnus-kill 553 (gnus-pp-gnus-kill
554 (nconc (list 'gnus-kill field 554 (nconc (list 'gnus-kill field
555 (if (consp regexp) (list 'quote regexp) regexp)) 555 (if (consp regexp) (list 'quote regexp) regexp))
556 (when (or exe-command all) 556 (when (or exe-command all)
557 (list (list 'quote exe-command))) 557 (list (list 'quote exe-command)))
558 (if all (list t) nil)))))) 558 (if all (list t) nil))))))
559 559
574 (insert (if first (progn (setq first nil) "") "\n ") 574 (insert (if first (progn (setq first nil) "") "\n ")
575 (gnus-prin1-to-string (car klist))) 575 (gnus-prin1-to-string (car klist)))
576 (setq klist (cdr klist)))) 576 (setq klist (cdr klist))))
577 (insert ")") 577 (insert ")")
578 (and (nth 3 object) 578 (and (nth 3 object)
579 (insert "\n " 579 (insert "\n "
580 (if (and (consp (nth 3 object)) 580 (if (and (consp (nth 3 object))
581 (not (eq 'quote (car (nth 3 object))))) 581 (not (eq 'quote (car (nth 3 object)))))
582 "'" "") 582 "'" "")
583 (gnus-prin1-to-string (nth 3 object)))) 583 (gnus-prin1-to-string (nth 3 object))))
584 (when (nth 4 object) 584 (when (nth 4 object)
612 ;; Search article body. 612 ;; Search article body.
613 (let ((gnus-current-article nil) ;Save article pointer. 613 (let ((gnus-current-article nil) ;Save article pointer.
614 (gnus-last-article nil) 614 (gnus-last-article nil)
615 (gnus-break-pages nil) ;No need to break pages. 615 (gnus-break-pages nil) ;No need to break pages.
616 (gnus-mark-article-hook nil)) ;Inhibit marking as read. 616 (gnus-mark-article-hook nil)) ;Inhibit marking as read.
617 (gnus-message 617 (gnus-message
618 6 "Searching for article: %d..." (mail-header-number header)) 618 6 "Searching for article: %d..." (mail-header-number header))
619 (gnus-article-setup-buffer) 619 (gnus-article-setup-buffer)
620 (gnus-article-prepare (mail-header-number header) t) 620 (gnus-article-prepare (mail-header-number header) t)
621 (when (save-excursion 621 (when (save-excursion
622 (set-buffer gnus-article-buffer) 622 (set-buffer gnus-article-buffer)
637 If optional 2nd argument UNREAD is non-nil, articles which are 637 If optional 2nd argument UNREAD is non-nil, articles which are
638 marked as read or ticked are ignored." 638 marked as read or ticked are ignored."
639 (save-excursion 639 (save-excursion
640 (let ((killed-no 0) 640 (let ((killed-no 0)
641 function article header) 641 function article header)
642 (cond 642 (cond
643 ;; Search body. 643 ;; Search body.
644 ((or (null field) 644 ((or (null field)
645 (string-equal field "")) 645 (string-equal field ""))
646 (setq function nil)) 646 (setq function nil))
647 ;; Get access function of header field. 647 ;; Get access function of header field.
648 ((fboundp 648 ((fboundp
649 (setq function 649 (setq function
650 (intern-soft 650 (intern-soft
651 (concat "mail-header-" (downcase field))))) 651 (concat "mail-header-" (downcase field)))))
652 (setq function `(lambda (h) (,function h)))) 652 (setq function `(lambda (h) (,function h))))
653 ;; Signal error. 653 ;; Signal error.
654 (t 654 (t
655 (error "Unknown header field: \"%s\"" field))) 655 (error "Unknown header field: \"%s\"" field)))
657 (while (or 657 (while (or
658 ;; First article. 658 ;; First article.
659 (and (not article) 659 (and (not article)
660 (setq article (gnus-summary-article-number))) 660 (setq article (gnus-summary-article-number)))
661 ;; Find later articles. 661 ;; Find later articles.
662 (setq article 662 (setq article
663 (gnus-summary-search-forward unread nil backward))) 663 (gnus-summary-search-forward unread nil backward)))
664 (and (or (null gnus-newsgroup-kill-headers) 664 (and (or (null gnus-newsgroup-kill-headers)
665 (memq article gnus-newsgroup-kill-headers)) 665 (memq article gnus-newsgroup-kill-headers))
666 (vectorp (setq header (gnus-summary-article-header article))) 666 (vectorp (setq header (gnus-summary-article-header article)))
667 (gnus-execute-1 function regexp form header) 667 (gnus-execute-1 function regexp form header)
677 Usage: emacs -batch -l gnus -f gnus-batch-score <newsgroups> ... 677 Usage: emacs -batch -l gnus -f gnus-batch-score <newsgroups> ...
678 Newsgroups is a list of strings in Bnews format. If you want to score 678 Newsgroups is a list of strings in Bnews format. If you want to score
679 the comp hierarchy, you'd say \"comp.all\". If you would not like to 679 the comp hierarchy, you'd say \"comp.all\". If you would not like to
680 score the alt hierarchy, you'd say \"!alt.all\"." 680 score the alt hierarchy, you'd say \"!alt.all\"."
681 (interactive) 681 (interactive)
682 (let* ((gnus-newsrc-options-n 682 (let* ((gnus-newsrc-options-n
683 (gnus-newsrc-parse-options 683 (gnus-newsrc-parse-options
684 (concat "options -n " 684 (concat "options -n "
685 (mapconcat 'identity command-line-args-left " ")))) 685 (mapconcat 'identity command-line-args-left " "))))
686 (gnus-expert-user t) 686 (gnus-expert-user t)
687 (nnmail-spool-file nil) 687 (nnmail-spool-file nil)