From: Lars Magne Ingebrigtsen Date: Tue, 25 Jun 1996 22:21:39 +0000 (+0000) Subject: New version. X-Git-Tag: emacs-19.34~351 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=231f989be9425a463c2f500a47c29e1954d83bcf;p=emacs.git New version. --- diff --git a/lisp/custom.el b/lisp/custom.el index d6fe0cbaa8b..910ef02b187 100644 --- a/lisp/custom.el +++ b/lisp/custom.el @@ -68,15 +68,50 @@ ;;; Code: +(eval-when-compile + (require 'cl)) + ;;; Compatibility: -(or (fboundp 'buffer-substring-no-properties) - ;; Introduced in Emacs 19.29. - (defun buffer-substring-no-properties (beg end) - "Return the text from BEG to END, without text properties, as a string." - (let ((string (buffer-substring beg end))) - (set-text-properties 0 (length string) nil string) - string))) +(defun custom-xmas-add-text-properties (start end props &optional object) + (add-text-properties start end props object) + (put-text-property start end 'start-open t object) + (put-text-property start end 'end-open t object)) + +(defun custom-xmas-put-text-property (start end prop value &optional object) + (put-text-property start end prop value object) + (put-text-property start end 'start-open t object) + (put-text-property start end 'end-open t object)) + +(defun custom-xmas-extent-start-open () + (map-extents (lambda (extent arg) + (set-extent-property extent 'start-open t)) + nil (point) (min (1+ (point)) (point-max)))) + +(if (string-match "XEmacs\\|Lucid" emacs-version) + (progn + (fset 'custom-add-text-properties 'custom-xmas-add-text-properties) + (fset 'custom-put-text-property 'custom-xmas-put-text-property) + (fset 'custom-extent-start-open 'custom-xmas-extent-start-open) + (fset 'custom-set-text-properties + (if (fboundp 'set-text-properties) + 'set-text-properties)) + (fset 'custom-buffer-substring-no-properties + (if (fboundp 'buffer-substring-no-properties) + 'buffer-substring-no-properties + 'custom-xmas-buffer-substring-no-properties))) + (fset 'custom-add-text-properties 'add-text-properties) + (fset 'custom-put-text-property 'put-text-property) + (fset 'custom-extent-start-open 'ignore) + (fset 'custom-set-text-properties 'set-text-properties) + (fset 'custom-buffer-substring-no-properties + 'buffer-substring-no-properties)) + +(defun custom-xmas-buffer-substring-no-properties (beg end) + "Return the text from BEG to END, without text properties, as a string." + (let ((string (buffer-substring beg end))) + (custom-set-text-properties 0 (length string) nil string) + string)) (or (fboundp 'add-to-list) ;; Introduced in Emacs 19.29. @@ -171,16 +206,14 @@ STRING should be given if the last search was by `string-match' on STRING." (and (fboundp 'set-face-underline-p) (funcall 'set-face-underline-p 'underline t)))) -(or (fboundp 'set-text-properties) - ;; Missing in XEmacs 19.12. - (defun set-text-properties (start end props &optional buffer) - (if (or (null buffer) (bufferp buffer)) - (if props - (while props - (put-text-property - start end (car props) (nth 1 props) buffer) - (setq props (nthcdr 2 props))) - (remove-text-properties start end ()))))) +(defun custom-xmas-set-text-properties (start end props &optional buffer) + (if (null buffer) + (if props + (while props + (custom-put-text-property + start end (car props) (nth 1 props) buffer) + (setq props (nthcdr 2 props))) + (remove-text-properties start end ())))) (or (fboundp 'event-point) ;; Missing in Emacs 19.29. @@ -201,60 +234,6 @@ into the buffer visible in the event's window." (defvar custom-mouse-face nil) (defvar custom-field-active-face nil)) -(or (and (fboundp 'modify-face) (not (featurep 'face-lock))) - ;; Introduced in Emacs 19.29. Incompatible definition also introduced - ;; by face-lock.el version 3.00 and above for Emacs 19.28 and below. - ;; face-lock does not call modify-face, so we can safely redefine it. - (defun modify-face (face foreground background stipple - bold-p italic-p underline-p) - "Change the display attributes for face FACE. -FOREGROUND and BACKGROUND should be color strings or nil. -STIPPLE should be a stipple pattern name or nil. -BOLD-P, ITALIC-P, and UNDERLINE-P specify whether the face should be set bold, -in italic, and underlined, respectively. (Yes if non-nil.) -If called interactively, prompts for a face and face attributes." - (interactive - (let* ((completion-ignore-case t) - (face (symbol-name (read-face-name "Modify face: "))) - (colors (mapcar 'list x-colors)) - (stipples (mapcar 'list - (apply 'nconc - (mapcar 'directory-files - x-bitmap-file-path)))) - (foreground (modify-face-read-string - face (face-foreground (intern face)) - "foreground" colors)) - (background (modify-face-read-string - face (face-background (intern face)) - "background" colors)) - (stipple (modify-face-read-string - face (face-stipple (intern face)) - "stipple" stipples)) - (bold-p (y-or-n-p (concat "Set face " face " bold "))) - (italic-p (y-or-n-p (concat "Set face " face " italic "))) - (underline-p (y-or-n-p (concat "Set face " face " underline ")))) - (message "Face %s: %s" face - (mapconcat 'identity - (delq nil - (list (and foreground (concat (downcase foreground) " foreground")) - (and background (concat (downcase background) " background")) - (and stipple (concat (downcase stipple) " stipple")) - (and bold-p "bold") (and italic-p "italic") - (and underline-p "underline"))) ", ")) - (list (intern face) foreground background stipple - bold-p italic-p underline-p))) - (condition-case nil (set-face-foreground face foreground) (error nil)) - (condition-case nil (set-face-background face background) (error nil)) - (condition-case nil (set-face-stipple face stipple) (error nil)) - (if (string-match "XEmacs" emacs-version) - (progn - (funcall (if bold-p 'make-face-bold 'make-face-unbold) face) - (funcall (if italic-p 'make-face-italic 'make-face-unitalic) face)) - (funcall (if bold-p 'make-face-bold 'make-face-unbold) face nil t) - (funcall (if italic-p 'make-face-italic 'make-face-unitalic) face nil t)) - (set-face-underline-p face underline-p) - (and (interactive-p) (redraw-display)))) - ;; We can't easily check for a working intangible. (defconst intangible (if (and (boundp 'emacs-minor-version) (or (> emacs-major-version 19) @@ -281,9 +260,10 @@ If called interactively, prompts for a face and face attributes." ;; Put it in the Help menu, if possible. (if (string-match "XEmacs" emacs-version) - ;; XEmacs (disabled because it doesn't work) - (and current-menubar - (add-menu-item '("Help") "Customize..." 'customize nil)) + (if (featurep 'menubar) + ;; XEmacs (disabled because it doesn't work) + (and current-menubar + (add-menu-item '("Help") "Customize..." 'customize t))) ;; Emacs 19.28 and earlier (global-set-key [ menu-bar help customize ] '("Customize..." . customize)) @@ -359,7 +339,7 @@ If called interactively, prompts for a face and face attributes." (defun custom-category-set (from to category) "Make text between FROM and TWO have category CATEGORY." - (put-text-property from to 'category category))) + (custom-put-text-property from to 'category category))) ;;; External Data: ;; @@ -419,7 +399,7 @@ If called interactively, prompts for a face and face attributes." ;; where each CUSTOM is a leaf in the hierarchy defined by the `type' ;; property and `custom-type-properties'. -(defvar custom-file (convert-standard-filename "~/.custom.el") +(defvar custom-file "~/.custom.el" "Name of file with customization information.") (defconst custom-data @@ -1080,6 +1060,7 @@ If optional ORIGINAL is non-nil, consider VALUE for the original value." (end (make-marker)) (data (vector repeat nil start end)) field) + (custom-extent-start-open) (insert-before-markers "\n") (backward-char 1) (set-marker start (point)) @@ -1309,7 +1290,7 @@ If optional ORIGINAL is non-nil, consider VALUE for the original value." (face-tag (custom-face-tag custom)) current) (if face-tag - (put-text-property from (+ from (length (custom-tag custom))) + (custom-put-text-property from (+ from (length (custom-tag custom))) 'face (funcall face-tag field value))) (if original (custom-field-original-set field value)) @@ -1395,9 +1376,10 @@ If optional ORIGINAL is non-nil, consider VALUE for the original value." () (setq begin (point) found (custom-insert (custom-property custom 'none) nil)) - (add-text-properties begin (point) - (list rear-nonsticky t - 'face custom-field-uninitialized-face))) + (custom-add-text-properties + begin (point) + (list rear-nonsticky t + 'face custom-field-uninitialized-face))) (or original (custom-field-original-set found (custom-field-original field))) (custom-field-accept found value original) @@ -1483,7 +1465,8 @@ If optional ORIGINAL is non-nil, consider VALUE for the original value." (defun custom-face-import (custom value) "Modify CUSTOM's VALUE to match internal expectations." - (let ((name (symbol-name value))) + (let ((name (or (and (facep value) (symbol-name (face-name value))) + (symbol-name value)))) (list (if (string-match "\ custom-face-\\(.*\\)-\\(.*\\)-\\(.*\\)-\\(.*\\)-\\(.*\\)-\\(.*\\)" name) @@ -1496,9 +1479,8 @@ custom-face-\\(.*\\)-\\(.*\\)-\\(.*\\)-\\(.*\\)-\\(.*\\)-\\(.*\\)" (intern (match-string 6 name))) value)))) -(defun custom-face-lookup (fg bg stipple bold italic underline) - "Lookup or create a face with specified attributes. -FG BG STIPPLE BOLD ITALIC UNDERLINE" +(defun custom-face-lookup (&optional fg bg stipple bold italic underline) + "Lookup or create a face with specified attributes." (let ((name (intern (format "custom-face-%s-%s-%s-%S-%S-%S" (or fg "default") (or bg "default") @@ -1507,12 +1489,37 @@ FG BG STIPPLE BOLD ITALIC UNDERLINE" (if (and (custom-facep name) (fboundp 'make-face)) () - (make-face name) - (modify-face name - (if (string-equal fg "default") nil fg) - (if (string-equal bg "default") nil bg) - (if (string-equal stipple "default") nil stipple) - bold italic underline)) + (copy-face 'default name) + (when (and fg + (not (string-equal fg "default"))) + (condition-case () + (set-face-foreground name fg) + (error nil))) + (when (and bg + (not (string-equal bg "default"))) + (condition-case () + (set-face-background name bg) + (error nil))) + (when (and stipple + (not (string-equal stipple "default")) + (not (eq stipple 'custom:asis)) + (fboundp 'set-face-stipple)) + (set-face-stipple name stipple)) + (when (and bold + (not (eq bold 'custom:asis))) + (condition-case () + (make-face-bold name) + (error nil))) + (when (and italic + (not (eq italic 'custom:asis))) + (condition-case () + (make-face-italic name) + (error nil))) + (when (and underline + (not (eq underline 'custom:asis))) + (condition-case () + (set-face-underline-p name t) + (error nil)))) name)) (defun custom-face-hack (field value) @@ -1528,7 +1535,7 @@ FG BG STIPPLE BOLD ITALIC UNDERLINE" (face (custom-field-face field)) (from (point))) (custom-text-insert (custom-tag custom)) - (add-text-properties from (point) + (custom-add-text-properties from (point) (list 'face face rear-nonsticky t)) (custom-documentation-insert custom) @@ -1539,7 +1546,7 @@ FG BG STIPPLE BOLD ITALIC UNDERLINE" "Update face of FIELD." (let ((from (custom-field-start field)) (custom (custom-field-custom field))) - (put-text-property from (+ from (length (custom-tag custom))) + (custom-put-text-property from (+ from (length (custom-tag custom))) 'face (custom-field-face field)))) (defun custom-const-valid (custom value) @@ -1828,9 +1835,9 @@ If the optional argument SAVE is non-nil, use that for saving changes." (let ((from (point))) (insert tag) (custom-category-set from (point) 'custom-button-properties) - (put-text-property from (point) 'custom-tag field) + (custom-put-text-property from (point) 'custom-tag field) (if data - (add-text-properties from (point) (list 'custom-data data))))) + (custom-add-text-properties from (point) (list 'custom-data data))))) (defun custom-documentation-insert (custom &rest ignore) "Insert documentation from CUSTOM in current buffer." @@ -1849,11 +1856,13 @@ If the optional argument SAVE is non-nil, use that for saving changes." "Describe how to execute COMMAND." (let ((from (point))) (insert "`" (key-description (where-is-internal command nil t)) "'") - (set-text-properties from (point) - (list 'face custom-button-face - mouse-face custom-mouse-face - 'custom-jump t ;Make TAB jump over it. - 'custom-tag command)) + (custom-set-text-properties from (point) + (list 'face custom-button-face + mouse-face custom-mouse-face + 'custom-jump t ;Make TAB jump over it. + 'custom-tag command + 'start-open t + 'end-open t)) (custom-category-set from (point) 'custom-documentation-properties)) (custom-help-insert ": " (custom-first-line (documentation command)) "\n")) @@ -2175,17 +2184,18 @@ If the optional argument is non-nil, show text iff the argument is positive." (insert-char (custom-padding custom) (- (custom-width custom) (- (point) from))) (custom-field-move field from (point)) - (set-text-properties + (custom-set-text-properties from (point) (list 'custom-field field 'custom-tag field 'face (custom-field-face field) - front-sticky t)))) + 'start-open t + 'end-open t)))) (defun custom-field-read (field) ;; Read the screen content of FIELD. (custom-read (custom-field-custom field) - (buffer-substring-no-properties (custom-field-start field) + (custom-buffer-substring-no-properties (custom-field-start field) (custom-field-end field)))) ;; Fields are shown in a special `active' face when point is inside @@ -2196,7 +2206,7 @@ If the optional argument is non-nil, show text iff the argument is positive." ;; Deactivate FIELD. (let ((before-change-functions nil) (after-change-functions nil)) - (put-text-property (custom-field-start field) (custom-field-end field) + (custom-put-text-property (custom-field-start field) (custom-field-end field) 'face (custom-field-face field)))) (defun custom-field-enter (field) @@ -2214,7 +2224,7 @@ If the optional argument is non-nil, show text iff the argument is positive." (setq pos (1- pos))) (if (< pos (point)) (goto-char pos)))) - (put-text-property start end 'face custom-field-active-face))) + (custom-put-text-property start end 'face custom-field-active-face))) (defun custom-field-resize (field) ;; Resize FIELD after change. @@ -2296,7 +2306,7 @@ If the optional argument is non-nil, show text iff the argument is positive." (let ((field custom-field-was)) (custom-assert '(prog1 field (setq custom-field-was nil))) ;; Prevent mixing fields properties. - (put-text-property begin end 'custom-field field) + (custom-put-text-property begin end 'custom-field field) ;; Update the field after modification. (if (eq (custom-field-property begin) field) (let ((field-end (custom-field-end field))) diff --git a/lisp/gnus-cache.el b/lisp/gnus-cache.el index 2dc7c7f9949..b478acce0f2 100644 --- a/lisp/gnus-cache.el +++ b/lisp/gnus-cache.el @@ -1,6 +1,5 @@ ;;; gnus-cache.el --- cache interface for Gnus - -;; Copyright (C) 1995 Free Software Foundation, Inc. +;; Copyright (C) 1995,96 Free Software Foundation, Inc. ;; Author: Lars Magne Ingebrigtsen ;; Keywords: news @@ -27,45 +26,55 @@ ;;; Code: (require 'gnus) +(eval-when-compile (require 'cl)) -(defvar gnus-cache-directory (concat gnus-article-save-directory "cache/") +(defvar gnus-cache-directory + (nnheader-concat gnus-directory "cache/") "*The directory where cached articles will be stored.") +(defvar gnus-cache-active-file + (concat (file-name-as-directory gnus-cache-directory) "active") + "*The cache active file.") + (defvar gnus-cache-enter-articles '(ticked dormant) "*Classes of articles to enter into the cache.") (defvar gnus-cache-remove-articles '(read) "*Classes of articles to remove from the cache.") +(defvar gnus-uncacheable-groups nil + "*Groups that match this regexp will not be cached. + +If you want to avoid caching your nnml groups, you could set this +variable to \"^nnml\".") + +;;; Internal variables. + (defvar gnus-cache-buffer nil) +(defvar gnus-cache-active-hashtb nil) +(defvar gnus-cache-active-altered nil) + +(eval-and-compile + (autoload 'nnml-generate-nov-databases-1 "nnml") + (autoload 'nnvirtual-find-group-art "nnvirtual")) -(defun gnus-cache-change-buffer (group) - (and gnus-cache-buffer - ;; see if the current group's overview cache has been loaded - (or (string= group (car gnus-cache-buffer)) - ;; another overview cache is current, save it - (gnus-cache-save-buffers))) - ;; if gnus-cache buffer is nil, create it - (or gnus-cache-buffer - ;; create cache buffer - (save-excursion - (setq gnus-cache-buffer - (cons group - (set-buffer (get-buffer-create " *gnus-cache-overview*")))) - (buffer-disable-undo (current-buffer)) - ;; insert the contents of this groups cache overview - (erase-buffer) - (let ((file (gnus-cache-file-name group ".overview"))) - (and (file-exists-p file) - (insert-file-contents file))) - ;; we have a fresh (empty/just loaded) buffer, - ;; mark it as unmodified to save a redundant write later. - (set-buffer-modified-p nil)))) +;;; Functions called from Gnus. +(defun gnus-cache-open () + "Initialize the cache." + (gnus-cache-read-active)) + +(gnus-add-shutdown 'gnus-cache-close 'gnus) + +(defun gnus-cache-close () + "Shut down the cache." + (gnus-cache-write-active) + (gnus-cache-save-buffers) + (setq gnus-cache-active-hashtb nil)) (defun gnus-cache-save-buffers () ;; save the overview buffer if it exists and has been modified @@ -99,185 +108,318 @@ (gnus-kill-buffer buffer) (setq gnus-cache-buffer nil)))) +(defun gnus-cache-possibly-enter-article + (group article headers ticked dormant unread &optional force) + (when (and (or force (not (eq gnus-use-cache 'passive))) + (numberp article) + (> article 0) + (vectorp headers)) ; This might be a dummy article. + ;; If this is a virtual group, we find the real group. + (when (gnus-virtual-group-p group) + (let ((result (nnvirtual-find-group-art + (gnus-group-real-name group) article))) + (setq group (car result) + headers (copy-sequence headers)) + (mail-header-set-number headers (cdr result)))) + (let ((number (mail-header-number headers)) + file dir) + (when (and (> number 0) ; Reffed article. + (or (not gnus-uncacheable-groups) + (not (string-match gnus-uncacheable-groups group))) + (or force + (gnus-cache-member-of-class + gnus-cache-enter-articles ticked dormant unread)) + (not (file-exists-p (setq file (gnus-cache-file-name + group number))))) + ;; Possibly create the cache directory. + (or (file-exists-p (setq dir (file-name-directory file))) + (gnus-make-directory dir)) + ;; Save the article in the cache. + (if (file-exists-p file) + t ; The article already is saved. + (save-excursion + (set-buffer nntp-server-buffer) + (let ((gnus-use-cache nil)) + (gnus-request-article-this-buffer number group)) + (when (> (buffer-size) 0) + (write-region (point-min) (point-max) file nil 'quiet) + (gnus-cache-change-buffer group) + (set-buffer (cdr gnus-cache-buffer)) + (goto-char (point-max)) + (forward-line -1) + (while (condition-case () + (and (not (bobp)) + (> (read (current-buffer)) number)) + (error + ;; The line was malformed, so we just remove it!! + (gnus-delete-line) + t)) + (forward-line -1)) + (if (bobp) + (if (not (eobp)) + (progn + (beginning-of-line) + (if (< (read (current-buffer)) number) + (forward-line 1))) + (beginning-of-line)) + (forward-line 1)) + (beginning-of-line) + ;; [number subject from date id references chars lines xref] + (insert (format "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t\n" + (mail-header-number headers) + (mail-header-subject headers) + (mail-header-from headers) + (mail-header-date headers) + (mail-header-id headers) + (or (mail-header-references headers) "") + (or (mail-header-chars headers) "") + (or (mail-header-lines headers) "") + (or (mail-header-xref headers) ""))) + ;; Update the active info. + (set-buffer gnus-summary-buffer) + (gnus-cache-update-active group number) + (push article gnus-newsgroup-cached) + (gnus-summary-update-secondary-mark article)) + t)))))) + +(defun gnus-cache-enter-remove-article (article) + "Mark ARTICLE for later possible removal." + (when article + (push article gnus-cache-removable-articles))) + +(defun gnus-cache-possibly-remove-articles () + "Possibly remove some of the removable articles." + (if (not (gnus-virtual-group-p gnus-newsgroup-name)) + (gnus-cache-possibly-remove-articles-1) + (let ((arts gnus-cache-removable-articles) + ga) + (while arts + (when (setq ga (nnvirtual-find-group-art + (gnus-group-real-name gnus-newsgroup-name) (pop arts))) + (let ((gnus-cache-removable-articles (list (cdr ga))) + (gnus-newsgroup-name (car ga))) + (gnus-cache-possibly-remove-articles-1))))) + (setq gnus-cache-removable-articles nil))) + +(defun gnus-cache-possibly-remove-articles-1 () + "Possibly remove some of the removable articles." + (unless (eq gnus-use-cache 'passive) + (let ((articles gnus-cache-removable-articles) + (cache-articles gnus-newsgroup-cached) + article) + (gnus-cache-change-buffer gnus-newsgroup-name) + (while articles + (if (memq (setq article (pop articles)) cache-articles) + ;; The article was in the cache, so we see whether we are + ;; supposed to remove it from the cache. + (gnus-cache-possibly-remove-article + article (memq article gnus-newsgroup-marked) + (memq article gnus-newsgroup-dormant) + (or (memq article gnus-newsgroup-unreads) + (memq article gnus-newsgroup-unselected)))))) + ;; The overview file might have been modified, save it + ;; safe because we're only called at group exit anyway. + (gnus-cache-save-buffers))) + +(defun gnus-cache-request-article (article group) + "Retrieve ARTICLE in GROUP from the cache." + (let ((file (gnus-cache-file-name group article)) + (buffer-read-only nil)) + (when (file-exists-p file) + (erase-buffer) + (gnus-kill-all-overlays) + (insert-file-contents file) + t))) + +(defun gnus-cache-possibly-alter-active (group active) + "Alter the ACTIVE info for GROUP to reflect the articles in the cache." + (let ((cache-active (gnus-gethash group gnus-cache-active-hashtb))) + (and cache-active + (< (car cache-active) (car active)) + (setcar active (car cache-active))) + (and cache-active + (> (cdr cache-active) (cdr active)) + (setcdr active (cdr cache-active))))) + +(defun gnus-cache-retrieve-headers (articles group &optional fetch-old) + "Retrieve the headers for ARTICLES in GROUP." + (let ((cached + (setq gnus-newsgroup-cached (gnus-cache-articles-in-group group)))) + (if (not cached) + ;; No cached articles here, so we just retrieve them + ;; the normal way. + (let ((gnus-use-cache nil)) + (gnus-retrieve-headers articles group fetch-old)) + (let ((uncached-articles (gnus-sorted-intersection + (gnus-sorted-complement articles cached) + articles)) + (cache-file (gnus-cache-file-name group ".overview")) + type) + ;; We first retrieve all the headers that we don't have in + ;; the cache. + (let ((gnus-use-cache nil)) + (when uncached-articles + (setq type (and articles + (gnus-retrieve-headers + uncached-articles group fetch-old))))) + (gnus-cache-save-buffers) + ;; Then we insert the cached headers. + (save-excursion + (cond + ((not (file-exists-p cache-file)) + ;; There are no cached headers. + type) + ((null type) + ;; There were no uncached headers (or retrieval was + ;; unsuccessful), so we use the cached headers exclusively. + (set-buffer nntp-server-buffer) + (erase-buffer) + (insert-file-contents cache-file) + 'nov) + ((eq type 'nov) + ;; We have both cached and uncached NOV headers, so we + ;; braid them. + (gnus-cache-braid-nov group cached) + type) + (t + ;; We braid HEADs. + (gnus-cache-braid-heads group (gnus-sorted-intersection + cached articles)) + type))))))) + +(defun gnus-cache-enter-article (&optional n) + "Enter the next N articles into the cache. +If not given a prefix, use the process marked articles instead. +Returns the list of articles entered." + (interactive "P") + (gnus-set-global-variables) + (let ((articles (gnus-summary-work-articles n)) + article out) + (while articles + (setq article (pop articles)) + (when (gnus-cache-possibly-enter-article + gnus-newsgroup-name article (gnus-summary-article-header article) + nil nil nil t) + (push article out)) + (gnus-summary-remove-process-mark article) + (gnus-summary-update-secondary-mark article)) + (gnus-summary-next-subject 1) + (gnus-summary-position-point) + (nreverse out))) + +(defun gnus-cache-remove-article (n) + "Remove the next N articles from the cache. +If not given a prefix, use the process marked articles instead. +Returns the list of articles removed." + (interactive "P") + (gnus-set-global-variables) + (gnus-cache-change-buffer gnus-newsgroup-name) + (let ((articles (gnus-summary-work-articles n)) + article out) + (while articles + (setq article (pop articles)) + (when (gnus-cache-possibly-remove-article article nil nil nil t) + (push article out)) + (gnus-summary-remove-process-mark article) + (gnus-summary-update-secondary-mark article)) + (gnus-summary-next-subject 1) + (gnus-summary-position-point) + (nreverse out))) + +(defun gnus-cached-article-p (article) + "Say whether ARTICLE is cached in the current group." + (memq article gnus-newsgroup-cached)) + +;;; Internal functions. + +(defun gnus-cache-change-buffer (group) + (and gnus-cache-buffer + ;; See if the current group's overview cache has been loaded. + (or (string= group (car gnus-cache-buffer)) + ;; Another overview cache is current, save it. + (gnus-cache-save-buffers))) + ;; if gnus-cache buffer is nil, create it + (or gnus-cache-buffer + ;; Create cache buffer + (save-excursion + (setq gnus-cache-buffer + (cons group + (set-buffer (get-buffer-create " *gnus-cache-overview*")))) + (buffer-disable-undo (current-buffer)) + ;; Insert the contents of this group's cache overview. + (erase-buffer) + (let ((file (gnus-cache-file-name group ".overview"))) + (and (file-exists-p file) + (insert-file-contents file))) + ;; We have a fresh (empty/just loaded) buffer, + ;; mark it as unmodified to save a redundant write later. + (set-buffer-modified-p nil)))) ;; Return whether an article is a member of a class. (defun gnus-cache-member-of-class (class ticked dormant unread) (or (and ticked (memq 'ticked class)) (and dormant (memq 'dormant class)) (and unread (memq 'unread class)) - (and (not unread) (memq 'read class)))) + (and (not unread) (not ticked) (not dormant) (memq 'read class)))) (defun gnus-cache-file-name (group article) (concat (file-name-as-directory gnus-cache-directory) - (if (gnus-use-long-file-name 'not-cache) - group - (let ((group (concat group ""))) - (if (string-match ":" group) - (aset group (match-beginning 0) ?/)) - (gnus-replace-chars-in-string group ?. ?/))) - "/" (if (stringp article) article (int-to-string article)))) - -(defun gnus-cache-possibly-enter-article - (group article headers ticked dormant unread) - (let ((number (mail-header-number headers)) - file dir) - (if (or (not (vectorp headers)) ; This might be a dummy article. - (< number 0) ; Reffed article from other group. - (not (gnus-cache-member-of-class - gnus-cache-enter-articles ticked dormant unread)) - (file-exists-p (setq file (gnus-cache-file-name group article)))) - () ; Do nothing. - ;; Possibly create the cache directory. - (or (file-exists-p (setq dir (file-name-directory file))) - (gnus-make-directory dir)) - ;; Save the article in the cache. - (if (file-exists-p file) - t ; The article already is saved, so we end here. - (let ((gnus-use-cache nil)) - (gnus-summary-select-article)) - (save-excursion - (set-buffer gnus-article-buffer) - (save-restriction - (widen) - (write-region (point-min) (point-max) file nil 'quiet)) - (gnus-cache-change-buffer group) - (set-buffer (cdr gnus-cache-buffer)) - (goto-char (point-max)) - (forward-line -1) - (while (condition-case () - (and (not (bobp)) - (> (read (current-buffer)) number)) - (error - ;; The line was malformed, so we just remove it!! - (gnus-delete-line) - t)) - (forward-line -1)) - (if (bobp) - (if (not (eobp)) - (progn - (beginning-of-line) - (if (< (read (current-buffer)) number) - (forward-line 1))) - (beginning-of-line)) - (forward-line 1)) - (beginning-of-line) - ;; [number subject from date id references chars lines xref] - (insert (format "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t\n" - (mail-header-number headers) - (mail-header-subject headers) - (mail-header-from headers) - (mail-header-date headers) - (mail-header-id headers) - (or (mail-header-references headers) "") - (or (mail-header-chars headers) "") - (or (mail-header-lines headers) "") - (or (mail-header-xref headers) "")))) - t)))) - -(defun gnus-cache-enter-remove-article (article) - (setq gnus-cache-removable-articles - (cons article gnus-cache-removable-articles))) - -(defsubst gnus-cache-possibly-remove-article - (article ticked dormant unread) - (let ((file (gnus-cache-file-name gnus-newsgroup-name article))) - (if (or (not (file-exists-p file)) - (not (gnus-cache-member-of-class - gnus-cache-remove-articles ticked dormant unread))) - nil + (file-name-as-directory + (if (gnus-use-long-file-name 'not-cache) + group + (let ((group (concat group ""))) + (if (string-match ":" group) + (aset group (match-beginning 0) ?/)) + (nnheader-replace-chars-in-string group ?. ?/)))) + (if (stringp article) article (int-to-string article)))) + +(defun gnus-cache-update-article (group article) + "If ARTICLE is in the cache, remove it and re-enter it." + (when (gnus-cache-possibly-remove-article article nil nil nil t) + (let ((gnus-use-cache nil)) + (gnus-cache-possibly-enter-article + gnus-newsgroup-name article (gnus-summary-article-header article) + nil nil nil t)))) + +(defun gnus-cache-possibly-remove-article (article ticked dormant unread + &optional force) + "Possibly remove ARTICLE from the cache." + (let ((group gnus-newsgroup-name) + (number article) + file) + ;; If this is a virtual group, we find the real group. + (when (gnus-virtual-group-p group) + (let ((result (nnvirtual-find-group-art + (gnus-group-real-name group) article))) + (setq group (car result) + number (cdr result)))) + (setq file (gnus-cache-file-name group number)) + (when (and (file-exists-p file) + (or force + (gnus-cache-member-of-class + gnus-cache-remove-articles ticked dormant unread))) (save-excursion (delete-file file) (set-buffer (cdr gnus-cache-buffer)) (goto-char (point-min)) - (if (or (looking-at (concat (int-to-string article) "\t")) - (search-forward (concat "\n" (int-to-string article) "\t") + (if (or (looking-at (concat (int-to-string number) "\t")) + (search-forward (concat "\n" (int-to-string number) "\t") (point-max) t)) (delete-region (progn (beginning-of-line) (point)) - (progn (forward-line 1) (point)))))))) - -(defun gnus-cache-possibly-remove-articles () - (let ((articles gnus-cache-removable-articles) - (cache-articles (gnus-cache-articles-in-group gnus-newsgroup-name)) - article) - (gnus-cache-change-buffer gnus-newsgroup-name) - (while articles - (setq article (car articles) - articles (cdr articles)) - (if (memq article cache-articles) - ;; The article was in the cache, so we see whether we are - ;; supposed to remove it from the cache. - (gnus-cache-possibly-remove-article - article (memq article gnus-newsgroup-marked) - (memq article gnus-newsgroup-dormant) - (or (memq article gnus-newsgroup-unreads) - (memq article gnus-newsgroup-unselected)))))) - ;; the overview file might have been modified, save it - ;; safe because we're only called at group exit anyway - (gnus-cache-save-buffers)) - - -(defun gnus-cache-request-article (article group) - (let ((file (gnus-cache-file-name group article))) - (if (not (file-exists-p file)) - () - (erase-buffer) - ;; There may be some overlays that we have to kill... - (insert "i") - (let ((overlays (overlays-at (point-min)))) - (while overlays - (delete-overlay (car overlays)) - (setq overlays (cdr overlays)))) - (erase-buffer) - (insert-file-contents file) + (progn (forward-line 1) (point))))) + (setq gnus-newsgroup-cached + (delq article gnus-newsgroup-cached)) + (gnus-summary-update-secondary-mark article) t))) (defun gnus-cache-articles-in-group (group) + "Return a sorted list of cached articles in GROUP." (let ((dir (file-name-directory (gnus-cache-file-name group 1))) articles) - (if (not (file-exists-p dir)) - nil - (setq articles (directory-files dir nil "^[0-9]+$" t)) - (if (not articles) - nil - (sort (mapcar (function (lambda (name) - (string-to-int name))) - articles) - '<))))) - -(defun gnus-cache-active-articles (group) - (let ((articles (gnus-cache-articles-in-group group))) - (and articles - (cons (car articles) (gnus-last-element articles))))) - -(defun gnus-cache-possibly-alter-active (group active) - (let ((cache-active (gnus-cache-active-articles group))) - (and cache-active (< (car cache-active) (car active)) - (setcar active (car cache-active))) - (and cache-active (> (cdr cache-active) (cdr active)) - (setcdr active (cdr cache-active))))) - -(defun gnus-cache-retrieve-headers (articles group) - (let* ((cached (gnus-cache-articles-in-group group)) - (articles (gnus-sorted-complement articles cached)) - (cache-file (gnus-cache-file-name group ".overview")) - type) - (let ((gnus-use-cache nil)) - (setq type (and articles (gnus-retrieve-headers articles group)))) - (gnus-cache-save-buffers) - (save-excursion - (cond ((not (file-exists-p cache-file)) - type) - ((null type) - (set-buffer nntp-server-buffer) - (erase-buffer) - (insert-file-contents cache-file) - 'nov) - ((eq type 'nov) - (gnus-cache-braid-nov group cached) - type) - (t - (gnus-cache-braid-heads group cached) - type))))) + (when (file-exists-p dir) + (sort (mapcar (lambda (name) (string-to-int name)) + (directory-files dir nil "^[0-9]+$" t)) + '<)))) (defun gnus-cache-braid-nov (group cached) (let ((cache-buf (get-buffer-create " *gnus-cache*")) @@ -331,7 +473,9 @@ (erase-buffer) (insert-file-contents (gnus-cache-file-name group (car cached))) (goto-char (point-min)) - (insert "220 " (int-to-string (car cached)) " Article retrieved.\n") + (insert "220 ") + (princ (car cached) (current-buffer)) + (insert " Article retrieved.\n") (search-forward "\n\n" nil 'move) (delete-region (point) (point-max)) (forward-char -1) @@ -340,23 +484,132 @@ (setq cached (cdr cached))) (kill-buffer cache-buf))) +;;;###autoload (defun gnus-jog-cache () "Go through all groups and put the articles into the cache." (interactive) - (let ((newsrc (cdr gnus-newsrc-alist)) - (gnus-cache-enter-articles '(unread)) - (gnus-mark-article-hook nil) + (let ((gnus-mark-article-hook nil) (gnus-expert-user t) + (nnmail-spool-file nil) + (gnus-use-dribble-file nil) + (gnus-novice-user nil) (gnus-large-newsgroup nil)) - (while newsrc - (gnus-summary-read-group (car (car newsrc))) - (if (not (eq major-mode 'gnus-summary-mode)) - () - (while gnus-newsgroup-unreads - (gnus-summary-select-article t t nil (car gnus-newsgroup-unreads)) - (setq gnus-newsgroup-unreads (cdr gnus-newsgroup-unreads))) - (kill-buffer (current-buffer))) - (setq newsrc (cdr newsrc))))) + ;; Start Gnus. + (gnus) + ;; Go through all groups... + (gnus-group-mark-buffer) + (gnus-group-universal-argument + nil nil + (lambda () + (gnus-summary-read-group nil nil t) + ;; ... and enter the articles into the cache. + (when (eq major-mode 'gnus-summary-mode) + (gnus-uu-mark-buffer) + (gnus-cache-enter-article) + (kill-buffer (current-buffer))))))) + +(defun gnus-cache-read-active (&optional force) + "Read the cache active file." + (unless (file-exists-p gnus-cache-directory) + (make-directory gnus-cache-directory t)) + (if (not (and (file-exists-p gnus-cache-active-file) + (or force (not gnus-cache-active-hashtb)))) + ;; There is no active file, so we generate one. + (gnus-cache-generate-active) + ;; We simply read the active file. + (save-excursion + (gnus-set-work-buffer) + (insert-file-contents gnus-cache-active-file) + (gnus-active-to-gnus-format + nil (setq gnus-cache-active-hashtb + (gnus-make-hashtable + (count-lines (point-min) (point-max))))) + (setq gnus-cache-active-altered nil)))) + +(defun gnus-cache-write-active (&optional force) + "Write the active hashtb to the active file." + (when (or force + (and gnus-cache-active-hashtb + gnus-cache-active-altered)) + (save-excursion + (gnus-set-work-buffer) + (mapatoms + (lambda (sym) + (when (and sym (boundp sym)) + (insert (format "%s %d %d y\n" + (symbol-name sym) (cdr (symbol-value sym)) + (car (symbol-value sym)))))) + gnus-cache-active-hashtb) + (gnus-make-directory (file-name-directory gnus-cache-active-file)) + (write-region + (point-min) (point-max) gnus-cache-active-file nil 'silent)) + ;; Mark the active hashtb as unaltered. + (setq gnus-cache-active-altered nil))) + +(defun gnus-cache-update-active (group number &optional low) + "Update the upper bound of the active info of GROUP to NUMBER. +If LOW, update the lower bound instead." + (let ((active (gnus-gethash group gnus-cache-active-hashtb))) + (if (null active) + ;; We just create a new active entry for this group. + (gnus-sethash group (cons number number) gnus-cache-active-hashtb) + ;; Update the lower or upper bound. + (if low + (setcar active number) + (setcdr active number)) + ;; Mark the active hashtb as altered. + (setq gnus-cache-active-altered t)))) + +;;;###autoload +(defun gnus-cache-generate-active (&optional directory) + "Generate the cache active file." + (interactive) + (let* ((top (null directory)) + (directory (expand-file-name (or directory gnus-cache-directory))) + (files (directory-files directory 'full)) + (group + (if top + "" + (string-match + (concat "^" (file-name-as-directory + (expand-file-name gnus-cache-directory))) + (directory-file-name directory)) + (nnheader-replace-chars-in-string + (substring (directory-file-name directory) (match-end 0)) + ?/ ?.))) + nums alphs) + (when top + (gnus-message 5 "Generating the cache active file...") + (setq gnus-cache-active-hashtb (gnus-make-hashtable 123))) + ;; Separate articles from all other files and directories. + (while files + (if (string-match "^[0-9]+$" (file-name-nondirectory (car files))) + (push (string-to-int (file-name-nondirectory (pop files))) nums) + (push (pop files) alphs))) + ;; If we have nums, then this is probably a valid group. + (when (setq nums (sort nums '<)) + (gnus-sethash group (cons (car nums) (gnus-last-element nums)) + gnus-cache-active-hashtb)) + ;; Go through all the other files. + (while alphs + (when (and (file-directory-p (car alphs)) + (not (string-match "^\\.\\.?$" + (file-name-nondirectory (car alphs))))) + ;; We descend directories. + (gnus-cache-generate-active (car alphs))) + (setq alphs (cdr alphs))) + ;; Write the new active file. + (when top + (gnus-cache-write-active t) + (gnus-message 5 "Generating the cache active file...done")))) + +;;;###autoload +(defun gnus-cache-generate-nov-databases (dir) + "Generate NOV files recursively starting in DIR." + (interactive (list gnus-cache-directory)) + (gnus-cache-close) + (let ((nnml-generate-active-function 'identity)) + (nnml-generate-nov-databases-1 dir))) (provide 'gnus-cache) diff --git a/lisp/gnus-cite.el b/lisp/gnus-cite.el index 5a5a247fc24..bc85ea42be0 100644 --- a/lisp/gnus-cite.el +++ b/lisp/gnus-cite.el @@ -1,6 +1,5 @@ ;;; gnus-cite.el --- parse citations in articles for Gnus - -;; Copyright (C) 1995 Free Software Foundation, Inc. +;; Copyright (C) 1995,96 Free Software Foundation, Inc. ;; Author: Per Abrahamsen ;; Keywords: news, mail @@ -29,13 +28,19 @@ (require 'gnus) (require 'gnus-msg) (require 'gnus-ems) +(eval-when-compile (require 'cl)) (eval-and-compile - (autoload 'gnus-article-add-button "gnus-vis") - ) + (autoload 'gnus-article-add-button "gnus-vis")) ;;; Customization: +(defvar gnus-cited-text-button-line-format "%(%{[...]%}%)\n" + "Format of cited text buttons.") + +(defvar gnus-cited-lines-visible nil + "The number of lines of hidden cited text to remain visible.") + (defvar gnus-cite-parse-max-size 25000 "Maximum article size (in bytes) where parsing citations is allowed. Set it to nil to parse all articles.") @@ -45,20 +50,20 @@ Set it to nil to parse all articles.") "Regexp matching the longest possible citation prefix on a line.") (defvar gnus-cite-max-prefix 20 - "Maximal possible length for a citation prefix.") + "Maximum possible length for a citation prefix.") (defvar gnus-supercite-regexp (concat "^\\(" gnus-cite-prefix-regexp "\\)? *" ">>>>> +\"\\([^\"\n]+\\)\" +==") - "Regexp matching normal SuperCite attribution lines. -The first regexp group should match a prefix added by another package.") + "Regexp matching normal Supercite attribution lines. +The first grouping must match prefixes added by other packages.") (defvar gnus-supercite-secondary-regexp "^.*\"\\([^\"\n]+\\)\" +==" - "Regexp matching mangled SuperCite attribution lines. -The first regexp group should match the SuperCite attribution.") + "Regexp matching mangled Supercite attribution lines. +The first regexp group should match the Supercite attribution.") (defvar gnus-cite-minimum-match-count 2 - "Minimal number of identical prefix'es before we believe it is a citation.") + "Minimum number of identical prefixes before we believe it's a citation.") ;see gnus-cus.el ;(defvar gnus-cite-face-list @@ -78,7 +83,7 @@ The first regexp group should match the SuperCite attribution.") (defvar gnus-cite-attribution-prefix "in article\\|in <" "Regexp matching the beginning of an attribution line.") -(defvar gnus-cite-attribution-postfix +(defvar gnus-cite-attribution-suffix "\\(wrote\\|writes\\|said\\|says\\):[ \t]*$" "Regexp matching the end of an attribution line. The text matching the first grouping will be used as a button.") @@ -112,9 +117,7 @@ The text matching the first grouping will be used as a button.") ;;; Internal Variables: -(defvar gnus-article-length nil) -;; Length of article last time we parsed it. -;; BUG! KLUDGE! UGLY! FIX ME! +(defvar gnus-cite-article nil) (defvar gnus-cite-prefix-alist nil) ;; Alist of citation prefixes. @@ -135,7 +138,13 @@ The text matching the first grouping will be used as a button.") ;; WROTE: is the attribution line number ;; IN: is the line number of the previous line if part of the same attribution, ;; PREFIX: Is the citation prefix of the attribution line(s), and -;; TAG: Is a SuperCite tag, if any. +;; TAG: Is a Supercite tag, if any. + +(defvar gnus-cited-text-button-line-format-alist + `((?b beg ?d) + (?e end ?d) + (?l (- end beg) ?d))) +(defvar gnus-cited-text-button-line-format-spec nil) ;;; Commands: @@ -149,7 +158,7 @@ corresponding citation merged with `gnus-cite-attribution-face'. Text is considered cited if at least `gnus-cite-minimum-match-count' lines matches `gnus-cite-prefix-regexp' with the same prefix. -Lines matching `gnus-cite-attribution-postfix' and perhaps +Lines matching `gnus-cite-attribution-suffix' and perhaps `gnus-cite-attribution-prefix' are considered attribution lines." (interactive (list 'force)) ;; Create dark or light faces if necessary. @@ -193,7 +202,7 @@ Lines matching `gnus-cite-attribution-postfix' and perhaps face (cdr (assoc prefix face-alist))) ;; Add attribution button. (goto-line number) - (if (re-search-forward gnus-cite-attribution-postfix + (if (re-search-forward gnus-cite-attribution-suffix (save-excursion (end-of-line 1) (point)) t) (gnus-article-add-button (match-beginning 1) (match-end 1) @@ -210,76 +219,203 @@ Lines matching `gnus-cite-attribution-postfix' and perhaps skip (gnus-cite-find-prefix number)) (gnus-cite-add-face number skip gnus-cite-attribution-face))))) -(defun gnus-article-hide-citation (&optional force) - "Hide all cited text except attribution lines. -See the documentation for `gnus-article-highlight-citation'." - (interactive (list 'force)) +(defun gnus-dissect-cited-text () + "Dissect the article buffer looking for cited text." (save-excursion (set-buffer gnus-article-buffer) - (gnus-cite-parse-maybe force) - (let ((buffer-read-only nil) - (alist gnus-cite-prefix-alist) - (inhibit-point-motion-hooks t) - numbers number) + (gnus-cite-parse-maybe) + (let ((alist gnus-cite-prefix-alist) + prefix numbers number marks m) + ;; Loop through citation prefixes. (while alist - (setq numbers (cdr (car alist)) - alist (cdr alist)) + (setq numbers (pop alist) + prefix (pop numbers)) (while numbers - (setq number (car numbers) - numbers (cdr numbers)) - (goto-line number) - (or (assq number gnus-cite-attribution-alist) - (add-text-properties (point) (progn (forward-line 1) (point)) - gnus-hidden-properties))))))) - -(defun gnus-article-hide-citation-maybe (&optional force) - "Hide cited text that has an attribution line. + (setq number (pop numbers)) + (goto-char (point-min)) + (forward-line number) + (push (cons (point-marker) "") marks) + (while (and numbers + (= (1- number) (car numbers))) + (setq number (pop numbers))) + (goto-char (point-min)) + (forward-line (1- number)) + (push (cons (point-marker) prefix) marks))) + (goto-char (point-min)) + (search-forward "\n\n" nil t) + (push (cons (point-marker) "") marks) + (goto-char (point-max)) + (re-search-backward gnus-signature-separator nil t) + (push (cons (point-marker) "") marks) + (setq marks (sort marks (lambda (m1 m2) (< (car m1) (car m2))))) + (let* ((omarks marks)) + (setq marks nil) + (while (cdr omarks) + (if (= (caar omarks) (caadr omarks)) + (progn + (unless (equal (cdar omarks) "") + (push (car omarks) marks)) + (unless (equal (cdadr omarks) "") + (push (cadr omarks) marks)) + (setq omarks (cdr omarks))) + (push (car omarks) marks)) + (setq omarks (cdr omarks))) + (when (car omarks) + (push (car omarks) marks)) + (setq marks (setq m (nreverse marks))) + (while (cddr m) + (if (and (equal (cdadr m) "") + (equal (cdar m) (cdaddr m)) + (goto-char (caadr m)) + (forward-line 1) + (= (point) (caaddr m))) + (setcdr m (cdddr m)) + (setq m (cdr m)))) + marks)))) + + +(defun gnus-article-fill-cited-article (&optional force) + "Do word wrapping in the current article." + (interactive (list t)) + (save-excursion + (set-buffer gnus-article-buffer) + (let ((buffer-read-only nil) + (inhibit-point-motion-hooks t) + (marks (gnus-dissect-cited-text)) + (adaptive-fill-mode nil)) + (save-restriction + (while (cdr marks) + (widen) + (narrow-to-region (caar marks) (caadr marks)) + (let ((adaptive-fill-regexp + (concat "^" (regexp-quote (cdar marks)) " *")) + (fill-prefix (cdar marks))) + (fill-region (point-min) (point-max))) + (set-marker (caar marks) nil) + (setq marks (cdr marks))) + (when marks + (set-marker (caar marks) nil)))))) + +(defun gnus-article-hide-citation (&optional arg force) + "Toggle hiding of all cited text except attribution lines. +See the documentation for `gnus-article-highlight-citation'. +If given a negative prefix, always show; if given a positive prefix, +always hide." + (interactive (append (gnus-hidden-arg) (list 'force))) + (setq gnus-cited-text-button-line-format-spec + (gnus-parse-format gnus-cited-text-button-line-format + gnus-cited-text-button-line-format-alist t)) + (unless (gnus-article-check-hidden-text 'cite arg) + (save-excursion + (set-buffer gnus-article-buffer) + (let ((buffer-read-only nil) + (marks (gnus-dissect-cited-text)) + (inhibit-point-motion-hooks t) + (props (nconc (list 'gnus-type 'cite) + gnus-hidden-properties)) + beg end) + (while marks + (setq beg nil + end nil) + (while (and marks (string= (cdar marks) "")) + (setq marks (cdr marks))) + (when marks + (setq beg (caar marks))) + (while (and marks (not (string= (cdar marks) ""))) + (setq marks (cdr marks))) + (when marks + (setq end (caar marks))) + ;; Skip past lines we want to leave visible. + (when (and beg end gnus-cited-lines-visible) + (goto-char beg) + (forward-line gnus-cited-lines-visible) + (if (>= (point) end) + (setq beg nil) + (setq beg (point-marker)))) + (when (and beg end) + (gnus-add-text-properties beg end props) + (goto-char beg) + (unless (save-excursion (search-backward "\n\n" nil t)) + (insert "\n")) + (gnus-article-add-button + (point) + (progn (eval gnus-cited-text-button-line-format-spec) (point)) + `gnus-article-toggle-cited-text (cons beg end)) + (set-marker beg (point)))))))) + +(defun gnus-article-toggle-cited-text (region) + "Toggle hiding the text in REGION." + (let (buffer-read-only) + (funcall + (if (text-property-any + (car region) (1- (cdr region)) + (car gnus-hidden-properties) (cadr gnus-hidden-properties)) + 'remove-text-properties 'gnus-add-text-properties) + (car region) (cdr region) gnus-hidden-properties))) + +(defun gnus-article-hide-citation-maybe (&optional arg force) + "Toggle hiding of cited text that has an attribution line. +If given a negative prefix, always show; if given a positive prefix, +always hide. This will do nothing unless at least `gnus-cite-hide-percentage' percent and at least `gnus-cite-hide-absolute' lines of the body is cited text with attributions. When called interactively, these two variables are ignored. See also the documentation for `gnus-article-highlight-citation'." - (interactive (list 'force)) + (interactive (append (gnus-hidden-arg) (list 'force))) + (unless (gnus-article-check-hidden-text 'cite arg) + (save-excursion + (set-buffer gnus-article-buffer) + (gnus-cite-parse-maybe force) + (goto-char (point-min)) + (search-forward "\n\n" nil t) + (let ((start (point)) + (atts gnus-cite-attribution-alist) + (buffer-read-only nil) + (inhibit-point-motion-hooks t) + (hiden 0) + total) + (goto-char (point-max)) + (re-search-backward gnus-signature-separator nil t) + (setq total (count-lines start (point))) + (while atts + (setq hiden (+ hiden (length (cdr (assoc (cdar atts) + gnus-cite-prefix-alist)))) + atts (cdr atts))) + (if (or force + (and (> (* 100 hiden) (* gnus-cite-hide-percentage total)) + (> hiden gnus-cite-hide-absolute))) + (progn + (setq atts gnus-cite-attribution-alist) + (while atts + (setq total (cdr (assoc (cdar atts) gnus-cite-prefix-alist)) + atts (cdr atts)) + (while total + (setq hiden (car total) + total (cdr total)) + (goto-line hiden) + (or (assq hiden gnus-cite-attribution-alist) + (gnus-add-text-properties + (point) (progn (forward-line 1) (point)) + (nconc (list 'gnus-type 'cite) + gnus-hidden-properties))))))))))) + +(defun gnus-article-hide-citation-in-followups () + "Hide cited text in non-root articles." + (interactive) (save-excursion (set-buffer gnus-article-buffer) - (gnus-cite-parse-maybe force) - (goto-char (point-min)) - (search-forward "\n\n" nil t) - (let ((start (point)) - (atts gnus-cite-attribution-alist) - (buffer-read-only nil) - (inhibit-point-motion-hooks t) - (hiden 0) - total) - (goto-char (point-max)) - (re-search-backward gnus-signature-separator nil t) - (setq total (count-lines start (point))) - (while atts - (setq hiden (+ hiden (length (cdr (assoc (cdr (car atts)) - gnus-cite-prefix-alist)))) - atts (cdr atts))) - (if (or force - (and (> (* 100 hiden) (* gnus-cite-hide-percentage total)) - (> hiden gnus-cite-hide-absolute))) - (progn - (setq atts gnus-cite-attribution-alist) - (while atts - (setq total (cdr (assoc (cdr (car atts)) gnus-cite-prefix-alist)) - atts (cdr atts)) - (while total - (setq hiden (car total) - total (cdr total)) - (goto-line hiden) - (or (assq hiden gnus-cite-attribution-alist) - (add-text-properties (point) - (progn (forward-line 1) (point)) - gnus-hidden-properties))))))))) + (let ((article (cdr gnus-article-current))) + (unless (save-excursion + (set-buffer gnus-summary-buffer) + (gnus-article-displayed-root-p article)) + (gnus-article-hide-citation))))) ;;; Internal functions: (defun gnus-cite-parse-maybe (&optional force) ;; Parse if the buffer has changes since last time. - (if (eq gnus-article-length (- (point-max) (point-min))) + (if (equal gnus-cite-article gnus-article-current) () ;;Reset parser information. (setq gnus-cite-prefix-alist nil @@ -291,7 +427,8 @@ See also the documentation for `gnus-article-highlight-citation'." gnus-cite-parse-max-size (> (buffer-size) gnus-cite-parse-max-size)) () - (setq gnus-article-length (- (point-max) (point-min))) + (setq gnus-cite-article (cons (car gnus-article-current) + (cdr gnus-article-current))) (gnus-cite-parse)))) (defun gnus-cite-parse () @@ -315,7 +452,7 @@ See also the documentation for `gnus-article-highlight-citation'." end (progn (beginning-of-line 2) (point)) start end) (goto-char begin) - ;; Ignore standard SuperCite attribution prefix. + ;; Ignore standard Supercite attribution prefix. (if (looking-at gnus-supercite-regexp) (if (match-end 1) (setq end (1+ (match-end 1))) @@ -327,7 +464,7 @@ See also the documentation for `gnus-article-highlight-citation'." ;; Each prefix. (setq end (match-end 0) prefix (buffer-substring begin end)) - (set-text-properties 0 (length prefix) nil prefix) + (gnus-set-text-properties 0 (length prefix) nil prefix) (setq entry (assoc prefix alist)) (if entry (setcdr entry (cons line (cdr entry))) @@ -374,7 +511,7 @@ See also the documentation for `gnus-article-highlight-citation'." ;; Parse current buffer searching for attribution lines. (goto-char (point-min)) (search-forward "\n\n" nil t) - (while (re-search-forward gnus-cite-attribution-postfix (point-max) t) + (while (re-search-forward gnus-cite-attribution-suffix (point-max) t) (let* ((start (match-beginning 0)) (end (match-end 0)) (wrote (count-lines (point-min) end)) @@ -392,7 +529,7 @@ See also the documentation for `gnus-article-highlight-citation'." (beginning-of-line 0) (point)) t) - (not (re-search-forward gnus-cite-attribution-postfix + (not (re-search-forward gnus-cite-attribution-suffix start t)) (count-lines (point-min) (1+ (point))))))) (if (eq wrote in) @@ -463,7 +600,7 @@ See also the documentation for `gnus-article-highlight-citation'." ;; ;; WROTE is the attribution line number. ;; PREFIX is the attribution line prefix. - ;; TAG is the SuperCite tag on the attribution line. + ;; TAG is the Supercite tag on the attribution line. (let ((atts gnus-cite-loose-attribution-alist) (case-fold-search t) att wrote in prefix tag regexp limit smallest best size) @@ -536,18 +673,19 @@ See also the documentation for `gnus-article-highlight-citation'." (defun gnus-cite-add-face (number prefix face) ;; At line NUMBER, ignore PREFIX and add FACE to the rest of the line. - (if face - (let ((inhibit-point-motion-hooks t) - from to) - (goto-line number) + (when face + (let ((inhibit-point-motion-hooks t) + from to) + (goto-line number) + (unless (eobp) ;; Sometimes things become confused. (forward-char (length prefix)) (skip-chars-forward " \t") (setq from (point)) (end-of-line 1) (skip-chars-backward " \t") (setq to (point)) - (if (< from to) - (gnus-overlay-put (gnus-make-overlay from to) 'face face))))) + (when (< from to) + (gnus-overlay-put (gnus-make-overlay from to) 'face face)))))) (defun gnus-cite-toggle (prefix) (save-excursion @@ -565,8 +703,10 @@ See also the documentation for `gnus-article-highlight-citation'." gnus-hidden-properties)) ((assq number gnus-cite-attribution-alist)) (t - (add-text-properties (point) (progn (forward-line 1) (point)) - gnus-hidden-properties))))))) + (gnus-add-text-properties + (point) (progn (forward-line 1) (point)) + (nconc (list 'gnus-type 'cite) + gnus-hidden-properties)))))))) (defun gnus-cite-find-prefix (line) ;; Return citation prefix for LINE. @@ -580,6 +720,11 @@ See also the documentation for `gnus-article-highlight-citation'." (setq prefix (car entry)))) prefix)) +(gnus-add-shutdown 'gnus-cache-close 'gnus) + +(defun gnus-cache-close () + (setq gnus-cite-prefix-alist nil)) + (gnus-ems-redefine) (provide 'gnus-cite) diff --git a/lisp/gnus-cus.el b/lisp/gnus-cus.el index 9bf51b126f5..12472e28c02 100644 --- a/lisp/gnus-cus.el +++ b/lisp/gnus-cus.el @@ -1,7 +1,6 @@ ;;; gnus-cus.el --- User friendly customization of Gnus - -;; Copyright (C) 1995 Free Software Foundation, Inc. - +;; Copyright (C) 1995,96 Free Software Foundation, Inc. +;; ;; Author: Per Abrahamsen ;; Keywords: help, news ;; Version: 0.1 @@ -29,12 +28,14 @@ (require 'custom) (require 'gnus-ems) +(require 'browse-url) +(eval-when-compile (require 'cl)) -;; The following is just helper functions and data, not ment to be set +;; The following is just helper functions and data, not meant to be set ;; by the user. (defun gnus-make-face (color) ;; Create entry for face with COLOR. - (custom-face-lookup color nil nil 'custom:asis 'custom:asis 'custom:asis)) + (custom-face-lookup color nil nil nil nil nil)) (defvar gnus-face-light-name-list '("light blue" "light cyan" "light yellow" "light pink" @@ -42,84 +43,107 @@ "turquoise")) (defvar gnus-face-dark-name-list - '("RoyalBlue" "firebrick" - "dark green" "OrangeRed" "dark khaki" "dark violet" - "SteelBlue4")) + '("dark blue" "firebrick" "dark green" "OrangeRed" + "dark khaki" "dark violet" "SteelBlue4")) ; CornflowerBlue SeaGreen OrangeRed SteelBlue4 DeepPink3 ; DarkOlviveGreen4 (custom-declare '() - '((tag . "GNUS") + '((tag . "Gnus") (doc . "\ The coffee-brewing, all singing, all dancing, kitchen sink newsreader.") (type . group) - (data ((tag . "Visual") - (doc . "\ -GNUS can be made colorful and fun or grey and dull as you wish.") - (type . group) - (data ((tag . "Visual") - (doc . "Enable visual features. + (data + ((tag . "Visual") + (doc . "\ +Gnus can be made colorful and fun or grey and dull as you wish.") + (type . group) + (data + ((tag . "Visual") + (doc . "Enable visual features. If `visual' is disabled, there will be no menus and few faces. Most of -the visual customization options below will be ignored. GNUS will use +the visual customization options below will be ignored. Gnus will use less space and be faster as a result.") - (default . t) - (name . gnus-visual) - (type . toggle)) - ((tag . "WWW Browser") - (doc . "\ + (default . + (summary-highlight group-highlight + article-highlight + mouse-face + summary-menu group-menu article-menu + tree-highlight menu highlight + browse-menu server-menu + page-marker tree-menu binary-menu pick-menu + grouplens-menu)) + (name . gnus-visual) + (type . sexp)) + ((tag . "WWW Browser") + (doc . "\ WWW Browser to call when clicking on an URL button in the article buffer. You can choose between one of the predefined browsers, or `Other'.") - (name . gnus-button-url) - (calculate . (cond ((boundp 'browse-url-browser-function) - browse-url-browser-function) - ((fboundp 'w3-fetch) - 'w3-fetch) - ((eq window-system 'x) - 'gnus-netscape-open-url))) - (type . choice) - (data ((tag . "W3") - (type . const) - (default . w3-fetch)) - ((tag . "Netscape") - (type . const) - (default . gnus-netscape-open-url)) - ((prompt . "Other") - (doc . "\ + (name . browse-url-browser-function) + (calculate . (cond ((boundp 'browse-url-browser-function) + browse-url-browser-function) + ((fboundp 'w3-fetch) + 'w3-fetch) + ((eq window-system 'x) + 'gnus-netscape-open-url))) + (type . choice) + (data + ((tag . "W3") + (type . const) + (default . w3-fetch)) + ((tag . "Netscape") + (type . const) + (default . browse-url-netscape)) + ((prompt . "Other") + (doc . "\ You must specify the name of a Lisp function here. The lisp function should open a WWW browser when called with an URL (a string). ") - (default . __uninitialized__) - (type . symbol)))) - ((tag . "Mouse Face") - (doc . "\ + (default . __uninitialized__) + (type . symbol)))) + ((tag . "Mouse Face") + (doc . "\ Face used for group or summary buffer mouse highlighting. The line beneath the mouse pointer will be highlighted with this face.") - (name . gnus-mouse-face) - (calculate . (if (boundp 'gnus-mouse-face) - gnus-mouse-face - 'highlight)) - (type . face)) - ((tag . "Article Display") - (doc . "Controls how the article buffer will look. - -The list below contains various filters you can use to change the look -of the article. If you leave the list empty, the article will appear -exactly as it is stored on the disk. The list entries will hide or -highlight various parts of the article, making it easier to find the -information you want.") - (name . gnus-article-display-hook) - (type . list) - (default . (gnus-article-hide-headers-if-wanted - gnus-article-treat-overstrike - gnus-article-maybe-highlight)) - (data ((type . repeat) - (header . nil) - (data (tag . "Filter") - (type . choice) - (data ((tag . "Treat Overstrike") - (doc . "\ + (name . gnus-mouse-face) + (calculate . (if (gnus-visual-p 'mouse-face 'highlight) + (if (boundp 'gnus-mouse-face) + gnus-mouse-face + 'highlight) + 'default)) + (type . face)) + ((tag . "Article Display") + (doc . "Controls how the article buffer will look. + +If you leave the list empty, the article will appear exactly as it is +stored on the disk. The list entries will hide or highlight various +parts of the article, making it easier to find the information you +want.") + (name . gnus-article-display-hook) + (type . list) + (calculate + . (if (and (string-match "xemacs" emacs-version) + (featurep 'xface)) + '(gnus-article-hide-headers-if-wanted + gnus-article-hide-boring-headers + gnus-article-treat-overstrike + gnus-article-maybe-highlight + gnus-article-display-x-face) + '(gnus-article-hide-headers-if-wanted + gnus-article-hide-boring-headers + gnus-article-treat-overstrike + gnus-article-maybe-highlight))) + (data + ((type . repeat) + (header . nil) + (data + (tag . "Filter") + (type . choice) + (data + ((tag . "Treat Overstrike") + (doc . "\ Convert use of overstrike into bold and underline. Two identical letters separated by a backspace are displayed as a @@ -129,178 +153,178 @@ technique was developed for old line printers (think about it), and is still in use on some newsgroups, in particular the ClariNet hierarchy. ") - (type . const) - (default . - gnus-article-treat-overstrike)) - ((tag . "Word Wrap") - (doc . "\ + (type . const) + (default . + gnus-article-treat-overstrike)) + ((tag . "Word Wrap") + (doc . "\ Format too long lines. ") - (type . const) - (default . gnus-article-word-wrap)) - ((tag . "Remove CR") - (doc . "\ + (type . const) + (default . gnus-article-word-wrap)) + ((tag . "Remove CR") + (doc . "\ Remove carriage returns from an article. ") - (type . const) - (default . gnus-article-remove-cr)) - ((tag . "Display X-Face") - (doc . "\ + (type . const) + (default . gnus-article-remove-cr)) + ((tag . "Display X-Face") + (doc . "\ Look for an X-Face header and display it if present. See also `X Face Command' for a definition of the external command used for decoding and displaying the face. ") - (type . const) - (default . gnus-article-display-x-face)) - ((tag . "Unquote Printable") - (doc . "\ + (type . const) + (default . gnus-article-display-x-face)) + ((tag . "Unquote Printable") + (doc . "\ Transform MIME quoted printable into 8-bit characters. Quoted printable is often seen by strings like `=EF' where you would expect a non-English letter. ") - (type . const) - (default . - gnus-article-de-quoted-unreadable)) - ((tag . "Universal Time") - (doc . "\ + (type . const) + (default . + gnus-article-de-quoted-unreadable)) + ((tag . "Universal Time") + (doc . "\ Convert date header to universal time. ") - (type . const) - (default . gnus-article-date-ut)) - ((tag . "Local Time") - (doc . "\ + (type . const) + (default . gnus-article-date-ut)) + ((tag . "Local Time") + (doc . "\ Convert date header to local timezone. ") - (type . const) - (default . gnus-article-date-local)) - ((tag . "Lapsed Time") - (doc . "\ + (type . const) + (default . gnus-article-date-local)) + ((tag . "Lapsed Time") + (doc . "\ Replace date header with a header showing the articles age. ") - (type . const) - (default . gnus-article-date-lapsed)) - ((tag . "Highlight") - (doc . "\ + (type . const) + (default . gnus-article-date-lapsed)) + ((tag . "Highlight") + (doc . "\ Highlight headers, citations, signature, and buttons. ") - (type . const) - (default . gnus-article-highlight)) - ((tag . "Maybe Highlight") - (doc . "\ + (type . const) + (default . gnus-article-highlight)) + ((tag . "Maybe Highlight") + (doc . "\ Highlight headers, signature, and buttons if `Visual' is turned on. ") - (type . const) - (default . - gnus-article-maybe-highlight)) - ((tag . "Highlight Some") - (doc . "\ + (type . const) + (default . + gnus-article-maybe-highlight)) + ((tag . "Highlight Some") + (doc . "\ Highlight headers, signature, and buttons. ") - (type . const) - (default . gnus-article-highlight-some)) - ((tag . "Highlight Headers") - (doc . "\ + (type . const) + (default . gnus-article-highlight-some)) + ((tag . "Highlight Headers") + (doc . "\ Highlight headers as specified by `Article Header Highlighting'. ") - (type . const) - (default . - gnus-article-highlight-headers)) - ((tag . "Highlight Signature") - (doc . "\ + (type . const) + (default . + gnus-article-highlight-headers)) + ((tag . "Highlight Signature") + (doc . "\ Highlight the signature as specified by `Article Signature Face'. ") - (type . const) - (default . - gnus-article-highlight-signature)) - ((tag . "Citation") - (doc . "\ + (type . const) + (default . + gnus-article-highlight-signature)) + ((tag . "Citation") + (doc . "\ Highlight the citations as specified by `Citation Faces'. ") - (type . const) - (default . - gnus-article-highlight-citation)) - ((tag . "Hide") - (doc . "\ + (type . const) + (default . + gnus-article-highlight-citation)) + ((tag . "Hide") + (doc . "\ Hide unwanted headers, excess citation, and the signature. ") - (type . const) - (default . gnus-article-hide)) - ((tag . "Hide Headers If Wanted") - (doc . "\ + (type . const) + (default . gnus-article-hide)) + ((tag . "Hide Headers If Wanted") + (doc . "\ Hide headers, but allow user to display them with `t' or `v'. ") - (type . const) - (default . - gnus-article-hide-headers-if-wanted)) - ((tag . "Hide Headers") - (doc . "\ + (type . const) + (default . + gnus-article-hide-headers-if-wanted)) + ((tag . "Hide Headers") + (doc . "\ Hide unwanted headers and possibly sort them as well. Most likely you want to use `Hide Headers If Wanted' instead. ") - (type . const) - (default . gnus-article-hide-headers)) - ((tag . "Hide Signature") - (doc . "\ + (type . const) + (default . gnus-article-hide-headers)) + ((tag . "Hide Signature") + (doc . "\ Hide the signature. ") - (type . const) - (default . gnus-article-hide-signature)) - ((tag . "Hide Excess Citations") - (doc . "\ + (type . const) + (default . gnus-article-hide-signature)) + ((tag . "Hide Excess Citations") + (doc . "\ Hide excess citation. Excess is defined by `Citation Hide Percentage' and `Citation Hide Absolute'. ") - (type . const) - (default . - gnus-article-hide-citation-maybe)) - ((tag . "Hide Citations") - (doc . "\ + (type . const) + (default . + gnus-article-hide-citation-maybe)) + ((tag . "Hide Citations") + (doc . "\ Hide all cited text. ") - (type . const) - (default . gnus-article-hide-citation)) - ((tag . "Add Buttons") - (doc . "\ + (type . const) + (default . gnus-article-hide-citation)) + ((tag . "Add Buttons") + (doc . "\ Make URL's into clickable buttons. ") - (type . const) - (default . gnus-article-add-buttons)) - ((prompt . "Other") - (doc . "\ + (type . const) + (default . gnus-article-add-buttons)) + ((prompt . "Other") + (doc . "\ Name of Lisp function to call. Push the `Filter' button to select one of the predefined filters. ") - (type . symbol))))))) - ((tag . "Article Button Face") - (doc . "\ + (type . symbol))))))) + ((tag . "Article Button Face") + (doc . "\ Face used for highlighting buttons in the article buffer. An article button is a piece of text that you can activate by pressing `RET' or `mouse-2' above it.") - (name . gnus-article-button-face) - (default . bold) - (type . face)) - ((tag . "Article Mouse Face") - (doc . "\ + (name . gnus-article-button-face) + (default . bold) + (type . face)) + ((tag . "Article Mouse Face") + (doc . "\ Face used for mouse highlighting in the article buffer. Article buttons will be displayed in this face when the cursor is above them.") - (name . gnus-article-mouse-face) - (default . highlight) - (type . face)) - ((tag . "Article Signature Face") - (doc . "\ + (name . gnus-article-mouse-face) + (default . highlight) + (type . face)) + ((tag . "Article Signature Face") + (doc . "\ Face used for highlighting a signature in the article buffer.") - (name . gnus-signature-face) - (default . italic) - (type . face)) - ((tag . "Article Header Highlighting") - (doc . "\ + (name . gnus-signature-face) + (default . italic) + (type . face)) + ((tag . "Article Header Highlighting") + (doc . "\ Controls highlighting of article header. Below is a list of article header names, and the faces used for @@ -322,110 +346,106 @@ If you only want to change the display of the name part for a specific header, specify `None' in the `Content' field. Similarly, specify `None' in the `Name' field if you only want to leave the name part alone.") - (name . gnus-header-face-alist) - (type . list) - (calculate . (cond ((not (eq gnus-display-type 'color)) - '(("" bold italic))) - ((eq gnus-background-mode 'dark) - (list (list "From" nil - (custom-face-lookup - "dark blue" nil nil t t - 'custom:asis)) - (list "Subject" nil - (custom-face-lookup - "pink" nil nil t t 'custom:asis)) - (list "Newsgroups:.*," nil - (custom-face-lookup - "yellow" nil nil t t 'custom:asis)) - (list "" - (custom-face-lookup - "cyan" nil nil t 'custom:asis 'custom:asis) - (custom-face-lookup - "forestgreen" - nil nil 'custom:asis t 'custom:asis)))) - (t - (list (list "From" nil - (custom-face-lookup - "RoyalBlue" - nil nil t t 'custom:asis)) - (list "Subject" nil - (custom-face-lookup - "firebrick" - nil nil t t 'custom:asis)) - (list "Newsgroups:.*," nil - (custom-face-lookup - "indianred" nil nil t t 'custom:asis)) - (list "" - (custom-face-lookup - "DarkGreen" - nil nil t 'custom:asis 'custom:asis) - (custom-face-lookup - "DarkGreen" - nil nil nil t 'custom:asis)))))) - (data ((type . repeat) - (header . nil) - (data (type . list) - (compact . t) - (data ((type . string) - (prompt . "Header") - (tag . "Header ")) - "\n " - ((type . face) - (prompt . "Name") - (tag . "Name ")) - "\n " - ((type . face) - (tag . "Content")) - "\n"))))) - ((tag . "Attribution Face") - (doc . "\ + (name . gnus-header-face-alist) + (type . list) + (calculate + . (cond + ((not (eq gnus-display-type 'color)) + '(("" bold italic))) + ((eq gnus-background-mode 'dark) + (list + (list "From" nil + (custom-face-lookup "light blue" nil nil t t nil)) + (list "Subject" nil + (custom-face-lookup "pink" nil nil t t nil)) + (list "Newsgroups:.*," nil + (custom-face-lookup "yellow" nil nil t t nil)) + (list + "" + (custom-face-lookup "cyan" nil nil t nil nil) + (custom-face-lookup "forestgreen" nil nil nil t + nil)))) + (t + (list + (list "From" nil + (custom-face-lookup "MidnightBlue" nil nil t t nil)) + (list "Subject" nil + (custom-face-lookup "firebrick" nil nil t t nil)) + (list "Newsgroups:.*," nil + (custom-face-lookup "indianred" nil nil t t nil)) + (list "" + (custom-face-lookup + "DarkGreen" nil nil t nil nil) + (custom-face-lookup "DarkGreen" nil nil + nil t nil)))))) + (data + ((type . repeat) + (header . nil) + (data + (type . list) + (compact . t) + (data + ((type . string) + (prompt . "Header") + (tag . "Header ")) + "\n " + ((type . face) + (prompt . "Name") + (tag . "Name ")) + "\n " + ((type . face) + (tag . "Content")) + "\n"))))) + ((tag . "Attribution Face") + (doc . "\ Face used for attribution lines. It is merged with the face for the cited text belonging to the attribution.") - (name . gnus-cite-attribution-face) - (default . underline) - (type . face)) - ((tag . "Citation Faces") - (doc . "\ + (name . gnus-cite-attribution-face) + (default . underline) + (type . face)) + ((tag . "Citation Faces") + (doc . "\ List of faces used for highlighting citations. When there are citations from multiple articles in the same message, Gnus will try to give each citation from each article its own face. This should make it easier to see who wrote what.") - (name . gnus-cite-face-list) - (import . gnus-custom-import-cite-face-list) - (type . list) - (calculate . (cond ((not (eq gnus-display-type 'color)) - '(italic)) - ((eq gnus-background-mode 'dark) - (mapcar 'gnus-make-face - gnus-face-light-name-list)) - (t - (mapcar 'gnus-make-face - gnus-face-dark-name-list)))) - (data ((type . repeat) - (header . nil) - (data (type . face) - (tag . "Face"))))) - ((tag . "Citation Hide Percentage") - (doc . "\ + (name . gnus-cite-face-list) + (import . gnus-custom-import-cite-face-list) + (type . list) + (calculate . (cond ((not (eq gnus-display-type 'color)) + '(italic)) + ((eq gnus-background-mode 'dark) + (mapcar 'gnus-make-face + gnus-face-light-name-list)) + (t + (mapcar 'gnus-make-face + gnus-face-dark-name-list)))) + (data + ((type . repeat) + (header . nil) + (data (type . face) + (tag . "Face"))))) + ((tag . "Citation Hide Percentage") + (doc . "\ Only hide excess citation if above this percentage of the body.") - (name . gnus-cite-hide-percentage) - (default . 50) - (type . integer)) - ((tag . "Citation Hide Absolute") - (doc . "\ + (name . gnus-cite-hide-percentage) + (default . 50) + (type . integer)) + ((tag . "Citation Hide Absolute") + (doc . "\ Only hide excess citation if above this number of lines in the body.") - (name . gnus-cite-hide-absolute) - (default . 10) - (type . integer)) - ((tag . "Summary Selected Face") - (doc . "\ + (name . gnus-cite-hide-absolute) + (default . 10) + (type . integer)) + ((tag . "Summary Selected Face") + (doc . "\ Face used for highlighting the current article in the summary buffer.") - (name . gnus-summary-selected-face) - (default . underline) - (type . face)) - ((tag . "Summary Line Highlighting") - (doc . "\ + (name . gnus-summary-selected-face) + (default . underline) + (type . face)) + ((tag . "Summary Line Highlighting") + (doc . "\ Controls the highlighting of summary buffer lines. Below is a list of `Form'/`Face' pairs. When deciding how a a @@ -443,87 +463,199 @@ score: The article's score default: The default article score. below: The score below which articles are automatically marked as read. mark: The article's mark.") - (name . gnus-summary-highlight) - (type . list) - (calculate . (cond ((not (eq gnus-display-type 'color)) - '(((> score default) . bold) - ((< score default) . italic))) - ((eq gnus-background-mode 'dark) - (list (cons '(= mark gnus-canceled-mark) - (custom-face-lookup "yellow" "black" nil 'custom:asis 'custom:asis 'custom:asis)) - (cons '(and (> score default) - (or (= mark gnus-dormant-mark) - (= mark gnus-ticked-mark))) - (custom-face-lookup "pink" nil nil t 'custom:asis 'custom:asis)) - (cons '(and (< score default) - (or (= mark gnus-dormant-mark) - (= mark gnus-ticked-mark))) - (custom-face-lookup "pink" nil nil 'custom:asis t 'custom:asis)) - (cons '(or (= mark gnus-dormant-mark) - (= mark gnus-ticked-mark)) - (custom-face-lookup "pink" nil nil 'custom:asis 'custom:asis 'custom:asis)) - - (cons '(and (> score default) (= mark gnus-ancient-mark)) - (custom-face-lookup "dark blue" nil nil t 'custom:asis 'custom:asis)) - (cons '(and (< score default) (= mark gnus-ancient-mark)) - (custom-face-lookup "SkyBlue" nil nil 'custom:asis t 'custom:asis)) - (cons '(= mark gnus-ancient-mark) - (custom-face-lookup "SkyBlue" nil nil 'custom:asis 'custom:asis 'custom:asis)) - - (cons '(and (> score default) (= mark gnus-unread-mark)) - (custom-face-lookup "white" nil nil t 'custom:asis 'custom:asis)) - (cons '(and (< score default) (= mark gnus-unread-mark)) - (custom-face-lookup "white" nil nil 'custom:asis t 'custom:asis)) - (cons '(= mark gnus-unread-mark) - (custom-face-lookup "white" nil nil 'custom:asis 'custom:asis 'custom:asis)) - - (cons '(> score default) 'bold) - (cons '(< score default) 'italic))) - (t - (list (cons '(= mark gnus-canceled-mark) - (custom-face-lookup "yellow" "black" nil 'custom:asis 'custom:asis 'custom:asis)) - (cons '(and (> score default) - (or (= mark gnus-dormant-mark) - (= mark gnus-ticked-mark))) - (custom-face-lookup "firebrick" nil nil t 'custom:asis 'custom:asis)) - (cons '(and (< score default) - (or (= mark gnus-dormant-mark) - (= mark gnus-ticked-mark))) - (custom-face-lookup "firebrick" nil nil 'custom:asis t 'custom:asis)) - (cons '(or (= mark gnus-dormant-mark) - (= mark gnus-ticked-mark)) - (custom-face-lookup "firebrick" nil nil 'custom:asis 'custom:asis 'custom:asis)) - - (cons '(and (> score default) (= mark gnus-ancient-mark)) - (custom-face-lookup "RoyalBlue" nil nil t 'custom:asis 'custom:asis)) - (cons '(and (< score default) (= mark gnus-ancient-mark)) - (custom-face-lookup "RoyalBlue" nil nil 'custom:asis t 'custom:asis)) - (cons '(= mark gnus-ancient-mark) - (custom-face-lookup "RoyalBlue" nil nil 'custom:asis 'custom:asis 'custom:asis)) - - (cons '(and (> score default) (/= mark gnus-unread-mark)) - (custom-face-lookup "DarkGreen" nil nil t 'custom:asis 'custom:asis)) - (cons '(and (< score default) (/= mark gnus-unread-mark)) - (custom-face-lookup "DarkGreen" nil nil 'custom:asis t 'custom:asis)) - (cons '(/= mark gnus-unread-mark) - (custom-face-lookup "DarkGreen" nil nil 'custom:asis 'custom:asis 'custom:asis)) - (cons '(> score default) 'bold) - (cons '(< score default) 'italic))))) - (data ((type . repeat) - (header . nil) - (data (type . pair) - (compact . t) - (data ((type . sexp) - (width . 60) - (tag . "Form")) - "\n " - ((type . face) - (tag . "Face")) - "\n"))))) - ;; Do not define `gnus-button-alist' before we have - ;; some `complexity' attribute so we can hide it from - ;; beginners. - ))))) + (name . gnus-summary-highlight) + (type . list) + (calculate + . (cond + ((not (eq gnus-display-type 'color)) + '(((> score default) . bold) + ((< score default) . italic))) + ((eq gnus-background-mode 'dark) + (list + (cons + '(= mark gnus-canceled-mark) + (custom-face-lookup "yellow" "black" nil + nil nil nil)) + (cons '(and (> score default) + (or (= mark gnus-dormant-mark) + (= mark gnus-ticked-mark))) + (custom-face-lookup + "pink" nil nil t nil nil)) + (cons '(and (< score default) + (or (= mark gnus-dormant-mark) + (= mark gnus-ticked-mark))) + (custom-face-lookup "pink" nil nil + nil t nil)) + (cons '(or (= mark gnus-dormant-mark) + (= mark gnus-ticked-mark)) + (custom-face-lookup + "pink" nil nil nil nil nil)) + + (cons + '(and (> score default) (= mark gnus-ancient-mark)) + (custom-face-lookup "medium blue" nil nil t + nil nil)) + (cons + '(and (< score default) (= mark gnus-ancient-mark)) + (custom-face-lookup "SkyBlue" nil nil + nil t nil)) + (cons + '(= mark gnus-ancient-mark) + (custom-face-lookup "SkyBlue" nil nil + nil nil nil)) + (cons '(and (> score default) (= mark gnus-unread-mark)) + (custom-face-lookup "white" nil nil t + nil nil)) + (cons '(and (< score default) (= mark gnus-unread-mark)) + (custom-face-lookup "white" nil nil + nil t nil)) + (cons '(= mark gnus-unread-mark) + (custom-face-lookup + "white" nil nil nil nil nil)) + + (cons '(> score default) 'bold) + (cons '(< score default) 'italic))) + (t + (list + (cons + '(= mark gnus-canceled-mark) + (custom-face-lookup + "yellow" "black" nil nil nil nil)) + (cons '(and (> score default) + (or (= mark gnus-dormant-mark) + (= mark gnus-ticked-mark))) + (custom-face-lookup "firebrick" nil nil + t nil nil)) + (cons '(and (< score default) + (or (= mark gnus-dormant-mark) + (= mark gnus-ticked-mark))) + (custom-face-lookup "firebrick" nil nil + nil t nil)) + (cons + '(or (= mark gnus-dormant-mark) + (= mark gnus-ticked-mark)) + (custom-face-lookup + "firebrick" nil nil nil nil nil)) + + (cons '(and (> score default) (= mark gnus-ancient-mark)) + (custom-face-lookup "RoyalBlue" nil nil + t nil nil)) + (cons '(and (< score default) (= mark gnus-ancient-mark)) + (custom-face-lookup "RoyalBlue" nil nil + nil t nil)) + (cons + '(= mark gnus-ancient-mark) + (custom-face-lookup + "RoyalBlue" nil nil nil nil nil)) + + (cons '(and (> score default) (/= mark gnus-unread-mark)) + (custom-face-lookup "DarkGreen" nil nil + t nil nil)) + (cons '(and (< score default) (/= mark gnus-unread-mark)) + (custom-face-lookup "DarkGreen" nil nil + nil t nil)) + (cons + '(/= mark gnus-unread-mark) + (custom-face-lookup "DarkGreen" nil nil + nil nil nil)) + + (cons '(> score default) 'bold) + (cons '(< score default) 'italic))))) + (data + ((type . repeat) + (header . nil) + (data (type . pair) + (compact . t) + (data ((type . sexp) + (width . 60) + (tag . "Form")) + "\n " + ((type . face) + (tag . "Face")) + "\n"))))) + + ((tag . "Group Line Highlighting") + (doc . "\ +Controls the highlighting of group buffer lines. + +Below is a list of `Form'/`Face' pairs. When deciding how a a +particular group line should be displayed, each form is +evaluated. The content of the face field after the first true form is +used. You can change how those group lines are displayed by +editing the face field. + +It is also possible to change and add form fields, but currently that +requires an understanding of Lisp expressions. Hopefully this will +change in a future release. For now, you can use the following +variables in the Lisp expression: + +group: The name of the group. +unread: The number of unread articles in the group. +method: The select method used. +mailp: Whether it's a mail group or not. +level: The level of the group. +score: The score of the group. +ticked: The number of ticked articles.") + (name . gnus-group-highlight) + (type . list) + (calculate + . (cond + ((not (eq gnus-display-type 'color)) + '((mailp . bold) + ((= unread 0) . italic))) + ((eq gnus-background-mode 'dark) + `(((and (not mailp) (eq level 1)) . + ,(custom-face-lookup "PaleTurquoise" nil nil t)) + ((and (not mailp) (eq level 2)) . + ,(custom-face-lookup "turquoise" nil nil t)) + ((and (not mailp) (eq level 3)) . + ,(custom-face-lookup "MediumTurquoise" nil nil t)) + ((and (not mailp) (>= level 4)) . + ,(custom-face-lookup "DarkTurquoise" nil nil t)) + ((and mailp (eq level 1)) . + ,(custom-face-lookup "aquamarine1" nil nil t)) + ((and mailp (eq level 2)) . + ,(custom-face-lookup "aquamarine2" nil nil t)) + ((and mailp (eq level 3)) . + ,(custom-face-lookup "aquamarine3" nil nil t)) + ((and mailp (>= level 4)) . + ,(custom-face-lookup "aquamarine4" nil nil t)) + )) + (t + `(((and (not mailp) (<= level 3)) . + ,(custom-face-lookup "ForestGreen" nil nil t)) + ((and (not mailp) (eq level 4)) . + ,(custom-face-lookup "DarkGreen" nil nil t)) + ((and (not mailp) (eq level 5)) . + ,(custom-face-lookup "CadetBlue4" nil nil t)) + ((and mailp (eq level 1)) . + ,(custom-face-lookup "DeepPink3" nil nil t)) + ((and mailp (eq level 2)) . + ,(custom-face-lookup "HotPink3" nil nil t)) + ((and mailp (eq level 3)) . + ,(custom-face-lookup "dark magenta" nil nil t)) + ((and mailp (eq level 4)) . + ,(custom-face-lookup "DeepPink4" nil nil t)) + ((and mailp (> level 4)) . + ,(custom-face-lookup "DarkOrchid4" nil nil t)) + )))) + (data + ((type . repeat) + (header . nil) + (data (type . pair) + (compact . t) + (data ((type . sexp) + (width . 60) + (tag . "Form")) + "\n " + ((type . face) + (tag . "Face")) + "\n"))))) + + ;; Do not define `gnus-button-alist' before we have + ;; some `complexity' attribute so we can hide it from + ;; beginners. + ))))) (defun gnus-custom-import-cite-face-list (custom alist) ;; Backward compatible grokking of light and dark. @@ -533,16 +665,6 @@ mark: The article's mark.") (setq alist (mapcar 'gnus-make-face gnus-face-dark-name-list)))) (funcall (custom-super custom 'import) custom alist)) -;(defun gnus-custom-import-swap-alist (custom alist) -; ;; Swap key and value in CUSTOM ALIST. -; (let ((swap (mapcar (lambda (e) (cons (cdr e) (car e))) alist))) -; (funcall (custom-super custom 'import) custom swap))) - -;(defun gnus-custom-export-swap-alist (custom alist) -; ;; Swap key and value in CUSTOM ALIST. -; (let ((swap (mapcar (lambda (e) (cons (cdr e) (car e))) alist))) -; (funcall (custom-super custom 'export) custom swap))) - (provide 'gnus-cus) ;;; gnus-cus.el ends here diff --git a/lisp/gnus-edit.el b/lisp/gnus-edit.el index e860233de74..4ac5e6777a1 100644 --- a/lisp/gnus-edit.el +++ b/lisp/gnus-edit.el @@ -1,36 +1,19 @@ ;;; gnus-edit.el --- Gnus SCORE file editing - -;; Copyright (C) 1995 Free Software Foundation, Inc. - +;; Copyright (C) 1995,96 Free Software Foundation, Inc. +;; ;; Author: Per Abrahamsen ;; Keywords: news, help ;; Version: 0.2 -;; This file is part of GNU Emacs. - -;; GNU Emacs is free software; you can redistribute it and/or modify -;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation; either version 2, or (at your option) -;; any later version. - -;; GNU Emacs is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. - -;; You should have received a copy of the GNU General Public License -;; along with GNU Emacs; see the file COPYING. If not, write to the -;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, -;; Boston, MA 02111-1307, USA. - ;;; Commentary: - +;; ;; Type `M-x gnus-score-customize RET' to invoke. ;;; Code: (require 'custom) (require 'gnus-score) +(eval-when-compile (require 'cl)) (defconst gnus-score-custom-data '((tag . "Score") @@ -64,7 +47,7 @@ the score file and the value of the global variable (query . gnus-score-custom-save)) ((name . file) (tag . "File") - (directory . "~/News/") + (directory . gnus-kill-files-directory) (default-file . "SCORE") (type . file)))) ((name . files) @@ -79,7 +62,7 @@ delete a score file from the list.") (data ((type . repeat) (header . nil) (data (type . file) - (directory . "~/News/"))))) + (directory . gnus-kill-files-directory))))) ((name . exclude-files) (tag . "Exclude Files") (doc . "\ @@ -94,7 +77,7 @@ delete a score file from the list.") (data ((type . repeat) (header . nil) (data (type . file) - (directory . "~/News/"))))) + (directory . gnus-kill-files-directory))))) ((name . mark) (tag . "Mark") (doc . "\ @@ -554,7 +537,8 @@ groups matched by the current score file.") 'gnus-score-custom-get 'gnus-score-custom-save)) (make-local-variable 'gnus-score-custom-file) - (setq gnus-score-custom-file (expand-file-name "SCORE" "~/News")) + (setq gnus-score-custom-file + (expand-file-name "SCORE" gnus-kill-files-directory)) (make-local-variable 'gnus-score-alist) (setq gnus-score-alist nil) (custom-reset-all)) @@ -566,9 +550,9 @@ groups matched by the current score file.") (if entry (mapcar 'gnus-score-custom-sanify (cdr entry)) (setq entry (assoc name gnus-score-alist)) - (if (or (memq name '(files exclude-files local)) - (and (eq name 'adapt) - (not (symbolp (car (cdr entry)))))) + (if (or (memq name '(files exclude-files local)) + (and (eq name 'adapt) + (not (symbolp (car (cdr entry)))))) (cdr entry) (car (cdr entry))))))) @@ -618,11 +602,11 @@ groups matched by the current score file.") (let ((file (custom-name-value 'file))) (if (eq file custom-nil) (error "You must specify a file name")) - (setq file (expand-file-name file "~/News")) + (setq file (expand-file-name file gnus-kill-files-directory)) (gnus-score-load file) (setq gnus-score-custom-file file) (custom-reset-all) - (message "Loaded"))) + (gnus-message 4 "Loaded"))) (defun gnus-score-custom-save () (interactive) @@ -639,7 +623,7 @@ groups matched by the current score file.") (gnus-make-directory (file-name-directory file)) (write-region (point-min) (point-max) file nil 'silent) (kill-buffer (current-buffer)))) - (message "Saved")) + (gnus-message 4 "Saved")) (provide 'gnus-edit) diff --git a/lisp/gnus-ems.el b/lisp/gnus-ems.el index a759acfc3bc..fb19e6cf711 100644 --- a/lisp/gnus-ems.el +++ b/lisp/gnus-ems.el @@ -1,6 +1,5 @@ ;;; gnus-ems.el --- functions for making Gnus work under different Emacsen - -;; Copyright (C) 1995 Free Software Foundation, Inc. +;; Copyright (C) 1995,96 Free Software Foundation, Inc. ;; Author: Lars Magne Ingebrigtsen ;; Keywords: news @@ -24,153 +23,89 @@ ;;; Commentary: -;;; This file has been censored by the Communications Decency Act. -;;; That law was passed under the guise of a ban on pornography, but -;;; it bans far more than that. This file did not contain pornography, -;;; but it was censored nonetheless. - -;;; For information on US government censorship of the Internet, and -;;; what you can do to bring back freedom of the press, see the web -;;; site http://www.vtw.org/ - ;;; Code: +(eval-when-compile (require 'cl)) + (defvar gnus-mouse-2 [mouse-2]) -(defvar gnus-group-mode-hook ()) -(defvar gnus-summary-mode-hook ()) -(defvar gnus-article-mode-hook ()) (defalias 'gnus-make-overlay 'make-overlay) (defalias 'gnus-overlay-put 'overlay-put) (defalias 'gnus-move-overlay 'move-overlay) +(defalias 'gnus-overlay-end 'overlay-end) +(defalias 'gnus-extent-detached-p 'ignore) +(defalias 'gnus-extent-start-open 'ignore) +(defalias 'gnus-set-text-properties 'set-text-properties) +(defalias 'gnus-group-remove-excess-properties 'ignore) +(defalias 'gnus-topic-remove-excess-properties 'ignore) +(defalias 'gnus-appt-select-lowest-window 'appt-select-lowest-window) +(defalias 'gnus-mail-strip-quoted-names 'mail-strip-quoted-names) +(defalias 'gnus-make-local-hook 'make-local-hook) +(defalias 'gnus-add-hook 'add-hook) +(defalias 'gnus-character-to-event 'identity) +(defalias 'gnus-add-text-properties 'add-text-properties) +(defalias 'gnus-put-text-property 'put-text-property) +(defalias 'gnus-mode-line-buffer-identification 'identity) + + +(eval-and-compile + (autoload 'gnus-xmas-define "gnus-xmas") + (autoload 'gnus-xmas-redefine "gnus-xmas") + (autoload 'appt-select-lowest-window "appt.el")) (or (fboundp 'mail-file-babyl-p) (fset 'mail-file-babyl-p 'rmail-file-p)) -;; Don't warn about these undefined variables. - ;defined in gnus.el -(defvar gnus-active-hashtb) -(defvar gnus-article-buffer) -(defvar gnus-auto-center-summary) -(defvar gnus-buffer-list) -(defvar gnus-current-headers) -(defvar gnus-level-killed) -(defvar gnus-level-zombie) -(defvar gnus-newsgroup-bookmarks) -(defvar gnus-newsgroup-dependencies) -(defvar gnus-newsgroup-headers-hashtb-by-number) -(defvar gnus-newsgroup-selected-overlay) -(defvar gnus-newsrc-hashtb) -(defvar gnus-read-mark) -(defvar gnus-refer-article-method) -(defvar gnus-reffed-article-number) -(defvar gnus-unread-mark) -(defvar gnus-version) -(defvar gnus-view-pseudos) -(defvar gnus-view-pseudos-separately) -(defvar gnus-visual) -(defvar gnus-zombie-list) - ;defined in gnus-msg.el -(defvar gnus-article-copy) -(defvar gnus-check-before-posting) - ;defined in gnus-vis.el -(defvar gnus-article-button-face) -(defvar gnus-article-mouse-face) -(defvar gnus-summary-selected-face) - - -;; We do not byte-compile this file, because error messages are such a -;; bore. - -(defun gnus-set-text-properties-xemacs (start end props &optional buffer) - "You should NEVER use this function. It is ideologically blasphemous. -It is provided only to ease porting of broken FSF Emacs programs." - (if (and (stringp buffer) (not (setq buffer (get-buffer buffer)))) - nil - (map-extents (lambda (extent ignored) - (remove-text-properties - start end - (list (extent-property extent 'text-prop) nil) - buffer)) - buffer start end nil nil 'text-prop) - (add-text-properties start end props buffer))) - -(eval - '(progn - (if (string-match "XEmacs\\|Lucid" emacs-version) - () - ;; Added by Per Abrahamsen . - (defvar gnus-display-type - (condition-case nil - (let ((display-resource (x-get-resource ".displayType" "DisplayType"))) - (cond (display-resource (intern (downcase display-resource))) - ((x-display-color-p) 'color) - ((x-display-grayscale-p) 'grayscale) - (t 'mono))) - (error 'mono)) - "A symbol indicating the display Emacs is running under. -The symbol should be one of `color', `grayscale' or `mono'. If Emacs -guesses this display attribute wrongly, either set this variable in -your `~/.emacs' or set the resource `Emacs.displayType' in your -`~/.Xdefaults'. See also `gnus-background-mode'. +;;; Mule functions. + +(defun gnus-mule-cite-add-face (number prefix face) + ;; At line NUMBER, ignore PREFIX and add FACE to the rest of the line. + (if face + (let ((inhibit-point-motion-hooks t) + from to) + (goto-line number) + (if (boundp 'MULE) + (forward-char (chars-in-string prefix)) + (forward-char (length prefix))) + (skip-chars-forward " \t") + (setq from (point)) + (end-of-line 1) + (skip-chars-backward " \t") + (setq to (point)) + (if (< from to) + (gnus-overlay-put (gnus-make-overlay from to) 'face face))))) + +(defun gnus-mule-max-width-function (el max-width) + (` (let* ((val (eval (, el))) + (valstr (if (numberp val) + (int-to-string val) val))) + (if (> (length valstr) (, max-width)) + (truncate-string valstr (, max-width)) + valstr)))) -This is a meta-variable that will affect what default values other -variables get. You would normally not change this variable, but -pounce directly on the real variables themselves.") - - (defvar gnus-background-mode - (condition-case nil - (let ((bg-resource (x-get-resource ".backgroundMode" - "BackgroundMode")) - (params (frame-parameters))) - (cond (bg-resource (intern (downcase bg-resource))) - ((and (cdr (assq 'background-color params)) - (< (apply '+ (x-color-values - (cdr (assq 'background-color params)))) - (* (apply '+ (x-color-values "white")) .6))) - 'dark) - (t 'light))) - (error 'light)) - "A symbol indicating the Emacs background brightness. -The symbol should be one of `light' or `dark'. -If Emacs guesses this frame attribute wrongly, either set this variable in -your `~/.emacs' or set the resource `Emacs.backgroundMode' in your -`~/.Xdefaults'. -See also `gnus-display-type'. - -This is a meta-variable that will affect what default values other -variables get. You would normally not change this variable, but -pounce directly on the real variables themselves.")) +(eval-and-compile + (if (string-match "XEmacs\\|Lucid" emacs-version) + () - (cond - ((string-match "XEmacs\\|Lucid" emacs-version) - ;; XEmacs definitions. - - (setq gnus-mouse-2 [button2]) - - (or (memq 'underline (list-faces)) - (and (fboundp 'make-face) - (funcall (intern "make-face") 'underline))) - ;; Must avoid calling set-face-underline-p directly, because it - ;; is a defsubst in emacs19, and will make the .elc files non - ;; portable! - (or (face-differs-from-default-p 'underline) - (funcall 'set-face-underline-p 'underline t)) - - (defalias 'gnus-make-overlay 'make-extent) - (defalias 'gnus-overlay-put 'set-extent-property) - (defun gnus-move-overlay (extent start end &optional buffer) - (set-extent-endpoints extent start end)) - - (require 'text-props) - (fset 'set-text-properties 'gnus-set-text-properties-xemacs) - - (or (boundp 'standard-display-table) (setq standard-display-table nil)) - (or (boundp 'read-event) (fset 'read-event 'next-command-event)) - - ;; Fix by "jeff (j.d.) sparkes" . - (defvar gnus-display-type (device-class) - "A symbol indicating the display Emacs is running under. + (defvar gnus-mouse-face-prop 'mouse-face + "Property used for highlighting mouse regions.") + + (defvar gnus-article-x-face-command + "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -" + "String or function to be executed to display an X-Face header. +If it is a string, the command will be executed in a sub-shell +asynchronously. The compressed face will be piped to this command.") + + ;; Added by Per Abrahamsen . + (defvar gnus-display-type + (condition-case nil + (let ((display-resource (x-get-resource ".displayType" "DisplayType"))) + (cond (display-resource (intern (downcase display-resource))) + ((x-display-color-p) 'color) + ((x-display-grayscale-p) 'grayscale) + (t 'mono))) + (error 'mono)) + "A symbol indicating the display Emacs is running under. The symbol should be one of `color', `grayscale' or `mono'. If Emacs guesses this display attribute wrongly, either set this variable in your `~/.emacs' or set the resource `Emacs.displayType' in your @@ -180,27 +115,20 @@ This is a meta-variable that will affect what default values other variables get. You would normally not change this variable, but pounce directly on the real variables themselves.") - - (or (fboundp 'x-color-values) - (fset 'x-color-values - (lambda (color) - (color-instance-rgb-components - (make-color-instance color))))) - - (defvar gnus-background-mode - (let ((bg-resource - (condition-case () - (x-get-resource ".backgroundMode" "BackgroundMode" 'string) - (error nil))) - (params (frame-parameters))) - (cond (bg-resource (intern (downcase bg-resource))) - ((and (assq 'background-color params) - (< (apply '+ (x-color-values - (cdr (assq 'background-color params)))) - (/ (apply '+ (x-color-values "white")) 3))) - 'dark) - (t 'light))) - "A symbol indicating the Emacs background brightness. + (defvar gnus-background-mode + (condition-case nil + (let ((bg-resource (x-get-resource ".backgroundMode" + "BackgroundMode")) + (params (frame-parameters))) + (cond (bg-resource (intern (downcase bg-resource))) + ((and (cdr (assq 'background-color params)) + (< (apply '+ (x-color-values + (cdr (assq 'background-color params)))) + (* (apply '+ (x-color-values "white")) .6))) + 'dark) + (t 'light))) + (error 'light)) + "A symbol indicating the Emacs background brightness. The symbol should be one of `light' or `dark'. If Emacs guesses this frame attribute wrongly, either set this variable in your `~/.emacs' or set the resource `Emacs.backgroundMode' in your @@ -209,28 +137,26 @@ See also `gnus-display-type'. This is a meta-variable that will affect what default values other variables get. You would normally not change this variable, but -pounce directly on the real variables themselves.") - +pounce directly on the real variables themselves.")) - (defun gnus-install-mouse-tracker () - (require 'mode-motion) - (setq mode-motion-hook 'mode-motion-highlight-line))) - - ((< emacs-minor-version 30) - ;; Remove the `intangible' prop. - (let ((props (and (boundp 'gnus-hidden-properties) - gnus-hidden-properties))) - (while (and props (not (eq (car (cdr props)) 'intangible))) - (setq props (cdr props))) - (and props (setcdr props (cdr (cdr (cdr props)))))) - (or (fboundp 'buffer-substring-no-properties) - (defun buffer-substring-no-properties (beg end) - (format "%s" (buffer-substring beg end))))) - - ((boundp 'MULE) - (provide 'gnusutil)) + (cond + ((string-match "XEmacs\\|Lucid" emacs-version) + (gnus-xmas-define)) + + ((or (not (boundp 'emacs-minor-version)) + (< emacs-minor-version 30)) + ;; Remove the `intangible' prop. + (let ((props (and (boundp 'gnus-hidden-properties) + gnus-hidden-properties))) + (while (and props (not (eq (car (cdr props)) 'intangible))) + (setq props (cdr props))) + (and props (setcdr props (cdr (cdr (cdr props)))))) + (or (fboundp 'buffer-substring-no-properties) + (defun buffer-substring-no-properties (beg end) + (format "%s" (buffer-substring beg end))))) - ))) + ((boundp 'MULE) + (provide 'gnusutil)))) (eval-and-compile (cond @@ -248,451 +174,64 @@ pounce directly on the real variables themselves.") (not (file-symlink-p file)) (file-exists-p file)))) (or (fboundp 'face-list) - (defun face-list (&rest args))) - ) - -(defun gnus-highlight-selected-summary-xemacs () - ;; Highlight selected article in summary buffer - (if gnus-summary-selected-face - (progn - (if gnus-newsgroup-selected-overlay - (delete-extent gnus-newsgroup-selected-overlay)) - (setq gnus-newsgroup-selected-overlay - (make-extent (gnus-point-at-bol) (gnus-point-at-eol))) - (set-extent-face gnus-newsgroup-selected-overlay - gnus-summary-selected-face)))) - -(defun gnus-summary-recenter-xemacs () - (let* ((top (cond ((< (window-height) 4) 0) - ((< (window-height) 7) 1) - (t 2))) - (height (- (window-height) 2)) - (bottom (save-excursion (goto-char (point-max)) - (forward-line (- height)) - (point))) - (window (get-buffer-window (current-buffer)))) - (and - ;; The user has to want it, - gnus-auto-center-summary - ;; the article buffer must be displayed, - (get-buffer-window gnus-article-buffer) - ;; Set the window start to either `bottom', which is the biggest - ;; possible valid number, or the second line from the top, - ;; whichever is the least. - (set-window-start - window (min bottom (save-excursion (forward-line (- top)) - (point))))))) - -(defun gnus-group-insert-group-line-info-xemacs (group) - (let ((entry (gnus-gethash group gnus-newsrc-hashtb)) - (beg (point)) - active info) - (if entry - (progn - (setq info (nth 2 entry)) - (gnus-group-insert-group-line - nil group (nth 1 info) (nth 3 info) (car entry) (nth 4 info))) - (setq active (gnus-gethash group gnus-active-hashtb)) - - (gnus-group-insert-group-line - nil group (if (member group gnus-zombie-list) gnus-level-zombie - gnus-level-killed) - nil (if active (- (1+ (cdr active)) (car active)) 0) nil)) - (save-excursion - (goto-char beg) - (remove-text-properties - (1+ (gnus-point-at-bol)) (1+ (gnus-point-at-eol)) - '(gnus-group nil))))) - -(defun gnus-summary-refer-article-xemacs (message-id) - "Refer article specified by MESSAGE-ID. -NOTE: This command only works with newsgroups that use real or simulated NNTP." - (interactive "sMessage-ID: ") - (if (or (not (stringp message-id)) - (zerop (length message-id))) - () - ;; Construct the correct Message-ID if necessary. - ;; Suggested by tale@pawl.rpi.edu. - (or (string-match "^<" message-id) - (setq message-id (concat "<" message-id))) - (or (string-match ">$" message-id) - (setq message-id (concat message-id ">"))) - (let ((header (car (gnus-gethash (downcase message-id) - gnus-newsgroup-dependencies)))) - (if header - (or (gnus-summary-goto-article (mail-header-number header)) - ;; The header has been read, but the article had been - ;; expunged, so we insert it again. - (let ((beg (point))) - (gnus-summary-insert-line - nil header 0 nil gnus-read-mark nil nil - (mail-header-subject header)) - (save-excursion - (goto-char beg) - (remove-text-properties - (1+ (gnus-point-at-bol)) (1+ (gnus-point-at-eol)) - '(gnus-number nil gnus-mark nil gnus-level nil))) - (forward-line -1) - (mail-header-number header))) - (let ((gnus-override-method gnus-refer-article-method) - (gnus-ancient-mark gnus-read-mark) - (tmp-point (window-start - (get-buffer-window gnus-article-buffer))) - number tmp-buf) - (and gnus-refer-article-method - (gnus-check-server gnus-refer-article-method)) - ;; Save the old article buffer. - (save-excursion - (set-buffer gnus-article-buffer) - (gnus-kill-buffer " *temp Article*") - (setq tmp-buf (rename-buffer " *temp Article*"))) - (prog1 - (if (gnus-article-prepare - message-id nil (gnus-read-header message-id)) - (progn - (setq number (mail-header-number gnus-current-headers)) - (gnus-rebuild-thread message-id) - (gnus-summary-goto-subject number) - (gnus-summary-recenter) - (gnus-article-set-window-start - (cdr (assq number gnus-newsgroup-bookmarks))) - message-id) - ;; We restore the old article buffer. - (save-excursion - (kill-buffer gnus-article-buffer) - (set-buffer tmp-buf) - (rename-buffer gnus-article-buffer) - (let ((buffer-read-only nil)) - (and tmp-point - (set-window-start (get-buffer-window (current-buffer)) - tmp-point))))))))))) - -(defun gnus-summary-insert-pseudos-xemacs (pslist &optional not-view) - (let ((buffer-read-only nil) - (article (gnus-summary-article-number)) - b) - (or (gnus-summary-goto-subject article) - (error "No such article: %d" article)) - (or gnus-newsgroup-headers-hashtb-by-number - (gnus-make-headers-hashtable-by-number)) - (gnus-summary-position-cursor) - ;; If all commands are to be bunched up on one line, we collect - ;; them here. - (if gnus-view-pseudos-separately - () - (let ((ps (setq pslist (sort pslist 'gnus-pseudos<))) - files action) - (while ps - (setq action (cdr (assq 'action (car ps)))) - (setq files (list (cdr (assq 'name (car ps))))) - (while (and ps (cdr ps) - (string= (or action "1") - (or (cdr (assq 'action (car (cdr ps)))) "2"))) - (setq files (cons (cdr (assq 'name (car (cdr ps)))) files)) - (setcdr ps (cdr (cdr ps)))) - (if (not files) - () - (if (not (string-match "%s" action)) - (setq files (cons " " files))) - (setq files (cons " " files)) - (and (assq 'execute (car ps)) - (setcdr (assq 'execute (car ps)) - (funcall (if (string-match "%s" action) - 'format 'concat) - action - (mapconcat (lambda (f) f) files " "))))) - (setq ps (cdr ps))))) - (if (and gnus-view-pseudos (not not-view)) - (while pslist - (and (assq 'execute (car pslist)) - (gnus-execute-command (cdr (assq 'execute (car pslist))) - (eq gnus-view-pseudos 'not-confirm))) - (setq pslist (cdr pslist))) - (save-excursion - (while pslist - (gnus-summary-goto-subject (or (cdr (assq 'article (car pslist))) - (gnus-summary-article-number))) - (forward-line 1) - (setq b (point)) - (insert " " - (file-name-nondirectory (cdr (assq 'name (car pslist)))) - ": " (or (cdr (assq 'execute (car pslist))) "") "\n") - (add-text-properties - b (1+ b) (list 'gnus-number gnus-reffed-article-number - 'gnus-mark gnus-unread-mark - 'gnus-level 0 - 'gnus-pseudo (car pslist))) - ;; Fire-trucking XEmacs redisplay bug with truncated lines. - (goto-char b) - (sit-for 0) - ;; Grumble.. fire-trucking XEmacs stickiness of text properties. - (remove-text-properties - (1+ b) (1+ (gnus-point-at-eol)) - '(gnus-number nil gnus-mark nil gnus-level nil)) - (forward-line -1) - (gnus-sethash (int-to-string gnus-reffed-article-number) - (car pslist) gnus-newsgroup-headers-hashtb-by-number) - (setq gnus-reffed-article-number (1- gnus-reffed-article-number)) - (setq pslist (cdr pslist))))))) - - -(defun gnus-copy-article-buffer-xemacs (&optional article-buffer) - (setq gnus-article-copy (get-buffer-create " *gnus article copy*")) - (buffer-disable-undo gnus-article-copy) - (or (memq gnus-article-copy gnus-buffer-list) - (setq gnus-buffer-list (cons gnus-article-copy gnus-buffer-list))) - (let ((article-buffer (or article-buffer gnus-article-buffer)) - buf) - (if (and (get-buffer article-buffer) - (buffer-name (get-buffer article-buffer))) - (save-excursion - (set-buffer article-buffer) - (widen) - (setq buf (buffer-substring (point-min) (point-max))) - (set-buffer gnus-article-copy) - (erase-buffer) - (insert (format "%s" buf)))))) - -(defun gnus-article-push-button-xemacs (event) - "Check text under the mouse pointer for a callback function. -If the text under the mouse pointer has a `gnus-callback' property, -call it with the value of the `gnus-data' text property." - (interactive "e") - (set-buffer (window-buffer (event-window event))) - (let* ((pos (event-closest-point event)) - (data (get-text-property pos 'gnus-data)) - (fun (get-text-property pos 'gnus-callback))) - (if fun (funcall fun data)))) - -;; Re-build the thread containing ID. -(defun gnus-rebuild-thread-xemacs (id) - (let ((dep gnus-newsgroup-dependencies) - (buffer-read-only nil) - parent headers refs thread art) - (while (and id (setq headers - (car (setq art (gnus-gethash (downcase id) - dep))))) - (setq parent art) - (setq id (and (setq refs (mail-header-references headers)) - (string-match "\\(<[^>]+>\\) *$" refs) - (substring refs (match-beginning 1) (match-end 1))))) - (setq thread (gnus-make-sub-thread (car parent))) - (gnus-rebuild-remove-articles thread) - (let ((beg (point))) - (gnus-summary-prepare-threads (list thread) 0) - (save-excursion - (while (and (>= (point) beg) - (not (bobp))) - (or (eobp) - (remove-text-properties - (1+ (gnus-point-at-bol)) (1+ (gnus-point-at-eol)) - '(gnus-number nil gnus-mark nil gnus-level nil))) - (forward-line -1))) - (gnus-summary-update-lines beg (point))))) - - -;; Fixed by Christopher Davis . -(defun gnus-article-add-button-xemacs (from to fun &optional data) - "Create a button between FROM and TO with callback FUN and data DATA." - (and gnus-article-button-face - (gnus-overlay-put (gnus-make-overlay from to) 'face gnus-article-button-face)) - (add-text-properties from to - (append - (and gnus-article-mouse-face - (list 'mouse-face gnus-article-mouse-face)) - (list 'gnus-callback fun) - (and data (list 'gnus-data data)) - (list 'highlight t)))) - -(defun gnus-window-top-edge-xemacs (&optional window) - (nth 1 (window-pixel-edges window))) - -;; Select the lowest window on the frame. -(defun gnus-appt-select-lowest-window-xemacs () - (let* ((lowest-window (selected-window)) - (bottom-edge (car (cdr (cdr (cdr (window-pixel-edges)))))) - (last-window (previous-window)) - (window-search t)) - (while window-search - (let* ((this-window (next-window)) - (next-bottom-edge (car (cdr (cdr (cdr - (window-pixel-edges - this-window))))))) - (if (< bottom-edge next-bottom-edge) - (progn - (setq bottom-edge next-bottom-edge) - (setq lowest-window this-window))) - - (select-window this-window) - (if (eq last-window this-window) - (progn - (select-window lowest-window) - (setq window-search nil))))))) + (defun face-list (&rest args)))) + +(eval-and-compile + (let ((case-fold-search t)) + (cond + ((string-match "windows-nt\\|os/2\\|emx" (format "%s" system-type)) + (setq nnheader-file-name-translation-alist + (append nnheader-file-name-translation-alist + '((?: . ?_) + (?+ . ?-)))))))) + +(defvar gnus-tmp-unread) +(defvar gnus-tmp-replied) +(defvar gnus-tmp-score-char) +(defvar gnus-tmp-indentation) +(defvar gnus-tmp-opening-bracket) +(defvar gnus-tmp-lines) +(defvar gnus-tmp-name) +(defvar gnus-tmp-closing-bracket) +(defvar gnus-tmp-subject-or-nil) (defun gnus-ems-redefine () (cond ((string-match "XEmacs\\|Lucid" emacs-version) - ;; XEmacs definitions. - (fset 'gnus-mouse-face-function 'identity) - (fset 'gnus-summary-make-display-table (lambda () nil)) - (fset 'gnus-visual-turn-off-edit-menu 'identity) - (fset 'gnus-highlight-selected-summary - 'gnus-highlight-selected-summary-xemacs) - (fset 'gnus-summary-recenter 'gnus-summary-recenter-xemacs) - (fset 'gnus-group-insert-group-line-info - 'gnus-group-insert-group-line-info-xemacs) - (fset 'gnus-copy-article-buffer 'gnus-copy-article-buffer-xemacs) - (fset 'gnus-summary-refer-article 'gnus-summary-refer-article-xemacs) - (fset 'gnus-summary-insert-pseudos 'gnus-summary-insert-pseudos-xemacs) - (fset 'gnus-article-push-button 'gnus-article-push-button-xemacs) - (fset 'gnus-rebuild-thread 'gnus-rebuild-thread-xemacs) - (fset 'gnus-article-add-button 'gnus-article-add-button-xemacs) - (fset 'gnus-window-top-edge 'gnus-window-top-edge-xemacs) - (fset 'set-text-properties 'gnus-set-text-properties-xemacs) - - (or (fboundp 'appt-select-lowest-window) - (fset 'appt-select-lowest-window - 'gnus-appt-select-lowest-window-xemacs)) - - (if (not gnus-visual) - () - (setq gnus-group-mode-hook - (cons - '(lambda () - (easy-menu-add gnus-group-reading-menu) - (easy-menu-add gnus-group-group-menu) - (easy-menu-add gnus-group-misc-menu) - (gnus-install-mouse-tracker)) - gnus-group-mode-hook)) - (setq gnus-summary-mode-hook - (cons - '(lambda () - (easy-menu-add gnus-summary-article-menu) - (easy-menu-add gnus-summary-thread-menu) - (easy-menu-add gnus-summary-misc-menu) - (easy-menu-add gnus-summary-post-menu) - (easy-menu-add gnus-summary-kill-menu) - (gnus-install-mouse-tracker)) - gnus-summary-mode-hook)) - (setq gnus-article-mode-hook - (cons - '(lambda () - (easy-menu-add gnus-article-article-menu) - (easy-menu-add gnus-article-treatment-menu)) - gnus-article-mode-hook))) - - (defvar gnus-logo (make-glyph (make-specifier 'image))) - - (defun gnus-group-startup-xmessage (&optional x y) - "Insert startup message in current buffer." - ;; Insert the message. - (erase-buffer) - (if (featurep 'xpm) - (progn - (set-glyph-property gnus-logo 'image "~/tmp/gnus.xpm") - (set-glyph-image gnus-logo "~/tmp/gnus.xpm" 'global 'x) - - (insert " ") - (set-extent-begin-glyph (make-extent (point) (point)) gnus-logo) - (insert " - Gnus * A newsreader for Emacsen - A Praxis Release * larsi@ifi.uio.no") - (goto-char (point-min)) - (while (not (eobp)) - (insert (make-string (/ (max (- (window-width) (or x 35)) 0) 2) - ? )) - (forward-line 1)) - (goto-char (point-min)) - ;; +4 is fuzzy factor. - (insert-char ?\n (/ (max (- (window-height) (or y 24)) 0) 2))) - - (insert - (format " - %s - A newsreader - for GNU Emacs - - Based on GNUS - written by - Masanobu UMEDA - - A Praxis Release - larsi@ifi.uio.no -" - gnus-version)) - ;; And then hack it. - ;; 18 is the longest line. - (indent-rigidly (point-min) (point-max) - (/ (max (- (window-width) (or x 28)) 0) 2)) - (goto-char (point-min)) - ;; +4 is fuzzy factor. - (insert-char ?\n (/ (max (- (window-height) (or y 12)) 0) 2))) - - ;; Fontify some. - (goto-char (point-min)) - (search-forward "Praxis") - (put-text-property (match-beginning 0) (match-end 0) 'face 'bold) - (goto-char (point-min))) - - - - ) + (gnus-xmas-redefine)) ((boundp 'MULE) ;; Mule definitions - (if (not (fboundp 'truncate-string)) - (defun truncate-string (str width) - (let ((w (string-width str)) - (col 0) (idx 0) (p-idx 0) chr) - (if (<= w width) - str - (while (< col width) - (setq chr (aref str idx) - col (+ col (char-width chr)) - p-idx idx - idx (+ idx (char-bytes chr)) - )) - (substring str 0 (if (= col width) - idx - p-idx)) - ))) - ) (defalias 'gnus-truncate-string 'truncate-string) - (defun gnus-cite-add-face (number prefix face) - ;; At line NUMBER, ignore PREFIX and add FACE to the rest of the line. - (if face - (let ((inhibit-point-motion-hooks t) - from to) - (goto-line number) - (if (boundp 'MULE) - (forward-char (chars-in-string prefix)) - (forward-char (length prefix))) - (skip-chars-forward " \t") - (setq from (point)) - (end-of-line 1) - (skip-chars-backward " \t") - (setq to (point)) - (if (< from to) - (gnus-overlay-put (gnus-make-overlay from to) 'face face))))) - - (defun gnus-max-width-function (el max-width) - (` (let* ((val (eval (, el))) - (valstr (if (numberp val) - (int-to-string val) val))) - (if (> (length valstr) (, max-width)) - (truncate-string valstr (, max-width)) - valstr)))) - (fset 'gnus-summary-make-display-table (lambda () nil)) + (fset 'gnus-cite-add-face 'gnus-mule-cite-add-face) + (fset 'gnus-max-width-function 'gnus-mule-max-width-function) (if (boundp 'gnus-check-before-posting) (setq gnus-check-before-posting (delq 'long-lines - (delq 'control-chars gnus-check-before-posting))) - ) - ) - )) + (delq 'control-chars gnus-check-before-posting)))) + + (defun gnus-summary-line-format-spec () + (insert gnus-tmp-unread gnus-tmp-replied + gnus-tmp-score-char gnus-tmp-indentation) + (put-text-property + (point) + (progn + (insert + gnus-tmp-opening-bracket + (format "%4d: %-20s" + gnus-tmp-lines + (if (> (length gnus-tmp-name) 20) + (truncate-string gnus-tmp-name 20) + gnus-tmp-name)) + gnus-tmp-closing-bracket) + (point)) + gnus-mouse-face-prop gnus-mouse-face) + (insert " " gnus-tmp-subject-or-nil "\n")) + ))) + (provide 'gnus-ems) diff --git a/lisp/gnus-kill.el b/lisp/gnus-kill.el index 628fff43e2e..ac76cd201d0 100644 --- a/lisp/gnus-kill.el +++ b/lisp/gnus-kill.el @@ -1,6 +1,5 @@ ;;; gnus-kill.el --- kill commands for Gnus - -;; Copyright (C) 1995 Free Software Foundation, Inc. +;; Copyright (C) 1995,96 Free Software Foundation, Inc. ;; Author: Masanobu UMEDA ;; Lars Magne Ingebrigtsen @@ -28,6 +27,7 @@ ;;; Code: (require 'gnus) +(eval-when-compile (require 'cl)) (defvar gnus-kill-file-mode-hook nil "*A hook for Gnus kill file mode.") @@ -43,12 +43,12 @@ (defmacro gnus-raise (field expression level) - (` (gnus-kill (, field) (, expression) - (function (gnus-summary-raise-score (, level))) t))) + `(gnus-kill ,field ,expression + (function (gnus-summary-raise-score ,level)) t)) (defmacro gnus-lower (field expression level) - (` (gnus-kill (, field) (, expression) - (function (gnus-summary-raise-score (- (, level)))) t))) + `(gnus-kill ,field ,expression + (function (gnus-summary-raise-score (- ,level))) t)) ;;; ;;; Gnus Kill File Mode @@ -56,23 +56,16 @@ (defvar gnus-kill-file-mode-map nil) -(if gnus-kill-file-mode-map - nil - (setq gnus-kill-file-mode-map (copy-keymap emacs-lisp-mode-map)) - (define-key gnus-kill-file-mode-map - "\C-c\C-k\C-s" 'gnus-kill-file-kill-by-subject) - (define-key gnus-kill-file-mode-map - "\C-c\C-k\C-a" 'gnus-kill-file-kill-by-author) - (define-key gnus-kill-file-mode-map - "\C-c\C-k\C-t" 'gnus-kill-file-kill-by-thread) - (define-key gnus-kill-file-mode-map - "\C-c\C-k\C-x" 'gnus-kill-file-kill-by-xref) - (define-key gnus-kill-file-mode-map - "\C-c\C-a" 'gnus-kill-file-apply-buffer) - (define-key gnus-kill-file-mode-map - "\C-c\C-e" 'gnus-kill-file-apply-last-sexp) - (define-key gnus-kill-file-mode-map - "\C-c\C-c" 'gnus-kill-file-exit)) +(unless gnus-kill-file-mode-map + (gnus-define-keymap + (setq gnus-kill-file-mode-map (copy-keymap emacs-lisp-mode-map)) + "\C-c\C-k\C-s" gnus-kill-file-kill-by-subject + "\C-c\C-k\C-a" gnus-kill-file-kill-by-author + "\C-c\C-k\C-t" gnus-kill-file-kill-by-thread + "\C-c\C-k\C-x" gnus-kill-file-kill-by-xref + "\C-c\C-a" gnus-kill-file-apply-buffer + "\C-c\C-e" gnus-kill-file-apply-last-sexp + "\C-c\C-c" gnus-kill-file-exit)) (defun gnus-kill-file-mode () "Major mode for editing kill files. @@ -181,7 +174,7 @@ If NEWSGROUP is nil, the global kill file is selected." (gnus-kill-file-mode) (bury-buffer buffer))) -(defun gnus-kill-file-enter-kill (field regexp) +(defun gnus-kill-file-enter-kill (field regexp &optional dont-move) ;; Enter kill file entry. ;; FIELD: String containing the name of the header field to kill. ;; REGEXP: The string to kill. @@ -189,8 +182,8 @@ If NEWSGROUP is nil, the global kill file is selected." (let (string) (or (eq major-mode 'gnus-kill-file-mode) (gnus-kill-set-kill-buffer)) - (current-buffer) - (goto-char (point-max)) + (unless dont-move + (goto-char (point-max))) (insert (setq string (format "(gnus-kill %S %S)\n" field regexp))) (gnus-kill-file-apply-string string)))) @@ -202,7 +195,7 @@ If NEWSGROUP is nil, the global kill file is selected." (if (vectorp gnus-current-headers) (regexp-quote (gnus-simplify-subject (mail-header-subject gnus-current-headers))) - ""))) + "") t)) (defun gnus-kill-file-kill-by-author () "Kill by author." @@ -211,7 +204,7 @@ If NEWSGROUP is nil, the global kill file is selected." "From" (if (vectorp gnus-current-headers) (regexp-quote (mail-header-from gnus-current-headers)) - ""))) + "") t)) (defun gnus-kill-file-kill-by-thread () "Kill by author." @@ -237,8 +230,8 @@ If NEWSGROUP is nil, the global kill file is selected." (substring xref (match-beginning 1) (match-end 1))) gnus-newsgroup-name)) (gnus-kill-file-enter-kill - "Xref" (concat " " (regexp-quote group) ":")))) - (gnus-kill-file-enter-kill "Xref" "")))) + "Xref" (concat " " (regexp-quote group) ":") t))) + (gnus-kill-file-enter-kill "Xref" "" t)))) (defun gnus-kill-file-raise-followups-to-author (level) "Raise score for all followups to the current author." @@ -258,7 +251,8 @@ If NEWSGROUP is nil, the global kill file is selected." "From" name level)) (insert string) (gnus-kill-file-apply-string string)) - (message "Added temporary score file entry for followups to %s." name))) + (gnus-message + 6 "Added temporary score file entry for followups to %s." name))) (defun gnus-kill-file-apply-buffer () "Apply current buffer to current newsgroup." @@ -267,7 +261,7 @@ If NEWSGROUP is nil, the global kill file is selected." (get-buffer gnus-summary-buffer)) ;; Assume newsgroup is selected. (gnus-kill-file-apply-string (buffer-string)) - (ding) (message "No newsgroup is selected."))) + (ding) (gnus-message 2 "No newsgroup is selected."))) (defun gnus-kill-file-apply-string (string) "Apply STRING to current newsgroup." @@ -291,7 +285,7 @@ If NEWSGROUP is nil, the global kill file is selected." (save-window-excursion (pop-to-buffer gnus-summary-buffer) (eval (car (read-from-string string)))))) - (ding) (message "No newsgroup is selected."))) + (ding) (gnus-message 2 "No newsgroup is selected."))) (defun gnus-kill-file-exit () "Save a kill file, then return to the previous buffer." @@ -318,24 +312,37 @@ If NEWSGROUP is nil, return the global kill file instead." (cond ((or (null newsgroup) (string-equal newsgroup "")) ;; The global kill file is placed at top of the directory. - (expand-file-name gnus-kill-file-name - (or gnus-kill-files-directory "~/News"))) + (expand-file-name gnus-kill-file-name gnus-kill-files-directory)) (gnus-use-long-file-name ;; Append ".KILL" to capitalized newsgroup name. (expand-file-name (concat (gnus-capitalize-newsgroup newsgroup) "." gnus-kill-file-name) - (or gnus-kill-files-directory "~/News"))) + gnus-kill-files-directory)) (t ;; Place "KILL" under the hierarchical directory. (expand-file-name (concat (gnus-newsgroup-directory-form newsgroup) "/" gnus-kill-file-name) - (or gnus-kill-files-directory "~/News"))))) + gnus-kill-files-directory)))) (defun gnus-expunge (marks) "Remove lines marked with MARKS." (save-excursion (set-buffer gnus-summary-buffer) - (gnus-summary-remove-lines-marked-with marks))) + (gnus-summary-limit-to-marks marks 'reverse))) + +(defun gnus-apply-kill-file-unless-scored () + "Apply .KILL file, unless a .SCORE file for the same newsgroup exists." + (cond ((file-exists-p (gnus-score-file-name gnus-newsgroup-name)) + ;; Ignores global KILL. + (if (file-exists-p (gnus-newsgroup-kill-file gnus-newsgroup-name)) + (gnus-message 3 "Note: Ignoring %s.KILL; preferring .SCORE" + gnus-newsgroup-name)) + 0) + ((or (file-exists-p (gnus-newsgroup-kill-file nil)) + (file-exists-p (gnus-newsgroup-kill-file gnus-newsgroup-name))) + (gnus-apply-kill-file-internal)) + (t + 0))) (defun gnus-apply-kill-file-internal () "Apply a kill file to the current newsgroup. @@ -346,8 +353,6 @@ Returns the number of articles marked as read." (gnus-summary-inhibit-highlight t) beg) (setq gnus-newsgroup-kill-headers nil) - (or gnus-newsgroup-headers-hashtb-by-number - (gnus-make-headers-hashtable-by-number)) ;; If there are any previously scored articles, we remove these ;; from the `gnus-newsgroup-headers' list that the score functions ;; will see. This is probably pretty wasteful when it comes to @@ -378,7 +383,7 @@ Returns the number of articles marked as read." (while kill-files (if (not (file-exists-p (car kill-files))) () - (message "Processing kill file %s..." (car kill-files)) + (gnus-message 6 "Processing kill file %s..." (car kill-files)) (find-file (car kill-files)) (gnus-add-current-to-buffer-list) (goto-char (point-min)) @@ -388,7 +393,8 @@ Returns the number of articles marked as read." (gnus-kill-parse-gnus-kill-file) (gnus-kill-parse-rn-kill-file)) - (message "Processing kill file %s...done" (car kill-files))) + (gnus-message + 6 "Processing kill file %s...done" (car kill-files))) (setq kill-files (cdr kill-files))))) (gnus-set-mode-line 'summary) @@ -396,7 +402,7 @@ Returns the number of articles marked as read." (if beg (let ((nunreads (- unreads (length gnus-newsgroup-unreads)))) (or (eq nunreads 0) - (message "Marked %d articles as read" nunreads)) + (gnus-message 6 "Marked %d articles as read" nunreads)) nunreads) 0)))) @@ -408,7 +414,7 @@ Returns the number of articles marked as read." (erase-buffer) (insert string ":\n\n") (while alist - (insert (format " %c: %s\n" (car (car alist)) (nth idx (car alist)))) + (insert (format " %c: %s\n" (caar alist) (nth idx (car alist)))) (setq alist (cdr alist))))) (defun gnus-kill-parse-gnus-kill-file () @@ -538,14 +544,14 @@ COMMAND must be a lisp expression or a string representing a key sequence." (if (or (not (consp (nth 2 object))) (not (consp (cdr (nth 2 object)))) (and (eq 'quote (car (nth 2 object))) - (not (consp (cdr (car (cdr (nth 2 object)))))))) + (not (consp (cdadr (nth 2 object)))))) (concat "\n" (prin1-to-string object)) (save-excursion (set-buffer (get-buffer-create "*Gnus PP*")) (buffer-disable-undo (current-buffer)) (erase-buffer) (insert (format "\n(%S %S\n '(" (nth 0 object) (nth 1 object))) - (let ((klist (car (cdr (nth 2 object)))) + (let ((klist (cadr (nth 2 object))) (first t)) (while klist (insert (if first (progn (setq first nil) "") "\n ") @@ -580,15 +586,19 @@ COMMAND must be a lisp expression or a string representing a key sequence." (or (stringp value) (setq value (prin1-to-string value))) (setq did-kill (string-match regexp value))) - (if (stringp form) ;Keyboard macro. - (execute-kbd-macro form) - (funcall form)))) + (cond ((stringp form) ;Keyboard macro. + (execute-kbd-macro form)) + ((gnus-functionp form) + (funcall form)) + (t + (eval form))))) ;; Search article body. (let ((gnus-current-article nil) ;Save article pointer. (gnus-last-article nil) (gnus-break-pages nil) ;No need to break pages. (gnus-mark-article-hook nil)) ;Inhibit marking as read. - (message "Searching for article: %d..." (mail-header-number header)) + (gnus-message + 6 "Searching for article: %d..." (mail-header-number header)) (gnus-article-setup-buffer) (gnus-article-prepare (mail-header-number header) t) (if (save-excursion @@ -609,27 +619,37 @@ marked as read or ticked are ignored." (save-excursion (let ((killed-no 0) function article header) - (if (or (null field) (string-equal field "")) - (setq function nil) - ;; Get access function of header filed. - (setq function (intern-soft (concat "gnus-header-" (downcase field)))) - (if (and function (fboundp function)) - (setq function (symbol-function function)) - (error "Unknown header field: \"%s\"" field)) - ;; Make FORM funcallable. - (if (and (listp form) (not (eq (car form) 'lambda))) - (setq form (list 'lambda nil form)))) + (cond + ;; Search body. + ((or (null field) + (string-equal field "")) + (setq function nil)) + ;; Get access function of header field. + ((fboundp + (setq function + (intern-soft + (concat "mail-header-" (downcase field))))) + (setq function `(lambda (h) (,function h)))) + ;; Signal error. + (t + (error "Unknown header field: \"%s\"" field))) ;; Starting from the current article. - (while (or (and (not article) - (setq article (gnus-summary-article-number)) - t) - (setq article - (gnus-summary-search-subject - backward (not ignore-marked)))) + (while (or + ;; First article. + (and (not article) + (setq article (gnus-summary-article-number))) + ;; Find later articles. + (setq article + (gnus-summary-search-forward + (not ignore-marked) nil backward))) (and (or (null gnus-newsgroup-kill-headers) (memq article gnus-newsgroup-kill-headers)) - (vectorp (setq header (gnus-get-header-by-number article))) + (vectorp (setq header (gnus-summary-article-header article))) (gnus-execute-1 function regexp form header) (setq killed-no (1+ killed-no)))) + ;; Return the number of killed articles. killed-no))) +(provide 'gnus-kill) + +;;; gnus-kill.el ends here diff --git a/lisp/gnus-mh.el b/lisp/gnus-mh.el index ad68b09a2fa..02317a22eeb 100644 --- a/lisp/gnus-mh.el +++ b/lisp/gnus-mh.el @@ -1,6 +1,5 @@ ;;; gnus-mh.el --- mh-e interface for Gnus - -;; Copyright (C) 1994,95 Free Software Foundation, Inc. +;; Copyright (C) 1994,95,96 Free Software Foundation, Inc. ;; Author: Masanobu UMEDA ;; Lars Magne Ingebrigtsen @@ -38,6 +37,7 @@ (require 'mh-comp) (require 'gnus) (require 'gnus-msg) +(eval-when-compile (require 'cl)) (defun gnus-summary-save-article-folder (&optional arg) "Append the current article to an mh folder. @@ -55,155 +55,30 @@ Optional argument FOLDER specifies folder name." ;; Thanks to yuki@flab.Fujitsu.JUNET and ohm@kaba.junet. (mh-find-path) (let ((folder - (or folder - (mh-prompt-for-folder - "Save article in" - (funcall gnus-folder-save-name gnus-newsgroup-name - gnus-current-headers gnus-newsgroup-last-folder) - t))) - (errbuf (get-buffer-create " *Gnus rcvstore*"))) - (gnus-eval-in-buffer-window - gnus-article-buffer - (save-restriction - (widen) - (unwind-protect - (call-process-region (point-min) (point-max) - (expand-file-name "rcvstore" mh-lib) - nil errbuf nil folder) - (set-buffer errbuf) - (if (zerop (buffer-size)) - (message "Article saved in folder: %s" folder) - (message "%s" (buffer-string))) - (kill-buffer errbuf)))) - (setq gnus-newsgroup-last-folder folder))) - -(defun gnus-mail-reply-using-mhe (&optional yank) - "Compose reply mail using mh-e. -Optional argument YANK means yank original article. -The command \\[mh-yank-cur-msg] yank the original message into current buffer." - (let (from cc subject date to reply-to to-userid orig-to - references message-id - (config (current-window-configuration)) - buffer) - (pop-to-buffer gnus-article-buffer) - (setq buffer (current-buffer)) - (save-excursion + (cond ((and (eq folder 'default) + gnus-newsgroup-last-folder) + gnus-newsgroup-last-folder) + (folder folder) + (t (mh-prompt-for-folder + "Save article in" + (funcall gnus-folder-save-name gnus-newsgroup-name + gnus-current-headers gnus-newsgroup-last-folder) + t)))) + (errbuf (get-buffer-create " *Gnus rcvstore*")) + ;; Find the rcvstore program. + (exec-path (if mh-lib (cons mh-lib exec-path) exec-path))) + (gnus-eval-in-buffer-window gnus-original-article-buffer (save-restriction - (or gnus-user-login-name ; we need this - (setq gnus-user-login-name (or (getenv "USER") - (getenv "LOGNAME")))) - - (gnus-article-show-all-headers);; so colors are happy - ;; lots of junk to avoid mh-send deleting other windows - (setq from (or (gnus-fetch-field "from") "") - subject (let ((subject (or (gnus-fetch-field "subject") - "(None)"))) - (if (and subject - (not (string-match "^[Rr][Ee]:.+$" subject))) - (concat "Re: " subject) subject)) - reply-to (gnus-fetch-field "reply-to") - cc (gnus-fetch-field "cc") - orig-to (or (gnus-fetch-field "to") "") - date (gnus-fetch-field "date") - references (gnus-fetch-field "references") - message-id (gnus-fetch-field "message-id")) - (setq to (or reply-to from)) - (setq to-userid (mail-strip-quoted-names orig-to)) - (if (or (string-match "," orig-to) - (not (string-match (substring to-userid 0 - (string-match "@" to-userid)) - gnus-user-login-name))) - (setq cc (concat (if cc (concat cc ", ") "") orig-to))) - ;; mh-yank-cur-msg needs to have mh-show-buffer set in the - ;; *Article* buffer - (setq mh-show-buffer buffer))) - - (mh-find-path) - (mh-send-sub (or to "") (or cc "") - (or subject "(None)") config);; Erik Selberg 1/23/94 - - (let ((draft (current-buffer)) - (gnus-mail-buffer (current-buffer)) - mail-buf) - (if (not yank) - (gnus-configure-windows 'reply 'force) - (gnus-configure-windows 'reply-yank 'force)) - (setq mail-buf gnus-mail-buffer) - (pop-to-buffer mail-buf);; always in the display, so won't have window probs - (switch-to-buffer draft)) - - ;; (mh-send to (or cc "") subject);; shouldn't use according to mhe - - ;; note - current buffer is now draft! - (save-excursion - (mh-insert-fields - "In-reply-to:" - (concat - (substring from 0 (string-match " *at \\| *@ \\| *(\\| *<" from)) - "'s message of " date)) - (nnheader-insert-references references message-id)) - - ;; need this for mh-yank-cur-msg - (setq mh-sent-from-folder buffer) - (setq mh-sent-from-msg 1) - (setq mh-show-buffer buffer) - (setq mh-previous-window-config config)) - - ;; Then, yank original article if requested. - (if yank - (let ((last (point))) - (mh-yank-cur-msg) - (goto-char last))) - - (run-hooks 'gnus-mail-hook)) - - -;; gnus-mail-forward-using-mhe is contributed by Jun-ichiro Itoh -;; - -(defun gnus-mail-forward-using-mhe (&optional buffer) - "Forward the current message to another user using mh-e." - ;; First of all, prepare mhe mail buffer. - (let* ((to (read-string "To: ")) - (cc (read-string "Cc: ")) - (buffer (or buffer gnus-article-buffer)) - (config (current-window-configuration));; need to add this - erik - (subject (gnus-forward-make-subject buffer))) - (setq mh-show-buffer buffer) - (mh-find-path) - (mh-send-sub to (or cc "") (or subject "(None)") config);; Erik Selberg 1/23/94 - (let ((draft (current-buffer)) - (gnus-mail-buffer (current-buffer)) - mail-buf) - (gnus-configure-windows 'reply-yank 'force) - (setq mail-buf (eval (cdr (assq 'mail gnus-window-to-buffer)))) - (pop-to-buffer mail-buf);; always in the display, so won't have window probs - (switch-to-buffer draft) - ) - (save-excursion - (goto-char (point-max)) - (insert "\n------- Forwarded Message\n\n") - (insert-buffer buffer) - (goto-char (point-max)) - (insert "\n------- End of Forwarded Message\n") - (setq mh-sent-from-folder buffer) - (setq mh-sent-from-msg 1) - (setq mh-previous-window-config config) - (run-hooks 'gnus-mail-hook) - ))) - -(defun gnus-mail-other-window-using-mhe () - "Compose mail other window using mh-e." - (let ((to (read-string "To: ")) - (cc (read-string "Cc: ")) - (subject (read-string "Subject: "))) - (gnus-article-show-all-headers) ;I don't think this is really needed. - (setq mh-show-buffer (current-buffer)) - (mh-find-path) - (mh-send-other-window to cc subject) - (setq mh-sent-from-folder (current-buffer)) - (setq mh-sent-from-msg 1) - (run-hooks 'gnus-mail-hook))) + (widen) + (unwind-protect + (call-process-region + (point-min) (point-max) "rcvstore" nil errbuf nil folder) + (set-buffer errbuf) + (if (zerop (buffer-size)) + (message "Article saved in folder: %s" folder) + (message "%s" (buffer-string))) + (kill-buffer errbuf)))) + (setq gnus-newsgroup-last-folder folder))) (defun gnus-Folder-save-name (newsgroup headers &optional last-folder) "Generate folder name from NEWSGROUP, HEADERS, and optional LAST-FOLDER. @@ -225,4 +100,6 @@ Otherwise, it is like +news/group." newsgroup (gnus-newsgroup-directory-form newsgroup))))) +(provide 'gnus-mh) + ;;; gnus-mh.el ends here diff --git a/lisp/gnus-msg.el b/lisp/gnus-msg.el index 099b5e1ebeb..5d1778e7aa5 100644 --- a/lisp/gnus-msg.el +++ b/lisp/gnus-msg.el @@ -1,6 +1,5 @@ ;;; gnus-msg.el --- mail and post interface for Gnus - -;; Copyright (C) 1995 Free Software Foundation, Inc. +;; Copyright (C) 1995,96 Free Software Foundation, Inc. ;; Author: Masanobu UMEDA ;; Lars Magne Ingebrigtsen @@ -28,216 +27,72 @@ ;;; Code: (require 'gnus) -(require 'sendmail) (require 'gnus-ems) - -(defvar gnus-organization-file "/usr/lib/news/organization" - "*Local news organization file.") - -(defvar gnus-prepare-article-hook (list 'gnus-inews-insert-signature) - "*A hook called after preparing body, but before preparing header headers. -The default hook (`gnus-inews-insert-signature') inserts a signature -file specified by the variable `gnus-signature-file'.") - -(defvar gnus-post-prepare-function nil - "*Function that is run after a post buffer has been prepared. -It is called with the name of the newsgroup that is posted to. It -might be used, for instance, for inserting signatures based on the -newsgroup name. (In that case, `gnus-signature-file' and -`mail-signature' should both be set to nil).") - -(defvar gnus-post-prepare-hook nil - "*Hook that is run after a post buffer has been prepared. -If you want to insert the signature, you might put -`gnus-inews-insert-signature' in this hook.") - -(defvar gnus-use-followup-to t - "*Specifies what to do with Followup-To header. -If nil, ignore the header. If it is t, use its value, but ignore -`poster'. If it is the symbol `ask', query the user before posting. -If it is the symbol `use', always use the value.") - -(defvar gnus-followup-to-function nil - "*A variable that contains a function that returns a followup address. -The function will be called in the buffer of the article that is being -followed up. The buffer will be narrowed to the headers of the -article. To pick header headers, one might use `mail-fetch-field'. The -function will be called with the name of the current newsgroup as the -argument. - -Here's an example `gnus-followup-to-function': - -(setq gnus-followup-to-function - (lambda (group) - (cond ((string= group \"mail.list\") - (or (mail-fetch-field \"sender\") - (mail-fetch-field \"from\"))) - (t - (or (mail-fetch-field \"reply-to\") - (mail-fetch-field \"from\"))))))") - -(defvar gnus-reply-to-function nil - "*A variable that contains a function that returns a reply address. -See the `gnus-followup-to-function' variable for an explanation of how -this variable is used. - -This function should return a string that will be used to fill in the -header. This function may also return a list. In that case, every -list element should be a cons where the first car should be a string -with the header name, and the cdr should be a string with the header -value.") - -(defvar gnus-author-copy (getenv "AUTHORCOPY") - "*Save outgoing articles in this file. -Initialized from the AUTHORCOPY environment variable. - -If this variable begins with the character \"|\", outgoing articles -will be piped to the named program. It is possible to save an article -in an MH folder as follows: - -\(setq gnus-author-copy \"|/usr/local/lib/mh/rcvstore +Article\") - -If the first character is not a pipe, articles are saved using the -function specified by the `gnus-author-copy-saver' variable.") - -(defvar gnus-mail-self-blind nil - "*Non-nil means insert a BCC header in all outgoing articles. -This will result in having a copy of the article mailed to yourself. -The BCC header is inserted when the post buffer is initialized, so you -can remove or alter the BCC header to override the default.") - -(defvar gnus-author-copy-saver (function rmail-output) - "*A function called to save outgoing articles. -This function will be called with the same of the file to store the -article in. The default function is `rmail-output' which saves in Unix -mailbox format.") - -(defvar gnus-user-login-name nil - "*The login name of the user. -Got from the function `user-login-name' if undefined.") - -(defvar gnus-user-full-name nil - "*The full name of the user. -Got from the NAME environment variable if undefined.") - -(defvar gnus-user-from-line nil - "*Your full, complete e-mail address. -Overrides the other Gnus variables if it is non-nil. - -Here are two example values of this variable: - - \"Lars Magne Ingebrigtsen \" - -and - - \"larsi@ifi.uio.no (Lars Magne Ingebrigtsen)\" - -The first version is recommended, but the name has to be quoted if it -contains non-alphanumerical characters.") - -(defvar gnus-signature-file "~/.signature" - "*Your signature file. -If the variable is a string that doesn't correspond to a file, the -string itself is inserted.") - -(defvar gnus-signature-function nil - "*A function that should return a signature file name. -The function will be called with the name of the newsgroup being -posted to. -If the function returns a string that doesn't correspond to a file, the -string itself is inserted. -If the function returns nil, the `gnus-signature-file' variable will -be used instead.") - -(defvar gnus-required-headers - '(From Date Newsgroups Subject Message-ID Organization Lines X-Newsreader) - "*Headers to be generated or prompted for when posting an article. -RFC977 and RFC1036 require From, Date, Newsgroups, Subject, -Message-ID. Organization, Lines and X-Newsreader are optional. If -you want Gnus not to insert some header, remove it from this list.") - -(defvar gnus-deletable-headers '(Message-ID Date) - "*Headers to be deleted if they already exists and were generated by Gnus previously.") - -(defvar gnus-removable-headers '(NNTP-Posting-Host Bcc Xref) - "*Headers to be removed unconditionally before posting.") - -(defvar gnus-check-before-posting - '(subject-cmsg multiple-headers sendsys message-id from - long-lines control-chars size new-text - signature) - "In non-nil, Gnus will attempt to run some checks on outgoing posts. -If this variable is t, Gnus will check everything it can. If it is a -list, then those elements in that list will be checked.") - -(defvar gnus-delete-supersedes-headers - "^Path:\\|^Date\\|^NNTP-Posting-Host:\\|^Supersedes:" - "*Header lines matching this regexp will be deleted before posting. -It's best to delete old Path and Date headers before posting to avoid -any confusion.") - -(defvar gnus-auto-mail-to-author nil - "*If non-nil, mail the authors of articles a copy of your follow-ups. -If this variable is `ask', the user will be prompted for whether to -mail a copy. The string given by `gnus-mail-courtesy-message' will be -inserted at the beginning of the mail copy. - -Mail is sent using the function specified by the -`gnus-mail-send-method' variable.") - -;; Added by Ethan Bradford . -(defvar gnus-mail-courtesy-message - "The following message is a courtesy copy of an article\nthat has been posted as well.\n\n" - "*This is inserted at the start of a mailed copy of a posted message. -If this variable is nil, no such courtesy message will be added.") - -(defvar gnus-mail-reply-method (function gnus-mail-reply-using-mail) - "*Function to compose a reply. -Three pre-made functions are `gnus-mail-reply-using-mail' (sendmail); -`gnus-mail-reply-using-mhe' (MH-E); and `gnus-mail-reply-using-vm'.") - -(defvar gnus-mail-forward-method (function gnus-mail-forward-using-mail) - "*Function to forward the current message to another user. -Three pre-made functions are `gnus-mail-forward-using-mail' (sendmail); -`gnus-mail-forward-using-mhe' (MH-E); and `gnus-mail-forward-using-vm'.") - -(defvar gnus-mail-other-window-method 'gnus-mail-other-window-using-mail - "*Function to compose mail in the other window. -Three pre-made functions are `gnus-mail-other-window-using-mail' -(sendmail); `gnus-mail-other-window-using-mhe' (MH-E); and -`gnus-mail-other-window-using-vm'.") - -(defvar gnus-mail-send-method send-mail-function - "*Function to mail a message which is also being posted as an article. -The message must have To or Cc header. The default is copied from -the variable `send-mail-function'.") - -(defvar gnus-inews-article-function 'gnus-inews-article - "*Function to post an article.") - -(defvar gnus-inews-article-hook (list 'gnus-inews-do-fcc) - "*A hook called before finally posting an article. -The default hook (`gnus-inews-do-fcc') does FCC processing (ie. saves -the article to a file).") - -(defvar gnus-inews-article-header-hook nil - "*A hook called after inserting the headers in an article to be posted. -The hook is called from the *post-news* buffer, narrowed to the -headers.") - -(defvar gnus-mail-hook nil - "*A hook called as the last thing after setting up a mail buffer.") +(require 'message) +(eval-when-compile (require 'cl)) + +;; Added by Sudish Joseph . +(defvar gnus-post-method nil + "*Preferred method for posting USENET news. +If this variable is nil, Gnus will use the current method to decide +which method to use when posting. If it is non-nil, it will override +the current method. This method will not be used in mail groups and +the like, only in \"real\" newsgroups. + +The value must be a valid method as discussed in the documentation of +`gnus-select-method'. It can also be a list of methods. If that is +the case, the user will be queried for what select method to use when +posting.") + +(defvar gnus-outgoing-message-group nil + "*All outgoing messages will be put in this group. +If you want to store all your outgoing mail and articles in the group +\"nnml:archive\", you set this variable to that value. This variable +can also be a list of group names. + +If you want to have greater control over what group to put each +message in, you can set this variable to a function that checks the +current newsgroup name and then returns a suitable group name (or list +of names).") + +(defvar gnus-message-archive-group + '((if (message-news-p) "misc-news" "misc-mail")) + "*Name of the group in which to save the messages you've written. +This can either be a string, a list of strings; or an alist +of regexps/functions/forms to be evaluated to return a string (or a list +of strings). The functions are called with the name of the current +group (or nil) as a parameter. + +Normally the group names returned by this variable should be +unprefixed -- which implictly means \"store on the archive server\". +However, you may wish to store the message on some other server. In +that case, just return a fully prefixed name of the group -- +\"nnml+private:mail.misc\", for instance.") + +(defvar gnus-mailing-list-groups nil + "*Regexp matching groups that are really mailing lists. +This is useful when you're reading a mailing list that has been +gatewayed to a newsgroup, and you want to followup to an article in +the group.") + +(defvar gnus-sent-message-ids-file + (nnheader-concat gnus-directory "Sent-Message-IDs") + "File where Gnus saves a cache of sent message ids.") + +(defvar gnus-sent-message-ids-length 1000 + "The number of sent Message-IDs to save.") ;;; Internal variables. -(defvar gnus-post-news-buffer "*post-news*") -(defvar gnus-mail-buffer "*mail*") -(defvar gnus-summary-send-map nil) +(defvar gnus-message-buffer "*Mail Gnus*") (defvar gnus-article-copy nil) -(defvar gnus-reply-subject nil) +(defvar gnus-last-posting-server nil) (eval-and-compile (autoload 'gnus-uu-post-news "gnus-uu" nil t) + (autoload 'news-setup "rnewspost") + (autoload 'news-reply-mode "rnewspost") + (autoload 'rmail-dont-reply-to "mail-utils") (autoload 'rmail-output "rmailout")) @@ -245,105 +100,155 @@ headers.") ;;; Gnus Posting Functions ;;; -(define-prefix-command 'gnus-summary-send-map) -(define-key gnus-summary-mode-map "S" 'gnus-summary-send-map) -(define-key gnus-summary-send-map "p" 'gnus-summary-post-news) -(define-key gnus-summary-send-map "f" 'gnus-summary-followup) -(define-key gnus-summary-send-map "F" 'gnus-summary-followup-with-original) -(define-key gnus-summary-send-map "b" 'gnus-summary-followup-and-reply) -(define-key gnus-summary-send-map "B" 'gnus-summary-followup-and-reply-with-original) -(define-key gnus-summary-send-map "c" 'gnus-summary-cancel-article) -(define-key gnus-summary-send-map "s" 'gnus-summary-supersede-article) -(define-key gnus-summary-send-map "r" 'gnus-summary-reply) -(define-key gnus-summary-send-map "R" 'gnus-summary-reply-with-original) -(define-key gnus-summary-send-map "m" 'gnus-summary-mail-other-window) -(define-key gnus-summary-send-map "u" 'gnus-uu-post-news) -(define-key gnus-summary-send-map "om" 'gnus-summary-mail-forward) -(define-key gnus-summary-send-map "op" 'gnus-summary-post-forward) -(define-key gnus-summary-send-map "Om" 'gnus-uu-digest-mail-forward) -(define-key gnus-summary-send-map "Op" 'gnus-uu-digest-post-forward) +(gnus-define-keys + (gnus-summary-send-map "S" gnus-summary-mode-map) + "p" gnus-summary-post-news + "f" gnus-summary-followup + "F" gnus-summary-followup-with-original + "c" gnus-summary-cancel-article + "s" gnus-summary-supersede-article + "r" gnus-summary-reply + "R" gnus-summary-reply-with-original + "m" gnus-summary-mail-other-window + "u" gnus-uu-post-news + "om" gnus-summary-mail-forward + "op" gnus-summary-post-forward + "Om" gnus-uu-digest-mail-forward + "Op" gnus-uu-digest-post-forward) + +(gnus-define-keys + (gnus-send-bounce-map "D" gnus-summary-send-map) + "b" gnus-summary-resend-bounced-mail +; "c" gnus-summary-send-draft + "r" gnus-summary-resend-message) ;;; Internal functions. -(defun gnus-number-base36 (num len) - (if (if (< len 0) (<= num 0) (= len 0)) - "" - (concat (gnus-number-base36 (/ num 36) (1- len)) - (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210" - (% num 36)))))) +(defvar gnus-article-reply nil) +(defmacro gnus-setup-message (config &rest forms) + (let ((winconf (make-symbol "winconf")) + (buffer (make-symbol "buffer")) + (article (make-symbol "article"))) + `(let ((,winconf (current-window-configuration)) + (,buffer (current-buffer)) + (,article (and gnus-article-reply (gnus-summary-article-number))) + (message-header-setup-hook + (copy-sequence message-header-setup-hook))) + (add-hook 'message-header-setup-hook 'gnus-inews-insert-gcc) + (add-hook 'message-header-setup-hook 'gnus-inews-insert-archive-gcc) + ,@forms + (gnus-inews-add-send-actions ,winconf ,buffer ,article) + (setq gnus-message-buffer (current-buffer)) + (gnus-configure-windows ,config t)))) + +(defun gnus-inews-add-send-actions (winconf buffer article) + (gnus-make-local-hook 'message-sent-hook) + (gnus-add-hook 'message-sent-hook 'gnus-inews-do-gcc nil t) + (setq message-post-method + `(lambda (arg) + (gnus-post-method arg ,gnus-newsgroup-name))) + (setq message-newsreader (setq message-mailer (gnus-extended-version))) + (message-add-action + `(set-window-configuration ,winconf) 'exit 'postpone 'kill) + (message-add-action + `(when (buffer-name ,buffer) + (save-excursion + (set-buffer ,buffer) + ,(when article + `(gnus-summary-mark-article-as-replied ,article)))) + 'send)) + +(put 'gnus-setup-message 'lisp-indent-function 1) +(put 'gnus-setup-message 'lisp-indent-hook 1) +(put 'gnus-setup-message 'edebug-form-spec '(form body)) ;;; Post news commands of Gnus group mode and summary mode (defun gnus-group-mail () "Start composing a mail." (interactive) - (funcall gnus-mail-other-window-method)) + (gnus-setup-message 'message + (message-mail))) -(defun gnus-group-post-news () - "Post an article." - (interactive) - (let ((gnus-newsgroup-name nil)) - (gnus-post-news 'post nil nil gnus-article-buffer))) +(defun gnus-group-post-news (&optional arg) + "Start composing a news message. +If ARG, post to the group under point. +If ARG is 1, prompt for a group name." + (interactive "P") + ;; Bind this variable here to make message mode hooks + ;; work ok. + (let ((gnus-newsgroup-name + (if arg + (if (= 1 (prefix-numeric-value arg)) + (completing-read "Newsgroup: " gnus-active-hashtb nil + (gnus-read-active-file-p)) + (gnus-group-group-name)) + ""))) + (gnus-post-news 'post gnus-newsgroup-name))) (defun gnus-summary-post-news () - "Post an article." + "Start composing a news message." (interactive) (gnus-set-global-variables) (gnus-post-news 'post gnus-newsgroup-name)) -(defun gnus-summary-followup (yank &optional yank-articles) +(defun gnus-summary-followup (yank &optional force-news) "Compose a followup to an article. If prefix argument YANK is non-nil, original article is yanked automatically." - (interactive "P") + (interactive + (list (and current-prefix-arg + (gnus-summary-work-articles 1)))) (gnus-set-global-variables) - (if yank-articles (gnus-summary-goto-subject (car yank-articles))) + (when yank + (gnus-summary-goto-subject (car yank))) (save-window-excursion (gnus-summary-select-article)) - (let ((headers (gnus-get-header-by-number (gnus-summary-article-number))) + (let ((headers (gnus-summary-article-header (gnus-summary-article-number))) (gnus-newsgroup-name gnus-newsgroup-name)) - ;; Check Followup-To: poster. - (set-buffer gnus-article-buffer) - (if (and gnus-use-followup-to - (string-equal "poster" (gnus-fetch-field "followup-to")) - (or (not (memq gnus-use-followup-to '(t ask))) - (not (gnus-y-or-n-p - "Do you want to ignore `Followup-To: poster'? ")))) - ;; Mail to the poster. - (gnus-summary-reply yank) - (gnus-post-news nil gnus-newsgroup-name - headers gnus-article-buffer - (or yank-articles (not (not yank))))))) - -(defun gnus-summary-followup-with-original (n) - "Compose a followup to an article and include the original article." - (interactive "P") - (gnus-summary-followup t (gnus-summary-work-articles n))) - -;; Suggested by Daniel Quinlan . -(defun gnus-summary-followup-and-reply (yank &optional yank-articles) - "Compose a followup and do an auto mail to author." - (interactive "P") - (gnus-set-global-variables) - (let ((gnus-auto-mail-to-author t)) - (gnus-summary-followup yank yank-articles))) + ;; Send a followup. + (gnus-post-news nil gnus-newsgroup-name + headers gnus-article-buffer + yank nil force-news))) -(defun gnus-summary-followup-and-reply-with-original (n) - "Compose a followup, include the original, and do an auto mail to author." +(defun gnus-summary-followup-with-original (n &optional force-news) + "Compose a followup to an article and include the original article." (interactive "P") - (gnus-summary-followup-and-reply t (gnus-summary-work-articles n))) + (gnus-summary-followup (gnus-summary-work-articles n) force-news)) + +(defun gnus-inews-yank-articles (articles) + (let (beg article) + (while (setq article (pop articles)) + (save-window-excursion + (set-buffer gnus-summary-buffer) + (gnus-summary-select-article nil nil nil article) + (gnus-summary-remove-process-mark article)) + (gnus-copy-article-buffer) + (let ((message-reply-buffer gnus-article-copy) + (message-reply-headers gnus-current-headers)) + (message-yank-original) + (setq beg (or beg (mark t)))) + (when articles (insert "\n"))) + + (push-mark) + (goto-char beg))) (defun gnus-summary-cancel-article (n) "Cancel an article you posted." (interactive "P") (gnus-set-global-variables) - (let ((articles (gnus-summary-work-articles n))) - (while articles - (gnus-summary-select-article t nil nil (car articles)) - (and (gnus-eval-in-buffer-window gnus-article-buffer (gnus-cancel-news)) - (gnus-summary-mark-as-read (car articles) gnus-canceled-mark)) - (gnus-summary-remove-process-mark (car articles)) - (gnus-article-hide-headers-if-wanted) - (setq articles (cdr articles))))) + (let ((articles (gnus-summary-work-articles n)) + (message-post-method + `(lambda (arg) + (gnus-post-method nil ,gnus-newsgroup-name))) + article) + (while (setq article (pop articles)) + (when (gnus-summary-select-article t nil nil article) + (when (gnus-eval-in-buffer-window + gnus-original-article-buffer (message-cancel-news)) + (gnus-summary-mark-as-read article gnus-canceled-mark) + (gnus-cache-remove-article 1)) + (gnus-article-hide-headers-if-wanted)) + (gnus-summary-remove-process-mark article)))) (defun gnus-summary-supersede-article () "Compose an article that will supersede a previous article. @@ -351,46 +256,17 @@ This is done simply by taking the old article and adding a Supersedes header line with the old Message-ID." (interactive) (gnus-set-global-variables) - (gnus-summary-select-article t) - (if (not - (string-equal - (downcase (mail-strip-quoted-names - (mail-header-from gnus-current-headers))) - (downcase (mail-strip-quoted-names (gnus-inews-user-name))))) - (error "This article is not yours.")) - (save-excursion - (set-buffer gnus-article-buffer) - (let ((buffer-read-only nil)) - (goto-char (point-min)) - (search-forward "\n\n" nil t) - (if (not (re-search-backward "^Message-ID: " nil t)) - (error "No Message-ID in this article")))) - (if (gnus-post-news 'post gnus-newsgroup-name) - (progn - (erase-buffer) - (insert-buffer gnus-article-buffer) - (if (search-forward "\n\n" nil t) - (forward-char -1) - (goto-char (point-max))) - (narrow-to-region (point-min) (point)) - (goto-char (point-min)) - (and gnus-delete-supersedes-headers - (delete-matching-lines gnus-delete-supersedes-headers)) - (goto-char (point-min)) - (if (not (re-search-forward "^Message-ID: " nil t)) - (error "No Message-ID in this article") - (replace-match "Supersedes: " t t)) - (goto-char (point-max)) - (insert mail-header-separator) - (widen) - (forward-line 1)))) + (let ((article (gnus-summary-article-number))) + (gnus-setup-message 'reply-yank + (gnus-summary-select-article t) + (set-buffer gnus-original-article-buffer) + (message-supersede) + (push + `((lambda () + (gnus-cache-possibly-remove-article ,article nil nil nil t))) + message-send-actions)))) -;;;###autoload -(defalias 'sendnews 'gnus-post-news) - -;;;###autoload -(defalias 'postnews 'gnus-post-news) (defun gnus-copy-article-buffer (&optional article-buffer) ;; make a copy of the article buffer with all text properties removed @@ -401,804 +277,222 @@ header line with the old Message-ID." (buffer-disable-undo gnus-article-copy) (or (memq gnus-article-copy gnus-buffer-list) (setq gnus-buffer-list (cons gnus-article-copy gnus-buffer-list))) - (let ((article-buffer (or article-buffer gnus-article-buffer))) - (if (and (get-buffer article-buffer) - (buffer-name (get-buffer article-buffer))) - (save-excursion - (set-buffer article-buffer) + (let ((article-buffer (or article-buffer gnus-article-buffer)) + end beg contents) + (when (and (get-buffer article-buffer) + (buffer-name (get-buffer article-buffer))) + (save-excursion + (set-buffer article-buffer) + (save-restriction (widen) - (copy-to-buffer gnus-article-copy (point-min) (point-max)) - (set-text-properties (point-min) (point-max) - nil gnus-article-copy))))) - -;;;###autoload -(defun gnus-post-news (post &optional group header article-buffer yank subject) - "Begin editing a new USENET news article to be posted. -Type \\[describe-mode] in the buffer to get a list of commands." - (interactive (list t)) - (gnus-copy-article-buffer article-buffer) - (if (or (not gnus-novice-user) - gnus-expert-user - (not (eq 'post - (nth 1 (assoc - (format "%s" (car (gnus-find-method-for-group - gnus-newsgroup-name))) - gnus-valid-select-methods)))) - (and group - (assq 'to-address - (nth 5 (nth 2 (gnus-gethash group gnus-newsrc-hashtb))))) - (gnus-y-or-n-p "Are you sure you want to post to all of USENET? ")) - (let ((sumart (if (not post) - (save-excursion - (set-buffer gnus-summary-buffer) - (cons (current-buffer) gnus-current-article)))) - (from (and header (mail-header-from header))) - (winconf (current-window-configuration)) - real-group) - (and gnus-interactive-post - (not gnus-expert-user) - post (not group) - (progn - (setq gnus-newsgroup-name - (setq group - (completing-read "Group: " gnus-active-hashtb))) - (or subject - (setq subject (read-string "Subject: "))))) - (setq mail-reply-buffer gnus-article-copy) - - (let ((newsgroup-name (or group gnus-newsgroup-name ""))) - (setq real-group (and group (gnus-group-real-name group))) - (setq gnus-post-news-buffer - (gnus-request-post-buffer - post real-group subject header gnus-article-copy - (nth 2 (and group (gnus-gethash group gnus-newsrc-hashtb))) - (or (cdr (assq 'to-group - (nth 5 (nth 2 (gnus-gethash - newsgroup-name - gnus-newsrc-hashtb))))) - (if (and (boundp 'gnus-followup-to-function) - gnus-followup-to-function - gnus-article-copy) - (save-excursion - (set-buffer gnus-article-copy) - (funcall gnus-followup-to-function group)))) - gnus-use-followup-to)) + (setq contents (format "%s" (buffer-string))) + (set-buffer gnus-original-article-buffer) + (goto-char (point-min)) + (while (looking-at message-unix-mail-delimiter) + (forward-line 1)) + (setq beg (point)) + (setq end (or (search-forward "\n\n" nil t) (point))) + (set-buffer gnus-article-copy) + (erase-buffer) + (insert contents) + (delete-region (goto-char (point-min)) + (or (search-forward "\n\n" nil t) (point))) + (insert-buffer-substring gnus-original-article-buffer beg end))) + gnus-article-copy))) + +(defun gnus-post-news (post &optional group header article-buffer yank subject + force-news) + (when article-buffer + (gnus-copy-article-buffer)) + (let ((gnus-article-reply article-buffer)) + (gnus-setup-message (cond (yank 'reply-yank) + (article-buffer 'reply) + (t 'message)) + (let* ((group (or group gnus-newsgroup-name)) + (pgroup group) + to-address to-group mailing-list to-list) + (when group + (setq to-address (gnus-group-get-parameter group 'to-address) + to-group (gnus-group-get-parameter group 'to-group) + to-list (gnus-group-get-parameter group 'to-list) + mailing-list (when gnus-mailing-list-groups + (string-match gnus-mailing-list-groups group)) + group (gnus-group-real-name group))) + (if (or (and to-group + (gnus-news-group-p to-group)) + force-news + (and (gnus-news-group-p + (or pgroup gnus-newsgroup-name) + (if header (mail-header-number header) + gnus-current-article)) + (not mailing-list) + (not to-list) + (not to-address))) + ;; This is news. + (if post + (message-news (or to-group group)) + (set-buffer gnus-article-copy) + (message-followup)) + ;; The is mail. (if post - (gnus-configure-windows 'post 'force) - (if yank - (gnus-configure-windows 'followup-yank 'force) - (gnus-configure-windows 'followup 'force))) - (gnus-overload-functions) - (make-local-variable 'gnus-article-reply) - (make-local-variable 'gnus-article-check-size) - (make-local-variable 'gnus-reply-subject) - (setq gnus-reply-subject (and header (mail-header-subject header))) - (setq gnus-article-reply sumart) - ;; Handle `gnus-auto-mail-to-author'. - ;; Suggested by Daniel Quinlan . - ;; Revised to respect Reply-To by Ulrik Dickow . - (let ((to (and (not post) - (if (if (eq gnus-auto-mail-to-author 'ask) - (y-or-n-p "Also send mail to author? ") - gnus-auto-mail-to-author) - (or (save-excursion - (set-buffer gnus-article-copy) - (gnus-fetch-field "reply-to")) - from))))) - (if to - (if (mail-fetch-field "To") - (progn - (beginning-of-line) - (insert "Cc: " to "\n")) - (mail-position-on-field "To") - (insert to)))) - ;; Handle author copy using BCC field. - (if (and gnus-mail-self-blind - (not (mail-fetch-field "bcc"))) (progn - (mail-position-on-field "Bcc") - (insert (if (stringp gnus-mail-self-blind) - gnus-mail-self-blind - (user-login-name))))) - ;; Handle author copy using FCC field. - (if gnus-author-copy - (progn - (mail-position-on-field "Fcc") - (insert gnus-author-copy))) - (goto-char (point-min)) - (if post - (cond ((not group) - (re-search-forward "^Newsgroup:" nil t) - (end-of-line)) - ((not subject) - (re-search-forward "^Subject:" nil t) - (end-of-line)) - (t - (re-search-forward - (concat "^" (regexp-quote mail-header-separator) "$")) - (forward-line 1))) - (re-search-forward - (concat "^" (regexp-quote mail-header-separator) "$")) - (forward-line 1) - (if (not yank) - () - (save-excursion - (if (not (listp yank)) - (news-reply-yank-original nil) - (setq yank (reverse yank)) - (while yank - (save-excursion - (save-window-excursion - (set-buffer gnus-summary-buffer) - (gnus-summary-select-article nil nil nil (car yank)) - (gnus-summary-remove-process-mark (car yank))) - (let ((mail-reply-buffer gnus-article-copy)) - (gnus-copy-article-buffer) - (let ((news-reply-yank-message-id - (save-excursion - (set-buffer gnus-article-copy) - (mail-fetch-field "message-id"))) - (news-reply-yank-from - (save-excursion - (set-buffer gnus-article-copy) - (mail-fetch-field "from")))) - (news-reply-yank-original nil)) - (setq yank (cdr yank))))))))) - (if gnus-post-prepare-function - (funcall gnus-post-prepare-function group)) - (run-hooks 'gnus-post-prepare-hook) - (make-local-variable 'gnus-prev-winconf) - (setq gnus-prev-winconf winconf)))) - (setq gnus-article-check-size (cons (buffer-size) (gnus-article-checksum))) - (message "") - t) - -(defun gnus-inews-news (&optional use-group-method) - "Send a news message. -If given a prefix, and the group is a foreign group, this function -will attempt to use the foreign server to post the article." - (interactive "P") - (or gnus-current-select-method - (setq gnus-current-select-method gnus-select-method)) - (let* ((case-fold-search nil) - (server-running (gnus-server-opened gnus-current-select-method)) - (reply gnus-article-reply) - error post-result) - (save-excursion - ;; Connect to default NNTP server if necessary. - ;; Suggested by yuki@flab.fujitsu.junet. - (gnus-start-news-server) ;Use default server. - ;; NNTP server must be opened before current buffer is modified. - (widen) - (goto-char (point-min)) - (run-hooks 'news-inews-hook) - (save-restriction - (narrow-to-region - (point-min) - (progn - (goto-char (point-min)) - (re-search-forward - (concat "^" (regexp-quote mail-header-separator) "$")) - (match-beginning 0))) - - ;; Correct newsgroups field: change sequence of spaces to comma and - ;; eliminate spaces around commas. Eliminate embedded line breaks. - (goto-char (point-min)) - (if (re-search-forward "^Newsgroups: +" nil t) - (save-restriction - (narrow-to-region - (point) - (if (re-search-forward "^[^ \t]" nil t) - (match-beginning 0) - (forward-line 1) - (point))) - (goto-char (point-min)) - (while (re-search-forward "\n[ \t]+" nil t) - (replace-match " " t t)) ;No line breaks (too confusing) - (goto-char (point-min)) - (while (re-search-forward "[ \t\n]*,[ \t\n]*\\|[ \t]+" nil t) - (replace-match "," t t)) - (goto-char (point-min)) - ;; Remove a trailing comma. - (if (re-search-forward ",$" nil t) - (replace-match "" t t)))) - - ;; Added by Per Abrahamsen . - ;; Help save the the world! - (or - gnus-expert-user - (let ((newsgroups (mail-fetch-field "newsgroups")) - (followup-to (mail-fetch-field "followup-to")) - groups to) - (if (and newsgroups - (string-match "," newsgroups) (not followup-to)) - (progn - (while (string-match "," newsgroups) - (setq groups - (cons (list (substring newsgroups - 0 (match-beginning 0))) - groups)) - (setq newsgroups (substring newsgroups (match-end 0)))) - (setq groups (nreverse (cons (list newsgroups) groups))) - - (setq to - (completing-read "Followups to: (default all groups) " - groups)) - (if (> (length to) 0) - (progn - (goto-char (point-min)) - (insert "Followup-To: " to "\n"))))))) - - ;; Cleanup Followup-To. - (goto-char (point-min)) - (if (search-forward-regexp "^Followup-To: +" nil t) - (save-restriction - (narrow-to-region - (point) - (if (re-search-forward "^[^ \t]" nil 'end) - (match-beginning 0) - (point-max))) - (goto-char (point-min)) - (replace-regexp "\n[ \t]+" " ") ;No line breaks (too confusing) - (goto-char (point-min)) - (replace-regexp "[ \t\n]*,[ \t\n]*\\|[ \t]+" ","))) - - ;; Mail the message too if To:, Bcc:. or Cc: exists. - (let* ((types '("to" "bcc" "cc")) - (ty types) - fcc-line) - (while ty - (or (mail-fetch-field (car ty) nil t) - (setq types (delete (car ty) types))) - (setq ty (cdr ty))) - - (if (not types) - ;; We do not want to send mail. - () - (if (not gnus-mail-send-method) - (progn - (ding) - (gnus-message - 1 "No mailer defined. To: and/or Cc: fields ignored.") - (sit-for 1)) - (save-excursion - ;; We want to remove Fcc, because we want to handle - ;; that one ourselves... - - (goto-char (point-min)) - (if (re-search-forward "^Fcc: " nil t) - (progn - (setq fcc-line - (buffer-substring - (progn (beginning-of-line) (point)) - (progn (forward-line 1) (point)))) - (forward-line -1) - (gnus-delete-line))) - - ;; We generate a Message-ID so that the mail and the - ;; news copy of the message both get the same ID. - (or (mail-fetch-field "message-id") - (not (memq 'Message-ID gnus-required-headers)) - (progn - (goto-char (point-max)) - (insert "Message-ID: " (gnus-inews-message-id) "\n"))) + (message-mail (or to-address to-list)) + ;; Arrange for mail groups that have no `to-address' to + ;; get that when the user sends off the mail. + (push (list 'gnus-inews-add-to-address group) + message-send-actions)) + (set-buffer gnus-article-copy) + (message-wide-reply to-address))) + (when yank + (gnus-inews-yank-articles yank)))))) + +(defun gnus-post-method (arg group &optional silent) + "Return the posting method based on GROUP and ARG. +If SILENT, don't prompt the user." + (let ((group-method (gnus-find-method-for-group group))) + (cond + ;; If the group-method is nil (which shouldn't happen) we use + ;; the default method. + ((null arg) + (or gnus-post-method gnus-select-method message-post-method)) + ;; We want this group's method. + ((and arg (not (eq arg 0))) + group-method) + ;; We query the user for a post method. + ((or arg + (and gnus-post-method + (listp (car gnus-post-method)))) + (let* ((methods + ;; Collect all methods we know about. + (append + (when gnus-post-method + (if (listp (car gnus-post-method)) + gnus-post-method + (list gnus-post-method))) + gnus-secondary-select-methods + (list gnus-select-method) + (list group-method))) + method-alist post-methods method) + ;; Weed out all mail methods. + (while methods + (setq method (gnus-server-get-method "" (pop methods))) + (when (or (gnus-method-option-p method 'post) + (gnus-method-option-p method 'post-mail)) + (push method post-methods))) + ;; Create a name-method alist. + (setq method-alist + (mapcar + (lambda (m) + (list (concat (cadr m) " (" (symbol-name (car m)) ")") m)) + post-methods)) + ;; Query the user. + (cadr + (assoc + (setq gnus-last-posting-server + (if (and silent + gnus-last-posting-server) + ;; Just use the last value. + gnus-last-posting-server + (completing-read + "Posting method: " method-alist nil t + (cons (or gnus-last-posting-server "") 0)))) + method-alist)))) + ;; Override normal method. + ((and gnus-post-method + (or (gnus-method-option-p group-method 'post) + (gnus-method-option-p group-method 'post-mail))) + gnus-post-method) + ;; Perhaps this is a mail group? + ((and (not (gnus-member-of-valid 'post group)) + (not (gnus-method-option-p group-method 'post-mail))) + group-method) + ;; Use the normal select method. + (t gnus-select-method)))) + +(defun gnus-inews-narrow-to-headers () + (widen) + (narrow-to-region + (goto-char (point-min)) + (or (and (re-search-forward + (concat "^" (regexp-quote mail-header-separator) "$") nil t) + (match-beginning 0)) + (point-max))) + (goto-char (point-min))) - (save-restriction - (widen) - (gnus-message 5 "Sending via mail...") - - (if (and gnus-mail-courtesy-message - (or (member "to" types) - (member "cc" types))) - ;; We only want to insert the courtesy mail - ;; message if we use to or cc; bcc should not - ;; have one. Well, if both bcc and to are - ;; present, it will get one anyway. - (progn - ;; Insert "courtesy" mail message. - (goto-char (point-min)) - (re-search-forward - (concat "^" (regexp-quote - mail-header-separator) "$")) - (forward-line 1) - (insert gnus-mail-courtesy-message) - (funcall gnus-mail-send-method) - (goto-char (point-min)) - (search-forward gnus-mail-courtesy-message) - (replace-match "" t t)) - (funcall gnus-mail-send-method)) - - (gnus-message 5 "Sending via mail...done") - - (goto-char (point-min)) - (narrow-to-region - (point) - (re-search-forward - (concat "^" (regexp-quote mail-header-separator) "$"))) - (goto-char (point-min)) - (while (re-search-forward "^BCC:" nil t) - (delete-region (match-beginning 0) - ;; There might be continuation headers. - (if (re-search-forward "^[^ \t]" nil t) - (match-beginning 0) - ;; Uhm... or something like this. - (forward-line 1) - (point))))) - (if fcc-line - (progn - (goto-char (point-max)) - (insert fcc-line)))))))) - - ;; Send to server. - (gnus-message 5 "Posting to USENET...") - (setq post-result (funcall gnus-inews-article-function use-group-method)) - (cond ((eq post-result 'illegal) - (setq error t) - (ding)) - (post-result - (gnus-message 5 "Posting to USENET...done") - (if (gnus-buffer-exists-p (car-safe reply)) - (progn - (save-excursion - (set-buffer gnus-summary-buffer) - (gnus-summary-mark-article-as-replied - (cdr reply))))) - (set-buffer-modified-p nil)) - (t - ;; We cannot signal an error. - (setq error t) - (ding) - (gnus-message 1 "Article rejected: %s" - (gnus-status-message gnus-select-method))))) - ;; If NNTP server is opened by gnus-inews-news, close it by myself. - (or server-running - (gnus-close-server (gnus-find-method-for-group gnus-newsgroup-name))) - (let ((conf gnus-prev-winconf)) - (if (not error) - (progn - (bury-buffer) - ;; Restore last window configuration. - (and conf (set-window-configuration conf))))))) - -(defun gnus-inews-check-post () - "Check whether the post looks ok." - (or - (not gnus-check-before-posting) - (and - ;; We narrow to the headers and check them first. - (save-excursion - (save-restriction - (goto-char (point-min)) - (narrow-to-region - (point) - (progn - (re-search-forward - (concat "^" (regexp-quote mail-header-separator) "$")) - (match-beginning 0))) - (goto-char (point-min)) - (and - ;; Check for commands in Subject. - (or - (gnus-check-before-posting 'subject-cmsg) - (save-excursion - (if (string-match "^cmsg " (mail-fetch-field "subject")) - (gnus-y-or-n-p - "The control code \"cmsg \" is in the subject. Really post? ") - t))) - ;; Check for multiple identical headers. - (or (gnus-check-before-posting 'multiple-headers) - (save-excursion - (let (found) - (while (and (not found) (re-search-forward "^[^ \t:]+: " - nil t)) - (save-excursion - (or (re-search-forward - (concat "^" (setq found - (buffer-substring - (match-beginning 0) - (- (match-end 0) 2)))) - nil t) - (setq found nil)))) - (if found - (gnus-y-or-n-p - (format "Multiple %s headers. Really post? " found)) - t)))) - ;; Check for version and sendsys. - (or (gnus-check-before-posting 'sendsys) - (save-excursion - (if (re-search-forward "^Sendsys:\\|^Version:" nil t) - (gnus-y-or-n-p - (format "The article contains a %s command. Really post? " - (buffer-substring (match-beginning 0) - (1- (match-end 0))))) - t))) - ;; Check the Message-Id header. - (or (gnus-check-before-posting 'message-id) - (save-excursion - (let* ((case-fold-search t) - (message-id (mail-fetch-field "message-id"))) - (or (not message-id) - (and (string-match "@" message-id) - (string-match "@[^\\.]*\\." message-id)) - (gnus-y-or-n-p - (format - "The Message-ID looks strange: \"%s\". Really post? " - message-id)))))) - ;; Check the From header. - (or (gnus-check-before-posting 'from) - (save-excursion - (let* ((case-fold-search t) - (from (mail-fetch-field "from"))) - (cond - ((not from) - (gnus-y-or-n-p "There is no From line. Really post? ")) - ((not (string-match "@[^\\.]*\\." from)) - (gnus-y-or-n-p - (format - "The address looks strange: \"%s\". Really post? " from))) - ((string-match "(.*).*(.*)" from) - (gnus-y-or-n-p - (format - "The From header looks strange: \"%s\". Really post? " - from))) - (t t))))) - ))) - ;; Check for long lines. - (or (gnus-check-before-posting 'long-lines) - (save-excursion - (goto-char (point-min)) - (re-search-forward - (concat "^" (regexp-quote mail-header-separator) "$")) - (while (and - (progn - (end-of-line) - (< (current-column) 80)) - (zerop (forward-line 1)))) - (or (bolp) - (eobp) - (gnus-y-or-n-p - (format - "You have lines longer than 79 characters. Really post? "))))) - ;; Check for control characters. - (or (gnus-check-before-posting 'control-chars) - (save-excursion - (if (re-search-forward "[\000-\007\013\015-\037\200-\237]" nil t) - (gnus-y-or-n-p - "The article contains control characters. Really post? ") - t))) - ;; Check excessive size. - (or (gnus-check-before-posting 'size) - (if (> (buffer-size) 60000) - (gnus-y-or-n-p - (format "The article is %d octets long. Really post? " - (buffer-size))) - t)) - ;; Use the (size . checksum) variable to see whether the - ;; article is empty or has only quoted text. - (or - (gnus-check-before-posting 'new-text) - (if (and (= (buffer-size) (car gnus-article-check-size)) - (= (gnus-article-checksum) (cdr gnus-article-check-size))) - (gnus-y-or-n-p - "It looks like there's no new text in your article. Really post? ") - t)) - ;; Check the length of the signature. - (or (gnus-check-before-posting 'signature) - (progn - (goto-char (point-max)) - (if (not (re-search-backward gnus-signature-separator nil t)) - t - (if (> (count-lines (point) (point-max)) 5) - (gnus-y-or-n-p - (format - "Your .sig is %d lines; it should be max 4. Really post? " - (count-lines (point) (point-max)))) - t))))))) - -(defun gnus-article-checksum () - (let ((sum 0)) - (save-excursion - (while (not (eobp)) - (setq sum (logxor sum (following-char))) - (forward-char 1))) - sum)) - -;; Returns non-nil if this type is not to be checked. -(defun gnus-check-before-posting (type) - (not - (or (not gnus-check-before-posting) - (if (listp gnus-check-before-posting) - (memq type gnus-check-before-posting) - t)))) - -(defun gnus-cancel-news () - "Cancel an article you posted." - (interactive) - (if (or gnus-expert-user - (gnus-yes-or-no-p "Do you really want to cancel this article? ")) - (let ((from nil) - (newsgroups nil) - (message-id nil) - (distribution nil)) - (or (gnus-member-of-valid 'post gnus-newsgroup-name) - (error "This backend does not support canceling")) - (save-excursion - ;; Get header info. from original article. - (save-restriction - (gnus-article-show-all-headers) - (goto-char (point-min)) - (search-forward "\n\n" nil 'move) - (narrow-to-region (point-min) (point)) - (setq from (mail-fetch-field "from")) - (setq newsgroups (mail-fetch-field "newsgroups")) - (setq message-id (mail-fetch-field "message-id")) - (setq distribution (mail-fetch-field "distribution"))) - ;; Verify if the article is absolutely user's by comparing - ;; user id with value of its From: field. - (if (not - (string-equal - (downcase (mail-strip-quoted-names from)) - (downcase (mail-strip-quoted-names (gnus-inews-user-name))))) - (progn - (ding) (gnus-message 3 "This article is not yours.") - nil) - ;; Make control article. - (set-buffer (get-buffer-create " *Gnus-canceling*")) - (buffer-disable-undo (current-buffer)) - (erase-buffer) - (insert "Newsgroups: " newsgroups "\n" - "Subject: cancel " message-id "\n" - "Control: cancel " message-id "\n" - (if distribution - (concat "Distribution: " distribution "\n") - "") - mail-header-separator "\n" - "This is a cancel message from " from ".\n") - ;; Send the control article to NNTP server. - (gnus-message 5 "Canceling your article...") - (prog1 - (if (funcall gnus-inews-article-function) - (gnus-message 5 "Canceling your article...done") - (progn - (ding) - (gnus-message 1 "Cancel failed; %s" - (gnus-status-message gnus-newsgroup-name)) - nil) - t) - ;; Kill the article buffer. - (kill-buffer (current-buffer)))))))) +;;; +;;; Check whether the message has been sent already. +;;; + +(defvar gnus-inews-sent-ids nil) + +(defun gnus-inews-reject-message () + "Check whether this message has already been sent." + (when gnus-sent-message-ids-file + (let ((message-id (save-restriction (gnus-inews-narrow-to-headers) + (mail-fetch-field "message-id"))) + end) + (when message-id + (unless gnus-inews-sent-ids + (condition-case () + (load t t t) + (error nil))) + (if (member message-id gnus-inews-sent-ids) + ;; Reject this message. + (not (gnus-yes-or-no-p + (format "Message %s already sent. Send anyway? " + message-id))) + (push message-id gnus-inews-sent-ids) + ;; Chop off the last Message-IDs. + (when (setq end (nthcdr gnus-sent-message-ids-length + gnus-inews-sent-ids)) + (setcdr end nil)) + (nnheader-temp-write gnus-sent-message-ids-file + (prin1 `(setq gnus-inews-sent-ids ',gnus-inews-sent-ids) + (current-buffer))) + nil))))) -;;; Lowlevel inews interface - -(defun gnus-inews-article (&optional use-group-method) - "Post an article in current buffer using NNTP protocol." - (let ((artbuf (current-buffer)) - (tmpbuf (get-buffer-create " *Gnus-posting*"))) - (widen) - (goto-char (point-max)) - ;; require a newline at the end for inews to append .signature to - (or (= (preceding-char) ?\n) - (insert ?\n)) - ;; Prepare article headers. All message body such as signature - ;; must be inserted before Lines: field is prepared. - (save-restriction - (goto-char (point-min)) - (narrow-to-region - (point-min) - (save-excursion - (re-search-forward - (concat "^" (regexp-quote mail-header-separator) "$")) - (match-beginning 0))) - (gnus-inews-remove-headers) - (gnus-inews-insert-headers) - (run-hooks 'gnus-inews-article-header-hook) - (widen)) - ;; Check whether the article is a good Net Citizen. - (if (and gnus-article-check-size - (not (gnus-inews-check-post))) - ;; Aber nein! - 'illegal - ;; Looks ok, so we do the nasty. - (save-excursion - (set-buffer tmpbuf) - (buffer-disable-undo (current-buffer)) - (erase-buffer) - (insert-buffer-substring artbuf) - ;; Remove the header separator. - (goto-char (point-min)) - (re-search-forward - (concat "^" (regexp-quote mail-header-separator) "$")) - (replace-match "" t t) - ;; This hook may insert a signature. - (save-excursion - (goto-char (point-min)) - (let ((gnus-newsgroup-name (or (mail-fetch-field "newsgroups") - gnus-newsgroup-name))) - (run-hooks 'gnus-prepare-article-hook))) - ;; Run final inews hooks. This hook may do FCC. - ;; The article must be saved before being posted because - ;; `gnus-request-post' modifies the buffer. - (run-hooks 'gnus-inews-article-hook) - ;; Post an article to NNTP server. - ;; Return NIL if post failed. - (prog1 - (gnus-request-post - (if use-group-method - (gnus-find-method-for-group gnus-newsgroup-name) - gnus-select-method) use-group-method) - (kill-buffer (current-buffer))))))) - -(defun gnus-inews-remove-headers () - (let ((case-fold-search t) - (headers gnus-removable-headers)) - ;; Remove toxic headers. - (while headers - (goto-char (point-min)) - (and (re-search-forward - (concat "^" (downcase (format "%s" (car headers)))) - nil t) - (delete-region (progn (beginning-of-line) (point)) - (progn (forward-line 1) (point)))) - (setq headers (cdr headers))))) - -(defun gnus-inews-insert-headers () - "Prepare article headers. -Headers already prepared in the buffer are not modified. -Headers in `gnus-required-headers' will be generated." - (let ((Date (gnus-inews-date)) - (Message-ID (gnus-inews-message-id)) - (Organization (gnus-inews-organization)) - (From (gnus-inews-user-name)) - (Path (gnus-inews-path)) - (Subject nil) - (Newsgroups nil) - (Distribution nil) - (Lines (gnus-inews-lines)) - (X-Newsreader gnus-version) - (headers gnus-required-headers) - (case-fold-search t) - header value elem) - ;; First we remove any old generated headers. - (let ((headers gnus-deletable-headers)) - (while headers - (goto-char (point-min)) - (and (re-search-forward - (concat "^" (symbol-name (car headers)) ": *") nil t) - (get-text-property (1+ (match-beginning 0)) 'gnus-deletable) - (gnus-delete-line)) - (setq headers (cdr headers)))) - ;; If there are References, and no "Re: ", then the thread has - ;; changed name. See Son-of-1036. - (if (and (mail-fetch-field "references") - (get-buffer gnus-article-buffer)) - (let ((psubject (gnus-simplify-subject-re - (mail-fetch-field "subject")))) - (or (and psubject gnus-reply-subject - (string= (gnus-simplify-subject-re gnus-reply-subject) - psubject)) - (progn - (string-match "@" Message-ID) - (setq Message-ID - (concat (substring Message-ID 0 (match-beginning 0)) - "_-_" - (substring Message-ID (match-beginning 0)))))))) - ;; Go through all the required headers and see if they are in the - ;; articles already. If they are not, or are empty, they are - ;; inserted automatically - except for Subject, Newsgroups and - ;; Distribution. - (while headers - (goto-char (point-min)) - (setq elem (car headers)) - (if (consp elem) - (setq header (car elem)) - (setq header elem)) - (if (or (not (re-search-forward - (concat "^" (downcase (symbol-name header)) ":") nil t)) - (progn - ;; The header was found. We insert a space after the - ;; colon, if there is none. - (if (/= (following-char) ? ) (insert " ")) - ;; Find out whether the header is empty... - (looking-at "[ \t]*$"))) - ;; So we find out what value we should insert. - (progn - (setq value - (or (if (consp elem) - ;; The element is a cons. Either the cdr is - ;; a string to be inserted verbatim, or it - ;; is a function, and we insert the value - ;; returned from this function. - (or (and (stringp (cdr elem)) (cdr elem)) - (and (fboundp (cdr elem)) (funcall (cdr elem)))) - ;; The element is a symbol. We insert the - ;; value of this symbol, if any. - (and (boundp header) (symbol-value header))) - ;; We couldn't generate a value for this header, - ;; so we just ask the user. - (read-from-minibuffer - (format "Empty header for %s; enter value: " header)))) - ;; Finally insert the header. - (save-excursion - (if (bolp) - (progn - (goto-char (point-max)) - (insert (symbol-name header) ": " value "\n") - (forward-line -1)) - (replace-match value t t)) - ;; Add the deletable property to the headers that require it. - (and (memq header gnus-deletable-headers) - (progn (beginning-of-line) (looking-at "[^:]+: ")) - (add-text-properties - (point) (match-end 0) - '(gnus-deletable t face italic) (current-buffer)))))) - (setq headers (cdr headers))) - ;; Insert new Sender if the From is strange. - (let ((from (mail-fetch-field "from")) - (sender (mail-fetch-field "sender"))) - (if (and from - (not (string= - (downcase - (car (cdr (gnus-extract-address-components from)))) - (downcase (gnus-inews-real-user-address)))) - (or (null sender) - (not - (string= - (downcase - (car (cdr (gnus-extract-address-components sender)))) - (downcase (gnus-inews-real-user-address)))))) - (progn - (goto-char (point-min)) - (and (re-search-forward "^Sender:" nil t) - (progn - (beginning-of-line) - (insert "Original-") - (beginning-of-line))) - (insert "Sender: " (gnus-inews-real-user-address) "\n")))))) - - -(defun gnus-inews-insert-signature () - "Insert a signature file. -If `gnus-signature-function' is bound and returns a string, this -string is used instead of the variable `gnus-signature-file'. -In either case, if the string is a file name, this file is -inserted. If the string is not a file name, the string itself is -inserted. - -If you never want any signature inserted, set both of these variables to -nil." - (save-excursion - (let ((signature - (or (and gnus-signature-function - (funcall gnus-signature-function gnus-newsgroup-name)) - gnus-signature-file))) - (if (and signature - (or (file-exists-p signature) - (string-match " " signature) - (not (string-match - "^/[^/]+/" (expand-file-name signature))))) - (progn - (goto-char (point-max)) - (if (and mail-signature (search-backward "\n-- \n" nil t)) - () - ;; Delete any previous signatures. - (if (search-backward "\n-- \n" nil t) - (delete-region (point) (point-max))) - (or (eolp) (insert "\n")) - (insert "-- \n") - (if (file-exists-p signature) - (insert-file-contents signature) - (insert signature)) - (goto-char (point-max)) - (or (bolp) (insert "\n")))))))) + +;; Dummy to avoid byte-compile warning. +(defvar nnspool-rejected-article-hook) + +;;; Since the X-Newsreader/X-Mailer are ``vanity'' headers, they might +;;; as well include the Emacs version as well. +;;; The following function works with later GNU Emacs, and XEmacs. +(defun gnus-extended-version () + "Stringified Gnus version and Emacs version" + (interactive) + (concat + gnus-version + "/" + (cond + ((string-match "^\\([0-9]+\\.[0-9]+\\)\\.[.0-9]+$" emacs-version) + (concat "Emacs " (substring emacs-version + (match-beginning 1) + (match-end 1)))) + ((string-match "\\([A-Z]*[Mm][Aa][Cc][Ss]\\)" emacs-version) + (concat (substring emacs-version + (match-beginning 1) + (match-end 1)) + (format " %d.%d" emacs-major-version emacs-minor-version))) + (t emacs-version)))) ;; Written by "Mr. Per Persson" . (defun gnus-inews-insert-mime-headers () - (let ((mail-header-separator "")) + (goto-char (point-min)) + (let ((mail-header-separator + (progn + (goto-char (point-min)) + (if (and (search-forward (concat "\n" mail-header-separator "\n") + nil t) + (not (search-backward "\n\n" nil t))) + mail-header-separator + "")))) (or (mail-position-on-field "Mime-Version") (insert "1.0") - (cond ((save-excursion - (beginning-of-buffer) + (cond ((save-restriction + (widen) + (goto-char (point-min)) (re-search-forward "[\200-\377]" nil t)) (or (mail-position-on-field "Content-Type") (insert "text/plain; charset=ISO-8859-1")) @@ -1209,230 +503,6 @@ nil." (or (mail-position-on-field "Content-Transfer-Encoding") (insert "7bit"))))))) -(defun gnus-inews-do-fcc () - "Process FCC: fields in current article buffer. -Unless the first character of the field is `|', the article is saved -to the specified file using the function specified by the variable -gnus-author-copy-saver. The default function rmail-output saves in -Unix mailbox format. -If the first character is `|', the contents of the article is send to -a program specified by the rest of the value." - (let ((fcc-list nil) - (fcc-file nil) - (case-fold-search t)) ;Should ignore case. - (save-excursion - (save-restriction - (goto-char (point-min)) - (search-forward "\n\n") - (narrow-to-region (point-min) (point)) - (goto-char (point-min)) - (while (re-search-forward "^FCC:[ \t]*" nil t) - (setq fcc-list - (cons (buffer-substring - (point) - (progn - (end-of-line) - (skip-chars-backward " \t") - (point))) - fcc-list)) - (delete-region (match-beginning 0) - (progn (forward-line 1) (point)))) - ;; Process FCC operations. - (widen) - (while fcc-list - (setq fcc-file (car fcc-list)) - (setq fcc-list (cdr fcc-list)) - (cond ((string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" fcc-file) - (let ((program (substring fcc-file - (match-beginning 1) (match-end 1)))) - ;; Suggested by yuki@flab.fujitsu.junet. - ;; Send article to named program. - (call-process-region (point-min) (point-max) shell-file-name - nil nil nil "-c" program))) - (t - ;; Suggested by hyoko@flab.fujitsu.junet. - ;; Save article in Unix mail format by default. - (gnus-make-directory (file-name-directory fcc-file)) - (if (and gnus-author-copy-saver - (not (eq gnus-author-copy-saver 'rmail-output))) - (funcall gnus-author-copy-saver fcc-file) - (if (and (file-readable-p fcc-file) - (mail-file-babyl-p fcc-file)) - (gnus-output-to-rmail fcc-file) - (rmail-output fcc-file 1 t t)))))))))) - -(defun gnus-inews-path () - "Return uucp path." - (let ((login-name (gnus-inews-login-name))) - (cond ((null gnus-use-generic-path) - (concat (nth 1 gnus-select-method) "!" login-name)) - ((stringp gnus-use-generic-path) - ;; Support GENERICPATH. Suggested by vixie@decwrl.dec.com. - (concat gnus-use-generic-path "!" login-name)) - (t login-name)))) - -(defun gnus-inews-user-name () - "Return user's network address as \"NAME@DOMAIN (FULL-NAME)\"." - (let ((full-name (gnus-inews-full-name)) - (address (if (or gnus-user-login-name gnus-use-generic-from - gnus-local-domain (getenv "DOMAINNAME")) - (concat (gnus-inews-login-name) "@" - (gnus-inews-domain-name gnus-use-generic-from)) - user-mail-address))) - (or gnus-user-from-line - (concat address - ;; User's full name. - (cond ((string-equal full-name "&") ;Unix hack. - (concat " (" (user-login-name) ")")) - ((string-match "[^ ]+@[^ ]+ +(.*)" address) - "") - (t - (concat " (" full-name ")"))))))) - -(defun gnus-inews-real-user-address () - "Return the \"real\" user address. -This function tries to ignore all user modifications, and -give as trustworthy answer as possible." - (concat (user-login-name) "@" (gnus-inews-full-address))) - -(defun gnus-inews-login-name () - "Return login name." - (or gnus-user-login-name (getenv "LOGNAME") (user-login-name))) - -(defun gnus-inews-full-name () - "Return full user name." - (or gnus-user-full-name (getenv "NAME") (user-full-name))) - -(defun gnus-inews-domain-name (&optional genericfrom) - "Return user's domain name. -If optional argument GENERICFROM is a string, use it as the domain -name; if it is non-nil, strip off local host name from the domain name. -If the function `system-name' returns full internet name and the -domain is undefined, the domain name is got from it." - (if (or genericfrom gnus-local-domain (getenv "DOMAINNAME")) - (let* ((system-name (system-name)) - (domain - (or (if (stringp genericfrom) genericfrom) - (getenv "DOMAINNAME") - gnus-local-domain - ;; Function `system-name' may return full internet name. - ;; Suggested by Mike DeCorte . - (if (string-match "\\." system-name) - (substring system-name (match-end 0))) - (read-string "Domain name (no host): "))) - (host (or (if (string-match "\\." system-name) - (substring system-name 0 (match-beginning 0))) - system-name))) - (if (string-equal "." (substring domain 0 1)) - (setq domain (substring domain 1))) - ;; Support GENERICFROM as same as standard Bnews system. - ;; Suggested by ohm@kaba.junet and vixie@decwrl.dec.com. - (cond ((null genericfrom) - (concat host "." domain)) - ;;((stringp genericfrom) genericfrom) - (t domain))) - (if (string-match "\\." (system-name)) - (system-name) - (substring user-mail-address - (1+ (string-match "@" user-mail-address)))))) - -(defun gnus-inews-full-address () - (let ((domain (gnus-inews-domain-name)) - (system (system-name)) - (case-fold-search t)) - (if (string-match "\\." system) system - (if (string-match (concat "^" (regexp-quote system)) domain) domain - (concat system "." domain))))) - -(defun gnus-inews-message-id () - "Generate unique Message-ID for user." - ;; Message-ID should not contain a slash and should be terminated by - ;; a number. I don't know the reason why it is so. - (concat "<" (gnus-inews-unique-id) "@" (gnus-inews-full-address) ">")) - -(defvar gnus-unique-id-char nil) - -;; If you ever change this function, make sure the new version -;; cannot generate IDs that the old version could. -;; You might for example insert a "." somewhere (not next to another dot -;; or string boundary), or modify the newsreader name to "Ding". -(defun gnus-inews-unique-id () - ;; Don't use microseconds from (current-time), they may be unsupported. - ;; Instead we use this randomly inited counter. - (setq gnus-unique-id-char - (% (1+ (or gnus-unique-id-char (logand (random t) (1- (lsh 1 20))))) - ;; (current-time) returns 16-bit ints, - ;; and 2^16*25 just fits into 4 digits i base 36. - (* 25 25))) - (let ((tm (if (fboundp 'current-time) - (current-time) '(12191 46742 287898)))) - (concat - (if (memq system-type '(ms-dos emx vax-vms)) - (let ((user (downcase (gnus-inews-login-name)))) - (while (string-match "[^a-z0-9_]" user) - (aset user (match-beginning 0) ?_)) - user) - (gnus-number-base36 (user-uid) -1)) - (gnus-number-base36 (+ (car tm) (lsh (% gnus-unique-id-char 25) 16)) 4) - (gnus-number-base36 (+ (nth 1 tm) (lsh (/ gnus-unique-id-char 25) 16)) 4) - ;; Append the newsreader name, because while the generated - ;; ID is unique to this newsreader, other newsreaders might - ;; otherwise generate the same ID via another algorithm. - ".fsf"))) - - -(defun gnus-inews-date () - "Current time string." - ;; We call (current-time) once, rather than letting current-time-string and - ;; current-time-zone default to it, because that avoids a rare race - ;; condition when the time zone changes between those two calls. - (let ((now (current-time))) - (timezone-make-date-arpa-standard - (current-time-string now) (current-time-zone now)))) - -(defun gnus-inews-organization () - "Return user's organization. -The ORGANIZATION environment variable is used if defined. -If not, the variable `gnus-local-organization' is used instead. -If it is a function, the function will be called with the current -newsgroup name as the argument. -If this is a file name, the contents of this file will be used as the -organization." - (let* ((organization - (or (getenv "ORGANIZATION") - (if gnus-local-organization - (if (and (symbolp gnus-local-organization) - (fboundp gnus-local-organization)) - (funcall gnus-local-organization gnus-newsgroup-name) - gnus-local-organization)) - gnus-organization-file - "~/.organization"))) - (and (stringp organization) - (> (length organization) 0) - (or (file-exists-p organization) - (string-match " " organization) - (not (string-match "^/usr/lib/" organization))) - (save-excursion - (gnus-set-work-buffer) - (if (file-exists-p organization) - (insert-file-contents organization) - (insert organization)) - (goto-char (point-min)) - (while (re-search-forward " *\n *" nil t) - (replace-match " " t t)) - (buffer-substring (point-min) (point-max)))))) - -(defun gnus-inews-lines () - "Count the number of lines and return numeric string." - (save-excursion - (save-restriction - (widen) - (goto-char (point-min)) - (re-search-forward - (concat "^" (regexp-quote mail-header-separator) "$")) - (forward-line 1) - (int-to-string (count-lines (point) (point-max)))))) - ;;; ;;; Gnus Mail Functions @@ -1440,37 +510,47 @@ organization." ;;; Mail reply commands of Gnus summary mode -(defun gnus-summary-reply (yank &optional yank-articles) +(defun gnus-summary-reply (&optional yank) "Reply mail to news author. -If prefix argument YANK is non-nil, original article is yanked automatically. -Customize the variable gnus-mail-reply-method to use another mailer." - (interactive "P") +If prefix argument YANK is non-nil, original article is yanked automatically." + (interactive + (list (and current-prefix-arg + (gnus-summary-work-articles 1)))) ;; Bug fix by jbw@bigbird.bu.edu (Joe Wells) ;; Stripping headers should be specified with mail-yank-ignored-headers. (gnus-set-global-variables) - (if yank-articles (gnus-summary-goto-subject (car yank-articles))) - (gnus-summary-select-article) - (let ((gnus-newsgroup-name gnus-newsgroup-name)) - (bury-buffer gnus-article-buffer) - (funcall gnus-mail-reply-method (or yank-articles (not (not yank)))))) + (when yank + (gnus-summary-goto-subject (car yank))) + (let ((gnus-article-reply t)) + (gnus-setup-message (if yank 'reply-yank 'reply) + (gnus-summary-select-article) + (set-buffer (gnus-copy-article-buffer)) + (message-reply nil nil (gnus-group-get-parameter + gnus-newsgroup-name 'broken-reply-to)) + (when yank + (gnus-inews-yank-articles yank))))) (defun gnus-summary-reply-with-original (n) - "Reply mail to news author with original article. -Customize the variable gnus-mail-reply-method to use another mailer." + "Reply mail to news author with original article." (interactive "P") - (gnus-summary-reply t (gnus-summary-work-articles n))) + (gnus-summary-reply (gnus-summary-work-articles n))) -(defun gnus-summary-mail-forward (post) - "Forward the current message to another user. -Customize the variable gnus-mail-forward-method to use another mailer." +(defun gnus-summary-mail-forward (&optional post) + "Forward the current message to another user." (interactive "P") (gnus-set-global-variables) + (gnus-setup-message 'forward + (gnus-summary-select-article) + (set-buffer gnus-original-article-buffer) + (message-forward post))) + +(defun gnus-summary-resend-message (address) + "Resend the current article to ADDRESS." + (interactive "sResend message to: ") (gnus-summary-select-article) - (gnus-copy-article-buffer) - (let ((gnus-newsgroup-name gnus-newsgroup-name)) - (if post - (gnus-forward-using-post gnus-article-copy) - (funcall gnus-mail-forward-method gnus-article-copy)))) + (save-excursion + (set-buffer gnus-original-article-buffer) + (message-resend address))) (defun gnus-summary-post-forward () "Forward the current article to a newsgroup." @@ -1490,125 +570,42 @@ The current group name will be inserted at \"%s\".") "Really send a nastygram to the author of the current article? ")) (let ((group gnus-newsgroup-name)) (gnus-summary-reply-with-original n) - (set-buffer gnus-mail-buffer) + (set-buffer gnus-message-buffer) (insert (format gnus-nastygram-message group)) - (gnus-mail-send-and-exit)))) + (message-send-and-exit)))) (defun gnus-summary-mail-other-window () - "Compose mail in other window. -Customize the variable `gnus-mail-other-window-method' to use another -mailer." + "Compose mail in other window." (interactive) - (gnus-set-global-variables) - (let ((gnus-newsgroup-name gnus-newsgroup-name)) - (funcall gnus-mail-other-window-method))) - -(defun gnus-mail-reply-using-mail (&optional yank to-address) - (save-excursion - (set-buffer gnus-summary-buffer) - (let ((group (gnus-group-real-name gnus-newsgroup-name)) - (cur (cons (current-buffer) (cdr gnus-article-current))) - (winconf (current-window-configuration)) - from subject date reply-to message-of - references message-id sender follow-to sendto elt) - (set-buffer (get-buffer-create gnus-mail-buffer)) - (mail-mode) - (make-local-variable 'gnus-article-reply) - (setq gnus-article-reply cur) - (make-local-variable 'gnus-prev-winconf) - (setq gnus-prev-winconf winconf) - (if (and (buffer-modified-p) - (> (buffer-size) 0) - (not (gnus-y-or-n-p - "Unsent article being composed; erase it? "))) - () - (erase-buffer) - (save-excursion - (gnus-copy-article-buffer) - (save-restriction - (set-buffer gnus-article-copy) - (gnus-narrow-to-headers) - (if (and (boundp 'gnus-reply-to-function) - gnus-reply-to-function) - (setq follow-to (funcall gnus-reply-to-function group))) - (setq from (mail-fetch-field "from")) - (setq date (or (mail-fetch-field "date") - (mail-header-date gnus-current-headers))) - (and from - (let ((stop-pos - (string-match " *at \\| *@ \\| *(\\| *<" from))) - (setq message-of - (concat (if stop-pos (substring from 0 stop-pos) from) - "'s message of " date)))) - (setq sender (mail-fetch-field "sender")) - (setq subject (or (mail-fetch-field "subject") - "Re: none")) - (or (string-match "^[Rr][Ee]:" subject) - (setq subject (concat "Re: " subject))) - (setq reply-to (mail-fetch-field "reply-to")) - (setq references (mail-fetch-field "references")) - (setq message-id (mail-fetch-field "message-id")) - (widen)) - (setq news-reply-yank-from (or from "(nobody)"))) - (setq news-reply-yank-message-id - (or message-id "(unknown Message-ID)")) - - ;; Gather the "to" addresses out of the follow-to list and remove - ;; them as we go. - (if (and follow-to (listp follow-to)) - (while (setq elt (assoc "To" follow-to)) - (setq sendto (concat sendto (and sendto ", ") (cdr elt))) - (setq follow-to (delq elt follow-to)))) - - (mail-setup (or to-address - (if (and follow-to (not (stringp follow-to))) sendto - (or follow-to reply-to from sender ""))) - subject message-of nil gnus-article-copy nil) - - (auto-save-mode auto-save-default) - (use-local-map (copy-keymap (current-local-map))) - (local-set-key "\C-c\C-c" 'gnus-mail-send-and-exit) - - (if (and follow-to (listp follow-to)) - (progn - (goto-char (point-min)) - (re-search-forward "^To:" nil t) - (beginning-of-line) - (forward-line 1) - (while follow-to - (insert (car (car follow-to)) ": " (cdr (car follow-to)) "\n") - (setq follow-to (cdr follow-to))))) - (nnheader-insert-references references message-id) - (goto-char (point-min)) - (re-search-forward - (concat "^" (regexp-quote mail-header-separator) "$")) - (forward-line 1) - (if (not yank) - (gnus-configure-windows 'reply 'force) - (let ((last (point)) - end) - (if (not (listp yank)) - (progn - (save-excursion - (mail-yank-original nil)) - (or mail-yank-hooks mail-citation-hook - (run-hooks 'news-reply-header-hook))) - (while yank - (save-window-excursion - (set-buffer gnus-summary-buffer) - (gnus-summary-select-article nil nil nil (car yank)) - (gnus-summary-remove-process-mark (car yank))) - (save-excursion - (gnus-copy-article-buffer) - (mail-yank-original nil) - (setq end (point))) - (or mail-yank-hooks mail-citation-hook - (run-hooks 'news-reply-header-hook)) - (goto-char end) - (setq yank (cdr yank)))) - (goto-char last)) - (gnus-configure-windows 'reply-yank 'force)) - (run-hooks 'gnus-mail-hook))))) + (gnus-setup-message 'message + (message-mail))) + +(defun gnus-mail-parse-comma-list () + (let (accumulated + beg) + (skip-chars-forward " ") + (while (not (eobp)) + (setq beg (point)) + (skip-chars-forward "^,") + (while (zerop + (save-excursion + (save-restriction + (let ((i 0)) + (narrow-to-region beg (point)) + (goto-char beg) + (logand (progn + (while (search-forward "\"" nil t) + (incf i)) + (if (zerop i) 2 i)) 2))))) + (skip-chars-forward ",") + (skip-chars-forward "^,")) + (skip-chars-backward " ") + (setq accumulated + (cons (buffer-substring beg (point)) + accumulated)) + (skip-chars-forward "^,") + (skip-chars-forward ", ")) + accumulated)) (defun gnus-mail-yank-original () (interactive) @@ -1617,11 +614,41 @@ mailer." (or mail-yank-hooks mail-citation-hook (run-hooks 'news-reply-header-hook))) -(defun gnus-mail-send-and-exit () +(defun gnus-inews-add-to-address (group) + (let ((to-address (mail-fetch-field "to"))) + (when (and to-address + (gnus-alive-p)) + ;; This mail group doesn't have a `to-list', so we add one + ;; here. Magic! + (gnus-group-add-parameter group (cons 'to-list to-address))))) + +(defun gnus-put-message () + "Put the current message in some group and return to Gnus." (interactive) (let ((reply gnus-article-reply) - (winconf gnus-prev-winconf)) - (mail-send-and-exit nil) + (winconf gnus-prev-winconf) + (group gnus-newsgroup-name)) + + (or (and group (not (gnus-group-read-only-p group))) + (setq group (read-string "Put in group: " nil + (gnus-writable-groups)))) + (and (gnus-gethash group gnus-newsrc-hashtb) + (error "No such group: %s" group)) + + (save-excursion + (save-restriction + (widen) + (gnus-inews-narrow-to-headers) + (let (gnus-deletable-headers) + (if (message-news-p) + (message-generate-headers message-required-news-headers) + (message-generate-headers message-required-mail-headers))) + (goto-char (point-max)) + (insert "Gcc: " group "\n") + (widen))) + + (gnus-inews-do-gcc) + (if (get-buffer gnus-group-buffer) (progn (if (gnus-buffer-exists-p (car-safe reply)) @@ -1632,73 +659,6 @@ mailer." (cdr reply))))) (and winconf (set-window-configuration winconf)))))) -(defun gnus-forward-make-subject (buffer) - (save-excursion - (set-buffer buffer) - (concat "[" (if (memq 'mail (assoc (symbol-name - (car (gnus-find-method-for-group - gnus-newsgroup-name))) - gnus-valid-select-methods)) - (gnus-fetch-field "From") - gnus-newsgroup-name) - "] " (or (gnus-fetch-field "Subject") "")))) - -(defun gnus-forward-insert-buffer (buffer) - (let ((beg (goto-char (point-max)))) - (insert "------- Start of forwarded message -------\n") - (insert-buffer buffer) - (goto-char (point-max)) - (insert "------- End of forwarded message -------\n") - ;; Suggested by Sudish Joseph . - (goto-char beg) - (while (setq beg (next-single-property-change (point) 'invisible)) - (goto-char beg) - (delete-region beg (or (next-single-property-change - (point) 'invisible) - (point-max)))))) - -(defun gnus-mail-forward-using-mail (&optional buffer) - "Forward the current message to another user using mail." - ;; This is almost a carbon copy of rmail-forward in rmail.el. - (let* ((forward-buffer (or buffer (current-buffer))) - (winconf (current-window-configuration)) - (subject (gnus-forward-make-subject forward-buffer))) - (set-buffer forward-buffer) - (mail nil nil subject) - (use-local-map (copy-keymap (current-local-map))) - (local-set-key "\C-c\C-c" 'gnus-mail-send-and-exit) - (make-local-variable 'gnus-prev-winconf) - (setq gnus-prev-winconf winconf) - (gnus-forward-insert-buffer forward-buffer) - (goto-char (point-min)) - (re-search-forward "^To: " nil t) - (gnus-configure-windows 'mail-forward 'force) - ;; You have a chance to arrange the message. - (run-hooks 'gnus-mail-forward-hook) - (run-hooks 'gnus-mail-hook))) - -(defun gnus-forward-using-post (&optional buffer) - (save-excursion - (let* ((forward-buffer (or buffer (current-buffer))) - (subject (gnus-forward-make-subject forward-buffer)) - (gnus-newsgroup-name nil)) - (gnus-post-news 'post nil nil nil nil subject) - (save-excursion - (gnus-forward-insert-buffer forward-buffer) - ;; You have a chance to arrange the message. - (run-hooks 'gnus-mail-forward-hook))))) - -(defun gnus-mail-other-window-using-mail () - "Compose mail other window using mail." - (let ((winconf (current-window-configuration))) - (mail-other-window nil nil nil nil nil (get-buffer gnus-article-buffer)) - (use-local-map (copy-keymap (current-local-map))) - (local-set-key "\C-c\C-c" 'gnus-mail-send-and-exit) - (make-local-variable 'gnus-prev-winconf) - (setq gnus-prev-winconf winconf) - (run-hooks 'gnus-mail-hook) - (gnus-configure-windows 'summary-mail 'force))) - (defun gnus-article-mail (yank) "Send a reply to the address near point. If YANK is non-nil, include the original article." @@ -1707,52 +667,47 @@ If YANK is non-nil, include the original article." (buffer-substring (save-excursion (re-search-backward "[ \t\n]" nil t) (1+ (point))) (save-excursion (re-search-forward "[ \t\n]" nil t) (1- (point)))))) - (and address - (progn - (switch-to-buffer gnus-summary-buffer) - (funcall gnus-mail-reply-method yank address))))) + (when address + (switch-to-buffer gnus-summary-buffer) + (message-reply address) + (when yank + (gnus-inews-yank-articles yank))))) (defun gnus-bug () "Send a bug report to the Gnus maintainers." (interactive) - (let ((winconf (current-window-configuration))) + (gnus-setup-message 'bug (delete-other-windows) (switch-to-buffer "*Gnus Help Bug*") (erase-buffer) (insert gnus-bug-message) (goto-char (point-min)) - (pop-to-buffer "*Gnus Bug*") - (erase-buffer) - (mail-mode) - (mail-setup gnus-maintainer nil nil nil nil nil) - (auto-save-mode auto-save-default) - (make-local-variable 'gnus-prev-winconf) - (setq gnus-prev-winconf winconf) - (use-local-map (copy-keymap mail-mode-map)) - (local-set-key "\C-c\C-c" 'gnus-bug-mail-send-and-exit) + (message-pop-to-buffer "*Gnus Bug*") + (message-setup `((To . ,gnus-maintainer) (Subject . ""))) + (push `(gnus-bug-kill-buffer) message-send-actions) (goto-char (point-min)) (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$")) (forward-line 1) - (insert (format "%s\n%s\n\n\n\n\n" (gnus-version) (emacs-version))) + (insert (gnus-version) "\n") + (insert (emacs-version)) + (insert "\n\n\n\n\n") (gnus-debug) (goto-char (point-min)) (search-forward "Subject: " nil t) (message ""))) -(defun gnus-bug-mail-send-and-exit () - "Send the bug message and exit." - (interactive) +(defun gnus-bug-kill-buffer () (and (get-buffer "*Gnus Help Bug*") - (kill-buffer "*Gnus Help Bug*")) - (gnus-mail-send-and-exit)) + (kill-buffer "*Gnus Help Bug*"))) (defun gnus-debug () "Attemps to go through the Gnus source file and report what variables have been changed. The source file has to be in the Emacs load path." (interactive) - (let ((files '("gnus.el" "gnus-msg.el" "gnus-score.el")) + (let ((files '("gnus.el" "gnus-msg.el" "gnus-score.el" "nnmail.el" + "message.el")) file dirs expr olist sym) - (message "Please wait while we snoop your variables...") + (gnus-message 4 "Please wait while we snoop your variables...") (sit-for 0) (save-excursion (set-buffer (get-buffer-create " *gnus bug info*")) @@ -1770,32 +725,37 @@ The source file has to be in the Emacs load path." (setq dirs nil) (insert-file-contents file) (goto-char (point-min)) - (or (re-search-forward "^;;* *Internal variables" nil t) - (error "Malformed sources in file %s" file)) - (narrow-to-region (point-min) (point)) - (goto-char (point-min)) - (while (setq expr (condition-case () - (read (current-buffer)) (error nil))) - (condition-case () - (and (eq (car expr) 'defvar) - (stringp (nth 3 expr)) - (or (not (boundp (nth 1 expr))) - (not (equal (eval (nth 2 expr)) - (symbol-value (nth 1 expr))))) - (setq olist (cons (nth 1 expr) olist))) - (error nil))))) + (if (not (re-search-forward "^;;* *Internal variables" nil t)) + (gnus-message 4 "Malformed sources in file %s" file) + (narrow-to-region (point-min) (point)) + (goto-char (point-min)) + (while (setq expr (condition-case () + (read (current-buffer)) (error nil))) + (condition-case () + (and (eq (car expr) 'defvar) + (stringp (nth 3 expr)) + (or (not (boundp (nth 1 expr))) + (not (equal (eval (nth 2 expr)) + (symbol-value (nth 1 expr))))) + (setq olist (cons (nth 1 expr) olist))) + (error nil)))))) (setq files (cdr files))) (kill-buffer (current-buffer))) - (insert "------------------- Environment follows -------------------\n\n") + (when (setq olist (nreverse olist)) + (insert "------------------ Environment follows ------------------\n\n")) (while olist (if (boundp (car olist)) - (insert "(setq " (symbol-name (car olist)) - (if (or (consp (setq sym (symbol-value (car olist)))) - (and (symbolp sym) - (not (or (eq sym nil) - (eq sym t))))) - " '" " ") - (prin1-to-string (symbol-value (car olist))) ")\n") + (condition-case () + (pp `(setq ,(car olist) + ,(if (or (consp (setq sym (symbol-value (car olist)))) + (and (symbolp sym) + (not (or (eq sym nil) + (eq sym t))))) + (list 'quote (symbol-value (car olist))) + (symbol-value (car olist)))) + (current-buffer)) + (error + (format "(setq %s 'whatever)\n" (car olist)))) (insert ";; (makeunbound '" (symbol-name (car olist)) ")\n")) (setq olist (cdr olist))) (insert "\n\n") @@ -1805,6 +765,178 @@ The source file has to be in the Emacs load path." (while (re-search-forward "[\000\200]" nil t) (replace-match "" t t)))) +;;; Treatment of rejected articles. +;;; Bounced mail. + +(defun gnus-summary-resend-bounced-mail (&optional fetch) + "Re-mail the current message. +This only makes sense if the current message is a bounce message than +contains some mail you have written which has been bounced back to +you. +If FETCH, try to fetch the article that this is a reply to, if indeed +this is a reply." + (interactive "P") + (gnus-summary-select-article t) + (set-buffer gnus-original-article-buffer) + (gnus-setup-message 'compose-bounce + (let* ((references (mail-fetch-field "references")) + (parent (and references (gnus-parent-id references)))) + (message-bounce) + ;; If there are references, we fetch the article we answered to. + (and fetch parent + (gnus-summary-refer-article parent) + (gnus-summary-show-all-headers))))) + +;;; Gcc handling. + +;; Do Gcc handling, which copied the message over to some group. +(defun gnus-inews-do-gcc (&optional gcc) + (when (gnus-alive-p) + (save-excursion + (save-restriction + (message-narrow-to-headers) + (let ((gcc (or gcc (mail-fetch-field "gcc" nil t))) + (cur (current-buffer)) + groups group method) + (when gcc + (message-remove-header "gcc") + (widen) + (setq groups (message-tokenize-header gcc " ,")) + ;; Copy the article over to some group(s). + (while (setq group (pop groups)) + (gnus-check-server + (setq method + (cond ((and (null (gnus-get-info group)) + (eq (car gnus-message-archive-method) + (car + (gnus-server-to-method + (gnus-group-method group))))) + ;; If the group doesn't exist, we assume + ;; it's an archive group... + gnus-message-archive-method) + ;; Use the method. + ((gnus-info-method (gnus-get-info group)) + (gnus-info-method (gnus-get-info group))) + ;; Find the method. + (t (gnus-group-method group))))) + (gnus-check-server method) + (unless (gnus-request-group group t method) + (gnus-request-create-group group method)) + (save-excursion + (nnheader-set-temp-buffer " *acc*") + (insert-buffer-substring cur) + (goto-char (point-min)) + (when (re-search-forward + (concat "^" (regexp-quote mail-header-separator) "$") + nil t) + (replace-match "" t t )) + (unless (gnus-request-accept-article group method t) + (gnus-message 1 "Couldn't store article in group %s: %s" + group (gnus-status-message method)) + (sit-for 2)) + (kill-buffer (current-buffer)))))))))) + +(defun gnus-inews-insert-gcc () + "Insert Gcc headers based on `gnus-outgoing-message-group'." + (save-excursion + (save-restriction + (gnus-inews-narrow-to-headers) + (let* ((group gnus-outgoing-message-group) + (gcc (cond + ((gnus-functionp group) + (funcall group)) + ((or (stringp group) (list group)) + group)))) + (when gcc + (insert "Gcc: " + (if (stringp gcc) gcc + (mapconcat 'identity gcc " ")) + "\n")))))) + +(defun gnus-inews-insert-archive-gcc (&optional group) + "Insert the Gcc to say where the article is to be archived." + (let* ((var gnus-message-archive-group) + (group (or group gnus-newsgroup-name "")) + result + (groups + (cond + ((null gnus-message-archive-method) + ;; Ignore. + nil) + ((stringp var) + ;; Just a single group. + (list var)) + ((null var) + ;; We don't want this. + nil) + ((and (listp var) (stringp (car var))) + ;; A list of groups. + var) + ((gnus-functionp var) + ;; A function. + (funcall var group)) + (t + ;; An alist of regexps/functions/forms. + (while (and var + (not + (setq result + (cond + ((stringp (caar var)) + ;; Regexp. + (when (string-match (caar var) group) + (cdar var))) + ((gnus-functionp (car var)) + ;; Function. + (funcall (car var) group)) + (t + (eval (car var))))))) + (setq var (cdr var))) + result))) + name) + (when groups + (when (stringp groups) + (setq groups (list groups))) + (save-excursion + (save-restriction + (gnus-inews-narrow-to-headers) + (goto-char (point-max)) + (insert "Gcc: ") + (while (setq name (pop groups)) + (insert (if (string-match ":" name) + name + (gnus-group-prefixed-name + name gnus-message-archive-method))) + (if groups (insert " "))) + (insert "\n")))))) + +(defun gnus-summary-send-draft () + "Enter a mail/post buffer to edit and send the draft." + (interactive) + (gnus-set-global-variables) + (let (buf) + (if (not (setq buf (gnus-request-restore-buffer + (gnus-summary-article-number) gnus-newsgroup-name))) + (error "Couldn't restore the article") + (switch-to-buffer buf) + (when (eq major-mode 'news-reply-mode) + (local-set-key "\C-c\C-c" 'gnus-inews-news)) + ;; Insert the separator. + (goto-char (point-min)) + (search-forward "\n\n") + (forward-char -1) + (insert mail-header-separator) + ;; Configure windows. + (let ((gnus-draft-buffer (current-buffer))) + (gnus-configure-windows 'draft t) + (goto-char (point)))))) + +(gnus-add-shutdown 'gnus-inews-close 'gnus) + +(defun gnus-inews-close () + (setq gnus-inews-sent-ids nil)) + +;;; Allow redefinition of functions. + (gnus-ems-redefine) (provide 'gnus-msg) diff --git a/lisp/gnus-score.el b/lisp/gnus-score.el index 7e3484e2430..c0686ef6903 100644 --- a/lisp/gnus-score.el +++ b/lisp/gnus-score.el @@ -1,6 +1,5 @@ ;;; gnus-score.el --- scoring code for Gnus - -;; Copyright (C) 1995 Free Software Foundation, Inc. +;; Copyright (C) 1995,96 Free Software Foundation, Inc. ;; Author: Per Abrahamsen ;; Lars Magne Ingebrigtsen @@ -28,9 +27,84 @@ ;;; Code: (require 'gnus) +(eval-when-compile (require 'cl)) + +(defvar gnus-global-score-files nil + "*List of global score files and directories. +Set this variable if you want to use people's score files. One entry +for each score file or each score file directory. Gnus will decide +by itself what score files are applicable to which group. + +Say you want to use the single score file +\"/ftp.ifi.uio.no@ftp:/pub/larsi/ding/score/soc.motss.SCORE\" and all +score files in the \"/ftp.some-where:/pub/score\" directory. + + (setq gnus-global-score-files + '(\"/ftp.ifi.uio.no:/pub/larsi/ding/score/soc.motss.SCORE\" + \"/ftp.some-where:/pub/score\"))") + +(defvar gnus-score-file-single-match-alist nil + "*Alist mapping regexps to lists of score files. +Each element of this alist should be of the form + (\"REGEXP\" [ \"SCORE-FILE-1\" ] [ \"SCORE-FILE-2\" ] ... ) + +If the name of a group is matched by REGEXP, the corresponding scorefiles +will be used for that group. +The first match found is used, subsequent matching entries are ignored (to +use multiple matches, see gnus-score-file-multiple-match-alist). + +These score files are loaded in addition to any files returned by +gnus-score-find-score-files-function (which see).") + +(defvar gnus-score-file-multiple-match-alist nil + "*Alist mapping regexps to lists of score files. +Each element of this alist should be of the form + (\"REGEXP\" [ \"SCORE-FILE-1\" ] [ \"SCORE-FILE-2\" ] ... ) + +If the name of a group is matched by REGEXP, the corresponding scorefiles +will be used for that group. +If multiple REGEXPs match a group, the score files corresponding to each +match will be used (for only one match to be used, see +gnus-score-file-single-match-alist). + +These score files are loaded in addition to any files returned by +gnus-score-find-score-files-function (which see).") + +(defvar gnus-score-file-suffix "SCORE" + "*Suffix of the score files.") + +(defvar gnus-adaptive-file-suffix "ADAPT" + "*Suffix of the adaptive score files.") + +(defvar gnus-score-find-score-files-function 'gnus-score-find-bnews + "*Function used to find score files. +The function will be called with the group name as the argument, and +should return a list of score files to apply to that group. The score +files do not actually have to exist. + +Predefined values are: + +gnus-score-find-single: Only apply the group's own score file. +gnus-score-find-hierarchical: Also apply score files from parent groups. +gnus-score-find-bnews: Apply score files whose names matches. + +See the documentation to these functions for more information. + +This variable can also be a list of functions to be called. Each +function should either return a list of score files, or a list of +score alists.") + +(defvar gnus-score-interactive-default-score 1000 + "*Scoring commands will raise/lower the score with this number as the default.") (defvar gnus-score-expiry-days 7 - "*Number of days before unused score file entries are expired.") + "*Number of days before unused score file entries are expired. +If this variable is nil, no score file entries will be expired.") + +(defvar gnus-update-score-entry-dates t + "*In non-nil, update matching score entry dates. +If this variable is nil, then score entries that provide matches +will be expired along with non-matching score entries.") (defvar gnus-orphan-score nil "*All orphans get this score added. Set in the score file.") @@ -50,16 +124,77 @@ (defvar gnus-score-exact-adapt-limit 10 "*Number that says how long a match has to be before using substring matching. When doing adaptive scoring, one normally uses fuzzy or substring -matching. However, if the header one matches is short, the possibility +matching. However, if the header one matches is short, the possibility for false positives is great, so if the length of the match is less than this variable, exact matching will be used. If this variable is nil, exact matching will always be used.") +(defvar gnus-score-uncacheable-files "ADAPT$" + "*All score files that match this regexp will not be cached.") + +(defvar gnus-score-default-header nil + "Default header when entering new scores. + +Should be one of the following symbols. + + a: from + s: subject + b: body + h: head + i: message-id + t: references + x: xref + l: lines + d: date + f: followup + +If nil, the user will be asked for a header.") + +(defvar gnus-score-default-type nil + "Default match type when entering new scores. + +Should be one of the following symbols. + + s: substring + e: exact string + f: fuzzy string + r: regexp string + b: before date + a: at date + n: this date + <: less than number + >: greater than number + =: equal to number + +If nil, the user will be asked for a match type.") + +(defvar gnus-score-default-fold nil + "Use case folding for new score file entries iff not nil.") + +(defvar gnus-score-default-duration nil + "Default duration of effect when entering new scores. + +Should be one of the following symbols. + + t: temporary + p: permanent + i: immediate + +If nil, the user will be asked for a duration.") + +(defvar gnus-score-after-write-file-function nil + "*Function called with the name of the score file just written to disk.") + ;; Internal variables. +(defvar gnus-internal-global-score-files nil) +(defvar gnus-score-file-list nil) + +(defvar gnus-short-name-score-file-cache nil) + (defvar gnus-score-help-winconf nil) (defvar gnus-adaptive-score-alist gnus-default-adaptive-score-alist) (defvar gnus-score-trace nil) @@ -83,31 +218,45 @@ of the last successful match.") (defvar gnus-score-cache nil) (defvar gnus-scores-articles nil) -(defvar gnus-header-index nil) (defvar gnus-score-index nil) -(eval-and-compile - (autoload 'gnus-uu-ctl-map "gnus-uu" nil nil 'keymap) - (autoload 'appt-select-lowest-window "appt.el")) - -;;; Summary mode score maps. -(defvar gnus-summary-score-map nil) +(defconst gnus-header-index + ;; Name to index alist. + '(("number" 0 gnus-score-integer) + ("subject" 1 gnus-score-string) + ("from" 2 gnus-score-string) + ("date" 3 gnus-score-date) + ("message-id" 4 gnus-score-string) + ("references" 5 gnus-score-string) + ("chars" 6 gnus-score-integer) + ("lines" 7 gnus-score-integer) + ("xref" 8 gnus-score-string) + ("head" -1 gnus-score-body) + ("body" -1 gnus-score-body) + ("all" -1 gnus-score-body) + ("followup" 2 gnus-score-followup) + ("thread" 5 gnus-score-thread))) -(define-prefix-command 'gnus-summary-score-map) -(define-key gnus-summary-mode-map "V" 'gnus-summary-score-map) -(define-key gnus-summary-score-map "s" 'gnus-summary-set-score) -(define-key gnus-summary-score-map "a" 'gnus-summary-score-entry) -(define-key gnus-summary-score-map "S" 'gnus-summary-current-score) -(define-key gnus-summary-score-map "c" 'gnus-score-change-score-file) -(define-key gnus-summary-score-map "m" 'gnus-score-set-mark-below) -(define-key gnus-summary-score-map "x" 'gnus-score-set-expunge-below) -(define-key gnus-summary-score-map "e" 'gnus-score-edit-alist) -(define-key gnus-summary-score-map "f" 'gnus-score-edit-file) -(define-key gnus-summary-score-map "t" 'gnus-score-find-trace) -(define-key gnus-summary-score-map "C" 'gnus-score-customize) +(eval-and-compile + (autoload 'gnus-uu-ctl-map "gnus-uu" nil nil 'keymap)) +;;; Summary mode score maps. +(gnus-define-keys + (gnus-summary-score-map "V" gnus-summary-mode-map) + "s" gnus-summary-set-score + "a" gnus-summary-score-entry + "S" gnus-summary-current-score + "c" gnus-score-change-score-file + "m" gnus-score-set-mark-below + "x" gnus-score-set-expunge-below + "R" gnus-summary-rescore + "e" gnus-score-edit-current-scores + "f" gnus-score-edit-file + "F" gnus-score-flush-cache + "t" gnus-score-find-trace + "C" gnus-score-customize) ;; Summary score file commands @@ -122,6 +271,21 @@ used as score." (interactive "P") (gnus-summary-increase-score (- (gnus-score-default score)))) +(defvar gnus-score-default-header nil + "*The default header to score on when entering a score rule interactively.") + +(defvar gnus-score-default-type nil + "*The default score type to use when entering a score rule interactively.") + +(defvar gnus-score-default-duration nil + "*The default score duration to use on when entering a score rule interactively.") + +(defun gnus-score-kill-help-buffer () + (when (get-buffer "*Score Help*") + (kill-buffer "*Score Help*") + (and gnus-score-help-winconf + (set-window-configuration gnus-score-help-winconf)))) + (defun gnus-summary-increase-score (&optional score) "Make a score entry based on the current article. The user will be prompted for header to score on, match type, @@ -138,18 +302,19 @@ used as score." (?b "body" "" nil body-string) (?h "head" "" nil body-string) (?i "message-id" nil t string) - (?t "references" "message-id" t string) + (?t "references" "message-id" nil string) (?x "xref" nil nil string) (?l "lines" nil nil number) (?d "date" nil nil date) - (?f "followup" nil nil string))) + (?f "followup" nil nil string) + (?T "thread" nil nil string))) (char-to-type '((?s s "substring" string) (?e e "exact string" string) (?f f "fuzzy string" string) (?r r "regexp string" string) - (?s s "substring" body-string) - (?r s "regexp string" body-string) + (?z s "substring" body-string) + (?p s "regexp string" body-string) (?b before "before date" date) (?a at "at date" date) (?n now "this date" date) @@ -160,124 +325,126 @@ used as score." (list (list ?t (current-time-string) "temporary") '(?p perm "permanent") '(?i now "immediate"))) (mimic gnus-score-mimic-keymap) - hchar entry temporary tchar pchar end type) - ;; First we read the header to score. - (while (not hchar) - (if mimic - (progn - (sit-for 1) - (message "%c-" prefix)) - (message "%s header (%s?): " (if increase "Increase" "Lower") - (mapconcat (lambda (s) (char-to-string (car s))) - char-to-header ""))) - (setq hchar (read-char)) - (if (not (or (= hchar ??) (= hchar ?\C-h))) - () - (setq hchar nil) - (gnus-score-insert-help "Match on header" char-to-header 1))) - - (and (get-buffer "*Score Help*") - (progn - (kill-buffer "*Score Help*") - (and gnus-score-help-winconf - (set-window-configuration gnus-score-help-winconf)))) - - (or (setq entry (assq (downcase hchar) char-to-header)) - (progn - (ding) - (setq end t) - (if mimic (message "%c %c" prefix hchar) (message "")))) - (if (or end (/= (downcase hchar) hchar)) + (hchar (and gnus-score-default-header + (aref (symbol-name gnus-score-default-header) 0))) + (tchar (and gnus-score-default-type + (aref (symbol-name gnus-score-default-type) 0))) + (pchar (and gnus-score-default-duration + (aref (symbol-name gnus-score-default-duration) 0))) + entry temporary type match) + + (unwind-protect (progn - ;; This was a majuscle, so we end reading and set the defaults. - (if mimic (message "%c %c" prefix hchar) (message "")) - (setq type nil - temporary (current-time-string))) - - ;; We continue reading - the type. - (while (not tchar) - (if mimic - (progn - (sit-for 1) - (message "%c %c-" prefix hchar)) - (message "%s header '%s' with match type (%s?): " - (if increase "Increase" "Lower") - (nth 1 entry) - (mapconcat (lambda (s) - (if (eq (nth 4 entry) - (nth 3 s)) - (char-to-string (car s)) - "")) - char-to-type ""))) - (setq tchar (read-char)) - (if (not (or (= tchar ??) (= tchar ?\C-h))) - () - (setq tchar nil) - (gnus-score-insert-help "Match type" char-to-type 2))) - - (and (get-buffer "*Score Help*") - (progn - (and gnus-score-help-winconf - (set-window-configuration gnus-score-help-winconf)) - (kill-buffer "*Score Help*"))) - - (or (setq type (nth 1 (assq (downcase tchar) char-to-type))) - (progn - (ding) + + ;; First we read the header to score. + (while (not hchar) + (if mimic + (progn + (sit-for 1) + (message "%c-" prefix)) + (message "%s header (%s?): " (if increase "Increase" "Lower") + (mapconcat (lambda (s) (char-to-string (car s))) + char-to-header ""))) + (setq hchar (read-char)) + (when (or (= hchar ??) (= hchar ?\C-h)) + (setq hchar nil) + (gnus-score-insert-help "Match on header" char-to-header 1))) + + (gnus-score-kill-help-buffer) + (unless (setq entry (assq (downcase hchar) char-to-header)) + (if mimic (error "%c %c" prefix hchar) (error ""))) + + (when (/= (downcase hchar) hchar) + ;; This was a majuscle, so we end reading and set the defaults. (if mimic (message "%c %c" prefix hchar) (message "")) - (setq end t))) - (if (or end (/= (downcase tchar) tchar)) - (progn + (setq tchar (or tchar ?s) + pchar (or pchar ?t))) + + ;; We continue reading - the type. + (while (not tchar) + (if mimic + (progn + (sit-for 1) (message "%c %c-" prefix hchar)) + (message "%s header '%s' with match type (%s?): " + (if increase "Increase" "Lower") + (nth 1 entry) + (mapconcat (lambda (s) + (if (eq (nth 4 entry) + (nth 3 s)) + (char-to-string (car s)) + "")) + char-to-type ""))) + (setq tchar (read-char)) + (when (or (= tchar ??) (= tchar ?\C-h)) + (setq tchar nil) + (gnus-score-insert-help + "Match type" + (delq nil + (mapcar (lambda (s) + (if (eq (nth 4 entry) + (nth 3 s)) + s nil)) + char-to-type )) + 2))) + + (gnus-score-kill-help-buffer) + (unless (setq type (nth 1 (assq (downcase tchar) char-to-type))) + (if mimic (error "%c %c" prefix hchar) (error ""))) + + (when (/= (downcase tchar) tchar) ;; It was a majuscle, so we end reading and the the default. (if mimic (message "%c %c %c" prefix hchar tchar) (message "")) - (setq temporary (current-time-string))) - - ;; We continue reading. - (while (not pchar) - (if mimic - (progn - (sit-for 1) - (message "%c %c %c-" prefix hchar tchar)) - (message "%s permanence (%s?): " (if increase "Increase" "Lower") - (mapconcat (lambda (s) (char-to-string (car s))) - char-to-perm ""))) - (setq pchar (read-char)) - (if (not (or (= pchar ??) (= pchar ?\C-h))) - () - (setq pchar nil) - (gnus-score-insert-help "Match permanence" char-to-perm 2))) - - (and (get-buffer "*Score Help*") - (progn - (and gnus-score-help-winconf - (set-window-configuration gnus-score-help-winconf)) - (kill-buffer "*Score Help*"))) - - (if mimic (message "%c %c %c" prefix hchar tchar pchar) - (message "")) - (if (setq temporary (nth 1 (assq pchar char-to-perm))) - () - (ding) - (setq end t) - (if mimic - (message "%c %c %c %c" prefix hchar tchar pchar) - (message ""))))) + (setq pchar (or pchar ?p))) + + ;; We continue reading. + (while (not pchar) + (if mimic + (progn + (sit-for 1) (message "%c %c %c-" prefix hchar tchar)) + (message "%s permanence (%s?): " (if increase "Increase" "Lower") + (mapconcat (lambda (s) (char-to-string (car s))) + char-to-perm ""))) + (setq pchar (read-char)) + (when (or (= pchar ??) (= pchar ?\C-h)) + (setq pchar nil) + (gnus-score-insert-help "Match permanence" char-to-perm 2))) + + (gnus-score-kill-help-buffer) + (if mimic (message "%c %c %c" prefix hchar tchar pchar) + (message "")) + (unless (setq temporary (cadr (assq pchar char-to-perm))) + (if mimic + (error "%c %c %c %c" prefix hchar tchar pchar) + (error "")))) + ;; Always kill the score help buffer. + (gnus-score-kill-help-buffer)) ;; We have all the data, so we enter this score. - (if end - () - (gnus-summary-score-entry - (nth 1 entry) ; Header - (if (string= (nth 2 entry) "") "" - (gnus-summary-header (or (nth 2 entry) (nth 1 entry)))) ; Match - type ; Type - (if (eq 's score) nil score) ; Score - (if (eq 'perm temporary) ; Temp - nil - temporary) - (not (nth 3 entry))) ; Prompt - ))) + (setq match (if (string= (nth 2 entry) "") "" + (gnus-summary-header (or (nth 2 entry) (nth 1 entry))))) + + ;; Modify the match, perhaps. + (cond + ((equal (nth 1 entry) "xref") + (when (string-match "^Xref: *" match) + (setq match (substring match (match-end 0)))) + (when (string-match "^[^:]* +" match) + (setq match (substring match (match-end 0)))))) + + (when (memq type '(r R regexp Regexp)) + (setq match (regexp-quote match))) + + (gnus-summary-score-entry + (nth 1 entry) ; Header + match ; Match + type ; Type + (if (eq 's score) nil score) ; Score + (if (eq 'perm temporary) ; Temp + nil + temporary) + (not (nth 3 entry))) ; Prompt + )) (defun gnus-score-insert-help (string alist idx) (setq gnus-score-help-winconf (current-window-configuration)) @@ -298,8 +465,8 @@ used as score." (setq max n)) (setq list (cdr list))) (setq max (+ max 4)) ; %c, `:', SPACE, a SPACE at end - (setq n (/ (window-width) max)) ; items per line - (setq width (/ (window-width) n)) ; width of each item + (setq n (/ (1- (window-width)) max)) ; items per line + (setq width (/ (1- (window-width)) n)) ; width of each item ;; insert `n' items, each in a field of width `width' (while alist (if (< i n) @@ -309,14 +476,15 @@ used as score." (insert "\n")) (setq pad (- width 3)) (setq format (concat "%c: %-" (int-to-string pad) "s")) - (insert (format format (car (car alist)) (nth idx (car alist)))) + (insert (format format (caar alist) (nth idx (car alist)))) (setq alist (cdr alist)) (setq i (1+ i)))) ;; display ourselves in a small window at the bottom - (appt-select-lowest-window) + (gnus-appt-select-lowest-window) (split-window) (pop-to-buffer "*Score Help*") - (shrink-window-if-larger-than-buffer) + (let ((window-min-height 1)) + (shrink-window-if-larger-than-buffer)) (select-window (get-buffer-window gnus-summary-buffer)))) (defun gnus-summary-header (header &optional no-err) @@ -324,7 +492,7 @@ used as score." (let ((article (gnus-summary-article-number)) headers) (if article - (if (and (setq headers (gnus-get-header-by-number article)) + (if (and (setq headers (gnus-summary-article-header article)) (vectorp headers)) (aref headers (nth 1 (assoc header gnus-header-index))) (if no-err @@ -334,6 +502,23 @@ used as score." (error "No article on current line") nil)))) +(defun gnus-newsgroup-score-alist () + (or + (let ((param-file (gnus-group-get-parameter + gnus-newsgroup-name 'score-file))) + (when param-file + (gnus-score-load param-file))) + (gnus-score-load + (gnus-score-file-name gnus-newsgroup-name))) + gnus-score-alist) + +(defsubst gnus-score-get (symbol &optional alist) + ;; Get SYMBOL's definition in ALIST. + (cdr (assoc symbol + (or alist + gnus-score-alist + (gnus-newsgroup-score-alist))))) + (defun gnus-summary-score-entry (header match type score date &optional prompt silent) "Enter score file entry. @@ -366,7 +551,8 @@ If optional argument `SILENT' is nil, show effect of score entry." ((eq type 'f) (setq match (gnus-simplify-subject-fuzzy match)))) (let ((score (gnus-score-default score)) - (header (downcase header))) + (header (downcase header)) + new) (and prompt (setq match (read-string (format "Match %s on %s, %s: " (cond ((eq date 'now) @@ -379,30 +565,23 @@ If optional argument `SILENT' is nil, show effect of score entry." (if (numberp match) (int-to-string match) match)))) - (and (>= (nth 1 (assoc header gnus-header-index)) 0) - (eq (nth 2 (assoc header gnus-header-index)) 'gnus-score-string) - (not silent) - (gnus-summary-score-effect header match type score)) ;; If this is an integer comparison, we transform from string to int. (and (eq (nth 2 (assoc header gnus-header-index)) 'gnus-score-integer) (setq match (string-to-int match))) - (if (eq date 'now) - () - (and (= score gnus-score-interactive-default-score) + (unless (eq date 'now) + ;; Add the score entry to the score file. + (when (= score gnus-score-interactive-default-score) (setq score nil)) - (let ((new (cond - (type - (list match score (and date (gnus-day-number date)) type)) - (date - (list match score (gnus-day-number date))) - (score - (list match score)) - (t - (list match)))) - (old (gnus-score-get header)) + (let ((old (gnus-score-get header)) elem) + (setq new + (cond + (type (list match score (and date (gnus-day-number date)) type)) + (date (list match score (gnus-day-number date))) + (score (list match score)) + (t (list match)))) ;; We see whether we can collapse some score entries. ;; This isn't quite correct, because there may be more elements ;; later on with the same key that have matching elems... Hm. @@ -417,8 +596,19 @@ If optional argument `SILENT' is nil, show effect of score entry." (or (nth 1 new) gnus-score-interactive-default-score))) ;; Nope, we have to add a new elem. - (gnus-score-set header (if old (cons new old) (list new))))) - (gnus-score-set 'touched '(t))))) + (gnus-score-set header (if old (cons new old) (list new)))) + (gnus-score-set 'touched '(t)))) + + ;; Score the current buffer. + (unless silent + (if (and (>= (nth 1 (assoc header gnus-header-index)) 0) + (eq (nth 2 (assoc header gnus-header-index)) + 'gnus-score-string)) + (gnus-summary-score-effect header match type score) + (gnus-summary-rescore))) + + ;; Return the new scoring rule. + new)) (defun gnus-summary-score-effect (header match type score) "Simulate the effect of a score file entry. @@ -439,8 +629,12 @@ SCORE is the score to add." (goto-char (point-min)) (let ((regexp (cond ((eq type 'f) (gnus-simplify-subject-fuzzy match)) - (type match) - (t (concat "\\`.*" (regexp-quote match) ".*\\'"))))) + ((eq type 'r) + match) + ((eq type 'e) + (concat "\\`" (regexp-quote match) "\\'")) + (t + (regexp-quote match))))) (while (not (eobp)) (let ((content (gnus-summary-header header 'noerr)) (case-fold-search t)) @@ -486,7 +680,30 @@ SCORE is the score to add." (gnus-score-set 'mark (list score)) (gnus-score-set 'touched '(t)) (setq gnus-summary-mark-below score) - (gnus-summary-update-lines)) + (gnus-score-update-lines)) + +(defun gnus-score-update-lines () + "Update all lines in the summary buffer." + (save-excursion + (goto-char (point-min)) + (while (not (eobp)) + (gnus-summary-update-line) + (forward-line 1)))) + +(defun gnus-score-update-all-lines () + "Update all lines in the summary buffer, even the hidden ones." + (save-excursion + (goto-char (point-min)) + (let (hidden) + (while (not (eobp)) + (when (gnus-summary-show-thread) + (push (point) hidden)) + (gnus-summary-update-line) + (forward-line 1)) + ;; Re-hide the hidden threads. + (while hidden + (goto-char (pop hidden)) + (gnus-summary-hide-thread))))) (defun gnus-score-set-expunge-below (score) "Automatically expunge articles with score below SCORE." @@ -497,14 +714,42 @@ SCORE is the score to add." (gnus-score-set 'expunge (list score)) (gnus-score-set 'touched '(t))) +(defun gnus-score-followup-article (&optional score) + "Add SCORE to all followups to the article in the current buffer." + (interactive "P") + (setq score (gnus-score-default score)) + (when (gnus-buffer-live-p gnus-summary-buffer) + (save-excursion + (set-buffer gnus-summary-buffer) + (save-restriction + (goto-char (point-min)) + (let ((id (mail-fetch-field "message-id"))) + (when id + (gnus-summary-score-entry + "references" (concat id "[ \t]*$") 'r + score (current-time-string) nil t))))))) + +(defun gnus-score-followup-thread (&optional score) + "Add SCORE to all later articles in the thread the current buffer is part of." + (interactive "P") + (setq score (gnus-score-default score)) + (when (gnus-buffer-live-p gnus-summary-buffer) + (save-excursion + (set-buffer gnus-summary-buffer) + (save-restriction + (goto-char (point-min)) + (let ((id (mail-fetch-field "message-id"))) + (when id + (gnus-summary-score-entry + "references" id 's + score (current-time-string)))))))) + (defun gnus-score-set (symbol value &optional alist) ;; Set SYMBOL to VALUE in ALIST. (let* ((alist (or alist gnus-score-alist - (progn - (gnus-score-load (gnus-score-file-name gnus-newsgroup-name)) - gnus-score-alist))) + (gnus-newsgroup-score-alist))) (entry (assoc symbol alist))) (cond ((gnus-score-get 'read-only alist) ;; This is a read-only score file, so we do nothing. @@ -517,62 +762,89 @@ SCORE is the score to add." (setcdr alist (cons (cons symbol value) (cdr alist))))))) -(defun gnus-score-get (symbol &optional alist) - ;; Get SYMBOL's definition in ALIST. - (cdr (assoc symbol - (or alist - gnus-score-alist - (progn - (gnus-score-load - (gnus-score-file-name gnus-newsgroup-name)) - gnus-score-alist))))) +(defun gnus-summary-raise-score (n) + "Raise the score of the current article by N." + (interactive "p") + (gnus-set-global-variables) + (gnus-summary-set-score (+ (gnus-summary-article-score) + (or n gnus-score-interactive-default-score )))) + +(defun gnus-summary-set-score (n) + "Set the score of the current article to N." + (interactive "p") + (gnus-set-global-variables) + (save-excursion + (gnus-summary-show-thread) + (let ((buffer-read-only nil)) + ;; Set score. + (gnus-summary-update-mark + (if (= n (or gnus-summary-default-score 0)) ? + (if (< n (or gnus-summary-default-score 0)) + gnus-score-below-mark gnus-score-over-mark)) 'score)) + (let* ((article (gnus-summary-article-number)) + (score (assq article gnus-newsgroup-scored))) + (if score (setcdr score n) + (setq gnus-newsgroup-scored + (cons (cons article n) gnus-newsgroup-scored)))) + (gnus-summary-update-line))) + +(defun gnus-summary-current-score () + "Return the score of the current article." + (interactive) + (gnus-set-global-variables) + (gnus-message 1 "%s" (gnus-summary-article-score))) (defun gnus-score-change-score-file (file) "Change current score alist." (interactive - (list (read-file-name "Edit score file: " gnus-kill-files-directory))) + (list (read-file-name "Change to score file: " gnus-kill-files-directory))) (gnus-score-load-file file) (gnus-set-mode-line 'summary)) -(defun gnus-score-edit-alist (file) +(defvar gnus-score-edit-exit-function) +(defun gnus-score-edit-current-scores (file) "Edit the current score alist." (interactive (list gnus-current-score-file)) (let ((winconf (current-window-configuration))) (and (buffer-name gnus-summary-buffer) (gnus-score-save)) + (gnus-make-directory (file-name-directory file)) (setq gnus-score-edit-buffer (find-file-noselect file)) (gnus-configure-windows 'edit-score) (gnus-score-mode) + (setq gnus-score-edit-exit-function 'gnus-score-edit-done) (make-local-variable 'gnus-prev-winconf) (setq gnus-prev-winconf winconf)) (gnus-message 4 (substitute-command-keys - "\\\\[gnus-score-edit-done] to save edits"))) + "\\\\[gnus-score-edit-exit] to save edits"))) (defun gnus-score-edit-file (file) "Edit a score file." (interactive (list (read-file-name "Edit score file: " gnus-kill-files-directory))) + (gnus-make-directory (file-name-directory file)) (and (buffer-name gnus-summary-buffer) (gnus-score-save)) (let ((winconf (current-window-configuration))) (setq gnus-score-edit-buffer (find-file-noselect file)) (gnus-configure-windows 'edit-score) (gnus-score-mode) + (setq gnus-score-edit-exit-function 'gnus-score-edit-done) (make-local-variable 'gnus-prev-winconf) (setq gnus-prev-winconf winconf)) (gnus-message 4 (substitute-command-keys - "\\\\[gnus-score-edit-done] to save edits"))) + "\\\\[gnus-score-edit-exit] to save edits"))) (defun gnus-score-load-file (file) ;; Load score file FILE. Returns a list a retrieved score-alists. - (setq gnus-kill-files-directory (or gnus-kill-files-directory "~/News/")) (let* ((file (expand-file-name (or (and (string-match (concat "^" (expand-file-name gnus-kill-files-directory)) (expand-file-name file)) file) - (concat gnus-kill-files-directory file)))) + (concat (file-name-as-directory gnus-kill-files-directory) + file)))) (cached (assoc file gnus-score-cache)) (global (member file gnus-internal-global-score-files)) lists alist) @@ -589,13 +861,20 @@ SCORE is the score to add." (and global (not (assq 'read-only alist)) (setq alist (cons (list 'read-only t) alist))) - ;; Update cache. (setq gnus-score-cache (cons (cons file alist) gnus-score-cache))) - ;; If there are actual scores in the alist, we add it to the - ;; return value of this function. - (if (memq t (mapcar (lambda (e) (stringp (car e))) alist)) - (setq lists (list alist))) + (let ((a alist) + found) + (while a + ;; Downcase all header names. + (when (stringp (caar a)) + (setcar (car a) (downcase (caar a))) + (setq found t)) + (pop a)) + ;; If there are actual scores in the alist, we add it to the + ;; return value of this function. + (when found + (setq lists (list alist)))) ;; Treat the other possible atoms in the score alist. (let ((mark (car (gnus-score-get 'mark alist))) (expunge (car (gnus-score-get 'expunge alist))) @@ -604,6 +883,9 @@ SCORE is the score to add." (exclude-files (gnus-score-get 'exclude-files alist)) (orphan (car (gnus-score-get 'orphan alist))) (adapt (gnus-score-get 'adapt alist)) + (thread-mark-and-expunge + (car (gnus-score-get 'thread-mark-and-expunge alist))) + (adapt-file (car (gnus-score-get 'adapt-file alist))) (local (gnus-score-get 'local alist)) (eval (car (gnus-score-get 'eval alist)))) ;; We do not respect eval and files atoms from global score @@ -612,7 +894,8 @@ SCORE is the score to add." (setq lists (apply 'append lists (mapcar (lambda (file) (gnus-score-load-file file)) - files)))) + (if adapt-file (cons adapt-file files) + files))))) (and eval (not global) (eval eval)) ;; We then expand any exclude-file directives. (setq gnus-scores-exclude-files @@ -627,10 +910,10 @@ SCORE is the score to add." (set-buffer gnus-summary-buffer) (while local (and (consp (car local)) - (symbolp (car (car local))) + (symbolp (caar local)) (progn - (make-local-variable (car (car local))) - (set (car (car local)) (nth 1 (car local))))) + (make-local-variable (caar local)) + (set (caar local) (nth 1 (car local))))) (setq local (cdr local))))) (if orphan (setq gnus-orphan-score orphan)) (setq gnus-adaptive-score-alist @@ -645,10 +928,14 @@ SCORE is the score to add." (t ;;(setq gnus-newsgroup-adaptive gnus-use-adaptive-scoring) gnus-default-adaptive-score-alist))) + (setq gnus-thread-expunge-below + (or thread-mark-and-expunge gnus-thread-expunge-below)) (setq gnus-summary-mark-below (or mark mark-and-expunge gnus-summary-mark-below)) (setq gnus-summary-expunge-below - (or expunge mark-and-expunge gnus-summary-expunge-below))) + (or expunge mark-and-expunge gnus-summary-expunge-below)) + (setq gnus-newsgroup-adaptive-score-file + (or adapt-file gnus-newsgroup-adaptive-score-file))) (setq gnus-current-score-file file) (setq gnus-score-alist alist) lists)) @@ -671,31 +958,33 @@ SCORE is the score to add." (defun gnus-score-load-score-alist (file) (let (alist) - (if (file-readable-p file) - (progn - (save-excursion - (gnus-set-work-buffer) - (insert-file-contents file) - (goto-char (point-min)) - ;; Only do the loading if the score file isn't empty. - (if (save-excursion (re-search-forward "[()0-9a-zA-Z]" nil t)) - (setq alist - (condition-case () - (read (current-buffer)) - (error - (progn - (gnus-message 3 "Problem with score file %s" file) - (ding) - (sit-for 2) - nil)))))) - (if (eq (car alist) 'setq) - (setq gnus-score-alist (gnus-score-transform-old-to-new alist)) - (setq gnus-score-alist alist)) - (setq gnus-score-alist - (gnus-score-check-syntax gnus-score-alist file))) - (setq gnus-score-alist nil)))) + (if (not (file-readable-p file)) + (setq gnus-score-alist nil) + (save-excursion + (gnus-set-work-buffer) + (insert-file-contents file) + (goto-char (point-min)) + ;; Only do the loading if the score file isn't empty. + (when (save-excursion (re-search-forward "[()0-9a-zA-Z]" nil t)) + (setq alist + (condition-case () + (read (current-buffer)) + (error + (progn + (gnus-message 3 "Problem with score file %s" file) + (ding) + (sit-for 2) + nil)))))) + (if (eq (car alist) 'setq) + ;; This is an old-style score file. + (setq gnus-score-alist (gnus-score-transform-old-to-new alist)) + (setq gnus-score-alist alist)) + ;; Check the syntax of the score file. + (setq gnus-score-alist + (gnus-score-check-syntax gnus-score-alist file))))) (defun gnus-score-check-syntax (alist file) + "Check the syntax of the score ALIST." (cond ((null alist) nil) @@ -705,20 +994,41 @@ SCORE is the score to add." nil) (t (let ((a alist) - err) + sr err s type) (while (and a (not err)) - (cond ((not (listp (car a))) - (gnus-message 3 "Illegal score element %s in %s" (car a) file) - (setq err t)) - ((and (stringp (car (car a))) - (not (listp (nth 1 (car a))))) - (gnus-message 3 "Illegal header match %s in %s" (nth 1 (car a)) file) - (setq err t)) - (t - (setq a (cdr a))))) + (setq + err + (cond + ((not (listp (car a))) + (format "Illegal score element %s in %s" (car a) file)) + ((stringp (caar a)) + (cond + ((not (listp (setq sr (cdar a)))) + (format "Illegal header match %s in %s" (nth 1 (car a)) file)) + (t + (setq type (caar a)) + (while (and sr (not err)) + (setq s (pop sr)) + (setq + err + (cond + ((if (member (downcase type) '("lines" "chars")) + (not (numberp (car s))) + (not (stringp (car s)))) + (format "Illegal match %s in %s" (car s) file)) + ((and (cadr s) (not (integerp (cadr s)))) + (format "Non-integer score %s in %s" (cadr s) file)) + ((and (caddr s) (not (integerp (caddr s)))) + (format "Non-integer date %s in %s" (caddr s) file)) + ((and (cadddr s) (not (symbolp (cadddr s)))) + (format "Non-symbol match type %s in %s" (cadddr s) file))))) + err))))) + (setq a (cdr a))) (if err (progn (ding) + (gnus-message 3 err) + (sit-for 2) nil) alist))))) @@ -734,7 +1044,7 @@ SCORE is the score to add." (setq out (cons entry out)) (while scor (setcar scor - (list (car (car scor)) (nth 2 (car scor)) + (list (caar scor) (nth 2 (car scor)) (and (nth 3 (car scor)) (gnus-day-number (nth 3 (car scor)))) (if (nth 1 (car scor)) 'r 's))) @@ -767,11 +1077,13 @@ SCORE is the score to add." (setq score (setcdr entry (delq (assq 'touched score) score))) (erase-buffer) (let (emacs-lisp-mode-hook) - (if (string-match (concat gnus-adaptive-file-suffix "$") file) + (if (string-match + (concat (regexp-quote gnus-adaptive-file-suffix) + "$") file) ;; This is an adaptive score file, so we do not run ;; it through `pp'. These files can get huge, and ;; are not meant to be edited by human hands. - (insert (format "%S" score)) + (prin1 score (current-buffer)) ;; This is a normal score file, so we print it very ;; prettily. (pp score (current-buffer)))) @@ -781,14 +1093,18 @@ SCORE is the score to add." (if (zerop (buffer-size)) (delete-file file) ;; There are scores, so we write the file. - (and (file-writable-p file) - (write-region (point-min) (point-max) - file nil 'silent))))))) + (when (file-writable-p file) + (write-region (point-min) (point-max) file nil 'silent) + (and gnus-score-after-write-file-function + (funcall gnus-score-after-write-file-function file))))) + (and gnus-score-uncacheable-files + (string-match gnus-score-uncacheable-files file) + (gnus-score-remove-from-cache file))))) (kill-buffer (current-buffer))))) (defun gnus-score-headers (score-files &optional trace) ;; Score `gnus-newsgroup-headers'. - (let (scores) + (let (scores news) ;; PLM: probably this is not the best place to clear orphan-score (setq gnus-orphan-score nil) (setq gnus-scores-articles nil) @@ -804,8 +1120,7 @@ SCORE is the score to add." (setq scores (nconc (car score-files) scores))) (setq score-files (cdr score-files))) ;; Prune the score files that are to be excluded, if any. - (if (not gnus-scores-exclude-files) - () + (when gnus-scores-exclude-files (let ((s scores) c) (while s @@ -813,67 +1128,69 @@ SCORE is the score to add." (member (car c) gnus-scores-exclude-files) (setq scores (delq (car s) scores))) (setq s (cdr s))))) - (if (not (and gnus-summary-default-score - scores - (> (length gnus-newsgroup-headers) - (length gnus-newsgroup-scored)))) - () - (let* ((entries gnus-header-index) - (now (gnus-day-number (current-time-string))) - (expire (- now gnus-score-expiry-days)) - (headers gnus-newsgroup-headers) - (current-score-file gnus-current-score-file) - entry header) - (gnus-message 5 "Scoring...") - ;; Create articles, an alist of the form `(HEADER . SCORE)'. - (while headers - (setq header (car headers) - headers (cdr headers)) - ;; WARNING: The assq makes the function O(N*S) while it could - ;; be written as O(N+S), where N is (length gnus-newsgroup-headers) - ;; and S is (length gnus-newsgroup-scored). - (or (assq (mail-header-number header) gnus-newsgroup-scored) - (setq gnus-scores-articles ;Total of 2 * N cons-cells used. - (cons (cons header (or gnus-summary-default-score 0)) - gnus-scores-articles)))) + (setq news scores) + ;; Do the scoring. + (while news + (setq scores news + news nil) + (when (and gnus-summary-default-score + scores) + (let* ((entries gnus-header-index) + (now (gnus-day-number (current-time-string))) + (expire (and gnus-score-expiry-days + (- now gnus-score-expiry-days))) + (headers gnus-newsgroup-headers) + (current-score-file gnus-current-score-file) + entry header new) + (gnus-message 5 "Scoring...") + ;; Create articles, an alist of the form `(HEADER . SCORE)'. + (while (setq header (pop headers)) + ;; WARNING: The assq makes the function O(N*S) while it could + ;; be written as O(N+S), where N is (length gnus-newsgroup-headers) + ;; and S is (length gnus-newsgroup-scored). + (or (assq (mail-header-number header) gnus-newsgroup-scored) + (setq gnus-scores-articles ;Total of 2 * N cons-cells used. + (cons (cons header (or gnus-summary-default-score 0)) + gnus-scores-articles)))) - (save-excursion - (set-buffer (get-buffer-create "*Headers*")) - (buffer-disable-undo (current-buffer)) - - ;; Set the global variant of this variable. - (setq gnus-current-score-file current-score-file) - ;; score orphans - (if gnus-orphan-score - (progn - (setq gnus-score-index - (nth 1 (assoc "references" gnus-header-index))) - (gnus-score-orphans gnus-orphan-score))) - ;; Run each header through the score process. - (while entries - (setq entry (car entries) - header (nth 0 entry) - entries (cdr entries)) - (setq gnus-score-index (nth 1 (assoc header gnus-header-index))) - (if (< 0 (apply 'max (mapcar - (lambda (score) - (length (gnus-score-get header score))) - scores))) - (funcall (nth 2 entry) scores header now expire trace))) - ;; Remove the buffer. - (kill-buffer (current-buffer))) - - ;; Add articles to `gnus-newsgroup-scored'. - (while gnus-scores-articles - (or (= gnus-summary-default-score (cdr (car gnus-scores-articles))) - (setq gnus-newsgroup-scored - (cons (cons (mail-header-number - (car (car gnus-scores-articles))) - (cdr (car gnus-scores-articles))) - gnus-newsgroup-scored))) - (setq gnus-scores-articles (cdr gnus-scores-articles))) - - (gnus-message 5 "Scoring...done"))))) + (save-excursion + (set-buffer (get-buffer-create "*Headers*")) + (buffer-disable-undo (current-buffer)) + + ;; Set the global variant of this variable. + (setq gnus-current-score-file current-score-file) + ;; score orphans + (when gnus-orphan-score + (setq gnus-score-index + (nth 1 (assoc "references" gnus-header-index))) + (gnus-score-orphans gnus-orphan-score)) + ;; Run each header through the score process. + (while entries + (setq entry (pop entries) + header (nth 0 entry) + gnus-score-index (nth 1 (assoc header gnus-header-index))) + (when (< 0 (apply 'max (mapcar + (lambda (score) + (length (gnus-score-get header score))) + scores))) + ;; Call the scoring function for this type of "header". + (when (setq new (funcall (nth 2 entry) scores header + now expire trace)) + (push new news)))) + ;; Remove the buffer. + (kill-buffer (current-buffer))) + + ;; Add articles to `gnus-newsgroup-scored'. + (while gnus-scores-articles + (or (= gnus-summary-default-score (cdar gnus-scores-articles)) + (setq gnus-newsgroup-scored + (cons (cons (mail-header-number + (caar gnus-scores-articles)) + (cdar gnus-scores-articles)) + gnus-newsgroup-scored))) + (setq gnus-scores-articles (cdr gnus-scores-articles))) + + (gnus-message 5 "Scoring...done")))))) (defun gnus-get-new-thread-ids (articles) @@ -975,25 +1292,29 @@ SCORE is the score to add." ;; time than one would gain. (while articles (and (funcall match-func - (or (aref (car (car articles)) gnus-score-index) 0) + (or (aref (caar articles) gnus-score-index) 0) match) (progn (and trace (setq gnus-score-trace - (cons (cons (car (car articles)) kill) - gnus-score-trace))) + (cons + (cons + (car-safe (rassq alist gnus-score-cache)) + kill) + gnus-score-trace))) (setq found t) - (setcdr (car articles) (+ score (cdr (car articles)))))) + (setcdr (car articles) (+ score (cdar articles))))) (setq articles (cdr articles))) ;; Update expire date (cond ((null date)) ;Permanent entry. - (found ;Match, update date. + ((and found gnus-update-score-entry-dates) ;Match, update date. (gnus-score-set 'touched '(t) alist) (setcar (nthcdr 2 kill) now)) - ((< date expire) ;Old entry, remove. + ((and expire (< date expire)) ;Old entry, remove. (gnus-score-set 'touched '(t) alist) (setcdr entries (cdr rest)) (setq rest entries))) - (setq entries rest)))))) + (setq entries rest))))) + nil) (defun gnus-score-date (scores header now expire &optional trace) (let ((gnus-score-index (nth 1 (assoc header gnus-header-index))) @@ -1026,130 +1347,151 @@ SCORE is the score to add." ;; time than one would gain. (while articles (and - (setq l (aref (car (car articles)) gnus-score-index)) + (setq l (aref (caar articles) gnus-score-index)) (funcall match-func match (timezone-make-date-sortable l)) (progn (and trace (setq gnus-score-trace - (cons (cons (car (car articles)) kill) - gnus-score-trace))) + (cons + (cons + (car-safe (rassq alist gnus-score-cache)) + kill) + gnus-score-trace))) (setq found t) - (setcdr (car articles) (+ score (cdr (car articles)))))) + (setcdr (car articles) (+ score (cdar articles))))) (setq articles (cdr articles))) ;; Update expire date (cond ((null date)) ;Permanent entry. - (found ;Match, update date. + ((and found gnus-update-score-entry-dates) ;Match, update date. (gnus-score-set 'touched '(t) alist) (setcar (nthcdr 2 kill) now)) - ((< date expire) ;Old entry, remove. + ((and expire (< date expire)) ;Old entry, remove. (gnus-score-set 'touched '(t) alist) (setcdr entries (cdr rest)) (setq rest entries))) - (setq entries rest)))))) + (setq entries rest))))) + nil) (defun gnus-score-body (scores header now expire &optional trace) (save-excursion (set-buffer nntp-server-buffer) + (setq gnus-scores-articles + (sort gnus-scores-articles + (lambda (a1 a2) + (< (mail-header-number (car a1)) + (mail-header-number (car a2)))))) (save-restriction (let* ((buffer-read-only nil) (articles gnus-scores-articles) - (last (mail-header-number (car (car gnus-scores-articles)))) (all-scores scores) - (request-func (cond ((string= "head" (downcase header)) + (request-func (cond ((string= "head" header) 'gnus-request-head) - ((string= "body" (downcase header)) + ((string= "body" header) 'gnus-request-body) (t 'gnus-request-article))) - entries alist ofunc article) - ;; Not all backends support partial fetching. In that case, - ;; we just fetch the entire article. - (or (gnus-check-backend-function - (and (string-match "^gnus-" (symbol-name request-func)) - (intern (substring (symbol-name request-func) - (match-end 0)))) - gnus-newsgroup-name) - (progn - (setq ofunc request-func) - (setq request-func 'gnus-request-article))) - (while articles - (setq article (mail-header-number (car (car articles)))) - (gnus-message 7 "Scoring on article %s of %s..." article last) - (if (not (funcall request-func article gnus-newsgroup-name)) - () - (widen) - (goto-char (point-min)) - ;; If just parts of the article is to be searched, but the - ;; backend didn't support partial fetching, we just narrow - ;; to the relevant parts. - (if ofunc - (if (eq ofunc 'gnus-request-head) + entries alist ofunc article last) + (when articles + (while (cdr articles) + (setq articles (cdr articles))) + (setq last (mail-header-number (caar articles))) + (setq articles gnus-scores-articles) + ;; Not all backends support partial fetching. In that case, + ;; we just fetch the entire article. + (or (gnus-check-backend-function + (and (string-match "^gnus-" (symbol-name request-func)) + (intern (substring (symbol-name request-func) + (match-end 0)))) + gnus-newsgroup-name) + (progn + (setq ofunc request-func) + (setq request-func 'gnus-request-article))) + (while articles + (setq article (mail-header-number (caar articles))) + (gnus-message 7 "Scoring on article %s of %s..." article last) + (when (funcall request-func article gnus-newsgroup-name) + (widen) + (goto-char (point-min)) + ;; If just parts of the article is to be searched, but the + ;; backend didn't support partial fetching, we just narrow + ;; to the relevant parts. + (if ofunc + (if (eq ofunc 'gnus-request-head) + (narrow-to-region + (point) + (or (search-forward "\n\n" nil t) (point-max))) (narrow-to-region - (point) - (or (search-forward "\n\n" nil t) (point-max))) - (narrow-to-region - (or (search-forward "\n\n" nil t) (point)) - (point-max)))) - (setq scores all-scores) - ;; Find matches. - (while scores - (setq alist (car scores) - scores (cdr scores) - entries (assoc header alist)) - (while (cdr entries) ;First entry is the header index. - (let* ((rest (cdr entries)) - (kill (car rest)) - (match (nth 0 kill)) - (type (or (nth 3 kill) 's)) - (score (or (nth 1 kill) - gnus-score-interactive-default-score)) - (date (nth 2 kill)) - (found nil) - (case-fold-search - (not (or (eq type 'R) (eq type 'S) - (eq type 'Regexp) (eq type 'String)))) - (search-func - (cond ((or (eq type 'r) (eq type 'R) - (eq type 'regexp) (eq type 'Regexp)) - 're-search-forward) - ((or (eq type 's) (eq type 'S) - (eq type 'string) (eq type 'String)) - 'search-forward) - (t - (error "Illegal match type: %s" type))))) - (goto-char (point-min)) - (if (funcall search-func match nil t) - ;; Found a match, update scores. - (progn - (setcdr (car articles) (+ score (cdr (car articles)))) - (setq found t) - (and trace (setq gnus-score-trace - (cons (cons (car (car articles)) kill) - gnus-score-trace))))) - ;; Update expire date - (cond ((null date)) ;Permanent entry. - (found ;Match, update date. - (gnus-score-set 'touched '(t) alist) - (setcar (nthcdr 2 kill) now)) - ((< date expire) ;Old entry, remove. - (gnus-score-set 'touched '(t) alist) - (setcdr entries (cdr rest)) - (setq rest entries))) - (setq entries rest))))) - (setq articles (cdr articles))))))) - - - -(defun gnus-score-followup (scores header now expire &optional trace) + (or (search-forward "\n\n" nil t) (point)) + (point-max)))) + (setq scores all-scores) + ;; Find matches. + (while scores + (setq alist (car scores) + scores (cdr scores) + entries (assoc header alist)) + (while (cdr entries) ;First entry is the header index. + (let* ((rest (cdr entries)) + (kill (car rest)) + (match (nth 0 kill)) + (type (or (nth 3 kill) 's)) + (score (or (nth 1 kill) + gnus-score-interactive-default-score)) + (date (nth 2 kill)) + (found nil) + (case-fold-search + (not (or (eq type 'R) (eq type 'S) + (eq type 'Regexp) (eq type 'String)))) + (search-func + (cond ((or (eq type 'r) (eq type 'R) + (eq type 'regexp) (eq type 'Regexp)) + 're-search-forward) + ((or (eq type 's) (eq type 'S) + (eq type 'string) (eq type 'String)) + 'search-forward) + (t + (error "Illegal match type: %s" type))))) + (goto-char (point-min)) + (if (funcall search-func match nil t) + ;; Found a match, update scores. + (progn + (setcdr (car articles) (+ score (cdar articles))) + (setq found t) + (and trace (setq gnus-score-trace + (cons + (cons + (car-safe + (rassq alist gnus-score-cache)) + kill) + gnus-score-trace))))) + ;; Update expire date + (cond + ((null date)) ;Permanent entry. + ((and found gnus-update-score-entry-dates) ;Match, update date. + (gnus-score-set 'touched '(t) alist) + (setcar (nthcdr 2 kill) now)) + ((and expire (< date expire)) ;Old entry, remove. + (gnus-score-set 'touched '(t) alist) + (setcdr entries (cdr rest)) + (setq rest entries))) + (setq entries rest))))) + (setq articles (cdr articles))))))) + nil) + +(defun gnus-score-followup (scores header now expire &optional trace thread) ;; Insert the unique article headers in the buffer. (let ((gnus-score-index (nth 1 (assoc header gnus-header-index))) (current-score-file gnus-current-score-file) (all-scores scores) ;; gnus-score-index is used as a free variable. - alike last this art entries alist articles) + alike last this art entries alist articles + new news) ;; Change score file to the adaptive score file. All entries that ;; this function makes will be put into this file. - (gnus-score-load-file (gnus-score-file-name - gnus-newsgroup-name gnus-adaptive-file-suffix)) + (save-excursion + (set-buffer gnus-summary-buffer) + (gnus-score-load-file + (or gnus-newsgroup-adaptive-score-file + (gnus-score-file-name + gnus-newsgroup-name gnus-adaptive-file-suffix)))) (setq gnus-scores-articles (sort gnus-scores-articles 'gnus-score-string<) articles gnus-scores-articles) @@ -1209,48 +1551,50 @@ SCORE is the score to add." (setq art (car arts) arts (cdr arts)) (gnus-score-add-followups - (car art) score all-scores))))) + (car art) score all-scores thread)))) + (end-of-line)) (while (funcall search-func match nil t) (end-of-line) (setq found (setq arts (get-text-property (point) 'articles))) ;; Found a match, update scores. - (while arts - (setq art (car arts) - arts (cdr arts)) - (gnus-score-add-followups (car art) score all-scores)))) + (while (setq art (pop arts)) + (when (setq new (gnus-score-add-followups + (car art) score all-scores thread)) + (push new news))))) ;; Update expire date (cond ((null date)) ;Permanent entry. - (found ;Match, update date. + ((and found gnus-update-score-entry-dates) ;Match, update date. (gnus-score-set 'touched '(t) alist) (setcar (nthcdr 2 kill) now)) - ((< date expire) ;Old entry, remove. + ((and expire (< date expire)) ;Old entry, remove. (gnus-score-set 'touched '(t) alist) (setcdr entries (cdr rest)) (setq rest entries))) (setq entries rest)))) ;; We change the score file back to the previous one. - (gnus-score-load-file current-score-file))) + (save-excursion + (set-buffer gnus-summary-buffer) + (gnus-score-load-file current-score-file)) + (list (cons "references" news)))) -(defun gnus-score-add-followups (header score scores) +(defun gnus-score-add-followups (header score scores &optional thread) + "Add a score entry to the adapt file." (save-excursion (set-buffer gnus-summary-buffer) (let* ((id (mail-header-id header)) (scores (car scores)) entry dont) ;; Don't enter a score if there already is one. - (while scores - (setq entry (car scores)) + (while (setq entry (pop scores)) (and (equal "references" (car entry)) - (or (null (nth 3 (car (cdr entry)))) - (eq 's (nth 3 (car (cdr entry))))) - (progn - (if (assoc id entry) - (setq dont t)))) - (setq scores (cdr scores))) - (or dont - (gnus-summary-score-entry - "references" id 's score (current-time-string) nil t))))) - + (or (null (nth 3 (cadr entry))) + (eq 's (nth 3 (cadr entry)))) + (assoc id entry) + (setq dont t))) + (unless dont + (gnus-summary-score-entry + (if thread "thread" "references") + id 's score (current-time-string) nil t))))) (defun gnus-score-string (score-list header now expire &optional trace) ;; Score ARTICLES according to HEADER in SCORE-LIST. @@ -1293,7 +1637,7 @@ SCORE is the score to add." (progn (insert last ?\n) (put-text-property (1- (point)) (point) 'articles alike))) - + ;; Find ordinary matches. (setq scores score-list) (while scores @@ -1319,8 +1663,10 @@ SCORE is the score to add." arts art) (if (= dmt ?f) (setq fuzzy t) + ;; Do non-fuzzy matching. (goto-char (point-min)) (if (= dmt ?e) + ;; Do exact matching. (while (and (not (eobp)) (funcall search-func match nil t)) (and (= (progn (beginning-of-line) (point)) @@ -1336,15 +1682,19 @@ SCORE is the score to add." (setq art (car arts) arts (cdr arts)) (setcdr art (+ score (cdr art))) - (setq gnus-score-trace - (cons (cons (mail-header-number - (car art)) kill) - gnus-score-trace))) + (setq gnus-score-trace + (cons + (cons + (car-safe + (rassq alist gnus-score-cache)) + kill) + gnus-score-trace))) (while arts (setq art (car arts) arts (cdr arts)) (setcdr art (+ score (cdr art))))))) (forward-line 1)) + ;; Do regexp and substring matching. (and (string= match "") (setq match "\n")) (while (and (not (eobp)) (funcall search-func match nil t)) @@ -1354,89 +1704,84 @@ SCORE is the score to add." ;; Found a match, update scores. (if trace (while arts - (setq art (car arts) - arts (cdr arts)) + (setq art (pop arts)) (setcdr art (+ score (cdr art))) - (setq gnus-score-trace - (cons (cons (mail-header-number (car art)) kill) - gnus-score-trace))) + (push (cons + (car-safe (rassq alist gnus-score-cache)) + kill) + gnus-score-trace)) (while arts - (setq art (car arts) - arts (cdr arts)) + (setq art (pop arts)) (setcdr art (+ score (cdr art))))) (forward-line 1))) ;; Update expire date - (cond ((null date)) ;Permanent entry. - (found ;Match, update date. - (gnus-score-set 'touched '(t) alist) - (setcar (nthcdr 2 kill) now)) - ((< date expire) ;Old entry, remove. - (gnus-score-set 'touched '(t) alist) - (setcdr entries (cdr rest)) - (setq rest entries)))) + (cond + ((null date)) ;Permanent entry. + ((and found gnus-update-score-entry-dates) ;Match, update date. + (gnus-score-set 'touched '(t) alist) + (setcar (nthcdr 2 kill) now)) + ((and expire (< date expire)) ;Old entry, remove. + (gnus-score-set 'touched '(t) alist) + (setcdr entries (cdr rest)) + (setq rest entries)))) (setq entries rest)))) - + ;; Find fuzzy matches. - (setq scores (and fuzzy score-list)) - (if fuzzy (gnus-simplify-buffer-fuzzy)) - (while scores - (setq alist (car scores) - scores (cdr scores) - entries (assoc header alist)) - (while (cdr entries) ;First entry is the header index. - (let* ((rest (cdr entries)) - (kill (car rest)) - (match (nth 0 kill)) - (type (or (nth 3 kill) 's)) - (score (or (nth 1 kill) gnus-score-interactive-default-score)) - (date (nth 2 kill)) - (found nil) - (mt (aref (symbol-name type) 0)) - (case-fold-search - (not (or (= mt ?R) (= mt ?S) (= mt ?E) (= mt ?F)))) - (dmt (downcase mt)) - (search-func - (cond ((= dmt ?r) 're-search-forward) - ((or (= dmt ?e) (= dmt ?s) (= dmt ?f)) 'search-forward) - (t (error "Illegal match type: %s" type)))) - arts art) - (if (/= dmt ?f) - () - (goto-char (point-min)) - (while (and (not (eobp)) - (funcall search-func match nil t)) - (and (= (progn (beginning-of-line) (point)) - (match-beginning 0)) - (= (progn (end-of-line) (point)) - (match-end 0)) - (progn - (setq found (setq arts (get-text-property - (point) 'articles))) - ;; Found a match, update scores. - (if trace - (while arts - (setq art (car arts) - arts (cdr arts)) - (setcdr art (+ score (cdr art))) - (setq gnus-score-trace - (cons (cons (mail-header-number - (car art)) kill) - gnus-score-trace))) - (while arts - (setq art (car arts) - arts (cdr arts)) - (setcdr art (+ score (cdr art))))))) - (forward-line 1)) - ;; Update expire date - (cond ((null date)) ;Permanent entry. - (found ;Match, update date. - (gnus-score-set 'touched '(t) alist) - (setcar (nthcdr 2 kill) now)) - ((< date expire) ;Old entry, remove. - (gnus-score-set 'touched '(t) alist) - (setcdr entries (cdr rest)) - (setq rest entries)))) - (setq entries rest)))))) + (when fuzzy + (setq scores score-list) + (gnus-simplify-buffer-fuzzy) + (while scores + (setq alist (car scores) + scores (cdr scores) + entries (assoc header alist)) + (while (cdr entries) ;First entry is the header index. + (let* ((rest (cdr entries)) + (kill (car rest)) + (match (nth 0 kill)) + (type (or (nth 3 kill) 's)) + (score (or (nth 1 kill) gnus-score-interactive-default-score)) + (date (nth 2 kill)) + (found nil) + (mt (aref (symbol-name type) 0)) + (case-fold-search (not (= mt ?F))) + (dmt (downcase mt)) + arts art) + (when (= dmt ?f) + (goto-char (point-min)) + (while (and (not (eobp)) + (search-forward match nil t)) + (when (and (= (progn (beginning-of-line) (point)) + (match-beginning 0)) + (= (progn (end-of-line) (point)) + (match-end 0))) + (setq found (setq arts (get-text-property + (point) 'articles))) + ;; Found a match, update scores. + (if trace + (while arts + (setq art (pop arts)) + (setcdr art (+ score (cdr art))) + (push (cons + (car-safe (rassq alist gnus-score-cache)) + kill) + gnus-score-trace)) + (while arts + (setq art (pop arts)) + (setcdr art (+ score (cdr art)))))) + (forward-line 1)) + ;; Update expire date + (unless trace + (cond + ((null date)) ;Permanent entry. + ((and found gnus-update-score-entry-dates) ;Match, update date. + (gnus-score-set 'touched '(t) alist) + (setcar (nthcdr 2 kill) now)) + ((and expire (< date expire)) ;Old entry, remove. + (gnus-score-set 'touched '(t) alist) + (setcdr entries (cdr rest)) + (setq rest entries))))) + (setq entries rest)))))) + nil) (defun gnus-score-string< (a1 a2) ;; Compare headers in articles A2 and A2. @@ -1448,22 +1793,6 @@ SCORE is the score to add." ;; Build a `gnus-newsgroup-scored' type cons from ARTICLE. (cons (mail-header-number (car article)) (cdr article))) -(defconst gnus-header-index - ;; Name to index alist. - '(("number" 0 gnus-score-integer) - ("subject" 1 gnus-score-string) - ("from" 2 gnus-score-string) - ("date" 3 gnus-score-date) - ("message-id" 4 gnus-score-string) - ("references" 5 gnus-score-string) - ("chars" 6 gnus-score-integer) - ("lines" 7 gnus-score-integer) - ("xref" 8 gnus-score-string) - ("head" -1 gnus-score-body) - ("body" -1 gnus-score-body) - ("all" -1 gnus-score-body) - ("followup" 2 gnus-score-followup))) - (defun gnus-current-score-file-nondirectory (&optional score-file) (let ((score-file (or score-file gnus-current-score-file))) (if score-file @@ -1475,6 +1804,7 @@ SCORE is the score to add." (let* ((malist (gnus-copy-sequence gnus-adaptive-score-alist)) (alist malist) (date (current-time-string)) + (data gnus-newsgroup-data) elem headers match) ;; First we transform the adaptive rule alist into something ;; that's faster to process. @@ -1485,160 +1815,440 @@ SCORE is the score to add." (setq elem (cdr elem)) (while elem (setcdr (car elem) - (cons (symbol-name (car (car elem))) (cdr (car elem)))) + (cons (if (eq (caar elem) 'followup) + "references" + (symbol-name (caar elem))) + (cdar elem))) (setcar (car elem) - (intern - (concat "gnus-header-" - (downcase (symbol-name (car (car elem))))))) + `(lambda (h) + (,(intern + (concat "mail-header-" + (if (eq (caar elem) 'followup) + "message-id" + (downcase (symbol-name (caar elem)))))) + h))) (setq elem (cdr elem))) (setq malist (cdr malist))) ;; We change the score file to the adaptive score file. - (gnus-score-load-file (gnus-score-file-name - gnus-newsgroup-name gnus-adaptive-file-suffix)) + (save-excursion + (set-buffer gnus-summary-buffer) + (gnus-score-load-file + (or gnus-newsgroup-adaptive-score-file + (gnus-score-file-name + gnus-newsgroup-name gnus-adaptive-file-suffix)))) ;; The we score away. - (goto-char (point-min)) - (while (not (eobp)) - (setq elem (cdr (assq (gnus-summary-article-mark) alist))) + (while data + (setq elem (cdr (assq (gnus-data-mark (car data)) alist))) (if (or (not elem) - (get-text-property (point) 'gnus-pseudo)) + (gnus-data-pseudo-p (car data))) () - (setq headers (gnus-get-header-by-number - (gnus-summary-article-number))) - (while (and elem headers) - (setq match (funcall (car (car elem)) headers)) - (gnus-summary-score-entry - (nth 1 (car elem)) match - (cond - ((numberp match) - '=) - ((equal (nth 1 (car elem)) "date") - 'a) - (t - ;; Whether we use substring or exact matches are controlled - ;; here. - (if (or (not gnus-score-exact-adapt-limit) - (< (length match) gnus-score-exact-adapt-limit)) - 'e - (if (equal (nth 1 (car elem)) "subject") - 'f 's)))) - (nth 2 (car elem)) date nil t) - (setq elem (cdr elem)))) - (forward-line 1))))) - -(defun gnus-score-remove-lines-adaptive (marks) - (save-excursion - (let* ((malist (gnus-copy-sequence gnus-adaptive-score-alist)) - (alist malist) - (date (current-time-string)) - (cur-score gnus-current-score-file) - elem headers match) - ;; First we transform the adaptive rule alist into something - ;; that's faster to process. - (while malist - (setq elem (car malist)) - (if (symbolp (car elem)) - (setcar elem (symbol-value (car elem)))) - (setq elem (cdr elem)) - (while elem - (setcdr (car elem) - (cons (symbol-name (car (car elem))) (cdr (car elem)))) - (setcar (car elem) - (intern - (concat "gnus-header-" - (downcase (symbol-name (car (car elem))))))) - (setq elem (cdr elem))) - (setq malist (cdr malist))) - ;; The we score away. - (goto-char (point-min)) - ;; We change the score file to the adaptive score file. - (gnus-score-load-file (gnus-score-file-name - gnus-newsgroup-name gnus-adaptive-file-suffix)) - (while (re-search-forward marks nil t) - (beginning-of-line) - (setq elem (cdr (assq (gnus-summary-article-mark) alist))) - (if (or (not elem) - (get-text-property (gnus-point-at-bol) 'gnus-pseudo)) - () - (setq headers (gnus-get-header-by-number - (gnus-summary-article-number))) - (while elem - (setq match (funcall (car (car elem)) headers)) - (gnus-summary-score-entry - (nth 1 (car elem)) match - (if (or (not gnus-score-exact-adapt-limit) - (< (length match) gnus-score-exact-adapt-limit)) - 'e 's) - (nth 2 (car elem)) date nil t) - (setq elem (cdr elem)))) - (delete-region (point) (progn (forward-line 1) (point)))) - ;; Switch back to the old score file. - (gnus-score-load-file cur-score)))) - -;;; -;;; Score mode. -;;; - -(defvar gnus-score-mode-map nil) -(defvar gnus-score-mode-hook nil) - -(if gnus-score-mode-map - () - (setq gnus-score-mode-map (copy-keymap emacs-lisp-mode-map)) - (define-key gnus-score-mode-map "\C-c\C-c" 'gnus-score-edit-done) - (define-key gnus-score-mode-map "\C-c\C-d" 'gnus-score-edit-insert-date)) - -(defun gnus-score-mode () - "Mode for editing score files. -This mode is an extended emacs-lisp mode. - -\\{gnus-score-mode-map}" - (interactive) - (kill-all-local-variables) - (use-local-map gnus-score-mode-map) - (set-syntax-table emacs-lisp-mode-syntax-table) - (setq major-mode 'gnus-score-mode) - (setq mode-name "Score") - (lisp-mode-variables nil) - (run-hooks 'emacs-lisp-mode-hook 'gnus-score-mode-hook)) - -(defun gnus-score-edit-insert-date () - "Insert date in numerical format." - (interactive) - (insert (int-to-string (gnus-day-number (current-time-string))))) + (when (setq headers (gnus-data-header (car data))) + (while elem + (setq match (funcall (caar elem) headers)) + (gnus-summary-score-entry + (nth 1 (car elem)) match + (cond + ((numberp match) + '=) + ((equal (nth 1 (car elem)) "date") + 'a) + (t + ;; Whether we use substring or exact matches are controlled + ;; here. + (if (or (not gnus-score-exact-adapt-limit) + (< (length match) gnus-score-exact-adapt-limit)) + 'e + (if (equal (nth 1 (car elem)) "subject") + 'f 's)))) + (nth 2 (car elem)) date nil t) + (setq elem (cdr elem))))) + (setq data (cdr data)))))) (defun gnus-score-edit-done () - "Save the score file and return to the summary buffer." - (interactive) (let ((bufnam (buffer-file-name (current-buffer))) (winconf gnus-prev-winconf)) - (gnus-make-directory (file-name-directory (buffer-file-name))) - (save-buffer) - (kill-buffer (current-buffer)) + (and winconf (set-window-configuration winconf)) (gnus-score-remove-from-cache bufnam) - (gnus-score-load-file bufnam) - (and winconf (set-window-configuration winconf)))) + (gnus-score-load-file bufnam))) (defun gnus-score-find-trace () - "Find all score rules applied to this article." + "Find all score rules that applies to the current article." (interactive) (let ((gnus-newsgroup-headers - (list (gnus-get-header-by-number (gnus-summary-article-number)))) + (list (gnus-summary-article-header))) (gnus-newsgroup-scored nil) (buf (current-buffer)) trace) + (when (get-buffer "*Gnus Scores*") + (save-excursion + (set-buffer "*Gnus Scores*") + (erase-buffer))) (setq gnus-score-trace nil) (gnus-possibly-score-headers 'trace) - (or (setq trace gnus-score-trace) - (error "No score rules apply to the current article.")) - (pop-to-buffer "*Gnus Scores*") - (gnus-add-current-to-buffer-list) - (erase-buffer) - (while trace - (insert (format "%S\n" (cdr (car trace)))) - (setq trace (cdr trace))) - (goto-char (point-min)) - (pop-to-buffer buf))) + (if (not (setq trace gnus-score-trace)) + (gnus-error 1 "No score rules apply to the current article.") + (pop-to-buffer "*Gnus Scores*") + (gnus-add-current-to-buffer-list) + (erase-buffer) + (while trace + (insert (format "%S -> %s\n" (cdar trace) + (file-name-nondirectory (caar trace)))) + (setq trace (cdr trace))) + (goto-char (point-min)) + (pop-to-buffer buf)))) + +(defun gnus-summary-rescore () + "Redo the entire scoring process in the current summary." + (interactive) + (gnus-score-save) + (setq gnus-score-cache nil) + (setq gnus-newsgroup-scored nil) + (gnus-possibly-score-headers) + (gnus-score-update-all-lines)) +(defun gnus-score-flush-cache () + "Flush the cache of score files." + (interactive) + (gnus-score-save) + (setq gnus-score-cache nil + gnus-score-alist nil + gnus-short-name-score-file-cache nil) + (gnus-message 6 "The score cache is now flushed")) + +(gnus-add-shutdown 'gnus-score-close 'gnus) + +(defvar gnus-score-file-alist-cache nil) + +(defun gnus-score-close () + "Clear all internal score variables." + (setq gnus-score-cache nil + gnus-internal-global-score-files nil + gnus-score-file-list nil + gnus-score-file-alist-cache nil)) + +;; Summary score marking commands. + +(defun gnus-summary-raise-same-subject-and-select (score) + "Raise articles which has the same subject with SCORE and select the next." + (interactive "p") + (let ((subject (gnus-summary-article-subject))) + (gnus-summary-raise-score score) + (while (gnus-summary-find-subject subject) + (gnus-summary-raise-score score)) + (gnus-summary-next-article t))) + +(defun gnus-summary-raise-same-subject (score) + "Raise articles which has the same subject with SCORE." + (interactive "p") + (let ((subject (gnus-summary-article-subject))) + (gnus-summary-raise-score score) + (while (gnus-summary-find-subject subject) + (gnus-summary-raise-score score)) + (gnus-summary-next-subject 1 t))) + +(defun gnus-score-default (level) + (if level (prefix-numeric-value level) + gnus-score-interactive-default-score)) + +(defun gnus-summary-raise-thread (&optional score) + "Raise the score of the articles in the current thread with SCORE." + (interactive "P") + (setq score (gnus-score-default score)) + (let (e) + (save-excursion + (let ((articles (gnus-summary-articles-in-thread))) + (while articles + (gnus-summary-goto-subject (car articles)) + (gnus-summary-raise-score score) + (setq articles (cdr articles)))) + (setq e (point))) + (let ((gnus-summary-check-current t)) + (or (zerop (gnus-summary-next-subject 1 t)) + (goto-char e)))) + (gnus-summary-recenter) + (gnus-summary-position-point) + (gnus-set-mode-line 'summary)) + +(defun gnus-summary-lower-same-subject-and-select (score) + "Raise articles which has the same subject with SCORE and select the next." + (interactive "p") + (gnus-summary-raise-same-subject-and-select (- score))) + +(defun gnus-summary-lower-same-subject (score) + "Raise articles which has the same subject with SCORE." + (interactive "p") + (gnus-summary-raise-same-subject (- score))) + +(defun gnus-summary-lower-thread (&optional score) + "Lower score of articles in the current thread with SCORE." + (interactive "P") + (gnus-summary-raise-thread (- (1- (gnus-score-default score))))) + +;;; Finding score files. + +(defun gnus-score-score-files (group) + "Return a list of all possible score files." + ;; Search and set any global score files. + (and gnus-global-score-files + (or gnus-internal-global-score-files + (gnus-score-search-global-directories gnus-global-score-files))) + ;; Fix the kill-file dir variable. + (setq gnus-kill-files-directory + (file-name-as-directory gnus-kill-files-directory)) + ;; If we can't read it, there are no score files. + (if (not (file-exists-p (expand-file-name gnus-kill-files-directory))) + (setq gnus-score-file-list nil) + (if (not (gnus-use-long-file-name 'not-score)) + ;; We do not use long file names, so we have to do some + ;; directory traversing. + (setq gnus-score-file-list + (cons nil + (or gnus-short-name-score-file-cache + (prog2 + (gnus-message 6 "Finding all score files...") + (setq gnus-short-name-score-file-cache + (gnus-score-score-files-1 + gnus-kill-files-directory)) + (gnus-message 6 "Finding all score files...done"))))) + ;; We want long file names. + (when (or (not gnus-score-file-list) + (not (car gnus-score-file-list)) + (gnus-file-newer-than gnus-kill-files-directory + (car gnus-score-file-list))) + (setq gnus-score-file-list + (cons (nth 5 (file-attributes gnus-kill-files-directory)) + (nreverse + (directory-files + gnus-kill-files-directory t + (gnus-score-file-regexp))))))) + (cdr gnus-score-file-list))) + +(defun gnus-score-score-files-1 (dir) + "Return all possible score files under DIR." + (let ((files (directory-files (expand-file-name dir) t nil t)) + (regexp (gnus-score-file-regexp)) + out file) + (while (setq file (pop files)) + (cond + ;; Ignore "." and "..". + ((member (file-name-nondirectory file) '("." "..")) + nil) + ;; Recurse down directories. + ((file-directory-p file) + (setq out (nconc (gnus-score-score-files-1 file) out))) + ;; Add files to the list of score files. + ((string-match regexp file) + (push file out)))) + (or out + ;; Return a dummy value. + (list "~/News/this.file.does.not.exist.SCORE")))) + +(defun gnus-score-file-regexp () + "Return a regexp that match all score files." + (concat "\\(" (regexp-quote gnus-score-file-suffix ) + "\\|" (regexp-quote gnus-adaptive-file-suffix) "\\)\\'")) + +(defun gnus-score-find-bnews (group) + "Return a list of score files for GROUP. +The score files are those files in the ~/News/ directory which matches +GROUP using BNews sys file syntax." + (let* ((sfiles (append (gnus-score-score-files group) + gnus-internal-global-score-files)) + (kill-dir (file-name-as-directory + (expand-file-name gnus-kill-files-directory))) + (klen (length kill-dir)) + (score-regexp (gnus-score-file-regexp)) + (trans (cdr (assq ?: nnheader-file-name-translation-alist))) + ofiles not-match regexp) + (save-excursion + (set-buffer (get-buffer-create "*gnus score files*")) + (buffer-disable-undo (current-buffer)) + ;; Go through all score file names and create regexp with them + ;; as the source. + (while sfiles + (erase-buffer) + (insert (car sfiles)) + (goto-char (point-min)) + ;; First remove the suffix itself. + (when (re-search-forward (concat "." score-regexp) nil t) + (replace-match "" t t) + (goto-char (point-min)) + (if (looking-at (regexp-quote kill-dir)) + ;; If the file name was just "SCORE", `klen' is one character + ;; too much. + (delete-char (min (1- (point-max)) klen)) + (goto-char (point-max)) + (search-backward "/") + (delete-region (1+ (point)) (point-min))) + ;; If short file names were used, we have to translate slashes. + (goto-char (point-min)) + (let ((regexp (concat + "[/:" (if trans (char-to-string trans) "") "]"))) + (while (re-search-forward regexp nil t) + (replace-match "." t t))) + ;; Cludge to get rid of "nntp+" problems. + (goto-char (point-min)) + (and (looking-at "nn[a-z]+\\+") + (progn + (search-forward "+") + (forward-char -1) + (insert "\\"))) + ;; Kludge to deal with "++". + (goto-char (point-min)) + (while (search-forward "++" nil t) + (replace-match "\\+\\+" t t)) + ;; Translate "all" to ".*". + (goto-char (point-min)) + (while (search-forward "all" nil t) + (replace-match ".*" t t)) + (goto-char (point-min)) + ;; Deal with "not."s. + (if (looking-at "not.") + (progn + (setq not-match t) + (setq regexp (buffer-substring 5 (point-max)))) + (setq regexp (buffer-substring 1 (point-max))) + (setq not-match nil)) + ;; Finally - if this resulting regexp matches the group name, + ;; we add this score file to the list of score files + ;; applicable to this group. + (if (or (and not-match + (not (string-match regexp group))) + (and (not not-match) + (string-match regexp group))) + (setq ofiles (cons (car sfiles) ofiles)))) + (setq sfiles (cdr sfiles))) + (kill-buffer (current-buffer)) + ;; Slight kludge here - the last score file returned should be + ;; the local score file, whether it exists or not. This is so + ;; that any score commands the user enters will go to the right + ;; file, and not end up in some global score file. + (let ((localscore (gnus-score-file-name group))) + (setq ofiles (cons localscore (delete localscore ofiles)))) + (nreverse ofiles)))) + +(defun gnus-score-find-single (group) + "Return list containing the score file for GROUP." + (list (or gnus-newsgroup-adaptive-score-file + (gnus-score-file-name group gnus-adaptive-file-suffix)) + (gnus-score-file-name group))) + +(defun gnus-score-find-hierarchical (group) + "Return list of score files for GROUP. +This includes the score file for the group and all its parents." + (let ((all (copy-sequence '(nil))) + (start 0)) + (while (string-match "\\." group (1+ start)) + (setq start (match-beginning 0)) + (setq all (cons (substring group 0 start) all))) + (setq all (cons group all)) + (nconc + (mapcar (lambda (newsgroup) + (gnus-score-file-name newsgroup gnus-adaptive-file-suffix)) + (setq all (nreverse all))) + (mapcar 'gnus-score-file-name all)))) + +(defun gnus-score-find-alist (group) + "Return list of score files for GROUP. +The list is determined from the variable gnus-score-file-alist." + (let ((alist gnus-score-file-multiple-match-alist) + score-files) + ;; if this group has been seen before, return the cached entry + (if (setq score-files (assoc group gnus-score-file-alist-cache)) + (cdr score-files) ;ensures caching groups with no matches + ;; handle the multiple match alist + (while alist + (and (string-match (caar alist) group) + (setq score-files + (nconc score-files (copy-sequence (cdar alist))))) + (setq alist (cdr alist))) + (setq alist gnus-score-file-single-match-alist) + ;; handle the single match alist + (while alist + (and (string-match (caar alist) group) + ;; progn used just in case ("regexp") has no files + ;; and score-files is still nil. -sj + ;; this can be construed as a "stop searching here" feature :> + ;; and used to simplify regexps in the single-alist + (progn + (setq score-files + (nconc score-files (copy-sequence (cdar alist)))) + (setq alist nil))) + (setq alist (cdr alist))) + ;; cache the score files + (setq gnus-score-file-alist-cache + (cons (cons group score-files) gnus-score-file-alist-cache)) + score-files))) + +(defun gnus-possibly-score-headers (&optional trace) + (let ((funcs gnus-score-find-score-files-function) + score-files) + ;; Make sure funcs is a list. + (and funcs + (not (listp funcs)) + (setq funcs (list funcs))) + ;; Get the initial score files for this group. + (when funcs + (setq score-files (gnus-score-find-alist gnus-newsgroup-name))) + ;; Go through all the functions for finding score files (or actual + ;; scores) and add them to a list. + (while funcs + (when (gnus-functionp (car funcs)) + (setq score-files + (nconc score-files (funcall (car funcs) gnus-newsgroup-name)))) + (setq funcs (cdr funcs))) + ;; Check whether there is a `score-file' group parameter. + (let ((param-file (gnus-group-get-parameter + gnus-newsgroup-name 'score-file))) + (when param-file + (push param-file score-files))) + ;; Do the scoring if there are any score files for this group. + (when score-files + (gnus-score-headers score-files trace)))) + +(defun gnus-score-file-name (newsgroup &optional suffix) + "Return the name of a score file for NEWSGROUP." + (let ((suffix (or suffix gnus-score-file-suffix))) + (nnheader-translate-file-chars + (cond + ((or (null newsgroup) + (string-equal newsgroup "")) + ;; The global score file is placed at top of the directory. + (expand-file-name + suffix gnus-kill-files-directory)) + ((gnus-use-long-file-name 'not-score) + ;; Append ".SCORE" to newsgroup name. + (expand-file-name (concat (gnus-newsgroup-savable-name newsgroup) + "." suffix) + gnus-kill-files-directory)) + (t + ;; Place "SCORE" under the hierarchical directory. + (expand-file-name (concat (gnus-newsgroup-directory-form newsgroup) + "/" suffix) + gnus-kill-files-directory)))))) + +(defun gnus-score-search-global-directories (files) + "Scan all global score directories for score files." + ;; Set the variable `gnus-internal-global-score-files' to all + ;; available global score files. + (interactive (list gnus-global-score-files)) + (let (out) + (while files + (if (string-match "/$" (car files)) + (setq out (nconc (directory-files + (car files) t + (concat (gnus-score-file-regexp) "$")))) + (setq out (cons (car files) out))) + (setq files (cdr files))) + (setq gnus-internal-global-score-files out))) + +(defun gnus-score-default-fold-toggle () + "Toggle folding for new score file entries." + (interactive) + (setq gnus-score-default-fold (not gnus-score-default-fold)) + (if gnus-score-default-fold + (gnus-message 1 "New score file entries will be case insensitive.") + (gnus-message 1 "New score file entries will be case sensitive."))) (provide 'gnus-score) diff --git a/lisp/gnus-uu.el b/lisp/gnus-uu.el index d8ea2a5af1b..bd23e9edeba 100644 --- a/lisp/gnus-uu.el +++ b/lisp/gnus-uu.el @@ -1,10 +1,8 @@ ;;; gnus-uu.el --- extract (uu)encoded files in Gnus - -;; Copyright (C) 1985,86,87,93,94,95 Free Software Foundation, Inc. +;; Copyright (C) 1985,86,87,93,94,95,96 Free Software Foundation, Inc. ;; Author: Lars Magne Ingebrigtsen ;; Created: 2 Oct 1993 -;; Version: v3.0 ;; Keyword: news ;; This file is part of GNU Emacs. @@ -30,6 +28,7 @@ (require 'gnus) (require 'gnus-msg) +(eval-when-compile (require 'cl)) ;; Default viewing action rules @@ -42,6 +41,7 @@ ("\\.\\(wav\\|aiff\\|hcom\\|u[blw]\\|s[bfw]\\|voc\\|smp\\)$" "sox -v .5 %s -t .au -u - > /dev/audio") ("\\.au$" "cat %s > /dev/audio") + ("\\.midi?$" "playmidi -f") ("\\.mod$" "str32") ("\\.ps$" "ghostview") ("\\.dvi$" "xdvi") @@ -185,15 +185,16 @@ Default is \"/tmp/\".") "*Non-nil means that gnus-uu won't peek inside archives looking for files to display. Default is nil.") -(defvar gnus-uu-view-and-save nil - "*Non-nil means that the user will always be asked to save a file after viewing it. -If the variable is nil, the user will only be asked to save if the -viewing is unsuccessful. Default is nil.") - (defvar gnus-uu-ignore-default-view-rules nil "*Non-nil means that gnus-uu will ignore the default viewing rules. Only the user viewing rules will be consulted. Default is nil.") +(defvar gnus-uu-grabbed-file-functions nil + "*Functions run on each file after successful decoding. +They will be called with the name of the file as the argument. +Likely functions you can use in this list are `gnus-uu-grab-view' +and `gnus-uu-grab-move'.") + (defvar gnus-uu-ignore-default-archive-rules nil "*Non-nil means that gnus-uu will ignore the default archive unpacking commands. Only the user unpacking commands will be consulted. Default is nil.") @@ -259,64 +260,62 @@ The headers will be included in the sequence they are matched.") (defconst gnus-uu-uudecode-process nil) (defvar gnus-uu-binhex-article-name nil) -(defvar gnus-uu-generated-file-list nil) (defvar gnus-uu-work-dir nil) (defconst gnus-uu-output-buffer-name " *Gnus UU Output*") -(defvar gnus-uu-default-dir default-directory) +(defvar gnus-uu-default-dir gnus-article-save-directory) +(defvar gnus-uu-digest-from-subject nil) ;; Keymaps -(defvar gnus-uu-extract-map nil) -(defvar gnus-uu-extract-view-map nil) -(defvar gnus-uu-mark-map nil) - -(define-prefix-command 'gnus-uu-mark-map) -(define-key gnus-summary-mark-map "P" 'gnus-uu-mark-map) -(define-key gnus-uu-mark-map "p" 'gnus-summary-mark-as-processable) -(define-key gnus-uu-mark-map "u" 'gnus-summary-unmark-as-processable) -(define-key gnus-uu-mark-map "U" 'gnus-summary-unmark-all-processable) -(define-key gnus-uu-mark-map "s" 'gnus-uu-mark-series) -(define-key gnus-uu-mark-map "r" 'gnus-uu-mark-region) -(define-key gnus-uu-mark-map "R" 'gnus-uu-mark-by-regexp) -(define-key gnus-uu-mark-map "t" 'gnus-uu-mark-thread) -(define-key gnus-uu-mark-map "a" 'gnus-uu-mark-all) -(define-key gnus-uu-mark-map "S" 'gnus-uu-mark-sparse) - -(define-prefix-command 'gnus-uu-extract-map) -(define-key gnus-summary-mode-map "X" 'gnus-uu-extract-map) -;;(define-key gnus-uu-extract-map "x" 'gnus-uu-extract-any) -;;(define-key gnus-uu-extract-map "m" 'gnus-uu-extract-mime) -(define-key gnus-uu-extract-map "u" 'gnus-uu-decode-uu) -(define-key gnus-uu-extract-map "U" 'gnus-uu-decode-uu-and-save) -(define-key gnus-uu-extract-map "s" 'gnus-uu-decode-unshar) -(define-key gnus-uu-extract-map "S" 'gnus-uu-decode-unshar-and-save) -(define-key gnus-uu-extract-map "o" 'gnus-uu-decode-save) -(define-key gnus-uu-extract-map "O" 'gnus-uu-decode-save) -(define-key gnus-uu-extract-map "b" 'gnus-uu-decode-binhex) -(define-key gnus-uu-extract-map "B" 'gnus-uu-decode-binhex) -(define-key gnus-uu-extract-map "p" 'gnus-uu-decode-postscript) -(define-key gnus-uu-extract-map "P" 'gnus-uu-decode-postscript-and-save) - -(define-prefix-command 'gnus-uu-extract-view-map) -(define-key gnus-uu-extract-map "v" 'gnus-uu-extract-view-map) -(define-key gnus-uu-extract-view-map "u" 'gnus-uu-decode-uu-view) -(define-key gnus-uu-extract-view-map "U" 'gnus-uu-decode-uu-and-save-view) -(define-key gnus-uu-extract-view-map "s" 'gnus-uu-decode-unshar-view) -(define-key gnus-uu-extract-view-map "S" 'gnus-uu-decode-unshar-and-save-view) -(define-key gnus-uu-extract-view-map "o" 'gnus-uu-decode-save-view) -(define-key gnus-uu-extract-view-map "O" 'gnus-uu-decode-save-view) -(define-key gnus-uu-extract-view-map "b" 'gnus-uu-decode-binhex-view) -(define-key gnus-uu-extract-view-map "B" 'gnus-uu-decode-binhex-view) -(define-key gnus-uu-extract-view-map "p" 'gnus-uu-decode-postscript-view) -(define-key gnus-uu-extract-view-map "P" 'gnus-uu-decode-postscript-and-save-view) - +(gnus-define-keys + (gnus-uu-mark-map "P" gnus-summary-mark-map) + "p" gnus-summary-mark-as-processable + "u" gnus-summary-unmark-as-processable + "U" gnus-summary-unmark-all-processable + "v" gnus-uu-mark-over + "s" gnus-uu-mark-series + "r" gnus-uu-mark-region + "R" gnus-uu-mark-by-regexp + "t" gnus-uu-mark-thread + "T" gnus-uu-unmark-thread + "a" gnus-uu-mark-all + "b" gnus-uu-mark-buffer + "S" gnus-uu-mark-sparse) + +(gnus-define-keys + (gnus-uu-extract-map "X" gnus-summary-mode-map) + ;;"x" gnus-uu-extract-any + ;;"m" gnus-uu-extract-mime + "u" gnus-uu-decode-uu + "U" gnus-uu-decode-uu-and-save + "s" gnus-uu-decode-unshar + "S" gnus-uu-decode-unshar-and-save + "o" gnus-uu-decode-save + "O" gnus-uu-decode-save + "b" gnus-uu-decode-binhex + "B" gnus-uu-decode-binhex + "p" gnus-uu-decode-postscript + "P" gnus-uu-decode-postscript-and-save) + +(gnus-define-keys + (gnus-uu-extract-view-map "v" gnus-uu-extract-map) + "u" gnus-uu-decode-uu-view + "U" gnus-uu-decode-uu-and-save-view + "s" gnus-uu-decode-unshar-view + "S" gnus-uu-decode-unshar-and-save-view + "o" gnus-uu-decode-save-view + "O" gnus-uu-decode-save-view + "b" gnus-uu-decode-binhex-view + "B" gnus-uu-decode-binhex-view + "p" gnus-uu-decode-postscript-view + "P" gnus-uu-decode-postscript-and-save-view) ;; Commands. -(defun gnus-uu-decode-uu (n) +(defun gnus-uu-decode-uu (&optional n) "Uudecodes the current article." (interactive "P") (gnus-uu-decode-with-method 'gnus-uu-uustrip-article n)) @@ -329,12 +328,12 @@ The headers will be included in the sequence they are matched.") (read-file-name "Uudecode and save in dir: " gnus-uu-default-dir gnus-uu-default-dir t)))) - (gnus-uu-decode-with-method 'gnus-uu-uustrip-article n dir)) + (gnus-uu-decode-with-method 'gnus-uu-uustrip-article n dir nil nil t)) -(defun gnus-uu-decode-unshar (n) +(defun gnus-uu-decode-unshar (&optional n) "Unshars the current article." (interactive "P") - (gnus-uu-decode-with-method 'gnus-uu-unshar-article n nil nil 'scan)) + (gnus-uu-decode-with-method 'gnus-uu-unshar-article n nil nil 'scan t)) (defun gnus-uu-decode-unshar-and-save (n dir) "Unshars and saves the current article." @@ -344,7 +343,7 @@ The headers will be included in the sequence they are matched.") (read-file-name "Unshar and save in dir: " gnus-uu-default-dir gnus-uu-default-dir t)))) - (gnus-uu-decode-with-method 'gnus-uu-unshar-article n dir nil 'scan)) + (gnus-uu-decode-with-method 'gnus-uu-unshar-article n dir nil 'scan t)) (defun gnus-uu-decode-save (n file) "Saves the current article." @@ -357,9 +356,7 @@ The headers will be included in the sequence they are matched.") gnus-uu-default-dir gnus-uu-default-dir))) (setq gnus-uu-saved-article-name file) - (gnus-uu-decode-with-method 'gnus-uu-save-article n nil t) - (setq gnus-uu-generated-file-list - (delete file gnus-uu-generated-file-list))) + (gnus-uu-decode-with-method 'gnus-uu-save-article n nil t)) (defun gnus-uu-decode-binhex (n dir) "Unbinhexes the current article." @@ -373,7 +370,7 @@ The headers will be included in the sequence they are matched.") (make-temp-name (concat gnus-uu-work-dir "binhex"))) (gnus-uu-decode-with-method 'gnus-uu-binhex-article n dir)) -(defun gnus-uu-decode-uu-view (n) +(defun gnus-uu-decode-uu-view (&optional n) "Uudecodes and views the current article." (interactive "P") (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic))) @@ -389,7 +386,7 @@ The headers will be included in the sequence they are matched.") (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic))) (gnus-uu-decode-uu-and-save n dir))) -(defun gnus-uu-decode-unshar-view (n) +(defun gnus-uu-decode-unshar-view (&optional n) "Unshars and views the current article." (interactive "P") (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic))) @@ -430,52 +427,74 @@ The headers will be included in the sequence they are matched.") ;; Digest and forward articles -(defun gnus-uu-digest-mail-forward (n &optional post) +(defun gnus-uu-digest-mail-forward (&optional n post) "Digests and forwards all articles in this series." (interactive "P") (let ((gnus-uu-save-in-digest t) (file (make-temp-name (concat gnus-uu-tmp-dir "forward"))) - buf) + buf subject from) + (setq gnus-uu-digest-from-subject nil) (gnus-uu-decode-save n file) - (gnus-uu-add-file file) (setq buf (switch-to-buffer (get-buffer-create " *gnus-uu-forward*"))) (gnus-add-current-to-buffer-list) (erase-buffer) (delete-other-windows) (insert-file file) + (let ((fs gnus-uu-digest-from-subject)) + (if (not fs) + () + (setq from (caar fs) + subject (gnus-simplify-subject-fuzzy (cdar fs)) + fs (cdr fs)) + (while (and fs (or from subject)) + (and from + (or (string= from (caar fs)) + (setq from nil))) + (and subject + (or (string= (gnus-simplify-subject-fuzzy (cdar fs)) + subject) + (setq subject nil))) + (setq fs (cdr fs)))) + (or subject (setq subject "Digested Articles")) + (or from (setq from "Various"))) (goto-char (point-min)) (and (re-search-forward "^Subject: ") (progn (delete-region (point) (gnus-point-at-eol)) - (insert "Digested Articles"))) + (insert subject))) (goto-char (point-min)) (and (re-search-forward "^From: ") (progn (delete-region (point) (gnus-point-at-eol)) - (insert "Various"))) - (if post - (gnus-forward-using-post) - (funcall gnus-mail-forward-method)) + (insert from))) + (message-forward post) (delete-file file) - (kill-buffer buf))) + (kill-buffer buf) + (setq gnus-uu-digest-from-subject nil))) -(defun gnus-uu-digest-post-forward (n) +(defun gnus-uu-digest-post-forward (&optional n) "Digest and forward to a newsgroup." (interactive "P") (gnus-uu-digest-mail-forward n t)) ;; Process marking. -(defun gnus-uu-mark-by-regexp (regexp) +(defun gnus-uu-mark-by-regexp (regexp &optional unmark) "Ask for a regular expression and set the process mark on all articles that match." (interactive (list (read-from-minibuffer "Mark (regexp): "))) (gnus-set-global-variables) (let ((articles (gnus-uu-find-articles-matching regexp))) (while articles - (gnus-summary-set-process-mark (car articles)) - (setq articles (cdr articles))) + (if unmark + (gnus-summary-remove-process-mark (pop articles)) + (gnus-summary-set-process-mark (pop articles)))) (message "")) - (gnus-summary-position-cursor)) + (gnus-summary-position-point)) + +(defun gnus-uu-unmark-by-regexp (regexp &optional unmark) + "Ask for a regular expression and remove the process mark on all articles that match." + (interactive (list (read-from-minibuffer "Mark (regexp): "))) + (gnus-uu-mark-by-regexp regexp t)) (defun gnus-uu-mark-series () "Mark the current series with the process mark." @@ -486,18 +505,35 @@ The headers will be included in the sequence they are matched.") (gnus-summary-set-process-mark (car articles)) (setq articles (cdr articles))) (message "")) - (gnus-summary-position-cursor)) + (gnus-summary-position-point)) -(defun gnus-uu-mark-region (beg end) - "Marks all articles between point and mark." +(defun gnus-uu-mark-region (beg end &optional unmark) + "Set the process mark on all articles between point and mark." (interactive "r") (gnus-set-global-variables) (save-excursion (goto-char beg) (while (< (point) end) - (gnus-summary-set-process-mark (gnus-summary-article-number)) + (if unmark + (gnus-summary-remove-process-mark (gnus-summary-article-number)) + (gnus-summary-set-process-mark (gnus-summary-article-number))) (forward-line 1))) - (gnus-summary-position-cursor)) + (gnus-summary-position-point)) + +(defun gnus-uu-unmark-region (beg end) + "Remove the process mark from all articles between point and mark." + (interactive "r") + (gnus-uu-mark-region beg end t)) + +(defun gnus-uu-mark-buffer () + "Set the process mark on all articles in the buffer." + (interactive) + (gnus-uu-mark-region (point-min) (point-max))) + +(defun gnus-uu-unmark-buffer () + "Remove the process mark on all articles in the buffer." + (interactive) + (gnus-uu-mark-region (point-min) (point-max) t)) (defun gnus-uu-mark-thread () "Marks all articles downwards in this thread." @@ -507,7 +543,33 @@ The headers will be included in the sequence they are matched.") (while (and (gnus-summary-set-process-mark (gnus-summary-article-number)) (zerop (gnus-summary-next-subject 1)) (> (gnus-summary-thread-level) level)))) - (gnus-summary-position-cursor)) + (gnus-summary-position-point)) + +(defun gnus-uu-unmark-thread () + "Unmarks all articles downwards in this thread." + (interactive) + (gnus-set-global-variables) + (let ((level (gnus-summary-thread-level))) + (while (and (gnus-summary-remove-process-mark + (gnus-summary-article-number)) + (zerop (gnus-summary-next-subject 1)) + (> (gnus-summary-thread-level) level)))) + (gnus-summary-position-point)) + +(defun gnus-uu-mark-over (&optional score) + "Mark all articles with a score over SCORE (the prefix.)" + (interactive "P") + (let ((score (gnus-score-default score)) + (data gnus-newsgroup-data)) + (save-excursion + (while data + (when (> (or (cdr (assq (gnus-data-number (caar data)) + gnus-newsgroup-scored)) + gnus-summary-default-score 0) + score) + (gnus-summary-set-process-mark (caar data))) + (setq data (cdr data)))) + (gnus-summary-position-point))) (defun gnus-uu-mark-sparse () "Mark all series that have some articles marked." @@ -519,7 +581,8 @@ The headers will be included in the sequence they are matched.") (setq gnus-newsgroup-processable nil) (save-excursion (while marked - (and (setq headers (gnus-get-header-by-number (car marked))) + (and (vectorp (setq headers + (gnus-summary-article-header (car marked)))) (setq subject (mail-header-subject headers) articles (gnus-uu-find-articles-matching (gnus-uu-reginize-string subject)) @@ -530,7 +593,7 @@ The headers will be included in the sequence they are matched.") (setq articles (cdr articles))) (setq marked (cdr marked))) (setq gnus-newsgroup-processable (nreverse total))) - (gnus-summary-position-cursor))) + (gnus-summary-position-point))) (defun gnus-uu-mark-all () "Mark all articles in \"series\" order." @@ -538,23 +601,25 @@ The headers will be included in the sequence they are matched.") (gnus-set-global-variables) (setq gnus-newsgroup-processable nil) (save-excursion - (goto-char (point-min)) - (let (number) - (while (and (not (eobp)) - (setq number (gnus-summary-article-number))) - (if (not (memq number gnus-newsgroup-processable)) - (save-excursion (gnus-uu-mark-series))) - (forward-line 1)))) - (gnus-summary-position-cursor)) + (let ((data gnus-newsgroup-data) + number) + (while data + (when (and (not (memq (setq number (gnus-data-number (car data))) + gnus-newsgroup-processable)) + (vectorp (gnus-data-header (car data)))) + (gnus-summary-goto-subject number) + (gnus-uu-mark-series)) + (setq data (cdr data))))) + (gnus-summary-position-point)) ;; All PostScript functions written by Erik Selberg . -(defun gnus-uu-decode-postscript (n) +(defun gnus-uu-decode-postscript (&optional n) "Gets postscript of the current article." (interactive "P") (gnus-uu-decode-with-method 'gnus-uu-decode-postscript-article n)) -(defun gnus-uu-decode-postscript-view (n) +(defun gnus-uu-decode-postscript-view (&optional n) "Gets and views the current article." (interactive "P") (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic))) @@ -568,8 +633,8 @@ The headers will be included in the sequence they are matched.") (read-file-name "Save in dir: " gnus-uu-default-dir gnus-uu-default-dir t)))) - (gnus-uu-decode-with-method 'gnus-uu-decode-postscript-article n dir)) - + (gnus-uu-decode-with-method 'gnus-uu-decode-postscript-article + n dir nil nil t)) (defun gnus-uu-decode-postscript-and-save-view (n dir) "Decodes, views and saves the resulting file." @@ -584,52 +649,58 @@ The headers will be included in the sequence they are matched.") ;; Internal functions. -(defun gnus-uu-decode-with-method (method n &optional save not-insert scan) +(defun gnus-uu-decode-with-method (method n &optional save not-insert + scan cdir) (gnus-uu-initialize scan) (if save (setq gnus-uu-default-dir save)) + ;; Create the directory we save to. + (when (and scan cdir save + (not (file-exists-p save))) + (make-directory save t)) (let ((articles (gnus-uu-get-list-of-articles n)) files) (setq files (gnus-uu-grab-articles articles method t)) (let ((gnus-current-article (car articles))) (and scan (setq files (gnus-uu-scan-directory gnus-uu-work-dir)))) (and save (gnus-uu-save-files files save)) - (setq files (gnus-uu-unpack-files files)) - (gnus-uu-add-file (mapcar (lambda (file) (cdr (assq 'name file))) files)) + (if (eq gnus-uu-do-not-unpack-archives nil) + (setq files (gnus-uu-unpack-files files))) (setq files (nreverse (gnus-uu-get-actions files))) - (or not-insert (gnus-summary-insert-pseudos files save)))) + (or not-insert (not gnus-insert-pseudo-articles) + (gnus-summary-insert-pseudos files save)))) -;; Return a list of files in dir. -(defun gnus-uu-scan-directory (dir) +(defun gnus-uu-scan-directory (dir &optional rec) + "Return a list of all files under DIR." (let ((files (directory-files dir t)) - dirs out) - (while files - (cond ((string-match "/\\.\\.?$" (car files))) - ((file-directory-p (car files)) - (setq dirs (cons (car files) dirs))) - (t (setq out (cons (list (cons 'name (car files)) - (cons 'article gnus-current-article)) - out)))) - (setq files (cdr files))) - (apply 'nconc out (mapcar (lambda (d) (gnus-uu-scan-directory d)) - dirs)))) + out file) + (while (setq file (pop files)) + (unless (member (file-name-nondirectory file) '("." "..")) + (push (list (cons 'name file) + (cons 'article gnus-current-article)) + out) + (when (file-directory-p file) + (setq out (nconc (gnus-uu-scan-directory file t) out))))) + (if rec + out + (nreverse out)))) (defun gnus-uu-save-files (files dir) + "Save FILES in DIR." (let ((len (length files)) - to-file file) - (while files - (and - (setq file (cdr (assq 'name (car files)))) - (file-exists-p file) - (progn - (setq to-file (if (file-directory-p dir) - (concat dir (file-name-nondirectory file)) - dir)) - (and (or (not (file-exists-p to-file)) - (gnus-y-or-n-p (format "%s exists; overwrite? " - to-file))) - (copy-file file to-file t t)))) - (setq files (cdr files))) - (message "Saved %d file%s" len (if (> len 1) "s" "")))) + (reg (concat "^" (regexp-quote gnus-uu-work-dir))) + to-file file fromdir) + (while (setq file (cdr (assq 'name (pop files)))) + (when (file-exists-p file) + (string-match reg file) + (setq fromdir (substring file (match-end 0))) + (if (file-directory-p file) + (unless (file-exists-p (concat dir fromdir)) + (make-directory (concat dir fromdir) t)) + (setq to-file (concat dir fromdir)) + (when (or (not (file-exists-p to-file)) + (gnus-y-or-n-p (format "%s exists; overwrite? " to-file))) + (copy-file file to-file t t))))) + (gnus-message 5 "Saved %d file%s" len (if (= len 1) "" "s")))) ;; Functions for saving and possibly digesting articles without ;; any decoding. @@ -657,7 +728,13 @@ The headers will be included in the sequence they are matched.") ((eq in-state 'last) (list 'end)) (t (list 'middle))))) (t + (let ((header (gnus-summary-article-header))) + (setq gnus-uu-digest-from-subject + (cons (cons (mail-header-from header) + (mail-header-subject header)) + gnus-uu-digest-from-subject))) (let ((name (file-name-nondirectory gnus-uu-saved-article-name)) + (delim (concat "^" (make-string 30 ?-) "$")) beg subj headers headline sorthead body end-string state) (if (or (eq in-state 'first) (eq in-state 'first-and-last)) @@ -680,31 +757,37 @@ The headers will be included in the sequence they are matched.") (save-restriction (set-buffer buffer) (let (buffer-read-only) - (set-text-properties (point-min) (point-max) nil) + (gnus-set-text-properties (point-min) (point-max) nil) ;; These two are necessary for XEmacs 19.12 fascism. (put-text-property (point-min) (point-max) 'invisible nil) (put-text-property (point-min) (point-max) 'intangible nil)) (goto-char (point-min)) (re-search-forward "\n\n") + ;; Quote all 30-dash lines. + (save-excursion + (while (re-search-forward delim nil t) + (beginning-of-line) + (delete-char 1) + (insert " "))) (setq body (buffer-substring (1- (point)) (point-max))) - (narrow-to-region 1 (point)) + (narrow-to-region (point-min) (point)) (if (not (setq headers gnus-uu-digest-headers)) (setq sorthead (buffer-substring (point-min) (point-max))) (while headers (setq headline (car headers)) (setq headers (cdr headers)) (goto-char (point-min)) - (if (re-search-forward headline nil t) - (setq sorthead - (concat sorthead - (buffer-substring - (match-beginning 0) - (or (and (re-search-forward "^[^ \t]" nil t) - (1- (point))) - (progn (forward-line 1) (point))))))))) + (while (re-search-forward headline nil t) + (setq sorthead + (concat sorthead + (buffer-substring + (match-beginning 0) + (or (and (re-search-forward "^[^ \t]" nil t) + (1- (point))) + (progn (forward-line 1) (point))))))))) (widen))) - (insert sorthead)(goto-char (point-max)) - (insert body)(goto-char (point-max)) + (insert sorthead) (goto-char (point-max)) + (insert body) (goto-char (point-max)) (insert (concat "\n" (make-string 30 ?-) "\n\n")) (goto-char beg) (if (re-search-forward "^Subject: \\(.*\\)$" nil t) @@ -795,12 +878,10 @@ The headers will be included in the sequence they are matched.") (setq end-char (point)) (set-buffer (get-buffer-create gnus-uu-output-buffer-name)) (insert-buffer-substring process-buffer start-char end-char) - (setq file-name (concat gnus-uu-work-dir (cdr gnus-article-current) ".ps")) + (setq file-name (concat gnus-uu-work-dir + (cdr gnus-article-current) ".ps")) (write-region (point-min) (point-max) file-name) - (setq state (list file-name'begin 'end)) - - )) - ) + (setq state (list file-name 'begin 'end))))) state)) @@ -816,9 +897,8 @@ The headers will be included in the sequence they are matched.") (setcar files (nconc (list (if (string= action "gnus-uu-archive") (cons 'action "file") (cons 'action action)) - (cons 'execute (if (string-match "%" action) - (format action name) - (concat action " " name)))) + (cons 'execute (gnus-uu-command + action name))) (car files)))) (setq files (cdr files))) ofiles)) @@ -926,27 +1006,28 @@ The headers will be included in the sequence they are matched.") ;; non-nil, only unread articles are chosen. If DO-NOT-TRANSLATE is ;; non-nil, article names are not equalized before sorting. (let ((subject (or subject - (gnus-uu-reginize-string (gnus-summary-subject-string)))) + (gnus-uu-reginize-string (gnus-summary-article-subject)))) list-of-subjects) (save-excursion (if (not subject) () ;; Collect all subjects matching subject. (let ((case-fold-search t) - subj mark) - (goto-char (point-min)) - (while (not (eobp)) - (and (setq subj (gnus-summary-subject-string)) - (string-match subject subj) + (data gnus-newsgroup-data) + subj mark d) + (while data + (setq d (pop data)) + (and (not (gnus-data-pseudo-p d)) (or (not only-unread) - (= (setq mark (gnus-summary-article-mark)) + (= (setq mark (gnus-data-mark d)) gnus-unread-mark) (= mark gnus-ticked-mark) (= mark gnus-dormant-mark)) + (setq subj (mail-header-subject (gnus-data-header d))) + (string-match subject subj) (setq list-of-subjects - (cons (cons subj (gnus-summary-article-number)) - list-of-subjects))) - (forward-line 1))) + (cons (cons subj (gnus-data-number d)) + list-of-subjects))))) ;; Expand numbers, sort, and return the list of article ;; numbers. @@ -969,7 +1050,7 @@ The headers will be included in the sequence they are matched.") (buffer-disable-undo (current-buffer)) (while string-list (erase-buffer) - (insert (car (car string-list))) + (insert (caar string-list)) ;; Translate multiple spaces to one space. (goto-char (point-min)) (while (re-search-forward "[ \t]+" nil t) @@ -1038,132 +1119,151 @@ The headers will be included in the sequence they are matched.") ;; ;; This function returns a list of files decoded if the grabbing and ;; the process-function has been successful and nil otherwise. -(defun gnus-uu-grab-articles - (articles process-function &optional sloppy limit no-errors) +(defun gnus-uu-grab-articles (articles process-function + &optional sloppy limit no-errors) (let ((state 'first) - has-been-begin article result-file result-files process-state - article-buffer) + has-been-begin article result-file result-files process-state + gnus-summary-display-article-function + gnus-article-display-hook gnus-article-prepare-hook + article-series files) - (if (not (gnus-server-opened gnus-current-select-method)) - (progn - (gnus-start-news-server) - (gnus-request-group gnus-newsgroup-name))) - - (setq gnus-uu-has-been-grabbed nil) - (while (and articles (not (memq 'error process-state)) (or sloppy (not (memq 'end process-state)))) - (setq article (car articles)) - (setq articles (cdr articles)) - (setq gnus-uu-has-been-grabbed (cons article gnus-uu-has-been-grabbed)) - - (if (eq articles ()) - (if (eq state 'first) - (setq state 'first-and-last) - (setq state 'last))) - - (message "Getting article %d, %s" article (gnus-uu-part-number article)) - - (if (not (= (or gnus-current-article 0) article)) - (let ((nntp-async-number nil)) - (gnus-request-article article gnus-newsgroup-name - nntp-server-buffer) - (setq gnus-last-article gnus-current-article) - (setq gnus-current-article article) - (setq gnus-article-current (cons gnus-newsgroup-name article)) - (if (stringp nntp-server-buffer) - (setq article-buffer nntp-server-buffer) - (setq article-buffer (buffer-name nntp-server-buffer)))) - (gnus-summary-stop-page-breaking) - (setq article-buffer gnus-article-buffer)) - - (buffer-disable-undo article-buffer) - ;; Mark article as read. - (and (memq article gnus-newsgroup-processable) - (gnus-summary-remove-process-mark article)) - (run-hooks 'gnus-mark-article-hook) - - (setq process-state (funcall process-function article-buffer state)) - - (if (or (memq 'begin process-state) - (and (or (eq state 'first) (eq state 'first-and-last)) - (memq 'ok process-state))) - (progn - (if has-been-begin - (if (and result-file (file-exists-p result-file)) - (delete-file result-file))) - (if (memq 'begin process-state) - (setq result-file (car process-state))) - (setq has-been-begin t))) - - (if (memq 'end process-state) - (progn - (setq gnus-uu-has-been-grabbed nil) - (setq result-files (cons (list (cons 'name result-file) - (cons 'article article)) - result-files)) - (setq has-been-begin nil) - (and limit (= (length result-files) limit) - (setq articles nil)))) - - (if (and (or (eq state 'last) (eq state 'first-and-last)) - (not (memq 'end process-state))) - (if (and result-file (file-exists-p result-file)) - (delete-file result-file))) + (setq article (pop articles)) + (push article article-series) - (if (not (memq 'wrong-type process-state)) - () - (if gnus-uu-unmark-articles-not-decoded - (gnus-summary-tick-article article t))) + (unless articles + (if (eq state 'first) + (setq state 'first-and-last) + (setq state 'last))) + (let ((part (gnus-uu-part-number article))) + (gnus-message 6 "Getting article %d%s..." + article (if (string= part "") "" (concat ", " part)))) + (gnus-summary-display-article article) + + ;; Push the article to the processing function. + (save-excursion + (set-buffer gnus-original-article-buffer) + (let ((buffer-read-only nil)) + (save-excursion + (set-buffer gnus-summary-buffer) + (setq process-state + (funcall process-function + gnus-original-article-buffer state))))) + + (gnus-summary-remove-process-mark article) + + ;; If this is the beginning of a decoded file, we push it + ;; on to a list. + (when (or (memq 'begin process-state) + (and (or (eq state 'first) + (eq state 'first-and-last)) + (memq 'ok process-state))) + (if has-been-begin + ;; If there is a `result-file' here, that means that the + ;; file was unsuccessfully decoded, so we delete it. + (when (and result-file + (file-exists-p result-file)) + (delete-file result-file))) + (when (memq 'begin process-state) + (setq result-file (car process-state))) + (setq has-been-begin t)) + + ;; Check whether we have decoded one complete file. + (when (memq 'end process-state) + (setq article-series nil) + (setq has-been-begin nil) + (if (stringp result-file) + (setq files (list result-file)) + (setq files result-file)) + (setq result-file (car files)) + (while files + (push (list (cons 'name (pop files)) + (cons 'article article)) + result-files)) + ;; Allow user-defined functions to be run on this file. + (when gnus-uu-grabbed-file-functions + (let ((funcs gnus-uu-grabbed-file-functions)) + (unless (listp funcs) + (setq funcs (list funcs))) + (while funcs + (funcall (pop funcs) result-file)))) + ;; Check whether we have decoded enough articles. + (and limit (= (length result-files) limit) + (setq articles nil))) + + ;; If this is the last article to be decoded, and + ;; we still haven't reached the end, then we delete + ;; the partially decoded file. + (and (or (eq state 'last) (eq state 'first-and-last)) + (not (memq 'end process-state)) + result-file + (file-exists-p result-file) + (delete-file result-file)) + + ;; If this was a file of the wrong sort, then + (when (and (or (memq 'wrong-type process-state) + (memq 'error process-state)) + gnus-uu-unmark-articles-not-decoded) + (gnus-summary-tick-article article t)) + + ;; Set the new series state. (if (and (not has-been-begin) (not sloppy) (or (memq 'end process-state) (memq 'middle process-state))) (progn (setq process-state (list 'error)) - (message "No begin part at the beginning") + (gnus-message 2 "No begin part at the beginning") (sleep-for 2)) (setq state 'middle))) - ;; Make sure the last article is put in the article buffer & fix - ;; windows etc. - - (if (not (string= article-buffer gnus-article-buffer)) - (save-excursion - (set-buffer (get-buffer-create gnus-article-buffer)) - (let ((buffer-read-only nil)) - (widen) - (erase-buffer) - (insert-buffer-substring article-buffer) - (gnus-set-mode-line 'article) - (goto-char (point-min))))) - - (gnus-set-mode-line 'summary) - + ;; When there are no result-files, then something must be wrong. (if result-files - () - (if (not has-been-begin) - (if (not no-errors) (message "Wrong type file")) - (if (memq 'error process-state) - (setq result-files nil) - (if (not (or (memq 'ok process-state) - (memq 'end process-state))) - (progn - (if (not no-errors) - (message "End of articles reached before end of file")) - (setq result-files nil)) - (gnus-uu-unmark-list-of-grabbed))))) + (message "") + (cond + ((not has-been-begin) + (gnus-message 2 "Wrong type file")) + ((memq 'error process-state) + (gnus-message 2 "An error occurred during decoding")) + ((not (or (memq 'ok process-state) + (memq 'end process-state))) + (gnus-message 2 "End of articles reached before end of file"))) + ;; Make unsuccessfully decoded articles unread. + (when gnus-uu-unmark-articles-not-decoded + (while article-series + (gnus-summary-tick-article (pop article-series) t)))) + result-files)) +(defun gnus-uu-grab-view (file) + "View FILE using the gnus-uu methods." + (let ((action (gnus-uu-get-action file))) + (gnus-execute-command + (if (string-match "%" action) + (format action file) + (concat action " " file)) + (eq gnus-view-pseudos 'not-confirm)))) + +(defun gnus-uu-grab-move (file) + "Move FILE to somewhere." + (when gnus-uu-default-dir + (let ((to-file (concat (file-name-as-directory gnus-uu-default-dir) + (file-name-nondirectory file)))) + (rename-file file to-file) + (unless (file-exists-p file) + (make-symbolic-link to-file file))))) + (defun gnus-uu-part-number (article) - (let ((subject (mail-header-subject (gnus-get-header-by-number article)))) - (if (string-match "[0-9]+ */[0-9]+\\|[0-9]+ * of *[0-9]+" - subject) - (substring subject (match-beginning 0) (match-end 0)) + (let* ((header (gnus-summary-article-header article)) + (subject (and header (mail-header-subject header)))) + (if (and subject + (string-match "[0-9]+ */[0-9]+\\|[0-9]+ * of *[0-9]+" subject)) + (match-string 0 subject) ""))) (defun gnus-uu-uudecode-sentinel (process event) @@ -1171,117 +1271,100 @@ The headers will be included in the sequence they are matched.") (defun gnus-uu-uustrip-article (process-buffer in-state) ;; Uudecodes a file asynchronously. - (let ((state (list 'ok)) - (process-connection-type nil) - start-char pst name-beg name-end) - (save-excursion - (set-buffer process-buffer) - (let ((case-fold-search nil) - (buffer-read-only nil)) + (save-excursion + (set-buffer process-buffer) + (let ((state (list 'wrong-type)) + process-connection-type case-fold-search buffer-read-only + files start-char) + (goto-char (point-min)) - (goto-char (point-min)) + ;; Deal with ^M at the end of the lines. + (when gnus-uu-kill-carriage-return + (save-excursion + (while (search-forward "\r" nil t) + (delete-backward-char 1)))) - (if gnus-uu-kill-carriage-return - (progn - (while (search-forward "\r" nil t) - (delete-backward-char 1)) - (goto-char (point-min)))) - - (if (not (re-search-forward gnus-uu-begin-string nil t)) - (if (not (re-search-forward gnus-uu-body-line nil t)) - (setq state (list 'wrong-type)))) - - (if (memq 'wrong-type state) - () - (beginning-of-line) - (setq start-char (point)) - - (if (looking-at gnus-uu-begin-string) - (progn - (setq name-end (match-end 1) - name-beg (match-beginning 1)) - ;; Remove any non gnus-uu-body-line right after start. - (forward-line 1) - (or (looking-at gnus-uu-body-line) - (gnus-delete-line)) - - ; Replace any slashes and spaces in file names before decoding - (goto-char name-beg) - (while (re-search-forward "/" name-end t) - (replace-match ",")) - (goto-char name-beg) - (while (re-search-forward " " name-end t) - (replace-match "_")) - (goto-char name-beg) - (if (re-search-forward "_*$" name-end t) - (replace-match "")) - - (setq gnus-uu-file-name (buffer-substring name-beg name-end)) - (and gnus-uu-uudecode-process - (setq pst (process-status - (or gnus-uu-uudecode-process "nevair"))) - (if (or (eq pst 'stop) (eq pst 'run)) - (progn - (delete-process gnus-uu-uudecode-process) - (gnus-uu-unmark-list-of-grabbed t)))) - (if (get-process "*uudecode*") - (delete-process "*uudecode*")) - (setq gnus-uu-uudecode-process - (start-process - "*uudecode*" - (get-buffer-create gnus-uu-output-buffer-name) - "sh" "-c" - (format "cd %s ; uudecode" gnus-uu-work-dir))) - (set-process-sentinel - gnus-uu-uudecode-process 'gnus-uu-uudecode-sentinel) - (setq state (list 'begin)) - (gnus-uu-add-file (concat gnus-uu-work-dir gnus-uu-file-name))) - (setq state (list 'middle))) - - (goto-char (point-max)) + (while (or (re-search-forward gnus-uu-begin-string nil t) + (re-search-forward gnus-uu-body-line nil t)) + (setq state (list 'ok)) + ;; Ok, we are at the first uucoded line. + (beginning-of-line) + (setq start-char (point)) - (re-search-backward - (concat gnus-uu-body-line "\\|" gnus-uu-end-string) nil t) - (beginning-of-line) + (if (not (looking-at gnus-uu-begin-string)) + (setq state (list 'middle)) + ;; This is the beginning of an uuencoded article. + ;; We replace certain characters that could make things messy. + (setq gnus-uu-file-name + (let ((nnheader-file-name-translation-alist + '((?/ . ?,) (? . ?_) (?* . ?_) (?$ . ?_)))) + (nnheader-translate-file-chars (match-string 1)))) - (if (looking-at gnus-uu-end-string) - (setq state (cons 'end state))) + ;; Remove any non gnus-uu-body-line right after start. (forward-line 1) + (while (and (not (eobp)) + (not (looking-at gnus-uu-body-line))) + (gnus-delete-line)) + + ;; If a process is running, we kill it. + (when (and gnus-uu-uudecode-process + (memq (process-status gnus-uu-uudecode-process) + '(run stop))) + (delete-process gnus-uu-uudecode-process) + (gnus-uu-unmark-list-of-grabbed t)) + + ;; Start a new uudecoding process. + (setq gnus-uu-uudecode-process + (start-process + "*uudecode*" + (get-buffer-create gnus-uu-output-buffer-name) + shell-file-name shell-command-switch + (format "cd %s ; uudecode" gnus-uu-work-dir))) + (set-process-sentinel + gnus-uu-uudecode-process 'gnus-uu-uudecode-sentinel) + (setq state (list 'begin)) + (push (concat gnus-uu-work-dir gnus-uu-file-name) files)) + + ;; We look for the end of the thing to be decoded. + (if (re-search-forward gnus-uu-end-string nil t) + (setq state (cons 'end state)) + (goto-char (point-max)) + (re-search-backward gnus-uu-body-line nil t)) + + (forward-line 1) - (and gnus-uu-uudecode-process - (setq pst (process-status - (or gnus-uu-uudecode-process "nevair"))) - (if (or (eq pst 'run) (eq pst 'stop)) - (progn - (if gnus-uu-correct-stripped-uucode - (progn - (gnus-uu-check-correct-stripped-uucode - start-char (point)) - (goto-char (point-max)) - (re-search-backward - (concat gnus-uu-body-line "\\|" - gnus-uu-end-string) - nil t) - (forward-line 1))) - - (condition-case nil - (process-send-region gnus-uu-uudecode-process - start-char (point)) - (error - (progn - (delete-process gnus-uu-uudecode-process) - (message "gnus-uu: Couldn't uudecode") - ; (sleep-for 2) - (setq state (list 'wrong-type))))) - - (if (memq 'end state) - (accept-process-output gnus-uu-uudecode-process))) - (setq state (list 'wrong-type)))) - (if (not gnus-uu-uudecode-process) - (setq state (list 'wrong-type))))) + (when gnus-uu-uudecode-process + (when (memq (process-status gnus-uu-uudecode-process) '(run stop)) + ;; Try to correct mishandled uucode. + (when gnus-uu-correct-stripped-uucode + (gnus-uu-check-correct-stripped-uucode start-char (point))) + + ;; Send the text to the process. + (condition-case nil + (process-send-region + gnus-uu-uudecode-process start-char (point)) + (error + (progn + (delete-process gnus-uu-uudecode-process) + (gnus-message 2 "gnus-uu: Couldn't uudecode") + (setq state (list 'wrong-type))))) + + (if (memq 'end state) + (progn + ;; Send an EOF, just in case. + (condition-case () + (process-send-eof gnus-uu-uudecode-process) + (error nil)) + (while (memq (process-status gnus-uu-uudecode-process) + '(open run)) + (accept-process-output gnus-uu-uudecode-process 1))) + (when (or (not gnus-uu-uudecode-process) + (not (memq (process-status gnus-uu-uudecode-process) + '(run stop)))) + (setq state (list 'wrong-type))))))) (if (memq 'begin state) - (cons (concat gnus-uu-work-dir gnus-uu-file-name) state) + (cons (if (= (length files) 1) (car files) files) state) state)))) ;; This function is used by `gnus-uu-grab-articles' to treat @@ -1297,9 +1380,9 @@ The headers will be included in the sequence they are matched.") (beginning-of-line) (setq start-char (point)) (call-process-region - start-char (point-max) "sh" nil + start-char (point-max) shell-file-name nil (get-buffer-create gnus-uu-output-buffer-name) nil - "-c" (concat "cd " gnus-uu-work-dir " ; sh")))) + shell-command-switch (concat "cd " gnus-uu-work-dir " ; sh")))) state)) ;; Returns the name of what the shar file is going to unpack. @@ -1334,7 +1417,7 @@ The headers will be included in the sequence they are matched.") (setq rule (car action-list)) (setq action-list (cdr action-list)) (if (string-match (car rule) file-name) - (setq action (car (cdr rule)))))) + (setq action (cadr rule))))) action)) (defun gnus-uu-treat-archive (file-path) @@ -1361,13 +1444,13 @@ The headers will be included in the sequence they are matched.") (set-buffer (get-buffer-create gnus-uu-output-buffer-name)) (erase-buffer)) - (message "Unpacking: %s..." (gnus-uu-command action file-path)) + (gnus-message 5 "Unpacking: %s..." (gnus-uu-command action file-path)) - (if (= 0 (call-process "sh" nil + (if (= 0 (call-process shell-file-name nil (get-buffer-create gnus-uu-output-buffer-name) - nil "-c" command)) + nil shell-command-switch command)) (message "") - (message "Error during unpacking of archive") + (gnus-message 2 "Error during unpacking of archive") (setq did-unpack nil)) (if (member action gnus-uu-destructive-archivers) @@ -1389,20 +1472,18 @@ The headers will be included in the sequence they are matched.") ;; Go through FILES and look for files to unpack. (let* ((totfiles (gnus-uu-ls-r gnus-uu-work-dir)) (ofiles files) - file did-unpack file-entry) - (gnus-uu-add-file totfiles) + file did-unpack) (while files - (setq file (cdr (setq file-entry (assq 'name (car files))))) + (setq file (cdr (assq 'name (car files)))) (if (and (not (member file ignore)) (equal (gnus-uu-get-action (file-name-nondirectory file)) "gnus-uu-archive")) (progn (setq did-unpack (cons file did-unpack)) (or (gnus-uu-treat-archive file) - (message "Error during unpacking of %s" file)) + (gnus-message 2 "Error during unpacking of %s" file)) (let* ((newfiles (gnus-uu-ls-r gnus-uu-work-dir)) (nfiles newfiles)) - (gnus-uu-add-file newfiles) (while nfiles (or (member (car nfiles) totfiles) (setq ofiles (cons (list (cons 'name (car nfiles)) @@ -1434,42 +1515,43 @@ The headers will be included in the sequence they are matched.") (while files (setq file (car files)) (setq files (cdr files)) - (or (string-match "/\\.\\.?$" file) + (or (member (file-name-nondirectory file) '("." "..")) (setq out (cons file out)))) (setq out (nreverse out)) out)) (defun gnus-uu-check-correct-stripped-uucode (start end) - (let (found beg length) - (if (not gnus-uu-correct-stripped-uucode) - () - (goto-char start) + (save-excursion + (let (found beg length) + (if (not gnus-uu-correct-stripped-uucode) + () + (goto-char start) - (if (re-search-forward " \\|`" end t) - (progn - (goto-char start) - (while (not (eobp)) - (progn - (if (looking-at "\n") (replace-match "")) - (forward-line 1)))) - - (while (not (eobp)) - (if (looking-at (concat gnus-uu-begin-string "\\|" - gnus-uu-end-string)) - () - (if (not found) + (if (re-search-forward " \\|`" end t) + (progn + (goto-char start) + (while (not (eobp)) (progn - (beginning-of-line) - (setq beg (point)) - (end-of-line) - (setq length (- (point) beg)))) - (setq found t) - (beginning-of-line) - (setq beg (point)) - (end-of-line) - (if (not (= length (- (point) beg))) - (insert (make-string (- length (- (point) beg)) ? )))) - (forward-line 1)))))) + (if (looking-at "\n") (replace-match "")) + (forward-line 1)))) + + (while (not (eobp)) + (if (looking-at (concat gnus-uu-begin-string "\\|" + gnus-uu-end-string)) + () + (if (not found) + (progn + (beginning-of-line) + (setq beg (point)) + (end-of-line) + (setq length (- (point) beg)))) + (setq found t) + (beginning-of-line) + (setq beg (point)) + (end-of-line) + (if (not (= length (- (point) beg))) + (insert (make-string (- length (- (point) beg)) ? )))) + (forward-line 1))))))) (defvar gnus-uu-tmp-alist nil) @@ -1492,7 +1574,6 @@ The headers will be included in the sequence they are matched.") (setq gnus-uu-work-dir (make-temp-name (concat gnus-uu-tmp-dir "gnus"))) - (gnus-uu-add-file gnus-uu-work-dir) (if (not (file-directory-p gnus-uu-work-dir)) (gnus-make-directory gnus-uu-work-dir)) (set-file-modes gnus-uu-work-dir 448) @@ -1505,44 +1586,12 @@ The headers will be included in the sequence they are matched.") (defun gnus-uu-clean-up () (let (buf pst) (and gnus-uu-uudecode-process - (setq pst (process-status (or gnus-uu-uudecode-process "nevair"))) - (if (or (eq pst 'stop) (eq pst 'run)) - (delete-process gnus-uu-uudecode-process))) + (memq (process-status (or gnus-uu-uudecode-process "nevair")) + '(stop run)) + (delete-process gnus-uu-uudecode-process)) (and (setq buf (get-buffer gnus-uu-output-buffer-name)) (kill-buffer buf)))) -;; `gnus-uu-check-for-generated-files' deletes any generated files that -;; hasn't been deleted, if, for instance, the user terminated decoding -;; with `C-g'. -(defun gnus-uu-check-for-generated-files () - (let (file dirs) - (while gnus-uu-generated-file-list - (setq file (car gnus-uu-generated-file-list)) - (setq gnus-uu-generated-file-list (cdr gnus-uu-generated-file-list)) - (if (not (string-match "/\\.[\\.]?$" file)) - (progn - (if (file-directory-p file) - (setq dirs (cons file dirs)) - (if (file-exists-p file) - (delete-file file)))))) - (setq dirs (nreverse dirs)) - (while dirs - (setq file (car dirs)) - (setq dirs (cdr dirs)) - (if (file-directory-p file) - (if (string-match "/$" file) - (delete-directory (substring file 0 (match-beginning 0))) - (delete-directory file)))))) - -;; Add a file (or a list of files) to be checked (and deleted if it/they -;; still exists upon exiting the newsgroup). -(defun gnus-uu-add-file (file) - (if (stringp file) - (setq gnus-uu-generated-file-list - (cons file gnus-uu-generated-file-list)) - (setq gnus-uu-generated-file-list - (append file gnus-uu-generated-file-list)))) - ;; Inputs an action and a file and returns a full command, putting ;; quotes round the file name and escaping any quotes in the file name. (defun gnus-uu-command (action file) @@ -1558,11 +1607,28 @@ The headers will be included in the sequence they are matched.") (format action ofile) (concat action " " ofile)))) +(defun gnus-uu-delete-work-dir (&optional dir) + "Delete recursively all files and directories under `gnus-uu-work-dir'." + (if dir + (gnus-message 7 "Deleting directory %s..." dir) + (setq dir gnus-uu-work-dir)) + (when (and dir + (file-exists-p dir)) + (let ((files (directory-files dir t nil t)) + file) + (while (setq file (pop files)) + (unless (member (file-name-nondirectory file) '("." "..")) + (if (file-directory-p file) + (gnus-uu-delete-work-dir file) + (gnus-message 9 "Deleting file %s..." file) + (delete-file file)))) + (delete-directory dir))) + (gnus-message 7 "")) ;; Initializing (add-hook 'gnus-exit-group-hook 'gnus-uu-clean-up) -(add-hook 'gnus-exit-group-hook 'gnus-uu-check-for-generated-files) +(add-hook 'gnus-exit-group-hook 'gnus-uu-delete-work-dir) @@ -1570,9 +1636,6 @@ The headers will be included in the sequence they are matched.") ;;; uuencoded posting ;;; -(require 'sendmail) -(require 'rnews) - ;; Any function that is to be used as and encoding method will take two ;; parameters: PATH-NAME and FILE-NAME. (E.g. "/home/gaga/spiral.jpg" ;; and "spiral.jpg", respectively.) The function should return nil if @@ -1636,8 +1699,6 @@ is t.") "Inserts an encoded file in the buffer. The user will be asked for a file name." (interactive) - (if (not (eq (current-buffer) (get-buffer gnus-post-news-buffer))) - (error "Not in post-news buffer")) (save-excursion (setq gnus-uu-post-inserted-file-name (gnus-uu-post-insert-binary)))) @@ -1673,7 +1734,7 @@ The user will be asked for a file name." file-name)) (insert (format "Content-Transfer-Encoding: %s\n\n" encoding)) (save-restriction - (set-buffer gnus-post-news-buffer) + (set-buffer gnus-message-buffer) (goto-char (point-min)) (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$")) (forward-line -1) @@ -1687,15 +1748,13 @@ The user will be asked for a file name." ;; Encodes a file PATH with COMMAND, leaving the result in the ;; current buffer. (defun gnus-uu-post-encode-file (command path file-name) - (= 0 (call-process "sh" nil t nil "-c" + (= 0 (call-process shell-file-name nil t nil shell-command-switch (format "%s %s %s" command path file-name)))) (defun gnus-uu-post-news-inews () "Posts the composed news article and encoded file. If no file has been included, the user will be asked for a file." (interactive) - (if (not (eq (current-buffer) (get-buffer gnus-post-news-buffer))) - (error "Not in post news buffer")) (let (file-name) @@ -1704,10 +1763,10 @@ If no file has been included, the user will be asked for a file." (setq file-name (gnus-uu-post-insert-binary))) (if gnus-uu-post-threaded - (let ((gnus-required-headers - (if (memq 'Message-ID gnus-required-headers) - gnus-required-headers - (cons 'Message-ID gnus-required-headers))) + (let ((message-required-news-headers + (if (memq 'Message-ID message-required-news-headers) + message-required-news-headers + (cons 'Message-ID message-required-news-headers))) gnus-inews-article-hook) (setq gnus-inews-article-hook (if (listp gnus-inews-article-hook) @@ -1756,7 +1815,7 @@ If no file has been included, the user will be asked for a file." (get-buffer-create uuencode-buffer-name))) (erase-buffer) (funcall gnus-uu-post-encode-method file-path file-name)) - (insert-buffer uubuf) + (insert-buffer-substring uubuf) (error "Encoding unsuccessful")) (kill-buffer uubuf)) file-name)) @@ -1811,7 +1870,7 @@ If no file has been included, the user will be asked for a file." (progn (end-of-line) (insert (format " (0/%d)" parts)))) - (gnus-inews-news)) + (message-send)) (save-excursion (setq i 1) @@ -1874,7 +1933,8 @@ If no file has been included, the user will be asked for a file." (forward-line 1))) (insert beg-line) (insert "\n") - (gnus-inews-news))) + (let (message-sent-message-via) + (message-send)))) (and (setq buf (get-buffer send-buffer-name)) (kill-buffer buf)) diff --git a/lisp/gnus-vis.el b/lisp/gnus-vis.el index c139aebc201..baddc09e087 100644 --- a/lisp/gnus-vis.el +++ b/lisp/gnus-vis.el @@ -1,6 +1,5 @@ ;;; gnus-vis.el --- display-oriented parts of Gnus - -;; Copyright (C) 1995 Free Software Foundation, Inc. +;; Copyright (C) 1995,96 Free Software Foundation, Inc. ;; Author: Lars Magne Ingebrigtsen ;; Per Abrahamsen @@ -31,6 +30,9 @@ (require 'gnus-ems) (require 'easymenu) (require 'custom) +(require 'browse-url) +(require 'gnus-score) +(eval-when-compile (require 'cl)) (defvar gnus-group-menu-hook nil "*Hook run after the creation of the group mode menu.") @@ -41,12 +43,6 @@ (defvar gnus-article-menu-hook nil "*Hook run after the creation of the article mode menu.") -(defvar gnus-server-menu-hook nil - "*Hook run after the creation of the server mode menu.") - -(defvar gnus-browse-menu-hook nil - "*Hook run after the creation of the browse mode menu.") - ;;; Summary highlights. ;(defvar gnus-summary-highlight-properties @@ -212,17 +208,21 @@ ;(defvar gnus-signature-face 'italic ; "Face used for signature.") +(defvar gnus-button-url-regexp "\\b\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?[-\\wa-zA-Z0-9_=!?#$@~`%&*+|\\/.,]*[-\\wa-zA-Z0-9_=#$@~`%&*+|\\/]" + "*Regular expression that matches URLs.") + (defvar gnus-button-alist - '(("in\\( +article\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2 - (assq (count-lines (point-min) (match-end 0)) - gnus-cite-attribution-alist) + `(("\\bin\\( +article\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2 + t gnus-button-message-id 3) + ("\\(\n\t ]*\\)>?\\)" 1 t gnus-button-message-id 3) + ("\\( \n\t]+\\)>?" 0 t gnus-button-reply 2) ;; This is how URLs _should_ be embedded in text... - ("]*\\)>" 0 t gnus-button-url 1) + ("]*\\)>" 0 t gnus-button-url 1) ;; Next regexp stolen from highlight-headers.el. ;; Modified by Vladimir Alexiev. - ("\\b\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?[-a-zA-Z0-9_=?#$@~`%&*+|\\/.,]*[-a-zA-Z0-9_=#$@~`%&*+|\\/]" 0 t gnus-button-url 0)) - "Alist of regexps matching buttons in an article. + (,gnus-button-url-regexp 0 t gnus-button-url 0)) + "Alist of regexps matching buttons in article bodies. Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where REGEXP: is the string matching text around the button, @@ -235,25 +235,53 @@ PAR: is a number of a regexp grouping whose text will be passed to CALLBACK. CALLBACK can also be a variable, in that case the value of that variable it the real callback function.") +(defvar gnus-header-button-alist + `(("^\\(References\\|Message-I[Dd]\\):" "<[^>]+>" + 0 t gnus-button-message-id 0) + ("^\\(From\\|Reply-To\\): " ": *\\(.+\\)$" 1 t gnus-button-reply 0) + ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+" + 0 t gnus-button-mailto 0) + ("^X-[Uu][Rr][Ll]:" ,gnus-button-url-regexp 0 t gnus-button-url 0) + ("^[^:]+:" ,gnus-button-url-regexp 0 t gnus-button-url 0) + ("^[^:]+:" "\\(<\\(url: \\)?news:\\([^>\n ]*\\)>\\)" 1 t + gnus-button-message-id 3)) + "Alist of headers and regexps to match buttons in article heads. + +This alist is very similar to `gnus-button-alist', except that each +alist has an additional HEADER element first in each entry: + +\(HEADER REGEXP BUTTON FORM CALLBACK PAR) + +HEADER is a regexp to match a header. For a fuller explanation, see +`gnus-button-alist'.") + ;see gnus-cus.el ;(eval-when-compile ; (defvar browse-url-browser-function)) +;;; Group mode highlighting. + ;see gnus-cus.el -;(defvar gnus-button-url -; (cond ((boundp 'browse-url-browser-function) browse-url-browser-function) -; ((fboundp 'w3-fetch) 'w3-fetch) -; ((eq window-system 'x) 'gnus-netscape-open-url)) -; "*Function to fetch URL. -;The function will be called with one argument, the URL to fetch. -;Useful values of this function are: - -;w3-fetch: -; defined in the w3 emacs package by William M. Perry. -;gnus-netscape-open-url: -; open url in existing netscape, start netscape if none found. -;gnus-netscape-start-url: -; start new netscape with url.") +;(defvar gnus-group-highlight nil +; "Group lines are highlighted with the FACE for the first FORM which +;evaluate to a non-nil value. +; +;Point will be at the beginning of the line when FORM is evaluated. +;Variables bound when these forms are evaluated include: +; +;group: The group name. +;unread: The number of unread articles. +;method: The select method. +;mailp: Whether the select method is a mail method. +;level: The level of the group. +;score: The score of the group. +;ticked: The number of ticked articles in the group. +;") + + +;;; Internal variables. + +(defvar gnus-button-marker-list nil) @@ -277,49 +305,86 @@ variable it the real callback function.") (boundp 'gnus-group-reading-menu) (progn (easy-menu-define - gnus-group-reading-menu - gnus-group-mode-map - "" + gnus-group-reading-menu gnus-group-mode-map "" '("Group" - ["Read" gnus-group-read-group t] - ["Select" gnus-group-select-group t] - ["See old articles" gnus-group-select-group-all t] - ["Catch up" gnus-group-catchup-current t] - ["Catch up all articles" gnus-group-catchup-current-all t] - ["Check for new articles" gnus-group-get-new-news-this-group t] - ["Toggle subscription" gnus-group-unsubscribe-current-group t] - ["Kill" gnus-group-kill-group t] - ["Yank" gnus-group-yank-group t] - ["Describe" gnus-group-describe-group t] - ["Fetch FAQ" gnus-group-fetch-faq t] - ["Edit kill file" gnus-group-edit-local-kill t] - ["Expire articles" gnus-group-expire-articles t] - ["Set group level" gnus-group-set-current-level t] + ["Read" gnus-group-read-group (gnus-group-group-name)] + ["Select" gnus-group-select-group (gnus-group-group-name)] + ["See old articles" (gnus-group-select-group 'all) + :keys "C-u SPC" :active (gnus-group-group-name)] + ["Catch up" gnus-group-catchup-current (gnus-group-group-name)] + ["Catch up all articles" gnus-group-catchup-current-all + (gnus-group-group-name)] + ["Check for new articles" gnus-group-get-new-news-this-group + (gnus-group-group-name)] + ["Toggle subscription" gnus-group-unsubscribe-current-group + (gnus-group-group-name)] + ["Kill" gnus-group-kill-group (gnus-group-group-name)] + ["Yank" gnus-group-yank-group gnus-list-of-killed-groups] + ["Describe" gnus-group-describe-group (gnus-group-group-name)] + ["Fetch FAQ" gnus-group-fetch-faq (gnus-group-group-name)] + ["Edit kill file" gnus-group-edit-local-kill + (gnus-group-group-name)] + ;; Actually one should check, if any of the marked groups gives t for + ;; (gnus-check-backend-function 'request-expire-articles ...) + ["Expire articles" gnus-group-expire-articles + (or (and (gnus-group-group-name) + (gnus-check-backend-function + 'request-expire-articles + (gnus-group-group-name))) gnus-group-marked)] + ["Set group level" gnus-group-set-current-level + (gnus-group-group-name)] + ["Select quick" gnus-group-quick-select-group (gnus-group-group-name)] )) (easy-menu-define - gnus-group-group-menu - gnus-group-mode-map - "" + gnus-group-group-menu gnus-group-mode-map "" '("Groups" ("Listing" - ["List subscribed groups" gnus-group-list-groups t] - ["List all groups" gnus-group-list-all-groups t] - ["List groups matching..." gnus-group-list-matching t] - ["List killed groups" gnus-group-list-killed t] - ["List zombie groups" gnus-group-list-zombies t] + ["List unread subscribed groups" gnus-group-list-groups t] + ["List (un)subscribed groups" gnus-group-list-all-groups t] + ["List killed groups" gnus-group-list-killed gnus-killed-list] + ["List zombie groups" gnus-group-list-zombies gnus-zombie-list] + ["List level..." gnus-group-list-level t] ["Describe all groups" gnus-group-describe-all-groups t] - ["Group apropos" gnus-group-apropos t] - ["Group and description apropos" gnus-group-description-apropos t] - ["List groups matching..." gnus-group-list-matching t]) + ["Group apropos..." gnus-group-apropos t] + ["Group and description apropos..." gnus-group-description-apropos t] + ["List groups matching..." gnus-group-list-matching t] + ["List all groups matching..." gnus-group-list-all-matching t] + ["List active file" gnus-group-list-active t]) + ("Sort" + ["Default sort" gnus-group-sort-groups + (or (not (boundp 'gnus-topic-mode)) (not gnus-topic-mode))] + ["Sort by method" gnus-group-sort-groups-by-method + (or (not (boundp 'gnus-topic-mode)) (not gnus-topic-mode))] + ["Sort by rank" gnus-group-sort-groups-by-rank + (or (not (boundp 'gnus-topic-mode)) (not gnus-topic-mode))] + ["Sort by score" gnus-group-sort-groups-by-score + (or (not (boundp 'gnus-topic-mode)) (not gnus-topic-mode))] + ["Sort by level" gnus-group-sort-groups-by-level + (or (not (boundp 'gnus-topic-mode)) (not gnus-topic-mode))] + ["Sort by unread" gnus-group-sort-groups-by-unread + (or (not (boundp 'gnus-topic-mode)) (not gnus-topic-mode))] + ["Sort by name" gnus-group-sort-groups-by-alphabet + (or (not (boundp 'gnus-topic-mode)) (not gnus-topic-mode))]) ("Mark" - ["Mark group" gnus-group-mark-group t] - ["Unmark group" gnus-group-unmark-group t] - ["Mark region" gnus-group-mark-region t]) + ["Mark group" gnus-group-mark-group + (and (gnus-group-group-name) + (not (memq (gnus-group-group-name) gnus-group-marked)))] + ["Unmark group" gnus-group-unmark-group + (and (gnus-group-group-name) + (memq (gnus-group-group-name) gnus-group-marked))] + ["Unmark all" gnus-group-unmark-all-groups gnus-group-marked] + ["Mark regexp..." gnus-group-mark-regexp t] + ["Mark region" gnus-group-mark-region t] + ["Mark buffer" gnus-group-mark-buffer t] + ["Execute command" gnus-group-universal-argument + (or gnus-group-marked (gnus-group-group-name))]) ("Subscribe" ["Subscribe to random group" gnus-group-unsubscribe-group t] ["Kill all newsgroups in region" gnus-group-kill-region t] - ["Kill all zombie groups" gnus-group-kill-all-zombies t]) + ["Kill all zombie groups" gnus-group-kill-all-zombies + gnus-zombie-list] + ["Kill all groups on level..." gnus-group-kill-level t]) ("Foreign groups" ["Make a foreign group" gnus-group-make-group t] ["Add a directory group" gnus-group-make-directory-group t] @@ -328,34 +393,54 @@ variable it the real callback function.") ["Make a doc group" gnus-group-make-doc-group t] ["Make a kiboze group" gnus-group-make-kiboze-group t] ["Make a virtual group" gnus-group-make-empty-virtual t] - ["Add a group to a virtual" gnus-group-add-to-virtual t]) + ["Add a group to a virtual" gnus-group-add-to-virtual t] + ["Rename group" gnus-group-rename-group + (gnus-check-backend-function + 'request-rename-group (gnus-group-group-name))] + ["Delete group" gnus-group-delete-group + (gnus-check-backend-function + 'request-delete-group (gnus-group-group-name))]) ("Editing groups" - ["Parameters" gnus-group-edit-group-parameters t] - ["Select method" gnus-group-edit-group-method t] - ["Info" gnus-group-edit-group t]) - ["Read a directory as a group" gnus-group-enter-directory t] - ["Jump to group" gnus-group-jump-to-group t] - ["Best unread group" gnus-group-best-unread-group t] + ["Parameters" gnus-group-edit-group-parameters + (gnus-group-group-name)] + ["Select method" gnus-group-edit-group-method + (gnus-group-group-name)] + ["Info" gnus-group-edit-group (gnus-group-group-name)]) + ("Score file" + ["Flush cache" gnus-score-flush-cache + (or gnus-score-cache gnus-short-name-score-file-cache)]) + ("Move" + ["Next" gnus-group-next-group t] + ["Previous" gnus-group-prev-group t] + ["Next unread" gnus-group-next-unread-group t] + ["Previous unread" gnus-group-prev-unread-group t] + ["Next unread same level" gnus-group-next-unread-group-same-level t] + ["Previous unread same level" + gnus-group-previous-unread-group-same-level t] + ["Jump to group" gnus-group-jump-to-group t] + ["First unread group" gnus-group-first-unread-group t] + ["Best unread group" gnus-group-best-unread-group t]) + ["Transpose" gnus-group-transpose-groups + (gnus-group-group-name)] + ["Read a directory as a group..." gnus-group-enter-directory t] )) (easy-menu-define - gnus-group-misc-menu - gnus-group-mode-map - "" + gnus-group-misc-menu gnus-group-mode-map "" '("Misc" ["Send a bug report" gnus-bug t] ["Send a mail" gnus-group-mail t] - ["Post an article" gnus-group-post-news t] - ["Customize score file" gnus-score-customize - (not (string-match "XEmacs" emacs-version)) ] + ["Post an article..." gnus-group-post-news t] + ["Customize score file" gnus-score-customize t] ["Check for new news" gnus-group-get-new-news t] + ["Activate all groups" gnus-activate-all-groups t] ["Delete bogus groups" gnus-group-check-bogus-groups t] ["Find new newsgroups" gnus-find-new-newsgroups t] ["Restart Gnus" gnus-group-restart t] ["Read init file" gnus-group-read-init-file t] ["Browse foreign server" gnus-group-browse-foreign-server t] ["Enter server buffer" gnus-group-enter-server-mode t] - ["Expire expirable articles" gnus-group-expire-all-groups t] + ["Expire all expirable articles" gnus-group-expire-all-groups t] ["Generate any kiboze groups" nnkiboze-generate-groups t] ["Gnus version" gnus-version t] ["Save .newsrc files" gnus-group-save-newsrc t] @@ -364,432 +449,396 @@ variable it the real callback function.") ["Exit from Gnus" gnus-group-exit t] ["Exit without saving" gnus-group-quit t] ["Edit global kill file" gnus-group-edit-global-kill t] - ["Sort group buffer" gnus-group-sort-groups t] + ["Read manual" gnus-info-find-node t] + ["Toggle topics" gnus-topic-mode t] + ("SOUP" + ["Pack replies" nnsoup-pack-replies (fboundp 'nnsoup-request-group)] + ["Send replies" gnus-soup-send-replies + (fboundp 'gnus-soup-pack-packet)] + ["Pack packet" gnus-soup-pack-packet (fboundp 'gnus-soup-pack-packet)] + ["Save areas" gnus-soup-save-areas (fboundp 'gnus-soup-pack-packet)] + ["Brew SOUP" gnus-soup-brew-soup (fboundp 'gnus-soup-pack-packet)]) )) (run-hooks 'gnus-group-menu-hook) ))) -;; Server mode -(defun gnus-server-make-menu-bar () - (gnus-visual-turn-off-edit-menu 'server) - (or - (boundp 'gnus-server-menu) - (progn - (easy-menu-define - gnus-server-menu - gnus-server-mode-map - "" - '("Server" - ["Add" gnus-server-add-server t] - ["Browse" gnus-server-read-server t] - ["List" gnus-server-list-servers t] - ["Kill" gnus-server-kill-server t] - ["Yank" gnus-server-yank-server t] - ["Copy" gnus-server-copy-server t] - ["Edit" gnus-server-edit-server t] - ["Exit" gnus-server-exit t] - )) - (run-hooks 'gnus-server-menu-hook) - ))) - -;; Browse mode -(defun gnus-browse-make-menu-bar () - (gnus-visual-turn-off-edit-menu 'browse) - (or - (boundp 'gnus-browse-menu) - (progn - (easy-menu-define - gnus-browse-menu - gnus-browse-mode-map - "" - '("Browse" - ["Subscribe" gnus-browse-unsubscribe-current-group t] - ["Read" gnus-group-read-group t] - ["Exit" gnus-browse-exit t] - )) - (run-hooks 'gnus-browse-menu-hook) - ))) - - ;; Summary buffer (defun gnus-summary-make-menu-bar () (gnus-visual-turn-off-edit-menu 'summary) - (or - (boundp 'gnus-summary-misc-menu) - (progn - - (easy-menu-define - gnus-summary-misc-menu - gnus-summary-mode-map - "" - '("Misc" - ("Mark" - ("Read" - ["Mark as read" gnus-summary-mark-as-read-forward t] - ["Mark same subject and select" gnus-summary-kill-same-subject-and-select t] - ["Mark same subject" gnus-summary-kill-same-subject t] - ["Catchup" gnus-summary-catchup t] - ["Catchup all" gnus-summary-catchup-all t] - ["Catchup to here" gnus-summary-catchup-to-here t] - ["Catchup region" gnus-summary-mark-region-as-read t]) - ("Various" - ["Tick" gnus-summary-tick-article-forward t] - ["Mark as dormant" gnus-summary-mark-as-dormant t] - ["Remove marks" gnus-summary-clear-mark-forward t] - ["Set expirable mark" gnus-summary-mark-as-expirable t] - ["Set bookmark" gnus-summary-set-bookmark t] - ["Remove bookmark" gnus-summary-remove-bookmark t]) - ("Display" - ["Remove lines marked as read" gnus-summary-remove-lines-marked-as-read t] - ["Remove lines marked with..." gnus-summary-remove-lines-marked-with t] - ["Show dormant articles" gnus-summary-show-all-dormant t] - ["Hide dormant articles" gnus-summary-hide-all-dormant t] - ["Show expunged articles" gnus-summary-show-all-expunged t]) - ("Process mark" - ["Set mark" gnus-summary-mark-as-processable t] - ["Remove mark" gnus-summary-unmark-as-processable t] - ["Remove all marks" gnus-summary-unmark-all-processable t] - ["Mark series" gnus-uu-mark-series t] - ["Mark region" gnus-uu-mark-region t] - ["Mark by regexp" gnus-uu-mark-by-regexp t] - ["Mark all" gnus-uu-mark-all t] - ["Mark sparse" gnus-uu-mark-sparse t] - ["Mark thread" gnus-uu-mark-thread t])) - ("Move" - ["Scroll article forwards" gnus-summary-next-page t] - ["Next unread article" gnus-summary-next-unread-article t] - ["Previous unread article" gnus-summary-prev-unread-article t] - ["Next article" gnus-summary-next-article t] - ["Previous article" gnus-summary-prev-article t] - ["Next article same subject" gnus-summary-next-same-subject t] - ["Previous article same subject" gnus-summary-prev-same-subject t] - ["First unread article" gnus-summary-first-unread-article t] - ["Go to subject number..." gnus-summary-goto-subject t] - ["Go to the last article" gnus-summary-goto-last-article t] - ["Pop article off history" gnus-summary-pop-article t]) - ("Sort" - ["Sort by number" gnus-summary-sort-by-number t] - ["Sort by author" gnus-summary-sort-by-author t] - ["Sort by subject" gnus-summary-sort-by-subject t] - ["Sort by date" gnus-summary-sort-by-date t] - ["Sort by score" gnus-summary-sort-by-score t]) - ("Exit" - ["Catchup and exit" gnus-summary-catchup-and-exit t] - ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t] - ["Exit group" gnus-summary-exit t] - ["Exit group without updating" gnus-summary-exit-no-update t] - ["Reselect group" gnus-summary-reselect-current-group t] - ["Rescan group" gnus-summary-rescan-group t]) + (unless (boundp 'gnus-summary-misc-menu) + + (easy-menu-define + gnus-summary-misc-menu gnus-summary-mode-map "" + '("Misc" + ("Mark" + ("Read" + ["Mark as read" gnus-summary-mark-as-read-forward t] + ["Mark same subject and select" + gnus-summary-kill-same-subject-and-select t] + ["Mark same subject" gnus-summary-kill-same-subject t] + ["Catchup" gnus-summary-catchup t] + ["Catchup all" gnus-summary-catchup-all t] + ["Catchup to here" gnus-summary-catchup-to-here t] + ["Catchup region" gnus-summary-mark-region-as-read t] + ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t]) + ("Various" + ["Tick" gnus-summary-tick-article-forward t] + ["Mark as dormant" gnus-summary-mark-as-dormant t] + ["Remove marks" gnus-summary-clear-mark-forward t] + ["Set expirable mark" gnus-summary-mark-as-expirable t] + ["Set bookmark" gnus-summary-set-bookmark t] + ["Remove bookmark" gnus-summary-remove-bookmark t]) + ("Limit" + ["Marks..." gnus-summary-limit-to-marks t] + ["Subject..." gnus-summary-limit-to-subject t] + ["Author..." gnus-summary-limit-to-author t] + ["Score" gnus-summary-limit-to-score t] + ["Unread" gnus-summary-limit-to-unread t] + ["Non-dormant" gnus-summary-limit-exclude-dormant t] + ["Articles" gnus-summary-limit-to-articles t] + ["Pop limit" gnus-summary-pop-limit t] + ["Show dormant" gnus-summary-limit-include-dormant t] + ["Hide childless dormant" + gnus-summary-limit-exclude-childless-dormant t] + ;;["Hide thread" gnus-summary-limit-exclude-thread t] + ["Show expunged" gnus-summary-show-all-expunged t]) + ("Process mark" + ["Set mark" gnus-summary-mark-as-processable t] + ["Remove mark" gnus-summary-unmark-as-processable t] + ["Remove all marks" gnus-summary-unmark-all-processable t] + ["Mark above" gnus-uu-mark-over t] + ["Mark series" gnus-uu-mark-series t] + ["Mark region" gnus-uu-mark-region t] + ["Mark by regexp..." gnus-uu-mark-by-regexp t] + ["Mark all" gnus-uu-mark-all t] + ["Mark buffer" gnus-uu-mark-buffer t] + ["Mark sparse" gnus-uu-mark-sparse t] + ["Mark thread" gnus-uu-mark-thread t] + ["Unmark thread" gnus-uu-unmark-thread t])) + ("Scroll article" + ["Page forward" gnus-summary-next-page t] + ["Page backward" gnus-summary-prev-page t] + ["Line forward" gnus-summary-scroll-up t]) + ("Move" + ["Next unread article" gnus-summary-next-unread-article t] + ["Previous unread article" gnus-summary-prev-unread-article t] + ["Next article" gnus-summary-next-article t] + ["Previous article" gnus-summary-prev-article t] + ["Next unread subject" gnus-summary-next-unread-subject t] + ["Previous unread subject" gnus-summary-prev-unread-subject t] + ["Next article same subject" gnus-summary-next-same-subject t] + ["Previous article same subject" gnus-summary-prev-same-subject t] + ["First unread article" gnus-summary-first-unread-article t] + ["Best unread article" gnus-summary-best-unread-article t] + ["Go to subject number..." gnus-summary-goto-subject t] + ["Go to article number..." gnus-summary-goto-article t] + ["Go to the last article" gnus-summary-goto-last-article t] + ["Pop article off history" gnus-summary-pop-article t]) + ("Sort" + ["Sort by number" gnus-summary-sort-by-number t] + ["Sort by author" gnus-summary-sort-by-author t] + ["Sort by subject" gnus-summary-sort-by-subject t] + ["Sort by date" gnus-summary-sort-by-date t] + ["Sort by score" gnus-summary-sort-by-score t]) + ("Exit" + ["Catchup and exit" gnus-summary-catchup-and-exit t] + ["Catchup all and exit" gnus-summary-catchup-and-exit t] + ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t] + ["Exit group" gnus-summary-exit t] + ["Exit group without updating" gnus-summary-exit-no-update t] + ["Exit and goto next group" gnus-summary-next-group t] + ["Exit and goto prev group" gnus-summary-prev-group t] + ["Reselect group" gnus-summary-reselect-current-group t] + ["Rescan group" gnus-summary-rescan-group t]) + ("Help" ["Fetch group FAQ" gnus-summary-fetch-faq t] - ["Filter articles" gnus-summary-execute-command t] - ["Toggle line truncation" gnus-summary-toggle-truncation t] - ["Expire expirable articles" gnus-summary-expire-articles t] ["Describe group" gnus-summary-describe-group t] - ["Edit local kill file" gnus-summary-edit-local-kill t] - )) - - (easy-menu-define - gnus-summary-kill-menu - gnus-summary-mode-map - "" - (cons - "Score" - (nconc - (list - ["Enter score" gnus-summary-score-entry t]) - (gnus-visual-score-map 'increase) - (gnus-visual-score-map 'lower) - '(["Current score" gnus-summary-current-score t] - ["Set score" gnus-summary-set-score t] - ["Customize score file" gnus-score-customize t] - ["Switch current score file" gnus-score-change-score-file t] - ["Set mark below" gnus-score-set-mark-below t] - ["Set expunge below" gnus-score-set-expunge-below t] - ["Edit current score file" gnus-score-edit-alist t] - ["Edit score file" gnus-score-edit-file t] - ["Trace score" gnus-score-find-trace t] - ["Increase score" gnus-summary-increase-score t] - ["Lower score" gnus-summary-lower-score t])))) - - (and nil - '(("Default header" - ["Ask" (gnus-score-set-default 'gnus-score-default-header nil) - :style radio - :selected (null gnus-score-default-header)] - ["From" (gnus-score-set-default 'gnus-score-default-header 'a) - :style radio - :selected (eq gnus-score-default-header 'a )] - ["Subject" (gnus-score-set-default 'gnus-score-default-header 's) - :style radio - :selected (eq gnus-score-default-header 's )] - ["Article body" - (gnus-score-set-default 'gnus-score-default-header 'b) - :style radio - :selected (eq gnus-score-default-header 'b )] - ["All headers" - (gnus-score-set-default 'gnus-score-default-header 'h) - :style radio - :selected (eq gnus-score-default-header 'h )] - ["Message-Id" (gnus-score-set-default 'gnus-score-default-header 'i) - :style radio - :selected (eq gnus-score-default-header 'i )] - ["Thread" (gnus-score-set-default 'gnus-score-default-header 't) - :style radio - :selected (eq gnus-score-default-header 't )] - ["Crossposting" - (gnus-score-set-default 'gnus-score-default-header 'x) - :style radio - :selected (eq gnus-score-default-header 'x )] - ["Lines" (gnus-score-set-default 'gnus-score-default-header 'l) - :style radio - :selected (eq gnus-score-default-header 'l )] - ["Date" (gnus-score-set-default 'gnus-score-default-header 'd) - :style radio - :selected (eq gnus-score-default-header 'd )] - ["Followups to author" - (gnus-score-set-default 'gnus-score-default-header 'f) - :style radio - :selected (eq gnus-score-default-header 'f )]) - ("Default type" - ["Ask" (gnus-score-set-default 'gnus-score-default-type nil) - :style radio - :selected (null gnus-score-default-type)] - ;; The `:active' key is commented out in the following, - ;; because the GNU Emacs hack to support radio buttons use - ;; active to indicate which button is selected. - ["Substring" (gnus-score-set-default 'gnus-score-default-type 's) - :style radio - ;; :active (not (memq gnus-score-default-header '(l d))) - :selected (eq gnus-score-default-type 's)] - ["Regexp" (gnus-score-set-default 'gnus-score-default-type 'r) - :style radio - ;; :active (not (memq gnus-score-default-header '(l d))) - :selected (eq gnus-score-default-type 'r)] - ["Exact" (gnus-score-set-default 'gnus-score-default-type 'e) - :style radio - ;; :active (not (memq gnus-score-default-header '(l d))) - :selected (eq gnus-score-default-type 'e)] - ["Fuzzy" (gnus-score-set-default 'gnus-score-default-type 'f) - :style radio - ;; :active (not (memq gnus-score-default-header '(l d))) - :selected (eq gnus-score-default-type 'f)] - ["Before date" (gnus-score-set-default 'gnus-score-default-type 'b) - :style radio - ;; :active (eq (gnus-score-default-header 'd)) - :selected (eq gnus-score-default-type 'b)] - ["At date" (gnus-score-set-default 'gnus-score-default-type 'n) - :style radio - ;; :active (eq (gnus-score-default-header 'd)) - :selected (eq gnus-score-default-type 'n)] - ["After date" (gnus-score-set-default 'gnus-score-default-type 'a) - :style radio - ;; :active (eq (gnus-score-default-header 'd)) - :selected (eq gnus-score-default-type 'a)] - ["Less than number" - (gnus-score-set-default 'gnus-score-default-type '<) - :style radio - ;; :active (eq (gnus-score-default-header 'l)) - :selected (eq gnus-score-default-type '<)] - ["Equal to number" - (gnus-score-set-default 'gnus-score-default-type '=) - :style radio - ;; :active (eq (gnus-score-default-header 'l)) - :selected (eq gnus-score-default-type '=)] - ["Greater than number" - (gnus-score-set-default 'gnus-score-default-type '>) - :style radio - ;; :active (eq (gnus-score-default-header 'l)) - :selected (eq gnus-score-default-type '>)]) - ["Default fold" gnus-score-default-fold-toggle - :style toggle - :selected gnus-score-default-fold] - ("Default duration" - ["Ask" (gnus-score-set-default 'gnus-score-default-duration nil) - :style radio - :selected (null gnus-score-default-duration)] - ["Permanent" - (gnus-score-set-default 'gnus-score-default-duration 'p) - :style radio - :selected (eq gnus-score-default-duration 'p)] - ["Temporary" - (gnus-score-set-default 'gnus-score-default-duration 't) - :style radio - :selected (eq gnus-score-default-duration 't)] - ["Immediate" - (gnus-score-set-default 'gnus-score-default-duration 'i) - :style radio - :selected (eq gnus-score-default-duration 'i)]) - )) - - (easy-menu-define - gnus-summary-article-menu - gnus-summary-mode-map - "" - '("Article" - ("Hide" - ["All" gnus-article-hide t] - ["Headers" gnus-article-hide-headers t] - ["Signature" gnus-article-hide-signature t] - ["Citation" gnus-article-hide-citation t]) - ("Highlight" - ["All" gnus-article-highlight t] - ["Headers" gnus-article-highlight-headers t] - ["Signature" gnus-article-highlight-signature t] - ["Citation" gnus-article-highlight-citation t]) - ("Date" - ["Local" gnus-article-date-local t] - ["UT" gnus-article-date-ut t] - ["Lapsed" gnus-article-date-lapsed t]) - ("Filter" - ["Overstrike" gnus-article-treat-overstrike t] - ["Word wrap" gnus-article-word-wrap t] - ["CR" gnus-article-remove-cr t] - ["Show X-Face" gnus-article-display-x-face t] - ["Quoted-Printable" gnus-article-de-quoted-unreadable t] - ["Rot 13" gnus-summary-caesar-message t] - ["Add buttons" gnus-article-add-buttons t] - ["Stop page breaking" gnus-summary-stop-page-breaking t] - ["Toggle MIME" gnus-summary-toggle-mime t] - ["Toggle header" gnus-summary-toggle-header t]) - ("Output" - ["Save in default format" gnus-summary-save-article t] - ["Save in file" gnus-summary-save-article-file t] - ["Save in Unix mail format" gnus-summary-save-article-mail t] - ["Save in MH folder" gnus-summary-save-article-folder t] - ["Save in VM folder" gnus-summary-save-article-vm t] - ["Save in RMAIL mbox" gnus-summary-save-article-rmail t] - ["Pipe through a filter" gnus-summary-pipe-output t]) - ("Backend" - ["Respool article" gnus-summary-respool-article t] - ["Move article" gnus-summary-move-article t] - ["Copy article" gnus-summary-copy-article t] - ["Import file" gnus-summary-import-article t] - ["Edit article" gnus-summary-edit-article t] - ["Delete article" gnus-summary-delete-article t]) - ("Extract" - ["Uudecode" gnus-uu-decode-uu t] - ["Uudecode and save" gnus-uu-decode-uu-and-save t] - ["Unshar" gnus-uu-decode-unshar t] - ["Unshar and save" gnus-uu-decode-unshar-and-save t] - ["Save" gnus-uu-decode-save t] - ["Binhex" gnus-uu-decode-binhex t]) - ["Enter digest buffer" gnus-summary-enter-digest-group t] - ["Isearch article" gnus-summary-isearch-article t] - ["Search all articles" gnus-summary-search-article-forward t] - ["Beginning of the article" gnus-summary-beginning-of-article t] - ["End of the article" gnus-summary-end-of-article t] - ["Fetch parent of article" gnus-summary-refer-parent-article t] - ["Fetch article with id..." gnus-summary-refer-article t] - ["Redisplay" gnus-summary-show-article t])) - - - - (easy-menu-define - gnus-summary-thread-menu - gnus-summary-mode-map - "" - '("Threads" - ["Toggle threading" gnus-summary-toggle-threads t] - ["Display hidden thread" gnus-summary-show-thread t] - ["Hide thread" gnus-summary-hide-thread t] - ["Go to next thread" gnus-summary-next-thread t] - ["Go to previous thread" gnus-summary-prev-thread t] - ["Go down thread" gnus-summary-down-thread t] - ["Go up thread" gnus-summary-up-thread t] - ["Mark thread as read" gnus-summary-kill-thread t] - ["Lower thread score" gnus-summary-lower-thread t] - ["Raise thread score" gnus-summary-raise-thread t] - )) - (easy-menu-define - gnus-summary-post-menu - gnus-summary-mode-map - "" - '("Post" - ["Post an article" gnus-summary-post-news t] - ["Followup" gnus-summary-followup t] - ["Followup and yank" gnus-summary-followup-with-original t] - ["Supersede article" gnus-summary-supersede-article t] - ["Cancel article" gnus-summary-cancel-article t] - ["Reply" gnus-summary-reply t] - ["Reply and yank" gnus-summary-reply-with-original t] - ["Mail forward" gnus-summary-mail-forward t] - ["Post forward" gnus-summary-post-forward t] - ["Digest and mail" gnus-uu-digest-mail-forward t] - ["Digest and post" gnus-uu-digest-post-forward t] - ["Send a mail" gnus-summary-mail-other-window t] - ["Reply & followup" gnus-summary-followup-and-reply t] - ["Reply & followup and yank" gnus-summary-followup-and-reply-with-original t] - ["Uuencode and post" gnus-uu-post-news t] - )) - (run-hooks 'gnus-summary-menu-hook) - ))) + ["Read manual" gnus-info-find-node t]) + ("Cache" + ["Enter article" gnus-cache-enter-article t] + ["Remove article" gnus-cache-remove-article t]) + ("Modes" + ["Pick and read" gnus-pick-mode t] + ["Binary" gnus-binary-mode t]) + ["Filter articles..." gnus-summary-execute-command t] + ["Run command on subjects..." gnus-summary-universal-argument t] + ["Toggle line truncation" gnus-summary-toggle-truncation t] + ["Expand window" gnus-summary-expand-window t] + ["Expire expirable articles" gnus-summary-expire-articles + (gnus-check-backend-function + 'request-expire-articles gnus-newsgroup-name)] + ["Edit local kill file" gnus-summary-edit-local-kill t] + ["Edit main kill file" gnus-summary-edit-global-kill t] + )) + + (easy-menu-define + gnus-summary-kill-menu gnus-summary-mode-map "" + (cons + "Score" + (nconc + (list + ["Enter score..." gnus-summary-score-entry t]) + (gnus-visual-score-map 'increase) + (gnus-visual-score-map 'lower) + '(("Mark" + ["Kill below" gnus-summary-kill-below t] + ["Mark above" gnus-summary-mark-above t] + ["Tick above" gnus-summary-tick-above t] + ["Clear above" gnus-summary-clear-above t]) + ["Current score" gnus-summary-current-score t] + ["Set score" gnus-summary-set-score t] + ["Customize score file" gnus-score-customize t] + ["Switch current score file..." gnus-score-change-score-file t] + ["Set mark below..." gnus-score-set-mark-below t] + ["Set expunge below..." gnus-score-set-expunge-below t] + ["Edit current score file" gnus-score-edit-current-scores t] + ["Edit score file" gnus-score-edit-file t] + ["Trace score" gnus-score-find-trace t] + ["Rescore buffer" gnus-summary-rescore t] + ["Increase score..." gnus-summary-increase-score t] + ["Lower score..." gnus-summary-lower-score t])))) + + '(("Default header" + ["Ask" (gnus-score-set-default 'gnus-score-default-header nil) + :style radio + :selected (null gnus-score-default-header)] + ["From" (gnus-score-set-default 'gnus-score-default-header 'a) + :style radio + :selected (eq gnus-score-default-header 'a)] + ["Subject" (gnus-score-set-default 'gnus-score-default-header 's) + :style radio + :selected (eq gnus-score-default-header 's)] + ["Article body" + (gnus-score-set-default 'gnus-score-default-header 'b) + :style radio + :selected (eq gnus-score-default-header 'b )] + ["All headers" + (gnus-score-set-default 'gnus-score-default-header 'h) + :style radio + :selected (eq gnus-score-default-header 'h )] + ["Message-Id" (gnus-score-set-default 'gnus-score-default-header 'i) + :style radio + :selected (eq gnus-score-default-header 'i )] + ["Thread" (gnus-score-set-default 'gnus-score-default-header 't) + :style radio + :selected (eq gnus-score-default-header 't )] + ["Crossposting" + (gnus-score-set-default 'gnus-score-default-header 'x) + :style radio + :selected (eq gnus-score-default-header 'x )] + ["Lines" (gnus-score-set-default 'gnus-score-default-header 'l) + :style radio + :selected (eq gnus-score-default-header 'l )] + ["Date" (gnus-score-set-default 'gnus-score-default-header 'd) + :style radio + :selected (eq gnus-score-default-header 'd )] + ["Followups to author" + (gnus-score-set-default 'gnus-score-default-header 'f) + :style radio + :selected (eq gnus-score-default-header 'f )]) + ("Default type" + ["Ask" (gnus-score-set-default 'gnus-score-default-type nil) + :style radio + :selected (null gnus-score-default-type)] + ;; The `:active' key is commented out in the following, + ;; because the GNU Emacs hack to support radio buttons use + ;; active to indicate which button is selected. + ["Substring" (gnus-score-set-default 'gnus-score-default-type 's) + :style radio + ;; :active (not (memq gnus-score-default-header '(l d))) + :selected (eq gnus-score-default-type 's)] + ["Regexp" (gnus-score-set-default 'gnus-score-default-type 'r) + :style radio + ;; :active (not (memq gnus-score-default-header '(l d))) + :selected (eq gnus-score-default-type 'r)] + ["Exact" (gnus-score-set-default 'gnus-score-default-type 'e) + :style radio + ;; :active (not (memq gnus-score-default-header '(l d))) + :selected (eq gnus-score-default-type 'e)] + ["Fuzzy" (gnus-score-set-default 'gnus-score-default-type 'f) + :style radio + ;; :active (not (memq gnus-score-default-header '(l d))) + :selected (eq gnus-score-default-type 'f)] + ["Before date" (gnus-score-set-default 'gnus-score-default-type 'b) + :style radio + ;; :active (eq (gnus-score-default-header 'd)) + :selected (eq gnus-score-default-type 'b)] + ["At date" (gnus-score-set-default 'gnus-score-default-type 'n) + :style radio + ;; :active (eq (gnus-score-default-header 'd)) + :selected (eq gnus-score-default-type 'n)] + ["After date" (gnus-score-set-default 'gnus-score-default-type 'a) + :style radio + ;; :active (eq (gnus-score-default-header 'd)) + :selected (eq gnus-score-default-type 'a)] + ["Less than number" + (gnus-score-set-default 'gnus-score-default-type '<) + :style radio + ;; :active (eq (gnus-score-default-header 'l)) + :selected (eq gnus-score-default-type '<)] + ["Equal to number" + (gnus-score-set-default 'gnus-score-default-type '=) + :style radio + ;; :active (eq (gnus-score-default-header 'l)) + :selected (eq gnus-score-default-type '=)] + ["Greater than number" + (gnus-score-set-default 'gnus-score-default-type '>) + :style radio + ;; :active (eq (gnus-score-default-header 'l)) + :selected (eq gnus-score-default-type '>)]) + ["Default fold" gnus-score-default-fold-toggle + :style toggle + :selected gnus-score-default-fold] + ("Default duration" + ["Ask" (gnus-score-set-default 'gnus-score-default-duration nil) + :style radio + :selected (null gnus-score-default-duration)] + ["Permanent" + (gnus-score-set-default 'gnus-score-default-duration 'p) + :style radio + :selected (eq gnus-score-default-duration 'p)] + ["Temporary" + (gnus-score-set-default 'gnus-score-default-duration 't) + :style radio + :selected (eq gnus-score-default-duration 't)] + ["Immediate" + (gnus-score-set-default 'gnus-score-default-duration 'i) + :style radio + :selected (eq gnus-score-default-duration 'i)])) + + (easy-menu-define + gnus-summary-article-menu gnus-summary-mode-map "" + '("Article" + ("Hide" + ["All" gnus-article-hide t] + ["Headers" gnus-article-hide-headers t] + ["Signature" gnus-article-hide-signature t] + ["Citation" gnus-article-hide-citation t] + ["PGP" gnus-article-hide-pgp t] + ["Boring headers" gnus-article-hide-boring-headers t]) + ("Highlight" + ["All" gnus-article-highlight t] + ["Headers" gnus-article-highlight-headers t] + ["Signature" gnus-article-highlight-signature t] + ["Citation" gnus-article-highlight-citation t]) + ("Date" + ["Local" gnus-article-date-local t] + ["UT" gnus-article-date-ut t] + ["Original" gnus-article-date-original t] + ["Lapsed" gnus-article-date-lapsed t]) + ("Filter" + ["Overstrike" gnus-article-treat-overstrike t] + ["Word wrap" gnus-article-fill-cited-article t] + ["CR" gnus-article-remove-cr t] + ["Trailing blank lines" gnus-article-remove-trailing-blank-lines t] + ["Show X-Face" gnus-article-display-x-face t] + ["Quoted-Printable" gnus-article-de-quoted-unreadable t] + ["Rot 13" gnus-summary-caesar-message t] + ["Add buttons" gnus-article-add-buttons t] + ["Add buttons to head" gnus-article-add-buttons-to-head t] + ["Stop page breaking" gnus-summary-stop-page-breaking t] + ["Toggle MIME" gnus-summary-toggle-mime t] + ["Verbose header" gnus-summary-verbose-headers t] + ["Toggle header" gnus-summary-toggle-header t]) + ("Output" + ["Save in default format" gnus-summary-save-article t] + ["Save in file" gnus-summary-save-article-file t] + ["Save in Unix mail format" gnus-summary-save-article-mail t] + ["Save in MH folder" gnus-summary-save-article-folder t] + ["Save in VM folder" gnus-summary-save-article-vm t] + ["Save in RMAIL mbox" gnus-summary-save-article-rmail t] + ["Save body in file" gnus-summary-save-article-body-file t] + ["Pipe through a filter" gnus-summary-pipe-output t] + ["Add to SOUP packet" gnus-soup-add-article t]) + ("Backend" + ["Respool article..." gnus-summary-respool-article t] + ["Move article..." gnus-summary-move-article + (gnus-check-backend-function + 'request-move-article gnus-newsgroup-name)] + ["Copy article..." gnus-summary-copy-article t] + ["Crosspost article..." gnus-summary-crosspost-article + (gnus-check-backend-function + 'request-replace-article gnus-newsgroup-name)] + ["Import file..." gnus-summary-import-article t] + ["Edit article" gnus-summary-edit-article + (not (gnus-group-read-only-p))] + ["Delete article" gnus-summary-delete-article + (gnus-check-backend-function + 'request-expire-articles gnus-newsgroup-name)] + ["Query respool" gnus-summary-respool-query t] + ["Delete expirable articles" gnus-summary-expire-articles-now + (gnus-check-backend-function + 'request-expire-articles gnus-newsgroup-name)]) + ("Extract" + ["Uudecode" gnus-uu-decode-uu t] + ["Uudecode and save" gnus-uu-decode-uu-and-save t] + ["Unshar" gnus-uu-decode-unshar t] + ["Unshar and save" gnus-uu-decode-unshar-and-save t] + ["Save" gnus-uu-decode-save t] + ["Binhex" gnus-uu-decode-binhex t] + ["Postscript" gnus-uu-decode-postscript t]) + ["Enter digest buffer" gnus-summary-enter-digest-group t] + ["Isearch article..." gnus-summary-isearch-article t] + ["Search articles forward..." gnus-summary-search-article-forward t] + ["Search articles backward..." gnus-summary-search-article-backward t] + ["Beginning of the article" gnus-summary-beginning-of-article t] + ["End of the article" gnus-summary-end-of-article t] + ["Fetch parent of article" gnus-summary-refer-parent-article t] + ["Fetch referenced articles" gnus-summary-refer-references t] + ["Fetch article with id..." gnus-summary-refer-article t] + ["Redisplay" gnus-summary-show-article t])) + + (easy-menu-define + gnus-summary-thread-menu gnus-summary-mode-map "" + '("Threads" + ["Toggle threading" gnus-summary-toggle-threads t] + ["Hide threads" gnus-summary-hide-all-threads t] + ["Show threads" gnus-summary-show-all-threads t] + ["Hide thread" gnus-summary-hide-thread t] + ["Show thread" gnus-summary-show-thread t] + ["Go to next thread" gnus-summary-next-thread t] + ["Go to previous thread" gnus-summary-prev-thread t] + ["Go down thread" gnus-summary-down-thread t] + ["Go up thread" gnus-summary-up-thread t] + ["Top of thread" gnus-summary-top-thread t] + ["Mark thread as read" gnus-summary-kill-thread t] + ["Lower thread score" gnus-summary-lower-thread t] + ["Raise thread score" gnus-summary-raise-thread t] + ["Rethread current" gnus-summary-rethread-current t] + )) + + (easy-menu-define + gnus-summary-post-menu gnus-summary-mode-map "" + '("Post" + ["Post an article" gnus-summary-post-news t] + ["Followup" gnus-summary-followup t] + ["Followup and yank" gnus-summary-followup-with-original t] + ["Supersede article" gnus-summary-supersede-article t] + ["Cancel article" gnus-summary-cancel-article t] + ["Reply" gnus-summary-reply t] + ["Reply and yank" gnus-summary-reply-with-original t] + ["Mail forward" gnus-summary-mail-forward t] + ["Post forward" gnus-summary-post-forward t] + ["Digest and mail" gnus-uu-digest-mail-forward t] + ["Digest and post" gnus-uu-digest-post-forward t] + ["Resend message" gnus-summary-resend-message t] + ["Send bounced mail" gnus-summary-resend-bounced-mail t] + ["Send a mail" gnus-summary-mail-other-window t] + ["Uuencode and post" gnus-uu-post-news t] + ;;("Draft" + ;;["Send" gnus-summary-send-draft t] + ;;["Send bounced" gnus-resend-bounced-mail t]) + )) + (run-hooks 'gnus-summary-menu-hook) + )) (defun gnus-score-set-default (var value) - ;; A version of set that updates the GNU Emacs menu-bar. + "A version of set that updates the GNU Emacs menu-bar." (set var value) ;; It is the message that forces the active status to be updated. (message "")) -(defvar gnus-score-default-header nil - "Default header when entering new scores. - -Should be one of the following symbols. - - a: from - s: subject - b: body - h: head - i: message-id - t: references - x: xref - l: lines - d: date - f: followup - -If nil, the user will be asked for a header.") - -(defvar gnus-score-default-type nil - "Default match type when entering new scores. - -Should be one of the following symbols. - - s: substring - e: exact string - f: fuzzy string - r: regexp string - b: before date - a: at date - n: this date - <: less than number - >: greater than number - =: equal to number - -If nil, the user will be asked for a match type.") - -(defvar gnus-score-default-fold nil - "Use case folding for new score file entries iff not nil.") - - -(defun gnus-score-default-fold-toggle () - "Toggle folding for new score file entries." - (interactive) - (setq gnus-score-default-fold (not gnus-score-default-fold)) - (if gnus-score-default-fold - (message "New score file entries will be case insensitive.") - (message "New score file entries will be case sensitive."))) - -(defvar gnus-score-default-duration nil - "Default duration of effect when entering new scores. - -Should be one of the following symbols. - - t: temporary - p: permanent - i: immediate - -If nil, the user will be asked for a duration.") - (defun gnus-visual-score-map (type) (if t nil @@ -833,14 +882,14 @@ If nil, the user will be asked for a duration.") (cons (apply 'nconc - (list (car (car ts))) + (list (caar ts)) (let ((ps perms) outp) (while ps (setq outp (cons (vector - (car (car ps)) + (caar ps) (list 'gnus-summary-score-entry (nth 1 header) @@ -873,21 +922,17 @@ If nil, the user will be asked for a duration.") (boundp 'gnus-article-article-menu) (progn (easy-menu-define - gnus-article-article-menu - gnus-article-mode-map - "" + gnus-article-article-menu gnus-article-mode-map "" '("Article" - ["Scroll forwards" gnus-article-next-page t] - ["Scroll backwards" gnus-article-prev-page t] + ["Scroll forwards" gnus-article-goto-next-page t] + ["Scroll backwards" gnus-article-goto-prev-page t] ["Show summary" gnus-article-show-summary t] ["Fetch Message-ID at point" gnus-article-refer-article t] ["Mail to address at point" gnus-article-mail t] )) (easy-menu-define - gnus-article-treatment-menu - gnus-article-mode-map - "" + gnus-article-treatment-menu gnus-article-mode-map "" '("Treatment" ["Hide headers" gnus-article-hide-headers t] ["Hide signature" gnus-article-hide-signature t] @@ -896,8 +941,7 @@ If nil, the user will be asked for a duration.") ["Remove carriage return" gnus-article-remove-cr t] ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t] )) - (run-hooks 'gnus-article-menu-hook) - ))) + (run-hooks 'gnus-article-menu-hook)))) ;;; ;;; summary highlights @@ -911,13 +955,13 @@ If nil, the user will be asked for a duration.") (let* ((beg (progn (beginning-of-line) (point))) (end (progn (end-of-line) (point))) ;; Fix by Mike Dugan . - (from (if (get-text-property beg 'mouse-face) + (from (if (get-text-property beg gnus-mouse-face-prop) beg (1+ (or (next-single-property-change - beg 'mouse-face nil end) + beg gnus-mouse-face-prop nil end) beg)))) (to (1- (or (next-single-property-change - from 'mouse-face nil end) + from gnus-mouse-face-prop nil end) end)))) ;; If no mouse-face prop on line (e.g. xemacs) we ;; will have to = from = end, so we highlight the @@ -941,20 +985,56 @@ If nil, the user will be asked for a duration.") (end (progn (end-of-line) (point))) ;; now find out where the line starts and leave point there. (beg (progn (beginning-of-line) (point))) - (score (or (cdr (assq (or (get-text-property beg 'gnus-number) - gnus-current-article) + (article (gnus-summary-article-number)) + (score (or (cdr (assq (or article gnus-current-article) gnus-newsgroup-scored)) gnus-summary-default-score 0)) - (default gnus-summary-default-score) - (mark (get-text-property beg 'gnus-mark)) + (mark (or (gnus-summary-article-mark) gnus-unread-mark)) + (inhibit-read-only t)) + ;; Eval the cars of the lists until we find a match. + (let ((default gnus-summary-default-score)) + (while (and list + (not (eval (caar list)))) + (setq list (cdr list)))) + (let ((face (cdar list))) + (unless (eq face (get-text-property beg 'face)) + (gnus-put-text-property + beg end 'face + (setq face (if (boundp face) (symbol-value face) face))) + (when gnus-summary-highlight-line-function + (funcall gnus-summary-highlight-line-function article face)))) + (goto-char p))) + +(defun gnus-group-highlight-line () + "Highlight the current line according to `gnus-group-highlight'." + (let* ((list gnus-group-highlight) + (p (point)) + (end (progn (end-of-line) (point))) + ;; now find out where the line starts and leave point there. + (beg (progn (beginning-of-line) (point))) + (group (gnus-group-group-name)) + (entry (gnus-group-entry group)) + (unread (if (numberp (car entry)) (car entry) 0)) + (info (nth 2 entry)) + (method (gnus-server-get-method group (gnus-info-method info))) + (marked (gnus-info-marks info)) + (mailp (memq 'mail (assoc (symbol-name + (car (or method gnus-select-method))) + gnus-valid-select-methods))) + (level (or (gnus-info-level info) 9)) + (score (or (gnus-info-score info) 0)) + (ticked (gnus-range-length (cdr (assq 'tick marked)))) (inhibit-read-only t)) - (while (and list (not (eval (car (car list))))) + ;; Eval the cars of the lists until we find a match. + (while (and list + (not (eval (caar list)))) (setq list (cdr list))) - (let ((face (and list (cdr (car list))))) - (or (eobp) - (eq face (get-text-property beg 'face)) - (put-text-property beg end 'face - (if (boundp face) (symbol-value face) face)))) + (let ((face (cdar list))) + (unless (eq face (get-text-property beg 'face)) + (gnus-put-text-property + beg end 'face + (setq face (if (boundp face) (symbol-value face) face))) + (gnus-extent-start-open beg))) (goto-char p))) ;;; @@ -1098,16 +1178,16 @@ The following commands are available: (setq button (car buttons) buttons (cdr buttons)) (if (stringp button) - (set-text-properties + (gnus-set-text-properties (point) (prog2 (insert button) (point) (insert " ")) (list 'face gnus-carpal-header-face)) - (set-text-properties + (gnus-set-text-properties (point) (prog2 (insert (car button)) (point) (insert " ")) (list 'gnus-callback (cdr button) 'face gnus-carpal-button-face - 'mouse-face 'highlight)))) + gnus-mouse-face-prop 'highlight)))) (let ((fill-column (- (window-width) 2))) (fill-region (point-min) (point-max))) (set-window-point (get-buffer-window (current-buffer)) @@ -1164,20 +1244,39 @@ call it with the value of the `gnus-data' text property." (fun (get-text-property (point) 'gnus-callback))) (if fun (funcall fun data)))) -;; Suggested by Arne Elofsson -(defun gnus-article-next-button () - "Move point to next button." - (interactive) - (if (get-text-property (point) 'gnus-callback) - (goto-char (next-single-property-change (point) 'gnus-callback - nil (point-max)))) - (let ((pos (next-single-property-change (point) 'gnus-callback))) - (if pos - (goto-char pos) - (setq pos (next-single-property-change (point-min) 'gnus-callback)) - (if pos - (goto-char pos) - (error "No buttons found"))))) +(defun gnus-article-prev-button (n) + "Move point to N buttons backward. +If N is negative, move forward instead." + (interactive "p") + (gnus-article-next-button (- n))) + +(defun gnus-article-next-button (n) + "Move point to N buttons forward. +If N is negative, move backward instead." + (interactive "p") + (let ((function (if (< n 0) 'previous-single-property-change + 'next-single-property-change)) + (inhibit-point-motion-hooks t) + (backward (< n 0)) + (limit (if (< n 0) (point-min) (point-max)))) + (setq n (abs n)) + (while (and (not (= limit (point))) + (> n 0)) + ;; Skip past the current button. + (when (get-text-property (point) 'gnus-callback) + (goto-char (funcall function (point) 'gnus-callback nil limit))) + ;; Go to the next (or previous) button. + (gnus-goto-char (funcall function (point) 'gnus-callback nil limit)) + ;; Put point at the start of the button. + (when (and backward (not (get-text-property (point) 'gnus-callback))) + (goto-char (funcall function (point) 'gnus-callback nil limit))) + ;; Skip past intangible buttons. + (when (get-text-property (point) 'intangible) + (incf n)) + (decf n)) + (unless (zerop n) + (gnus-message 5 "No more buttons")) + n)) (defun gnus-article-highlight (&optional force) "Highlight current article. @@ -1189,7 +1288,8 @@ do the highlighting. See the documentation for those functions." (gnus-article-highlight-headers) (gnus-article-highlight-citation force) (gnus-article-highlight-signature) - (gnus-article-add-buttons force)) + (gnus-article-add-buttons force) + (gnus-article-add-buttons-to-head)) (defun gnus-article-highlight-some (&optional force) "Highlight current article. @@ -1201,59 +1301,46 @@ do the highlighting. See the documentation for those functions." (gnus-article-highlight-signature) (gnus-article-add-buttons)) -(defun gnus-article-hide (&optional force) - "Hide current article. -This function calls `gnus-article-hide-headers', -`gnus-article-hide-citation-maybe', and `gnus-article-hide-signature' -to do the hiding. See the documentation for those functions." - (interactive (list 'force)) - (gnus-article-hide-headers) - (gnus-article-hide-citation-maybe force) - (gnus-article-hide-signature)) - (defun gnus-article-highlight-headers () "Highlight article headers as specified by `gnus-header-face-alist'." (interactive) (save-excursion (set-buffer gnus-article-buffer) - (goto-char (point-min)) - (if (not (search-forward "\n\n" nil t)) - () - (beginning-of-line 0) - (while (not (bobp)) - (let ((alist gnus-header-face-alist) - (buffer-read-only nil) - (case-fold-search t) - (end (point)) - (inhibit-point-motion-hooks t) - begin entry regexp header-face field-face - header-found field-found) - (re-search-backward "^[^ \t]" nil t) - (setq begin (point)) - (while alist - (setq entry (car alist) - regexp (nth 0 entry) + (save-restriction + (let ((alist gnus-header-face-alist) + (buffer-read-only nil) + (case-fold-search t) + (inhibit-point-motion-hooks t) + entry regexp header-face field-face from hpoints fpoints) + (goto-char (point-min)) + (when (search-forward "\n\n" nil t) + (narrow-to-region (1- (point)) (point-min)) + (while (setq entry (pop alist)) + (goto-char (point-min)) + (setq regexp (concat "^\\(" + (if (string-equal "" (nth 0 entry)) + "[^\t ]" + (nth 0 entry)) + "\\)") header-face (nth 1 entry) - field-face (nth 2 entry) - alist (cdr alist)) - (if (looking-at regexp) - (let ((from (point))) - (skip-chars-forward "^:\n") - (and (not header-found) - header-face - (progn - (put-text-property from (point) 'face header-face) - (setq header-found t))) - (and (not field-found) - field-face - (progn - (skip-chars-forward ": \t") - (let ((from (point))) - (goto-char end) - (skip-chars-backward " \t") - (put-text-property from (point) 'face field-face) - (setq field-found t)))))) - (goto-char begin))))))) + field-face (nth 2 entry)) + (while (and (re-search-forward regexp nil t) + (not (eobp))) + (beginning-of-line) + (setq from (point)) + (or (search-forward ":" nil t) + (forward-char 1)) + (when (and header-face + (not (memq (point) hpoints))) + (push (point) hpoints) + (gnus-put-text-property from (point) 'face header-face)) + (when (and field-face + (not (memq (setq from (point)) fpoints))) + (push from fpoints) + (if (re-search-forward "^[^ \t]" nil t) + (forward-char -2) + (goto-char (point-max))) + (gnus-put-text-property from (point) 'face field-face))))))))) (defun gnus-article-highlight-signature () "Highlight the signature in an article. @@ -1264,76 +1351,93 @@ It does this by highlighting everything after (set-buffer gnus-article-buffer) (let ((buffer-read-only nil) (inhibit-point-motion-hooks t)) - (goto-char (point-max)) - (and (re-search-backward gnus-signature-separator nil t) - gnus-signature-face - (let ((start (match-beginning 0)) - (end (match-end 0))) - (gnus-article-add-button start end 'gnus-signature-toggle end) - (gnus-overlay-put (gnus-make-overlay end (point-max)) - 'face gnus-signature-face)))))) - -(defun gnus-article-hide-signature () - "Hide the signature in an article. -It does this by making everything after `gnus-signature-separator' invisible." - (interactive) - (save-excursion - (set-buffer gnus-article-buffer) - (let ((buffer-read-only nil)) - (goto-char (point-max)) - (and (re-search-backward gnus-signature-separator nil t) - gnus-signature-face - (add-text-properties (match-end 0) (point-max) - gnus-hidden-properties))))) + (save-restriction + (when (and gnus-signature-face + (gnus-narrow-to-signature)) + (gnus-overlay-put (gnus-make-overlay (point-min) (point-max)) + 'face gnus-signature-face) + (widen) + (re-search-backward gnus-signature-separator nil t) + (let ((start (match-beginning 0)) + (end (set-marker (make-marker) (1+ (match-end 0))))) + (gnus-article-add-button start (1- end) 'gnus-signature-toggle + end))))))) (defun gnus-article-add-buttons (&optional force) - "Find external references in article and make them to buttons. - -External references are things like message-ids and URLs, as specified by -`gnus-button-alist'." + "Find external references in the article and make buttons of them. +\"External references\" are things like Message-IDs and URLs, as +specified by `gnus-button-alist'." (interactive (list 'force)) - (if (eq gnus-button-last gnus-button-alist) - () - (setq gnus-button-regexp (mapconcat 'car gnus-button-alist "\\|") - gnus-button-last gnus-button-alist)) (save-excursion (set-buffer gnus-article-buffer) - (gnus-cite-parse-maybe force) + ;; Remove all old markers. + (while gnus-button-marker-list + (set-marker (pop gnus-button-marker-list) nil)) (let ((buffer-read-only nil) (inhibit-point-motion-hooks t) - (case-fold-search t)) + (case-fold-search t) + (alist gnus-button-alist) + beg entry regexp) (goto-char (point-min)) - (or (search-forward "\n\n" nil t) - (goto-char (point-max))) - (while (re-search-forward gnus-button-regexp nil t) - (goto-char (match-beginning 0)) - (let* ((from (point)) - (entry (gnus-button-entry)) - (start (and entry (match-beginning (nth 1 entry)))) - (end (and entry (match-end (nth 1 entry)))) - (form (nth 2 entry))) - (if (not entry) - () - (goto-char (match-end 0)) - (if (eval form) - (gnus-article-add-button start end 'gnus-button-push - (set-marker (make-marker) - from))))))))) -(defun gnus-netscape-open-url (url) - "Open URL in netscape, or start new scape with URL." - (let ((process (start-process (concat "netscape " url) - nil - "netscape" - "-remote" - (concat "openUrl(" url ")'")))) - (set-process-sentinel process - (` (lambda (process change) - (or (eq (process-exit-status process) 0) - (gnus-netscape-start-url (, url)))))))) - -(defun gnus-netscape-start-url (url) - "Start netscape with URL." - (start-process (concat "netscape" url) nil "netscape" url)) + ;; We skip the headers. + (unless (search-forward "\n\n" nil t) + (goto-char (point-max))) + (setq beg (point)) + (while (setq entry (pop alist)) + (setq regexp (car entry)) + (goto-char beg) + (while (re-search-forward regexp nil t) + (let* ((start (and entry (match-beginning (nth 1 entry)))) + (end (and entry (match-end (nth 1 entry)))) + (from (match-beginning 0))) + (when (or (eq t (nth 1 entry)) + (eval (nth 1 entry))) + ;; That optional form returned non-nil, so we add the + ;; button. + (gnus-article-add-button + start end 'gnus-button-push + (car (push (set-marker (make-marker) from) + gnus-button-marker-list)))))))))) + +;; Add buttons to the head of an article. +(defun gnus-article-add-buttons-to-head () + "Add buttons to the head of the article." + (interactive) + (save-excursion + (set-buffer gnus-article-buffer) + (let ((buffer-read-only nil) + (inhibit-point-motion-hooks t) + (case-fold-search t) + (alist gnus-header-button-alist) + entry beg end) + (nnheader-narrow-to-headers) + (while alist + ;; Each alist entry. + (setq entry (car alist) + alist (cdr alist)) + (goto-char (point-min)) + (while (re-search-forward (car entry) nil t) + ;; Each header matching the entry. + (setq beg (match-beginning 0)) + (setq end (or (and (re-search-forward "^[^ \t]" nil t) + (match-beginning 0)) + (point-max))) + (goto-char beg) + (while (re-search-forward (nth 1 entry) end t) + ;; Each match within a header. + (let* ((from (match-beginning 0)) + (entry (cdr entry)) + (start (match-beginning (nth 1 entry))) + (end (match-end (nth 1 entry))) + (form (nth 2 entry))) + (goto-char (match-end 0)) + (and (eval form) + (gnus-article-add-button + start end (nth 3 entry) + (buffer-substring (match-beginning (nth 4 entry)) + (match-end (nth 4 entry))))))) + (goto-char end)))) + (widen))) ;;; External functions: @@ -1342,36 +1446,30 @@ External references are things like message-ids and URLs, as specified by (and gnus-article-button-face (gnus-overlay-put (gnus-make-overlay from to) 'face gnus-article-button-face)) - (add-text-properties from to - (append (and gnus-article-mouse-face - (list 'mouse-face gnus-article-mouse-face)) - (list 'gnus-callback fun) - (and data (list 'gnus-data data))))) + (gnus-add-text-properties + from to + (nconc (and gnus-article-mouse-face + (list gnus-mouse-face-prop gnus-article-mouse-face)) + (list 'gnus-callback fun) + (and data (list 'gnus-data data))))) ;;; Internal functions: (defun gnus-signature-toggle (end) (save-excursion (set-buffer gnus-article-buffer) - (let ((buffer-read-only nil)) + (let ((buffer-read-only nil) + (inhibit-point-motion-hooks t)) (if (get-text-property end 'invisible) - (remove-text-properties end (point-max) gnus-hidden-properties) - (add-text-properties end (point-max) gnus-hidden-properties))))) - -;see gnus-cus.el -;(defun gnus-make-face (color) -; ;; Create entry for face with COLOR. -; (if gnus-make-foreground -; (custom-face-lookup color nil nil nil nil nil) -; (custom-face-lookup nil color nil nil nil nil))) + (gnus-unhide-text end (point-max)) + (gnus-hide-text end (point-max) gnus-hidden-properties))))) (defun gnus-button-entry () ;; Return the first entry in `gnus-button-alist' matching this place. (let ((alist gnus-button-alist) (entry nil)) (while alist - (setq entry (car alist) - alist (cdr alist)) + (setq entry (pop alist)) (if (looking-at (car entry)) (setq alist nil) (setq entry nil))) @@ -1389,24 +1487,103 @@ External references are things like message-ids and URLs, as specified by (let ((string (buffer-substring (match-beginning group) (match-end group)))) - (set-text-properties 0 (length string) nil string) + (gnus-set-text-properties + 0 (length string) nil string) string)) (nthcdr 4 entry)))) - (cond ((fboundp fun) - (apply fun args)) - ((and (boundp fun) - (fboundp (symbol-value fun))) - (apply (symbol-value fun) args)) - (t - (message "You must define `%S' to use this button" + (cond + ((fboundp fun) + (apply fun args)) + ((and (boundp fun) + (fboundp (symbol-value fun))) + (apply (symbol-value fun) args)) + (t + (gnus-message 1 "You must define `%S' to use this button" (cons fun args))))))) (defun gnus-button-message-id (message-id) - ;; Push on MESSAGE-ID. + "Fetch MESSAGE-ID." (save-excursion (set-buffer gnus-summary-buffer) (gnus-summary-refer-article message-id))) +(defun gnus-button-mailto (address) + ;; Mail to ADDRESS. + (set-buffer (gnus-copy-article-buffer)) + (message-reply address)) + +(defun gnus-button-reply (address) + ;; Reply to ADDRESS. + (message-reply address)) + +(defun gnus-button-url (address) + "Browse ADDRESS." + (funcall browse-url-browser-function address)) + +;;; Next/prev buttons in the article buffer. + +(defvar gnus-next-page-line-format "%{%(Next page...%)%}\n") +(defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n") + +(defvar gnus-prev-page-map nil) +(unless gnus-prev-page-map + (setq gnus-prev-page-map (make-sparse-keymap)) + (define-key gnus-prev-page-map gnus-mouse-2 'gnus-button-prev-page) + (define-key gnus-prev-page-map "\r" 'gnus-button-prev-page)) + +(defun gnus-insert-prev-page-button () + (let ((buffer-read-only nil)) + (gnus-eval-format + gnus-prev-page-line-format nil + `(gnus-prev t local-map ,gnus-prev-page-map + gnus-callback gnus-article-button-prev-page)))) + +(defvar gnus-next-page-map nil) +(unless gnus-next-page-map + (setq gnus-next-page-map (make-keymap)) + (suppress-keymap gnus-prev-page-map) + (define-key gnus-next-page-map gnus-mouse-2 'gnus-button-next-page) + (define-key gnus-next-page-map "\r" 'gnus-button-next-page)) + +(defun gnus-button-next-page () + "Go to the next page." + (interactive) + (let ((win (selected-window))) + (select-window (get-buffer-window gnus-article-buffer t)) + (gnus-article-next-page) + (select-window win))) + +(defun gnus-button-prev-page () + "Go to the prev page." + (interactive) + (let ((win (selected-window))) + (select-window (get-buffer-window gnus-article-buffer t)) + (gnus-article-prev-page) + (select-window win))) + +(defun gnus-insert-next-page-button () + (let ((buffer-read-only nil)) + (gnus-eval-format gnus-next-page-line-format nil + `(gnus-next t local-map ,gnus-next-page-map + gnus-callback + gnus-article-button-next-page)))) + +(defun gnus-article-button-next-page (arg) + "Go to the next page." + (interactive "P") + (let ((win (selected-window))) + (select-window (get-buffer-window gnus-article-buffer t)) + (gnus-article-next-page) + (select-window win))) + +(defun gnus-article-button-prev-page (arg) + "Go to the prev page." + (interactive "P") + (let ((win (selected-window))) + (select-window (get-buffer-window gnus-article-buffer t)) + (gnus-article-prev-page) + (select-window win))) + ;;; Compatibility Functions: (or (fboundp 'rassoc) diff --git a/lisp/gnus-vm.el b/lisp/gnus-vm.el index 0f41968ee65..ecfc0e93880 100644 --- a/lisp/gnus-vm.el +++ b/lisp/gnus-vm.el @@ -1,6 +1,5 @@ ;;; gnus-vm.el --- vm interface for Gnus - -;; Copyright (C) 1994,95 Free Software Foundation, Inc. +;; Copyright (C) 1994,95,96 Free Software Foundation, Inc. ;; Author: Per Persson ;; Keywords: news, mail @@ -32,6 +31,7 @@ ;;; Code: (require 'sendmail) +(require 'message) (require 'gnus) (require 'gnus-msg) @@ -90,19 +90,13 @@ save those articles instead." (let ((default-name (funcall gnus-mail-save-name gnus-newsgroup-name gnus-current-headers gnus-newsgroup-last-mail))) - (or folder - (setq folder - (read-file-name - (concat "Save article in VM folder: (default " - (file-name-nondirectory default-name) ") ") - (file-name-directory default-name) - default-name))) (setq folder - (expand-file-name folder - (and default-name - (file-name-directory default-name)))) + (cond ((eq folder 'default) default-name) + (folder folder) + (t (gnus-read-save-file-name + "Save article in VM folder:" default-name)))) (gnus-make-directory (file-name-directory folder)) - (set-buffer gnus-article-buffer) + (set-buffer gnus-original-article-buffer) (save-excursion (save-restriction (widen) @@ -111,152 +105,6 @@ save those articles instead." (kill-buffer vm-folder)))) ;; Remember the directory name to save articles. (setq gnus-newsgroup-last-mail folder))) - -(defun gnus-mail-forward-using-vm (&optional buffer) - "Forward the current message to another user using vm." - (let* ((gnus-buffer (or buffer (current-buffer))) - (subject (gnus-forward-make-subject gnus-buffer))) - (or (featurep 'win-vm) - (if gnus-use-full-window - (pop-to-buffer gnus-article-buffer) - (switch-to-buffer gnus-article-buffer))) - (gnus-copy-article-buffer) - (set-buffer gnus-article-copy) - (save-excursion - (save-restriction - (widen) - (let ((vm-folder (gnus-vm-make-folder)) - (vm-forward-message-hook - (append (symbol-value 'vm-forward-message-hook) - '((lambda () - (save-excursion - (mail-position-on-field "Subject") - (beginning-of-line) - (looking-at "^\\(Subject: \\).*$") - (replace-match (concat "\\1" subject)))))))) - (vm-forward-message) - (gnus-vm-init-reply-buffer gnus-buffer) - (run-hooks 'gnus-mail-hook) - (kill-buffer vm-folder)))))) - -(defun gnus-vm-init-reply-buffer (buffer) - (make-local-variable 'gnus-summary-buffer) - (setq gnus-summary-buffer buffer) - (set 'vm-mail-buffer nil) - (use-local-map (copy-keymap (current-local-map))) - (local-set-key "\C-c\C-y" 'gnus-yank-article)) - -(defun gnus-mail-reply-using-vm (&optional yank) - "Compose reply mail using vm. -Optional argument YANK means yank original article. -The command \\[vm-yank-message] yank the original message into current buffer." - (let ((gnus-buffer (current-buffer))) - (gnus-copy-article-buffer) - (set-buffer gnus-article-copy) - (save-excursion - (save-restriction - (widen) - (let ((vm-folder (gnus-vm-make-folder gnus-article-copy))) - (vm-reply 1) - (gnus-vm-init-reply-buffer gnus-buffer) - (setq gnus-buffer (current-buffer)) - (and yank - ;; nil will (magically :-)) yank the current article - (gnus-yank-article nil)) - (kill-buffer vm-folder)))) - (if (featurep 'win-vm) nil - (pop-to-buffer gnus-buffer)) - (run-hooks 'gnus-mail-hook))) - -(defun gnus-mail-other-window-using-vm () - "Compose mail in the other window using VM." - (interactive) - (let ((gnus-buffer (current-buffer))) - (vm-mail) - (gnus-vm-init-reply-buffer gnus-buffer)) - (run-hooks 'gnus-mail-hook)) - -(defun gnus-yank-article (article &optional prefix) - ;; Based on vm-yank-message by Kyle Jones. - "Yank article number N into the current buffer at point. -When called interactively N is read from the minibuffer. - -This command is meant to be used in GNUS created Mail mode buffers; -the yanked article comes from the newsgroup containing the article -you are replying to or forwarding. - -All article headers are yanked along with the text. Point is left -before the inserted text, the mark after. Any hook functions bound to -`mail-citation-hook' are run, after inserting the text and setting -point and mark. - -Prefix arg means to ignore `mail-citation-hook', don't set the mark, -prepend the value of `vm-included-text-prefix' to every yanked line. -For backwards compatibility, if `mail-citation-hook' is set to nil, -`mail-yank-hooks' is run instead. If that is also nil, a default -action is taken." - (interactive - (list - (let ((result 0) - default prompt) - (setq default (and gnus-summary-buffer - (save-excursion - (set-buffer gnus-summary-buffer) - (and gnus-current-article - (int-to-string gnus-current-article)))) - prompt (if default - (format "Yank article number: (default %s) " default) - "Yank article number: ")) - (while (and (not (stringp result)) (zerop result)) - (setq result (read-string prompt)) - (and (string= result "") default (setq result default)) - (or (string-match "^<.*>$" result) - (setq result (string-to-int result)))) - result) - current-prefix-arg)) - (if gnus-summary-buffer - (save-excursion - (let ((message (current-buffer)) - (start (point)) end - (tmp (generate-new-buffer " *tmp-yank*"))) - (set-buffer gnus-summary-buffer) - ;; Make sure the connection to the server is alive. - (or (gnus-server-opened (gnus-find-method-for-group - gnus-newsgroup-name)) - (progn - (gnus-check-server - (gnus-find-method-for-group gnus-newsgroup-name)) - (gnus-request-group gnus-newsgroup-name t))) - (and (stringp article) - (let ((gnus-override-method gnus-refer-article-method)) - (gnus-read-header article))) - (gnus-request-article (or article - gnus-current-article) - gnus-newsgroup-name tmp) - (set-buffer tmp) - (run-hooks 'gnus-article-prepare-hook) - ;; Decode MIME message. - (if (and gnus-show-mime - (gnus-fetch-field "Mime-Version")) - (funcall gnus-show-mime-method)) - ;; Perform the article display hooks. - (let ((buffer-read-only nil)) - (run-hooks 'gnus-article-display-hook)) - (append-to-buffer message (point-min) (point-max)) - (kill-buffer tmp) - (set-buffer message) - (setq end (point)) - (goto-char start) - (if (or prefix - (not (or mail-citation-hook mail-yank-hooks))) - (save-excursion - (while (< (point) end) - (insert (symbol-value 'vm-included-text-prefix)) - (forward-line 1))) - (push-mark end) - (cond - (mail-citation-hook (run-hooks 'mail-citation-hook)) - (mail-yank-hooks (run-hooks 'mail-yank-hooks)))))))) (provide 'gnus-vm) diff --git a/lisp/gnus.el b/lisp/gnus.el index 74a6ed20a18..3243e09c554 100644 --- a/lisp/gnus.el +++ b/lisp/gnus.el @@ -1,5 +1,4 @@ ;;; gnus.el --- a newsreader for GNU Emacs - ;; Copyright (C) 1987,88,89,90,93,94,95,96 Free Software Foundation, Inc. ;; Author: Masanobu UMEDA @@ -15,7 +14,7 @@ ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License @@ -25,14 +24,6 @@ ;;; Commentary: -;; Although Gnus looks suspiciously like GNUS, it isn't quite the same -;; beast. Most internal structures have been changed. If you have -;; written packages that depend on any of the hash tables, -;; `gnus-newsrc-alist', `gnus-killed-assoc', marked lists, the .newsrc -;; buffer, or internal knowledge of the `nntp-header-' macros, or -;; dependence on the buffers having a certain format, your code will -;; fail. - ;;; Code: (eval '(run-hooks 'gnus-load-hook)) @@ -40,8 +31,16 @@ (require 'mail-utils) (require 'timezone) (require 'nnheader) +(require 'message) +(require 'nnmail) +(require 'backquote) + +(eval-when-compile (require 'cl)) + +(defvar gnus-directory (or (getenv "SAVEDIR") "~/News/") + "*Directory variable from which all other Gnus file variables are derived.") -;; Site dependent variables. These variables should be defined in +;; Site dependent variables. These variables should be defined in ;; paths.el. (defvar gnus-default-nntp-server nil @@ -51,7 +50,7 @@ by the user. If you want to change servers, you should use `gnus-select-method'. See the documentation to that variable.") -(defconst gnus-backup-default-subscribed-newsgroups +(defvar gnus-backup-default-subscribed-newsgroups '("news.announce.newusers" "news.groups.questions" "gnu.emacs.gnus") "Default default new newsgroups the first time Gnus is run. Should be set in paths.el, and shouldn't be touched by the user.") @@ -66,49 +65,60 @@ no need to set this variable.") "String with a description of what organization (if any) the user belongs to. The ORGANIZATION environment variable is used instead if it is defined. If this variable contains a function, this function will be called -with the current newsgroup name as the argument. The function should +with the current newsgroup name as the argument. The function should return a string. In any case, if the string (either in the variable, in the environment variable, or returned by the function) is a file name, the contents of this file will be used as the organization.") -(defvar gnus-use-generic-from nil - "If nil, the full host name will be the system name prepended to the domain name. -If this is a string, the full host name will be this string. -If this is non-nil, non-string, the domain name will be used as the -full host name.") - -(defvar gnus-use-generic-path nil - "If nil, use the NNTP server name in the Path header. -If stringp, use this; if non-nil, use no host name (user name only).") - - ;; Customization variables ;; Don't touch this variable. (defvar gnus-nntp-service "nntp" "*NNTP service name (\"nntp\" or 119). -This is an obsolete variable, which is scarcely used. If you use an +This is an obsolete variable, which is scarcely used. If you use an nntp server for your newsgroup and want to change the port number used to 899, you would say something along these lines: (setq gnus-select-method '(nntp \"my.nntp.server\" (nntp-port-number 899)))") -(defvar gnus-select-method +(defvar gnus-nntpserver-file "/etc/nntpserver" + "*A file with only the name of the nntp server in it.") + +;; This function is used to check both the environment variable +;; NNTPSERVER and the /etc/nntpserver file to see whether one can find +;; an nntp server name default. +(defun gnus-getenv-nntpserver () + (or (getenv "NNTPSERVER") + (and (file-readable-p gnus-nntpserver-file) + (save-excursion + (set-buffer (get-buffer-create " *gnus nntp*")) + (buffer-disable-undo (current-buffer)) + (insert-file-contents gnus-nntpserver-file) + (let ((name (buffer-string))) + (prog1 + (if (string-match "^[ \t\n]*$" name) + nil + name) + (kill-buffer (current-buffer)))))))) + +(defvar gnus-select-method (nconc - (list 'nntp (or (getenv "NNTPSERVER") + (list 'nntp (or (condition-case () + (gnus-getenv-nntpserver) + (error nil)) (if (and gnus-default-nntp-server (not (string= gnus-default-nntp-server ""))) gnus-default-nntp-server) (system-name))) (if (or (null gnus-nntp-service) (equal gnus-nntp-service "nntp")) - nil + nil (list gnus-nntp-service))) "*Default method for selecting a newsgroup. This variable should be a list, where the first element is how the -news is to be fetched, the second is the address. +news is to be fetched, the second is the address. For instance, if you want to get your news via NNTP from \"flab.flab.edu\", you could say: @@ -124,30 +134,34 @@ If you use this variable, you must set `gnus-nntp-server' to nil. There is a lot more to know about select methods and virtual servers - see the manual for details.") -;; Added by Sudish Joseph . -(defvar gnus-post-method nil - "*Preferred method for posting USENET news. -If this variable is nil, Gnus will use the current method to decide -which method to use when posting. If it is non-nil, it will override -the current method. This method will not be used in mail groups and -the like, only in \"real\" newsgroups. - -The value must be a valid method as discussed in the documentation of -`gnus-select-method'.") +(defvar gnus-message-archive-method + `(nnfolder + "archive" + (nnfolder-directory ,(nnheader-concat message-directory "archive")) + (nnfolder-active-file + ,(nnheader-concat message-directory "archive/active")) + (nnfolder-get-new-mail nil) + (nnfolder-inhibit-expiry t)) + "*Method used for archiving messages you've sent. +This should be a mail method. + +It's probably not a very effective to change this variable once you've +run Gnus once. After doing that, you must edit this server from the +server buffer.") (defvar gnus-refer-article-method nil "*Preferred method for fetching an article by Message-ID. If you are reading news from the local spool (with nnspool), fetching -articles by Message-ID is painfully slow. By setting this method to an +articles by Message-ID is painfully slow. By setting this method to an nntp method, you might get acceptable results. The value of this variable must be a valid select method as discussed -in the documentation of `gnus-select-method'") +in the documentation of `gnus-select-method'.") (defvar gnus-secondary-select-methods nil "*A list of secondary methods that will be used for reading news. This is a list where each element is a complete select method (see -`gnus-select-method'). +`gnus-select-method'). If, for instance, you want to read your mail with the nnml backend, you could set this variable: @@ -161,7 +175,7 @@ non-numeric prefix - `C-u M-x gnus', in short.") (defvar gnus-nntp-server nil "*The name of the host running the NNTP server. -This variable is semi-obsolete. Use the `gnus-select-method' +This variable is semi-obsolete. Use the `gnus-select-method' variable instead.") (defvar gnus-startup-file "~/.newsrc" @@ -171,33 +185,47 @@ variable instead.") (defvar gnus-init-file "~/.gnus" "*Your Gnus elisp startup file. If a file with the .el or .elc suffixes exist, it will be read -instead.") +instead.") (defvar gnus-group-faq-directory - "/ftp@mirrors.aol.com:/pub/rtfm/usenet/" + '("/ftp@mirrors.aol.com:/pub/rtfm/usenet/" + "/ftp@sunsite.auc.dk:/pub/usenet/" + "/ftp@sunsite.doc.ic.ac.uk:/pub/usenet/news-faqs/" + "/ftp@src.doc.ic.ac.uk:/usenet/news-FAQS/" + "/ftp@ftp.seas.gwu.edu:/pub/rtfm/" + "/ftp@rtfm.mit.edu:/pub/usenet/" + "/ftp@ftp.uni-paderborn.de:/pub/FAQ/" + "/ftp@ftp.sunet.se:/pub/usenet/" + "/ftp@nctuccca.edu.tw:/USENET/FAQ/" + "/ftp@hwarang.postech.ac.kr:/pub/usenet/" + "/ftp@ftp.hk.super.net:/mirror/faqs/") "*Directory where the group FAQs are stored. This will most commonly be on a remote machine, and the file will be fetched by ange-ftp. +This variable can also be a list of directories. In that case, the +first element in the list will be used by default, and the others will +be used as backup sites. + Note that Gnus uses an aol machine as the default directory. If this feels fundamentally unclean, just think of it as a way to finally get something of value back from them. If the default site is too slow, try one of these: - North America: ftp.uu.net /usenet/news.answers - mirrors.aol.com /pub/rtfm/usenet - ftp.seas.gwu.edu /pub/rtfm - rtfm.mit.edu /pub/usenet/news.answers - Europe: ftp.uni-paderborn.de /pub/FAQ - ftp.Germany.EU.net /pub/newsarchive/news.answers - ftp.sunet.se /pub/usenet - Asia: nctuccca.edu.tw /USENET/FAQ - hwarang.postech.ac.kr /pub/usenet/news.answers - ftp.hk.super.net /mirror/faqs") + North America: mirrors.aol.com /pub/rtfm/usenet + ftp.seas.gwu.edu /pub/rtfm + rtfm.mit.edu /pub/usenet + Europe: ftp.uni-paderborn.de /pub/FAQ + src.doc.ic.ac.uk /usenet/news-FAQS + ftp.sunet.se /pub/usenet + sunsite.auc.dk /pub/usenet + Asia: nctuccca.edu.tw /USENET/FAQ + hwarang.postech.ac.kr /pub/usenet + ftp.hk.super.net /mirror/faqs") (defvar gnus-group-archive-directory - "/ftp@ftp.hpc.uh.edu:/pub/emacs/ding-list/" + "/ftp@ftp.hpc.uh.edu:/pub/emacs/ding-list/" "*The address of the (ding) archives.") (defvar gnus-group-recent-archive-directory @@ -213,74 +241,30 @@ started; it'll just use the normal newsgroups subscription methods.") (defvar gnus-use-cross-reference t "*Non-nil means that cross referenced articles will be marked as read. If nil, ignore cross references. If t, mark articles as read in -subscribed newsgroups. If neither t nor nil, mark as read in all -newsgroups.") +subscribed newsgroups. If neither t nor nil, mark as read in all +newsgroups.") + +(defvar gnus-single-article-buffer t + "*If non-nil, display all articles in the same buffer. +If nil, each group will get its own article buffer.") (defvar gnus-use-dribble-file t "*Non-nil means that Gnus will use a dribble file to store user updates. If Emacs should crash without saving the .newsrc files, complete information can be restored from the dribble file.") +(defvar gnus-dribble-directory nil + "*The directory where dribble files will be saved. +If this variable is nil, the directory where the .newsrc files are +saved will be used.") + (defvar gnus-asynchronous nil "*If non-nil, Gnus will supply backends with data needed for async article fetching.") -(defvar gnus-asynchronous-article-function nil - "*Function for picking articles to pre-fetch, possibly.") - -(defvar gnus-score-file-single-match-alist nil - "*Alist mapping regexps to lists of score files. -Each element of this alist should be of the form - (\"REGEXP\" [ \"SCORE-FILE-1\" ] [ \"SCORE-FILE-2\" ] ... ) - -If the name of a group is matched by REGEXP, the corresponding scorefiles -will be used for that group. -The first match found is used, subsequent matching entries are ignored (to -use multiple matches, see gnus-score-file-multiple-match-alist). - -These score files are loaded in addition to any files returned by -gnus-score-find-score-files-function (which see).") - -(defvar gnus-score-file-multiple-match-alist nil - "*Alist mapping regexps to lists of score files. -Each element of this alist should be of the form - (\"REGEXP\" [ \"SCORE-FILE-1\" ] [ \"SCORE-FILE-2\" ] ... ) - -If the name of a group is matched by REGEXP, the corresponding scorefiles -will be used for that group. -If multiple REGEXPs match a group, the score files corresponding to each -match will be used (for only one match to be used, see -gnus-score-file-single-match-alist). - -These score files are loaded in addition to any files returned by -gnus-score-find-score-files-function (which see).") - - -(defvar gnus-score-file-suffix "SCORE" - "*Suffix of the score files.") - -(defvar gnus-adaptive-file-suffix "ADAPT" - "*Suffix of the adaptive score files.") - -(defvar gnus-score-find-score-files-function 'gnus-score-find-bnews - "*Function used to find score files. -The function will be called with the group name as the argument, and -should return a list of score files to apply to that group. The score -files do not actually have to exist. - -Predefined values are: - -gnus-score-find-single: Only apply the group's own score file. -gnus-score-find-hierarchical: Also apply score files from parent groups. -gnus-score-find-bnews: Apply score files whose names matches. - -See the documentation to these functions for more information. - -This variable can also be a list of functions to be called. Each -function should either return a list of score files, or a list of -score alists.") - -(defvar gnus-score-interactive-default-score 1000 - "*Scoring commands will raise/lower the score with this number as the default.") +(defvar gnus-kill-summary-on-exit t + "*If non-nil, kill the summary buffer when you exit from it. +If nil, the summary will become a \"*Dead Summary*\" buffer, and +it will be killed sometime later.") (defvar gnus-large-newsgroup 200 "*The number of articles which indicates a large newsgroup. @@ -299,15 +283,17 @@ If this variable is a list, and the list contains the element `not-score', long file names will not be used for score files; if it contains the element `not-save', long file names will not be used for saving; and if it contains the element `not-kill', long file names -will not be used for kill files.") +will not be used for kill files. + +Note that the default for this variable varies according to what system +type you're using. On `usg-unix-v' and `xenix' this variable defaults +to nil while on all other systems it defaults to t.") -(defvar gnus-article-save-directory (or (getenv "SAVEDIR") "~/News/") - "*Name of the directory articles will be saved in (default \"~/News\"). -Initialized from the SAVEDIR environment variable.") +(defvar gnus-article-save-directory gnus-directory + "*Name of the directory articles will be saved in (default \"~/News\").") -(defvar gnus-kill-files-directory (or (getenv "SAVEDIR") "~/News/") - "*Name of the directory where kill files will be stored (default \"~/News\"). -Initialized from the SAVEDIR environment variable.") +(defvar gnus-kill-files-directory gnus-directory + "*Name of the directory where kill files will be stored (default \"~/News\").") (defvar gnus-default-article-saver 'gnus-summary-save-in-rmail "*A function to save articles in your favorite format. @@ -322,6 +308,15 @@ Gnus provides the following functions: * gnus-summary-save-in-file (article format). * gnus-summary-save-in-vm (use VM's folder format).") +(defvar gnus-prompt-before-saving 'always + "*This variable says how much prompting is to be done when saving articles. +If it is nil, no prompting will be done, and the articles will be +saved to the default files. If this variable is `always', each and +every article that is saved will be preceded by a prompt, even when +saving large batches of articles. If this variable is neither nil not +`always', there the user will be prompted once for a file name for +each invocation of the saving commands.") + (defvar gnus-rmail-save-name (function gnus-plain-save-name) "*A function generating a file name to save articles in Rmail format. The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE.") @@ -339,16 +334,31 @@ The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER.") The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE.") -(defvar gnus-split-methods nil +(defvar gnus-split-methods + '((gnus-article-archive-name)) "*Variable used to suggest where articles are to be saved. -The syntax of this variable is the same as `nnmail-split-methods'. - For instance, if you would like to save articles related to Gnus in the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\", you could set this variable to something like: '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\") - (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))") + (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\")) + +This variable is an alist where the where the key is the match and the +value is a list of possible files to save in if the match is non-nil. + +If the match is a string, it is used as a regexp match on the +article. If the match is a symbol, that symbol will be funcalled +from the buffer of the article to be saved with the newsgroup as the +parameter. If it is a list, it will be evaled in the same buffer. + +If this form or function returns a string, this string will be used as +a possible file name; and if it returns a non-nil list, that list will +be used as possible file names.") + +(defvar gnus-move-split-methods nil + "*Variable used to suggest where articles are to be moved to. +It uses the same syntax as the `gnus-split-methods' variable.") (defvar gnus-save-score nil "*If non-nil, save group scoring info.") @@ -356,22 +366,48 @@ you could set this variable to something like: (defvar gnus-use-adaptive-scoring nil "*If non-nil, use some adaptive scoring scheme.") -(defvar gnus-use-cache nil - "*If non-nil, Gnus will cache (some) articles locally.") +(defvar gnus-use-cache 'passive + "*If nil, Gnus will ignore the article cache. +If `passive', it will allow entering (and reading) articles +explicitly entered into the cache. If anything else, use the +cache to the full extent of the law.") + +(defvar gnus-use-trees nil + "*If non-nil, display a thread tree buffer.") + +(defvar gnus-use-grouplens nil + "*If non-nil, use GroupLens ratings.") + +(defvar gnus-keep-backlog nil + "*If non-nil, Gnus will keep read articles for later re-retrieval. +If it is a number N, then Gnus will only keep the last N articles +read. If it is neither nil nor a number, Gnus will keep all read +articles. This is not a good idea.") + +(defvar gnus-use-nocem nil + "*If non-nil, Gnus will read NoCeM cancel messages.") + +(defvar gnus-use-demon nil + "If non-nil, Gnus might use some demons.") (defvar gnus-use-scoring t "*If non-nil, enable scoring.") +(defvar gnus-use-picons nil + "*If non-nil, display picons.") + (defvar gnus-fetch-old-headers nil "*Non-nil means that Gnus will try to build threads by grabbing old headers. If an unread article in the group refers to an older, already read (or just marked as read) article, the old article will not normally be displayed in the Summary buffer. If this variable is non-nil, Gnus will attempt to grab the headers to the old articles, and thereby -build complete threads. If it has the value `some', only enough +build complete threads. If it has the value `some', only enough headers to connect otherwise loose threads will be displayed. +This variable can also be a number. In that case, no more than that +number of old headers will be fetched. -The server has to support XOVER for any of this to work.") +The server has to support NOV for any of this to work.") ;see gnus-cus.el ;(defvar gnus-visual t @@ -399,9 +435,9 @@ jabbering all the time.") (defvar gnus-keep-same-level nil "*Non-nil means that the next newsgroup after the current will be on the same level. When you type, for instance, `n' after reading the last article in the -current newsgroup, you will go to the next newsgroup. If this variable +current newsgroup, you will go to the next newsgroup. If this variable is nil, the next newsgroup will be the next from the group -buffer. +buffer. If this variable is non-nil, Gnus will either put you in the next newsgroup with the same level, or, if no such newsgroup is available, the next newsgroup with the lowest possible level higher @@ -413,8 +449,8 @@ with the best level.") "*nil means that Gnus won't gather loose threads. If the root of a thread has expired or been read in a previous session, the information necessary to build a complete thread has been -lost. Instead of having many small sub-threads from this original thread -scattered all over the summary buffer, Gnus can gather them. +lost. Instead of having many small sub-threads from this original thread +scattered all over the summary buffer, Gnus can gather them. If non-nil, Gnus will try to gather all loose sub-threads from an original thread into one large thread. @@ -429,9 +465,15 @@ have all the sub-threads as children. If this variable is `adopt', Gnus will make one of the \"children\" the parent and mark all the step-children as such. If this variable is `empty', the \"children\" are printed with empty -subject fields. (Or rather, they will be printed with a string +subject fields. (Or rather, they will be printed with a string given by the `gnus-summary-same-subject' variable.)") +(defvar gnus-summary-gather-exclude-subject "^ *$\\|^(none)$" + "*A regexp to match subjects to be excluded from loose thread gathering. +As loose thread gathering is done on subjects only, that means that +there can be many false gatherings performed. By rooting out certain +common subjects, gathering might become saner.") + (defvar gnus-summary-gather-subject-limit nil "*Maximum length of subject comparisons when gathering loose threads. Use nil to compare full subjects. Setting this variable to a low @@ -443,6 +485,22 @@ same few characters will be incorrectly gathered. If this variable is `fuzzy', Gnus will use a fuzzy algorithm when comparing subjects.") +(defvar gnus-simplify-ignored-prefixes nil + "*Regexp, matches for which are removed from subject lines when simplifying.") + +(defvar gnus-build-sparse-threads nil + "*If non-nil, fill in the gaps in threads. +If `some', only fill in the gaps that are needed to tie loose threads +together. If `more', fill in all leaf nodes that Gnus can find. If +non-nil and non-`some', fill in all gaps that Gnus manages to guess.") + +(defvar gnus-summary-thread-gathering-function 'gnus-gather-threads-by-subject + "Function used for gathering loose threads. +There are two pre-defined functions: `gnus-gather-threads-by-subject', +which only takes Subjects into consideration; and +`gnus-gather-threads-by-references', which compared the References +headers of the articles to find matches.") + ;; Added by Per Abrahamsen . (defvar gnus-summary-same-subject "" "*String indicating that the current article has the same subject as the previous. @@ -450,25 +508,30 @@ This variable will only be used if the value of `gnus-summary-make-false-root' is `empty'.") (defvar gnus-summary-goto-unread t - "*If non-nil, marking commands will go to the next unread article.") + "*If non-nil, marking commands will go to the next unread article. +If `never', \\\\[gnus-summary-next-page] will go to the next article, +whether it is read or not.") (defvar gnus-group-goto-unread t "*If non-nil, movement commands will go to the next unread and subscribed group.") +(defvar gnus-goto-next-group-when-activating t + "*If non-nil, the \\\\[gnus-group-get-new-news-this-group] command will advance point to the next group.") + (defvar gnus-check-new-newsgroups t "*Non-nil means that Gnus will add new newsgroups at startup. If this variable is `ask-server', Gnus will ask the server for new -groups since the last time it checked. This means that the killed list +groups since the last time it checked. This means that the killed list is no longer necessary, so you could set `gnus-save-killed-list' to -nil. +nil. -A variant is to have this variable be a list of select methods. Gnus +A variant is to have this variable be a list of select methods. Gnus will then use the `ask-server' method on all these select methods to query for new groups from all those servers. Eg. - (setq gnus-check-new-newsgroups - '((nntp \"some.server\") (nntp \"other.server\"))) + (setq gnus-check-new-newsgroups + '((nntp \"some.server\") (nntp \"other.server\"))) If this variable is nil, then you have to tell Gnus explicitly to check for new newsgroups with \\\\[gnus-find-new-newsgroups].") @@ -513,16 +576,21 @@ less than this variable, are subscribed.") (defvar gnus-level-default-unsubscribed 6 "*New unsubscribed groups will be unsubscribed at this level.") +(defvar gnus-activate-level (1+ gnus-level-subscribed) + "*Groups higher than this level won't be activated on startup. +Setting this variable to something log might save lots of time when +you have many groups that you aren't interested in.") + (defvar gnus-activate-foreign-newsgroups 4 "*If nil, Gnus will not check foreign newsgroups at startup. -If it is non-nil, it should be a number between one and nine. Foreign +If it is non-nil, it should be a number between one and nine. Foreign newsgroups that have a level lower or equal to this number will be -activated on startup. For instance, if you want to active all -subscribed newsgroups, but not the rest, you'd set this variable to +activated on startup. For instance, if you want to active all +subscribed newsgroups, but not the rest, you'd set this variable to `gnus-level-subscribed'. If you subscribe to lots of newsgroups from different servers, startup -might take a while. By setting this variable to nil, you'll save time, +might take a while. By setting this variable to nil, you'll save time, but you won't be told how many unread articles there are in the groups.") @@ -536,19 +604,17 @@ exit.") (defvar gnus-save-killed-list t "*If non-nil, save the list of killed groups to the startup file. -This will save both time (when starting and quitting) and space (both -memory and disk), but it will also mean that Gnus has no record of -which groups are new and which are old, so the automatic new -newsgroups subscription methods become meaningless. You should always -set `gnus-check-new-newsgroups' to `ask-server' or nil if you set this -variable to nil.") +If you set this variable to nil, you'll save both time (when starting +and quitting) and space (both memory and disk), but it will also mean +that Gnus has no record of which groups are new and which are old, so +the automatic new newsgroups subscription methods become meaningless. + +You should always set `gnus-check-new-newsgroups' to `ask-server' or +nil if you set this variable to nil.") (defvar gnus-interactive-catchup t "*If non-nil, require your confirmation when catching up a group.") -(defvar gnus-interactive-post t - "*If non-nil, group name will be asked for when posting.") - (defvar gnus-interactive-exit t "*If non-nil, require your confirmation when exiting Gnus.") @@ -575,28 +641,46 @@ Articles with scores closer than this to `gnus-summary-default-score' will not be marked.") (defvar gnus-simplify-subject-fuzzy-regexp nil - "*Regular expression that will be removed from subject strings if -fuzzy subject simplification is selected.") + "*Strings to be removed when doing fuzzy matches. +This can either be a regular expression or list of regular expressions +that will be removed from subject strings if fuzzy subject +simplification is selected.") + +(defvar gnus-permanently-visible-groups nil + "*Regexp to match groups that should always be listed in the group buffer. +This means that they will still be listed when there are no unread +articles in the groups.") + +(defvar gnus-list-groups-with-ticked-articles t + "*If non-nil, list groups that have only ticked articles. +If nil, only list groups that have unread articles.") (defvar gnus-group-default-list-level gnus-level-subscribed - "*Default listing level. + "*Default listing level. Ignored if `gnus-group-use-permanent-levels' is non-nil.") (defvar gnus-group-use-permanent-levels nil "*If non-nil, once you set a level, Gnus will use this level.") +(defvar gnus-group-list-inactive-groups t + "*If non-nil, inactive groups will be listed.") + (defvar gnus-show-mime nil "*If non-nil, do mime processing of articles. The articles will simply be fed to the function given by `gnus-show-mime-method'.") (defvar gnus-strict-mime t - "*If nil, decode MIME header even if there is not Mime-Version field.") - -(defvar gnus-show-mime-method (function metamail-buffer) + "*If nil, MIME-decode even if there is no Mime-Version header in the article.") + +(defvar gnus-show-mime-method 'metamail-buffer "*Function to process a MIME message. The function is called from the article buffer.") +(defvar gnus-decode-encoded-word-method (lambda ()) + "*Function to decode a MIME encoded-words. +The function is called from the article buffer.") + (defvar gnus-show-threads t "*If non-nil, display threads in summary mode.") @@ -614,16 +698,26 @@ to expose hidden threads.") If nil, which is the default, articles that have different subjects from their parents will start separate threads.") +(defvar gnus-thread-operation-ignore-subject t + "*If non-nil, subjects will be ignored when doing thread commands. +This affects commands like `gnus-summary-kill-thread' and +`gnus-summary-lower-thread'. + +If this variable is nil, articles in the same thread with different +subjects will not be included in the operation in question. If this +variable is `fuzzy', only articles that have subjects that are fuzzily +equal will be included.") + (defvar gnus-thread-indent-level 4 "*Number that says how much each sub-thread should be indented.") -(defvar gnus-ignored-newsgroups +(defvar gnus-ignored-newsgroups (purecopy (mapconcat 'identity - '("^to\\." ; not "real" groups - "^[0-9. \t]+ " ; all digits in name - "[][\"#'()]" ; bogus characters - ) - "\\|")) + '("^to\\." ; not "real" groups + "^[0-9. \t]+ " ; all digits in name + "[][\"#'()]" ; bogus characters + ) + "\\|")) "*A regexp to match uninteresting newsgroups in the active file. Any lines in the active file matching this regular expression are removed from the newsgroup list before anything else is done to it, @@ -632,48 +726,78 @@ thus making them effectively non-existent.") (defvar gnus-ignored-headers "^Path:\\|^Posting-Version:\\|^Article-I.D.:\\|^Expires:\\|^Date-Received:\\|^References:\\|^Control:\\|^Xref:\\|^Lines:\\|^Posted:\\|^Relay-Version:\\|^Message-ID:\\|^Nf-ID:\\|^Nf-From:\\|^Approved:\\|^Sender:\\|^Received:\\|^Mail-from:" "*All headers that match this regexp will be hidden. +This variable can also be a list of regexps of headers to be ignored. If `gnus-visible-headers' is non-nil, this variable will be ignored.") -(defvar gnus-visible-headers "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:" +(defvar gnus-visible-headers "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-" "*All headers that do not match this regexp will be hidden. +This variable can also be a list of regexp of headers to remain visible. If this variable is non-nil, `gnus-ignored-headers' will be ignored.") (defvar gnus-sorted-header-list - '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:" "^To:" + '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:" "^To:" "^Cc:" "^Date:" "^Organization:") "*This variable is a list of regular expressions. If it is non-nil, headers that match the regular expressions will be placed first in the article buffer in the sequence specified by this list.") +(defvar gnus-boring-article-headers + '(empty followup-to reply-to) + "*Headers that are only to be displayed if they have interesting data. +Possible values in this list are `empty', `newsgroups', `followup-to', +`reply-to', and `date'.") + (defvar gnus-show-all-headers nil "*If non-nil, don't hide any headers.") (defvar gnus-save-all-headers t "*If non-nil, don't remove any headers before saving.") +(defvar gnus-saved-headers gnus-visible-headers + "*Headers to keep if `gnus-save-all-headers' is nil. +If `gnus-save-all-headers' is non-nil, this variable will be ignored. +If that variable is nil, however, all headers that match this regexp +will be kept while the rest will be deleted before saving.") + (defvar gnus-inhibit-startup-message nil "*If non-nil, the startup message will not be displayed.") (defvar gnus-signature-separator "^-- *$" "Regexp matching signature separator.") +(defvar gnus-signature-limit nil + "Provide a limit to what is considered a signature. +If it is a number, no signature may not be longer (in characters) than +that number. If it is a function, the function will be called without +any parameters, and if it returns nil, there is no signature in the +buffer. If it is a string, it will be used as a regexp. If it +matches, the text in question is not a signature.") + (defvar gnus-auto-extend-newsgroup t "*If non-nil, extend newsgroup forward and backward when requested.") (defvar gnus-auto-select-first t - "*If non-nil, select the first unread article when entering a group. + "*If nil, don't select the first unread article when entering a group. +If this variable is `best', select the highest-scored unread article +in the group. If neither nil nor `best', select the first unread +article. + If you want to prevent automatic selection of the first unread article in some newsgroups, set the variable to nil in -`gnus-select-group-hook'.") +`gnus-select-group-hook'.") (defvar gnus-auto-select-next t "*If non-nil, offer to go to the next group from the end of the previous. If the value is t and the next newsgroup is empty, Gnus will exit -summary mode and go back to group mode. If the value is neither nil -nor t, Gnus will select the following unread newsgroup. In +summary mode and go back to group mode. If the value is neither nil +nor t, Gnus will select the following unread newsgroup. In particular, if the value is the symbol `quietly', the next unread -newsgroup will be selected without any confirmations.") +newsgroup will be selected without any confirmation, and if it is +`almost-quietly', the next group will be selected without any +confirmation if you are located on the last article in the group. +Finally, if this variable is `slightly-quietly', the `Z n' command +will go to the next group without confirmation.") (defvar gnus-auto-select-same nil "*If non-nil, select the next article with the same subject.") @@ -684,7 +808,9 @@ The \"unread\" movement commands will stay on the same line if the current article is unread.") (defvar gnus-auto-center-summary t - "*If non-nil, always center the current summary buffer.") + "*If non-nil, always center the current summary buffer. +In particular, if `vertical' do only vertical recentering. If non-nil +and non-`vertical', do both horizontal and vertical recentering.") (defvar gnus-break-pages t "*If non-nil, do page breaking on articles. @@ -702,52 +828,119 @@ beginning of a line.") (defvar gnus-window-configuration nil "Obsolete variable. See `gnus-buffer-configuration'.") +(defvar gnus-window-min-width 2 + "*Minimum width of Gnus buffers.") + +(defvar gnus-window-min-height 1 + "*Minimum height of Gnus buffers.") + (defvar gnus-buffer-configuration - '((group ([group 1.0 point] - (if gnus-carpal [group-carpal 4]))) - (summary ([summary 1.0 point] - (if gnus-carpal [summary-carpal 4]))) - (article ([summary 0.25 point] - (if gnus-carpal [summary-carpal 4]) - [article 1.0])) - (pipe ([summary 0.25 point] - (if gnus-carpal [summary-carpal 4]) - [pipe 1.0])) - (server ([server 1.0 point] - (if gnus-carpal [server-carpal 2]))) - (browse ([browse 1.0 point] - (if gnus-carpal [browse-carpal 2]))) - (group-mail ([mail 1.0 point])) - (summary-mail ([mail 1.0 point])) - (summary-reply ([article 0.5] - [mail 1.0 point])) - (info ([nil 1.0 point])) - (summary-faq ([summary 0.25] - [faq 1.0 point])) - (edit-group ([group 0.5] - [edit-group 1.0 point])) - (edit-server ([server 0.5] - [edit-server 1.0 point])) - (edit-score ([summary 0.25] - [edit-score 1.0 point])) - (post ([post 1.0 point])) - (reply ([article 0.5] - [mail 1.0 point])) - (mail-forward ([mail 1.0 point])) - (post-forward ([post 1.0 point])) - (reply-yank ([mail 1.0 point])) - (followup ([article 0.5] - [post 1.0 point])) - (followup-yank ([post 1.0 point]))) + '((group + (vertical 1.0 + (group 1.0 point) + (if gnus-carpal '(group-carpal 4)))) + (summary + (vertical 1.0 + (summary 1.0 point) + (if gnus-carpal '(summary-carpal 4)))) + (article + (cond + (gnus-use-picons + '(frame 1.0 + (vertical 1.0 + (summary 0.25 point) + (if gnus-carpal '(summary-carpal 4)) + (article 1.0)) + (vertical ((height . 5) (width . 15) + (user-position . t) + (left . -1) (top . 1)) + (picons 1.0)))) + (gnus-use-trees + '(vertical 1.0 + (summary 0.25 point) + (tree 0.25) + (article 1.0))) + (t + '(vertical 1.0 + (summary 0.25 point) + (if gnus-carpal '(summary-carpal 4)) + (if gnus-use-trees '(tree 0.25)) + (article 1.0))))) + (server + (vertical 1.0 + (server 1.0 point) + (if gnus-carpal '(server-carpal 2)))) + (browse + (vertical 1.0 + (browse 1.0 point) + (if gnus-carpal '(browse-carpal 2)))) + (message + (vertical 1.0 + (message 1.0 point))) + (pick + (vertical 1.0 + (article 1.0 point))) + (info + (vertical 1.0 + (info 1.0 point))) + (summary-faq + (vertical 1.0 + (summary 0.25) + (faq 1.0 point))) + (edit-group + (vertical 1.0 + (group 0.5) + (edit-group 1.0 point))) + (edit-server + (vertical 1.0 + (server 0.5) + (edit-server 1.0 point))) + (edit-score + (vertical 1.0 + (summary 0.25) + (edit-score 1.0 point))) + (post + (vertical 1.0 + (post 1.0 point))) + (reply + (vertical 1.0 + (article-copy 0.5) + (message 1.0 point))) + (forward + (vertical 1.0 + (message 1.0 point))) + (reply-yank + (vertical 1.0 + (message 1.0 point))) + (mail-bounce + (vertical 1.0 + (article 0.5) + (message 1.0 point))) + (draft + (vertical 1.0 + (draft 1.0 point))) + (pipe + (vertical 1.0 + (summary 0.25 point) + (if gnus-carpal '(summary-carpal 4)) + ("*Shell Command Output*" 1.0))) + (bug + (vertical 1.0 + ("*Gnus Help Bug*" 0.5) + ("*Gnus Bug*" 1.0 point))) + (compose-bounce + (vertical 1.0 + (article 0.5) + (message 1.0 point)))) "Window configuration for all possible Gnus buffers. This variable is a list of lists. Each of these lists has a NAME and -a RULE. The NAMEs are common-sense names like `group', which names a +a RULE. The NAMEs are commonsense names like `group', which names a rule used when displaying the group buffer; `summary', which names a rule for what happens when you enter a group and do not display an article buffer; and so on. See the value of this variable for a complete list of NAMEs. -Each RULE is a list of vectors. The first element in this vector is +Each RULE is a list of vectors. The first element in this vector is the name of the buffer to be displayed; the second element is the percentage of the screen this buffer is to occupy (a number in the 0.0-0.99 range); the optional third element is `point', which should @@ -760,7 +953,6 @@ buffer configuration.") (article . gnus-article-buffer) (server . gnus-server-buffer) (browse . "*Gnus Browse Server*") - (pipe . "*Shell Command Output*") (edit-group . gnus-group-edit-buffer) (edit-server . gnus-server-edit-buffer) (group-carpal . gnus-carpal-group-buffer) @@ -768,9 +960,15 @@ buffer configuration.") (server-carpal . gnus-carpal-server-buffer) (browse-carpal . gnus-carpal-browse-buffer) (edit-score . gnus-score-edit-buffer) - (mail . gnus-mail-buffer) - (post . gnus-post-news-buffer) - (faq . gnus-faq-buffer)) + (message . gnus-message-buffer) + (mail . gnus-message-buffer) + (post-news . gnus-message-buffer) + (faq . gnus-faq-buffer) + (picons . "*Picons*") + (tree . gnus-tree-buffer) + (info . gnus-info-buffer) + (article-copy . gnus-article-copy) + (draft . gnus-draft-buffer)) "Mapping from short symbols to buffer names or buffer variables.") (defvar gnus-carpal nil @@ -783,10 +981,11 @@ inserts new groups at the beginning of the list of groups; `gnus-subscribe-alphabetically' inserts new groups in strict alphabetic order; `gnus-subscribe-hierarchically' inserts new groups in hierarchical newsgroup order; `gnus-subscribe-interactively' asks -for your decision.") +for your decision; `gnus-subscribe-killed' kills all new groups; +`gnus-subscribe-zombies' will make all new groups into zombies.") ;; Suggested by a bug report by Hallvard B Furuseth. -;; . +;; . (defvar gnus-subscribe-options-newsgroup-method (function gnus-subscribe-alphabetically) "*This function is called to subscribe newsgroups mentioned on \"options -n\" lines. @@ -813,11 +1012,16 @@ hierarchy in its entirety.") "*Function used for sorting the group buffer. This function will be called with group info entries as the arguments for the groups to be sorted. Pre-made functions include -`gnus-group-sort-by-alphabet', `gnus-group-sort-by-unread' and -`gnus-group-sort-by-level'") +`gnus-group-sort-by-alphabet', `gnus-group-sort-by-unread', +`gnus-group-sort-by-level', `gnus-group-sort-by-score', and +`gnus-group-sort-by-rank'. + +This variable can also be a list of sorting functions. In that case, +the most significant sort function should be the last function in the +list.") ;; Mark variables suggested by Thomas Michanek -;; . +;; . (defvar gnus-unread-mark ? "*Mark used for unread articles.") (defvar gnus-ticked-mark ?! @@ -832,6 +1036,8 @@ for the groups to be sorted. Pre-made functions include "*Mark used for expirable articles.") (defvar gnus-killed-mark ?K "*Mark used for killed articles.") +(defvar gnus-souped-mark ?F + "*Mark used for killed articles.") (defvar gnus-kill-file-mark ?X "*Mark used for articles killed by kill files.") (defvar gnus-low-score-mark ?Y @@ -840,10 +1046,16 @@ for the groups to be sorted. Pre-made functions include "*Mark used for articles that are caught up.") (defvar gnus-replied-mark ?A "*Mark used for articles that have been replied to.") -(defvar gnus-process-mark ?# +(defvar gnus-cached-mark ?* + "*Mark used for articles that are in the cache.") +(defvar gnus-saved-mark ?S + "*Mark used for articles that have been saved to.") +(defvar gnus-process-mark ?# "*Process mark.") (defvar gnus-ancient-mark ?O "*Mark used for ancient articles.") +(defvar gnus-sparse-mark ?Q + "*Mark used for sparsely reffed articles.") (defvar gnus-canceled-mark ?G "*Mark used for canceled articles.") (defvar gnus-score-over-mark ?+ @@ -854,8 +1066,6 @@ for the groups to be sorted. Pre-made functions include "*There is no thread under the article.") (defvar gnus-not-empty-thread-mark ?= "*There is a thread under the article.") -(defvar gnus-dummy-mark ?Z - "*This is a dummy article.") (defvar gnus-view-pseudo-asynchronously nil "*If non-nil, Gnus will view pseudo-articles asynchronously.") @@ -870,7 +1080,10 @@ will not be asked to confirm the command.") If nil, all files that use the same viewing command will be given as a list of parameters to that command.") -(defvar gnus-group-line-format "%M%S%p%5y: %(%g%)\n" +(defvar gnus-insert-pseudo-articles t + "*If non-nil, insert pseudo-articles when decoding articles.") + +(defvar gnus-group-line-format "%M%S%p%P%5y: %(%g%)%l\n" "*Format of group lines. It works along the same lines as a normal formatting string, with some simple extensions. @@ -892,21 +1105,23 @@ with some simple extensions. %o Moderated group (char, \"m\") %p Process mark (char) %O Moderated group (string, \"(m)\" or \"\") +%P Topic indentation (string) +%l Whether there are GroupLens predictions for this group (string) %n Select from where (string) %z A string that look like `<%s:%n>' if a foreign select method is used -%u User defined specifier. The next character in the format string should +%u User defined specifier. The next character in the format string should be a letter. Gnus will call the function gnus-user-format-function-X, - where X is the letter following %u. The function will be passed the - current header as argument. The function should return a string, which + where X is the letter following %u. The function will be passed the + current header as argument. The function should return a string, which will be inserted into the buffer just like information from any other group specifier. Text between %( and %) will be highlighted with `gnus-mouse-face' when the mouse point move inside the area. There can only be one such area. -Note that this format specification is not always respected. For +Note that this format specification is not always respected. For reasons of efficiency, when listing killed groups, this specification -is ignored altogether. If the spec is changed considerably, your +is ignored altogether. If the spec is changed considerably, your output may end up looking strange when listing both alive and killed groups. @@ -914,7 +1129,7 @@ If you use %o or %O, reading the active file will be slower and quite a bit of extra memory will be used. %D will also worsen performance. Also note that if you change the format specification to include any of these specs, you must probably re-start Gnus to see them go into -effect.") +effect.") (defvar gnus-summary-line-format "%U%R%z%I%(%[%4L: %-20,20n%]%) %s\n" "*The format specification of the lines in the summary buffer. @@ -949,73 +1164,99 @@ with some simple extensions. %z Article zcore (character) %t Number of articles under the current thread (number). %e Whether the thread is empty or not (character). -%u User defined specifier. The next character in the format string should +%l GroupLens score (string). +%u User defined specifier. The next character in the format string should be a letter. Gnus will call the function gnus-user-format-function-X, - where X is the letter following %u. The function will be passed the - current header as argument. The function should return a string, which + where X is the letter following %u. The function will be passed the + current header as argument. The function should return a string, which will be inserted into the summary just like information from any other summary specifier. Text between %( and %) will be highlighted with `gnus-mouse-face' -when the mouse point is placed inside the area. There can only be one +when the mouse point is placed inside the area. There can only be one such area. The %U (status), %R (replied) and %z (zcore) specs have to be handled -with care. For reasons of efficiency, Gnus will compute what column -these characters will end up in, and \"hard-code\" that. This means that -it is illegal to have these specs after a variable-length spec. Well, +with care. For reasons of efficiency, Gnus will compute what column +these characters will end up in, and \"hard-code\" that. This means that +it is illegal to have these specs after a variable-length spec. Well, you might not be arrested, but your summary buffer will look strange, which is bad enough. The smart choice is to have these specs as for to the left as -possible. +possible. This restriction may disappear in later versions of Gnus.") -(defvar gnus-summary-dummy-line-format "* : : %S\n" +(defvar gnus-summary-dummy-line-format + "* %(: :%) %S\n" "*The format specification for the dummy roots in the summary buffer. It works along the same lines as a normal formatting string, with some simple extensions. %S The subject") -(defvar gnus-summary-mode-line-format "Gnus: %b [%A] %Z" - "*The format specification for the summary mode line.") - -(defvar gnus-article-mode-line-format "Gnus: %b %S" - "*The format specification for the article mode line.") +(defvar gnus-summary-mode-line-format "Gnus: %%b [%A] %Z" + "*The format specification for the summary mode line. +It works along the same lines as a normal formatting string, +with some simple extensions: + +%G Group name +%p Unprefixed group name +%A Current article number +%V Gnus version +%U Number of unread articles in the group +%e Number of unselected articles in the group +%Z A string with unread/unselected article counts +%g Shortish group name +%S Subject of the current article +%u User-defined spec +%s Current score file name +%d Number of dormant articles +%r Number of articles that have been marked as read in this session +%E Number of articles expunged by the score files") + +(defvar gnus-article-mode-line-format "Gnus: %%b %S" + "*The format specification for the article mode line. +See `gnus-summary-mode-line-format' for a closer description.") + +(defvar gnus-group-mode-line-format "Gnus: %%b {%M%:%S}" + "*The format specification for the group mode line. +It works along the same lines as a normal formatting string, +with some simple extensions: -(defvar gnus-group-mode-line-format "Gnus: %b {%M:%S} " - "*The format specification for the group mode line.") +%S The native news server. +%M The native select method. +%: \":\" if %S isn't \"\".") (defvar gnus-valid-select-methods '(("nntp" post address prompt-address) - ("nnspool" post) - ("nnvirtual" none virtual prompt-address) - ("nnmbox" mail respool) - ("nnml" mail respool) - ("nnmh" mail respool) - ("nndir" none prompt-address address) - ("nneething" none prompt-address) - ("nndigest" none) - ("nndoc" none prompt-address) - ("nnbabyl" mail respool) - ("nnkiboze" post virtual) - ;;("nnsoup" post) - ("nnfolder" mail respool)) + ("nnspool" post address) + ("nnvirtual" post-mail virtual prompt-address) + ("nnmbox" mail respool address) + ("nnml" mail respool address) + ("nnmh" mail respool address) + ("nndir" post-mail prompt-address address) + ("nneething" none address prompt-address) + ("nndoc" none address prompt-address) + ("nnbabyl" mail address respool) + ("nnkiboze" post virtual) + ("nnsoup" post-mail address) + ("nndraft" post-mail) + ("nnfolder" mail respool address)) "An alist of valid select methods. The first element of each list lists should be a string with the name -of the select method. The other elements may be be the category of +of the select method. The other elements may be be the category of this method (ie. `post', `mail', `none' or whatever) or other properties that this method has (like being respoolable). If you implement a new select method, all you should have to change is -this variable. I think.") +this variable. I think.") -(defvar gnus-updated-mode-lines '(group article summary) +(defvar gnus-updated-mode-lines '(group article summary tree) "*List of buffers that should update their mode lines. -The list may contain the symbols `group', `article' and `summary'. If +The list may contain the symbols `group', `article' and `summary'. If the corresponding symbol is present, Gnus will keep that mode line -updated with information that may be pertinent. +updated with information that may be pertinent. If this variable is nil, screen refresh may be quicker.") ;; Added by Keinonen Kari . @@ -1029,10 +1270,14 @@ of the modeline intact.") ; "*Face used for mouse highlighting in Gnus. ;No mouse highlights will be done if `gnus-visual' is nil.") -(defvar gnus-summary-mark-below nil +(defvar gnus-summary-mark-below 0 "*Mark all articles with a score below this variable as read. This variable is local to each summary buffer and usually set by the -score file.") +score file.") + +(defvar gnus-article-sort-functions '(gnus-article-sort-by-number) + "*List of functions used for sorting articles in the summary buffer. +This variable is only used when not using a threaded display.") (defvar gnus-thread-sort-functions '(gnus-thread-sort-by-number) "*List of functions used for sorting threads in the summary buffer. @@ -1040,7 +1285,9 @@ By default, threads are sorted by article number. Each function takes two threads and return non-nil if the first thread should be sorted before the other. If you use more than one function, -the primary sort function should be the last. +the primary sort function should be the last. You should probably +always include `gnus-thread-sort-by-number' in the list of sorting +functions -- preferably first. Ready-mady functions include `gnus-thread-sort-by-number', `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject', @@ -1055,14 +1302,28 @@ subthread and should then return the score of the thread. Some functions you can use are `+', `max', or `min'.") +(defvar gnus-summary-expunge-below nil + "All articles that have a score less than this variable will be expunged.") + +(defvar gnus-thread-expunge-below nil + "All threads that have a total score less than this variable will be expunged. +See `gnus-thread-score-function' for en explanation of what a +\"thread score\" is.") + +(defvar gnus-auto-subscribed-groups + "^nnml\\|^nnfolder\\|^nnmbox\\|^nnmh\\|^nnbabyl" + "*All new groups that match this regexp will be subscribed automatically. +Note that this variable only deals with new groups. It has no effect +whatsoever on old groups.") + (defvar gnus-options-subscribe nil "*All new groups matching this regexp will be subscribed unconditionally. -Note that this variable deals only with new newsgroups. This variable +Note that this variable deals only with new newsgroups. This variable does not affect old newsgroups.") (defvar gnus-options-not-subscribe nil "*All new groups matching this regexp will be ignored. -Note that this variable deals only with new newsgroups. This variable +Note that this variable deals only with new newsgroups. This variable does not affect old (already subscribed) newsgroups.") (defvar gnus-auto-expirable-newsgroups nil @@ -1070,12 +1331,23 @@ does not affect old (already subscribed) newsgroups.") If non-nil, this should be a regexp that should match all groups in which to perform auto-expiry. This only makes sense for mail groups.") +(defvar gnus-total-expirable-newsgroups nil + "*Groups in which to perform expiry of all read articles. +Use with extreme caution. All groups that match this regexp will be +expiring - which means that all read articles will be deleted after +(say) one week. (This only goes for mail groups and the like, of +course.)") + +(defvar gnus-group-uncollapsed-levels 1 + "Number of group name elements to leave alone when making a short group name.") + (defvar gnus-hidden-properties '(invisible t intangible t) "Property list to use for hiding text.") (defvar gnus-modtime-botch nil - "*Non-nil means .newsrc should be deleted prior to save. Its use is -due to the bogus appearance that .newsrc was modified on disc.") + "*Non-nil means .newsrc should be deleted prior to save. +Its use is due to the bogus appearance that .newsrc was modified on +disc.") ;; Hooks. @@ -1089,14 +1361,20 @@ This hook is run before any variables are set in the summary buffer.") (defvar gnus-article-mode-hook nil "*A hook for Gnus article mode.") -(defun gnus-summary-prepare-exit-hook nil +(defvar gnus-summary-prepare-exit-hook nil "*A hook called when preparing to exit from the summary buffer. It calls `gnus-summary-expire-articles' by default.") (add-hook 'gnus-summary-prepare-exit-hook 'gnus-summary-expire-articles) -(defun gnus-summary-exit-hook nil +(defvar gnus-summary-exit-hook nil "*A hook called on exit from the summary buffer.") +(defvar gnus-group-catchup-group-hook nil + "*A hook run when catching up a group from the group buffer.") + +(defvar gnus-group-update-group-hook nil + "*A hook called when updating group lines.") + (defvar gnus-open-server-hook nil "*A hook called just before opening connection to the news server.") @@ -1110,12 +1388,15 @@ This hook is called after Gnus is connected to the NNTP server.") (defvar gnus-get-new-news-hook nil "*A hook run just before Gnus checks for new news.") +(defvar gnus-after-getting-new-news-hook nil + "*A hook run after Gnus checks for new news.") + (defvar gnus-group-prepare-function 'gnus-group-prepare-flat "*A function that is called to generate the group buffer. The function is called with three arguments: The first is a number; all group with a level less or equal to that number should be listed, -if the second is non-nil, empty groups should also be displayed. If -the third is non-nil, it is a number. No groups with a level lower +if the second is non-nil, empty groups should also be displayed. If +the third is non-nil, it is a number. No groups with a level lower than this number should be displayed. The only current function implemented is `gnus-group-prepare-flat'.") @@ -1128,6 +1409,11 @@ If you want to modify the group buffer, you can use this hook.") "*A hook called after the summary buffer has been generated. If you want to modify the summary buffer, you can use this hook.") +(defvar gnus-summary-generate-hook nil + "*A hook run just before generating the summary buffer. +This hook is commonly used to customize threading variables and the +like.") + (defvar gnus-article-prepare-hook nil "*A hook called after an article has been prepared in the article buffer. If you want to run a special decoding program like nkf, use this hook.") @@ -1135,21 +1421,15 @@ If you want to run a special decoding program like nkf, use this hook.") ;(defvar gnus-article-display-hook nil ; "*A hook called after the article is displayed in the article buffer. ;The hook is designed to change the contents of the article -;buffer. Typical functions that this hook may contain are +;buffer. Typical functions that this hook may contain are ;`gnus-article-hide-headers' (hide selected headers), -;`gnus-article-maybe-highlight' (perform fancy article highlighting), +;`gnus-article-maybe-highlight' (perform fancy article highlighting), ;`gnus-article-hide-signature' (hide signature) and ;`gnus-article-treat-overstrike' (turn \"^H_\" into bold characters).") ;(add-hook 'gnus-article-display-hook 'gnus-article-hide-headers-if-wanted) ;(add-hook 'gnus-article-display-hook 'gnus-article-treat-overstrike) ;(add-hook 'gnus-article-display-hook 'gnus-article-maybe-highlight) -(defvar gnus-article-x-face-command - "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | xv -quit -" - "String or function to be executed to display an X-Face header. -If it is a string, the command will be executed in a sub-shell -asynchronously. The compressed face will be piped to this command.") - (defvar gnus-article-x-face-too-ugly nil "Regexp matching posters whose face shouldn't be shown automatically.") @@ -1170,11 +1450,8 @@ following hook: (mail-header-subject header) 're-only))) gnus-newsgroup-headers))))") -(defvar gnus-select-article-hook - '(gnus-summary-show-thread) - "*A hook called when an article is selected. -The default hook shows conversation thread subtrees of the selected -article automatically using `gnus-summary-show-thread'.") +(defvar gnus-select-article-hook nil + "*A hook called when an article is selected.") (defvar gnus-apply-kill-hook '(gnus-apply-kill-file) "*A hook called to apply kill files to a group. @@ -1182,7 +1459,7 @@ This hook is intended to apply a kill file to the selected newsgroup. The function `gnus-apply-kill-file' is called by default. Since a general kill file is too heavy to use only for a few -newsgroups, I recommend you to use a lighter hook function. For +newsgroups, I recommend you to use a lighter hook function. For example, if you'd like to apply a kill file to articles which contains a string `rmgroup' in subject in newsgroup `control', you can use the following hook: @@ -1194,14 +1471,15 @@ following hook: (gnus-kill \"Subject\" \"rmgroup\") (gnus-expunge \"X\"))))))") -(defvar gnus-visual-mark-article-hook +(defvar gnus-visual-mark-article-hook (list 'gnus-highlight-selected-summary) "*Hook run after selecting an article in the summary buffer. It is meant to be used for highlighting the article in some way. It is not run if `gnus-visual' is nil.") -(defun gnus-parse-headers-hook nil +(defvar gnus-parse-headers-hook nil "*A hook called before parsing the headers.") +(add-hook 'gnus-parse-headers-hook 'gnus-decode-rfc1522) (defvar gnus-exit-group-hook nil "*A hook called when exiting (not quitting) summary mode.") @@ -1212,10 +1490,21 @@ is not run if `gnus-visual' is nil.") (defvar gnus-exit-gnus-hook nil "*A hook called when exiting Gnus.") +(defvar gnus-after-exiting-gnus-hook nil + "*A hook called after exiting Gnus.") + (defvar gnus-save-newsrc-hook nil - "*A hook called when saving the newsrc file.") + "*A hook called before saving any of the newsrc files.") + +(defvar gnus-save-quick-newsrc-hook nil + "*A hook called just before saving the quick newsrc file. +Can be used to turn version control on or off.") -(defvar gnus-summary-update-hook +(defvar gnus-save-standard-newsrc-hook nil + "*A hook called just before saving the standard newsrc file. +Can be used to turn version control on or off.") + +(defvar gnus-summary-update-hook (list 'gnus-summary-highlight-line) "*A hook called when a summary line is changed. The hook will not be called if `gnus-visual' is nil. @@ -1224,29 +1513,85 @@ The default function `gnus-summary-highlight-line' will highlight the line according to the `gnus-summary-highlight' variable.") -(defvar gnus-mark-article-hook (list 'gnus-summary-mark-unread-as-read) +(defvar gnus-group-update-hook '(gnus-group-highlight-line) + "*A hook called when a group line is changed. +The hook will not be called if `gnus-visual' is nil. + +The default function `gnus-group-highlight-line' will +highlight the line according to the `gnus-group-highlight' +variable.") + +(defvar gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read) "*A hook called when an article is selected for the first time. The hook is intended to mark an article as read (or unread) automatically when it is selected.") +(defvar gnus-group-change-level-function nil + "Function run when a group level is changed. +It is called with three parameters -- GROUP, LEVEL and OLDLEVEL.") + ;; Remove any hilit infestation. (add-hook 'gnus-startup-hook (lambda () (remove-hook 'gnus-summary-prepare-hook 'hilit-rehighlight-buffer-quietly) (remove-hook 'gnus-summary-prepare-hook 'hilit-install-line-hooks) - (setq gnus-mark-article-hook '(gnus-summary-mark-unread-as-read)) + (setq gnus-mark-article-hook + '(gnus-summary-mark-read-and-unread-as-read)) (remove-hook 'gnus-article-prepare-hook 'hilit-rehighlight-buffer-quietly))) - ;; Internal variables +(defvar gnus-tree-buffer "*Tree*" + "Buffer where Gnus thread trees are displayed.") + +;; Dummy variable. +(defvar gnus-use-generic-from nil) + +(defvar gnus-thread-indent-array nil) +(defvar gnus-thread-indent-array-level gnus-thread-indent-level) + +(defvar gnus-newsrc-file-version nil) + +(defvar gnus-method-history nil) +;; Variable holding the user answers to all method prompts. + +(defvar gnus-group-history nil) +;; Variable holding the user answers to all group prompts. + +(defvar gnus-server-alist nil + "List of available servers.") + +(defvar gnus-group-indentation-function nil) + +(defvar gnus-topic-indentation "") ;; Obsolete variable. + +(defvar gnus-goto-missing-group-function nil) + +(defvar gnus-override-subscribe-method nil) + +(defvar gnus-group-goto-next-group-function nil + "Function to override finding the next group after listing groups.") + +(defconst gnus-article-mark-lists + '((marked . tick) (replied . reply) + (expirable . expire) (killed . killed) + (bookmarks . bookmark) (dormant . dormant) + (scored . score) (saved . save) + (cached . cache) + )) + ;; Avoid highlighting in kill files. (defvar gnus-summary-inhibit-highlight nil) (defvar gnus-newsgroup-selected-overlay nil) +(defvar gnus-inhibit-hiding nil) +(defvar gnus-group-indentation "") +(defvar gnus-inhibit-limiting nil) +(defvar gnus-created-frames nil) + (defvar gnus-article-mode-map nil) (defvar gnus-dribble-buffer nil) (defvar gnus-headers-retrieved-by nil) @@ -1255,104 +1600,129 @@ automatically when it is selected.") (defvar gnus-article-check-size nil) (defvar gnus-current-score-file nil) -(defvar gnus-internal-global-score-files nil) -(defvar gnus-score-file-list nil) +(defvar gnus-newsgroup-adaptive-score-file nil) (defvar gnus-scores-exclude-files nil) +(defvar gnus-opened-servers nil) + (defvar gnus-current-move-group nil) +(defvar gnus-current-copy-group nil) +(defvar gnus-current-crosspost-group nil) (defvar gnus-newsgroup-dependencies nil) -(defvar gnus-newsgroup-threads nil) (defvar gnus-newsgroup-async nil) (defconst gnus-group-edit-buffer "*Gnus edit newsgroup*") (defvar gnus-newsgroup-adaptive nil) (defvar gnus-summary-display-table nil) - -(defconst gnus-group-line-format-alist - (list (list ?M 'marked ?c) - (list ?S 'subscribed ?c) - (list ?L 'level ?d) - (list ?N 'number ?s) - (list ?I 'number-of-dormant ?d) - (list ?T 'number-of-ticked ?d) - (list ?R 'number-of-read ?s) - (list ?t 'number-total ?d) - (list ?y 'number-of-unread-unticked ?s) - (list ?i 'number-of-ticked-and-dormant ?d) - (list ?g 'group ?s) - (list ?G 'qualified-group ?s) - (list ?D 'newsgroup-description ?s) - (list ?o 'moderated ?c) - (list ?O 'moderated-string ?s) - (list ?p 'process-marked ?c) - (list ?s 'news-server ?s) - (list ?n 'news-method ?s) - (list ?z 'news-method-string ?s) - (list ?u 'user-defined ?s))) - -(defconst gnus-summary-line-format-alist - (list (list ?N 'number ?d) - (list ?S 'subject ?s) - (list ?s 'subject-or-nil ?s) - (list ?n 'name ?s) - (list ?A '(car (cdr (funcall gnus-extract-address-components from))) - ?s) - (list ?a '(or (car (funcall gnus-extract-address-components from)) - from) ?s) - (list ?F 'from ?s) - (list ?x (macroexpand '(mail-header-xref header)) ?s) - (list ?D (macroexpand '(mail-header-date header)) ?s) - (list ?d '(gnus-dd-mmm (mail-header-date header)) ?s) - (list ?M (macroexpand '(mail-header-id header)) ?s) - (list ?r (macroexpand '(mail-header-references header)) ?s) - (list ?c '(or (mail-header-chars header) 0) ?d) - (list ?L 'lines ?d) - (list ?I 'indentation ?s) - (list ?T '(if (= level 0) "" (make-string (frame-width) ? )) ?s) - (list ?R 'replied ?c) - (list ?\[ 'opening-bracket ?c) - (list ?\] 'closing-bracket ?c) - (list ?\> '(make-string level ? ) ?s) - (list ?\< '(make-string (max 0 (- 20 level)) ? ) ?s) - (list ?i 'score ?d) - (list ?z 'score-char ?c) - (list ?U 'unread ?c) - (list ?t '(gnus-summary-number-of-articles-in-thread - (and (boundp 'thread) (car thread))) - ?d) - (list ?e '(gnus-summary-number-of-articles-in-thread - (and (boundp 'thread) (car thread)) t) - ?c) - (list ?u 'user-defined ?s)) +(defvar gnus-summary-display-article-function nil) + +(defvar gnus-summary-highlight-line-function nil + "Function called after highlighting a summary line.") + +(defvar gnus-group-line-format-alist + `((?M gnus-tmp-marked-mark ?c) + (?S gnus-tmp-subscribed ?c) + (?L gnus-tmp-level ?d) + (?N (cond ((eq number t) "*" ) + ((numberp number) + (int-to-string + (+ number + (gnus-range-length (cdr (assq 'dormant gnus-tmp-marked))) + (gnus-range-length (cdr (assq 'tick gnus-tmp-marked)))))) + (t number)) ?s) + (?R gnus-tmp-number-of-read ?s) + (?t gnus-tmp-number-total ?d) + (?y gnus-tmp-number-of-unread ?s) + (?I (gnus-range-length (cdr (assq 'dormant gnus-tmp-marked))) ?d) + (?T (gnus-range-length (cdr (assq 'tick gnus-tmp-marked))) ?d) + (?i (+ (gnus-range-length (cdr (assq 'dormant gnus-tmp-marked))) + (gnus-range-length (cdr (assq 'tick gnus-tmp-marked)))) ?d) + (?g gnus-tmp-group ?s) + (?G gnus-tmp-qualified-group ?s) + (?c (gnus-short-group-name gnus-tmp-group) ?s) + (?D gnus-tmp-newsgroup-description ?s) + (?o gnus-tmp-moderated ?c) + (?O gnus-tmp-moderated-string ?s) + (?p gnus-tmp-process-marked ?c) + (?s gnus-tmp-news-server ?s) + (?n gnus-tmp-news-method ?s) + (?P gnus-group-indentation ?s) + (?l gnus-tmp-grouplens ?s) + (?z gnus-tmp-news-method-string ?s) + (?u gnus-tmp-user-defined ?s))) + +(defvar gnus-summary-line-format-alist + `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d) + (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s) + (?s gnus-tmp-subject-or-nil ?s) + (?n gnus-tmp-name ?s) + (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from))) + ?s) + (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from)) + gnus-tmp-from) ?s) + (?F gnus-tmp-from ?s) + (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s) + (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s) + (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s) + (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s) + (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s) + (?c (or (mail-header-chars gnus-tmp-header) 0) ?d) + (?L gnus-tmp-lines ?d) + (?I gnus-tmp-indentation ?s) + (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s) + (?R gnus-tmp-replied ?c) + (?\[ gnus-tmp-opening-bracket ?c) + (?\] gnus-tmp-closing-bracket ?c) + (?\> (make-string gnus-tmp-level ? ) ?s) + (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s) + (?i gnus-tmp-score ?d) + (?z gnus-tmp-score-char ?c) + (?l (bbb-grouplens-score gnus-tmp-header) ?s) + (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d) + (?U gnus-tmp-unread ?c) + (?t (gnus-summary-number-of-articles-in-thread + (and (boundp 'thread) (car thread)) gnus-tmp-level) + ?d) + (?e (gnus-summary-number-of-articles-in-thread + (and (boundp 'thread) (car thread)) gnus-tmp-level t) + ?c) + (?u gnus-tmp-user-defined ?s)) "An alist of format specifications that can appear in summary lines, and what variables they correspond with, along with the type of the variable (string, integer, character, etc).") -(defconst gnus-summary-dummy-line-format-alist - (list (list ?S 'subject ?s) - (list ?N 'number ?d) - (list ?u 'user-defined ?s))) - -(defconst gnus-summary-mode-line-format-alist - (list (list ?G 'group-name ?s) - (list ?g '(gnus-short-group-name group-name) ?s) - (list ?A 'article-number ?d) - (list ?Z 'unread-and-unselected ?s) - (list ?V 'gnus-version ?s) - (list ?U 'unread ?d) - (list ?S 'subject ?s) - (list ?e 'unselected ?d) - (list ?u 'user-defined ?s) - (list ?b 'buffer-name ?s) - (list ?s '(gnus-current-score-file-nondirectory) ?s))) - -(defconst gnus-group-mode-line-format-alist - (list (list ?S 'news-server ?s) - (list ?M 'news-method ?s) - (list ?b '(buffer-name) ?s) - (list ?u 'user-defined ?s))) +(defvar gnus-summary-dummy-line-format-alist + `((?S gnus-tmp-subject ?s) + (?N gnus-tmp-number ?d) + (?u gnus-tmp-user-defined ?s))) + +(defvar gnus-summary-mode-line-format-alist + `((?G gnus-tmp-group-name ?s) + (?g (gnus-short-group-name gnus-tmp-group-name) ?s) + (?p (gnus-group-real-name gnus-tmp-group-name) ?s) + (?A gnus-tmp-article-number ?d) + (?Z gnus-tmp-unread-and-unselected ?s) + (?V gnus-version ?s) + (?U gnus-tmp-unread-and-unticked ?d) + (?S gnus-tmp-subject ?s) + (?e gnus-tmp-unselected ?d) + (?u gnus-tmp-user-defined ?s) + (?d (length gnus-newsgroup-dormant) ?d) + (?t (length gnus-newsgroup-marked) ?d) + (?r (length gnus-newsgroup-reads) ?d) + (?E gnus-newsgroup-expunged-tally ?d) + (?s (gnus-current-score-file-nondirectory) ?s))) + +(defvar gnus-article-mode-line-format-alist + gnus-summary-mode-line-format-alist) + +(defvar gnus-group-mode-line-format-alist + `((?S gnus-tmp-news-server ?s) + (?M gnus-tmp-news-method ?s) + (?u gnus-tmp-user-defined ?s) + (?: gnus-tmp-colon ?s))) (defvar gnus-have-read-active-file nil) @@ -1360,14 +1730,21 @@ variable (string, integer, character, etc).") "gnus-bug@ifi.uio.no (The Gnus Bugfixing Girls + Boys)" "The mail address of the Gnus maintainers.") -(defconst gnus-version "Gnus v5.1" +(defconst gnus-version-number "5.3" "Version number for this version of Gnus.") +(defconst gnus-version (format "Gnus v%s" gnus-version-number) + "Version string for this version of Gnus.") + (defvar gnus-info-nodes - '((gnus-group-mode "(gnus)The Group Buffer") - (gnus-summary-mode "(gnus)The Summary Buffer") - (gnus-article-mode "(gnus)The Article Buffer")) - "Assoc list of major modes and related Info nodes.") + '((gnus-group-mode "(gnus)The Group Buffer") + (gnus-summary-mode "(gnus)The Summary Buffer") + (gnus-article-mode "(gnus)The Article Buffer") + (gnus-server-mode "(gnus)The Server Buffer") + (gnus-browse-mode "(gnus)Browse Foreign Server") + (gnus-tree-mode "(gnus)Tree Display") + ) + "Alist of major modes and related Info nodes.") (defvar gnus-group-buffer "*Group*") (defvar gnus-summary-buffer "*Summary*") @@ -1376,33 +1753,39 @@ variable (string, integer, character, etc).") (defvar gnus-work-buffer " *gnus work*") +(defvar gnus-original-article-buffer " *Original Article*") +(defvar gnus-original-article nil) + (defvar gnus-buffer-list nil "Gnus buffers that should be killed on exit.") -(defvar gnus-server-alist nil - "List of available servers.") +(defvar gnus-slave nil + "Whether this Gnus is a slave or not.") (defvar gnus-variable-list '(gnus-newsrc-options gnus-newsrc-options-n - gnus-newsrc-last-checked-date + gnus-newsrc-last-checked-date gnus-newsrc-alist gnus-server-alist - gnus-killed-list gnus-zombie-list) + gnus-killed-list gnus-zombie-list + gnus-topic-topology gnus-topic-alist + gnus-format-specs) "Gnus variables saved in the quick startup file.") -(defvar gnus-overload-functions - '((news-inews gnus-inews-news "rnewspost")) - "Functions overloaded by gnus. -It is a list of `(original overload &optional file)'.") - (defvar gnus-newsrc-options nil "Options line in the .newsrc file.") (defvar gnus-newsrc-options-n nil - "List of regexps representing groups to be subscribed/ignored unconditionally.") + "List of regexps representing groups to be subscribed/ignored unconditionally.") (defvar gnus-newsrc-last-checked-date nil "Date Gnus last asked server for new newsgroups.") +(defvar gnus-topic-topology nil + "The complete topic hierarchy.") + +(defvar gnus-topic-alist nil + "The complete topic-group alist.") + (defvar gnus-newsrc-alist nil "Assoc list of read articles. gnus-newsrc-hashtb should be kept so that both hold the same information.") @@ -1459,6 +1842,11 @@ gnus-newsrc-hashtb should be kept so that both hold the same information.") (defvar gnus-newsgroup-auto-expire nil) (defvar gnus-newsgroup-active nil) +(defvar gnus-newsgroup-data nil) +(defvar gnus-newsgroup-data-reverse nil) +(defvar gnus-newsgroup-limit nil) +(defvar gnus-newsgroup-limits nil) + (defvar gnus-newsgroup-unreads nil "List of unread articles in the current newsgroup.") @@ -1468,12 +1856,20 @@ gnus-newsrc-hashtb should be kept so that both hold the same information.") (defvar gnus-newsgroup-reads nil "Alist of read articles and article marks in the current newsgroup.") +(defvar gnus-newsgroup-expunged-tally nil) + (defvar gnus-newsgroup-marked nil "List of ticked articles in the current newsgroup (a subset of unread art).") (defvar gnus-newsgroup-killed nil "List of ranges of articles that have been through the scoring process.") +(defvar gnus-newsgroup-cached nil + "List of articles that come from the article cache.") + +(defvar gnus-newsgroup-saved nil + "List of articles that have been saved.") + (defvar gnus-newsgroup-kill-headers nil) (defvar gnus-newsgroup-replied nil @@ -1496,11 +1892,17 @@ gnus-newsrc-hashtb should be kept so that both hold the same information.") (defvar gnus-newsgroup-headers nil "List of article headers in the current newsgroup.") -(defvar gnus-newsgroup-headers-hashtb-by-number nil) + +(defvar gnus-newsgroup-threads nil) + +(defvar gnus-newsgroup-prepared nil + "Whether the current group has been prepared properly.") (defvar gnus-newsgroup-ancient nil "List of `gnus-fetch-old-headers' articles in the current newsgroup.") +(defvar gnus-newsgroup-sparse nil) + (defvar gnus-current-article nil) (defvar gnus-article-current nil) (defvar gnus-current-headers nil) @@ -1512,46 +1914,47 @@ gnus-newsrc-hashtb should be kept so that both hold the same information.") ;; Save window configuration. (defvar gnus-prev-winconf nil) -;; Format specs -(defvar gnus-summary-line-format-spec nil) -(defvar gnus-summary-dummy-line-format-spec nil) -(defvar gnus-group-line-format-spec nil) -(defvar gnus-summary-mode-line-format-spec nil) -(defvar gnus-article-mode-line-format-spec nil) -(defvar gnus-group-mode-line-format-spec nil) (defvar gnus-summary-mark-positions nil) (defvar gnus-group-mark-positions nil) -(defvar gnus-summary-expunge-below nil) (defvar gnus-reffed-article-number nil) -; Let the byte-compiler know that we know about this variable. +;;; Let the byte-compiler know that we know about this variable. (defvar rmail-default-rmail-file) (defvar gnus-cache-removable-articles nil) -(defconst gnus-summary-local-variables - '(gnus-newsgroup-name - gnus-newsgroup-begin gnus-newsgroup-end - gnus-newsgroup-last-rmail gnus-newsgroup-last-mail - gnus-newsgroup-last-folder gnus-newsgroup-last-file - gnus-newsgroup-auto-expire gnus-newsgroup-unreads +(defvar gnus-dead-summary nil) + +(defconst gnus-summary-local-variables + '(gnus-newsgroup-name + gnus-newsgroup-begin gnus-newsgroup-end + gnus-newsgroup-last-rmail gnus-newsgroup-last-mail + gnus-newsgroup-last-folder gnus-newsgroup-last-file + gnus-newsgroup-auto-expire gnus-newsgroup-unreads gnus-newsgroup-unselected gnus-newsgroup-marked - gnus-newsgroup-reads + gnus-newsgroup-reads gnus-newsgroup-saved gnus-newsgroup-replied gnus-newsgroup-expirable gnus-newsgroup-processable gnus-newsgroup-killed gnus-newsgroup-bookmarks gnus-newsgroup-dormant - gnus-newsgroup-headers gnus-newsgroup-headers-hashtb-by-number + gnus-newsgroup-headers gnus-newsgroup-threads + gnus-newsgroup-prepared gnus-summary-highlight-line-function gnus-current-article gnus-current-headers gnus-have-all-headers gnus-last-article gnus-article-internal-prepare-hook gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay gnus-newsgroup-scored gnus-newsgroup-kill-headers - gnus-newsgroup-threads gnus-newsgroup-async - gnus-score-alist gnus-current-score-file gnus-summary-expunge-below - gnus-summary-mark-below gnus-newsgroup-active gnus-scores-exclude-files + gnus-newsgroup-async gnus-thread-expunge-below + gnus-score-alist gnus-current-score-file gnus-summary-expunge-below + (gnus-summary-mark-below . global) + gnus-newsgroup-active gnus-scores-exclude-files gnus-newsgroup-history gnus-newsgroup-ancient + gnus-newsgroup-sparse (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring) - gnus-cache-removable-articles) + gnus-newsgroup-adaptive-score-file + (gnus-newsgroup-expunged-tally . 0) + gnus-cache-removable-articles gnus-newsgroup-cached + gnus-newsgroup-data gnus-newsgroup-data-reverse + gnus-newsgroup-limit gnus-newsgroup-limits) "Variables that are buffer-local to the summary buffers.") (defconst gnus-bug-message @@ -1559,14 +1962,14 @@ gnus-newsrc-hashtb should be kept so that both hold the same information.") ======================================== The buffer below is a mail buffer. When you press `C-c C-c', it will -be sent to the Gnus Bug Exterminators. +be sent to the Gnus Bug Exterminators. At the bottom of the buffer you'll see lots of variable settings. Please do not delete those. They will tell the Bug People what your environment is, so that it will be easier to locate the bugs. If you have found a bug that makes Emacs go \"beep\", set -debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET') +debug-on-error to t (`M-x set-variable RET debug-on-error RET t RET') and include the backtrace in your bug report. Please describe the bug in annoying, painstaking detail. @@ -1579,206 +1982,191 @@ Thank you for your help in stamping out bugs. ;; Define some autoload functions Gnus might use. (eval-and-compile - ;; Various - (autoload 'metamail-buffer "metamail") - (autoload 'Info-goto-node "info") - (autoload 'hexl-hex-string-to-integer "hexl") - (autoload 'pp "pp") - (autoload 'pp-to-string "pp") - (autoload 'pp-eval-expression "pp") - (autoload 'mail-extract-address-components "mail-extr") - - (autoload 'nnmail-split-fancy "nnmail") - (autoload 'nnvirtual-catchup-group "nnvirtual") - - ;; timezone - (autoload 'timezone-make-date-arpa-standard "timezone") - (autoload 'timezone-fix-time "timezone") - (autoload 'timezone-make-sortable-date "timezone") - (autoload 'timezone-make-time-string "timezone") - - ;; rmail & friends - (autoload 'mail-position-on-field "sendmail") - (autoload 'mail-setup "sendmail") - (autoload 'rmail-output "rmailout") - (autoload 'news-mail-other-window "rnewspost") - (autoload 'news-reply-yank-original "rnewspost") - (autoload 'news-caesar-buffer-body "rnewspost") - (autoload 'rmail-insert-rmail-file-header "rmail") - (autoload 'rmail-count-new-messages "rmail") - (autoload 'rmail-show-message "rmail") - - ;; gnus-soup - ;;(autoload 'gnus-group-brew-soup "gnus-soup" nil t) - ;;(autoload 'gnus-brew-soup "gnus-soup" nil t) - ;;(autoload 'gnus-soup-add-article "gnus-soup" nil t) - ;;(autoload 'gnus-soup-send-replies "gnus-soup" nil t) - ;;(autoload 'gnus-soup-save-areas "gnus-soup" nil t) - ;;(autoload 'gnus-soup-pack-packet "gnus-soup" nil t) - ;;(autoload 'nnsoup-pack-replies "nnsoup" nil t) - - ;; gnus-mh - (autoload 'gnus-mail-reply-using-mhe "gnus-mh") - (autoload 'gnus-mail-forward-using-mhe "gnus-mh") - (autoload 'gnus-mail-other-window-using-mhe "gnus-mh") - (autoload 'gnus-summary-save-in-folder "gnus-mh" nil t) - (autoload 'gnus-summary-save-article-folder "gnus-mh") - (autoload 'gnus-Folder-save-name "gnus-mh") - (autoload 'gnus-folder-save-name "gnus-mh") - - ;; gnus-vis misc - (autoload 'gnus-group-make-menu-bar "gnus-vis") - (autoload 'gnus-summary-make-menu-bar "gnus-vis") - (autoload 'gnus-server-make-menu-bar "gnus-vis") - (autoload 'gnus-article-make-menu-bar "gnus-vis") - (autoload 'gnus-browse-make-menu-bar "gnus-vis") - (autoload 'gnus-highlight-selected-summary "gnus-vis") - (autoload 'gnus-summary-highlight-line "gnus-vis") - (autoload 'gnus-carpal-setup-buffer "gnus-vis") - - ;; gnus-vis article - (autoload 'gnus-article-push-button "gnus-vis" nil t) - (autoload 'gnus-article-press-button "gnus-vis" nil t) - (autoload 'gnus-article-highlight "gnus-vis" nil t) - (autoload 'gnus-article-highlight-some "gnus-vis" nil t) - (autoload 'gnus-article-hide "gnus-vis" nil t) - (autoload 'gnus-article-hide-signature "gnus-vis" nil t) - (autoload 'gnus-article-highlight-headers "gnus-vis" nil t) - (autoload 'gnus-article-highlight-signature "gnus-vis" nil t) - (autoload 'gnus-article-add-buttons "gnus-vis" nil t) - (autoload 'gnus-article-next-button "gnus-vis" nil t) - (autoload 'gnus-article-add-button "gnus-vis") - - ;; gnus-cite - (autoload 'gnus-article-highlight-citation "gnus-cite" nil t) - (autoload 'gnus-article-hide-citation-maybe "gnus-cite" nil t) - (autoload 'gnus-article-hide-citation "gnus-cite" nil t) - - ;; gnus-kill - (autoload 'gnus-kill "gnus-kill") - (autoload 'gnus-apply-kill-file-internal "gnus-kill") - (autoload 'gnus-kill-file-edit-file "gnus-kill") - (autoload 'gnus-kill-file-raise-followups-to-author "gnus-kill") - (autoload 'gnus-execute "gnus-kill") - (autoload 'gnus-expunge "gnus-kill") - - ;; gnus-cache - (autoload 'gnus-cache-possibly-enter-article "gnus-cache") - (autoload 'gnus-cache-save-buffers "gnus-cache") - (autoload 'gnus-cache-possibly-remove-articles "gnus-cache") - (autoload 'gnus-cache-request-article "gnus-cache") - (autoload 'gnus-cache-retrieve-headers "gnus-cache") - (autoload 'gnus-cache-possibly-alter-active "gnus-cache") - (autoload 'gnus-jog-cache "gnus-cache" nil t) - (autoload 'gnus-cache-enter-remove-article "gnus-cache") - - ;; gnus-score - (autoload 'gnus-summary-increase-score "gnus-score" nil t) - (autoload 'gnus-summary-lower-score "gnus-score" nil t) - (autoload 'gnus-summary-score-map "gnus-score" nil nil 'keymap) - (autoload 'gnus-score-save "gnus-score") - (autoload 'gnus-score-headers "gnus-score") - (autoload 'gnus-current-score-file-nondirectory "gnus-score") - (autoload 'gnus-score-adaptive "gnus-score") - (autoload 'gnus-score-remove-lines-adaptive "gnus-score") - (autoload 'gnus-score-find-trace "gnus-score") - - ;; gnus-edit - (autoload 'gnus-score-customize "gnus-edit" nil t) - - ;; gnus-uu - (autoload 'gnus-uu-extract-map "gnus-uu" nil nil 'keymap) - (autoload 'gnus-uu-mark-map "gnus-uu" nil nil 'keymap) - (autoload 'gnus-uu-digest-mail-forward "gnus-uu" nil t) - (autoload 'gnus-uu-digest-post-forward "gnus-uu" nil t) - (autoload 'gnus-uu-mark-series "gnus-uu" nil t) - (autoload 'gnus-uu-mark-region "gnus-uu" nil t) - (autoload 'gnus-uu-mark-by-regexp "gnus-uu" nil t) - (autoload 'gnus-uu-mark-all "gnus-uu" nil t) - (autoload 'gnus-uu-mark-sparse "gnus-uu" nil t) - (autoload 'gnus-uu-mark-thread "gnus-uu" nil t) - (autoload 'gnus-uu-decode-uu "gnus-uu" nil t) - (autoload 'gnus-uu-decode-uu-and-save "gnus-uu" nil t) - (autoload 'gnus-uu-decode-unshar "gnus-uu" nil t) - (autoload 'gnus-uu-decode-unshar-and-save "gnus-uu" nil t) - (autoload 'gnus-uu-decode-save "gnus-uu" nil t) - (autoload 'gnus-uu-decode-binhex "gnus-uu" nil t) - (autoload 'gnus-uu-decode-uu-view "gnus-uu" nil t) - (autoload 'gnus-uu-decode-uu-and-save-view "gnus-uu" nil t) - (autoload 'gnus-uu-decode-unshar-view "gnus-uu" nil t) - (autoload 'gnus-uu-decode-unshar-and-save-view "gnus-uu" nil t) - (autoload 'gnus-uu-decode-save-view "gnus-uu" nil t) - (autoload 'gnus-uu-decode-binhex-view "gnus-uu" nil t) - - ;; gnus-msg - (autoload 'gnus-summary-send-map "gnus-msg" nil nil 'keymap) - (autoload 'gnus-group-post-news "gnus-msg" nil t) - (autoload 'gnus-group-mail "gnus-msg" nil t) - (autoload 'gnus-summary-post-news "gnus-msg" nil t) - (autoload 'gnus-summary-followup "gnus-msg" nil t) - (autoload 'gnus-summary-followup-with-original "gnus-msg" nil t) - (autoload 'gnus-summary-followup-and-reply "gnus-msg" nil t) - (autoload 'gnus-summary-followup-and-reply-with-original "gnus-msg" nil t) - (autoload 'gnus-summary-cancel-article "gnus-msg" nil t) - (autoload 'gnus-summary-supersede-article "gnus-msg" nil t) - (autoload 'gnus-post-news "gnus-msg" nil t) - (autoload 'gnus-inews-news "gnus-msg" nil t) - (autoload 'gnus-cancel-news "gnus-msg" nil t) - (autoload 'gnus-summary-reply "gnus-msg" nil t) - (autoload 'gnus-summary-reply-with-original "gnus-msg" nil t) - (autoload 'gnus-summary-mail-forward "gnus-msg" nil t) - (autoload 'gnus-summary-mail-other-window "gnus-msg" nil t) - (autoload 'gnus-mail-reply-using-mail "gnus-msg") - (autoload 'gnus-mail-yank-original "gnus-msg") - (autoload 'gnus-mail-send-and-exit "gnus-msg") - (autoload 'gnus-mail-forward-using-mail "gnus-msg") - (autoload 'gnus-mail-other-window-using-mail "gnus-msg") - (autoload 'gnus-article-mail "gnus-msg") - (autoload 'gnus-bug "gnus-msg" nil t) - - ;; gnus-vm - (autoload 'gnus-summary-save-in-vm "gnus-vm" nil t) - (autoload 'gnus-summary-save-article-vm "gnus-vm" nil t) - (autoload 'gnus-mail-forward-using-vm "gnus-vm") - (autoload 'gnus-mail-reply-using-vm "gnus-vm") - (autoload 'gnus-mail-other-window-using-vm "gnus-vm" nil t) - (autoload 'gnus-yank-article "gnus-vm" nil t) - - ) + ;; This little mapcar goes through the list below and marks the + ;; symbols in question as autoloaded functions. + (mapcar + (lambda (package) + (let ((interactive (nth 1 (memq ':interactive package)))) + (mapcar + (lambda (function) + (let (keymap) + (when (consp function) + (setq keymap (car (memq 'keymap function))) + (setq function (car function))) + (autoload function (car package) nil interactive keymap))) + (if (eq (nth 1 package) ':interactive) + (cdddr package) + (cdr package))))) + '(("metamail" metamail-buffer) + ("info" Info-goto-node) + ("hexl" hexl-hex-string-to-integer) + ("pp" pp pp-to-string pp-eval-expression) + ("mail-extr" mail-extract-address-components) + ("nnmail" nnmail-split-fancy nnmail-article-group) + ("nnvirtual" nnvirtual-catchup-group) + ("timezone" timezone-make-date-arpa-standard timezone-fix-time + timezone-make-sortable-date timezone-make-time-string) + ("rmailout" rmail-output) + ("rmail" rmail-insert-rmail-file-header rmail-count-new-messages + rmail-show-message) + ("gnus-soup" :interactive t + gnus-group-brew-soup gnus-brew-soup gnus-soup-add-article + gnus-soup-send-replies gnus-soup-save-areas gnus-soup-pack-packet) + ("nnsoup" nnsoup-pack-replies) + ("gnus-scomo" :interactive t gnus-score-mode) + ("gnus-mh" gnus-mh-mail-setup gnus-summary-save-article-folder + gnus-Folder-save-name gnus-folder-save-name) + ("gnus-mh" :interactive t gnus-summary-save-in-folder) + ("gnus-vis" gnus-group-make-menu-bar gnus-summary-make-menu-bar + gnus-server-make-menu-bar gnus-article-make-menu-bar + gnus-browse-make-menu-bar gnus-highlight-selected-summary + gnus-summary-highlight-line gnus-carpal-setup-buffer + gnus-group-highlight-line + gnus-article-add-button gnus-insert-next-page-button + gnus-insert-prev-page-button gnus-visual-turn-off-edit-menu) + ("gnus-vis" :interactive t + gnus-article-push-button gnus-article-press-button + gnus-article-highlight gnus-article-highlight-some + gnus-article-highlight-headers gnus-article-highlight-signature + gnus-article-add-buttons gnus-article-add-buttons-to-head + gnus-article-next-button gnus-article-prev-button) + ("gnus-demon" gnus-demon-add-nocem gnus-demon-add-scanmail + gnus-demon-add-disconnection gnus-demon-add-handler + gnus-demon-remove-handler) + ("gnus-demon" :interactive t + gnus-demon-init gnus-demon-cancel) + ("gnus-salt" gnus-highlight-selected-tree gnus-possibly-generate-tree + gnus-tree-open gnus-tree-close) + ("gnus-nocem" gnus-nocem-scan-groups gnus-nocem-close + gnus-nocem-unwanted-article-p) + ("gnus-srvr" gnus-enter-server-buffer gnus-server-set-info) + ("gnus-srvr" gnus-browse-foreign-server) + ("gnus-cite" :interactive t + gnus-article-highlight-citation gnus-article-hide-citation-maybe + gnus-article-hide-citation gnus-article-fill-cited-article + gnus-article-hide-citation-in-followups) + ("gnus-kill" gnus-kill gnus-apply-kill-file-internal + gnus-kill-file-edit-file gnus-kill-file-raise-followups-to-author + gnus-execute gnus-expunge) + ("gnus-cache" gnus-cache-possibly-enter-article gnus-cache-save-buffers + gnus-cache-possibly-remove-articles gnus-cache-request-article + gnus-cache-retrieve-headers gnus-cache-possibly-alter-active + gnus-cache-enter-remove-article gnus-cached-article-p + gnus-cache-open gnus-cache-close gnus-cache-update-article) + ("gnus-cache" :interactive t gnus-jog-cache gnus-cache-enter-article + gnus-cache-remove-article) + ("gnus-score" :interactive t + gnus-summary-increase-score gnus-summary-lower-score + gnus-score-flush-cache gnus-score-close + gnus-score-raise-same-subject-and-select + gnus-score-raise-same-subject gnus-score-default + gnus-score-raise-thread gnus-score-lower-same-subject-and-select + gnus-score-lower-same-subject gnus-score-lower-thread + gnus-possibly-score-headers gnus-summary-raise-score + gnus-summary-set-score gnus-summary-current-score) + ("gnus-score" + (gnus-summary-score-map keymap) gnus-score-save gnus-score-headers + gnus-current-score-file-nondirectory gnus-score-adaptive + gnus-score-find-trace gnus-score-file-name) + ("gnus-edit" :interactive t gnus-score-customize) + ("gnus-topic" :interactive t gnus-topic-mode) + ("gnus-topic" gnus-topic-remove-group) + ("gnus-salt" :interactive t gnus-pick-mode gnus-binary-mode) + ("gnus-uu" (gnus-uu-extract-map keymap) (gnus-uu-mark-map keymap)) + ("gnus-uu" :interactive t + gnus-uu-digest-mail-forward gnus-uu-digest-post-forward + gnus-uu-mark-series gnus-uu-mark-region gnus-uu-mark-buffer + gnus-uu-mark-by-regexp gnus-uu-mark-all + gnus-uu-mark-sparse gnus-uu-mark-thread gnus-uu-decode-uu + gnus-uu-decode-uu-and-save gnus-uu-decode-unshar + gnus-uu-decode-unshar-and-save gnus-uu-decode-save + gnus-uu-decode-binhex gnus-uu-decode-uu-view + gnus-uu-decode-uu-and-save-view gnus-uu-decode-unshar-view + gnus-uu-decode-unshar-and-save-view gnus-uu-decode-save-view + gnus-uu-decode-binhex-view) + ("gnus-msg" (gnus-summary-send-map keymap) + gnus-mail-yank-original gnus-mail-send-and-exit + gnus-article-mail gnus-new-mail gnus-mail-reply) + ("gnus-msg" :interactive t + gnus-group-post-news gnus-group-mail gnus-summary-post-news + gnus-summary-followup gnus-summary-followup-with-original + gnus-summary-cancel-article gnus-summary-supersede-article + gnus-post-news gnus-inews-news + gnus-summary-reply gnus-summary-reply-with-original + gnus-summary-mail-forward gnus-summary-mail-other-window + gnus-bug) + ("gnus-picon" :interactive t gnus-article-display-picons + gnus-group-display-picons gnus-picons-article-display-x-face) + ("gnus-gl" bbb-login bbb-logout bbb-grouplens-group-p + gnus-grouplens-mode) + ("smiley" :interactive t gnus-smiley-display) + ("gnus-vm" gnus-vm-mail-setup) + ("gnus-vm" :interactive t gnus-summary-save-in-vm + gnus-summary-save-article-vm)))) ;; Fix by Hallvard B Furuseth . ;; If you want the cursor to go somewhere else, set these two ;; functions in some startup hook to whatever you want. -(defalias 'gnus-summary-position-cursor 'gnus-goto-colon) -(defalias 'gnus-group-position-cursor 'gnus-goto-colon) +(defalias 'gnus-summary-position-point 'gnus-goto-colon) +(defalias 'gnus-group-position-point 'gnus-goto-colon) ;;; Various macros and substs. +(defun gnus-header-from (header) + (mail-header-from header)) + (defmacro gnus-eval-in-buffer-window (buffer &rest forms) - "Pop to BUFFER, evaluate FORMS, and then returns to original window." - (` (let ((GnusStartBufferWindow (selected-window))) + "Pop to BUFFER, evaluate FORMS, and then return to the original window." + (let ((tempvar (make-symbol "GnusStartBufferWindow")) + (w (make-symbol "w")) + (buf (make-symbol "buf"))) + `(let* ((,tempvar (selected-window)) + (,buf ,buffer) + (,w (get-buffer-window ,buf 'visible))) (unwind-protect (progn - (pop-to-buffer (, buffer)) - (,@ forms)) - (select-window GnusStartBufferWindow))))) + (if ,w + (select-window ,w) + (pop-to-buffer ,buf)) + ,@forms) + (select-window ,tempvar))))) + +(put 'gnus-eval-in-buffer-window 'lisp-indent-function 1) +(put 'gnus-eval-in-buffer-window 'lisp-indent-hook 1) +(put 'gnus-eval-in-buffer-window 'edebug-form-spec '(form body)) (defmacro gnus-gethash (string hashtable) "Get hash value of STRING in HASHTABLE." - ;;(` (symbol-value (abbrev-symbol (, string) (, hashtable)))) - ;;(` (abbrev-expansion (, string) (, hashtable))) - (` (symbol-value (intern-soft (, string) (, hashtable))))) + `(symbol-value (intern-soft ,string ,hashtable))) (defmacro gnus-sethash (string value hashtable) - "Set hash value. Arguments are STRING, VALUE, and HASHTABLE." - ;; We cannot use define-abbrev since it only accepts string as value. - ;; (set (intern string hashtable) value)) - (` (set (intern (, string) (, hashtable)) (, value)))) + "Set hash value. Arguments are STRING, VALUE, and HASHTABLE." + `(set (intern ,string ,hashtable) ,value)) + +(defmacro gnus-intern-safe (string hashtable) + "Set hash value. Arguments are STRING, VALUE, and HASHTABLE." + `(let ((symbol (intern ,string ,hashtable))) + (or (boundp symbol) + (set symbol nil)) + symbol)) + +(defmacro gnus-group-unread (group) + "Get the currently computed number of unread articles in GROUP." + `(car (gnus-gethash ,group gnus-newsrc-hashtb))) + +(defmacro gnus-group-entry (group) + "Get the newsrc entry for GROUP." + `(gnus-gethash ,group gnus-newsrc-hashtb)) -(defsubst gnus-buffer-substring (beg end) - (buffer-substring (match-beginning beg) (match-end end))) +(defmacro gnus-active (group) + "Get active info on GROUP." + `(gnus-gethash ,group gnus-active-hashtb)) + +(defmacro gnus-set-active (group active) + "Set GROUP's active info." + `(gnus-sethash ,group ,active gnus-active-hashtb)) ;; modified by MORIOKA Tomohiko ;; function `substring' might cut on a middle of multi-octet @@ -1786,8 +2174,8 @@ Thank you for your help in stamping out bugs. (defun gnus-truncate-string (str width) (substring str 0 width)) -;; Added by Geoffrey T. Dairiki . A safe way -;; to limit the length of a string. This function is necessary since +;; Added by Geoffrey T. Dairiki . A safe way +;; to limit the length of a string. This function is necessary since ;; `(substr "abc" 0 30)' pukes with "Args out of range". (defsubst gnus-limit-string (str width) (if (> (length str) width) @@ -1796,25 +2184,31 @@ Thank you for your help in stamping out bugs. (defsubst gnus-simplify-subject-re (subject) "Remove \"Re:\" from subject lines." - (let ((case-fold-search t)) - (if (string-match "^re: *" subject) - (substring subject (match-end 0)) - subject))) + (if (string-match "^[Rr][Ee]: *" subject) + (substring subject (match-end 0)) + subject)) + +(defsubst gnus-functionp (form) + "Return non-nil if FORM is funcallable." + (or (and (symbolp form) (fboundp form)) + (and (listp form) (eq (car form) 'lambda)))) (defsubst gnus-goto-char (point) (and point (goto-char point))) (defmacro gnus-buffer-exists-p (buffer) - (` (and (, buffer) - (funcall (if (stringp (, buffer)) 'get-buffer 'buffer-name) - (, buffer))))) + `(let ((buffer ,buffer)) + (and buffer + (funcall (if (stringp buffer) 'get-buffer 'buffer-name) + buffer)))) (defmacro gnus-kill-buffer (buffer) - (` (if (gnus-buffer-exists-p (, buffer)) - (kill-buffer (, buffer))))) + `(let ((buf ,buffer)) + (if (gnus-buffer-exists-p buf) + (kill-buffer buf)))) (defsubst gnus-point-at-bol () - "Return point at the beginning of line." + "Return point at the beginning of the line." (let ((p (point))) (beginning-of-line) (prog1 @@ -1822,17 +2216,34 @@ Thank you for your help in stamping out bugs. (goto-char p)))) (defsubst gnus-point-at-eol () - "Return point at the beginning of line." + "Return point at the end of the line." (let ((p (point))) (end-of-line) (prog1 (point) (goto-char p)))) +(defun gnus-alive-p () + "Say whether Gnus is running or not." + (and gnus-group-buffer + (get-buffer gnus-group-buffer))) + +(defun gnus-delete-first (elt list) + "Delete by side effect the first occurrence of ELT as a member of LIST." + (if (equal (car list) elt) + (cdr list) + (let ((total list)) + (while (and (cdr list) + (not (equal (cadr list) elt))) + (setq list (cdr list))) + (when (cdr list) + (setcdr list (cddr list))) + total))) + ;; Delete the current line (and the next N lines.); (defmacro gnus-delete-line (&optional n) - (` (delete-region (progn (beginning-of-line) (point)) - (progn (forward-line (, (or n 1))) (point))))) + `(delete-region (progn (beginning-of-line) (point)) + (progn (forward-line ,(or n 1)) (point)))) ;; Suggested by Brian Edmonds . (defvar gnus-init-inhibit nil) @@ -1841,21 +2252,207 @@ Thank you for your help in stamping out bugs. (setq gnus-init-inhibit nil) (setq gnus-init-inhibit inhibit-next) (and gnus-init-file - (or (and (file-exists-p gnus-init-file) + (or (and (file-exists-p gnus-init-file) ;; Don't try to load a directory. (not (file-directory-p gnus-init-file))) (file-exists-p (concat gnus-init-file ".el")) (file-exists-p (concat gnus-init-file ".elc"))) - (load gnus-init-file nil t)))) - -;;; Load the user startup file. -;; (eval '(gnus-read-init-file 'inhibit)) - -;;; Load the compatibility functions. + (condition-case var + (load gnus-init-file nil t) + (error + (error "Error in %s: %s" gnus-init-file var)))))) + +;; Info access macros. + +(defmacro gnus-info-group (info) + `(nth 0 ,info)) +(defmacro gnus-info-rank (info) + `(nth 1 ,info)) +(defmacro gnus-info-read (info) + `(nth 2 ,info)) +(defmacro gnus-info-marks (info) + `(nth 3 ,info)) +(defmacro gnus-info-method (info) + `(nth 4 ,info)) +(defmacro gnus-info-params (info) + `(nth 5 ,info)) + +(defmacro gnus-info-level (info) + `(let ((rank (gnus-info-rank ,info))) + (if (consp rank) + (car rank) + rank))) +(defmacro gnus-info-score (info) + `(let ((rank (gnus-info-rank ,info))) + (or (and (consp rank) (cdr rank)) 0))) + +(defmacro gnus-info-set-group (info group) + `(setcar ,info ,group)) +(defmacro gnus-info-set-rank (info rank) + `(setcar (nthcdr 1 ,info) ,rank)) +(defmacro gnus-info-set-read (info read) + `(setcar (nthcdr 2 ,info) ,read)) +(defmacro gnus-info-set-marks (info marks) + `(setcar (nthcdr 3 ,info) ,marks)) +(defmacro gnus-info-set-method (info method) + `(setcar (nthcdr 4 ,info) ,method)) +(defmacro gnus-info-set-params (info params) + `(setcar (nthcdr 5 ,info) ,params)) + +(defmacro gnus-info-set-level (info level) + `(let ((rank (cdr ,info))) + (if (consp (car rank)) + (setcar (car rank) ,level) + (setcar rank ,level)))) +(defmacro gnus-info-set-score (info score) + `(let ((rank (cdr ,info))) + (if (consp (car rank)) + (setcdr (car rank) ,score) + (setcar rank (cons (car rank) ,score))))) + +(defmacro gnus-get-info (group) + `(nth 2 (gnus-gethash ,group gnus-newsrc-hashtb))) + +(defun gnus-byte-code (func) + "Return a form that can be `eval'ed based on FUNC." + (let ((fval (symbol-function func))) + (if (byte-code-function-p fval) + (let ((flist (append fval nil))) + (setcar flist 'byte-code) + flist) + (cons 'progn (cddr fval))))) + +;; Find out whether the gnus-visual TYPE is wanted. +(defun gnus-visual-p (&optional type class) + (and gnus-visual ; Has to be non-nil, at least. + (if (not type) ; We don't care about type. + gnus-visual + (if (listp gnus-visual) ; It's a list, so we check it. + (or (memq type gnus-visual) + (memq class gnus-visual)) + t)))) + +;;; Load the compatability functions. (require 'gnus-cus) (require 'gnus-ems) + +;;; +;;; Shutdown +;;; + +(defvar gnus-shutdown-alist nil) + +(defun gnus-add-shutdown (function &rest symbols) + "Run FUNCTION whenever one of SYMBOLS is shut down." + (push (cons function symbols) gnus-shutdown-alist)) + +(defun gnus-shutdown (symbol) + "Shut down everything that waits for SYMBOL." + (let ((alist gnus-shutdown-alist) + entry) + (while (setq entry (pop alist)) + (when (memq symbol (cdr entry)) + (funcall (car entry)))))) + + + +;; Format specs. The chunks below are the machine-generated forms +;; that are to be evaled as the result of the default format strings. +;; We write them in here to get them byte-compiled. That way the +;; default actions will be quite fast, while still retaining the full +;; flexibility of the user-defined format specs. + +;; First we have lots of dummy defvars to let the compiler know these +;; are really dynamic variables. + +(defvar gnus-tmp-unread) +(defvar gnus-tmp-replied) +(defvar gnus-tmp-score-char) +(defvar gnus-tmp-indentation) +(defvar gnus-tmp-opening-bracket) +(defvar gnus-tmp-lines) +(defvar gnus-tmp-name) +(defvar gnus-tmp-closing-bracket) +(defvar gnus-tmp-subject-or-nil) +(defvar gnus-tmp-subject) +(defvar gnus-tmp-marked) +(defvar gnus-tmp-marked-mark) +(defvar gnus-tmp-subscribed) +(defvar gnus-tmp-process-marked) +(defvar gnus-tmp-number-of-unread) +(defvar gnus-tmp-group-name) +(defvar gnus-tmp-group) +(defvar gnus-tmp-article-number) +(defvar gnus-tmp-unread-and-unselected) +(defvar gnus-tmp-news-method) +(defvar gnus-tmp-news-server) +(defvar gnus-tmp-article-number) +(defvar gnus-mouse-face) +(defvar gnus-mouse-face-prop) + +(defun gnus-summary-line-format-spec () + (insert gnus-tmp-unread gnus-tmp-replied + gnus-tmp-score-char gnus-tmp-indentation) + (gnus-put-text-property + (point) + (progn + (insert + gnus-tmp-opening-bracket + (format "%4d: %-20s" + gnus-tmp-lines + (if (> (length gnus-tmp-name) 20) + (substring gnus-tmp-name 0 20) + gnus-tmp-name)) + gnus-tmp-closing-bracket) + (point)) + gnus-mouse-face-prop gnus-mouse-face) + (insert " " gnus-tmp-subject-or-nil "\n")) + +(defvar gnus-summary-line-format-spec + (gnus-byte-code 'gnus-summary-line-format-spec)) + +(defun gnus-summary-dummy-line-format-spec () + (insert "* ") + (gnus-put-text-property + (point) + (progn + (insert ": :") + (point)) + gnus-mouse-face-prop gnus-mouse-face) + (insert " " gnus-tmp-subject "\n")) + +(defvar gnus-summary-dummy-line-format-spec + (gnus-byte-code 'gnus-summary-dummy-line-format-spec)) + +(defun gnus-group-line-format-spec () + (insert gnus-tmp-marked-mark gnus-tmp-subscribed + gnus-tmp-process-marked + gnus-group-indentation + (format "%5s: " gnus-tmp-number-of-unread)) + (gnus-put-text-property + (point) + (progn + (insert gnus-tmp-group "\n") + (1- (point))) + gnus-mouse-face-prop gnus-mouse-face)) +(defvar gnus-group-line-format-spec + (gnus-byte-code 'gnus-group-line-format-spec)) + +(defvar gnus-format-specs + `((version . ,emacs-version) + (group ,gnus-group-line-format ,gnus-group-line-format-spec) + (summary-dummy ,gnus-summary-dummy-line-format + ,gnus-summary-dummy-line-format-spec) + (summary ,gnus-summary-line-format ,gnus-summary-line-format-spec))) + +(defvar gnus-article-mode-line-format-spec nil) +(defvar gnus-summary-mode-line-format-spec nil) +(defvar gnus-group-mode-line-format-spec nil) + +;;; Phew. All that gruft is over, fortunately. + ;;; ;;; Gnus Utility Functions @@ -1870,24 +2467,24 @@ Thank you for your help in stamping out bugs. (setq address (substring from (match-beginning 0) (match-end 0)))) ;; Then we check whether the "name
" format is used. (and address - ;; Fix by MORIOKA Tomohiko - ;; Linear white space is not required. - (string-match (concat "[ \t]*<" (regexp-quote address) ">") from) - (and (setq name (substring from 0 (match-beginning 0))) + ;; Fix by MORIOKA Tomohiko + ;; Linear white space is not required. + (string-match (concat "[ \t]*<" (regexp-quote address) ">") from) + (and (setq name (substring from 0 (match-beginning 0))) ;; Strip any quotes from the name. (string-match "\".*\"" name) (setq name (substring name 1 (1- (match-end 0)))))) ;; If not, then "address (name)" is used. (or name (and (string-match "(.+)" from) - (setq name (substring from (1+ (match-beginning 0)) + (setq name (substring from (1+ (match-beginning 0)) (1- (match-end 0))))) (and (string-match "()" from) (setq name address)) ;; Fix by MORIOKA Tomohiko . ;; XOVER might not support folded From headers. (and (string-match "(.*" from) - (setq name (substring from (1+ (match-beginning 0)) + (setq name (substring from (1+ (match-beginning 0)) (match-end 0))))) ;; Fix by Hallvard B Furuseth . (list (or name from) (or address from)))) @@ -1896,180 +2493,354 @@ Thank you for your help in stamping out bugs. "Return the value of the header FIELD of current article." (save-excursion (save-restriction - (let ((case-fold-search t)) - (gnus-narrow-to-headers) - (mail-fetch-field field))))) + (let ((case-fold-search t) + (inhibit-point-motion-hooks t)) + (nnheader-narrow-to-headers) + (message-fetch-field field))))) (defun gnus-goto-colon () (beginning-of-line) (search-forward ":" (gnus-point-at-eol) t)) -(defun gnus-narrow-to-headers () - (widen) - (save-excursion - (narrow-to-region - (goto-char (point-min)) - (if (search-forward "\n\n" nil t) - (1- (point)) - (point-max))))) - -(defvar gnus-old-specs nil) +;;;###autoload +(defun gnus-update-format (var) + "Update the format specification near point." + (interactive + (list + (save-excursion + (eval-defun nil) + ;; Find the end of the current word. + (re-search-forward "[ \t\n]" nil t) + ;; Search backward. + (when (re-search-backward "\\(gnus-[-a-z]+-line-format\\)" nil t) + (match-string 1))))) + (let* ((type (intern (progn (string-match "gnus-\\([-a-z]+\\)-line" var) + (match-string 1 var)))) + (entry (assq type gnus-format-specs)) + value spec) + (when entry + (setq gnus-format-specs (delq entry gnus-format-specs))) + (set + (intern (format "%s-spec" var)) + (gnus-parse-format (setq value (symbol-value (intern var))) + (symbol-value (intern (format "%s-alist" var))) + (not (string-match "mode" var)))) + (setq spec (symbol-value (intern (format "%s-spec" var)))) + (push (list type value spec) gnus-format-specs) + + (pop-to-buffer "*Gnus Format*") + (erase-buffer) + (lisp-interaction-mode) + (insert (pp-to-string spec)))) -(defun gnus-update-format-specifications () +(defun gnus-update-format-specifications (&optional force) + "Update all (necessary) format specifications." + ;; Make the indentation array. (gnus-make-thread-indent-array) - (let ((formats '(summary summary-dummy group - summary-mode group-mode article-mode)) - old-format new-format) - (while formats - (setq new-format (symbol-value - (intern (format "gnus-%s-line-format" (car formats))))) - (or (and (setq old-format (cdr (assq (car formats) gnus-old-specs))) - (equal old-format new-format)) - (set (intern (format "gnus-%s-line-format-spec" (car formats))) - (gnus-parse-format - new-format - (symbol-value - (intern (format "gnus-%s-line-format-alist" - (if (eq (car formats) 'article-mode) - 'summary-mode (car formats)))))))) - (setq gnus-old-specs (cons (cons (car formats) new-format) - (delq (car formats) gnus-old-specs))) - (setq formats (cdr formats)))) - - (gnus-update-group-mark-positions) - (gnus-update-summary-mark-positions) + ;; See whether all the stored info needs to be flushed. + (when (or force + (not (equal emacs-version + (cdr (assq 'version gnus-format-specs))))) + (setq gnus-format-specs nil)) + + ;; Go through all the formats and see whether they need updating. + (let ((types '(summary summary-dummy group + summary-mode group-mode article-mode)) + new-format entry type val) + (while (setq type (pop types)) + ;; Jump to the proper buffer to find out the value of + ;; the variable, if possible. (It may be buffer-local.) + (save-excursion + (let ((buffer (intern (format "gnus-%s-buffer" type))) + val) + (when (and (boundp buffer) + (setq val (symbol-value buffer)) + (get-buffer val) + (buffer-name (get-buffer val))) + (set-buffer (get-buffer val))) + (setq new-format (symbol-value + (intern (format "gnus-%s-line-format" type)))))) + (setq entry (cdr (assq type gnus-format-specs))) + (if (and entry + (equal (car entry) new-format)) + ;; Use the old format. + (set (intern (format "gnus-%s-line-format-spec" type)) + (cadr entry)) + ;; This is a new format. + (setq val + (if (not (stringp new-format)) + ;; This is a function call or something. + new-format + ;; This is a "real" format. + (gnus-parse-format + new-format + (symbol-value + (intern (format "gnus-%s-line-format-alist" + (if (eq type 'article-mode) + 'summary-mode type)))) + (not (string-match "mode$" (symbol-name type)))))) + ;; Enter the new format spec into the list. + (if entry + (progn + (setcar (cdr entry) val) + (setcar entry new-format)) + (push (list type new-format val) gnus-format-specs)) + (set (intern (format "gnus-%s-line-format-spec" type)) val)))) - (if (and (string-match "%D" gnus-group-line-format) - (not gnus-description-hashtb) - gnus-read-active-file) - (gnus-read-all-descriptions-files))) + (unless (assq 'version gnus-format-specs) + (push (cons 'version emacs-version) gnus-format-specs)) + + (gnus-update-group-mark-positions) + (gnus-update-summary-mark-positions)) (defun gnus-update-summary-mark-positions () + "Compute where the summary marks are to go." (save-excursion + (when (and gnus-summary-buffer + (get-buffer gnus-summary-buffer) + (buffer-name (get-buffer gnus-summary-buffer))) + (set-buffer gnus-summary-buffer)) (let ((gnus-replied-mark 129) (gnus-score-below-mark 130) (gnus-score-over-mark 130) (thread nil) + (gnus-visual nil) + (spec gnus-summary-line-format-spec) pos) - (gnus-set-work-buffer) - (gnus-summary-insert-line - nil [0 "" "" "" "" "" 0 0 ""] 0 nil 128 t nil "" nil 1) - (goto-char (point-min)) - (setq pos (list (cons 'unread (and (search-forward "\200" nil t) - (- (point) 2))))) - (goto-char (point-min)) - (setq pos (cons (cons 'replied (and (search-forward "\201" nil t) - (- (point) 2))) pos)) - (goto-char (point-min)) - (setq pos (cons (cons 'score (and (search-forward "\202" nil t) - (- (point) 2))) pos)) + (save-excursion + (gnus-set-work-buffer) + (let ((gnus-summary-line-format-spec spec)) + (gnus-summary-insert-line + [0 "" "" "" "" "" 0 0 ""] 0 nil 128 t nil "" nil 1) + (goto-char (point-min)) + (setq pos (list (cons 'unread (and (search-forward "\200" nil t) + (- (point) 2))))) + (goto-char (point-min)) + (push (cons 'replied (and (search-forward "\201" nil t) + (- (point) 2))) + pos) + (goto-char (point-min)) + (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2))) + pos))) (setq gnus-summary-mark-positions pos)))) (defun gnus-update-group-mark-positions () (save-excursion (let ((gnus-process-mark 128) - (gnus-group-marked '("dummy.group"))) - (gnus-sethash "dummy.group" '(0 . 0) gnus-active-hashtb) + (gnus-group-marked '("dummy.group")) + (gnus-active-hashtb (make-vector 10 0))) + (gnus-set-active "dummy.group" '(0 . 0)) (gnus-set-work-buffer) - (gnus-group-insert-group-line nil "dummy.group" 0 nil 0 nil) + (gnus-group-insert-group-line "dummy.group" 0 nil 0 nil) (goto-char (point-min)) (setq gnus-group-mark-positions (list (cons 'process (and (search-forward "\200" nil t) (- (point) 2)))))))) -(defun gnus-mouse-face-function (form) - (` (let ((string (, form))) - (put-text-property 0 (length string) 'mouse-face gnus-mouse-face string) - string))) +(defvar gnus-mouse-face-0 'highlight) +(defvar gnus-mouse-face-1 'highlight) +(defvar gnus-mouse-face-2 'highlight) +(defvar gnus-mouse-face-3 'highlight) +(defvar gnus-mouse-face-4 'highlight) + +(defun gnus-mouse-face-function (form type) + `(gnus-put-text-property + (point) (progn ,@form (point)) + gnus-mouse-face-prop + ,(if (equal type 0) + 'gnus-mouse-face + `(quote ,(symbol-value (intern (format "gnus-mouse-face-%d" type))))))) + +(defvar gnus-face-0 'bold) +(defvar gnus-face-1 'italic) +(defvar gnus-face-2 'bold-italic) +(defvar gnus-face-3 'bold) +(defvar gnus-face-4 'bold) + +(defun gnus-face-face-function (form type) + `(gnus-put-text-property + (point) (progn ,@form (point)) + 'face ',(symbol-value (intern (format "gnus-face-%d" type))))) (defun gnus-max-width-function (el max-width) (or (numberp max-width) (signal 'wrong-type-argument '(numberp max-width))) - (` (let* ((val (eval (, el))) - (valstr (if (numberp val) - (int-to-string val) val))) - (if (> (length valstr) (, max-width)) - (substring valstr 0 (, max-width)) - valstr)))) - -(defun gnus-parse-format (format spec-alist) + (if (symbolp el) + `(if (> (length ,el) ,max-width) + (substring ,el 0 ,max-width) + ,el) + `(let ((val (eval ,el))) + (if (numberp val) + (setq val (int-to-string val))) + (if (> (length val) ,max-width) + (substring val 0 ,max-width) + val)))) + +(defun gnus-parse-format (format spec-alist &optional insert) ;; This function parses the FORMAT string with the help of the ;; SPEC-ALIST and returns a list that can be eval'ed to return the ;; string. If the FORMAT string contains the specifiers %( and %) ;; the text between them will have the mouse-face text property. - (if (string-match "\\`\\(.*\\)%(\\(.*\\)%)\\(.*\n?\\)\\'" format) - (if (and gnus-visual gnus-mouse-face) - (let ((pre (substring format (match-beginning 1) (match-end 1))) - (button (substring format (match-beginning 2) (match-end 2))) - (post (substring format (match-beginning 3) (match-end 3)))) - (list 'concat - (gnus-parse-simple-format pre spec-alist) - (gnus-mouse-face-function - (gnus-parse-simple-format button spec-alist)) - (gnus-parse-simple-format post spec-alist))) - (gnus-parse-simple-format - (concat (substring format (match-beginning 1) (match-end 1)) - (substring format (match-beginning 2) (match-end 2)) - (substring format (match-beginning 3) (match-end 3))) - spec-alist)) - (gnus-parse-simple-format format spec-alist))) - -(defun gnus-parse-simple-format (format spec-alist) + (if (string-match + "\\`\\(.*\\)%[0-9]?[{(]\\(.*\\)%[0-9]?[})]\\(.*\n?\\)\\'" + format) + (gnus-parse-complex-format format spec-alist) + ;; This is a simple format. + (gnus-parse-simple-format format spec-alist insert))) + +(defun gnus-parse-complex-format (format spec-alist) + (save-excursion + (gnus-set-work-buffer) + (insert format) + (goto-char (point-min)) + (while (re-search-forward "\"" nil t) + (replace-match "\\\"" nil t)) + (goto-char (point-min)) + (insert "(\"") + (while (re-search-forward "%\\([0-9]+\\)?\\([{}()]\\)" nil t) + (let ((number (if (match-beginning 1) + (match-string 1) "0")) + (delim (aref (match-string 2) 0))) + (if (or (= delim ?\() (= delim ?\{)) + (replace-match (concat "\"(" (if (= delim ?\() "mouse" "face") + " " number " \"")) + (replace-match "\")\"")))) + (goto-char (point-max)) + (insert "\")") + (goto-char (point-min)) + (let ((form (read (current-buffer)))) + (cons 'progn (gnus-complex-form-to-spec form spec-alist))))) + +(defun gnus-complex-form-to-spec (form spec-alist) + (delq nil + (mapcar + (lambda (sform) + (if (stringp sform) + (gnus-parse-simple-format sform spec-alist t) + (funcall (intern (format "gnus-%s-face-function" (car sform))) + (gnus-complex-form-to-spec (cddr sform) spec-alist) + (nth 1 sform)))) + form))) + +(defun gnus-parse-simple-format (format spec-alist &optional insert) ;; This function parses the FORMAT string with the help of the - ;; SPEC-ALIST and returns a list that can be eval'ed to return the - ;; string. The list will consist of the symbol `format', a format - ;; specification string, and a list of forms depending on the - ;; SPEC-ALIST. + ;; SPEC-ALIST and returns a list that can be eval'ed to return a + ;; string. (let ((max-width 0) - spec flist fstring newspec elem beg) + spec flist fstring newspec elem beg result dontinsert) (save-excursion (gnus-set-work-buffer) (insert format) (goto-char (point-min)) - (while (re-search-forward "%[-0-9]*\\(,[0-9]+\\)?\\([^0-9]\\)\\(.\\)?" nil t) - (setq spec (string-to-char (buffer-substring (match-beginning 2) - (match-end 2)))) - ;; First check if there are any specs that look anything like - ;; "%12,12A", ie. with a "max width specification". These have - ;; to be treated specially. - (if (setq beg (match-beginning 1)) - (setq max-width - (string-to-int - (buffer-substring (1+ (match-beginning 1)) (match-end 1)))) - (setq max-width 0) - (setq beg (match-beginning 2))) - ;; Find the specification from `spec-alist'. - (if (not (setq elem (cdr (assq spec spec-alist)))) + (while (re-search-forward "%[-0-9]*\\(,[0-9]+\\)?\\([^0-9]\\)\\(.\\)?" + nil t) + (if (= (setq spec (string-to-char (match-string 2))) ?%) + (setq newspec "%" + beg (1+ (match-beginning 0))) + ;; First check if there are any specs that look anything like + ;; "%12,12A", ie. with a "max width specification". These have + ;; to be treated specially. + (if (setq beg (match-beginning 1)) + (setq max-width + (string-to-int + (buffer-substring + (1+ (match-beginning 1)) (match-end 1)))) + (setq max-width 0) + (setq beg (match-beginning 2))) + ;; Find the specification from `spec-alist'. + (unless (setq elem (cdr (assq spec spec-alist))) (setq elem '("*" ?s))) - ;; Treat user defined format specifiers specially - (and (eq (car elem) 'user-defined) - (setq elem - (list - (list (intern (concat "gnus-user-format-function-" - (buffer-substring - (match-beginning 3) - (match-end 3)))) - 'header) - ?s)) - (delete-region (match-beginning 3) (match-end 3))) - (if (not (zerop max-width)) - (let ((el (car elem))) - (cond ((= (car (cdr elem)) ?c) - (setq el (list 'char-to-string el))) - ((= (car (cdr elem)) ?d) - (numberp el) (setq el (list 'int-to-string el)))) - (setq flist (cons (gnus-max-width-function el max-width) - flist)) - (setq newspec ?s)) - (setq flist (cons (car elem) flist)) - (setq newspec (car (cdr elem)))) + ;; Treat user defined format specifiers specially. + (when (eq (car elem) 'gnus-tmp-user-defined) + (setq elem + (list + (list (intern (concat "gnus-user-format-function-" + (match-string 3))) + 'gnus-tmp-header) ?s)) + (delete-region (match-beginning 3) (match-end 3))) + (if (not (zerop max-width)) + (let ((el (car elem))) + (cond ((= (cadr elem) ?c) + (setq el (list 'char-to-string el))) + ((= (cadr elem) ?d) + (setq el (list 'int-to-string el)))) + (setq flist (cons (gnus-max-width-function el max-width) + flist)) + (setq newspec ?s)) + (progn + (setq flist (cons (car elem) flist)) + (setq newspec (cadr elem))))) ;; Remove the old specification (and possibly a ",12" string). (delete-region beg (match-end 2)) ;; Insert the new specification. (goto-char beg) (insert newspec)) (setq fstring (buffer-substring 1 (point-max)))) - (cons 'format (cons fstring (nreverse flist))))) + ;; Do some postprocessing to increase efficiency. + (setq + result + (cond + ;; Emptyness. + ((string= fstring "") + nil) + ;; Not a format string. + ((not (string-match "%" fstring)) + (list fstring)) + ;; A format string with just a single string spec. + ((string= fstring "%s") + (list (car flist))) + ;; A single character. + ((string= fstring "%c") + (list (car flist))) + ;; A single number. + ((string= fstring "%d") + (setq dontinsert) + (if insert + (list `(princ ,(car flist))) + (list `(int-to-string ,(car flist))))) + ;; Just lots of chars and strings. + ((string-match "\\`\\(%[cs]\\)+\\'" fstring) + (nreverse flist)) + ;; A single string spec at the beginning of the spec. + ((string-match "\\`%[sc][^%]+\\'" fstring) + (list (car flist) (substring fstring 2))) + ;; A single string spec in the middle of the spec. + ((string-match "\\`\\([^%]+\\)%[sc]\\([^%]+\\)\\'" fstring) + (list (match-string 1 fstring) (car flist) (match-string 2 fstring))) + ;; A single string spec in the end of the spec. + ((string-match "\\`\\([^%]+\\)%[sc]\\'" fstring) + (list (match-string 1 fstring) (car flist))) + ;; A more complex spec. + (t + (list (cons 'format (cons fstring (nreverse flist))))))) + + (if insert + (when result + (if dontinsert + result + (cons 'insert result))) + (cond ((stringp result) + result) + ((consp result) + (cons 'concat result)) + (t ""))))) + +(defun gnus-eval-format (format &optional alist props) + "Eval the format variable FORMAT, using ALIST. +If PROPS, insert the result." + (let ((form (gnus-parse-format format alist props))) + (if props + (gnus-add-text-properties (point) (progn (eval form) (point)) props) + (eval form)))) + +(defun gnus-remove-text-with-property (prop) + "Delete all text in the current buffer with text property PROP." + (save-excursion + (goto-char (point-min)) + (while (not (eobp)) + (while (get-text-property (point) prop) + (delete-char 1)) + (goto-char (next-single-property-change (point) prop nil (point-max)))))) (defun gnus-set-work-buffer () (if (get-buffer gnus-work-buffer) @@ -2093,7 +2864,7 @@ Otherwise, it is like ~/News/news/group/num." (gnus-capitalize-newsgroup newsgroup) (gnus-newsgroup-directory-form newsgroup)) "/" (int-to-string (mail-header-number headers))) - (or gnus-article-save-directory "~/News")))) + gnus-article-save-directory))) (if (and last-file (string-equal (file-name-directory default) (file-name-directory last-file)) @@ -2104,14 +2875,14 @@ Otherwise, it is like ~/News/news/group/num." (defun gnus-numeric-save-name (newsgroup headers &optional last-file) "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE. If variable `gnus-use-long-file-name' is non-nil, it is -~/News/news.group/num. Otherwise, it is like ~/News/news/group/num." +~/News/news.group/num. Otherwise, it is like ~/News/news/group/num." (let ((default (expand-file-name (concat (if (gnus-use-long-file-name 'not-save) newsgroup (gnus-newsgroup-directory-form newsgroup)) "/" (int-to-string (mail-header-number headers))) - (or gnus-article-save-directory "~/News")))) + gnus-article-save-directory))) (if (and last-file (string-equal (file-name-directory default) (file-name-directory last-file)) @@ -2128,7 +2899,7 @@ If variable `gnus-use-long-file-name' is non-nil, it is (if (gnus-use-long-file-name 'not-save) (gnus-capitalize-newsgroup newsgroup) (concat (gnus-newsgroup-directory-form newsgroup) "/news")) - (or gnus-article-save-directory "~/News")))) + gnus-article-save-directory))) (defun gnus-plain-save-name (newsgroup headers &optional last-file) "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE. @@ -2139,7 +2910,7 @@ If variable `gnus-use-long-file-name' is non-nil, it is (if (gnus-use-long-file-name 'not-save) newsgroup (concat (gnus-newsgroup-directory-form newsgroup) "/news")) - (or gnus-article-save-directory "~/News")))) + gnus-article-save-directory))) ;; For subscribing new newsgroup @@ -2155,26 +2926,29 @@ If variable `gnus-use-long-file-name' is non-nil, it is (setq start (1- (length prefix))) (if (and (string-match "[^\\.]\\." (car groups) start) (cdr groups) - (setq prefix + (setq prefix (concat "^" (substring (car groups) 0 (match-end 0)))) - (string-match prefix (car (cdr groups)))) + (string-match prefix (cadr groups))) (progn (setq prefixes (cons prefix prefixes)) - (message "Descend hierarchy %s? ([y]nsq): " + (message "Descend hierarchy %s? ([y]nsq): " (substring prefix 1 (1- (length prefix)))) - (setq ans (read-char)) + (while (not (memq (setq ans (read-char)) '(?y ?\n ?n ?s ?q))) + (ding) + (message "Descend hierarchy %s? ([y]nsq): " + (substring prefix 1 (1- (length prefix))))) (cond ((= ans ?n) - (while (and groups - (string-match prefix + (while (and groups + (string-match prefix (setq group (car groups)))) - (setq gnus-killed-list + (setq gnus-killed-list (cons group gnus-killed-list)) (gnus-sethash group group gnus-killed-hashtb) (setq groups (cdr groups))) (setq starts (cdr starts))) ((= ans ?s) - (while (and groups - (string-match prefix + (while (and groups + (string-match prefix (setq group (car groups)))) (gnus-sethash group group gnus-killed-hashtb) (gnus-subscribe-alphabetically (car groups)) @@ -2188,7 +2962,9 @@ If variable `gnus-use-long-file-name' is non-nil, it is (setq groups (cdr groups)))) (t nil))) (message "Subscribe %s? ([n]yq)" (car groups)) - (setq ans (read-char)) + (while (not (memq (setq ans (read-char)) '(?y ?\n ?q ?n))) + (ding) + (message "Subscribe %s? ([n]yq)" (car groups))) (setq group (car groups)) (cond ((= ans ?y) (gnus-subscribe-alphabetically (car groups)) @@ -2199,7 +2975,7 @@ If variable `gnus-use-long-file-name' is non-nil, it is (setq gnus-killed-list (cons group gnus-killed-list)) (gnus-sethash group group gnus-killed-hashtb) (setq groups (cdr groups)))) - (t + (t (setq gnus-killed-list (cons group gnus-killed-list)) (gnus-sethash group group gnus-killed-hashtb))) (setq groups (cdr groups))))))) @@ -2210,12 +2986,11 @@ If variable `gnus-use-long-file-name' is non-nil, it is (defun gnus-subscribe-alphabetically (newgroup) "Subscribe new NEWSGROUP and insert it in alphabetical order." - ;; Basic ideas by mike-w@cs.aukuni.ac.nz (Mike Williams) (let ((groups (cdr gnus-newsrc-alist)) before) (while (and (not before) groups) - (if (string< newgroup (car (car groups))) - (setq before (car (car groups))) + (if (string< newgroup (caar groups)) + (setq before (caar groups)) (setq groups (cdr groups)))) (gnus-subscribe-newsgroup newgroup before))) @@ -2232,8 +3007,7 @@ If variable `gnus-use-long-file-name' is non-nil, it is (concat "^\\(" (regexp-quote groupkey) ".*\\)[!:]"))) (while (and (re-search-forward groupkey-re nil t) (progn - (setq before (buffer-substring - (match-beginning 1) (match-end 1))) + (setq before (match-string 1)) (string< before newgroup))))) ;; Remove tail of newsgroup name (eg. a.b.c -> a.b) (setq groupkey @@ -2241,24 +3015,28 @@ If variable `gnus-use-long-file-name' is non-nil, it is (substring groupkey (match-beginning 1) (match-end 1))))) (gnus-subscribe-newsgroup newgroup before)))) -(defun gnus-subscribe-interactively (newsgroup) - "Subscribe new NEWSGROUP interactively. -It is inserted in hierarchical newsgroup order if subscribed. If not, +(defun gnus-subscribe-interactively (group) + "Subscribe the new GROUP interactively. +It is inserted in hierarchical newsgroup order if subscribed. If not, it is killed." - (if (gnus-y-or-n-p (format "Subscribe new newsgroup: %s " newsgroup)) - (gnus-subscribe-hierarchically newsgroup) - (setq gnus-killed-list (cons newsgroup gnus-killed-list)))) + (if (gnus-y-or-n-p (format "Subscribe new newsgroup: %s " group)) + (gnus-subscribe-hierarchically group) + (push group gnus-killed-list))) + +(defun gnus-subscribe-zombies (group) + "Make the new GROUP into a zombie group." + (push group gnus-zombie-list)) -(defun gnus-subscribe-zombies (newsgroup) - "Make new NEWSGROUP a zombie group." - (setq gnus-zombie-list (cons newsgroup gnus-zombie-list))) +(defun gnus-subscribe-killed (group) + "Make the new GROUP a killed group." + (push group gnus-killed-list)) (defun gnus-subscribe-newsgroup (newsgroup &optional next) "Subscribe new NEWSGROUP. -If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made +If NEXT is non-nil, it is inserted before NEXT. Otherwise it is made the first newsgroup." ;; We subscribe the group by changing its level to `subscribed'. - (gnus-group-change-level + (gnus-group-change-level newsgroup gnus-level-default-subscribed gnus-level-killed (gnus-gethash (or next "dummy.group") gnus-newsrc-hashtb)) (gnus-message 5 "Subscribe newsgroup: %s" newsgroup)) @@ -2271,7 +3049,7 @@ the first newsgroup." (len (length newsgroup)) idx) ;; If this is a foreign group, we don't want to translate the - ;; entire name. + ;; entire name. (if (setq idx (string-match ":" newsgroup)) (aset newsgroup idx ?/) (setq idx 0)) @@ -2285,11 +3063,11 @@ the first newsgroup." (defun gnus-newsgroup-savable-name (group) ;; Replace any slashes in a group name (eg. an ange-ftp nndoc group) ;; with dots. - (gnus-replace-chars-in-string group ?/ ?.)) + (nnheader-replace-chars-in-string group ?/ ?.)) (defun gnus-make-directory (dir) "Make DIRECTORY recursively." - ;; Why don't we use `(make-directory dir 'parents)'? That's just one + ;; Why don't we use `(make-directory dir 'parents)'? That's just one ;; of the many mysteries of the universe. (let* ((dir (expand-file-name dir default-directory)) dirs err) @@ -2306,7 +3084,7 @@ the first newsgroup." (make-directory (car dirs)) (error (setq err t))) (setq dirs (cdr dirs))) - ;; We return whether we were successful or not. + ;; We return whether we were successful or not. (not dirs))) (defun gnus-capitalize-newsgroup (newsgroup) @@ -2315,55 +3093,86 @@ the first newsgroup." (concat (char-to-string (upcase (aref newsgroup 0))) (substring newsgroup 1)))) -;; Var +;; Various... things. (defun gnus-simplify-subject (subject &optional re-only) "Remove `Re:' and words in parentheses. -If optional argument RE-ONLY is non-nil, strip `Re:' only." +If RE-ONLY is non-nil, strip leading `Re:'s only." (let ((case-fold-search t)) ;Ignore case. - ;; Remove `Re:' and `Re^N:'. - (if (string-match "^re:[ \t]*" subject) + ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'. + (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject) + (setq subject (substring subject (match-end 0)))) + ;; Remove uninteresting prefixes. + (if (and (not re-only) + gnus-simplify-ignored-prefixes + (string-match gnus-simplify-ignored-prefixes subject)) (setq subject (substring subject (match-end 0)))) ;; Remove words in parentheses from end. - (or re-only - (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject) - (setq subject (substring subject 0 (match-beginning 0))))) + (unless re-only + (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject) + (setq subject (substring subject 0 (match-beginning 0))))) ;; Return subject string. subject)) ;; Remove any leading "re:"s, any trailing paren phrases, and simplify ;; all whitespace. -(defun gnus-simplify-subject-fuzzy (subject) +;; Written by Stainless Steel Rat . +(defun gnus-simplify-buffer-fuzzy () (let ((case-fold-search t)) - (save-excursion - (gnus-set-work-buffer) + (goto-char (point-min)) + (while (search-forward "\t" nil t) + (replace-match " " t t)) + (goto-char (point-min)) + (re-search-forward "^ *\\(re\\|fwd\\)[[{(^0-9]*[])}]?[:;] *" nil t) + (goto-char (match-beginning 0)) + (while (or + (looking-at "^ *\\(re\\|fwd\\)[[{(^0-9]*[])}]?[:;] *") + (looking-at "^[[].*: .*[]]$")) + (goto-char (point-min)) + (while (re-search-forward "^ *\\(re\\|fwd\\)[[{(^0-9]*[])}]?[:;] *" + nil t) + (replace-match "" t t)) + (goto-char (point-min)) + (while (re-search-forward "^[[].*: .*[]]$" nil t) + (goto-char (match-end 0)) + (delete-char -1) + (delete-region + (progn (goto-char (match-beginning 0))) + (re-search-forward ":")))) + (goto-char (point-min)) + (while (re-search-forward " *[[{(][^()\n]*[]})] *$" nil t) + (replace-match "" t t)) + (goto-char (point-min)) + (while (re-search-forward " +" nil t) + (replace-match " " t t)) + (goto-char (point-min)) + (while (re-search-forward " $" nil t) + (replace-match "" t t)) + (goto-char (point-min)) + (while (re-search-forward "^ +" nil t) + (replace-match "" t t)) + (goto-char (point-min)) + (when gnus-simplify-subject-fuzzy-regexp + (if (listp gnus-simplify-subject-fuzzy-regexp) + (let ((list gnus-simplify-subject-fuzzy-regexp)) + (while list + (goto-char (point-min)) + (while (re-search-forward (car list) nil t) + (replace-match "" t t)) + (setq list (cdr list)))) + (while (re-search-forward gnus-simplify-subject-fuzzy-regexp nil t) + (replace-match "" t t)))))) + +(defun gnus-simplify-subject-fuzzy (subject) + "Siplify a subject string fuzzily." + (save-excursion + (gnus-set-work-buffer) + (let ((case-fold-search t)) (insert subject) (inline (gnus-simplify-buffer-fuzzy)) (buffer-string)))) -(defun gnus-simplify-buffer-fuzzy () - (goto-char (point-min)) - ;; Fix by Stainless Steel Rat . - (while (re-search-forward "^[ \t]*\\(re\\|fwd\\)[[{(^0-9]*[])}]?[:;][ \t]*" - nil t) - (replace-match "" t t)) - (goto-char (point-min)) - (while (re-search-forward "[ \t\n]*([^()]*)[ \t\n]*$" nil t) - (replace-match "" t t)) - (goto-char (point-min)) - (while (re-search-forward "[ \t]+" nil t) - (replace-match " " t t)) - (goto-char (point-min)) - (while (re-search-forward "[ \t]+$" nil t) - (replace-match "" t t)) - (goto-char (point-min)) - (while (re-search-forward "^[ \t]+" nil t) - (replace-match "" t t)) - (if gnus-simplify-subject-fuzzy-regexp - (while (re-search-forward gnus-simplify-subject-fuzzy-regexp nil t) - (replace-match "" t t)))) - -;; Add the current buffer to the list of buffers to be killed on exit. +;; Add the current buffer to the list of buffers to be killed on exit. (defun gnus-add-current-to-buffer-list () (or (memq (current-buffer) gnus-buffer-list) (setq gnus-buffer-list (cons (current-buffer) gnus-buffer-list)))) @@ -2372,38 +3181,9 @@ If optional argument RE-ONLY is non-nil, strip `Re:' only." (not (or (string< s1 s2) (string= s1 s2)))) -;; Functions accessing headers. -;; Functions are more convenient than macros in some cases. - -(defun gnus-header-number (header) - (mail-header-number header)) - -(defun gnus-header-subject (header) - (mail-header-subject header)) - -(defun gnus-header-from (header) - (mail-header-from header)) - -(defun gnus-header-xref (header) - (mail-header-xref header)) - -(defun gnus-header-lines (header) - (mail-header-lines header)) - -(defun gnus-header-date (header) - (mail-header-date header)) - -(defun gnus-header-id (header) - (mail-header-id header)) - -(defun gnus-header-message-id (header) - (mail-header-id header)) - -(defun gnus-header-chars (header) - (mail-header-chars header)) - -(defun gnus-header-references (header) - (mail-header-references header)) +(defun gnus-read-active-file-p () + "Say whether the active file has been read from `gnus-select-method'." + (memq gnus-select-method gnus-have-read-active-file)) ;;; General various misc type functions. @@ -2425,53 +3205,63 @@ If optional argument RE-ONLY is non-nil, strip `Re:' only." gnus-active-hashtb nil gnus-moderated-list nil gnus-description-hashtb nil + gnus-current-headers nil + gnus-thread-indent-array nil gnus-newsgroup-headers nil - gnus-newsgroup-headers-hashtb-by-number nil gnus-newsgroup-name nil gnus-server-alist nil + gnus-group-list-mode nil + gnus-opened-servers nil + gnus-group-mark-positions nil + gnus-newsgroup-data nil + gnus-newsgroup-unreads nil gnus-current-select-method nil) - ;; Reset any score variables. - (and (boundp 'gnus-score-cache) - (set 'gnus-score-cache nil)) - (and (boundp 'gnus-internal-global-score-files) - (set 'gnus-internal-global-score-files nil)) + (gnus-shutdown 'gnus) ;; Kill the startup file. (and gnus-current-startup-file (get-file-buffer gnus-current-startup-file) (kill-buffer (get-file-buffer gnus-current-startup-file))) - ;; Save any cache buffers. - (and gnus-use-cache (gnus-cache-save-buffers)) ;; Clear the dribble buffer. (gnus-dribble-clear) ;; Kill global KILL file buffer. - (if (get-file-buffer (gnus-newsgroup-kill-file nil)) - (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil)))) + (when (get-file-buffer (gnus-newsgroup-kill-file nil)) + (kill-buffer (get-file-buffer (gnus-newsgroup-kill-file nil)))) (gnus-kill-buffer nntp-server-buffer) ;; Kill Gnus buffers. (while gnus-buffer-list - (gnus-kill-buffer (car gnus-buffer-list)) - (setq gnus-buffer-list (cdr gnus-buffer-list)))) + (gnus-kill-buffer (pop gnus-buffer-list))) + ;; Remove Gnus frames. + (gnus-kill-gnus-frames)) + +(defun gnus-kill-gnus-frames () + "Kill all frames Gnus has created." + (while gnus-created-frames + (when (frame-live-p (car gnus-created-frames)) + ;; We slap a condition-case around this `delete-frame' to ensure + ;; against errors if we try do delete the single frame that's left. + (condition-case () + (delete-frame (car gnus-created-frames)) + (error nil))) + (pop gnus-created-frames))) (defun gnus-windows-old-to-new (setting) ;; First we take care of the really, really old Gnus 3 actions. - (if (symbolp setting) - (setq setting - (cond ((memq setting '(SelectArticle)) - 'article) - ((memq setting '(SelectSubject ExpandSubject)) - 'summary) - ((memq setting '(SelectNewsgroup ExitNewsgroup)) - 'group) - (t setting)))) + (when (symbolp setting) + (setq setting + ;; Take care of ooold GNUS 3.x values. + (cond ((eq setting 'SelectArticle) 'article) + ((memq setting '(SelectSubject ExpandSubject)) 'summary) + ((memq setting '(SelectNewsgroup ExitNewsgroup)) 'group) + (t setting)))) (if (or (listp setting) (not (and gnus-window-configuration (memq setting '(group summary article))))) setting - (let* ((setting (if (eq setting 'group) + (let* ((setting (if (eq setting 'group) (if (assq 'newsgroup gnus-window-configuration) 'newsgroup 'newsgroups) setting)) - (elem (car (cdr (assq setting gnus-window-configuration)))) + (elem (cadr (assq setting gnus-window-configuration))) (total (apply '+ elem)) (types '(group summary article)) (pbuf (if (eq setting 'newsgroups) 'group 'summary)) @@ -2482,151 +3272,242 @@ If optional argument RE-ONLY is non-nil, strip `Re:' only." (or (not (numberp (nth i elem))) (zerop (nth i elem)) (progn - (setq perc (/ (* 1.0 (nth 0 elem)) total)) + (setq perc (if (= i 2) + 1.0 + (/ (float (nth 0 elem)) total))) (setq out (cons (if (eq pbuf (nth i types)) - (vector (nth i types) perc 'point) - (vector (nth i types) perc)) + (list (nth i types) perc 'point) + (list (nth i types) perc)) out)))) (setq i (1+ i))) - (list (nreverse out))))) - + `(vertical 1.0 ,@(nreverse out))))) + +;;;###autoload (defun gnus-add-configuration (conf) - (setq gnus-buffer-configuration + "Add the window configuration CONF to `gnus-buffer-configuration'." + (setq gnus-buffer-configuration (cons conf (delq (assq (car conf) gnus-buffer-configuration) gnus-buffer-configuration)))) +(defvar gnus-frame-list nil) + +(defun gnus-configure-frame (split &optional window) + "Split WINDOW according to SPLIT." + (unless window + (setq window (get-buffer-window (current-buffer)))) + (select-window window) + ;; This might be an old-stylee buffer config. + (when (vectorp split) + (setq split (append split nil))) + (when (or (consp (car split)) + (vectorp (car split))) + (push 1.0 split) + (push 'vertical split)) + ;; The SPLIT might be something that is to be evaled to + ;; return a new SPLIT. + (while (and (not (assq (car split) gnus-window-to-buffer)) + (gnus-functionp (car split))) + (setq split (eval split))) + (let* ((type (car split)) + (subs (cddr split)) + (len (if (eq type 'horizontal) (window-width) (window-height))) + (total 0) + (window-min-width (or gnus-window-min-width window-min-width)) + (window-min-height (or gnus-window-min-height window-min-height)) + s result new-win rest comp-subs size sub) + (cond + ;; Nothing to do here. + ((null split)) + ;; Don't switch buffers. + ((null type) + (and (memq 'point split) window)) + ;; This is a buffer to be selected. + ((not (memq type '(frame horizontal vertical))) + (let ((buffer (cond ((stringp type) type) + (t (cdr (assq type gnus-window-to-buffer))))) + buf) + (unless buffer + (error "Illegal buffer type: %s" type)) + (unless (setq buf (get-buffer (if (symbolp buffer) + (symbol-value buffer) buffer))) + (setq buf (get-buffer-create (if (symbolp buffer) + (symbol-value buffer) buffer)))) + (switch-to-buffer buf) + ;; We return the window if it has the `point' spec. + (and (memq 'point split) window))) + ;; This is a frame split. + ((eq type 'frame) + (unless gnus-frame-list + (setq gnus-frame-list (list (window-frame + (get-buffer-window (current-buffer)))))) + (let ((i 0) + params frame fresult) + (while (< i (length subs)) + ;; Frame parameter is gotten from the sub-split. + (setq params (cadr (elt subs i))) + ;; It should be a list. + (unless (listp params) + (setq params nil)) + ;; Create a new frame? + (unless (setq frame (elt gnus-frame-list i)) + (nconc gnus-frame-list (list (setq frame (make-frame params)))) + (push frame gnus-created-frames)) + ;; Is the old frame still alive? + (unless (frame-live-p frame) + (setcar (nthcdr i gnus-frame-list) + (setq frame (make-frame params)))) + ;; Select the frame in question and do more splits there. + (select-frame frame) + (setq fresult (or (gnus-configure-frame (elt subs i)) fresult)) + (incf i)) + ;; Select the frame that has the selected buffer. + (when fresult + (select-frame (window-frame fresult))))) + ;; This is a normal split. + (t + (when (> (length subs) 0) + ;; First we have to compute the sizes of all new windows. + (while subs + (setq sub (append (pop subs) nil)) + (while (and (not (assq (car sub) gnus-window-to-buffer)) + (gnus-functionp (car sub))) + (setq sub (eval sub))) + (when sub + (push sub comp-subs) + (setq size (cadar comp-subs)) + (cond ((equal size 1.0) + (setq rest (car comp-subs)) + (setq s 0)) + ((floatp size) + (setq s (floor (* size len)))) + ((integerp size) + (setq s size)) + (t + (error "Illegal size: %s" size))) + ;; Try to make sure that we are inside the safe limits. + (cond ((zerop s)) + ((eq type 'horizontal) + (setq s (max s window-min-width))) + ((eq type 'vertical) + (setq s (max s window-min-height)))) + (setcar (cdar comp-subs) s) + (incf total s))) + ;; Take care of the "1.0" spec. + (if rest + (setcar (cdr rest) (- len total)) + (error "No 1.0 specs in %s" split)) + ;; The we do the actual splitting in a nice recursive + ;; fashion. + (setq comp-subs (nreverse comp-subs)) + (while comp-subs + (if (null (cdr comp-subs)) + (setq new-win window) + (setq new-win + (split-window window (cadar comp-subs) + (eq type 'horizontal)))) + (setq result (or (gnus-configure-frame + (car comp-subs) window) result)) + (select-window new-win) + (setq window new-win) + (setq comp-subs (cdr comp-subs)))) + ;; Return the proper window, if any. + (when result + (select-window result)))))) + +(defvar gnus-frame-split-p nil) + (defun gnus-configure-windows (setting &optional force) (setq setting (gnus-windows-old-to-new setting)) - (let ((r (if (symbolp setting) - (cdr (assq setting gnus-buffer-configuration)) - setting)) - (in-buf (current-buffer)) - rule val w height hor ohor heights sub jump-buffer - rel total to-buf all-visible) - (or r (error "No such setting: %s" setting)) - - (if (and (not force) (setq all-visible (gnus-all-windows-visible-p r))) + (let ((split (if (symbolp setting) + (cadr (assq setting gnus-buffer-configuration)) + setting)) + all-visible) + + (setq gnus-frame-split-p nil) + + (unless split + (error "No such setting: %s" setting)) + + (if (and (setq all-visible (gnus-all-windows-visible-p split)) + (not force)) ;; All the windows mentioned are already visible, so we just ;; put point in the assigned buffer, and do not touch the - ;; winconf. - (select-window (get-buffer-window all-visible t)) - + ;; winconf. + (select-window all-visible) ;; Either remove all windows or just remove all Gnus windows. - (if gnus-use-full-window - (delete-other-windows) - (gnus-remove-some-windows) - (switch-to-buffer nntp-server-buffer)) - - (while r - (setq hor (car r) - ohor nil) - - ;; We have to do the (possible) horizontal splitting before the - ;; vertical. - (if (and (listp (car hor)) - (eq (car (car hor)) 'horizontal)) - (progn - (split-window - nil - (if (integerp (nth 1 (car hor))) - (nth 1 (car hor)) - (- (frame-width) (floor (* (frame-width) (nth 1 (car hor)))))) - t) - (setq hor (cdr hor)))) - - ;; Go through the rules and eval the elements that are to be - ;; evalled. - (while hor - (if (setq val (if (vectorp (car hor)) (car hor) (eval (car hor)))) - (progn - ;; Expand short buffer name. - (setq w (aref val 0)) - (and (setq w (cdr (assq w gnus-window-to-buffer))) - (progn - (setq val (apply 'vector (mapcar 'identity val))) - (aset val 0 w))) - (setq ohor (cons val ohor)))) - (setq hor (cdr hor))) - (setq rule (cons (nreverse ohor) rule)) - (setq r (cdr r))) - (setq rule (nreverse rule)) - - ;; We tally the window sizes. - (setq total (window-height)) - (while rule - (setq hor (car rule)) - (if (and (listp (car hor)) (eq (car (car hor)) 'horizontal)) - (setq hor (cdr hor))) - (setq sub 0) - (while hor - (setq rel (aref (car hor) 1) - heights (cons - (cond ((and (floatp rel) (= 1.0 rel)) - 'x) - ((integerp rel) - rel) - (t - (max (floor (* total rel)) 4))) - heights) - sub (+ sub (if (numberp (car heights)) (car heights) 0)) - hor (cdr hor))) - (setq heights (nreverse heights) - hor (car rule)) - - ;; We then go through these heights and create windows for them. - (while heights - (setq height (car heights) - heights (cdr heights)) - (and (eq height 'x) - (setq height (- total sub))) - (and heights - (split-window nil height)) - (setq to-buf (aref (car hor) 0)) - (switch-to-buffer - (cond ((not to-buf) - in-buf) - ((symbolp to-buf) - (symbol-value (aref (car hor) 0))) - (t - (aref (car hor) 0)))) - (and (> (length (car hor)) 2) - (eq (aref (car hor) 2) 'point) - (setq jump-buffer (current-buffer))) - (other-window 1) - (setq hor (cdr hor))) - - (setq rule (cdr rule))) - - ;; Finally, we pop to the buffer that's supposed to have point. - (or jump-buffer (error "Missing `point' in spec for %s" setting)) - - (select-window (get-buffer-window jump-buffer t)) - (set-buffer jump-buffer)))) - -(defun gnus-all-windows-visible-p (rule) - (let (invisible hor jump-buffer val buffer) - ;; Go through the rules and eval the elements that are to be - ;; evalled. - (while (and rule (not invisible)) - (setq hor (car rule) - rule (cdr rule)) - (while (and hor (not invisible)) - (if (setq val (if (vectorp (car hor)) - (car hor) - (if (not (eq (car (car hor)) 'horizontal)) - (eval (car hor))))) - (progn - ;; Expand short buffer name. - (setq buffer (or (cdr (assq (aref val 0) gnus-window-to-buffer)) - (aref val 0))) - (setq buffer (if (symbolp buffer) (symbol-value buffer) - buffer)) - (and (> (length val) 2) (eq 'point (aref val 2)) - (setq jump-buffer buffer)) - (setq invisible (not (and buffer (get-buffer-window buffer)))))) - (setq hor (cdr hor)))) - (and (not invisible) jump-buffer))) + (let ((frame (selected-frame))) + (unwind-protect + (if gnus-use-full-window + ;; We want to remove all other windows. + (if (not gnus-frame-split-p) + ;; This is not a `frame' split, so we ignore the + ;; other frames. + (delete-other-windows) + ;; This is a `frame' split, so we delete all windows + ;; on all frames. + (mapcar + (lambda (frame) + (unless (eq (cdr (assq 'minibuffer + (frame-parameters frame))) + 'only) + (select-frame frame) + (delete-other-windows))) + (frame-list))) + ;; Just remove some windows. + (gnus-remove-some-windows) + (switch-to-buffer nntp-server-buffer)) + (select-frame frame))) + + (switch-to-buffer nntp-server-buffer) + (gnus-configure-frame split (get-buffer-window (current-buffer)))))) + +(defun gnus-all-windows-visible-p (split) + "Say whether all buffers in SPLIT are currently visible. +In particular, the value returned will be the window that +should have point." + (let ((stack (list split)) + (all-visible t) + type buffer win buf) + (while (and (setq split (pop stack)) + all-visible) + ;; Be backwards compatible. + (when (vectorp split) + (setq split (append split nil))) + (when (or (consp (car split)) + (vectorp (car split))) + (push 1.0 split) + (push 'vertical split)) + ;; The SPLIT might be something that is to be evaled to + ;; return a new SPLIT. + (while (and (not (assq (car split) gnus-window-to-buffer)) + (gnus-functionp (car split))) + (setq split (eval split))) + + (setq type (elt split 0)) + (cond + ;; Nothing here. + ((null split) t) + ;; A buffer. + ((not (memq type '(horizontal vertical frame))) + (setq buffer (cond ((stringp type) type) + (t (cdr (assq type gnus-window-to-buffer))))) + (unless buffer + (error "Illegal buffer type: %s" type)) + (when (setq buf (get-buffer (if (symbolp buffer) + (symbol-value buffer) + buffer))) + (setq win (get-buffer-window buf t))) + (if win + (when (memq 'point split) + (setq all-visible win)) + (setq all-visible nil))) + (t + (when (eq type 'frame) + (setq gnus-frame-split-p t)) + (setq stack (append (cddr split) stack))))) + (unless (eq all-visible t) + all-visible))) (defun gnus-window-top-edge (&optional window) (nth 1 (window-edges window))) @@ -2637,10 +3518,10 @@ If optional argument RE-ONLY is non-nil, strip `Re:' only." (save-excursion ;; Remove windows on all known Gnus buffers. (while buffers - (setq buf (cdr (car buffers))) + (setq buf (cdar buffers)) (if (symbolp buf) (setq buf (and (boundp buf) (symbol-value buf)))) - (and buf + (and buf (get-buffer-window buf) (progn (setq bufs (cons buf bufs)) @@ -2652,20 +3533,19 @@ If optional argument RE-ONLY is non-nil, strip `Re:' only." (setq lowest-buf buf))))) (setq buffers (cdr buffers))) ;; Remove windows on *all* summary buffers. - (let (wins) - (walk-windows - (lambda (win) - (let ((buf (window-buffer win))) - (if (string-match "^\\*Summary" (buffer-name buf)) - (progn - (setq bufs (cons buf bufs)) - (pop-to-buffer buf) - (if (or (not lowest) - (< (gnus-window-top-edge) lowest)) - (progn - (setq lowest-buf buf) - (setq lowest (gnus-window-top-edge)))))))))) - (and lowest-buf + (walk-windows + (lambda (win) + (let ((buf (window-buffer win))) + (if (string-match "^\\*Summary" (buffer-name buf)) + (progn + (setq bufs (cons buf bufs)) + (pop-to-buffer buf) + (if (or (not lowest) + (< (gnus-window-top-edge) lowest)) + (progn + (setq lowest-buf buf) + (setq lowest (gnus-window-top-edge))))))))) + (and lowest-buf (progn (pop-to-buffer lowest-buf) (switch-to-buffer nntp-server-buffer))) @@ -2673,63 +3553,37 @@ If optional argument RE-ONLY is non-nil, strip `Re:' only." (and (not (eq (car bufs) lowest-buf)) (delete-windows-on (car bufs))) (setq bufs (cdr bufs)))))) - -(defun gnus-version () - "Version numbers of this version of Gnus." - (interactive) + +(defun gnus-version (&optional arg) + "Version number of this version of Gnus. +If ARG, insert string at point." + (interactive "P") (let ((methods gnus-valid-select-methods) (mess gnus-version) meth) ;; Go through all the legal select methods and add their version - ;; numbers to the total version string. Only the backends that are + ;; numbers to the total version string. Only the backends that are ;; currently in use will have their message numbers taken into - ;; consideration. + ;; consideration. (while methods - (setq meth (intern (concat (car (car methods)) "-version"))) + (setq meth (intern (concat (caar methods) "-version"))) (and (boundp meth) (stringp (symbol-value meth)) (setq mess (concat mess "; " (symbol-value meth)))) (setq methods (cdr methods))) - (gnus-message 2 mess))) + (if arg + (insert (message mess)) + (message mess)))) (defun gnus-info-find-node () "Find Info documentation of Gnus." (interactive) ;; Enlarge info window if needed. - (let ((mode major-mode)) - (gnus-configure-windows 'info) - (Info-goto-node (car (cdr (assq mode gnus-info-nodes)))))) - -(defun gnus-overload-functions (&optional overloads) - "Overload functions specified by optional argument OVERLOADS. -If nothing is specified, use the variable gnus-overload-functions." - (let ((defs nil) - (overloads (or overloads gnus-overload-functions))) - (while overloads - (setq defs (car overloads)) - (setq overloads (cdr overloads)) - ;; Load file before overloading function if necessary. Make - ;; sure we cannot use `require' always. - (and (not (fboundp (car defs))) - (car (cdr (cdr defs))) - (load (car (cdr (cdr defs))) nil 'nomessage)) - (fset (car defs) (car (cdr defs)))))) - -(defun gnus-replace-chars-in-string (string &rest pairs) - "Replace characters in STRING from FROM to TO." - (let ((string (substring string 0)) ;Copy string. - (len (length string)) - (idx 0) - sym to) - (or (zerop (% (length pairs) 2)) - (error "Odd number of translation pairs")) - (setplist 'sym pairs) - ;; Replace all occurrences of FROM with TO. - (while (< idx len) - (if (setq to (get 'sym (aref string idx))) - (aset string idx to)) - (setq idx (1+ idx))) - string)) + (let ((mode major-mode) + gnus-info-buffer) + (Info-goto-node (cadr (assq mode gnus-info-nodes))) + (setq gnus-info-buffer (current-buffer)) + (gnus-configure-windows 'info))) (defun gnus-days-between (date1 date2) ;; Return the number of days between date1 and date2. @@ -2738,27 +3592,22 @@ If nothing is specified, use the variable gnus-overload-functions." (defun gnus-day-number (date) (let ((dat (mapcar (lambda (s) (and s (string-to-int s)) ) (timezone-parse-date date)))) - (timezone-absolute-from-gregorian + (timezone-absolute-from-gregorian (nth 1 dat) (nth 2 dat) (car dat)))) -;; Returns a floating point number that says how many seconds have -;; lapsed between Jan 1 12:00:00 1970 and DATE. -(defun gnus-seconds-since-epoch (date) - (let* ((tdate (mapcar (lambda (ti) (and ti (string-to-int ti))) - (timezone-parse-date date))) - (ttime (mapcar (lambda (ti) (and ti (string-to-int ti))) - (timezone-parse-time - (aref (timezone-parse-date date) 3)))) - (edate (mapcar (lambda (ti) (and ti (string-to-int ti))) - (timezone-parse-date "Jan 1 12:00:00 1970"))) - (tday (- (timezone-absolute-from-gregorian - (nth 1 tdate) (nth 2 tdate) (nth 0 tdate)) - (timezone-absolute-from-gregorian - (nth 1 edate) (nth 2 edate) (nth 0 edate))))) - (+ (nth 2 ttime) - (* (nth 1 ttime) 60) - (* 1.0 (nth 0 ttime) 60 60) - (* 1.0 tday 60 60 24)))) +(defun gnus-encode-date (date) + "Convert DATE to internal time." + (let* ((parse (timezone-parse-date date)) + (date (mapcar (lambda (d) (and d (string-to-int d))) parse)) + (time (mapcar 'string-to-int (timezone-parse-time (aref parse 3))))) + (encode-time (caddr time) (cadr time) (car time) + (caddr date) (cadr date) (car date) (nth 4 date)))) + +(defun gnus-time-minus (t1 t2) + "Subtract two internal times." + (let ((borrow (< (cadr t1) (cadr t2)))) + (list (- (car t1) (car t2) (if borrow 1 0)) + (- (+ (if borrow 65536 0) (cadr t1)) (cadr t2))))) (defun gnus-file-newer-than (file date) (let ((fdate (nth 5 (file-attributes file)))) @@ -2766,13 +3615,117 @@ If nothing is specified, use the variable gnus-overload-functions." (and (= (car fdate) (car date)) (> (nth 1 fdate) (nth 1 date)))))) +(defmacro gnus-local-set-keys (&rest plist) + "Set the keys in PLIST in the current keymap." + `(gnus-define-keys-1 (current-local-map) ',plist)) + +(defmacro gnus-define-keys (keymap &rest plist) + "Define all keys in PLIST in KEYMAP." + `(gnus-define-keys-1 (quote ,keymap) (quote ,plist))) + +(put 'gnus-define-keys 'lisp-indent-function 1) +(put 'gnus-define-keys 'lisp-indent-hook 1) +(put 'gnus-define-keymap 'lisp-indent-function 1) +(put 'gnus-define-keymap 'lisp-indent-hook 1) + +(defmacro gnus-define-keymap (keymap &rest plist) + "Define all keys in PLIST in KEYMAP." + `(gnus-define-keys-1 ,keymap (quote ,plist))) + +(defun gnus-define-keys-1 (keymap plist) + (when (null keymap) + (error "Can't set keys in a null keymap")) + (cond ((symbolp keymap) + (setq keymap (symbol-value keymap))) + ((keymapp keymap)) + ((listp keymap) + (set (car keymap) nil) + (define-prefix-command (car keymap)) + (define-key (symbol-value (caddr keymap)) (cadr keymap) (car keymap)) + (setq keymap (symbol-value (car keymap))))) + (let (key) + (while plist + (when (symbolp (setq key (pop plist))) + (setq key (symbol-value key))) + (define-key keymap key (pop plist))))) + (defun gnus-group-read-only-p (&optional group) "Check whether GROUP supports editing or not. -If GROUP is nil, `gnus-newsgroup-name' will be checked instead. Note +If GROUP is nil, `gnus-newsgroup-name' will be checked instead. Note that that variable is buffer-local to the summary buffers." (let ((group (or group gnus-newsgroup-name))) (not (gnus-check-backend-function 'request-replace-article group)))) +(defun gnus-group-total-expirable-p (group) + "Check whether GROUP is total-expirable or not." + (let ((params (gnus-info-params (gnus-get-info group)))) + (or (memq 'total-expire params) + (cdr (assq 'total-expire params)) ; (total-expire . t) + (and gnus-total-expirable-newsgroups ; Check var. + (string-match gnus-total-expirable-newsgroups group))))) + +(defun gnus-group-auto-expirable-p (group) + "Check whether GROUP is total-expirable or not." + (let ((params (gnus-info-params (gnus-get-info group)))) + (or (memq 'auto-expire params) + (cdr (assq 'auto-expire params)) ; (auto-expire . t) + (and gnus-auto-expirable-newsgroups ; Check var. + (string-match gnus-auto-expirable-newsgroups group))))) + +(defun gnus-virtual-group-p (group) + "Say whether GROUP is virtual or not." + (memq 'virtual (assoc (symbol-name (car (gnus-find-method-for-group group))) + gnus-valid-select-methods))) + +(defun gnus-news-group-p (group &optional article) + "Return non-nil if GROUP (and ARTICLE) come from a news server." + (or (gnus-member-of-valid 'post group) ; Ordinary news group. + (and (gnus-member-of-valid 'post-mail group) ; Combined group. + (eq (gnus-request-type group article) 'news)))) + +(defsubst gnus-simplify-subject-fully (subject) + "Simplify a subject string according to the user's wishes." + (cond + ((null gnus-summary-gather-subject-limit) + (gnus-simplify-subject-re subject)) + ((eq gnus-summary-gather-subject-limit 'fuzzy) + (gnus-simplify-subject-fuzzy subject)) + ((numberp gnus-summary-gather-subject-limit) + (gnus-limit-string (gnus-simplify-subject-re subject) + gnus-summary-gather-subject-limit)) + (t + subject))) + +(defsubst gnus-subject-equal (s1 s2 &optional simple-first) + "Check whether two subjects are equal. If optional argument +simple-first is t, first argument is already simplified." + (cond + ((null simple-first) + (equal (gnus-simplify-subject-fully s1) + (gnus-simplify-subject-fully s2))) + (t + (equal s1 + (gnus-simplify-subject-fully s2))))) + +;; Returns a list of writable groups. +(defun gnus-writable-groups () + (let ((alist gnus-newsrc-alist) + groups group) + (while (setq group (car (pop alist))) + (unless (gnus-group-read-only-p group) + (push group groups))) + (nreverse groups))) + +(defun gnus-completing-read (default prompt &rest args) + ;; Like `completing-read', except that DEFAULT is the default argument. + (let* ((prompt (if default + (concat prompt " (default " default ") ") + (concat prompt " "))) + (answer (apply 'completing-read prompt args))) + (if (or (null answer) (zerop (length answer))) + default + answer))) + ;; Two silly functions to ensure that all `y-or-n-p' questions clear ;; the echo area. (defun gnus-y-or-n-p (prompt) @@ -2792,21 +3745,37 @@ that that variable is buffer-local to the summary buffers." ;; If it isn't a list, then we return t. (or (not (listp gnus-use-long-file-name)) ;; If it is a list, and the list contains `symbol', we - ;; return nil. + ;; return nil. (not (memq symbol gnus-use-long-file-name))))) ;; I suspect there's a better way, but I haven't taken the time to do ;; it yet. -erik selberg@cs.washington.edu (defun gnus-dd-mmm (messy-date) "Return a string like DD-MMM from a big messy string" - (let ((datevec (timezone-parse-date messy-date))) - (format "%2s-%s" - (or (aref datevec 2) "??") - (capitalize - (or (car - (nth (1- (string-to-number (aref datevec 1))) - timezone-months-assoc)) - "???"))))) + (let ((datevec (condition-case () (timezone-parse-date messy-date) + (error nil)))) + (if (not datevec) + "??-???" + (format "%2s-%s" + (condition-case () + ;; Make sure leading zeroes are stripped. + (number-to-string (string-to-number (aref datevec 2))) + (error "??")) + (capitalize + (or (car + (nth (1- (string-to-number (aref datevec 1))) + timezone-months-assoc)) + "???")))))) + +(defun gnus-mode-string-quote (string) + "Quote all \"%\" in STRING." + (save-excursion + (gnus-set-work-buffer) + (insert string) + (goto-char (point-min)) + (while (search-forward "%" nil t) + (insert "%")) + (buffer-string))) ;; Make a hash table (default and minimum size is 255). ;; Optional argument HASHSIZE specifies the table size. @@ -2821,8 +3790,8 @@ that that variable is buffer-local to the summary buffers." (setq i (* 2 i))) (1- i))) -;; Show message if message has a lower level than `gnus-verbose'. -;; Guide-line for numbers: +;; Show message if message has a lower level than `gnus-verbose'. +;; Guideline for numbers: ;; 1 - error messages, 3 - non-serious error messages, 5 - messages ;; for things that take a long time, 7 - not very important messages ;; on stuff, 9 - messages inside loops. @@ -2834,6 +3803,17 @@ that that variable is buffer-local to the summary buffers." ;; from `message'. (apply 'format args))) +(defun gnus-error (level &rest args) + "Beep an error if `gnus-verbose' is on LEVEL or less." + (when (<= (floor level) gnus-verbose) + (apply 'message args) + (ding) + (let (duration) + (when (and (floatp level) + (not (zerop (setq duration (* 10 (- level (floor level))))))) + (sit-for duration)))) + nil) + ;; Generate a unique new group name. (defun gnus-generate-new-group-name (leaf) (let ((name leaf) @@ -2842,23 +3822,74 @@ that that variable is buffer-local to the summary buffers." (setq name (concat leaf "<" (int-to-string (setq num (1+ num))) ">"))) name)) +(defsubst gnus-hide-text (b e props) + "Set text PROPS on the B to E region, extending `intangible' 1 past B." + (gnus-add-text-properties b e props) + (when (memq 'intangible props) + (gnus-put-text-property (max (1- b) (point-min)) + b 'intangible (cddr (memq 'intangible props))))) + +(defsubst gnus-unhide-text (b e) + "Remove hidden text properties from region between B and E." + (remove-text-properties b e gnus-hidden-properties) + (when (memq 'intangible gnus-hidden-properties) + (gnus-put-text-property (max (1- b) (point-min)) + b 'intangible nil))) + +(defun gnus-hide-text-type (b e type) + "Hide text of TYPE between B and E." + (gnus-hide-text b e (cons 'gnus-type (cons type gnus-hidden-properties)))) + +(defun gnus-parent-headers (headers &optional generation) + "Return the headers of the GENERATIONeth parent of HEADERS." + (unless generation + (setq generation 1)) + (let (references parent) + (while (and headers (not (zerop generation))) + (setq references (mail-header-references headers)) + (when (and references + (setq parent (gnus-parent-id references)) + (setq headers (car (gnus-id-to-thread parent)))) + (decf generation))) + headers)) + +(defun gnus-parent-id (references) + "Return the last Message-ID in REFERENCES." + (when (and references + (string-match "\\(<[^\n<>]+>\\)[ \t\n]*\\'" references)) + (substring references (match-beginning 1) (match-end 1)))) + +(defun gnus-split-references (references) + "Return a list of Message-IDs in REFERENCES." + (let ((beg 0) + ids) + (while (string-match "<[^>]+>" references beg) + (push (substring references (match-beginning 0) (setq beg (match-end 0))) + ids)) + (nreverse ids))) + +(defun gnus-buffer-live-p (buffer) + "Say whether BUFFER is alive or not." + (and buffer + (get-buffer buffer) + (buffer-name (get-buffer buffer)))) + (defun gnus-ephemeral-group-p (group) "Say whether GROUP is ephemeral or not." - (assoc 'quit-config (gnus-find-method-for-group group))) + (gnus-group-get-parameter group 'quit-config)) (defun gnus-group-quit-config (group) "Return the quit-config of GROUP." - (nth 1 (assoc 'quit-config (gnus-find-method-for-group group)))) + (gnus-group-get-parameter group 'quit-config)) (defun gnus-simplify-mode-line () "Make mode lines a bit simpler." (setq mode-line-modified "-- ") - (if (listp mode-line-format) - (progn - (make-local-variable 'mode-line-format) - (setq mode-line-format (copy-sequence mode-line-format)) - (and (equal (nth 3 mode-line-format) " ") - (setcar (nthcdr 3 mode-line-format) ""))))) + (when (listp mode-line-format) + (make-local-variable 'mode-line-format) + (setq mode-line-format (copy-sequence mode-line-format)) + (when (equal (nth 3 mode-line-format) " ") + (setcar (nthcdr 3 mode-line-format) " ")))) ;;; List and range functions @@ -2872,7 +3903,7 @@ that that variable is buffer-local to the summary buffers." "Do a complete, total copy of a list." (if (and (consp list) (not (consp (cdr list)))) (cons (car list) (cdr list)) - (mapcar (lambda (elem) (if (consp elem) + (mapcar (lambda (elem) (if (consp elem) (if (consp (cdr elem)) (gnus-copy-sequence elem) (cons (car elem) (cdr elem))) @@ -2905,7 +3936,7 @@ Both lists have to be sorted over <." (setq list2 (cdr list2))))) (nconc (nreverse out) (or list1 list2))))) -(defun gnus-intersection (list1 list2) +(defun gnus-intersection (list1 list2) (let ((result nil)) (while list2 (if (memq (car list2) list1) @@ -2961,7 +3992,7 @@ ranges." ((= (1+ last) (car numbers)) ;Still in sequence (setq last (car numbers))) (t ;End of one sequence - (setq result + (setq result (cons (if (= first last) first (cons first last)) result)) (setq first (car numbers)) @@ -2978,7 +4009,7 @@ ranges." RANGES is either a single range on the form `(num . num)' or a list of these ranges." (let (first last result) - (cond + (cond ((null ranges) nil) ((not (listp (cdr ranges))) @@ -2993,8 +4024,8 @@ these ranges." (if (atom (car ranges)) (if (numberp (car ranges)) (setq result (cons (car ranges) result))) - (setq first (car (car ranges))) - (setq last (cdr (car ranges))) + (setq first (caar ranges)) + (setq last (cdar ranges)) (while (<= first last) (setq result (cons first result)) (setq first (1+ first)))) @@ -3014,8 +4045,8 @@ Note: LIST has to be sorted over `<'." (while (and ranges list) (setq ilist list) (setq lowest (or (and (atom (car ranges)) (car ranges)) - (car (car ranges)))) - (while (and list (cdr list) (< (car (cdr list)) lowest)) + (caar ranges))) + (while (and list (cdr list) (< (cadr list) lowest)) (setq list (cdr list))) (if (< (car ilist) lowest) (progn @@ -3024,40 +4055,40 @@ Note: LIST has to be sorted over `<'." (setcdr temp nil) (setq out (nconc (gnus-compress-sequence ilist t) out)))) (setq highest (or (and (atom (car ranges)) (car ranges)) - (cdr (car ranges)))) + (cdar ranges))) (while (and list (<= (car list) highest)) (setq list (cdr list))) (setq ranges (cdr ranges))) (if list (setq out (nconc (gnus-compress-sequence list t) out))) - (setq out (sort out (lambda (r1 r2) + (setq out (sort out (lambda (r1 r2) (< (or (and (atom r1) r1) (car r1)) (or (and (atom r2) r2) (car r2)))))) (setq ranges out) (while ranges (if (atom (car ranges)) (if (cdr ranges) - (if (atom (car (cdr ranges))) - (if (= (1+ (car ranges)) (car (cdr ranges))) + (if (atom (cadr ranges)) + (if (= (1+ (car ranges)) (cadr ranges)) (progn - (setcar ranges (cons (car ranges) - (car (cdr ranges)))) - (setcdr ranges (cdr (cdr ranges))))) - (if (= (1+ (car ranges)) (car (car (cdr ranges)))) + (setcar ranges (cons (car ranges) + (cadr ranges))) + (setcdr ranges (cddr ranges)))) + (if (= (1+ (car ranges)) (caadr ranges)) (progn - (setcar (car (cdr ranges)) (car ranges)) - (setcar ranges (car (cdr ranges))) - (setcdr ranges (cdr (cdr ranges))))))) + (setcar (cadr ranges) (car ranges)) + (setcar ranges (cadr ranges)) + (setcdr ranges (cddr ranges)))))) (if (cdr ranges) - (if (atom (car (cdr ranges))) - (if (= (1+ (cdr (car ranges))) (car (cdr ranges))) + (if (atom (cadr ranges)) + (if (= (1+ (cdar ranges)) (cadr ranges)) (progn - (setcdr (car ranges) (car (cdr ranges))) - (setcdr ranges (cdr (cdr ranges))))) - (if (= (1+ (cdr (car ranges))) (car (car (cdr ranges)))) + (setcdr (car ranges) (cadr ranges)) + (setcdr ranges (cddr ranges)))) + (if (= (1+ (cdar ranges)) (caadr ranges)) (progn - (setcdr (car ranges) (cdr (car (cdr ranges)))) - (setcdr ranges (cdr (cdr ranges)))))))) + (setcdr (car ranges) (cdadr ranges)) + (setcdr ranges (cddr ranges))))))) (setq ranges (cdr ranges))) out))) @@ -3065,176 +4096,208 @@ Note: LIST has to be sorted over `<'." "Return a list of ranges that has all articles from LIST removed from RANGES. Note: LIST has to be sorted over `<'." ;; !!! This function shouldn't look like this, but I've got a headache. - (gnus-compress-sequence + (gnus-compress-sequence (gnus-sorted-complement (gnus-uncompress-range ranges) list))) (defun gnus-member-of-range (number ranges) (if (not (listp (cdr ranges))) - (and (>= number (car ranges)) + (and (>= number (car ranges)) (<= number (cdr ranges))) (let ((not-stop t)) - (while (and ranges + (while (and ranges (if (numberp (car ranges)) (>= number (car ranges)) - (>= number (car (car ranges)))) + (>= number (caar ranges))) not-stop) (if (if (numberp (car ranges)) (= number (car ranges)) - (and (>= number (car (car ranges))) - (<= number (cdr (car ranges))))) + (and (>= number (caar ranges)) + (<= number (cdar ranges)))) (setq not-stop nil)) (setq ranges (cdr ranges))) (not not-stop)))) +(defun gnus-range-length (range) + "Return the length RANGE would have if uncompressed." + (length (gnus-uncompress-range range))) + +(defun gnus-sublist-p (list sublist) + "Test whether all elements in SUBLIST are members of LIST." + (let ((sublistp t)) + (while sublist + (unless (memq (pop sublist) list) + (setq sublistp nil + sublist nil))) + sublistp)) + ;;; ;;; Gnus group mode ;;; (defvar gnus-group-mode-map nil) -(defvar gnus-group-group-map nil) -(defvar gnus-group-mark-map nil) -(defvar gnus-group-list-map nil) -(defvar gnus-group-help-map nil) -(defvar gnus-group-sub-map nil) (put 'gnus-group-mode 'mode-class 'special) -(if gnus-group-mode-map - nil +(unless gnus-group-mode-map (setq gnus-group-mode-map (make-keymap)) (suppress-keymap gnus-group-mode-map) - (define-key gnus-group-mode-map " " 'gnus-group-read-group) - (define-key gnus-group-mode-map "=" 'gnus-group-select-group) - (define-key gnus-group-mode-map "\r" 'gnus-group-select-group) - (define-key gnus-group-mode-map "j" 'gnus-group-jump-to-group) - (define-key gnus-group-mode-map "n" 'gnus-group-next-unread-group) - (define-key gnus-group-mode-map "p" 'gnus-group-prev-unread-group) - (define-key gnus-group-mode-map "\177" 'gnus-group-prev-unread-group) - (define-key gnus-group-mode-map "N" 'gnus-group-next-group) - (define-key gnus-group-mode-map "P" 'gnus-group-prev-group) - (define-key gnus-group-mode-map - "\M-n" 'gnus-group-next-unread-group-same-level) - (define-key gnus-group-mode-map - "\M-p" 'gnus-group-prev-unread-group-same-level) - (define-key gnus-group-mode-map "," 'gnus-group-best-unread-group) - (define-key gnus-group-mode-map "." 'gnus-group-first-unread-group) - (define-key gnus-group-mode-map "u" 'gnus-group-unsubscribe-current-group) - (define-key gnus-group-mode-map "U" 'gnus-group-unsubscribe-group) - (define-key gnus-group-mode-map "c" 'gnus-group-catchup-current) - (define-key gnus-group-mode-map "C" 'gnus-group-catchup-current-all) - (define-key gnus-group-mode-map "l" 'gnus-group-list-groups) - (define-key gnus-group-mode-map "L" 'gnus-group-list-all-groups) - (define-key gnus-group-mode-map "m" 'gnus-group-mail) - (define-key gnus-group-mode-map "g" 'gnus-group-get-new-news) - (define-key gnus-group-mode-map "\M-g" 'gnus-group-get-new-news-this-group) - (define-key gnus-group-mode-map "R" 'gnus-group-restart) - (define-key gnus-group-mode-map "r" 'gnus-group-read-init-file) - (define-key gnus-group-mode-map "B" 'gnus-group-browse-foreign-server) - (define-key gnus-group-mode-map "b" 'gnus-group-check-bogus-groups) - (define-key gnus-group-mode-map "F" 'gnus-find-new-newsgroups) - (define-key gnus-group-mode-map "\C-c\C-d" 'gnus-group-describe-group) - (define-key gnus-group-mode-map "\M-d" 'gnus-group-describe-all-groups) - (define-key gnus-group-mode-map "\C-c\C-a" 'gnus-group-apropos) - (define-key gnus-group-mode-map "\C-c\M-\C-a" 'gnus-group-description-apropos) - (define-key gnus-group-mode-map "a" 'gnus-group-post-news) - (define-key gnus-group-mode-map "\ek" 'gnus-group-edit-local-kill) - (define-key gnus-group-mode-map "\eK" 'gnus-group-edit-global-kill) - (define-key gnus-group-mode-map "\C-k" 'gnus-group-kill-group) - (define-key gnus-group-mode-map "\C-y" 'gnus-group-yank-group) - (define-key gnus-group-mode-map "\C-w" 'gnus-group-kill-region) - (define-key gnus-group-mode-map "\C-x\C-t" 'gnus-group-transpose-groups) - (define-key gnus-group-mode-map "\C-c\C-l" 'gnus-group-list-killed) - (define-key gnus-group-mode-map "\C-c\C-x" 'gnus-group-expire-articles) - (define-key gnus-group-mode-map "\C-c\M-\C-x" 'gnus-group-expire-all-groups) - (define-key gnus-group-mode-map "V" 'gnus-version) - (define-key gnus-group-mode-map "s" 'gnus-group-save-newsrc) - (define-key gnus-group-mode-map "z" 'gnus-group-suspend) - (define-key gnus-group-mode-map "Z" 'gnus-group-clear-dribble) - (define-key gnus-group-mode-map "q" 'gnus-group-exit) - (define-key gnus-group-mode-map "Q" 'gnus-group-quit) - (define-key gnus-group-mode-map "?" 'gnus-group-describe-briefly) - (define-key gnus-group-mode-map "\C-c\C-i" 'gnus-info-find-node) - (define-key gnus-group-mode-map "\M-e" 'gnus-group-edit-group-method) - (define-key gnus-group-mode-map "^" 'gnus-group-enter-server-mode) - (define-key gnus-group-mode-map gnus-mouse-2 'gnus-mouse-pick-group) - (define-key gnus-group-mode-map "<" 'beginning-of-buffer) - (define-key gnus-group-mode-map ">" 'end-of-buffer) - (define-key gnus-group-mode-map "\C-c\C-b" 'gnus-bug) - (define-key gnus-group-mode-map "\C-c\C-s" 'gnus-group-sort-groups) - - (define-key gnus-group-mode-map "#" 'gnus-group-mark-group) - (define-key gnus-group-mode-map "\M-#" 'gnus-group-unmark-group) - (define-prefix-command 'gnus-group-mark-map) - (define-key gnus-group-mode-map "M" 'gnus-group-mark-map) - (define-key gnus-group-mark-map "m" 'gnus-group-mark-group) - (define-key gnus-group-mark-map "u" 'gnus-group-unmark-group) - (define-key gnus-group-mark-map "w" 'gnus-group-mark-region) - - (define-prefix-command 'gnus-group-group-map) - (define-key gnus-group-mode-map "G" 'gnus-group-group-map) - (define-key gnus-group-group-map "d" 'gnus-group-make-directory-group) - (define-key gnus-group-group-map "h" 'gnus-group-make-help-group) - (define-key gnus-group-group-map "a" 'gnus-group-make-archive-group) - (define-key gnus-group-group-map "k" 'gnus-group-make-kiboze-group) - (define-key gnus-group-group-map "m" 'gnus-group-make-group) - (define-key gnus-group-group-map "E" 'gnus-group-edit-group) - (define-key gnus-group-group-map "e" 'gnus-group-edit-group-method) - (define-key gnus-group-group-map "p" 'gnus-group-edit-group-parameters) - (define-key gnus-group-group-map "v" 'gnus-group-add-to-virtual) - (define-key gnus-group-group-map "V" 'gnus-group-make-empty-virtual) - (define-key gnus-group-group-map "D" 'gnus-group-enter-directory) - (define-key gnus-group-group-map "f" 'gnus-group-make-doc-group) - ;;(define-key gnus-group-group-map "sb" 'gnus-group-brew-soup) - ;;(define-key gnus-group-group-map "sw" 'gnus-soup-save-areas) - ;;(define-key gnus-group-group-map "ss" 'gnus-soup-send-replies) - ;;(define-key gnus-group-group-map "sp" 'gnus-soup-pack-packet) - ;;(define-key gnus-group-group-map "sr" 'nnsoup-pack-replies) - - (define-prefix-command 'gnus-group-list-map) - (define-key gnus-group-mode-map "A" 'gnus-group-list-map) - (define-key gnus-group-list-map "k" 'gnus-group-list-killed) - (define-key gnus-group-list-map "z" 'gnus-group-list-zombies) - (define-key gnus-group-list-map "s" 'gnus-group-list-groups) - (define-key gnus-group-list-map "u" 'gnus-group-list-all-groups) - (define-key gnus-group-list-map "a" 'gnus-group-apropos) - (define-key gnus-group-list-map "d" 'gnus-group-description-apropos) - (define-key gnus-group-list-map "m" 'gnus-group-list-matching) - (define-key gnus-group-list-map "M" 'gnus-group-list-all-matching) - - (define-prefix-command 'gnus-group-help-map) - (define-key gnus-group-mode-map "H" 'gnus-group-help-map) - (define-key gnus-group-help-map "f" 'gnus-group-fetch-faq) - - (define-prefix-command 'gnus-group-sub-map) - (define-key gnus-group-mode-map "S" 'gnus-group-sub-map) - (define-key gnus-group-sub-map "l" 'gnus-group-set-current-level) - (define-key gnus-group-sub-map "t" 'gnus-group-unsubscribe-current-group) - (define-key gnus-group-sub-map "s" 'gnus-group-unsubscribe-group) - (define-key gnus-group-sub-map "k" 'gnus-group-kill-group) - (define-key gnus-group-sub-map "y" 'gnus-group-yank-group) - (define-key gnus-group-sub-map "w" 'gnus-group-kill-region) - (define-key gnus-group-sub-map "z" 'gnus-group-kill-all-zombies)) + + (gnus-define-keys gnus-group-mode-map + " " gnus-group-read-group + "=" gnus-group-select-group + "\r" gnus-group-select-group + "\M-\r" gnus-group-quick-select-group + "j" gnus-group-jump-to-group + "n" gnus-group-next-unread-group + "p" gnus-group-prev-unread-group + "\177" gnus-group-prev-unread-group + [delete] gnus-group-prev-unread-group + "N" gnus-group-next-group + "P" gnus-group-prev-group + "\M-n" gnus-group-next-unread-group-same-level + "\M-p" gnus-group-prev-unread-group-same-level + "," gnus-group-best-unread-group + "." gnus-group-first-unread-group + "u" gnus-group-unsubscribe-current-group + "U" gnus-group-unsubscribe-group + "c" gnus-group-catchup-current + "C" gnus-group-catchup-current-all + "l" gnus-group-list-groups + "L" gnus-group-list-all-groups + "m" gnus-group-mail + "g" gnus-group-get-new-news + "\M-g" gnus-group-get-new-news-this-group + "R" gnus-group-restart + "r" gnus-group-read-init-file + "B" gnus-group-browse-foreign-server + "b" gnus-group-check-bogus-groups + "F" gnus-find-new-newsgroups + "\C-c\C-d" gnus-group-describe-group + "\M-d" gnus-group-describe-all-groups + "\C-c\C-a" gnus-group-apropos + "\C-c\M-\C-a" gnus-group-description-apropos + "a" gnus-group-post-news + "\ek" gnus-group-edit-local-kill + "\eK" gnus-group-edit-global-kill + "\C-k" gnus-group-kill-group + "\C-y" gnus-group-yank-group + "\C-w" gnus-group-kill-region + "\C-x\C-t" gnus-group-transpose-groups + "\C-c\C-l" gnus-group-list-killed + "\C-c\C-x" gnus-group-expire-articles + "\C-c\M-\C-x" gnus-group-expire-all-groups + "V" gnus-version + "s" gnus-group-save-newsrc + "z" gnus-group-suspend +; "Z" gnus-group-clear-dribble + "q" gnus-group-exit + "Q" gnus-group-quit + "?" gnus-group-describe-briefly + "\C-c\C-i" gnus-info-find-node + "\M-e" gnus-group-edit-group-method + "^" gnus-group-enter-server-mode + gnus-mouse-2 gnus-mouse-pick-group + "<" beginning-of-buffer + ">" end-of-buffer + "\C-c\C-b" gnus-bug + "\C-c\C-s" gnus-group-sort-groups + "t" gnus-topic-mode + "\C-c\M-g" gnus-activate-all-groups + "\M-&" gnus-group-universal-argument + "#" gnus-group-mark-group + "\M-#" gnus-group-unmark-group) + + (gnus-define-keys (gnus-group-mark-map "M" gnus-group-mode-map) + "m" gnus-group-mark-group + "u" gnus-group-unmark-group + "w" gnus-group-mark-region + "m" gnus-group-mark-buffer + "r" gnus-group-mark-regexp + "U" gnus-group-unmark-all-groups) + + (gnus-define-keys (gnus-group-group-map "G" gnus-group-mode-map) + "d" gnus-group-make-directory-group + "h" gnus-group-make-help-group + "a" gnus-group-make-archive-group + "k" gnus-group-make-kiboze-group + "m" gnus-group-make-group + "E" gnus-group-edit-group + "e" gnus-group-edit-group-method + "p" gnus-group-edit-group-parameters + "v" gnus-group-add-to-virtual + "V" gnus-group-make-empty-virtual + "D" gnus-group-enter-directory + "f" gnus-group-make-doc-group + "r" gnus-group-rename-group + "\177" gnus-group-delete-group + [delete] gnus-group-delete-group) + + (gnus-define-keys (gnus-group-soup-map "s" gnus-group-group-map) + "b" gnus-group-brew-soup + "w" gnus-soup-save-areas + "s" gnus-soup-send-replies + "p" gnus-soup-pack-packet + "r" nnsoup-pack-replies) + + (gnus-define-keys (gnus-group-sort-map "S" gnus-group-group-map) + "s" gnus-group-sort-groups + "a" gnus-group-sort-groups-by-alphabet + "u" gnus-group-sort-groups-by-unread + "l" gnus-group-sort-groups-by-level + "v" gnus-group-sort-groups-by-score + "r" gnus-group-sort-groups-by-rank + "m" gnus-group-sort-groups-by-method) + + (gnus-define-keys (gnus-group-list-map "A" gnus-group-mode-map) + "k" gnus-group-list-killed + "z" gnus-group-list-zombies + "s" gnus-group-list-groups + "u" gnus-group-list-all-groups + "A" gnus-group-list-active + "a" gnus-group-apropos + "d" gnus-group-description-apropos + "m" gnus-group-list-matching + "M" gnus-group-list-all-matching + "l" gnus-group-list-level) + + (gnus-define-keys (gnus-group-score-map "W" gnus-group-mode-map) + "f" gnus-score-flush-cache) + + (gnus-define-keys (gnus-group-help-map "H" gnus-group-mode-map) + "f" gnus-group-fetch-faq) + + (gnus-define-keys (gnus-group-sub-map "S" gnus-group-mode-map) + "l" gnus-group-set-current-level + "t" gnus-group-unsubscribe-current-group + "s" gnus-group-unsubscribe-group + "k" gnus-group-kill-group + "y" gnus-group-yank-group + "w" gnus-group-kill-region + "\C-k" gnus-group-kill-level + "z" gnus-group-kill-all-zombies)) (defun gnus-group-mode () "Major mode for reading news. All normal editing commands are switched off. \\ -The group buffer lists (some of) the groups available. For instance, +The group buffer lists (some of) the groups available. For instance, `\\[gnus-group-list-groups]' will list all subscribed groups with unread articles, while `\\[gnus-group-list-zombies]' -lists all zombie groups. +lists all zombie groups. -Groups that are displayed can be entered with `\\[gnus-group-read-group]'. To subscribe -to a group not displayed, type `\\[gnus-group-unsubscribe-group]'. +Groups that are displayed can be entered with `\\[gnus-group-read-group]'. To subscribe +to a group not displayed, type `\\[gnus-group-unsubscribe-group]'. -For more in-depth information on this mode, read the manual (`\\[gnus-info-find-node]'). +For more in-depth information on this mode, read the manual (`\\[gnus-info-find-node]'). The following commands are available: \\{gnus-group-mode-map}" (interactive) - (if gnus-visual (gnus-group-make-menu-bar)) + (when (and menu-bar-mode + (gnus-visual-p 'group-menu 'menu)) + (gnus-group-make-menu-bar)) (kill-all-local-variables) (gnus-simplify-mode-line) (setq major-mode 'gnus-group-mode) @@ -3245,9 +4308,15 @@ The following commands are available: (buffer-disable-undo (current-buffer)) (setq truncate-lines t) (setq buffer-read-only t) + (gnus-make-local-hook 'post-command-hook) + (gnus-add-hook 'post-command-hook 'gnus-clear-inboxes-moved nil t) (run-hooks 'gnus-group-mode-hook)) +(defun gnus-clear-inboxes-moved () + (setq nnmail-moved-inboxes nil)) + (defun gnus-mouse-pick-group (e) + "Enter the group under the mouse pointer." (interactive "e") (mouse-set-point e) (gnus-group-read-group nil)) @@ -3256,61 +4325,72 @@ The following commands are available: ;; If LEVEL is non-nil, LEVEL will be returned, if not, what happens ;; will depend on whether `gnus-group-use-permanent-levels' is used. (defun gnus-group-default-level (&optional level number-or-nil) - (cond + (cond (gnus-group-use-permanent-levels - (setq gnus-group-default-list-level - (or level gnus-group-default-list-level)) - (or gnus-group-default-list-level gnus-level-subscribed)) + (or (setq gnus-group-use-permanent-levels + (or level (if (numberp gnus-group-use-permanent-levels) + gnus-group-use-permanent-levels + (or gnus-group-default-list-level + gnus-level-subscribed)))) + gnus-group-default-list-level gnus-level-subscribed)) (number-or-nil level) (t (or level gnus-group-default-list-level gnus-level-subscribed)))) - -(defvar gnus-tmp-prev-perm nil) +;;;###autoload +(defun gnus-slave-no-server (&optional arg) + "Read network news as a slave, without connecting to local server" + (interactive "P") + (gnus-no-server arg t)) ;;;###autoload -(defun gnus-no-server (&optional arg) +(defun gnus-no-server (&optional arg slave) "Read network news. If ARG is a positive number, Gnus will use that as the -startup level. If ARG is nil, Gnus will be started at level 2. +startup level. If ARG is nil, Gnus will be started at level 2. If ARG is non-nil and not a positive number, Gnus will prompt the user for the name of an NNTP server to use. As opposed to `gnus', this command will not connect to the local server." (interactive "P") - (let ((perm - (cons gnus-group-use-permanent-levels gnus-group-default-list-level))) - (setq gnus-tmp-prev-perm nil) - (setq gnus-group-use-permanent-levels t) - (gnus (or arg (1- gnus-level-default-subscribed)) t) - (setq gnus-tmp-prev-perm perm))) + (let ((val (or arg (1- gnus-level-default-subscribed)))) + (gnus val t slave) + (make-local-variable 'gnus-group-use-permanent-levels) + (setq gnus-group-use-permanent-levels val))) + +;;;###autoload +(defun gnus-slave (&optional arg) + "Read news as a slave." + (interactive "P") + (gnus arg nil 'slave)) ;;;###autoload -(defun read-news (&optional arg dont-connect) - "Read network news. This is an alias for the `gnus' command." - (gnus arg dont-connect)) +(defun gnus-other-frame (&optional arg) + "Pop up a frame to read news." + (interactive "P") + (if (get-buffer gnus-group-buffer) + (let ((pop-up-frames t)) + (gnus arg)) + (select-frame (make-frame)) + (gnus arg))) ;;;###autoload -(defun gnus (&optional arg dont-connect) +(defun gnus (&optional arg dont-connect slave) "Read network news. If ARG is non-nil and a positive number, Gnus will use that as the -startup level. If ARG is non-nil and not a positive number, Gnus will +startup level. If ARG is non-nil and not a positive number, Gnus will prompt the user for the name of an NNTP server to use." (interactive "P") + (if (get-buffer gnus-group-buffer) (progn (switch-to-buffer gnus-group-buffer) (gnus-group-get-new-news)) (gnus-clear-system) - (nnheader-init-server-buffer) - ;; We do this if `gnus-no-server' has been run. - (if gnus-tmp-prev-perm - (setq gnus-group-use-permanent-levels (car gnus-tmp-prev-perm) - gnus-group-default-list-level (cdr gnus-tmp-prev-perm) - gnus-tmp-prev-perm nil)) (gnus-read-init-file) + (setq gnus-slave slave) (gnus-group-setup-buffer) (let ((buffer-read-only nil)) @@ -3319,31 +4399,41 @@ prompt the user for the name of an NNTP server to use." (progn (gnus-group-startup-message) (sit-for 0)))) - - (let ((level (and arg (numberp arg) (> arg 0) arg)) + + (let ((level (and (numberp arg) (> arg 0) arg)) did-connect) (unwind-protect (progn - (or dont-connect + (or dont-connect (setq did-connect (gnus-start-news-server (and arg (not level)))))) - (if (and (not dont-connect) + (if (and (not dont-connect) (not did-connect)) (gnus-group-quit) (run-hooks 'gnus-startup-hook) - ;; NNTP server is successfully open. + ;; NNTP server is successfully open. ;; Find the current startup file name. - (setq gnus-current-startup-file + (setq gnus-current-startup-file (gnus-make-newsrc-file gnus-startup-file)) ;; Read the dribble file. - (and gnus-use-dribble-file (gnus-dribble-read-file)) + (when (or gnus-slave gnus-use-dribble-file) + (gnus-dribble-read-file)) + + ;; Allow using GroupLens predictions. + (when gnus-use-grouplens + (bbb-login) + (add-hook 'gnus-summary-mode-hook 'gnus-grouplens-mode)) (gnus-summary-make-display-table) - (gnus-setup-news nil level) + ;; Do the actual startup. + (gnus-setup-news nil level dont-connect) + ;; Generate the group buffer. (gnus-group-list-groups level) - (gnus-configure-windows 'group)))))) + (gnus-group-first-unread-group) + (gnus-configure-windows 'group) + (gnus-group-set-mode-line)))))) (defun gnus-unload () "Unload all Gnus features." @@ -3353,89 +4443,88 @@ prompt the user for the name of an NNTP server to use." (let ((history load-history) feature) (while history - (and (string-match "^gnus" (car (car history))) + (and (string-match "^\\(gnus\\|nn\\)" (caar history)) (setq feature (cdr (assq 'provide (car history)))) (unload-feature feature 'force)) (setq history (cdr history))))) +(defun gnus-compile () + "Byte-compile the user-defined format specs." + (interactive) + (let ((entries gnus-format-specs) + entry gnus-tmp-func) + (save-excursion + (gnus-message 7 "Compiling format specs...") + + (while entries + (setq entry (pop entries)) + (if (eq (car entry) 'version) + (setq gnus-format-specs (delq entry gnus-format-specs)) + (when (and (listp (caddr entry)) + (not (eq 'byte-code (caaddr entry)))) + (fset 'gnus-tmp-func + `(lambda () ,(caddr entry))) + (byte-compile 'gnus-tmp-func) + (setcar (cddr entry) (gnus-byte-code 'gnus-tmp-func))))) + + (push (cons 'version emacs-version) gnus-format-specs) + + (gnus-message 7 "Compiling user specs...done")))) + +(defun gnus-indent-rigidly (start end arg) + "Indent rigidly using only spaces and no tabs." + (save-excursion + (save-restriction + (narrow-to-region start end) + (indent-rigidly start end arg) + (goto-char (point-min)) + (while (search-forward "\t" nil t) + (replace-match " " t t))))) + (defun gnus-group-startup-message (&optional x y) "Insert startup message in current buffer." ;; Insert the message. (erase-buffer) (insert - (format " - _ ___ _ _ - _ ___ __ ___ __ _ ___ - __ _ ___ __ ___ - _ ___ _ - _ _ __ _ - ___ __ _ - __ _ - _ _ _ - _ _ _ - _ _ _ - __ ___ - _ _ _ _ - _ _ - _ _ - _ _ - _ - __ - - - Gnus * A newsreader for Emacsen - A Praxis release * larsi@ifi.uio.no -" - gnus-version)) + (format " %s + _ ___ _ _ + _ ___ __ ___ __ _ ___ + __ _ ___ __ ___ + _ ___ _ + _ _ __ _ + ___ __ _ + __ _ + _ _ _ + _ _ _ + _ _ _ + __ ___ + _ _ _ _ + _ _ + _ _ + _ _ + _ + __ + +" + "")) ;; And then hack it. - ;; 18 is the longest line. - (indent-rigidly (point-min) (point-max) - (/ (max (- (window-width) (or x 46)) 0) 2)) + (gnus-indent-rigidly (point-min) (point-max) + (/ (max (- (window-width) (or x 46)) 0) 2)) (goto-char (point-min)) + (forward-line 1) (let* ((pheight (count-lines (point-min) (point-max))) (wheight (window-height)) - (rest (- wheight pheight))) + (rest (- wheight pheight))) (insert (make-string (max 0 (* 2 (/ rest 3))) ?\n))) - - - ;; Fontify some. (goto-char (point-min)) - (search-forward "Praxis") - (put-text-property (match-beginning 0) (match-end 0) 'face 'bold) - (goto-char (point-min))) - -(defun gnus-group-startup-message-old (&optional x y) - "Insert startup message in current buffer." - ;; Insert the message. - (erase-buffer) - (insert - (format " - %s - A newsreader - for GNU Emacs - - Based on GNUS - written by - Masanobu UMEDA - - A Praxis Release - larsi@ifi.uio.no -" - gnus-version)) - ;; And then hack it. - ;; 18 is the longest line. - (indent-rigidly (point-min) (point-max) - (/ (max (- (window-width) (or x 28)) 0) 2)) - (goto-char (point-min)) - ;; +4 is fuzzy factor. - (insert-char ?\n (/ (max (- (window-height) (or y 12)) 0) 2)) - - ;; Fontify some. + (and (search-forward "Praxis" nil t) + (gnus-put-text-property (match-beginning 0) (match-end 0) 'face 'bold)) (goto-char (point-min)) - (search-forward "Praxis") - (put-text-property (match-beginning 0) (match-end 0) 'face 'bold) - (goto-char (point-min))) + (let* ((mode-string (gnus-group-set-mode-line))) + (setq mode-line-buffer-identification + (list (concat gnus-version (substring (car mode-string) 4)))) + (set-buffer-modified-p t))) (defun gnus-group-setup-buffer () (or (get-buffer gnus-group-buffer) @@ -3445,11 +4534,11 @@ prompt the user for the name of an NNTP server to use." (gnus-group-mode) (and gnus-carpal (gnus-carpal-setup-buffer 'group))))) -(defun gnus-group-list-groups (&optional level unread) +(defun gnus-group-list-groups (&optional level unread lowest) "List newsgroups with level LEVEL or lower that have unread articles. Default is all subscribed groups. If argument UNREAD is non-nil, groups with no unread articles are also -listed." +listed." (interactive (list (if current-prefix-arg (prefix-numeric-value current-prefix-arg) (or @@ -3461,35 +4550,49 @@ listed." unread (cdr gnus-group-list-mode))) (setq level (gnus-group-default-level level)) (gnus-group-setup-buffer) ;May call from out of group buffer + (gnus-update-format-specifications) (let ((case-fold-search nil) + (props (text-properties-at (gnus-point-at-bol))) (group (gnus-group-group-name))) - (funcall gnus-group-prepare-function level unread nil) + (set-buffer gnus-group-buffer) + (funcall gnus-group-prepare-function level unread lowest) (if (zerop (buffer-size)) (gnus-message 5 gnus-no-groups-message) - (goto-char (point-min)) - (if (not group) - ;; Go to the first group with unread articles. - (gnus-group-search-forward nil nil nil t) - ;; Find the right group to put point on. If the current group - ;; has disappeared in the new listing, try to find the next - ;; one. If no next one can be found, just leave point at the - ;; first newsgroup in the buffer. - (if (not (gnus-goto-char - (text-property-any (point-min) (point-max) - 'gnus-group (intern group)))) - (let ((newsrc (nthcdr 3 (gnus-gethash group gnus-newsrc-hashtb)))) - (while (and newsrc - (not (gnus-goto-char - (text-property-any - (point-min) (point-max) 'gnus-group - (intern (car (car newsrc))))))) - (setq newsrc (cdr newsrc))) - (or newsrc (progn (goto-char (point-max)) - (forward-line -1)))))) + (goto-char (point-max)) + (when (or (not gnus-group-goto-next-group-function) + (not (funcall gnus-group-goto-next-group-function + group props))) + (if (not group) + ;; Go to the first group with unread articles. + (gnus-group-search-forward t) + ;; Find the right group to put point on. If the current group + ;; has disappeared in the new listing, try to find the next + ;; one. If no next one can be found, just leave point at the + ;; first newsgroup in the buffer. + (if (not (gnus-goto-char + (text-property-any + (point-min) (point-max) + 'gnus-group (gnus-intern-safe group gnus-active-hashtb)))) + (let ((newsrc (cdddr (gnus-gethash group gnus-newsrc-hashtb)))) + (while (and newsrc + (not (gnus-goto-char + (text-property-any + (point-min) (point-max) 'gnus-group + (gnus-intern-safe + (caar newsrc) gnus-active-hashtb))))) + (setq newsrc (cdr newsrc))) + (or newsrc (progn (goto-char (point-max)) + (forward-line -1))))))) ;; Adjust cursor point. - (gnus-group-position-cursor)))) + (gnus-group-position-point)))) + +(defun gnus-group-list-level (level &optional all) + "List groups on LEVEL. +If ALL (the prefix), also list groups that have no unread articles." + (interactive "nList groups on level: \nP") + (gnus-group-list-groups level all level)) -(defun gnus-group-prepare-flat (level &optional all lowest regexp) +(defun gnus-group-prepare-flat (level &optional all lowest regexp) "List all newsgroups with unread articles of level LEVEL or lower. If ALL is non-nil, list groups that have no unread articles. If LOWEST is non-nil, list all newsgroups of level LOWEST or higher. @@ -3498,36 +4601,47 @@ If REGEXP, only list groups matching REGEXP." (let ((buffer-read-only nil) (newsrc (cdr gnus-newsrc-alist)) (lowest (or lowest 1)) - info clevel unread group) + info clevel unread group params) (erase-buffer) (if (< lowest gnus-level-zombie) ;; List living groups. (while newsrc (setq info (car newsrc) - group (car info) + group (gnus-info-group info) + params (gnus-info-params info) newsrc (cdr newsrc) unread (car (gnus-gethash group gnus-newsrc-hashtb))) (and unread ; This group might be bogus (or (not regexp) (string-match regexp group)) - (<= (setq clevel (car (cdr info))) level) + (<= (setq clevel (gnus-info-level info)) level) (>= clevel lowest) (or all ; We list all groups? - (eq unread t) ; We list unactivated groups - (> unread 0) ; We list groups with unread articles - (cdr (assq 'tick (nth 3 info)))) ; And ticked groups - (gnus-group-insert-group-line - nil group (car (cdr info)) (nth 3 info) unread (nth 4 info))))) + (if (eq unread t) ; Unactivated? + gnus-group-list-inactive-groups ; We list unactivated + (> unread 0)) ; We list groups with unread articles + (and gnus-list-groups-with-ticked-articles + (cdr (assq 'tick (gnus-info-marks info)))) + ; And groups with tickeds + ;; Check for permanent visibility. + (and gnus-permanently-visible-groups + (string-match gnus-permanently-visible-groups + group)) + (memq 'visible params) + (cdr (assq 'visible params))) + (gnus-group-insert-group-line + group (gnus-info-level info) + (gnus-info-marks info) unread (gnus-info-method info))))) ;; List dead groups. (and (>= level gnus-level-zombie) (<= lowest gnus-level-zombie) - (gnus-group-prepare-flat-list-dead - (setq gnus-zombie-list (sort gnus-zombie-list 'string<)) + (gnus-group-prepare-flat-list-dead + (setq gnus-zombie-list (sort gnus-zombie-list 'string<)) gnus-level-zombie ?Z regexp)) (and (>= level gnus-level-killed) (<= lowest gnus-level-killed) - (gnus-group-prepare-flat-list-dead - (setq gnus-killed-list (sort gnus-killed-list 'string<)) + (gnus-group-prepare-flat-list-dead + (setq gnus-killed-list (sort gnus-killed-list 'string<)) gnus-level-killed ?K regexp)) (gnus-group-set-mode-line) @@ -3536,35 +4650,119 @@ If REGEXP, only list groups matching REGEXP." (defun gnus-group-prepare-flat-list-dead (groups level mark regexp) ;; List zombies and killed lists somewhat faster, which was - ;; suggested by Jack Vinson . It does + ;; suggested by Jack Vinson . It does ;; this by ignoring the group format specification altogether. - (let (group beg) - (while groups - (setq group (car groups) - groups (cdr groups)) - (if (or (not regexp) - (string-match regexp group)) - (progn - (setq beg (point)) - (insert (format " %c *: %s\n" mark group)) - (add-text-properties - beg (1+ beg) - (list 'gnus-group (intern group) + (let (group) + (if regexp + ;; This loop is used when listing groups that match some + ;; regexp. + (while groups + (setq group (pop groups)) + (when (string-match regexp group) + (gnus-add-text-properties + (point) (prog1 (1+ (point)) + (insert " " mark " *: " group "\n")) + (list 'gnus-group (gnus-intern-safe group gnus-active-hashtb) 'gnus-unread t - 'gnus-level level))))))) - -(defun gnus-group-real-name (group) + 'gnus-level level)))) + ;; This loop is used when listing all groups. + (while groups + (gnus-add-text-properties + (point) (prog1 (1+ (point)) + (insert " " mark " *: " + (setq group (pop groups)) "\n")) + (list 'gnus-group (gnus-intern-safe group gnus-active-hashtb) + 'gnus-unread t + 'gnus-level level)))))) + +(defmacro gnus-group-real-name (group) "Find the real name of a foreign newsgroup." - (if (string-match ":[^:]+$" group) - (substring group (1+ (match-beginning 0))) - group)) + `(let ((gname ,group)) + (if (string-match ":[^:]+$" gname) + (substring gname (1+ (match-beginning 0))) + gname))) + +(defsubst gnus-server-add-address (method) + (let ((method-name (symbol-name (car method)))) + (if (and (memq 'address (assoc method-name gnus-valid-select-methods)) + (not (assq (intern (concat method-name "-address")) method))) + (append method (list (list (intern (concat method-name "-address")) + (nth 1 method)))) + method))) + +(defsubst gnus-server-get-method (group method) + ;; Input either a server name, and extended server name, or a + ;; select method, and return a select method. + (cond ((stringp method) + (gnus-server-to-method method)) + ((equal method gnus-select-method) + gnus-select-method) + ((and (stringp (car method)) group) + (gnus-server-extend-method group method)) + ((and method (not group) + (equal (cadr method) "")) + method) + (t + (gnus-server-add-address method)))) + +(defun gnus-server-to-method (server) + "Map virtual server names to select methods." + (or + ;; Is this a method, perhaps? + (and server (listp server) server) + ;; Perhaps this is the native server? + (and (equal server "native") gnus-select-method) + ;; It should be in the server alist. + (cdr (assoc server gnus-server-alist)) + ;; If not, we look through all the opened server + ;; to see whether we can find it there. + (let ((opened gnus-opened-servers)) + (while (and opened + (not (equal server (format "%s:%s" (caaar opened) + (cadaar opened))))) + (pop opened)) + (caar opened)))) + +(defmacro gnus-method-equal (ss1 ss2) + "Say whether two servers are equal." + `(let ((s1 ,ss1) + (s2 ,ss2)) + (or (equal s1 s2) + (and (= (length s1) (length s2)) + (progn + (while (and s1 (member (car s1) s2)) + (setq s1 (cdr s1))) + (null s1)))))) + +(defun gnus-server-equal (m1 m2) + "Say whether two methods are equal." + (let ((m1 (cond ((null m1) gnus-select-method) + ((stringp m1) (gnus-server-to-method m1)) + (t m1))) + (m2 (cond ((null m2) gnus-select-method) + ((stringp m2) (gnus-server-to-method m2)) + (t m2)))) + (gnus-method-equal m1 m2))) + +(defun gnus-servers-using-backend (backend) + "Return a list of known servers using BACKEND." + (let ((opened gnus-opened-servers) + out) + (while opened + (when (eq backend (caaar opened)) + (push (caar opened) out)) + (pop opened)) + out)) (defun gnus-group-prefixed-name (group method) "Return the whole name from GROUP and METHOD." (and (stringp method) (setq method (gnus-server-to-method method))) (concat (format "%s" (car method)) - (if (and - (assoc (format "%s" (car method)) (gnus-methods-using 'address)) + (if (and + (or (assoc (format "%s" (car method)) + (gnus-methods-using 'address)) + (gnus-server-equal method gnus-message-archive-method)) + (nth 1 method) (not (string= (nth 1 method) ""))) (concat "+" (nth 1 method))) ":" group)) @@ -3575,83 +4773,156 @@ If REGEXP, only list groups matching REGEXP." (substring group 0 (match-end 0)) "")) -(defun gnus-group-method-name (group) - "Return the method used for selecting GROUP." +(defun gnus-group-method (group) + "Return the server or method used for selecting GROUP." (let ((prefix (gnus-group-real-prefix group))) (if (equal prefix "") gnus-select-method - (if (string-match "^[^\\+]+\\+" prefix) - (list (intern (substring prefix 0 (1- (match-end 0)))) - (substring prefix (match-end 0) (1- (length prefix)))) - (list (intern (substring prefix 0 (1- (length prefix)))) ""))))) + (let ((servers gnus-opened-servers) + (server "") + backend possible found) + (if (string-match "^[^\\+]+\\+" prefix) + (setq backend (intern (substring prefix 0 (1- (match-end 0)))) + server (substring prefix (match-end 0) (1- (length prefix)))) + (setq backend (intern (substring prefix 0 (1- (length prefix)))))) + (while servers + (when (eq (caaar servers) backend) + (setq possible (caar servers)) + (when (equal (cadaar servers) server) + (setq found (caar servers)))) + (pop servers)) + (or (car (rassoc found gnus-server-alist)) + found + (car (rassoc possible gnus-server-alist)) + possible + (list backend server)))))) + +(defsubst gnus-secondary-method-p (method) + "Return whether METHOD is a secondary select method." + (let ((methods gnus-secondary-select-methods) + (gmethod (gnus-server-get-method nil method))) + (while (and methods + (not (equal (gnus-server-get-method nil (car methods)) + gmethod))) + (setq methods (cdr methods))) + methods)) (defun gnus-group-foreign-p (group) - "Return nil if GROUP is native, non-nil if it is foreign." - (string-match ":" group)) + "Say whether a group is foreign or not." + (and (not (gnus-group-native-p group)) + (not (gnus-group-secondary-p group)))) + +(defun gnus-group-native-p (group) + "Say whether the group is native or not." + (not (string-match ":" group))) + +(defun gnus-group-secondary-p (group) + "Say whether the group is secondary or not." + (gnus-secondary-method-p (gnus-find-method-for-group group))) + +(defun gnus-group-get-parameter (group &optional symbol) + "Returns the group parameters for GROUP. +If SYMBOL, return the value of that symbol in the group parameters." + (let ((params (gnus-info-params (gnus-get-info group)))) + (if symbol + (gnus-group-parameter-value params symbol) + params))) + +(defun gnus-group-parameter-value (params symbol) + "Return the value of SYMBOL in group PARAMS." + (or (car (memq symbol params)) ; It's either a simple symbol + (cdr (assq symbol params)))) ; or a cons. + +(defun gnus-group-add-parameter (group param) + "Add parameter PARAM to GROUP." + (let ((info (gnus-get-info group))) + (if (not info) + () ; This is a dead group. We just ignore it. + ;; Cons the new param to the old one and update. + (gnus-group-set-info (cons param (gnus-info-params info)) + group 'params)))) + +(defun gnus-group-set-parameter (group name value) + "Set parameter NAME to VALUE in GROUP." + (let ((info (gnus-get-info group))) + (if (not info) + () ; This is a dead group. We just ignore it. + (let ((old-params (gnus-info-params info)) + (new-params (list (cons name value)))) + (while old-params + (if (or (not (listp (car old-params))) + (not (eq (caar old-params) name))) + (setq new-params (append new-params (list (car old-params))))) + (setq old-params (cdr old-params))) + (gnus-group-set-info new-params group 'params))))) + +(defun gnus-group-add-score (group &optional score) + "Add SCORE to the GROUP score. +If SCORE is nil, add 1 to the score of GROUP." + (let ((info (gnus-get-info group))) + (when info + (gnus-info-set-score info (+ (gnus-info-score info) (or score 1)))))) + +(defun gnus-summary-bubble-group () + "Increase the score of the current group. +This is a handy function to add to `gnus-summary-exit-hook' to +increase the score of each group you read." + (gnus-group-add-score gnus-newsgroup-name)) (defun gnus-group-set-info (info &optional method-only-group part) (let* ((entry (gnus-gethash - (or method-only-group (car info)) gnus-newsrc-hashtb)) + (or method-only-group (gnus-info-group info)) + gnus-newsrc-hashtb)) (part-info info) - (info (if method-only-group (nth 2 entry) info))) - (if (not method-only-group) - () - (or entry - (error "Trying to change non-existent group %s" method-only-group)) + (info (if method-only-group (nth 2 entry) info)) + method) + (when method-only-group + (unless entry + (error "Trying to change non-existent group %s" method-only-group)) ;; We have received parts of the actual group info - either the - ;; select method or the group parameters. We first check + ;; select method or the group parameters. We first check ;; whether we have to extend the info, and if so, do that. (let ((len (length info)) (total (if (eq part 'method) 5 6))) - (and (< len total) - (setcdr (nthcdr (1- len) info) - (make-list (- total len) nil))) + (when (< len total) + (setcdr (nthcdr (1- len) info) + (make-list (- total len) nil))) ;; Then we enter the new info. (setcar (nthcdr (1- total) info) part-info))) - ;; We uncompress some lists of marked articles. - (let (marked) - (if (not (setq marked (nth 3 info))) - () - (while marked - (or (eq 'score (car (car marked))) - (eq 'bookmark (car (car marked))) - (eq 'killed (car (car marked))) - (setcdr (car marked) - (gnus-uncompress-range (cdr (car marked))))) - (setq marked (cdr marked))))) - (if entry - () + (unless entry ;; This is a new group, so we just create it. (save-excursion (set-buffer gnus-group-buffer) - (if (nth 4 info) - ;; It's a foreign group... - (gnus-group-make-group - (gnus-group-real-name (car info)) - (prin1-to-string (car (nth 4 info))) - (nth 1 (nth 4 info))) - ;; It's a native group. - (gnus-group-make-group (car info))) + (setq method (gnus-info-method info)) + (when (gnus-server-equal method "native") + (setq method nil)) + (save-excursion + (set-buffer gnus-group-buffer) + (if method + ;; It's a foreign group... + (gnus-group-make-group + (gnus-group-real-name (gnus-info-group info)) + (if (stringp method) method + (prin1-to-string (car method))) + (and (consp method) + (nth 1 (gnus-info-method info)))) + ;; It's a native group. + (gnus-group-make-group (gnus-info-group info)))) (gnus-message 6 "Note: New group created") - (setq entry - (gnus-gethash (gnus-group-prefixed-name - (gnus-group-real-name (car info)) - (or (nth 4 info) gnus-select-method)) + (setq entry + (gnus-gethash (gnus-group-prefixed-name + (gnus-group-real-name (gnus-info-group info)) + (or (gnus-info-method info) gnus-select-method)) gnus-newsrc-hashtb)))) ;; Whether it was a new group or not, we now have the entry, so we ;; can do the update. (if entry (progn (setcar (nthcdr 2 entry) info) - (if (and (not (eq (car entry) t)) - (gnus-gethash (car info) gnus-active-hashtb)) - (let ((marked (nth 3 info))) - (setcar entry - (max 0 (- (length (gnus-list-of-unread-articles - (car info))) - (length (cdr (assq 'tick marked))) - (length (cdr (assq 'dormant marked))))))))) - (error "No such group: %s" (car info))))) + (when (and (not (eq (car entry) t)) + (gnus-active (gnus-info-group info))) + (setcar entry (length (gnus-list-of-unread-articles (car info)))))) + (error "No such group: %s" (gnus-info-group info))))) (defun gnus-group-set-method-info (group select-method) (gnus-group-set-info select-method group 'method)) @@ -3660,159 +4931,205 @@ If REGEXP, only list groups matching REGEXP." (gnus-group-set-info params group 'params)) (defun gnus-group-update-group-line () - "This function updates the current line in the newsgroup buffer and -moves the point to the colon." + "Update the current line in the group buffer." (let* ((buffer-read-only nil) (group (gnus-group-group-name)) - (entry (and group (gnus-gethash group gnus-newsrc-hashtb)))) - (if (and entry (not (gnus-ephemeral-group-p group))) - (gnus-dribble-enter - (concat "(gnus-group-set-info '" (prin1-to-string (nth 2 entry)) - ")"))) - (beginning-of-line) - (delete-region (point) (progn (forward-line 1) (point))) - (gnus-group-insert-group-line-info group) - (forward-line -1) - (gnus-group-position-cursor))) + (entry (and group (gnus-gethash group gnus-newsrc-hashtb))) + gnus-group-indentation) + (when group + (and entry + (not (gnus-ephemeral-group-p group)) + (gnus-dribble-enter + (concat "(gnus-group-set-info '" + (prin1-to-string (nth 2 entry)) ")"))) + (setq gnus-group-indentation (gnus-group-group-indentation)) + (gnus-delete-line) + (gnus-group-insert-group-line-info group) + (forward-line -1) + (gnus-group-position-point)))) (defun gnus-group-insert-group-line-info (group) - (let ((entry (gnus-gethash group gnus-newsrc-hashtb)) + "Insert GROUP on the current line." + (let ((entry (gnus-gethash group gnus-newsrc-hashtb)) active info) (if entry (progn + ;; (Un)subscribed group. (setq info (nth 2 entry)) - (gnus-group-insert-group-line - nil group (nth 1 info) (nth 3 info) (car entry) (nth 4 info))) - (setq active (gnus-gethash group gnus-active-hashtb)) - (gnus-group-insert-group-line - nil group + (gnus-group-insert-group-line + group (gnus-info-level info) (gnus-info-marks info) + (or (car entry) t) (gnus-info-method info))) + ;; This group is dead. + (gnus-group-insert-group-line + group (if (member group gnus-zombie-list) gnus-level-zombie gnus-level-killed) - nil (if active (- (1+ (cdr active)) (car active)) 0) nil)))) - -(defun gnus-group-insert-group-line (gformat group level marked number method) - (let* ((gformat (or gformat gnus-group-line-format-spec)) - (active (gnus-gethash group gnus-active-hashtb)) - (number-total (if active (1+ (- (cdr active) (car active))) 0)) - (number-of-dormant (length (cdr (assq 'dormant marked)))) - (number-of-ticked (length (cdr (assq 'tick marked)))) - (number-of-ticked-and-dormant - (+ number-of-ticked number-of-dormant)) - (number-of-unread-unticked + nil + (if (setq active (gnus-active group)) + (- (1+ (cdr active)) (car active)) 0) + nil)))) + +(defun gnus-group-insert-group-line (gnus-tmp-group gnus-tmp-level + gnus-tmp-marked number + gnus-tmp-method) + "Insert a group line in the group buffer." + (let* ((gnus-tmp-active (gnus-active gnus-tmp-group)) + (gnus-tmp-number-total + (if gnus-tmp-active + (1+ (- (cdr gnus-tmp-active) (car gnus-tmp-active))) + 0)) + (gnus-tmp-number-of-unread (if (numberp number) (int-to-string (max 0 number)) "*")) - (number-of-read + (gnus-tmp-number-of-read (if (numberp number) - (max 0 (- number-total number)) + (int-to-string (max 0 (- gnus-tmp-number-total number))) "*")) - (subscribed (cond ((<= level gnus-level-subscribed) ? ) - ((<= level gnus-level-unsubscribed) ?U) - ((= level gnus-level-zombie) ?Z) - (t ?K))) - (qualified-group (gnus-group-real-name group)) - (newsgroup-description + (gnus-tmp-subscribed + (cond ((<= gnus-tmp-level gnus-level-subscribed) ? ) + ((<= gnus-tmp-level gnus-level-unsubscribed) ?U) + ((= gnus-tmp-level gnus-level-zombie) ?Z) + (t ?K))) + (gnus-tmp-qualified-group (gnus-group-real-name gnus-tmp-group)) + (gnus-tmp-newsgroup-description (if gnus-description-hashtb - (or (gnus-gethash group gnus-description-hashtb) "") + (or (gnus-gethash gnus-tmp-group gnus-description-hashtb) "") "")) - (moderated (if (member group gnus-moderated-list) ?m ? )) - (moderated-string (if (eq moderated ?m) "(m)" "")) - (method (gnus-server-get-method group method)) - (news-server (or (car (cdr method)) "")) - (news-method (or (car method) "")) - (news-method-string - (if method (format "(%s:%s)" (car method) (car (cdr method))) "")) - (marked (if (and - (numberp number) - (zerop number) - (> number-of-ticked 0)) - ?* ? )) - (number (if (eq number t) "*" (+ number number-of-dormant - number-of-ticked))) - (process-marked (if (member group gnus-group-marked) - gnus-process-mark ? )) + (gnus-tmp-moderated + (if (member gnus-tmp-group gnus-moderated-list) ?m ? )) + (gnus-tmp-moderated-string + (if (eq gnus-tmp-moderated ?m) "(m)" "")) + (gnus-tmp-method + (gnus-server-get-method gnus-tmp-group gnus-tmp-method)) + (gnus-tmp-news-server (or (cadr gnus-tmp-method) "")) + (gnus-tmp-news-method (or (car gnus-tmp-method) "")) + (gnus-tmp-news-method-string + (if gnus-tmp-method + (format "(%s:%s)" (car gnus-tmp-method) + (cadr gnus-tmp-method)) "")) + (gnus-tmp-marked-mark + (if (and (numberp number) + (zerop number) + (cdr (assq 'tick gnus-tmp-marked))) + ?* ? )) + (gnus-tmp-process-marked + (if (member gnus-tmp-group gnus-group-marked) + gnus-process-mark ? )) + (gnus-tmp-grouplens + (or (and gnus-use-grouplens + (bbb-grouplens-group-p gnus-tmp-group)) + "")) (buffer-read-only nil) - header ; passed as parameter to user-funcs. - b) + header gnus-tmp-header) ; passed as parameter to user-funcs. (beginning-of-line) - (setq b (point)) - ;; Insert the text. - (insert (eval gformat)) - - (add-text-properties - b (1+ b) (list 'gnus-group (intern group) - 'gnus-unread (if (numberp number) - (string-to-int number-of-unread-unticked) - t) - 'gnus-marked marked - 'gnus-level level)))) + (gnus-add-text-properties + (point) + (prog1 (1+ (point)) + ;; Insert the text. + (eval gnus-group-line-format-spec)) + `(gnus-group ,(gnus-intern-safe gnus-tmp-group gnus-active-hashtb) + gnus-unread ,(if (numberp number) + (string-to-int gnus-tmp-number-of-unread) + t) + gnus-marked ,gnus-tmp-marked-mark + gnus-indentation ,gnus-group-indentation + gnus-level ,gnus-tmp-level)) + (when (inline (gnus-visual-p 'group-highlight 'highlight)) + (forward-line -1) + (run-hooks 'gnus-group-update-hook) + (forward-line)) + ;; Allow XEmacs to remove front-sticky text properties. + (gnus-group-remove-excess-properties))) (defun gnus-group-update-group (group &optional visible-only) - "Update newsgroup info of GROUP. -If VISIBLE-ONLY is non-nil, the group won't be displayed if it isn't already." + "Update all lines where GROUP appear. +If VISIBLE-ONLY is non-nil, the group won't be displayed if it isn't +already." (save-excursion (set-buffer gnus-group-buffer) - (let ((buffer-read-only nil) - visible) - (let ((entry (gnus-gethash group gnus-newsrc-hashtb))) - (if (and entry - (not (gnus-ephemeral-group-p group))) - (gnus-dribble-enter - (concat "(gnus-group-set-info '" (prin1-to-string (nth 2 entry)) - ")")))) - ;; Buffer may be narrowed. - (save-restriction - (widen) - ;; Search a line to modify. If the buffer is large, the search - ;; takes long time. In most cases, current point is on the line - ;; we are looking for. So, first of all, check current line. - (if (or (progn - (beginning-of-line) - (eq (get-text-property (point) 'gnus-group) - (intern group))) - (progn - (gnus-goto-char - (text-property-any - (point-min) (point-max) 'gnus-group (intern group))))) - ;; GROUP is listed in current buffer. So, delete old line. - (progn - (setq visible t) - (beginning-of-line) - (delete-region (point) (progn (forward-line 1) (point)))) + ;; The buffer may be narrowed. + (save-restriction + (widen) + (let ((ident (gnus-intern-safe group gnus-active-hashtb)) + (loc (point-min)) + found buffer-read-only) + ;; Enter the current status into the dribble buffer. + (let ((entry (gnus-gethash group gnus-newsrc-hashtb))) + (if (and entry (not (gnus-ephemeral-group-p group))) + (gnus-dribble-enter + (concat "(gnus-group-set-info '" (prin1-to-string (nth 2 entry)) + ")")))) + ;; Find all group instances. If topics are in use, each group + ;; may be listed in more than once. + (while (setq loc (text-property-any + loc (point-max) 'gnus-group ident)) + (setq found t) + (goto-char loc) + (let ((gnus-group-indentation (gnus-group-group-indentation))) + (gnus-delete-line) + (gnus-group-insert-group-line-info group) + (save-excursion + (forward-line -1) + (run-hooks 'gnus-group-update-group-hook))) + (setq loc (1+ loc))) + (unless (or found visible-only) ;; No such line in the buffer, find out where it's supposed to ;; go, and insert it there (or at the end of the buffer). - ;; Fix by Per Abrahamsen . - (or visible-only - (let ((entry - (cdr (cdr (gnus-gethash group gnus-newsrc-hashtb))))) - (while (and entry - (car entry) - (not - (gnus-goto-char - (text-property-any - (point-min) (point-max) - 'gnus-group (intern (car (car entry))))))) - (setq entry (cdr entry))) - (or entry (goto-char (point-max))))))) - (if (or visible (not visible-only)) - (gnus-group-insert-group-line-info group)) - (gnus-group-set-mode-line)))) + (if gnus-goto-missing-group-function + (funcall gnus-goto-missing-group-function group) + (let ((entry (cddr (gnus-gethash group gnus-newsrc-hashtb)))) + (while (and entry (car entry) + (not + (gnus-goto-char + (text-property-any + (point-min) (point-max) + 'gnus-group (gnus-intern-safe + (caar entry) gnus-active-hashtb))))) + (setq entry (cdr entry))) + (or entry (goto-char (point-max))))) + ;; Finally insert the line. + (let ((gnus-group-indentation (gnus-group-group-indentation))) + (gnus-group-insert-group-line-info group) + (save-excursion + (forward-line -1) + (run-hooks 'gnus-group-update-group-hook)))) + (gnus-group-set-mode-line))))) (defun gnus-group-set-mode-line () - (if (memq 'group gnus-updated-mode-lines) + "Update the mode line in the group buffer." + (when (memq 'group gnus-updated-mode-lines) + ;; Yes, we want to keep this mode line updated. + (save-excursion + (set-buffer gnus-group-buffer) (let* ((gformat (or gnus-group-mode-line-format-spec (setq gnus-group-mode-line-format-spec - (gnus-parse-format - gnus-group-mode-line-format + (gnus-parse-format + gnus-group-mode-line-format gnus-group-mode-line-format-alist)))) - (news-server (car (cdr gnus-select-method))) - (news-method (car gnus-select-method)) + (gnus-tmp-news-server (cadr gnus-select-method)) + (gnus-tmp-news-method (car gnus-select-method)) + (gnus-tmp-colon (if (equal gnus-tmp-news-server "") "" ":")) (max-len 60) - header ;Dummy binding for user-defined specs. + gnus-tmp-header ;Dummy binding for user-defined formats + ;; Get the resulting string. + (modified + (and gnus-dribble-buffer + (buffer-name gnus-dribble-buffer) + (buffer-modified-p gnus-dribble-buffer) + (save-excursion + (set-buffer gnus-dribble-buffer) + (not (zerop (buffer-size)))))) (mode-string (eval gformat))) - (setq mode-string (eval gformat)) - (if (> (length mode-string) max-len) - (setq mode-string (substring mode-string 0 (- max-len 4)))) - (setq mode-line-buffer-identification mode-string) - (set-buffer-modified-p t)))) + ;; Say whether the dribble buffer has been modified. + (setq mode-line-modified + (if modified "---*- " "----- ")) + ;; If the line is too long, we chop it off. + (when (> (length mode-string) max-len) + (setq mode-string (substring mode-string 0 (- max-len 4)))) + (prog1 + (setq mode-line-buffer-identification + (gnus-mode-line-buffer-identification + (list mode-string))) + (set-buffer-modified-p modified)))))) (defun gnus-group-group-name () "Get the name of the newsgroup on the current line." @@ -3823,6 +5140,13 @@ If VISIBLE-ONLY is non-nil, the group won't be displayed if it isn't already." "Get the level of the newsgroup on the current line." (get-text-property (gnus-point-at-bol) 'gnus-level)) +(defun gnus-group-group-indentation () + "Get the indentation of the newsgroup on the current line." + (or (get-text-property (gnus-point-at-bol) 'gnus-indentation) + (and gnus-group-indentation-function + (funcall gnus-group-indentation-function)) + "")) + (defun gnus-group-group-unread () "Get the number of unread articles of the newsgroup on the current line." (get-text-property (gnus-point-at-bol) 'gnus-unread)) @@ -3841,15 +5165,15 @@ If FIRST-TOO, the current line is also eligible as a target." (if (and backward (progn (beginning-of-line)) (bobp)) nil (or first-too (forward-line way)) - (while (and + (while (and (not (eobp)) - (not (setq - found + (not (setq + found (and (or all (and - (let ((unread + (let ((unread (get-text-property (point) 'gnus-unread))) - (or (eq unread t) (and unread (> unread 0)))) + (and (numberp unread) (> unread 0))) (setq lev (get-text-property (point) 'gnus-level)) (<= lev gnus-level-subscribed))) @@ -3864,8 +5188,8 @@ If FIRST-TOO, the current line is also eligible as a target." (setq pos (point)) nil)))))))) (zerop (forward-line way))))) - (if found - (progn (gnus-group-position-cursor) t) + (if found + (progn (gnus-group-position-point) t) (goto-char (or pos beg)) (and pos t)))) @@ -3878,31 +5202,40 @@ If FIRST-TOO, the current line is also eligible as a target." (interactive "p") (let ((buffer-read-only nil) group) - (while - (and (> n 0) - (setq group (gnus-group-group-name)) - (progn - (beginning-of-line) - (forward-char - (or (cdr (assq 'process gnus-group-mark-positions)) 2)) - (delete-char 1) - (if unmark - (progn - (insert " ") - (setq gnus-group-marked (delete group gnus-group-marked))) - (insert "#") - (setq gnus-group-marked - (cons group (delete group gnus-group-marked)))) - t) - (or no-advance (zerop (gnus-group-next-group 1)))) - (setq n (1- n))) - (gnus-summary-position-cursor) + (while (and (> n 0) + (not (eobp))) + (when (setq group (gnus-group-group-name)) + ;; Update the mark. + (beginning-of-line) + (forward-char + (or (cdr (assq 'process gnus-group-mark-positions)) 2)) + (delete-char 1) + (if unmark + (progn + (insert " ") + (setq gnus-group-marked (delete group gnus-group-marked))) + (insert "#") + (setq gnus-group-marked + (cons group (delete group gnus-group-marked))))) + (or no-advance (gnus-group-next-group 1)) + (decf n)) + (gnus-summary-position-point) n)) (defun gnus-group-unmark-group (n) "Remove the mark from the current group." (interactive "p") - (gnus-group-mark-group n 'unmark)) + (gnus-group-mark-group n 'unmark) + (gnus-group-position-point)) + +(defun gnus-group-unmark-all-groups () + "Unmark all groups." + (interactive) + (let ((groups gnus-group-marked)) + (save-excursion + (while groups + (gnus-group-remove-mark (pop groups))))) + (gnus-group-position-point)) (defun gnus-group-mark-region (unmark beg end) "Mark all groups between point and mark. @@ -3913,58 +5246,123 @@ If UNMARK, remove the mark instead." (goto-char beg) (- num (gnus-group-mark-group num unmark))))) +(defun gnus-group-mark-buffer (&optional unmark) + "Mark all groups in the buffer. +If UNMARK, remove the mark instead." + (interactive "P") + (gnus-group-mark-region unmark (point-min) (point-max))) + +(defun gnus-group-mark-regexp (regexp) + "Mark all groups that match some regexp." + (interactive "sMark (regexp): ") + (let ((alist (cdr gnus-newsrc-alist)) + group) + (while alist + (when (string-match regexp (setq group (gnus-info-group (pop alist)))) + (gnus-group-set-mark group)))) + (gnus-group-position-point)) + (defun gnus-group-remove-mark (group) - (and (gnus-group-goto-group group) - (save-excursion - (gnus-group-mark-group 1 'unmark t)))) + "Remove the process mark from GROUP and move point there. +Return nil if the group isn't displayed." + (if (gnus-group-goto-group group) + (save-excursion + (gnus-group-mark-group 1 'unmark t) + t) + (setq gnus-group-marked + (delete group gnus-group-marked)) + nil)) + +(defun gnus-group-set-mark (group) + "Set the process mark on GROUP." + (if (gnus-group-goto-group group) + (save-excursion + (gnus-group-mark-group 1 nil t)) + (setq gnus-group-marked (cons group (delete group gnus-group-marked))))) + +(defun gnus-group-universal-argument (arg &optional groups func) + "Perform any command on all groups accoring to the process/prefix convention." + (interactive "P") + (let ((groups (or groups (gnus-group-process-prefix arg))) + group func) + (if (eq (setq func (or func + (key-binding + (read-key-sequence + (substitute-command-keys + "\\\\[gnus-group-universal-argument]"))))) + 'undefined) + (gnus-error 1 "Undefined key") + (while groups + (gnus-group-remove-mark (setq group (pop groups))) + (command-execute func)))) + (gnus-group-position-point)) -;; Return a list of groups to work on. Take into consideration N (the -;; prefix) and the list of marked groups. (defun gnus-group-process-prefix (n) - (cond (n - (setq n (prefix-numeric-value n)) - ;; There is a prefix, so we return a list of the N next - ;; groups. - (let ((way (if (< n 0) -1 1)) - (n (abs n)) - group groups) - (save-excursion - (while (and (> n 0) - (setq group (gnus-group-group-name))) - (setq groups (cons group groups)) - (setq n (1- n)) - (forward-line way))) - (nreverse groups))) - (gnus-group-marked - ;; No prefix, but a list of marked articles. - (reverse gnus-group-marked)) - (t - ;; Neither marked articles or a prefix, so we return the - ;; current group. - (let ((group (gnus-group-group-name))) - (and group (list group)))))) + "Return a list of groups to work on. +Take into consideration N (the prefix) and the list of marked groups." + (cond + (n + (setq n (prefix-numeric-value n)) + ;; There is a prefix, so we return a list of the N next + ;; groups. + (let ((way (if (< n 0) -1 1)) + (n (abs n)) + group groups) + (save-excursion + (while (and (> n 0) + (setq group (gnus-group-group-name))) + (setq groups (cons group groups)) + (setq n (1- n)) + (gnus-group-next-group way))) + (nreverse groups))) + ((and (boundp 'transient-mark-mode) + transient-mark-mode + (boundp 'mark-active) + mark-active) + ;; Work on the region between point and mark. + (let ((max (max (point) (mark))) + groups) + (save-excursion + (goto-char (min (point) (mark))) + (while + (and + (push (gnus-group-group-name) groups) + (zerop (gnus-group-next-group 1)) + (< (point) max))) + (nreverse groups)))) + (gnus-group-marked + ;; No prefix, but a list of marked articles. + (reverse gnus-group-marked)) + (t + ;; Neither marked articles or a prefix, so we return the + ;; current group. + (let ((group (gnus-group-group-name))) + (and group (list group)))))) ;; Selecting groups. (defun gnus-group-read-group (&optional all no-article group) "Read news in this newsgroup. If the prefix argument ALL is non-nil, already read articles become -readable. If the optional argument NO-ARTICLE is non-nil, no article -will be auto-selected upon group entry." +readable. IF ALL is a number, fetch this number of articles. If the +optional argument NO-ARTICLE is non-nil, no article will be +auto-selected upon group entry. If GROUP is non-nil, fetch that +group." (interactive "P") (let ((group (or group (gnus-group-group-name))) number active marked entry) (or group (error "No group on current line")) - (setq marked - (nth 3 (nth 2 (setq entry (gnus-gethash group gnus-newsrc-hashtb))))) - ;; This group might be a dead group. In that case we have to get + (setq marked (nth 3 (nth 2 (setq entry (gnus-gethash + group gnus-newsrc-hashtb))))) + ;; This group might be a dead group. In that case we have to get ;; the number of unread articles from `gnus-active-hashtb'. - (if entry - (setq number (car entry)) - (if (setq active (gnus-gethash group gnus-active-hashtb)) - (setq number (- (1+ (cdr active)) (car active))))) - (gnus-summary-read-group - group (or all (and (numberp number) + (setq number + (cond ((numberp all) all) + (entry (car entry)) + ((setq active (gnus-active group)) + (- (1+ (cdr active)) (car active))))) + (gnus-summary-read-group + group (or all (and (numberp number) (zerop (+ number (length (cdr (assq 'tick marked))) (length (cdr (assq 'dormant marked))))))) no-article))) @@ -3972,29 +5370,47 @@ will be auto-selected upon group entry." (defun gnus-group-select-group (&optional all) "Select this newsgroup. No article is selected automatically. -If argument ALL is non-nil, already read articles become readable." +If ALL is non-nil, already read articles become readable. +If ALL is a number, fetch this number of articles." (interactive "P") (gnus-group-read-group all t)) -(defun gnus-group-select-group-all () - "Select the current group and display all articles in it." - (interactive) - (gnus-group-select-group 'all)) +(defun gnus-group-quick-select-group (&optional all) + "Select the current group \"quickly\". +This means that no highlighting or scoring will be performed." + (interactive "P") + (let (gnus-visual + gnus-score-find-score-files-function + gnus-apply-kill-hook + gnus-summary-expunge-below) + (gnus-group-read-group all t))) + +(defun gnus-group-visible-select-group (&optional all) + "Select the current group without hiding any articles." + (interactive "P") + (let ((gnus-inhibit-limiting t)) + (gnus-group-read-group all t))) + +;;;###autoload +(defun gnus-fetch-group (group) + "Start Gnus if necessary and enter GROUP. +Returns whether the fetching was successful or not." + (interactive "sGroup name: ") + (or (get-buffer gnus-group-buffer) + (gnus)) + (gnus-group-read-group nil nil group)) -;; Enter a group that is not in the group buffer. Non-nil is returned +;; Enter a group that is not in the group buffer. Non-nil is returned ;; if selection was successful. -(defun gnus-group-read-ephemeral-group +(defun gnus-group-read-ephemeral-group (group method &optional activate quit-config) (let ((group (if (gnus-group-foreign-p group) group (gnus-group-prefixed-name group method)))) - (gnus-sethash + (gnus-sethash group - (list t nil (list group gnus-level-default-subscribed nil nil - (append method - (list - (list 'quit-config - (if quit-config quit-config - (cons (current-buffer) 'summary))))))) + `(t nil (,group ,gnus-level-default-subscribed nil nil ,method + ((quit-config . ,(if quit-config quit-config + (cons (current-buffer) 'summary)))))) gnus-newsrc-hashtb) (set-buffer gnus-group-buffer) (or (gnus-check-server method) @@ -4004,41 +5420,50 @@ If argument ALL is non-nil, already read articles become readable." (condition-case () (gnus-group-read-group t t group) (error nil) - (quit nil)) - (not (equal major-mode 'gnus-group-mode)))) - + (quit nil)))) + (defun gnus-group-jump-to-group (group) "Jump to newsgroup GROUP." - (interactive - (list (completing-read - "Group: " gnus-active-hashtb nil - (memq gnus-select-method gnus-have-read-active-file)))) - - (if (equal group "") - (error "Empty group name")) - - (let ((b (text-property-any - (point-min) (point-max) 'gnus-group (intern group)))) - (if b - ;; Either go to the line in the group buffer... - (goto-char b) - ;; ... or insert the line. - (or - (gnus-gethash group gnus-active-hashtb) - (gnus-activate-group group) - (error "%s error: %s" group (gnus-status-message group))) - - (gnus-group-update-group group) - (goto-char (text-property-any - (point-min) (point-max) 'gnus-group (intern group))))) - ;; Adjust cursor point. - (gnus-group-position-cursor)) + (interactive + (list (completing-read + "Group: " gnus-active-hashtb nil + (gnus-read-active-file-p) + nil + 'gnus-group-history))) + + (when (equal group "") + (error "Empty group name")) + + (when (string-match "[\000-\032]" group) + (error "Control characters in group: %s" group)) + + (let ((b (text-property-any + (point-min) (point-max) + 'gnus-group (gnus-intern-safe group gnus-active-hashtb)))) + (unless (gnus-ephemeral-group-p group) + (if b + ;; Either go to the line in the group buffer... + (goto-char b) + ;; ... or insert the line. + (or + (gnus-active group) + (gnus-activate-group group) + (error "%s error: %s" group (gnus-status-message group))) + + (gnus-group-update-group group) + (goto-char (text-property-any + (point-min) (point-max) + 'gnus-group (gnus-intern-safe group gnus-active-hashtb))))) + ;; Adjust cursor point. + (gnus-group-position-point))) (defun gnus-group-goto-group (group) "Goto to newsgroup GROUP." - (let ((b (text-property-any (point-min) (point-max) - 'gnus-group (intern group)))) - (and b (goto-char b)))) + (when group + (let ((b (text-property-any (point-min) (point-max) + 'gnus-group (gnus-intern-safe + group gnus-active-hashtb)))) + (and b (goto-char b))))) (defun gnus-group-next-group (n) "Go to next N'th newsgroup. @@ -4061,7 +5486,7 @@ made." (let ((backward (< n 0)) (n (abs n))) (while (and (> n 0) - (gnus-group-search-forward + (gnus-group-search-forward backward (or (not gnus-group-goto-unread) all) level)) (setq n (1- n))) (if (/= 0 n) (gnus-message 7 "No more%s newsgroups%s" (if all "" " unread") @@ -4078,7 +5503,7 @@ done." (defun gnus-group-prev-unread-group (n) "Go to previous N'th unread newsgroup. Returns the difference between N and the number of skips actually -done." +done." (interactive "p") (gnus-group-next-unread-group (- n))) @@ -4089,7 +5514,7 @@ Returns the difference between N and the number of skips actually done." (interactive "p") (gnus-group-next-unread-group n t (gnus-group-group-level)) - (gnus-group-position-cursor)) + (gnus-group-position-point)) (defun gnus-group-prev-unread-group-same-level (n) "Go to next N'th unread newsgroup on the same level. @@ -4097,7 +5522,7 @@ Returns the difference between N and the number of skips actually done." (interactive "p") (gnus-group-next-unread-group (- n) t (gnus-group-group-level)) - (gnus-group-position-cursor)) + (gnus-group-position-point)) (defun gnus-group-best-unread-group (&optional exclude-group) "Go to the group with the highest level. @@ -4106,18 +5531,20 @@ If EXCLUDE-GROUP, do not go to that group." (goto-char (point-min)) (let ((best 100000) unread best-point) - (while (setq unread (get-text-property (point) 'gnus-unread)) + (while (not (eobp)) + (setq unread (get-text-property (point) 'gnus-unread)) (if (and (numberp unread) (> unread 0)) (progn - (if (and (< (get-text-property (point) 'gnus-level) best) + (if (and (get-text-property (point) 'gnus-level) + (< (get-text-property (point) 'gnus-level) best) (or (not exclude-group) (not (equal exclude-group (gnus-group-group-name))))) - (progn + (progn (setq best (get-text-property (point) 'gnus-level)) (setq best-point (point)))))) (forward-line 1)) (if best-point (goto-char best-point)) - (gnus-summary-position-cursor) + (gnus-summary-position-point) (and best-point (gnus-group-group-name)))) (defun gnus-group-first-unread-group () @@ -4128,74 +5555,155 @@ If EXCLUDE-GROUP, do not go to that group." unread) (goto-char (point-min)) (if (or (eq (setq unread (gnus-group-group-unread)) t) ; Not active. - (not (zerop unread)) ; Has unread articles. + (and (numberp unread) ; Not a topic. + (not (zerop unread))) ; Has unread articles. (zerop (gnus-group-next-unread-group 1))) ; Next unread group. (point) ; Success. (goto-char opoint) nil)) ; Not success. - (gnus-group-position-cursor))) + (gnus-group-position-point))) (defun gnus-group-enter-server-mode () "Jump to the server buffer." (interactive) - (gnus-server-setup-buffer) - (gnus-configure-windows 'server) - (gnus-server-prepare)) + (gnus-enter-server-buffer)) (defun gnus-group-make-group (name &optional method address) "Add a new newsgroup. The user will be prompted for a NAME, for a select METHOD, and an ADDRESS." (interactive - (cons + (cons (read-string "Group name: ") (let ((method - (completing-read + (completing-read "Method: " (append gnus-valid-select-methods gnus-server-alist) - nil t))) - (if (assoc method gnus-valid-select-methods) - (list method - (if (memq 'prompt-address - (assoc method gnus-valid-select-methods)) - (read-string "Address: ") - "")) - (list method nil))))) - - (let* ((meth (and method (if address (list (intern method) address) method))) + nil t nil 'gnus-method-history))) + (cond ((assoc method gnus-valid-select-methods) + (list method + (if (memq 'prompt-address + (assoc method gnus-valid-select-methods)) + (read-string "Address: ") + ""))) + ((assoc method gnus-server-alist) + (list method)) + (t + (list method "")))))) + + (let* ((meth (and method (if address (list (intern method) address) + method))) (nname (if method (gnus-group-prefixed-name name meth) name)) - info) - (and (gnus-gethash nname gnus-newsrc-hashtb) - (error "Group %s already exists" nname)) - (gnus-group-change-level + backend info) + (when (gnus-gethash nname gnus-newsrc-hashtb) + (error "Group %s already exists" nname)) + ;; Subscribe to the new group. + (gnus-group-change-level (setq info (list t nname gnus-level-default-subscribed nil nil meth)) - gnus-level-default-subscribed gnus-level-killed + gnus-level-default-subscribed gnus-level-killed (and (gnus-group-group-name) (gnus-gethash (gnus-group-group-name) gnus-newsrc-hashtb)) t) - (gnus-sethash nname (cons 1 0) gnus-active-hashtb) + ;; Make it active. + (gnus-set-active nname (cons 1 0)) (or (gnus-ephemeral-group-p name) - (gnus-dribble-enter + (gnus-dribble-enter (concat "(gnus-group-set-info '" (prin1-to-string (cdr info)) ")"))) + ;; Insert the line. (gnus-group-insert-group-line-info nname) - - (if (assoc method gnus-valid-select-methods) - (require (intern method))) + (forward-line -1) + (gnus-group-position-point) + + ;; Load the backend and try to make the backend create + ;; the group as well. + (when (assoc (symbol-name (setq backend (car (gnus-server-get-method + nil meth)))) + gnus-valid-select-methods) + (require backend)) + (gnus-check-server meth) (and (gnus-check-backend-function 'request-create-group nname) - (gnus-request-create-group nname)))) + (gnus-request-create-group nname)) + t)) + +(defun gnus-group-delete-group (group &optional force) + "Delete the current group. Only meaningful with mail groups. +If FORCE (the prefix) is non-nil, all the articles in the group will +be deleted. This is \"deleted\" as in \"removed forever from the face +of the Earth\". There is no undo. The user will be prompted before +doing the deletion." + (interactive + (list (gnus-group-group-name) + current-prefix-arg)) + (or group (error "No group to rename")) + (or (gnus-check-backend-function 'request-delete-group group) + (error "This backend does not support group deletion")) + (prog1 + (if (not (gnus-yes-or-no-p + (format + "Do you really want to delete %s%s? " + group (if force " and all its contents" "")))) + () ; Whew! + (gnus-message 6 "Deleting group %s..." group) + (if (not (gnus-request-delete-group group force)) + (gnus-error 3 "Couldn't delete group %s" group) + (gnus-message 6 "Deleting group %s...done" group) + (gnus-group-goto-group group) + (gnus-group-kill-group 1 t) + (gnus-sethash group nil gnus-active-hashtb) + t)) + (gnus-group-position-point))) + +(defun gnus-group-rename-group (group new-name) + (interactive + (list + (gnus-group-group-name) + (progn + (or (gnus-check-backend-function + 'request-rename-group (gnus-group-group-name)) + (error "This backend does not support renaming groups")) + (read-string "New group name: ")))) + + (or (gnus-check-backend-function 'request-rename-group group) + (error "This backend does not support renaming groups")) + + (or group (error "No group to rename")) + (and (string-match "^[ \t]*$" new-name) + (error "Not a valid group name")) + + ;; We find the proper prefixed name. + (setq new-name + (gnus-group-prefixed-name + (gnus-group-real-name new-name) + (gnus-info-method (gnus-get-info group)))) + + (gnus-message 6 "Renaming group %s to %s..." group new-name) + (prog1 + (if (not (gnus-request-rename-group group new-name)) + (gnus-error 3 "Couldn't rename group %s to %s" group new-name) + ;; We rename the group internally by killing it... + (gnus-group-goto-group group) + (gnus-group-kill-group) + ;; ... changing its name ... + (setcar (cdar gnus-list-of-killed-groups) new-name) + ;; ... and then yanking it. Magic! + (gnus-group-yank-group) + (gnus-set-active new-name (gnus-active group)) + (gnus-message 6 "Renaming group %s to %s...done" group new-name) + new-name) + (gnus-group-position-point))) (defun gnus-group-edit-group (group &optional part) "Edit the group on the current line." (interactive (list (gnus-group-group-name))) - (let ((done-func '(lambda () - "Exit editing mode and update the information." - (interactive) - (gnus-group-edit-group-done 'part 'group))) - (part (or part 'info)) - (winconf (current-window-configuration)) - info) + (let* ((part (or part 'info)) + (done-func `(lambda () + "Exit editing mode and update the information." + (interactive) + (gnus-group-edit-group-done ',part ,group))) + (winconf (current-window-configuration)) + info) (or group (error "No group on current line")) - (or (setq info (nth 2 (gnus-gethash group gnus-newsrc-hashtb))) + (or (setq info (gnus-get-info group)) (error "Killed group; can't be edited")) (set-buffer (get-buffer-create gnus-group-edit-buffer)) (gnus-configure-windows 'edit-group) @@ -4206,39 +5714,23 @@ ADDRESS." (local-set-key "\C-c\C-c" done-func) (make-local-variable 'gnus-prev-winconf) (setq gnus-prev-winconf winconf) - ;; We modify the func to let it know what part it is editing. - (setcar (cdr (nth 4 done-func)) (list 'quote part)) - (setcar (cdr (cdr (nth 4 done-func))) group) (erase-buffer) (insert - (cond + (cond ((eq part 'method) ";; Type `C-c C-c' after editing the select method.\n\n") ((eq part 'params) ";; Type `C-c C-c' after editing the group parameters.\n\n") ((eq part 'info) ";; Type `C-c C-c' after editing the group info.\n\n"))) - (let ((cinfo (gnus-copy-sequence info)) - marked) - (if (not (setq marked (nth 3 cinfo))) - () - (while marked - (or (eq 'score (car (car marked))) - (eq 'bookmark (car (car marked))) - (eq 'killed (car (car marked))) - (not (numberp (car (cdr (car marked))))) - (setcdr (car marked) - (gnus-compress-sequence (sort (cdr (car marked)) '<) t))) - (setq marked (cdr marked)))) - (insert - (pp-to-string - (cond ((eq part 'method) - (or (nth 4 info) "native")) - ((eq part 'params) - (nth 5 info)) - (t - cinfo))) - "\n")))) + (insert + (pp-to-string + (cond ((eq part 'method) + (or (gnus-info-method info) "native")) + ((eq part 'params) + (gnus-info-params info)) + (t info))) + "\n"))) (defun gnus-group-edit-group-method (group) "Edit the select method of GROUP." @@ -4254,91 +5746,139 @@ ADDRESS." "Get info from buffer, update variables and jump to the group buffer." (set-buffer (get-buffer-create gnus-group-edit-buffer)) (goto-char (point-min)) - (let ((form (read (current-buffer))) - (winconf gnus-prev-winconf)) - (if (eq part 'info) - (gnus-group-set-info form) - (gnus-group-set-info form group part)) + (let* ((form (read (current-buffer))) + (winconf gnus-prev-winconf) + (method (cond ((eq part 'info) (nth 4 form)) + ((eq part 'method) form) + (t nil))) + (info (cond ((eq part 'info) form) + ((eq part 'method) (gnus-get-info group)) + (t nil))) + (new-group (if info + (if (or (not method) + (gnus-server-equal + gnus-select-method method)) + (gnus-group-real-name (car info)) + (gnus-group-prefixed-name + (gnus-group-real-name (car info)) method)) + nil))) + (when (and new-group + (not (equal new-group group))) + (when (gnus-group-goto-group group) + (gnus-group-kill-group 1)) + (gnus-activate-group new-group)) + ;; Set the info. + (if (and info new-group) + (progn + (setq info (gnus-copy-sequence info)) + (setcar info new-group) + (unless (gnus-server-equal method "native") + (unless (nthcdr 3 info) + (nconc info (list nil nil))) + (unless (nthcdr 4 info) + (nconc info (list nil))) + (gnus-info-set-method info method)) + (gnus-group-set-info info)) + (gnus-group-set-info form (or new-group group) part)) (kill-buffer (current-buffer)) (and winconf (set-window-configuration winconf)) (set-buffer gnus-group-buffer) - (gnus-group-update-group (gnus-group-group-name)) - (gnus-group-position-cursor))) + (gnus-group-update-group (or new-group group)) + (gnus-group-position-point))) (defun gnus-group-make-help-group () "Create the Gnus documentation group." (interactive) - (let ((path (if installation-directory - (cons (concat installation-directory "etc/") load-path) - (cons data-directory load-path))) + (let ((path load-path) (name (gnus-group-prefixed-name "gnus-help" '(nndoc "gnus-help"))) - file) + file dir) (and (gnus-gethash name gnus-newsrc-hashtb) (error "Documentation group already exists")) - (while (and path - (not (file-exists-p - (setq file (concat (file-name-as-directory (car path)) - "gnus-tut.txt"))))) - (setq path (cdr path))) - (if (not path) - (message "Couldn't find doc group") - (gnus-group-make-group + (while path + (setq dir (file-name-as-directory (expand-file-name (pop path))) + file nil) + (when (or (file-exists-p (setq file (concat dir "gnus-tut.txt"))) + (file-exists-p + (setq file (concat (file-name-directory + (directory-file-name dir)) + "etc/gnus-tut.txt")))) + (setq path nil))) + (if (not file) + (gnus-message 1 "Couldn't find doc group") + (gnus-group-make-group (gnus-group-real-name name) - (list 'nndoc name + (list 'nndoc "gnus-help" (list 'nndoc-address file) (list 'nndoc-article-type 'mbox))))) - (gnus-group-position-cursor)) + (gnus-group-position-point)) (defun gnus-group-make-doc-group (file type) "Create a group that uses a single file as the source." - (interactive - (list (read-file-name "File name: ") - (let ((err "") - found char) - (while (not found) - (message "%sFile type (mbox, babyl, digest) [mbd]: " err) - (setq found (cond ((= (setq char (read-char)) ?m) 'mbox) - ((= char ?b) 'babyl) - ((= char ?d) 'digest) - (t (setq err (format "%c unknown. " char)) - nil)))) - found))) + (interactive + (list (read-file-name "File name: ") + (and current-prefix-arg 'ask))) + (when (eq type 'ask) + (let ((err "") + char found) + (while (not found) + (message + "%sFile type (mbox, babyl, digest, forward, mmfd, guess) [mbdfag]: " + err) + (setq found (cond ((= (setq char (read-char)) ?m) 'mbox) + ((= char ?b) 'babyl) + ((= char ?d) 'digest) + ((= char ?f) 'forward) + ((= char ?a) 'mmfd) + (t (setq err (format "%c unknown. " char)) + nil)))) + (setq type found))) (let* ((file (expand-file-name file)) (name (gnus-generate-new-group-name (gnus-group-prefixed-name (file-name-nondirectory file) '(nndoc ""))))) - (gnus-group-make-group + (gnus-group-make-group (gnus-group-real-name name) - (list 'nndoc name + (list 'nndoc (file-name-nondirectory file) (list 'nndoc-address file) - (list 'nndoc-article-type type))))) + (list 'nndoc-article-type (or type 'guess)))))) (defun gnus-group-make-archive-group (&optional all) "Create the (ding) Gnus archive group of the most recent articles. Given a prefix, create a full group." (interactive "P") - (let ((group (gnus-group-prefixed-name + (let ((group (gnus-group-prefixed-name (if all "ding.archives" "ding.recent") '(nndir "")))) (and (gnus-gethash group gnus-newsrc-hashtb) (error "Archive group already exists")) (gnus-group-make-group (gnus-group-real-name group) - "nndir" - (if all gnus-group-archive-directory - gnus-group-recent-archive-directory))) - (gnus-group-position-cursor)) + (list 'nndir (if all "hpc" "edu") + (list 'nndir-directory + (if all gnus-group-archive-directory + gnus-group-recent-archive-directory)))))) (defun gnus-group-make-directory-group (dir) "Create an nndir group. -The user will be prompted for a directory. The contents of this -directory will be used as a newsgroup. The directory should contain +The user will be prompted for a directory. The contents of this +directory will be used as a newsgroup. The directory should contain mail messages or news articles in files that have numeric names." (interactive (list (read-file-name "Create group from directory: "))) (or (file-exists-p dir) (error "No such directory")) (or (file-directory-p dir) (error "Not a directory")) - (gnus-group-make-group dir "nndir" dir) - (gnus-group-position-cursor)) + (let ((ext "") + (i 0) + group) + (while (or (not group) (gnus-gethash group gnus-newsrc-hashtb)) + (setq group + (gnus-group-prefixed-name + (concat (file-name-as-directory (directory-file-name dir)) + ext) + '(nndir ""))) + (setq ext (format "<%d>" (setq i (1+ i))))) + (gnus-group-make-group + (gnus-group-real-name group) + (list 'nndir group (list 'nndir-directory dir))))) (defun gnus-group-make-kiboze-group (group address scores) "Create an nnkiboze group. @@ -4350,26 +5890,22 @@ score file entries for articles to include in the group." (read-string "Source groups (regexp): ") (let ((headers (mapcar (lambda (group) (list group)) '("subject" "from" "number" "date" "message-id" - "references" "chars" "lines" "xref"))) + "references" "chars" "lines" "xref" + "followup" "all" "body" "head"))) scores header regexp regexps) - (while (not (equal "" (setq header (completing-read + (while (not (equal "" (setq header (completing-read "Match on header: " headers nil t)))) (setq regexps nil) - (while (not (equal "" (setq regexp (read-string + (while (not (equal "" (setq regexp (read-string (format "Match on %s (string): " header))))) (setq regexps (cons (list regexp nil nil 'r) regexps))) (setq scores (cons (cons header regexps) scores))) scores))) (gnus-group-make-group group "nnkiboze" address) - (save-excursion - (gnus-set-work-buffer) + (nnheader-temp-write (gnus-score-file-name (concat "nnkiboze:" group)) (let (emacs-lisp-mode-hook) - (pp scores (current-buffer))) - (write-region (point-min) (point-max) - (concat (or gnus-kill-files-directory "~/News") - "nnkiboze:" group "." gnus-score-file-suffix))) - (gnus-group-position-cursor)) + (pp scores (current-buffer))))) (defun gnus-group-add-to-virtual (n vgroup) "Add the current group to a virtual group." @@ -4380,16 +5916,16 @@ score file entries for articles to include in the group." (or (eq (car (gnus-find-method-for-group vgroup)) 'nnvirtual) (error "%s is not an nnvirtual group" vgroup)) (let* ((groups (gnus-group-process-prefix n)) - (method (nth 4 (nth 2 (gnus-gethash vgroup gnus-newsrc-hashtb))))) + (method (gnus-info-method (gnus-get-info vgroup)))) (setcar (cdr method) - (concat + (concat (nth 1 method) "\\|" - (mapconcat - (lambda (s) + (mapconcat + (lambda (s) (gnus-group-remove-mark s) (concat "\\(^" (regexp-quote s) "$\\)")) groups "\\|")))) - (gnus-group-position-cursor)) + (gnus-group-position-point)) (defun gnus-group-make-empty-virtual (group) "Create a new, fresh, empty virtual group." @@ -4403,7 +5939,7 @@ score file entries for articles to include in the group." (gnus-subscribe-group pgroup (gnus-group-group-name) method) (gnus-group-update-group pgroup) (forward-line -1) - (gnus-group-position-cursor))) + (gnus-group-position-point))) (defun gnus-group-enter-directory (dir) "Enter an ephemeral nneething group." @@ -4414,7 +5950,7 @@ score file entries for articles to include in the group." method)) (name (gnus-generate-new-group-name leaf))) (let ((nneething-read-only t)) - (or (gnus-group-read-ephemeral-group + (or (gnus-group-read-ephemeral-group name method t (cons (current-buffer) (if (eq major-mode 'gnus-summary-mode) 'summary 'group))) @@ -4423,36 +5959,128 @@ score file entries for articles to include in the group." ;; Group sorting commands ;; Suggested by Joe Hildebrand . -(defun gnus-group-sort-groups () - "Sort the group buffer using `gnus-group-sort-function'." - (interactive) - (setq gnus-newsrc-alist - (sort (cdr gnus-newsrc-alist) gnus-group-sort-function)) - (gnus-make-hashtable-from-newsrc-alist) - (gnus-group-list-groups)) +(defun gnus-group-sort-groups (func &optional reverse) + "Sort the group buffer according to FUNC. +If REVERSE, reverse the sorting order." + (interactive (list gnus-group-sort-function + current-prefix-arg)) + (let ((func (cond + ((not (listp func)) func) + ((null func) func) + ((= 1 (length func)) (car func)) + (t `(lambda (t1 t2) + ,(gnus-make-sort-function + (reverse func))))))) + ;; We peel off the dummy group from the alist. + (when func + (when (equal (car (gnus-info-group gnus-newsrc-alist)) "dummy.group") + (pop gnus-newsrc-alist)) + ;; Do the sorting. + (setq gnus-newsrc-alist + (sort gnus-newsrc-alist func)) + (when reverse + (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist))) + ;; Regenerate the hash table. + (gnus-make-hashtable-from-newsrc-alist) + (gnus-group-list-groups)))) + +(defun gnus-group-sort-groups-by-alphabet (&optional reverse) + "Sort the group buffer alphabetically by group name. +If REVERSE, sort in reverse order." + (interactive "P") + (gnus-group-sort-groups 'gnus-group-sort-by-alphabet reverse)) + +(defun gnus-group-sort-groups-by-unread (&optional reverse) + "Sort the group buffer by number of unread articles. +If REVERSE, sort in reverse order." + (interactive "P") + (gnus-group-sort-groups 'gnus-group-sort-by-unread reverse)) + +(defun gnus-group-sort-groups-by-level (&optional reverse) + "Sort the group buffer by group level. +If REVERSE, sort in reverse order." + (interactive "P") + (gnus-group-sort-groups 'gnus-group-sort-by-level reverse)) + +(defun gnus-group-sort-groups-by-score (&optional reverse) + "Sort the group buffer by group score. +If REVERSE, sort in reverse order." + (interactive "P") + (gnus-group-sort-groups 'gnus-group-sort-by-score reverse)) + +(defun gnus-group-sort-groups-by-rank (&optional reverse) + "Sort the group buffer by group rank. +If REVERSE, sort in reverse order." + (interactive "P") + (gnus-group-sort-groups 'gnus-group-sort-by-rank reverse)) + +(defun gnus-group-sort-groups-by-method (&optional reverse) + "Sort the group buffer alphabetically by backend name. +If REVERSE, sort in reverse order." + (interactive "P") + (gnus-group-sort-groups 'gnus-group-sort-by-method reverse)) (defun gnus-group-sort-by-alphabet (info1 info2) - (string< (car info1) (car info2))) + "Sort alphabetically." + (string< (gnus-info-group info1) (gnus-info-group info2))) (defun gnus-group-sort-by-unread (info1 info2) - (let ((n1 (car (gnus-gethash (car info1) gnus-newsrc-hashtb))) - (n2 (car (gnus-gethash (car info2) gnus-newsrc-hashtb)))) + "Sort by number of unread articles." + (let ((n1 (car (gnus-gethash (gnus-info-group info1) gnus-newsrc-hashtb))) + (n2 (car (gnus-gethash (gnus-info-group info2) gnus-newsrc-hashtb)))) (< (or (and (numberp n1) n1) 0) (or (and (numberp n2) n2) 0)))) (defun gnus-group-sort-by-level (info1 info2) - (< (nth 1 info1) (nth 1 info2))) + "Sort by level." + (< (gnus-info-level info1) (gnus-info-level info2))) + +(defun gnus-group-sort-by-method (info1 info2) + "Sort alphabetically by backend name." + (string< (symbol-name (car (gnus-find-method-for-group + (gnus-info-group info1) info1))) + (symbol-name (car (gnus-find-method-for-group + (gnus-info-group info2) info2))))) + +(defun gnus-group-sort-by-score (info1 info2) + "Sort by group score." + (< (gnus-info-score info1) (gnus-info-score info2))) + +(defun gnus-group-sort-by-rank (info1 info2) + "Sort by level and score." + (let ((level1 (gnus-info-level info1)) + (level2 (gnus-info-level info2))) + (or (< level1 level2) + (and (= level1 level2) + (> (gnus-info-score info1) (gnus-info-score info2)))))) ;; Group catching up. +(defun gnus-group-clear-data (n) + "Clear all marks and read ranges from the current group." + (interactive "P") + (let ((groups (gnus-group-process-prefix n)) + group info) + (while (setq group (pop groups)) + (setq info (gnus-get-info group)) + (gnus-info-set-read info nil) + (when (gnus-info-marks info) + (gnus-info-set-marks info nil)) + (gnus-get-unread-articles-in-group info (gnus-active group) t) + (when (gnus-group-goto-group group) + (gnus-group-remove-mark group) + (gnus-group-update-group-line))))) + (defun gnus-group-catchup-current (&optional n all) "Mark all articles not marked as unread in current newsgroup as read. If prefix argument N is numeric, the ARG next newsgroups will be -caught up. If ALL is non-nil, marked articles will also be marked as -read. Cross references (Xref: header) of articles are ignored. +caught up. If ALL is non-nil, marked articles will also be marked as +read. Cross references (Xref: header) of articles are ignored. The difference between N and actual number of newsgroups that were caught up is returned." (interactive "P") + (unless (gnus-group-group-name) + (error "No group on the current line")) (if (not (or (not gnus-interactive-catchup) ;Without confirmation? gnus-expert-user (gnus-y-or-n-p @@ -4463,17 +6091,19 @@ caught up is returned." (let ((groups (gnus-group-process-prefix n)) (ret 0)) (while groups - ;; Virtual groups have to be given special treatment. + ;; Virtual groups have to be given special treatment. (let ((method (gnus-find-method-for-group (car groups)))) (if (eq 'nnvirtual (car method)) (nnvirtual-catchup-group (gnus-group-real-name (car groups)) (nth 1 method) all))) (gnus-group-remove-mark (car groups)) - (if (prog1 - (gnus-group-goto-group (car groups)) - (gnus-group-catchup (car groups) all)) - (gnus-group-update-group-line) - (setq ret (1+ ret))) + (if (>= (gnus-group-group-level) gnus-level-zombie) + (gnus-message 2 "Dead groups can't be caught up") + (if (prog1 + (gnus-group-goto-group (car groups)) + (gnus-group-catchup (car groups) all)) + (gnus-group-update-group-line) + (setq ret (1+ ret)))) (setq groups (cdr groups))) (gnus-group-next-unread-group 1) ret))) @@ -4490,73 +6120,101 @@ If ALL is non-nil, all articles are marked as read. The return value is the number of articles that were marked as read, or nil if no action could be taken." (let* ((entry (gnus-gethash group gnus-newsrc-hashtb)) - (num (car entry)) - (marked (nth 3 (nth 2 entry)))) + (num (car entry))) + ;; Do the updating only if the newsgroup isn't killed. (if (not (numberp (car entry))) (gnus-message 1 "Can't catch up; non-active group") - ;; Do the updating only if the newsgroup isn't killed. - (if (not entry) - () - (gnus-update-read-articles - group (and (not all) (append (cdr (assq 'tick marked)) - (cdr (assq 'dormant marked)))) - nil (and (not all) (cdr (assq 'tick marked)))) - (and all - (setq marked (nth 3 (nth 2 entry))) - (setcar (nthcdr 3 (nth 2 entry)) - (delq (assq 'dormant marked) - (nth 3 (nth 2 entry))))))) - num)) + ;; Do auto-expirable marks if that's required. + (when (gnus-group-auto-expirable-p group) + (gnus-add-marked-articles + group 'expire (gnus-list-of-unread-articles group)) + (when all + (let ((marks (nth 3 (nth 2 entry)))) + (gnus-add-marked-articles + group 'expire (gnus-uncompress-range (cdr (assq 'tick marks)))) + (gnus-add-marked-articles + group 'expire (gnus-uncompress-range (cdr (assq 'tick marks))))))) + (when entry + (gnus-update-read-articles group nil) + ;; Also nix out the lists of marks and dormants. + (when all + (gnus-add-marked-articles group 'tick nil nil 'force) + (gnus-add-marked-articles group 'dormant nil nil 'force)) + (run-hooks 'gnus-group-catchup-group-hook) + num)))) (defun gnus-group-expire-articles (&optional n) "Expire all expirable articles in the current newsgroup." (interactive "P") (let ((groups (gnus-group-process-prefix n)) group) - (or groups (error "No groups to expire")) - (while groups - (setq group (car groups) - groups (cdr groups)) + (unless groups + (error "No groups to expire")) + (while (setq group (pop groups)) (gnus-group-remove-mark group) - (if (not (gnus-check-backend-function 'request-expire-articles group)) - () - (let* ((info (nth 2 (gnus-gethash group gnus-newsrc-hashtb))) - (expirable (if (memq 'total-expire (nth 5 info)) + (when (gnus-check-backend-function 'request-expire-articles group) + (gnus-message 6 "Expiring articles in %s..." group) + (let* ((info (gnus-get-info group)) + (expirable (if (gnus-group-total-expirable-p group) (cons nil (gnus-list-of-read-articles group)) - (assq 'expire (nth 3 info))))) - (and expirable - (setcdr expirable - (gnus-request-expire-articles - (cdr expirable) group)))))))) + (assq 'expire (gnus-info-marks info)))) + (expiry-wait (gnus-group-get-parameter group 'expiry-wait))) + (when expirable + (setcdr + expirable + (gnus-compress-sequence + (if expiry-wait + ;; We set the expiry variables to the groupp + ;; parameter. + (let ((nnmail-expiry-wait-function nil) + (nnmail-expiry-wait expiry-wait)) + (gnus-request-expire-articles + (gnus-uncompress-sequence (cdr expirable)) group)) + ;; Just expire using the normal expiry values. + (gnus-request-expire-articles + (gnus-uncompress-sequence (cdr expirable)) group)))) + (gnus-close-group group)) + (gnus-message 6 "Expiring articles in %s...done" group))) + (gnus-group-position-point)))) (defun gnus-group-expire-all-groups () "Expire all expirable articles in all newsgroups." (interactive) (save-excursion (gnus-message 5 "Expiring...") - (let ((gnus-group-marked (mapcar (lambda (info) (car info)) + (let ((gnus-group-marked (mapcar (lambda (info) (gnus-info-group info)) (cdr gnus-newsrc-alist)))) (gnus-group-expire-articles nil))) - (gnus-group-position-cursor) + (gnus-group-position-point) (gnus-message 5 "Expiring...done")) (defun gnus-group-set-current-level (n level) "Set the level of the next N groups to LEVEL." - (interactive "P\nnLevel: ") + (interactive + (list + current-prefix-arg + (string-to-int + (let ((s (read-string + (format "Level (default %s): " + (or (gnus-group-group-level) + gnus-level-default-subscribed))))) + (if (string-match "^\\s-*$" s) + (int-to-string (or (gnus-group-group-level) + gnus-level-default-subscribed)) + s))))) (or (and (>= level 1) (<= level gnus-level-killed)) (error "Illegal level: %d" level)) (let ((groups (gnus-group-process-prefix n)) group) - (while groups - (setq group (car groups) - groups (cdr groups)) + (while (setq group (pop groups)) (gnus-group-remove-mark group) - (gnus-message 6 "Changed level of %s from %d to %d" - group (gnus-group-group-level) level) - (gnus-group-change-level group level - (gnus-group-group-level)) + (gnus-message 6 "Changed level of %s from %d to %d" + group (or (gnus-group-group-level) gnus-level-killed) + level) + (gnus-group-change-level + group level (or (gnus-group-group-level) gnus-level-killed)) (gnus-group-update-group-line))) - (gnus-group-position-cursor)) + (gnus-group-position-point)) (defun gnus-group-unsubscribe-current-group (&optional n) "Toggle subscription of the current group. @@ -4571,49 +6229,54 @@ If given numerical prefix, toggle the N next groups." (gnus-group-unsubscribe-group group (if (<= (gnus-group-group-level) gnus-level-subscribed) gnus-level-default-unsubscribed - gnus-level-default-subscribed)) + gnus-level-default-subscribed) t) (gnus-group-update-group-line)) (gnus-group-next-group 1))) -(defun gnus-group-unsubscribe-group (group &optional level) - "Toggle subscribe from/to unsubscribe GROUP. -New newsgroup is added to .newsrc automatically." +(defun gnus-group-unsubscribe-group (group &optional level silent) + "Toggle subscription to GROUP. +Killed newsgroups are subscribed. If SILENT, don't try to update the +group line." (interactive (list (completing-read - "Group: " gnus-active-hashtb nil - (memq gnus-select-method gnus-have-read-active-file)))) + "Group: " gnus-active-hashtb nil + (gnus-read-active-file-p) + nil + 'gnus-group-history))) (let ((newsrc (gnus-gethash group gnus-newsrc-hashtb))) (cond ((string-match "^[ \t]$" group) (error "Empty group name")) (newsrc ;; Toggle subscription flag. - (gnus-group-change-level - newsrc (if level level (if (<= (nth 1 (nth 2 newsrc)) - gnus-level-subscribed) + (gnus-group-change-level + newsrc (if level level (if (<= (nth 1 (nth 2 newsrc)) + gnus-level-subscribed) (1+ gnus-level-subscribed) gnus-level-default-subscribed))) - (gnus-group-update-group group)) + (unless silent + (gnus-group-update-group group))) ((and (stringp group) - (or (not (memq gnus-select-method gnus-have-read-active-file)) - (gnus-gethash group gnus-active-hashtb))) + (or (not (gnus-read-active-file-p)) + (gnus-active group))) ;; Add new newsgroup. - (gnus-group-change-level - group - (if level level gnus-level-default-subscribed) - (or (and (member group gnus-zombie-list) - gnus-level-zombie) + (gnus-group-change-level + group + (if level level gnus-level-default-subscribed) + (or (and (member group gnus-zombie-list) + gnus-level-zombie) gnus-level-killed) (and (gnus-group-group-name) (gnus-gethash (gnus-group-group-name) gnus-newsrc-hashtb))) - (gnus-group-update-group group)) + (unless silent + (gnus-group-update-group group))) (t (error "No such newsgroup: %s" group))) - (gnus-group-position-cursor))) + (gnus-group-position-point))) (defun gnus-group-transpose-groups (n) "Move the current newsgroup up N places. -If given a negative prefix, move down instead. The difference between -N and the number of steps taken is returned." +If given a negative prefix, move down instead. The difference between +N and the number of steps taken is returned." (interactive "p") (or (gnus-group-group-name) (error "No group on current line")) @@ -4621,7 +6284,7 @@ N and the number of steps taken is returned." (prog1 (forward-line (- n)) (gnus-group-yank-group) - (gnus-group-position-cursor))) + (gnus-group-position-point))) (defun gnus-group-kill-all-zombies () "Kill all zombie newsgroups." @@ -4650,59 +6313,109 @@ The killed newsgroups can be yanked by using \\[gnus-group-yank-group]." (beginning-of-line) ;Important when LINES < 1 (gnus-group-kill-group lines))) -(defun gnus-group-kill-group (&optional n) - "The the next N groups. +(defun gnus-group-kill-group (&optional n discard) + "Kill the next N groups. The killed newsgroups can be yanked by using \\[gnus-group-yank-group]. -However, only groups that were alive can be yanked; already killed +However, only groups that were alive can be yanked; already killed groups or zombie groups can't be yanked. -The return value is the name of the (last) group that was killed." +The return value is the name of the group that was killed, or a list +of groups killed." (interactive "P") (let ((buffer-read-only nil) (groups (gnus-group-process-prefix n)) - group entry level) - (while groups - (setq group (car groups) - groups (cdr groups)) - (gnus-group-remove-mark group) - (setq level (gnus-group-group-level)) - (gnus-delete-line) - (if (setq entry (gnus-gethash group gnus-newsrc-hashtb)) - (setq gnus-list-of-killed-groups - (cons (cons (car entry) (nth 2 entry)) - gnus-list-of-killed-groups))) - (gnus-group-change-level - (if entry entry group) gnus-level-killed (if entry nil level))) - (gnus-group-position-cursor) - group)) + group entry level out) + (if (< (length groups) 10) + ;; This is faster when there are few groups. + (while groups + (push (setq group (pop groups)) out) + (gnus-group-remove-mark group) + (setq level (gnus-group-group-level)) + (gnus-delete-line) + (when (and (not discard) + (setq entry (gnus-gethash group gnus-newsrc-hashtb))) + (push (cons (car entry) (nth 2 entry)) + gnus-list-of-killed-groups)) + (gnus-group-change-level + (if entry entry group) gnus-level-killed (if entry nil level))) + ;; If there are lots and lots of groups to be killed, we use + ;; this thing instead. + (let (entry) + (setq groups (nreverse groups)) + (while groups + (gnus-group-remove-mark (setq group (pop groups))) + (gnus-delete-line) + (push group gnus-killed-list) + (setq gnus-newsrc-alist + (delq (assoc group gnus-newsrc-alist) + gnus-newsrc-alist)) + (when gnus-group-change-level-function + (funcall gnus-group-change-level-function group 9 3)) + (cond + ((setq entry (gnus-gethash group gnus-newsrc-hashtb)) + (push (cons (car entry) (nth 2 entry)) + gnus-list-of-killed-groups) + (setcdr (cdr entry) (cdddr entry))) + ((member group gnus-zombie-list) + (setq gnus-zombie-list (delete group gnus-zombie-list))))) + (gnus-make-hashtable-from-newsrc-alist))) + + (gnus-group-position-point) + (if (< (length out) 2) (car out) (nreverse out)))) (defun gnus-group-yank-group (&optional arg) "Yank the last newsgroups killed with \\[gnus-group-kill-group], inserting it before the current newsgroup. The numeric ARG specifies -how many newsgroups are to be yanked. The name of the (last) -newsgroup yanked is returned." +how many newsgroups are to be yanked. The name of the newsgroup yanked +is returned, or (if several groups are yanked) a list of yanked groups +is returned." (interactive "p") - (if (not arg) (setq arg 1)) - (let (info group prev) - (while (>= (setq arg (1- arg)) 0) - (if (not (setq info (car gnus-list-of-killed-groups))) + (setq arg (or arg 1)) + (let (info group prev out) + (while (>= (decf arg) 0) + (if (not (setq info (pop gnus-list-of-killed-groups))) (error "No more newsgroups to yank")) - (setq group (nth 2 info)) + (push (setq group (nth 1 info)) out) ;; Find which newsgroup to insert this one before - search - ;; backward until something suitable is found. If there are no + ;; backward until something suitable is found. If there are no ;; other newsgroups in this buffer, just make this newsgroup the ;; first newsgroup. (setq prev (gnus-group-group-name)) - (gnus-group-change-level - info (nth 2 info) gnus-level-killed + (gnus-group-change-level + info (gnus-info-level (cdr info)) gnus-level-killed (and prev (gnus-gethash prev gnus-newsrc-hashtb)) t) - (gnus-group-insert-group-line-info (nth 1 info)) - (setq gnus-list-of-killed-groups - (cdr gnus-list-of-killed-groups))) + (gnus-group-insert-group-line-info group)) (forward-line -1) - (gnus-group-position-cursor) - group)) - + (gnus-group-position-point) + (if (< (length out) 2) (car out) (nreverse out)))) + +(defun gnus-group-kill-level (level) + "Kill all groups that is on a certain LEVEL." + (interactive "nKill all groups on level: ") + (cond + ((= level gnus-level-zombie) + (setq gnus-killed-list + (nconc gnus-zombie-list gnus-killed-list)) + (setq gnus-zombie-list nil)) + ((and (< level gnus-level-zombie) + (> level 0) + (or gnus-expert-user + (gnus-yes-or-no-p + (format + "Do you really want to kill all groups on level %d? " + level)))) + (let* ((prev gnus-newsrc-alist) + (alist (cdr prev))) + (while alist + (if (= (gnus-info-level level) level) + (setcdr prev (cdr alist)) + (setq prev alist)) + (setq alist (cdr alist))) + (gnus-make-hashtable-from-newsrc-alist) + (gnus-group-list-groups))) + (t + (error "Can't kill; illegal level: %d" level)))) + (defun gnus-group-list-all-groups (&optional arg) "List all newsgroups with level ARG or lower. Default is gnus-level-unsubscribed, which lists all subscribed and most @@ -4710,16 +6423,23 @@ unsubscribed groups." (interactive "P") (gnus-group-list-groups (or arg gnus-level-unsubscribed) t)) -(defun gnus-group-list-killed () - "List all killed newsgroups in the group buffer." - (interactive) +;; Redefine this to list ALL killed groups if prefix arg used. +;; Rewritten by engstrom@src.honeywell.com (Eric Engstrom). +(defun gnus-group-list-killed (&optional arg) + "List all killed newsgroups in the group buffer. +If ARG is non-nil, list ALL killed groups known to Gnus. This may +entail asking the server for the groups." + (interactive "P") + ;; Find all possible killed newsgroups if arg. + (when arg + (gnus-get-killed-groups)) (if (not gnus-killed-list) (gnus-message 6 "No killed groups") (let (gnus-group-list-mode) - (funcall gnus-group-prepare-function + (funcall gnus-group-prepare-function gnus-level-killed t gnus-level-killed)) (goto-char (point-min))) - (gnus-group-position-cursor)) + (gnus-group-position-point)) (defun gnus-group-list-zombies () "List all zombie newsgroups in the group buffer." @@ -4730,21 +6450,65 @@ unsubscribed groups." (funcall gnus-group-prepare-function gnus-level-zombie t gnus-level-zombie)) (goto-char (point-min))) - (gnus-group-position-cursor)) + (gnus-group-position-point)) -(defun gnus-group-get-new-news (&optional arg) - "Get newly arrived articles. -If ARG is non-nil, it should be a number between one and nine to -specify which levels you are interested in re-scanning." +(defun gnus-group-list-active () + "List all groups that are available from the server(s)." + (interactive) + ;; First we make sure that we have really read the active file. + (unless (gnus-read-active-file-p) + (let ((gnus-read-active-file t)) + (gnus-read-active-file))) + ;; Find all groups and sort them. + (let ((groups + (sort + (let (list) + (mapatoms + (lambda (sym) + (and (boundp sym) + (symbol-value sym) + (setq list (cons (symbol-name sym) list)))) + gnus-active-hashtb) + list) + 'string<)) + (buffer-read-only nil)) + (erase-buffer) + (while groups + (gnus-group-insert-group-line-info (pop groups))) + (goto-char (point-min)))) + +(defun gnus-activate-all-groups (level) + "Activate absolutely all groups." + (interactive (list 7)) + (let ((gnus-activate-level level) + (gnus-activate-foreign-newsgroups level)) + (gnus-group-get-new-news))) + +(defun gnus-group-get-new-news (&optional arg) + "Get newly arrived articles. +If ARG is a number, it specifies which levels you are interested in +re-scanning. If ARG is non-nil and not a number, this will force +\"hard\" re-reading of the active files from all servers." (interactive "P") (run-hooks 'gnus-get-new-news-hook) + ;; We might read in new NoCeM messages here. + (when (and gnus-use-nocem + (null arg)) + (gnus-nocem-scan-groups)) + ;; If ARG is not a number, then we read the active file. + (when (and arg (not (numberp arg))) + (let ((gnus-read-active-file t)) + (gnus-read-active-file)) + (setq arg nil)) + (setq arg (gnus-group-default-level arg t)) (if (and gnus-read-active-file (not arg)) (progn (gnus-read-active-file) - (gnus-get-unread-articles (or arg (1+ gnus-level-subscribed)))) + (gnus-get-unread-articles arg)) (let ((gnus-read-active-file (if arg nil gnus-read-active-file))) - (gnus-get-unread-articles (or arg (1+ gnus-level-subscribed))))) + (gnus-get-unread-articles arg))) + (run-hooks 'gnus-after-getting-new-news-hook) (gnus-group-list-groups)) (defun gnus-group-get-new-news-this-group (&optional n) @@ -4754,55 +6518,64 @@ If N is negative, this group and the N-1 previous groups will be checked." (interactive "P") (let* ((groups (gnus-group-process-prefix n)) (ret (if (numberp n) (- n (length groups)) 0)) + (beg (unless n (point))) group) - (while groups - (setq group (car groups) - groups (cdr groups)) + (while (setq group (pop groups)) (gnus-group-remove-mark group) - (or (gnus-get-new-news-in-group group) - (progn - (ding) - (message "%s error: %s" group (gnus-status-message group)) - (sit-for 2)))) - (gnus-group-next-unread-group 1 t) - (gnus-summary-position-cursor) + (if (gnus-activate-group group 'scan) + (progn + (gnus-get-unread-articles-in-group + (gnus-get-info group) (gnus-active group) t) + (unless (gnus-virtual-group-p group) + (gnus-close-group group)) + (gnus-group-update-group group)) + (gnus-error 3 "%s error: %s" group (gnus-status-message group)))) + (when beg (goto-char beg)) + (when gnus-goto-next-group-when-activating + (gnus-group-next-unread-group 1 t)) + (gnus-summary-position-point) ret)) -(defun gnus-get-new-news-in-group (group) - (and group - (gnus-activate-group group) - (progn - (gnus-get-unread-articles-in-group - (nth 2 (gnus-gethash group gnus-newsrc-hashtb)) - (gnus-gethash group gnus-active-hashtb)) - (gnus-group-update-group-line) - t))) - -(defun gnus-group-fetch-faq (group) +(defun gnus-group-fetch-faq (group &optional faq-dir) "Fetch the FAQ for the current group." - (interactive (list (gnus-group-real-name (gnus-group-group-name)))) + (interactive + (list + (and (gnus-group-group-name) + (gnus-group-real-name (gnus-group-group-name))) + (cond (current-prefix-arg + (completing-read + "Faq dir: " (and (listp gnus-group-faq-directory) + (mapcar (lambda (file) (list file)) + gnus-group-faq-directory))))))) + (or faq-dir + (setq faq-dir (if (listp gnus-group-faq-directory) + (car gnus-group-faq-directory) + gnus-group-faq-directory))) (or group (error "No group name given")) - (let ((file (concat gnus-group-faq-directory (gnus-group-real-name group)))) + (let ((file (concat (file-name-as-directory faq-dir) + (gnus-group-real-name group)))) (if (not (file-exists-p file)) (error "No such file: %s" file) (find-file file)))) - + (defun gnus-group-describe-group (force &optional group) "Display a description of the current newsgroup." (interactive (list current-prefix-arg (gnus-group-group-name))) - (and force (setq gnus-description-hashtb nil)) + (when (and force + gnus-description-hashtb) + (gnus-sethash group nil gnus-description-hashtb)) (let ((method (gnus-find-method-for-group group)) desc) (or group (error "No group name given")) (and (or (and gnus-description-hashtb ;; We check whether this group's method has been - ;; queried for a description file. - (gnus-gethash - (gnus-group-prefixed-name "" method) + ;; queried for a description file. + (gnus-gethash + (gnus-group-prefixed-name "" method) gnus-description-hashtb)) (setq desc (gnus-group-get-description group)) (gnus-read-descriptions-file method)) - (message + (gnus-message 1 (or desc (gnus-gethash group gnus-description-hashtb) "No description available"))))) @@ -4822,13 +6595,13 @@ If N is negative, this group and the N-1 previous groups will be checked." (setq b (point)) (insert (format " *: %-20s %s\n" (symbol-name group) (symbol-value group))) - (add-text-properties + (gnus-add-text-properties b (1+ b) (list 'gnus-group group 'gnus-unread t 'gnus-marked nil 'gnus-level (1+ gnus-level-subscribed)))) gnus-description-hashtb) (goto-char (point-min)) - (gnus-group-position-cursor))) + (gnus-group-position-point))) ;; Suggested by by Daniel Quinlan . (defun gnus-group-apropos (regexp &optional search-description) @@ -4838,20 +6611,20 @@ If N is negative, this group and the N-1 previous groups will be checked." (obuf (current-buffer)) groups des) ;; Go through all newsgroups that are known to Gnus. - (mapatoms + (mapatoms (lambda (group) (and (symbol-name group) (string-match regexp (symbol-name group)) (setq groups (cons (symbol-name group) groups)))) gnus-active-hashtb) - ;; Go through all descriptions that are known to Gnus. - (if search-description - (mapatoms - (lambda (group) - (and (string-match regexp (symbol-value group)) - (gnus-gethash (symbol-name group) gnus-active-hashtb) - (setq groups (cons (symbol-name group) groups)))) - gnus-description-hashtb)) + ;; Also go through all descriptions that are known to Gnus. + (when search-description + (mapatoms + (lambda (group) + (and (string-match regexp (symbol-value group)) + (gnus-active (symbol-name group)) + (setq groups (cons (symbol-name group) groups)))) + gnus-description-hashtb)) (if (not groups) (gnus-message 3 "No groups matched \"%s\"." regexp) ;; Print out all the groups. @@ -4866,7 +6639,7 @@ If N is negative, this group and the N-1 previous groups will be checked." (progn (insert (setq prev (car groups)) "\n") (if (and gnus-description-hashtb - (setq des (gnus-gethash (car groups) + (setq des (gnus-gethash (car groups) gnus-description-hashtb))) (insert " " des "\n")))) (setq groups (cdr groups))) @@ -4882,38 +6655,48 @@ If N is negative, this group and the N-1 previous groups will be checked." (gnus-group-apropos regexp t)) ;; Suggested by Per Abrahamsen . -(defun gnus-group-list-matching (level regexp &optional all lowest) +(defun gnus-group-list-matching (level regexp &optional all lowest) "List all groups with unread articles that match REGEXP. If the prefix LEVEL is non-nil, it should be a number that says which -level to cut off listing groups. +level to cut off listing groups. If ALL, also list groups with no unread articles. -If LOWEST, don't list groups with level lower than LOWEST." +If LOWEST, don't list groups with level lower than LOWEST. + +This command may read the active file." (interactive "P\nsList newsgroups matching: ") + ;; First make sure active file has been read. + (when (and level + (> (prefix-numeric-value level) gnus-level-killed)) + (gnus-get-killed-groups)) (gnus-group-prepare-flat (or level gnus-level-subscribed) all (or lowest 1) regexp) (goto-char (point-min)) - (gnus-group-position-cursor)) + (gnus-group-position-point)) -(defun gnus-group-list-all-matching (level regexp &optional lowest) +(defun gnus-group-list-all-matching (level regexp &optional lowest) "List all groups that match REGEXP. If the prefix LEVEL is non-nil, it should be a number that says which -level to cut off listing groups. +level to cut off listing groups. If LOWEST, don't list groups with level lower than LOWEST." (interactive "P\nsList newsgroups matching: ") (gnus-group-list-matching (or level gnus-level-killed) regexp t lowest)) ;; Suggested by Jack Vinson . -(defun gnus-group-save-newsrc () - "Save the Gnus startup files." - (interactive) - (gnus-save-newsrc-file)) +(defun gnus-group-save-newsrc (&optional force) + "Save the Gnus startup files. +If FORCE, force saving whether it is necessary or not." + (interactive "P") + (gnus-save-newsrc-file force)) (defun gnus-group-restart (&optional arg) "Force Gnus to read the .newsrc file." (interactive "P") - (gnus-save-newsrc-file) - (gnus-setup-news 'force) - (gnus-group-list-groups arg)) + (when (gnus-yes-or-no-p + (format "Are you sure you want to read %s? " + gnus-current-startup-file)) + (gnus-save-newsrc-file) + (gnus-setup-news 'force) + (gnus-group-list-groups arg))) (defun gnus-group-read-init-file () "Read the Gnus elisp init file." @@ -4934,10 +6717,11 @@ If GROUP, edit that local kill file instead." (interactive "P") (setq gnus-current-kill-article article) (gnus-kill-file-edit-file group) - (gnus-message + (gnus-message 6 (substitute-command-keys - "Editing a global kill file (Type \\[gnus-kill-file-exit] to exit)"))) + (format "Editing a %s kill file (Type \\[gnus-kill-file-exit] to exit)" + (if group "local" "global"))))) (defun gnus-group-edit-local-kill (article group) "Edit a local kill file." @@ -4956,51 +6740,52 @@ The hook gnus-suspend-gnus-hook is called before actually suspending." (interactive) (run-hooks 'gnus-suspend-gnus-hook) ;; Kill Gnus buffers except for group mode buffer. - (let ((group-buf (get-buffer gnus-group-buffer))) - ;; Do this on a separate list in case the user does a ^G before we finish - (let ((gnus-buffer-list - (delq group-buf (delq gnus-dribble-buffer - (append gnus-buffer-list nil))))) - (while gnus-buffer-list - (gnus-kill-buffer (car gnus-buffer-list)) - (setq gnus-buffer-list (cdr gnus-buffer-list)))) - (if group-buf - (progn - (setq gnus-buffer-list (list group-buf)) - (bury-buffer group-buf) - (delete-windows-on group-buf t))))) + (let* ((group-buf (get-buffer gnus-group-buffer)) + ;; Do this on a separate list in case the user does a ^G before we finish + (gnus-buffer-list + (delete group-buf (delete gnus-dribble-buffer + (append gnus-buffer-list nil))))) + (while gnus-buffer-list + (gnus-kill-buffer (pop gnus-buffer-list))) + (gnus-kill-gnus-frames) + (when group-buf + (setq gnus-buffer-list (list group-buf)) + (bury-buffer group-buf) + (delete-windows-on group-buf t)))) (defun gnus-group-clear-dribble () "Clear all information from the dribble buffer." (interactive) - (gnus-dribble-clear)) + (gnus-dribble-clear) + (gnus-message 7 "Cleared dribble buffer")) (defun gnus-group-exit () "Quit reading news after updating .newsrc.eld and .newsrc. The hook `gnus-exit-gnus-hook' is called before actually exiting." (interactive) - (if (or noninteractive ;For gnus-batch-kill - (not (gnus-server-opened gnus-select-method)) ;NNTP connection closed + (when + (or noninteractive ;For gnus-batch-kill (not gnus-interactive-exit) ;Without confirmation gnus-expert-user (gnus-y-or-n-p "Are you sure you want to quit reading news? ")) - (progn - (run-hooks 'gnus-exit-gnus-hook) - ;; Offer to save data from non-quitted summary buffers. - (gnus-offer-save-summaries) - ;; Save the newsrc file(s). - (gnus-save-newsrc-file) - ;; Kill-em-all. - (gnus-close-backends) - ;; Reset everything. - (gnus-clear-system)))) + (run-hooks 'gnus-exit-gnus-hook) + ;; Offer to save data from non-quitted summary buffers. + (gnus-offer-save-summaries) + ;; Save the newsrc file(s). + (gnus-save-newsrc-file) + ;; Kill-em-all. + (gnus-close-backends) + ;; Reset everything. + (gnus-clear-system) + ;; Allow the user to do things after cleaning up. + (run-hooks 'gnus-after-exiting-gnus-hook))) (defun gnus-close-backends () - ;; Send a close request to all backends that support such a request. + ;; Send a close request to all backends that support such a request. (let ((methods gnus-valid-select-methods) func) (while methods - (if (fboundp (setq func (intern (concat (car (car methods)) + (if (fboundp (setq func (intern (concat (caar methods) "-request-close")))) (funcall func)) (setq methods (cdr methods))))) @@ -5009,43 +6794,47 @@ The hook `gnus-exit-gnus-hook' is called before actually exiting." "Quit reading news without updating .newsrc.eld or .newsrc. The hook `gnus-exit-gnus-hook' is called before actually exiting." (interactive) - (if (or noninteractive ;For gnus-batch-kill - (zerop (buffer-size)) - (not (gnus-server-opened gnus-select-method)) - gnus-expert-user - (not gnus-current-startup-file) - (gnus-yes-or-no-p - (format "Quit reading news without saving %s? " - (file-name-nondirectory gnus-current-startup-file)))) - (progn - (run-hooks 'gnus-exit-gnus-hook) - (if gnus-use-full-window - (delete-other-windows) - (gnus-remove-some-windows)) - (gnus-dribble-save) - (gnus-close-backends) - (gnus-clear-system)))) + (when (or noninteractive ;For gnus-batch-kill + (zerop (buffer-size)) + (not (gnus-server-opened gnus-select-method)) + gnus-expert-user + (not gnus-current-startup-file) + (gnus-yes-or-no-p + (format "Quit reading news without saving %s? " + (file-name-nondirectory gnus-current-startup-file)))) + (run-hooks 'gnus-exit-gnus-hook) + (if gnus-use-full-window + (delete-other-windows) + (gnus-remove-some-windows)) + (gnus-dribble-save) + (gnus-close-backends) + (gnus-clear-system) + ;; Allow the user to do things after cleaning up. + (run-hooks 'gnus-after-exiting-gnus-hook))) (defun gnus-offer-save-summaries () + "Offer to save all active summary buffers." (save-excursion - (let ((buflist (buffer-list)) + (let ((buflist (buffer-list)) buffers bufname) + ;; Go through all buffers and find all summaries. (while buflist (and (setq bufname (buffer-name (car buflist))) (string-match "Summary" bufname) (save-excursion (set-buffer bufname) ;; We check that this is, indeed, a summary buffer. - (eq major-mode 'gnus-summary-mode)) - (setq buffers (cons bufname buffers))) + (and (eq major-mode 'gnus-summary-mode) + ;; Also make sure this isn't bogus. + gnus-newsgroup-prepared)) + (push bufname buffers)) (setq buflist (cdr buflist))) - (and buffers - (map-y-or-n-p - "Update summary buffer %s? " - (lambda (buf) - (set-buffer buf) - (gnus-summary-exit)) - buffers))))) + ;; Go through all these summary buffers and offer to save them. + (when buffers + (map-y-or-n-p + "Update summary buffer %s? " + (lambda (buf) (set-buffer buf) (gnus-summary-exit)) + buffers))))) (defun gnus-group-describe-briefly () "Give a one line description of the group mode commands." @@ -5055,576 +6844,320 @@ The hook `gnus-exit-gnus-hook' is called before actually exiting." (defun gnus-group-browse-foreign-server (method) "Browse a foreign news server. If called interactively, this function will ask for a select method - (nntp, nnspool, etc.) and a server address (eg. nntp.some.where). + (nntp, nnspool, etc.) and a server address (eg. nntp.some.where). If not, METHOD should be a list where the first element is the method and the second element is the address." (interactive - (list (let ((how (completing-read + (list (let ((how (completing-read "Which backend: " (append gnus-valid-select-methods gnus-server-alist) - nil t "nntp"))) + nil t (cons "nntp" 0) 'gnus-method-history))) ;; We either got a backend name or a virtual server name. ;; If the first, we also need an address. (if (assoc how gnus-valid-select-methods) (list (intern how) ;; Suggested by mapjph@bath.ac.uk. - (completing-read - "Address: " + (completing-read + "Address: " (mapcar (lambda (server) (list server)) gnus-secondary-servers))) ;; We got a server name, so we find the method. (gnus-server-to-method how))))) (gnus-browse-foreign-server method)) - -;;; -;;; Browse Server Mode -;;; - -(defvar gnus-browse-mode-hook nil) -(defvar gnus-browse-mode-map nil) -(put 'gnus-browse-mode 'mode-class 'special) - -(if gnus-browse-mode-map - nil - (setq gnus-browse-mode-map (make-keymap)) - (suppress-keymap gnus-browse-mode-map) - (define-key gnus-browse-mode-map " " 'gnus-browse-read-group) - (define-key gnus-browse-mode-map "=" 'gnus-browse-select-group) - (define-key gnus-browse-mode-map "n" 'gnus-browse-next-group) - (define-key gnus-browse-mode-map "p" 'gnus-browse-prev-group) - (define-key gnus-browse-mode-map "\177" 'gnus-browse-prev-group) - (define-key gnus-browse-mode-map "N" 'gnus-browse-next-group) - (define-key gnus-browse-mode-map "P" 'gnus-browse-prev-group) - (define-key gnus-browse-mode-map "\M-n" 'gnus-browse-next-group) - (define-key gnus-browse-mode-map "\M-p" 'gnus-browse-prev-group) - (define-key gnus-browse-mode-map "\r" 'gnus-browse-select-group) - (define-key gnus-browse-mode-map "u" 'gnus-browse-unsubscribe-current-group) - (define-key gnus-browse-mode-map "l" 'gnus-browse-exit) - (define-key gnus-browse-mode-map "L" 'gnus-browse-exit) - (define-key gnus-browse-mode-map "q" 'gnus-browse-exit) - (define-key gnus-browse-mode-map "Q" 'gnus-browse-exit) - (define-key gnus-browse-mode-map "\C-c\C-c" 'gnus-browse-exit) - (define-key gnus-browse-mode-map "?" 'gnus-browse-describe-briefly) - (define-key gnus-browse-mode-map "\C-c\C-i" 'gnus-info-find-node) - ) - -(defvar gnus-browse-current-method nil) -(defvar gnus-browse-return-buffer nil) - -(defvar gnus-browse-buffer "*Gnus Browse Server*") - -(defun gnus-browse-foreign-server (method &optional return-buffer) - (setq gnus-browse-current-method method) - (setq gnus-browse-return-buffer return-buffer) - (let ((gnus-select-method method) - groups group) - (gnus-message 5 "Connecting to %s..." (nth 1 method)) - (or (gnus-check-server method) - (error "Unable to contact server: %s" (gnus-status-message method))) - (or (gnus-request-list method) - (error "Couldn't request list: %s" (gnus-status-message method))) - (get-buffer-create gnus-browse-buffer) - (gnus-add-current-to-buffer-list) - (and gnus-carpal (gnus-carpal-setup-buffer 'browse)) - (gnus-configure-windows 'browse) - (buffer-disable-undo (current-buffer)) - (let ((buffer-read-only nil)) - (erase-buffer)) - (gnus-browse-mode) - (setq mode-line-buffer-identification - (format - "Gnus Browse Server {%s:%s}" (car method) (car (cdr method)))) - (save-excursion - (set-buffer nntp-server-buffer) - (let ((cur (current-buffer))) - (goto-char (point-min)) - (or (string= gnus-ignored-newsgroups "") - (delete-matching-lines gnus-ignored-newsgroups)) - (while (re-search-forward - "\\(^[^ \t]+\\)[ \t]+[0-9]+[ \t]+[0-9]+" nil t) - (goto-char (match-end 1)) - (setq groups (cons (cons (buffer-substring (match-beginning 1) - (match-end 1)) - (max 0 (- (1+ (read cur)) (read cur)))) - groups))))) - (setq groups (sort groups - (lambda (l1 l2) - (string< (car l1) (car l2))))) - (let ((buffer-read-only nil)) - (while groups - (setq group (car groups)) - (insert - (format "K%7d: %s\n" (cdr group) (car group))) - (setq groups (cdr groups)))) - (switch-to-buffer (current-buffer)) - (goto-char (point-min)) - (gnus-group-position-cursor))) - -(defun gnus-browse-mode () - "Major mode for browsing a foreign server. - -All normal editing commands are switched off. - -\\ -The only things you can do in this buffer is - -1) `\\[gnus-browse-unsubscribe-current-group]' to subscribe to a group. -The group will be inserted into the group buffer upon exit from this -buffer. - -2) `\\[gnus-browse-read-group]' to read a group ephemerally. - -3) `\\[gnus-browse-exit]' to return to the group buffer." - (interactive) - (kill-all-local-variables) - (if gnus-visual (gnus-browse-make-menu-bar)) - (gnus-simplify-mode-line) - (setq major-mode 'gnus-browse-mode) - (setq mode-name "Browse Server") - (setq mode-line-process nil) - (use-local-map gnus-browse-mode-map) - (buffer-disable-undo (current-buffer)) - (setq truncate-lines t) - (setq buffer-read-only t) - (run-hooks 'gnus-browse-mode-hook)) - -(defun gnus-browse-read-group (&optional no-article) - "Enter the group at the current line." - (interactive) - (let ((group (gnus-browse-group-name))) - (or (gnus-group-read-ephemeral-group - group gnus-browse-current-method nil - (cons (current-buffer) 'browse)) - (error "Couldn't enter %s" group)))) - -(defun gnus-browse-select-group () - "Select the current group." - (interactive) - (gnus-browse-read-group 'no)) - -(defun gnus-browse-next-group (n) - "Go to the next group." - (interactive "p") - (prog1 - (forward-line n) - (gnus-group-position-cursor))) - -(defun gnus-browse-prev-group (n) - "Go to the next group." - (interactive "p") - (gnus-browse-next-group (- n))) - -(defun gnus-browse-unsubscribe-current-group (arg) - "(Un)subscribe to the next ARG groups." - (interactive "p") - (and (eobp) - (error "No group at current line.")) - (let ((ward (if (< arg 0) -1 1)) - (arg (abs arg))) - (while (and (> arg 0) - (not (eobp)) - (gnus-browse-unsubscribe-group) - (zerop (gnus-browse-next-group ward))) - (setq arg (1- arg))) - (gnus-group-position-cursor) - (if (/= 0 arg) (gnus-message 7 "No more newsgroups")) - arg)) - -(defun gnus-browse-group-name () - (save-excursion - (beginning-of-line) - (if (not (re-search-forward ": \\(.*\\)$" (gnus-point-at-eol) t)) - () - (gnus-group-prefixed-name - (buffer-substring (match-beginning 1) (match-end 1)) - gnus-browse-current-method)))) - -(defun gnus-browse-unsubscribe-group () - "Toggle subscription of the current group in the browse buffer." - (let ((sub nil) - (buffer-read-only nil) - group) - (save-excursion - (beginning-of-line) - ;; If this group it killed, then we want to subscribe it. - (if (= (following-char) ?K) (setq sub t)) - (setq group (gnus-browse-group-name)) - (delete-char 1) - (if sub - (progn - (gnus-group-change-level - (list t group gnus-level-default-subscribed - nil nil gnus-browse-current-method) - gnus-level-default-subscribed gnus-level-killed - (and (car (nth 1 gnus-newsrc-alist)) - (gnus-gethash (car (nth 1 gnus-newsrc-alist)) - gnus-newsrc-hashtb)) - t) - (insert ? )) - (gnus-group-change-level - group gnus-level-killed gnus-level-default-subscribed) - (insert ?K))) - t)) - -(defun gnus-browse-exit () - "Quit browsing and return to the group buffer." - (interactive) - (if (eq major-mode 'gnus-browse-mode) - (kill-buffer (current-buffer))) - (if gnus-browse-return-buffer - (gnus-configure-windows 'server 'force) - (gnus-configure-windows 'group 'force) - (gnus-group-list-groups nil))) - -(defun gnus-browse-describe-briefly () - "Give a one line description of the group mode commands." - (interactive) - (gnus-message 6 - (substitute-command-keys "\\\\[gnus-group-next-group]:Forward \\[gnus-group-prev-group]:Backward \\[gnus-browse-exit]:Exit \\[gnus-info-find-node]:Run Info \\[gnus-browse-describe-briefly]:This help"))) - ;;; ;;; Gnus summary mode ;;; (defvar gnus-summary-mode-map nil) -(defvar gnus-summary-mark-map nil) -(defvar gnus-summary-mscore-map nil) -(defvar gnus-summary-article-map nil) -(defvar gnus-summary-thread-map nil) -(defvar gnus-summary-goto-map nil) -(defvar gnus-summary-exit-map nil) -(defvar gnus-summary-interest-map nil) -(defvar gnus-summary-sort-map nil) -(defvar gnus-summary-backend-map nil) -(defvar gnus-summary-save-map nil) -(defvar gnus-summary-wash-map nil) -(defvar gnus-summary-wash-hide-map nil) -(defvar gnus-summary-wash-highlight-map nil) -(defvar gnus-summary-wash-time-map nil) -(defvar gnus-summary-help-map nil) (put 'gnus-summary-mode 'mode-class 'special) -(if gnus-summary-mode-map - nil +(unless gnus-summary-mode-map (setq gnus-summary-mode-map (make-keymap)) (suppress-keymap gnus-summary-mode-map) ;; Non-orthogonal keys - (define-key gnus-summary-mode-map " " 'gnus-summary-next-page) - (define-key gnus-summary-mode-map "\177" 'gnus-summary-prev-page) - (define-key gnus-summary-mode-map "\r" 'gnus-summary-scroll-up) - (define-key gnus-summary-mode-map "n" 'gnus-summary-next-unread-article) - (define-key gnus-summary-mode-map "p" 'gnus-summary-prev-unread-article) - (define-key gnus-summary-mode-map "N" 'gnus-summary-next-article) - (define-key gnus-summary-mode-map "P" 'gnus-summary-prev-article) - (define-key gnus-summary-mode-map "\M-\C-n" 'gnus-summary-next-same-subject) - (define-key gnus-summary-mode-map "\M-\C-p" 'gnus-summary-prev-same-subject) - (define-key gnus-summary-mode-map "\M-n" 'gnus-summary-next-unread-subject) - (define-key gnus-summary-mode-map "\M-p" 'gnus-summary-prev-unread-subject) - (define-key gnus-summary-mode-map "." 'gnus-summary-first-unread-article) - (define-key gnus-summary-mode-map "," 'gnus-summary-best-unread-article) - (define-key gnus-summary-mode-map - "\M-s" 'gnus-summary-search-article-forward) - (define-key gnus-summary-mode-map - "\M-r" 'gnus-summary-search-article-backward) - (define-key gnus-summary-mode-map "<" 'gnus-summary-beginning-of-article) - (define-key gnus-summary-mode-map ">" 'gnus-summary-end-of-article) - (define-key gnus-summary-mode-map "j" 'gnus-summary-goto-subject) - (define-key gnus-summary-mode-map "^" 'gnus-summary-refer-parent-article) - (define-key gnus-summary-mode-map "\M-^" 'gnus-summary-refer-article) - (define-key gnus-summary-mode-map "u" 'gnus-summary-tick-article-forward) - (define-key gnus-summary-mode-map "!" 'gnus-summary-tick-article-forward) - (define-key gnus-summary-mode-map "U" 'gnus-summary-tick-article-backward) - (define-key gnus-summary-mode-map "d" 'gnus-summary-mark-as-read-forward) - (define-key gnus-summary-mode-map "D" 'gnus-summary-mark-as-read-backward) - (define-key gnus-summary-mode-map "E" 'gnus-summary-mark-as-expirable) - (define-key gnus-summary-mode-map "\M-u" 'gnus-summary-clear-mark-forward) - (define-key gnus-summary-mode-map "\M-U" 'gnus-summary-clear-mark-backward) - (define-key gnus-summary-mode-map - "k" 'gnus-summary-kill-same-subject-and-select) - (define-key gnus-summary-mode-map "\C-k" 'gnus-summary-kill-same-subject) - (define-key gnus-summary-mode-map "\M-\C-k" 'gnus-summary-kill-thread) - (define-key gnus-summary-mode-map "\M-\C-l" 'gnus-summary-lower-thread) - (define-key gnus-summary-mode-map "e" 'gnus-summary-edit-article) - (define-key gnus-summary-mode-map "#" 'gnus-summary-mark-as-processable) - (define-key gnus-summary-mode-map "\M-#" 'gnus-summary-unmark-as-processable) - (define-key gnus-summary-mode-map "\M-\C-t" 'gnus-summary-toggle-threads) - (define-key gnus-summary-mode-map "\M-\C-s" 'gnus-summary-show-thread) - (define-key gnus-summary-mode-map "\M-\C-h" 'gnus-summary-hide-thread) - (define-key gnus-summary-mode-map "\M-\C-f" 'gnus-summary-next-thread) - (define-key gnus-summary-mode-map "\M-\C-b" 'gnus-summary-prev-thread) - (define-key gnus-summary-mode-map "\M-\C-u" 'gnus-summary-up-thread) - (define-key gnus-summary-mode-map "\M-\C-d" 'gnus-summary-down-thread) - (define-key gnus-summary-mode-map "&" 'gnus-summary-execute-command) - (define-key gnus-summary-mode-map "c" 'gnus-summary-catchup-and-exit) - (define-key gnus-summary-mode-map "\C-w" 'gnus-summary-mark-region-as-read) - (define-key gnus-summary-mode-map "\C-t" 'gnus-summary-toggle-truncation) - (define-key gnus-summary-mode-map "?" 'gnus-summary-mark-as-dormant) - (define-key gnus-summary-mode-map - "\C-c\M-\C-s" 'gnus-summary-show-all-expunged) - (define-key gnus-summary-mode-map - "\C-c\C-s\C-n" 'gnus-summary-sort-by-number) - (define-key gnus-summary-mode-map - "\C-c\C-s\C-a" 'gnus-summary-sort-by-author) - (define-key gnus-summary-mode-map - "\C-c\C-s\C-s" 'gnus-summary-sort-by-subject) - (define-key gnus-summary-mode-map "\C-c\C-s\C-d" 'gnus-summary-sort-by-date) - (define-key gnus-summary-mode-map "\C-c\C-s\C-i" 'gnus-summary-sort-by-score) - (define-key gnus-summary-mode-map "=" 'gnus-summary-expand-window) - (define-key gnus-summary-mode-map - "\C-x\C-s" 'gnus-summary-reselect-current-group) - (define-key gnus-summary-mode-map "\M-g" 'gnus-summary-rescan-group) - (define-key gnus-summary-mode-map "w" 'gnus-summary-stop-page-breaking) - (define-key gnus-summary-mode-map "\C-c\C-r" 'gnus-summary-caesar-message) - (define-key gnus-summary-mode-map "\M-t" 'gnus-summary-toggle-mime) - (define-key gnus-summary-mode-map "f" 'gnus-summary-followup) - (define-key gnus-summary-mode-map "F" 'gnus-summary-followup-with-original) - (define-key gnus-summary-mode-map "C" 'gnus-summary-cancel-article) - (define-key gnus-summary-mode-map "r" 'gnus-summary-reply) - (define-key gnus-summary-mode-map "R" 'gnus-summary-reply-with-original) - (define-key gnus-summary-mode-map "\C-c\C-f" 'gnus-summary-mail-forward) - (define-key gnus-summary-mode-map "o" 'gnus-summary-save-article) - (define-key gnus-summary-mode-map "\C-o" 'gnus-summary-save-article-mail) - (define-key gnus-summary-mode-map "|" 'gnus-summary-pipe-output) - (define-key gnus-summary-mode-map "\M-k" 'gnus-summary-edit-local-kill) - (define-key gnus-summary-mode-map "\M-K" 'gnus-summary-edit-global-kill) - (define-key gnus-summary-mode-map "V" 'gnus-version) - (define-key gnus-summary-mode-map "\C-c\C-d" 'gnus-summary-describe-group) - (define-key gnus-summary-mode-map "q" 'gnus-summary-exit) - (define-key gnus-summary-mode-map "Q" 'gnus-summary-exit-no-update) - (define-key gnus-summary-mode-map "\C-c\C-i" 'gnus-info-find-node) - (define-key gnus-summary-mode-map gnus-mouse-2 'gnus-mouse-pick-article) - (define-key gnus-summary-mode-map "m" 'gnus-summary-mail-other-window) - (define-key gnus-summary-mode-map "a" 'gnus-summary-post-news) - (define-key gnus-summary-mode-map - "x" 'gnus-summary-remove-lines-marked-as-read) -; (define-key gnus-summary-mode-map "X" 'gnus-summary-remove-lines-marked-with) - (define-key gnus-summary-mode-map "s" 'gnus-summary-isearch-article) - (define-key gnus-summary-mode-map "t" 'gnus-summary-toggle-header) - (define-key gnus-summary-mode-map "g" 'gnus-summary-show-article) -; (define-key gnus-summary-mode-map "?" 'gnus-summary-describe-briefly) - (define-key gnus-summary-mode-map "l" 'gnus-summary-goto-last-article) - (define-key gnus-summary-mode-map "\C-c\C-v\C-v" 'gnus-uu-decode-uu-view) - (define-key gnus-summary-mode-map "\C-d" 'gnus-summary-enter-digest-group) - (define-key gnus-summary-mode-map "v" 'gnus-summary-verbose-headers) - (define-key gnus-summary-mode-map "\C-c\C-b" 'gnus-bug) - + (gnus-define-keys gnus-summary-mode-map + " " gnus-summary-next-page + "\177" gnus-summary-prev-page + [delete] gnus-summary-prev-page + "\r" gnus-summary-scroll-up + "n" gnus-summary-next-unread-article + "p" gnus-summary-prev-unread-article + "N" gnus-summary-next-article + "P" gnus-summary-prev-article + "\M-\C-n" gnus-summary-next-same-subject + "\M-\C-p" gnus-summary-prev-same-subject + "\M-n" gnus-summary-next-unread-subject + "\M-p" gnus-summary-prev-unread-subject + "." gnus-summary-first-unread-article + "," gnus-summary-best-unread-article + "\M-s" gnus-summary-search-article-forward + "\M-r" gnus-summary-search-article-backward + "<" gnus-summary-beginning-of-article + ">" gnus-summary-end-of-article + "j" gnus-summary-goto-article + "^" gnus-summary-refer-parent-article + "\M-^" gnus-summary-refer-article + "u" gnus-summary-tick-article-forward + "!" gnus-summary-tick-article-forward + "U" gnus-summary-tick-article-backward + "d" gnus-summary-mark-as-read-forward + "D" gnus-summary-mark-as-read-backward + "E" gnus-summary-mark-as-expirable + "\M-u" gnus-summary-clear-mark-forward + "\M-U" gnus-summary-clear-mark-backward + "k" gnus-summary-kill-same-subject-and-select + "\C-k" gnus-summary-kill-same-subject + "\M-\C-k" gnus-summary-kill-thread + "\M-\C-l" gnus-summary-lower-thread + "e" gnus-summary-edit-article + "#" gnus-summary-mark-as-processable + "\M-#" gnus-summary-unmark-as-processable + "\M-\C-t" gnus-summary-toggle-threads + "\M-\C-s" gnus-summary-show-thread + "\M-\C-h" gnus-summary-hide-thread + "\M-\C-f" gnus-summary-next-thread + "\M-\C-b" gnus-summary-prev-thread + "\M-\C-u" gnus-summary-up-thread + "\M-\C-d" gnus-summary-down-thread + "&" gnus-summary-execute-command + "c" gnus-summary-catchup-and-exit + "\C-w" gnus-summary-mark-region-as-read + "\C-t" gnus-summary-toggle-truncation + "?" gnus-summary-mark-as-dormant + "\C-c\M-\C-s" gnus-summary-limit-include-expunged + "\C-c\C-s\C-n" gnus-summary-sort-by-number + "\C-c\C-s\C-a" gnus-summary-sort-by-author + "\C-c\C-s\C-s" gnus-summary-sort-by-subject + "\C-c\C-s\C-d" gnus-summary-sort-by-date + "\C-c\C-s\C-i" gnus-summary-sort-by-score + "=" gnus-summary-expand-window + "\C-x\C-s" gnus-summary-reselect-current-group + "\M-g" gnus-summary-rescan-group + "w" gnus-summary-stop-page-breaking + "\C-c\C-r" gnus-summary-caesar-message + "\M-t" gnus-summary-toggle-mime + "f" gnus-summary-followup + "F" gnus-summary-followup-with-original + "C" gnus-summary-cancel-article + "r" gnus-summary-reply + "R" gnus-summary-reply-with-original + "\C-c\C-f" gnus-summary-mail-forward + "o" gnus-summary-save-article + "\C-o" gnus-summary-save-article-mail + "|" gnus-summary-pipe-output + "\M-k" gnus-summary-edit-local-kill + "\M-K" gnus-summary-edit-global-kill + "V" gnus-version + "\C-c\C-d" gnus-summary-describe-group + "q" gnus-summary-exit + "Q" gnus-summary-exit-no-update + "\C-c\C-i" gnus-info-find-node + gnus-mouse-2 gnus-mouse-pick-article + "m" gnus-summary-mail-other-window + "a" gnus-summary-post-news + "x" gnus-summary-limit-to-unread + "s" gnus-summary-isearch-article + "t" gnus-article-hide-headers + "g" gnus-summary-show-article + "l" gnus-summary-goto-last-article + "\C-c\C-v\C-v" gnus-uu-decode-uu-view + "\C-d" gnus-summary-enter-digest-group + "\C-c\C-b" gnus-bug + "*" gnus-cache-enter-article + "\M-*" gnus-cache-remove-article + "\M-&" gnus-summary-universal-argument + "\C-l" gnus-recenter + "I" gnus-summary-increase-score + "L" gnus-summary-lower-score + + "V" gnus-summary-score-map + "X" gnus-uu-extract-map + "S" gnus-summary-send-map) ;; Sort of orthogonal keymap - (define-prefix-command 'gnus-summary-mark-map) - (define-key gnus-summary-mode-map "M" 'gnus-summary-mark-map) - (define-key gnus-summary-mark-map "t" 'gnus-summary-tick-article-forward) - (define-key gnus-summary-mark-map "!" 'gnus-summary-tick-article-forward) - (define-key gnus-summary-mark-map "d" 'gnus-summary-mark-as-read-forward) - (define-key gnus-summary-mark-map "r" 'gnus-summary-mark-as-read-forward) - (define-key gnus-summary-mark-map "c" 'gnus-summary-clear-mark-forward) - (define-key gnus-summary-mark-map " " 'gnus-summary-clear-mark-forward) - (define-key gnus-summary-mark-map "e" 'gnus-summary-mark-as-expirable) - (define-key gnus-summary-mark-map "x" 'gnus-summary-mark-as-expirable) - (define-key gnus-summary-mark-map "?" 'gnus-summary-mark-as-dormant) - (define-key gnus-summary-mark-map "b" 'gnus-summary-set-bookmark) - (define-key gnus-summary-mark-map "B" 'gnus-summary-remove-bookmark) - (define-key gnus-summary-mark-map "#" 'gnus-summary-mark-as-processable) - (define-key gnus-summary-mark-map "\M-#" 'gnus-summary-unmark-as-processable) - (define-key gnus-summary-mark-map - "\M-r" 'gnus-summary-remove-lines-marked-as-read) - (define-key gnus-summary-mark-map - "\M-\C-r" 'gnus-summary-remove-lines-marked-with) - (define-key gnus-summary-mark-map "D" 'gnus-summary-show-all-dormant) - (define-key gnus-summary-mark-map "\M-D" 'gnus-summary-hide-all-dormant) - (define-key gnus-summary-mark-map "S" 'gnus-summary-show-all-expunged) - (define-key gnus-summary-mark-map "C" 'gnus-summary-catchup) - (define-key gnus-summary-mark-map "H" 'gnus-summary-catchup-to-here) - (define-key gnus-summary-mark-map "\C-c" 'gnus-summary-catchup-all) - (define-key gnus-summary-mark-map - "k" 'gnus-summary-kill-same-subject-and-select) - (define-key gnus-summary-mark-map "K" 'gnus-summary-kill-same-subject) - - (define-prefix-command 'gnus-summary-mscore-map) - (define-key gnus-summary-mark-map "V" 'gnus-summary-mscore-map) - (define-key gnus-summary-mscore-map "c" 'gnus-summary-clear-above) - (define-key gnus-summary-mscore-map "u" 'gnus-summary-tick-above) - (define-key gnus-summary-mscore-map "m" 'gnus-summary-mark-above) - (define-key gnus-summary-mscore-map "k" 'gnus-summary-kill-below) - - (define-key gnus-summary-mark-map "P" 'gnus-uu-mark-map) - - (define-key gnus-summary-mode-map "S" 'gnus-summary-send-map) - - (define-prefix-command 'gnus-summary-goto-map) - (define-key gnus-summary-mode-map "G" 'gnus-summary-goto-map) - (define-key gnus-summary-goto-map "n" 'gnus-summary-next-unread-article) - (define-key gnus-summary-goto-map "p" 'gnus-summary-prev-unread-article) - (define-key gnus-summary-goto-map "N" 'gnus-summary-next-article) - (define-key gnus-summary-goto-map "P" 'gnus-summary-prev-article) - (define-key gnus-summary-goto-map "\C-n" 'gnus-summary-next-same-subject) - (define-key gnus-summary-goto-map "\C-p" 'gnus-summary-prev-same-subject) - (define-key gnus-summary-goto-map "\M-n" 'gnus-summary-next-unread-subject) - (define-key gnus-summary-goto-map "\M-p" 'gnus-summary-prev-unread-subject) - (define-key gnus-summary-goto-map "f" 'gnus-summary-first-unread-article) - (define-key gnus-summary-goto-map "b" 'gnus-summary-best-unread-article) - (define-key gnus-summary-goto-map "g" 'gnus-summary-goto-subject) - (define-key gnus-summary-goto-map "l" 'gnus-summary-goto-last-article) - (define-key gnus-summary-goto-map "p" 'gnus-summary-pop-article) - - - (define-prefix-command 'gnus-summary-thread-map) - (define-key gnus-summary-mode-map "T" 'gnus-summary-thread-map) - (define-key gnus-summary-thread-map "k" 'gnus-summary-kill-thread) - (define-key gnus-summary-thread-map "l" 'gnus-summary-lower-thread) - (define-key gnus-summary-thread-map "i" 'gnus-summary-raise-thread) - (define-key gnus-summary-thread-map "T" 'gnus-summary-toggle-threads) - (define-key gnus-summary-thread-map "s" 'gnus-summary-show-thread) - (define-key gnus-summary-thread-map "S" 'gnus-summary-show-all-threads) - (define-key gnus-summary-thread-map "h" 'gnus-summary-hide-thread) - (define-key gnus-summary-thread-map "H" 'gnus-summary-hide-all-threads) - (define-key gnus-summary-thread-map "n" 'gnus-summary-next-thread) - (define-key gnus-summary-thread-map "p" 'gnus-summary-prev-thread) - (define-key gnus-summary-thread-map "u" 'gnus-summary-up-thread) - (define-key gnus-summary-thread-map "d" 'gnus-summary-down-thread) - (define-key gnus-summary-thread-map "#" 'gnus-uu-mark-thread) - - - (define-prefix-command 'gnus-summary-exit-map) - (define-key gnus-summary-mode-map "Z" 'gnus-summary-exit-map) - (define-key gnus-summary-exit-map "c" 'gnus-summary-catchup-and-exit) - (define-key gnus-summary-exit-map "C" 'gnus-summary-catchup-all-and-exit) - (define-key gnus-summary-exit-map "E" 'gnus-summary-exit-no-update) - (define-key gnus-summary-exit-map "Q" 'gnus-summary-exit) - (define-key gnus-summary-exit-map "Z" 'gnus-summary-exit) - (define-key gnus-summary-exit-map - "n" 'gnus-summary-catchup-and-goto-next-group) - (define-key gnus-summary-exit-map "R" 'gnus-summary-reselect-current-group) - (define-key gnus-summary-exit-map "G" 'gnus-summary-rescan-group) - (define-key gnus-summary-exit-map "N" 'gnus-summary-next-group) - (define-key gnus-summary-exit-map "P" 'gnus-summary-prev-group) - - - (define-prefix-command 'gnus-summary-article-map) - (define-key gnus-summary-mode-map "A" 'gnus-summary-article-map) - (define-key gnus-summary-article-map " " 'gnus-summary-next-page) - (define-key gnus-summary-article-map "n" 'gnus-summary-next-page) - (define-key gnus-summary-article-map "\177" 'gnus-summary-prev-page) - (define-key gnus-summary-article-map "p" 'gnus-summary-prev-page) - (define-key gnus-summary-article-map "\r" 'gnus-summary-scroll-up) - (define-key gnus-summary-article-map "<" 'gnus-summary-beginning-of-article) - (define-key gnus-summary-article-map ">" 'gnus-summary-end-of-article) - (define-key gnus-summary-article-map "b" 'gnus-summary-beginning-of-article) - (define-key gnus-summary-article-map "e" 'gnus-summary-end-of-article) - (define-key gnus-summary-article-map "^" 'gnus-summary-refer-parent-article) - (define-key gnus-summary-article-map "r" 'gnus-summary-refer-parent-article) - (define-key gnus-summary-article-map "g" 'gnus-summary-show-article) - (define-key gnus-summary-article-map "s" 'gnus-summary-isearch-article) - - - - (define-prefix-command 'gnus-summary-wash-map) - (define-key gnus-summary-mode-map "W" 'gnus-summary-wash-map) - - (define-prefix-command 'gnus-summary-wash-hide-map) - (define-key gnus-summary-wash-map "W" 'gnus-summary-wash-hide-map) - (define-key gnus-summary-wash-hide-map "a" 'gnus-article-hide) - (define-key gnus-summary-wash-hide-map "h" 'gnus-article-hide-headers) - (define-key gnus-summary-wash-hide-map "s" 'gnus-article-hide-signature) - (define-key gnus-summary-wash-hide-map "c" 'gnus-article-hide-citation) - (define-key gnus-summary-wash-hide-map - "\C-c" 'gnus-article-hide-citation-maybe) - - (define-prefix-command 'gnus-summary-wash-highlight-map) - (define-key gnus-summary-wash-map "H" 'gnus-summary-wash-highlight-map) - (define-key gnus-summary-wash-highlight-map "a" 'gnus-article-highlight) - (define-key gnus-summary-wash-highlight-map - "h" 'gnus-article-highlight-headers) - (define-key gnus-summary-wash-highlight-map - "c" 'gnus-article-highlight-citation) - (define-key gnus-summary-wash-highlight-map - "s" 'gnus-article-highlight-signature) - - (define-prefix-command 'gnus-summary-wash-time-map) - (define-key gnus-summary-wash-map "T" 'gnus-summary-wash-time-map) - (define-key gnus-summary-wash-time-map "z" 'gnus-article-date-ut) - (define-key gnus-summary-wash-time-map "u" 'gnus-article-date-ut) - (define-key gnus-summary-wash-time-map "l" 'gnus-article-date-local) - (define-key gnus-summary-wash-time-map "e" 'gnus-article-date-lapsed) - - (define-key gnus-summary-wash-map "b" 'gnus-article-add-buttons) - (define-key gnus-summary-wash-map "o" 'gnus-article-treat-overstrike) - (define-key gnus-summary-wash-map "w" 'gnus-article-word-wrap) - (define-key gnus-summary-wash-map "c" 'gnus-article-remove-cr) - (define-key gnus-summary-wash-map "q" 'gnus-article-de-quoted-unreadable) - (define-key gnus-summary-wash-map "f" 'gnus-article-display-x-face) - (define-key gnus-summary-wash-map "l" 'gnus-summary-stop-page-breaking) - (define-key gnus-summary-wash-map "r" 'gnus-summary-caesar-message) - (define-key gnus-summary-wash-map "t" 'gnus-summary-toggle-header) - (define-key gnus-summary-wash-map "m" 'gnus-summary-toggle-mime) - - - (define-prefix-command 'gnus-summary-help-map) - (define-key gnus-summary-mode-map "H" 'gnus-summary-help-map) - (define-key gnus-summary-help-map "v" 'gnus-version) - (define-key gnus-summary-help-map "f" 'gnus-summary-fetch-faq) - (define-key gnus-summary-help-map "d" 'gnus-summary-describe-group) - (define-key gnus-summary-help-map "h" 'gnus-summary-describe-briefly) - (define-key gnus-summary-help-map "i" 'gnus-info-find-node) - - - (define-prefix-command 'gnus-summary-backend-map) - (define-key gnus-summary-mode-map "B" 'gnus-summary-backend-map) - (define-key gnus-summary-backend-map "e" 'gnus-summary-expire-articles) - (define-key gnus-summary-backend-map "\M-\C-e" - 'gnus-summary-expire-articles-now) - (define-key gnus-summary-backend-map "\177" 'gnus-summary-delete-article) - (define-key gnus-summary-backend-map "m" 'gnus-summary-move-article) - (define-key gnus-summary-backend-map "r" 'gnus-summary-respool-article) - (define-key gnus-summary-backend-map "w" 'gnus-summary-edit-article) - (define-key gnus-summary-backend-map "c" 'gnus-summary-copy-article) - (define-key gnus-summary-backend-map "q" 'gnus-summary-fancy-query) - (define-key gnus-summary-backend-map "i" 'gnus-summary-import-article) - - - (define-prefix-command 'gnus-summary-save-map) - (define-key gnus-summary-mode-map "O" 'gnus-summary-save-map) - (define-key gnus-summary-save-map "o" 'gnus-summary-save-article) - (define-key gnus-summary-save-map "m" 'gnus-summary-save-article-mail) - (define-key gnus-summary-save-map "r" 'gnus-summary-save-article-rmail) - (define-key gnus-summary-save-map "f" 'gnus-summary-save-article-file) - (define-key gnus-summary-save-map "h" 'gnus-summary-save-article-folder) - (define-key gnus-summary-save-map "v" 'gnus-summary-save-article-vm) - (define-key gnus-summary-save-map "p" 'gnus-summary-pipe-output) -; (define-key gnus-summary-save-map "s" 'gnus-soup-add-article) - - (define-key gnus-summary-mode-map "X" 'gnus-uu-extract-map) - - (define-key gnus-summary-mode-map "\M-&" 'gnus-summary-universal-argument) -; (define-key gnus-summary-various-map "\C-s" 'gnus-summary-search-article-forward) -; (define-key gnus-summary-various-map "\C-r" 'gnus-summary-search-article-backward) -; (define-key gnus-summary-various-map "r" 'gnus-summary-refer-article) -; (define-key gnus-summary-various-map "&" 'gnus-summary-execute-command) -; (define-key gnus-summary-various-map "T" 'gnus-summary-toggle-truncation) -; (define-key gnus-summary-various-map "e" 'gnus-summary-expand-window) - (define-key gnus-summary-article-map "D" 'gnus-summary-enter-digest-group) -; (define-key gnus-summary-various-map "k" 'gnus-summary-edit-local-kill) -; (define-key gnus-summary-various-map "K" 'gnus-summary-edit-global-kill) - - (define-key gnus-summary-mode-map "V" 'gnus-summary-score-map) - -; (define-prefix-command 'gnus-summary-sort-map) -; (define-key gnus-summary-various-map "s" 'gnus-summary-sort-map) -; (define-key gnus-summary-sort-map "n" 'gnus-summary-sort-by-number) -; (define-key gnus-summary-sort-map "a" 'gnus-summary-sort-by-author) -; (define-key gnus-summary-sort-map "s" 'gnus-summary-sort-by-subject) -; (define-key gnus-summary-sort-map "d" 'gnus-summary-sort-by-date) -; (define-key gnus-summary-sort-map "i" 'gnus-summary-sort-by-score) - - (define-key gnus-summary-mode-map "I" 'gnus-summary-increase-score) - (define-key gnus-summary-mode-map "L" 'gnus-summary-lower-score) + (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map) + "t" gnus-summary-tick-article-forward + "!" gnus-summary-tick-article-forward + "d" gnus-summary-mark-as-read-forward + "r" gnus-summary-mark-as-read-forward + "c" gnus-summary-clear-mark-forward + " " gnus-summary-clear-mark-forward + "e" gnus-summary-mark-as-expirable + "x" gnus-summary-mark-as-expirable + "?" gnus-summary-mark-as-dormant + "b" gnus-summary-set-bookmark + "B" gnus-summary-remove-bookmark + "#" gnus-summary-mark-as-processable + "\M-#" gnus-summary-unmark-as-processable + "S" gnus-summary-limit-include-expunged + "C" gnus-summary-catchup + "H" gnus-summary-catchup-to-here + "\C-c" gnus-summary-catchup-all + "k" gnus-summary-kill-same-subject-and-select + "K" gnus-summary-kill-same-subject + "P" gnus-uu-mark-map) + + (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mode-map) + "c" gnus-summary-clear-above + "u" gnus-summary-tick-above + "m" gnus-summary-mark-above + "k" gnus-summary-kill-below) + + (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map) + "/" gnus-summary-limit-to-subject + "n" gnus-summary-limit-to-articles + "w" gnus-summary-pop-limit + "s" gnus-summary-limit-to-subject + "a" gnus-summary-limit-to-author + "u" gnus-summary-limit-to-unread + "m" gnus-summary-limit-to-marks + "v" gnus-summary-limit-to-score + "D" gnus-summary-limit-include-dormant + "d" gnus-summary-limit-exclude-dormant + ;; "t" gnus-summary-limit-exclude-thread + "E" gnus-summary-limit-include-expunged + "c" gnus-summary-limit-exclude-childless-dormant + "C" gnus-summary-limit-mark-excluded-as-read) + + (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map) + "n" gnus-summary-next-unread-article + "p" gnus-summary-prev-unread-article + "N" gnus-summary-next-article + "P" gnus-summary-prev-article + "\C-n" gnus-summary-next-same-subject + "\C-p" gnus-summary-prev-same-subject + "\M-n" gnus-summary-next-unread-subject + "\M-p" gnus-summary-prev-unread-subject + "f" gnus-summary-first-unread-article + "b" gnus-summary-best-unread-article + "j" gnus-summary-goto-article + "g" gnus-summary-goto-subject + "l" gnus-summary-goto-last-article + "p" gnus-summary-pop-article) + + (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map) + "k" gnus-summary-kill-thread + "l" gnus-summary-lower-thread + "i" gnus-summary-raise-thread + "T" gnus-summary-toggle-threads + "t" gnus-summary-rethread-current + "^" gnus-summary-reparent-thread + "s" gnus-summary-show-thread + "S" gnus-summary-show-all-threads + "h" gnus-summary-hide-thread + "H" gnus-summary-hide-all-threads + "n" gnus-summary-next-thread + "p" gnus-summary-prev-thread + "u" gnus-summary-up-thread + "o" gnus-summary-top-thread + "d" gnus-summary-down-thread + "#" gnus-uu-mark-thread + "\M-#" gnus-uu-unmark-thread) + + (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map) + "c" gnus-summary-catchup-and-exit + "C" gnus-summary-catchup-all-and-exit + "E" gnus-summary-exit-no-update + "Q" gnus-summary-exit + "Z" gnus-summary-exit + "n" gnus-summary-catchup-and-goto-next-group + "R" gnus-summary-reselect-current-group + "G" gnus-summary-rescan-group + "N" gnus-summary-next-group + "P" gnus-summary-prev-group) + + (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map) + " " gnus-summary-next-page + "n" gnus-summary-next-page + "\177" gnus-summary-prev-page + [delete] gnus-summary-prev-page + "p" gnus-summary-prev-page + "\r" gnus-summary-scroll-up + "<" gnus-summary-beginning-of-article + ">" gnus-summary-end-of-article + "b" gnus-summary-beginning-of-article + "e" gnus-summary-end-of-article + "^" gnus-summary-refer-parent-article + "r" gnus-summary-refer-parent-article + "R" gnus-summary-refer-references + "g" gnus-summary-show-article + "s" gnus-summary-isearch-article) + + (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map) + "b" gnus-article-add-buttons + "B" gnus-article-add-buttons-to-head + "o" gnus-article-treat-overstrike + ;; "w" gnus-article-word-wrap + "w" gnus-article-fill-cited-article + "c" gnus-article-remove-cr + "L" gnus-article-remove-trailing-blank-lines + "q" gnus-article-de-quoted-unreadable + "f" gnus-article-display-x-face + "l" gnus-summary-stop-page-breaking + "r" gnus-summary-caesar-message + "t" gnus-article-hide-headers + "v" gnus-summary-verbose-headers + "m" gnus-summary-toggle-mime) + + (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map) + "a" gnus-article-hide + "h" gnus-article-hide-headers + "b" gnus-article-hide-boring-headers + "s" gnus-article-hide-signature + "c" gnus-article-hide-citation + "p" gnus-article-hide-pgp + "\C-c" gnus-article-hide-citation-maybe) + + (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map) + "a" gnus-article-highlight + "h" gnus-article-highlight-headers + "c" gnus-article-highlight-citation + "s" gnus-article-highlight-signature) + + (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map) + "z" gnus-article-date-ut + "u" gnus-article-date-ut + "l" gnus-article-date-local + "e" gnus-article-date-lapsed + "o" gnus-article-date-original) + + (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map) + "v" gnus-version + "f" gnus-summary-fetch-faq + "d" gnus-summary-describe-group + "h" gnus-summary-describe-briefly + "i" gnus-info-find-node) + + (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map) + "e" gnus-summary-expire-articles + "\M-\C-e" gnus-summary-expire-articles-now + "\177" gnus-summary-delete-article + [delete] gnus-summary-delete-article + "m" gnus-summary-move-article + "r" gnus-summary-respool-article + "w" gnus-summary-edit-article + "c" gnus-summary-copy-article + "B" gnus-summary-crosspost-article + "q" gnus-summary-respool-query + "i" gnus-summary-import-article) + + (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map) + "o" gnus-summary-save-article + "m" gnus-summary-save-article-mail + "r" gnus-summary-save-article-rmail + "f" gnus-summary-save-article-file + "b" gnus-summary-save-article-body-file + "h" gnus-summary-save-article-folder + "v" gnus-summary-save-article-vm + "p" gnus-summary-pipe-output + "s" gnus-soup-add-article) ) - (defun gnus-summary-mode (&optional group) @@ -5634,31 +7167,25 @@ All normal editing commands are switched off. \\ Each line in this buffer represents one article. To read an article, you can, for instance, type `\\[gnus-summary-next-page]'. To move forwards -and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]', +and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]', respectively. -You can also post articles and send mail from this buffer. To -follow up an article, type `\\[gnus-summary-followup]'. To mail a reply to the author +You can also post articles and send mail from this buffer. To +follow up an article, type `\\[gnus-summary-followup]'. To mail a reply to the author of an article, type `\\[gnus-summary-reply]'. -There are approx. one gazillion commands you can execute in this -buffer; read the info pages for more information (`\\[gnus-info-find-node]'). +There are approx. one gazillion commands you can execute in this +buffer; read the info pages for more information (`\\[gnus-info-find-node]'). The following commands are available: \\{gnus-summary-mode-map}" (interactive) - (if gnus-visual (gnus-summary-make-menu-bar)) + (when (and menu-bar-mode + (gnus-visual-p 'summary-menu 'menu)) + (gnus-summary-make-menu-bar)) (kill-all-local-variables) - (let ((locals gnus-summary-local-variables)) - (while locals - (if (consp (car locals)) - (progn - (make-local-variable (car (car locals))) - (set (car (car locals)) (eval (cdr (car locals))))) - (make-local-variable (car locals)) - (set (car locals) nil)) - (setq locals (cdr locals)))) + (gnus-summary-make-local-variables) (gnus-make-thread-indent-array) (gnus-simplify-mode-line) (setq major-mode 'gnus-summary-mode) @@ -5672,15 +7199,36 @@ The following commands are available: (setq selective-display-ellipses t) ;Display `...' (setq buffer-display-table gnus-summary-display-table) (setq gnus-newsgroup-name group) + (make-local-variable 'gnus-summary-line-format) + (make-local-variable 'gnus-summary-line-format-spec) + (make-local-variable 'gnus-summary-mark-positions) (run-hooks 'gnus-summary-mode-hook)) +(defun gnus-summary-make-local-variables () + "Make all the local summary buffer variables." + (let ((locals gnus-summary-local-variables) + global local) + (while (setq local (pop locals)) + (if (consp local) + (progn + (if (eq (cdr local) 'global) + ;; Copy the global value of the variable. + (setq global (symbol-value (car local))) + ;; Use the value from the list. + (setq global (eval (cdr local)))) + (make-local-variable (car local)) + (set (car local) global)) + ;; Simple nil-valued local variable. + (make-local-variable local) + (set local nil))))) + (defun gnus-summary-make-display-table () - ;; Change the display table. Odd characters have a tendency to mess + ;; Change the display table. Odd characters have a tendency to mess ;; up nicely formatted displays - we make all possible glyphs ;; display only a single character. ;; We start from the standard display table, if any. - (setq gnus-summary-display-table + (setq gnus-summary-display-table (or (copy-sequence standard-display-table) (make-display-table))) ;; Nix out all the control chars... @@ -5688,83 +7236,281 @@ The following commands are available: (while (>= (setq i (1- i)) 0) (aset gnus-summary-display-table i [??]))) ;; ... but not newline and cr, of course. (cr is necessary for the - ;; selective display). + ;; selective display). (aset gnus-summary-display-table ?\n nil) (aset gnus-summary-display-table ?\r nil) - ;; We nix out any glyphs over 126 that are not set already. + ;; We nix out any glyphs over 126 that are not set already. (let ((i 256)) (while (>= (setq i (1- i)) 127) ;; Only modify if the entry is nil. - (or (aref gnus-summary-display-table i) + (or (aref gnus-summary-display-table i) (aset gnus-summary-display-table i [??]))))) (defun gnus-summary-clear-local-variables () (let ((locals gnus-summary-local-variables)) (while locals (if (consp (car locals)) - (and (vectorp (car (car locals))) - (set (car (car locals)) nil)) + (and (vectorp (caar locals)) + (set (caar locals) nil)) (and (vectorp (car locals)) (set (car locals) nil))) (setq locals (cdr locals))))) +;; Summary data functions. + +(defmacro gnus-data-number (data) + `(car ,data)) + +(defmacro gnus-data-set-number (data number) + `(setcar ,data ,number)) + +(defmacro gnus-data-mark (data) + `(nth 1 ,data)) + +(defmacro gnus-data-set-mark (data mark) + `(setcar (nthcdr 1 ,data) ,mark)) + +(defmacro gnus-data-pos (data) + `(nth 2 ,data)) + +(defmacro gnus-data-set-pos (data pos) + `(setcar (nthcdr 2 ,data) ,pos)) + +(defmacro gnus-data-header (data) + `(nth 3 ,data)) + +(defmacro gnus-data-level (data) + `(nth 4 ,data)) + +(defmacro gnus-data-unread-p (data) + `(= (nth 1 ,data) gnus-unread-mark)) + +(defmacro gnus-data-pseudo-p (data) + `(consp (nth 3 ,data))) + +(defmacro gnus-data-find (number) + `(assq ,number gnus-newsgroup-data)) + +(defmacro gnus-data-find-list (number &optional data) + `(let ((bdata ,(or data 'gnus-newsgroup-data))) + (memq (assq ,number bdata) + bdata))) + +(defmacro gnus-data-make (number mark pos header level) + `(list ,number ,mark ,pos ,header ,level)) + +(defun gnus-data-enter (after-article number mark pos header level offset) + (let ((data (gnus-data-find-list after-article))) + (or data (error "No such article: %d" after-article)) + (setcdr data (cons (gnus-data-make number mark pos header level) + (cdr data))) + (setq gnus-newsgroup-data-reverse nil) + (gnus-data-update-list (cddr data) offset))) + +(defun gnus-data-enter-list (after-article list &optional offset) + (when list + (let ((data (and after-article (gnus-data-find-list after-article))) + (ilist list)) + (or data (not after-article) (error "No such article: %d" after-article)) + ;; Find the last element in the list to be spliced into the main + ;; list. + (while (cdr list) + (setq list (cdr list))) + (if (not data) + (progn + (setcdr list gnus-newsgroup-data) + (setq gnus-newsgroup-data ilist) + (and offset (gnus-data-update-list (cdr list) offset))) + (setcdr list (cdr data)) + (setcdr data ilist) + (and offset (gnus-data-update-list (cdr data) offset))) + (setq gnus-newsgroup-data-reverse nil)))) + +(defun gnus-data-remove (article &optional offset) + (let ((data gnus-newsgroup-data)) + (if (= (gnus-data-number (car data)) article) + (setq gnus-newsgroup-data (cdr gnus-newsgroup-data) + gnus-newsgroup-data-reverse nil) + (while (cdr data) + (and (= (gnus-data-number (cadr data)) article) + (progn + (setcdr data (cddr data)) + (and offset (gnus-data-update-list (cdr data) offset)) + (setq data nil + gnus-newsgroup-data-reverse nil))) + (setq data (cdr data)))))) + +(defmacro gnus-data-list (backward) + `(if ,backward + (or gnus-newsgroup-data-reverse + (setq gnus-newsgroup-data-reverse + (reverse gnus-newsgroup-data))) + gnus-newsgroup-data)) + +(defun gnus-data-update-list (data offset) + "Add OFFSET to the POS of all data entries in DATA." + (while data + (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data)))) + (setq data (cdr data)))) + +(defun gnus-data-compute-positions () + "Compute the positions of all articles." + (let ((data gnus-newsgroup-data) + pos) + (while data + (when (setq pos (text-property-any + (point-min) (point-max) + 'gnus-number (gnus-data-number (car data)))) + (gnus-data-set-pos (car data) (+ pos 3))) + (setq data (cdr data))))) + +(defun gnus-summary-article-pseudo-p (article) + "Say whether this article is a pseudo article or not." + (not (vectorp (gnus-data-header (gnus-data-find article))))) + +(defun gnus-article-parent-p (number) + "Say whether this article is a parent or not." + (let ((data (gnus-data-find-list number))) + (and (cdr data) ; There has to be an article after... + (< (gnus-data-level (car data)) ; And it has to have a higher level. + (gnus-data-level (nth 1 data)))))) + +(defun gnus-article-children (number) + "Return a list of all children to NUMBER." + (let* ((data (gnus-data-find-list number)) + (level (gnus-data-level (car data))) + children) + (setq data (cdr data)) + (while (and data + (= (gnus-data-level (car data)) (1+ level))) + (push (gnus-data-number (car data)) children) + (setq data (cdr data))) + children)) + +(defmacro gnus-summary-skip-intangible () + "If the current article is intangible, then jump to a different article." + '(let ((to (get-text-property (point) 'gnus-intangible))) + (and to (gnus-summary-goto-subject to)))) + +(defmacro gnus-summary-article-intangible-p () + "Say whether this article is intangible or not." + '(get-text-property (point) 'gnus-intangible)) + ;; Some summary mode macros. -;; Return a header specified by a NUMBER. -(defun gnus-get-header-by-number (number) - (save-excursion - (set-buffer gnus-summary-buffer) - (or gnus-newsgroup-headers-hashtb-by-number - (gnus-make-headers-hashtable-by-number)) - (gnus-gethash (int-to-string number) - gnus-newsgroup-headers-hashtb-by-number))) - -;; Fast version of the function above. -(defmacro gnus-get-header-by-num (number) - (` (gnus-gethash (int-to-string (, number)) - gnus-newsgroup-headers-hashtb-by-number))) - -(defmacro gnus-summary-search-forward (&optional unread subject backward) - "Search for article forward. -If UNREAD is non-nil, only unread articles are selected. -If SUBJECT is non-nil, the article which has the same subject will be -searched for. -If BACKWARD is non-nil, the search will be performed backwards instead." - (` (gnus-summary-search-subject (, backward) (, unread) (, subject)))) - -(defmacro gnus-summary-search-backward (&optional unread subject) - "Search for article backward. -If 1st optional argument UNREAD is non-nil, only unread article is selected. -If 2nd optional argument SUBJECT is non-nil, the article which has -the same subject will be searched for." - (` (gnus-summary-search-forward (, unread) (, subject) t))) - -(defmacro gnus-summary-article-number (&optional number-or-nil) +(defmacro gnus-summary-article-number () "The article number of the article on the current line. If there isn's an article number here, then we return the current article number." - (if number-or-nil - '(get-text-property (gnus-point-at-bol) 'gnus-number) - '(or (get-text-property (gnus-point-at-bol) 'gnus-number) - gnus-current-article))) - -(defmacro gnus-summary-thread-level () - "The thread level of the article on the current line." - '(or (get-text-property (gnus-point-at-bol) 'gnus-level) - 0)) - -(defmacro gnus-summary-article-mark () - "The mark on the current line." - '(get-text-property (gnus-point-at-bol) 'gnus-mark)) - -(defun gnus-summary-subject-string () + '(progn + (gnus-summary-skip-intangible) + (or (get-text-property (point) 'gnus-number) + (gnus-summary-last-subject)))) + +(defmacro gnus-summary-article-header (&optional number) + `(gnus-data-header (gnus-data-find + ,(or number '(gnus-summary-article-number))))) + +(defmacro gnus-summary-thread-level (&optional number) + `(if (and (eq gnus-summary-make-false-root 'dummy) + (get-text-property (point) 'gnus-intangible)) + 0 + (gnus-data-level (gnus-data-find + ,(or number '(gnus-summary-article-number)))))) + +(defmacro gnus-summary-article-mark (&optional number) + `(gnus-data-mark (gnus-data-find + ,(or number '(gnus-summary-article-number))))) + +(defmacro gnus-summary-article-pos (&optional number) + `(gnus-data-pos (gnus-data-find + ,(or number '(gnus-summary-article-number))))) + +(defalias 'gnus-summary-subject-string 'gnus-summary-article-subject) +(defmacro gnus-summary-article-subject (&optional number) "Return current subject string or nil if nothing." - (let ((article (gnus-summary-article-number)) - header) - (and article - (setq header (gnus-get-header-by-num article)) - (vectorp header) - (mail-header-subject header)))) + `(let ((headers + ,(if number + `(gnus-data-header (assq ,number gnus-newsgroup-data)) + '(gnus-data-header (assq (gnus-summary-article-number) + gnus-newsgroup-data))))) + (and headers + (vectorp headers) + (mail-header-subject headers)))) + +(defmacro gnus-summary-article-score (&optional number) + "Return current article score." + `(or (cdr (assq ,(or number '(gnus-summary-article-number)) + gnus-newsgroup-scored)) + gnus-summary-default-score 0)) + +(defun gnus-summary-article-children (&optional number) + (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number)))) + (level (gnus-data-level (car data))) + l children) + (while (and (setq data (cdr data)) + (> (setq l (gnus-data-level (car data))) level)) + (and (= (1+ level) l) + (setq children (cons (gnus-data-number (car data)) + children)))) + (nreverse children))) + +(defun gnus-summary-article-parent (&optional number) + (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number)) + (gnus-data-list t))) + (level (gnus-data-level (car data)))) + (if (zerop level) + () ; This is a root. + ;; We search until we find an article with a level less than + ;; this one. That function has to be the parent. + (while (and (setq data (cdr data)) + (not (< (gnus-data-level (car data)) level)))) + (and data (gnus-data-number (car data)))))) + +(defun gnus-unread-mark-p (mark) + "Say whether MARK is the unread mark." + (= mark gnus-unread-mark)) + +(defun gnus-read-mark-p (mark) + "Say whether MARK is one of the marks that mark as read. +This is all marks except unread, ticked, dormant, and expirable." + (not (or (= mark gnus-unread-mark) + (= mark gnus-ticked-mark) + (= mark gnus-dormant-mark) + (= mark gnus-expirable-mark)))) + +;; Saving hidden threads. + +(put 'gnus-save-hidden-threads 'lisp-indent-function 0) +(put 'gnus-save-hidden-threads 'lisp-indent-hook 0) +(put 'gnus-save-hidden-threads 'edebug-form-spec '(body)) + +(defmacro gnus-save-hidden-threads (&rest forms) + "Save hidden threads, eval FORMS, and restore the hidden threads." + (let ((config (make-symbol "config"))) + `(let ((,config (gnus-hidden-threads-configuration))) + (unwind-protect + (progn + ,@forms) + (gnus-restore-hidden-threads-configuration ,config))))) + +(defun gnus-hidden-threads-configuration () + "Return the current hidden threads configuration." + (save-excursion + (let (config) + (goto-char (point-min)) + (while (search-forward "\r" nil t) + (push (1- (point)) config)) + config))) + +(defun gnus-restore-hidden-threads-configuration (config) + "Restore hidden threads configuration from CONFIG." + (let (point buffer-read-only) + (while (setq point (pop config)) + (when (and (< point (point-max)) + (goto-char point) + (= (following-char) ?\n)) + (subst-char-in-region point (1+ point) ?\n ?\r))))) ;; Various summary mode internalish functions. @@ -5779,55 +7525,67 @@ article number." (if (get-buffer buffer) (progn (set-buffer buffer) - (not gnus-newsgroup-begin)) + (setq gnus-summary-buffer (current-buffer)) + (not gnus-newsgroup-prepared)) ;; Fix by Sudish Joseph (setq gnus-summary-buffer (set-buffer (get-buffer-create buffer))) (gnus-add-current-to-buffer-list) (gnus-summary-mode group) - (and gnus-carpal (gnus-carpal-setup-buffer 'summary)) + (when gnus-carpal + (gnus-carpal-setup-buffer 'summary)) + (unless gnus-single-article-buffer + (make-local-variable 'gnus-article-buffer) + (make-local-variable 'gnus-article-current) + (make-local-variable 'gnus-original-article-buffer)) (setq gnus-newsgroup-name group) t))) (defun gnus-set-global-variables () ;; Set the global equivalents of the summary buffer-local variables - ;; to the latest values they had. These reflect the summary buffer + ;; to the latest values they had. These reflect the summary buffer ;; that was in action when the last article was fetched. - (if (eq major-mode 'gnus-summary-mode) - (progn - (setq gnus-summary-buffer (current-buffer)) - (let ((name gnus-newsgroup-name) - (marked gnus-newsgroup-marked) - (unread gnus-newsgroup-unreads) - (headers gnus-current-headers) - (score-file gnus-current-score-file)) - (save-excursion - (set-buffer gnus-group-buffer) - (setq gnus-newsgroup-name name) - (setq gnus-newsgroup-marked marked) - (setq gnus-newsgroup-unreads unread) - (setq gnus-current-headers headers) - (setq gnus-current-score-file score-file)))))) - -(defun gnus-summary-insert-dummy-line (sformat subject number) - (if (not sformat) - (setq sformat gnus-summary-dummy-line-format-spec)) - (let (b) - (beginning-of-line) - (setq b (point)) - (insert (eval sformat)) - (add-text-properties - b (1+ b) - (list 'gnus-number number - 'gnus-mark gnus-dummy-mark - 'gnus-level 0)))) + (when (eq major-mode 'gnus-summary-mode) + (setq gnus-summary-buffer (current-buffer)) + (let ((name gnus-newsgroup-name) + (marked gnus-newsgroup-marked) + (unread gnus-newsgroup-unreads) + (headers gnus-current-headers) + (data gnus-newsgroup-data) + (summary gnus-summary-buffer) + (article-buffer gnus-article-buffer) + (original gnus-original-article-buffer) + (gac gnus-article-current) + (score-file gnus-current-score-file)) + (save-excursion + (set-buffer gnus-group-buffer) + (setq gnus-newsgroup-name name) + (setq gnus-newsgroup-marked marked) + (setq gnus-newsgroup-unreads unread) + (setq gnus-current-headers headers) + (setq gnus-newsgroup-data data) + (setq gnus-article-current gac) + (setq gnus-summary-buffer summary) + (setq gnus-article-buffer article-buffer) + (setq gnus-original-article-buffer original) + (setq gnus-current-score-file score-file))))) + +(defun gnus-summary-last-article-p (&optional article) + "Return whether ARTICLE is the last article in the buffer." + (if (not (setq article (or article (gnus-summary-article-number)))) + t ; All non-existant numbers are the last article. :-) + (not (cdr (gnus-data-find-list article))))) + +(defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number) + "Insert a dummy root in the summary buffer." + (beginning-of-line) + (gnus-add-text-properties + (point) (progn (eval gnus-summary-dummy-line-format-spec) (point)) + (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number))) -(defvar gnus-thread-indent-array nil) -(defvar gnus-thread-indent-array-level gnus-thread-indent-level) (defun gnus-make-thread-indent-array () (let ((n 200)) - (if (and gnus-thread-indent-array - (= gnus-thread-indent-level gnus-thread-indent-array-level)) - nil + (unless (and gnus-thread-indent-array + (= gnus-thread-indent-level gnus-thread-indent-array-level)) (setq gnus-thread-indent-array (make-vector 201 "") gnus-thread-indent-array-level gnus-thread-indent-level) (while (>= n 0) @@ -5835,158 +7593,174 @@ article number." (make-string (* n gnus-thread-indent-level) ? )) (setq n (1- n)))))) -(defun gnus-summary-insert-line - (sformat header level current unread replied expirable subject-or-nil - &optional dummy score process) - (or sformat (setq sformat gnus-summary-line-format-spec)) - (let* ((indentation (aref gnus-thread-indent-array level)) - (lines (mail-header-lines header)) - (score (or score gnus-summary-default-score 0)) - (score-char +(defun gnus-summary-insert-line + (gnus-tmp-header gnus-tmp-level gnus-tmp-current gnus-tmp-unread + gnus-tmp-replied gnus-tmp-expirable gnus-tmp-subject-or-nil + &optional gnus-tmp-dummy gnus-tmp-score gnus-tmp-process) + (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level)) + (gnus-tmp-lines (mail-header-lines gnus-tmp-header)) + (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0)) + (gnus-tmp-score-char (if (or (null gnus-summary-default-score) - (<= (abs (- score gnus-summary-default-score)) + (<= (abs (- gnus-tmp-score gnus-summary-default-score)) gnus-summary-zcore-fuzz)) ? - (if (< score gnus-summary-default-score) + (if (< gnus-tmp-score gnus-summary-default-score) gnus-score-below-mark gnus-score-over-mark))) - (replied (cond (process gnus-process-mark) - (replied gnus-replied-mark) - (t gnus-unread-mark))) - (from (mail-header-from header)) - (name (cond - ((string-match "(.+)" from) - (substring from (1+ (match-beginning 0)) (1- (match-end 0)))) - ((string-match "<[^>]+> *$" from) - (let ((beg (match-beginning 0))) - (or (and (string-match "^\"[^\"]*\"" from) - (substring from (1+ (match-beginning 0)) - (1- (match-end 0)))) - (substring from 0 beg)))) - (t from))) - (subject (mail-header-subject header)) - (number (mail-header-number header)) - (opening-bracket (if dummy ?\< ?\[)) - (closing-bracket (if dummy ?\> ?\])) - (buffer-read-only nil) - (b (progn (beginning-of-line) (point)))) - (or (numberp lines) (setq lines 0)) - (insert (eval sformat)) - (add-text-properties - b (1+ b) (list 'gnus-number number - 'gnus-mark (or unread gnus-unread-mark) - 'gnus-level level)))) + (gnus-tmp-replied (cond (gnus-tmp-process gnus-process-mark) + ((memq gnus-tmp-current gnus-newsgroup-cached) + gnus-cached-mark) + (gnus-tmp-replied gnus-replied-mark) + ((memq gnus-tmp-current gnus-newsgroup-saved) + gnus-saved-mark) + (t gnus-unread-mark))) + (gnus-tmp-from (mail-header-from gnus-tmp-header)) + (gnus-tmp-name + (cond + ((string-match "(.+)" gnus-tmp-from) + (substring gnus-tmp-from + (1+ (match-beginning 0)) (1- (match-end 0)))) + ((string-match "<[^>]+> *$" gnus-tmp-from) + (let ((beg (match-beginning 0))) + (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from) + (substring gnus-tmp-from (1+ (match-beginning 0)) + (1- (match-end 0)))) + (substring gnus-tmp-from 0 beg)))) + (t gnus-tmp-from))) + (gnus-tmp-subject (mail-header-subject gnus-tmp-header)) + (gnus-tmp-number (mail-header-number gnus-tmp-header)) + (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[)) + (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\])) + (buffer-read-only nil)) + (when (string= gnus-tmp-name "") + (setq gnus-tmp-name gnus-tmp-from)) + (or (numberp gnus-tmp-lines) (setq gnus-tmp-lines 0)) + (gnus-put-text-property + (point) + (progn (eval gnus-summary-line-format-spec) (point)) + 'gnus-number gnus-tmp-number) + (when (gnus-visual-p 'summary-highlight 'highlight) + (forward-line -1) + (run-hooks 'gnus-summary-update-hook) + (forward-line 1)))) (defun gnus-summary-update-line (&optional dont-update) ;; Update summary line after change. - (or (not gnus-summary-default-score) - gnus-summary-inhibit-highlight - (let ((gnus-summary-inhibit-highlight t) - (article (gnus-summary-article-number))) - (progn - (or dont-update - (if (and gnus-summary-mark-below - (< (gnus-summary-article-score) - gnus-summary-mark-below)) - (and (not (memq article gnus-newsgroup-marked)) - (not (memq article gnus-newsgroup-dormant)) - (memq article gnus-newsgroup-unreads) - (gnus-summary-mark-article-as-read gnus-low-score-mark)) - (and (eq (gnus-summary-article-mark) gnus-low-score-mark) - (gnus-summary-mark-article-as-unread gnus-unread-mark)))) - (and gnus-visual - (run-hooks 'gnus-summary-update-hook)))))) - -(defun gnus-summary-update-lines (&optional beg end) - ;; Mark article as read (or not) by taking into account scores. - (let ((beg (or beg (point-min))) - (end (or end (point-max)))) - (if (or (not gnus-summary-default-score) - gnus-summary-inhibit-highlight) - () - (let ((gnus-summary-inhibit-highlight t) - article) - (save-excursion - (set-buffer gnus-summary-buffer) - (goto-char beg) - (beginning-of-line) - (while (and (not (eobp)) (< (point) end)) - (if (and gnus-summary-mark-below - (< (or (cdr (assq - (setq article (get-text-property - (point) 'gnus-number)) - gnus-newsgroup-scored)) - gnus-summary-default-score 0) - gnus-summary-mark-below)) - ;; We want to possibly mark it as read... - (and (not (memq article gnus-newsgroup-marked)) - (not (memq article gnus-newsgroup-dormant)) - (memq article gnus-newsgroup-unreads) - (gnus-summary-mark-article-as-read gnus-low-score-mark)) - ;; We want to possibly mark it as unread. - (and (eq (get-text-property (point) 'gnus-mark) - gnus-low-score-mark) - (gnus-summary-mark-article-as-unread gnus-unread-mark))) - ;; Do the visual highlights at the same time. - (and gnus-visual (run-hooks 'gnus-summary-update-hook)) - (forward-line 1))))))) - -(defvar gnus-tmp-gathered nil) - -(defun gnus-summary-number-of-articles-in-thread (thread &optional char) + (when (and gnus-summary-default-score + (not gnus-summary-inhibit-highlight)) + (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion. + (article (gnus-summary-article-number)) + (score (gnus-summary-article-score article))) + (unless dont-update + (if (and gnus-summary-mark-below + (< (gnus-summary-article-score) + gnus-summary-mark-below)) + ;; This article has a low score, so we mark it as read. + (when (memq article gnus-newsgroup-unreads) + (gnus-summary-mark-article-as-read gnus-low-score-mark)) + (when (eq (gnus-summary-article-mark) gnus-low-score-mark) + ;; This article was previously marked as read on account + ;; of a low score, but now it has risen, so we mark it as + ;; unread. + (gnus-summary-mark-article-as-unread gnus-unread-mark))) + (gnus-summary-update-mark + (if (or (null gnus-summary-default-score) + (<= (abs (- score gnus-summary-default-score)) + gnus-summary-zcore-fuzz)) ? + (if (< score gnus-summary-default-score) + gnus-score-below-mark gnus-score-over-mark)) 'score)) + ;; Do visual highlighting. + (when (gnus-visual-p 'summary-highlight 'highlight) + (run-hooks 'gnus-summary-update-hook))))) + +(defvar gnus-tmp-new-adopts nil) + +(defun gnus-summary-number-of-articles-in-thread (thread &optional level char) ;; Sum up all elements (and sub-elements) in a list. (let* ((number ;; Fix by Luc Van Eycken . - (if (and (consp thread) (cdr thread)) - (apply - '+ 1 (mapcar - 'gnus-summary-number-of-articles-in-thread - (cdr thread))) - 1))) - (if char + (cond + ((and (consp thread) (cdr thread)) + (apply + '+ 1 (mapcar + 'gnus-summary-number-of-articles-in-thread (cdr thread)))) + ((null thread) + 1) + ((memq (mail-header-number (car thread)) gnus-newsgroup-limit) + 1) + (t 0)))) + (when (and level (zerop level) gnus-tmp-new-adopts) + (incf number + (apply '+ (mapcar + 'gnus-summary-number-of-articles-in-thread + gnus-tmp-new-adopts)))) + (if char (if (> number 1) gnus-not-empty-thread-mark gnus-empty-thread-mark) number))) -(defun gnus-summary-read-group - (group &optional show-all no-article kill-buffer) +(defun gnus-summary-set-local-parameters (group) + "Go through the local params of GROUP and set all variable specs in that list." + (let ((params (gnus-info-params (gnus-get-info group))) + elem) + (while params + (setq elem (car params) + params (cdr params)) + (and (consp elem) ; Has to be a cons. + (consp (cdr elem)) ; The cdr has to be a list. + (symbolp (car elem)) ; Has to be a symbol in there. + (not (memq (car elem) + '(quit-config to-address to-list to-group))) + (progn ; So we set it. + (make-local-variable (car elem)) + (set (car elem) (eval (nth 1 elem)))))))) + +(defun gnus-summary-read-group (group &optional show-all no-article + kill-buffer no-display) "Start reading news in newsgroup GROUP. If SHOW-ALL is non-nil, already read articles are also listed. -If NO-ARTICLE is non-nil, no article is selected initially." +If NO-ARTICLE is non-nil, no article is selected initially. +If NO-DISPLAY, don't generate a summary buffer." (gnus-message 5 "Retrieving newsgroup: %s..." group) (let* ((new-group (gnus-summary-setup-buffer group)) (quit-config (gnus-group-quit-config group)) (did-select (and new-group (gnus-select-newsgroup group show-all)))) - (cond + (cond + ;; This summary buffer exists already, so we just select it. ((not new-group) (gnus-set-global-variables) - (gnus-kill-buffer kill-buffer) + (when kill-buffer + (gnus-kill-or-deaden-summary kill-buffer)) (gnus-configure-windows 'summary 'force) (gnus-set-mode-line 'summary) - (gnus-summary-position-cursor) + (gnus-summary-position-point) (message "") t) - ((null did-select) - (and (eq major-mode 'gnus-summary-mode) - (not (equal (current-buffer) kill-buffer)) - (progn - (kill-buffer (current-buffer)) - (if (not quit-config) - (progn - (set-buffer gnus-group-buffer) - (gnus-group-jump-to-group group) - (gnus-group-next-unread-group 1)) - (if (not (buffer-name (car quit-config))) - (gnus-configure-windows 'group 'force) - (set-buffer (car quit-config)) - (and (eq major-mode 'gnus-summary-mode) - (gnus-set-global-variables)) - (gnus-configure-windows (cdr quit-config)))))) - (message "Can't select group") + ;; We couldn't select this group. + ((null did-select) + (when (and (eq major-mode 'gnus-summary-mode) + (not (equal (current-buffer) kill-buffer))) + (kill-buffer (current-buffer)) + (if (not quit-config) + (progn + (set-buffer gnus-group-buffer) + (gnus-group-jump-to-group group) + (gnus-group-next-unread-group 1)) + (if (not (buffer-name (car quit-config))) + (gnus-configure-windows 'group 'force) + (set-buffer (car quit-config)) + (and (eq major-mode 'gnus-summary-mode) + (gnus-set-global-variables)) + (gnus-configure-windows (cdr quit-config))))) + (gnus-message 3 "Can't select group") nil) + ;; The user did a `C-g' while prompting for number of articles, + ;; so we exit this group. ((eq did-select 'quit) (and (eq major-mode 'gnus-summary-mode) (not (equal (current-buffer) kill-buffer)) (kill-buffer (current-buffer))) - (gnus-kill-buffer kill-buffer) + (when kill-buffer + (gnus-kill-or-deaden-summary kill-buffer)) (if (not quit-config) (progn (set-buffer gnus-group-buffer) @@ -5999,38 +7773,64 @@ If NO-ARTICLE is non-nil, no article is selected initially." (and (eq major-mode 'gnus-summary-mode) (gnus-set-global-variables)) (gnus-configure-windows (cdr quit-config)))) + ;; Finally signal the quit. (signal 'quit nil)) + ;; The group was successfully selected. (t (gnus-set-global-variables) ;; Save the active value in effect when the group was entered. - (setq gnus-newsgroup-active + (setq gnus-newsgroup-active (gnus-copy-sequence - (gnus-gethash gnus-newsgroup-name gnus-active-hashtb))) - ;; You can change the subjects in this hook. + (gnus-active gnus-newsgroup-name))) + ;; You can change the summary buffer in some way with this hook. (run-hooks 'gnus-select-group-hook) - ;; Do score processing. - (and gnus-use-scoring (gnus-possibly-score-headers)) + ;; Set any local variables in the group parameters. + (gnus-summary-set-local-parameters gnus-newsgroup-name) (gnus-update-format-specifications) + ;; Do score processing. + (when gnus-use-scoring + (gnus-possibly-score-headers)) + ;; Check whether to fill in the gaps in the threads. + (when gnus-build-sparse-threads + (gnus-build-sparse-threads)) + ;; Find the initial limit. + (if gnus-show-threads + (if show-all + (let ((gnus-newsgroup-dormant nil)) + (gnus-summary-initial-limit show-all)) + (gnus-summary-initial-limit show-all)) + (setq gnus-newsgroup-limit + (mapcar + (lambda (header) (mail-header-number header)) + gnus-newsgroup-headers))) ;; Generate the summary buffer. - (gnus-summary-prepare) - (if (zerop (buffer-size)) - (cond (gnus-newsgroup-dormant - (gnus-summary-show-all-dormant)) - ((and gnus-newsgroup-scored show-all) - (gnus-summary-show-all-expunged)))) + (unless no-display + (gnus-summary-prepare)) + (when gnus-use-trees + (gnus-tree-open group) + (setq gnus-summary-highlight-line-function + 'gnus-tree-highlight-article)) + ;; If the summary buffer is empty, but there are some low-scored + ;; articles or some excluded dormants, we include these in the + ;; buffer. + (when (and (zerop (buffer-size)) + (not no-display)) + (cond (gnus-newsgroup-dormant + (gnus-summary-limit-include-dormant)) + ((and gnus-newsgroup-scored show-all) + (gnus-summary-limit-include-expunged)))) ;; Function `gnus-apply-kill-file' must be called in this hook. (run-hooks 'gnus-apply-kill-hook) - (if (zerop (buffer-size)) + (if (and (zerop (buffer-size)) + (not no-display)) (progn ;; This newsgroup is empty. (gnus-summary-catchup-and-exit nil t) ;Without confirmations. (gnus-message 6 "No unread news") - (gnus-kill-buffer kill-buffer) + (when kill-buffer + (gnus-kill-or-deaden-summary kill-buffer)) + ;; Return nil from this function. nil) - ;;(save-excursion - ;; (if kill-buffer - ;; (let ((gnus-summary-buffer kill-buffer)) - ;; (gnus-configure-windows 'group)))) ;; Hide conversation thread subtrees. We cannot do this in ;; gnus-summary-prepare-hook since kill processing may not ;; work with hidden articles. @@ -6038,330 +7838,252 @@ If NO-ARTICLE is non-nil, no article is selected initially." gnus-thread-hide-subtree (gnus-summary-hide-all-threads)) ;; Show first unread article if requested. - (goto-char (point-min)) (if (and (not no-article) - gnus-auto-select-first - (gnus-summary-first-unread-article)) - () + (not no-display) + gnus-newsgroup-unreads + gnus-auto-select-first) + (unless (if (eq gnus-auto-select-first 'best) + (gnus-summary-best-unread-article) + (gnus-summary-first-unread-article)) + (gnus-configure-windows 'summary)) + ;; Don't select any articles, just move point to the first + ;; article in the group. + (goto-char (point-min)) + (gnus-summary-position-point) + (gnus-set-mode-line 'summary) (gnus-configure-windows 'summary 'force)) - (gnus-set-mode-line 'summary) - (gnus-summary-position-cursor) - ;; If in async mode, we send some info to the backend. - (and gnus-newsgroup-async - (setq gnus-newsgroup-threads (nreverse gnus-newsgroup-threads)) - (gnus-request-asynchronous - gnus-newsgroup-name - (if (and gnus-asynchronous-article-function - (fboundp gnus-asynchronous-article-function)) - (funcall gnus-asynchronous-article-function - gnus-newsgroup-threads) - gnus-newsgroup-threads))) - (gnus-kill-buffer kill-buffer) - (if (not (get-buffer-window gnus-group-buffer)) - () - ;; gotta use windows, because recenter does weird stuff if + ;; If we are in async mode, we send some info to the backend. + (when gnus-newsgroup-async + (gnus-request-asynchronous gnus-newsgroup-name gnus-newsgroup-data)) + (when kill-buffer + (gnus-kill-or-deaden-summary kill-buffer)) + (when (get-buffer-window gnus-group-buffer t) + ;; Gotta use windows, because recenter does wierd stuff if ;; the current buffer ain't the displayed window. - (let ((owin (selected-window))) - (select-window (get-buffer-window gnus-group-buffer)) - (and (gnus-group-goto-group group) - (recenter)) - (select-window owin)))) + (let ((owin (selected-window))) + (select-window (get-buffer-window gnus-group-buffer t)) + (when (gnus-group-goto-group group) + (recenter)) + (select-window owin)))) + ;; Mark this buffer as "prepared". + (setq gnus-newsgroup-prepared t) t)))) (defun gnus-summary-prepare () - ;; Generate the summary buffer. + "Generate the summary buffer." (let ((buffer-read-only nil)) (erase-buffer) - (gnus-summary-prepare-threads - (if gnus-show-threads - (gnus-gather-threads - (gnus-sort-threads - (if (and gnus-summary-expunge-below - (not gnus-fetch-old-headers)) - (gnus-make-threads-and-expunge) - (gnus-make-threads)))) - gnus-newsgroup-headers) - 'cull) - (gnus-summary-update-lines) - ;; Create the header hashtb. - (gnus-make-headers-hashtable-by-number) + (setq gnus-newsgroup-data nil + gnus-newsgroup-data-reverse nil) + (run-hooks 'gnus-summary-generate-hook) + ;; Generate the buffer, either with threads or without. + (when gnus-newsgroup-headers + (gnus-summary-prepare-threads + (if gnus-show-threads + (gnus-sort-gathered-threads + (funcall gnus-summary-thread-gathering-function + (gnus-sort-threads + (gnus-cut-threads (gnus-make-threads))))) + ;; Unthreaded display. + (gnus-sort-articles gnus-newsgroup-headers)))) + (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data)) ;; Call hooks for modifying summary buffer. - ;; Suggested by sven@tde.LTH.Se (Sven Mattisson). (goto-char (point-min)) (run-hooks 'gnus-summary-prepare-hook))) -(defun gnus-gather-threads (threads) - "Gather threads that have lost their roots." +(defun gnus-gather-threads-by-subject (threads) + "Gather threads by looking at Subject headers." (if (not gnus-summary-make-false-root) - threads + threads (let ((hashtb (gnus-make-hashtable 1023)) (prev threads) (result threads) subject hthread whole-subject) (while threads - (setq whole-subject - (setq subject (mail-header-subject (car (car threads))))) - (if gnus-summary-gather-subject-limit - (or (and (numberp gnus-summary-gather-subject-limit) - (> (length subject) gnus-summary-gather-subject-limit) - (setq subject - (substring subject 0 - gnus-summary-gather-subject-limit))) - (and (eq 'fuzzy gnus-summary-gather-subject-limit) - (setq subject (gnus-simplify-subject-fuzzy subject)))) - (setq subject (gnus-simplify-subject-re subject))) - (if (setq hthread - (gnus-gethash subject hashtb)) - (progn - (or (stringp (car (car hthread))) + (setq whole-subject (mail-header-subject (caar threads))) + (setq subject + (cond + ;; Truncate the subject. + ((numberp gnus-summary-gather-subject-limit) + (setq subject (gnus-simplify-subject-re whole-subject)) + (if (> (length subject) gnus-summary-gather-subject-limit) + (substring subject 0 gnus-summary-gather-subject-limit) + subject)) + ;; Fuzzily simplify it. + ((eq 'fuzzy gnus-summary-gather-subject-limit) + (gnus-simplify-subject-fuzzy whole-subject)) + ;; Just remove the leading "Re:". + (t + (gnus-simplify-subject-re whole-subject)))) + + (if (and gnus-summary-gather-exclude-subject + (string-match gnus-summary-gather-exclude-subject + subject)) + () ; We don't want to do anything with this article. + ;; We simplify the subject before looking it up in the + ;; hash table. + + (if (setq hthread (gnus-gethash subject hashtb)) + (progn + ;; We enter a dummy root into the thread, if we + ;; haven't done that already. + (unless (stringp (caar hthread)) (setcar hthread (list whole-subject (car hthread)))) - (setcdr (car hthread) (nconc (cdr (car hthread)) - (list (car threads)))) - (setcdr prev (cdr threads)) - (setq threads prev)) - (gnus-sethash subject threads hashtb)) + ;; We add this new gathered thread to this gathered + ;; thread. + (setcdr (car hthread) + (nconc (cdar hthread) (list (car threads)))) + ;; Remove it from the list of threads. + (setcdr prev (cdr threads)) + (setq threads prev)) + ;; Enter this thread into the hash table. + (gnus-sethash subject threads hashtb))) (setq prev threads) (setq threads (cdr threads))) result))) -(defun gnus-make-threads () - ;; This function takes the dependencies already made by - ;; `gnus-get-newsgroup-headers' and builds the trees. First we go - ;; through the dependencies in the hash table and finds all the - ;; roots. Roots do not refer back to any valid articles. - (gnus-message 6 "Threading...") - (let (roots new-roots) - (and gnus-fetch-old-headers - (eq gnus-headers-retrieved-by 'nov) - (gnus-build-old-threads)) - (mapatoms - (lambda (refs) - (if (not (car (symbol-value refs))) - (setq roots (append (cdr (symbol-value refs)) roots)) - ;; Ok, these refer back to valid articles, but if - ;; `gnus-thread-ignore-subject' is nil, we have to check that - ;; the root has the same subject as its children. The children - ;; that do not are made into roots and removed from the list - ;; of children. - (or gnus-thread-ignore-subject - (let* ((prev (symbol-value refs)) - (subject (gnus-simplify-subject-re - (mail-header-subject (car prev)))) - (headers (cdr prev))) - (while headers - (if (not (string= subject - (gnus-simplify-subject-re - (mail-header-subject (car headers))))) - (progn - (setq new-roots (cons (car headers) new-roots)) - (setcdr prev (cdr headers))) - (setq prev headers)) - (setq headers (cdr headers))))))) - gnus-newsgroup-dependencies) - - ;; We enter the new roots into the dependencies structure to - ;; ensure that any possible later thread-regeneration will be - ;; possible. - (let ((r new-roots)) - (while r - (gnus-sethash (concat (mail-header-id (car r)) ".boo") - (list nil (car r)) gnus-newsgroup-dependencies) - (setq r (cdr r)))) - - (setq roots (nconc new-roots roots)) +(defun gnus-gather-threads-by-references (threads) + "Gather threads by looking at References headers." + (let ((idhashtb (gnus-make-hashtable 1023)) + (thhashtb (gnus-make-hashtable 1023)) + (prev threads) + (result threads) + ids references id gthread gid entered) + (while threads + (when (setq references (mail-header-references (caar threads))) + (setq id (mail-header-id (caar threads))) + (setq ids (gnus-split-references references)) + (setq entered nil) + (while ids + (if (not (setq gid (gnus-gethash (car ids) idhashtb))) + (progn + (gnus-sethash (car ids) id idhashtb) + (gnus-sethash id threads thhashtb)) + (setq gthread (gnus-gethash gid thhashtb)) + (unless entered + ;; We enter a dummy root into the thread, if we + ;; haven't done that already. + (unless (stringp (caar gthread)) + (setcar gthread (list (mail-header-subject (caar gthread)) + (car gthread)))) + ;; We add this new gathered thread to this gathered + ;; thread. + (setcdr (car gthread) + (nconc (cdar gthread) (list (car threads))))) + ;; Add it into the thread hash table. + (gnus-sethash id gthread thhashtb) + (setq entered t) + ;; Remove it from the list of threads. + (setcdr prev (cdr threads)) + (setq threads prev)) + (setq ids (cdr ids)))) + (setq prev threads) + (setq threads (cdr threads))) + result)) - (prog1 - (mapcar 'gnus-trim-thread - (apply 'append - (mapcar 'gnus-cut-thread - (mapcar 'gnus-make-sub-thread roots)))) - (gnus-message 6 "Threading...done")))) +(defun gnus-sort-gathered-threads (threads) + "Sort subtreads inside each gathered thread by article number." + (let ((result threads)) + (while threads + (when (stringp (caar threads)) + (setcdr (car threads) + (sort (cdar threads) 'gnus-thread-sort-by-number))) + (setq threads (cdr threads))) + result)) - -(defun gnus-make-threads-and-expunge () - ;; This function takes the dependencies already made by - ;; `gnus-get-newsgroup-headers' and builds the trees. First we go - ;; through the dependencies in the hash table and finds all the - ;; roots. Roots do not refer back to any valid articles. - (gnus-message 6 "Threading...") - (let ((default (or gnus-summary-default-score 0)) - (below gnus-summary-expunge-below) - roots article new-roots) - (and gnus-fetch-old-headers - (eq gnus-headers-retrieved-by 'nov) - (gnus-build-old-threads)) +(defun gnus-make-threads () + "Go through the dependency hashtb and find the roots. Return all threads." + (let (threads) (mapatoms (lambda (refs) - (if (not (car (symbol-value refs))) - ;; These articles do not refer back to any other articles - - ;; they are roots. - (let ((headers (cdr (symbol-value refs)))) - ;; We weed out the low-scored articles. - (while headers - (if (not (< (or (cdr (assq (mail-header-number (car headers)) - gnus-newsgroup-scored)) default) - below)) - ;; It is over. - (setq roots (cons (car headers) roots)) - ;; It is below, so we mark it as read. - (setq gnus-newsgroup-unreads - (delq (mail-header-number (car headers)) - gnus-newsgroup-unreads)) - (setq gnus-newsgroup-reads - (cons (cons (mail-header-number (car headers)) - gnus-low-score-mark) - gnus-newsgroup-reads))) - (setq headers (cdr headers)))) - ;; Ok, these refer back to valid articles, but if - ;; `gnus-thread-ignore-subject' is nil, we have to check that - ;; the root has the same subject as its children. The children - ;; that do not are made into roots and removed from the list - ;; of children. - (or gnus-thread-ignore-subject - (let* ((prev (symbol-value refs)) - (subject (gnus-simplify-subject-re - (mail-header-subject (car prev)))) - (headers (cdr prev))) - (while headers - (if (not (string= subject - (gnus-simplify-subject-re - (mail-header-subject (car headers))))) - (progn - (if (not (< (or (cdr (assq (mail-header-number - (car headers)) - gnus-newsgroup-scored)) - default) below)) - (setq new-roots (cons (car headers) new-roots)) - (setq gnus-newsgroup-unreads - (delq (mail-header-number (car headers)) - gnus-newsgroup-unreads)) - (setq gnus-newsgroup-reads - (cons (cons (mail-header-number (car headers)) - gnus-low-score-mark) - gnus-newsgroup-reads))) - (setcdr prev (cdr headers))) - (setq prev headers)) - (setq headers (cdr headers))))) - ;; If this article is expunged, some of the children might be - ;; roots. - (if (< (or (cdr (assq (mail-header-number (car (symbol-value refs))) - gnus-newsgroup-scored)) default) - below) - (let* ((prev (symbol-value refs)) - (headers (cdr prev))) - (while headers - (setq article (mail-header-number (car headers))) - (if (not (< (or (cdr (assq article gnus-newsgroup-scored)) - default) below)) - (progn (setq new-roots (cons (car headers) new-roots)) - (setq prev headers)) - (setq gnus-newsgroup-unreads - (delq article gnus-newsgroup-unreads)) - (setq gnus-newsgroup-reads - (cons (cons article gnus-low-score-mark) - gnus-newsgroup-reads)) - (setcdr prev (cdr headers))) - (setq headers (cdr headers)))) - ;; It was not expunged, but we look at expunged children. - (let* ((prev (symbol-value refs)) - (headers (cdr prev)) - article) - (while headers - (setq article (mail-header-number (car headers))) - (if (not (< (or (cdr (assq article gnus-newsgroup-scored)) - default) below)) - (setq prev headers) - (setq gnus-newsgroup-unreads - (delq article gnus-newsgroup-unreads)) - (setq gnus-newsgroup-reads - (cons (cons article gnus-low-score-mark) - gnus-newsgroup-reads)) - (setcdr prev (cdr headers))) - (setq headers (cdr headers))))))) + (unless (car (symbol-value refs)) + ;; These threads do not refer back to any other articles, + ;; so they're roots. + (setq threads (append (cdr (symbol-value refs)) threads)))) gnus-newsgroup-dependencies) - - ;; We enter the new roots into the dependencies structure to - ;; ensure that any possible later thread-regeneration will be - ;; possible. - (let ((r new-roots)) - (while r - (gnus-sethash (concat (mail-header-id (car r)) ".boo") - (list nil (car r)) gnus-newsgroup-dependencies) - (setq r (cdr r)))) - - (setq roots (nconc new-roots roots)) - - (prog1 - (mapcar 'gnus-trim-thread - (apply 'append - (mapcar 'gnus-cut-thread - (mapcar 'gnus-make-sub-thread roots)))) - (gnus-message 6 "Threading...done")))) - - -(defun gnus-cut-thread (thread) - ;; Remove leaf dormant or ancient articles from THREAD. - (let ((head (car thread)) - (tail (apply 'append (mapcar 'gnus-cut-thread (cdr thread))))) - (if (and (null tail) - (let ((number (mail-header-number head))) - (or (memq number gnus-newsgroup-ancient) - (memq number gnus-newsgroup-dormant) - (and gnus-summary-expunge-below - (eq gnus-fetch-old-headers 'some) - (< (or (cdr (assq number gnus-newsgroup-scored)) - gnus-summary-default-score 0) - gnus-summary-expunge-below) - (progn - (setq gnus-newsgroup-unreads - (delq number gnus-newsgroup-unreads)) - (setq gnus-newsgroup-reads - (cons (cons number gnus-low-score-mark) - gnus-newsgroup-reads)) - t))))) - nil - (list (cons head tail))))) - -(defun gnus-trim-thread (thread) - ;; Remove root ancient articles with only one child from THREAD. - (if (and (eq gnus-fetch-old-headers 'some) - (memq (mail-header-number (car thread)) gnus-newsgroup-ancient) - (= (length thread) 2)) - (gnus-trim-thread (nth 1 thread)) - thread)) - -(defun gnus-make-sub-thread (root) - ;; This function makes a sub-tree for a node in the tree. - (let ((children (reverse (cdr (gnus-gethash (downcase (mail-header-id root)) - gnus-newsgroup-dependencies))))) - (cons root (mapcar 'gnus-make-sub-thread children)))) + threads)) + +(defun gnus-build-sparse-threads () + (let ((headers gnus-newsgroup-headers) + (deps gnus-newsgroup-dependencies) + header references generation relations + cthread subject child end pthread relation) + ;; First we create an alist of generations/relations, where + ;; generations is how much we trust the ralation, and the relation + ;; is parent/child. + (gnus-message 7 "Making sparse threads...") + (save-excursion + (nnheader-set-temp-buffer " *gnus sparse threads*") + (while (setq header (pop headers)) + (when (and (setq references (mail-header-references header)) + (not (string= references ""))) + (insert references) + (setq child (mail-header-id header) + subject (mail-header-subject header)) + (setq generation 0) + (while (search-backward ">" nil t) + (setq end (1+ (point))) + (when (search-backward "<" nil t) + (push (list (incf generation) + child (setq child (buffer-substring (point) end)) + subject) + relations))) + (push (list (1+ generation) child nil subject) relations) + (erase-buffer))) + (kill-buffer (current-buffer))) + ;; Sort over trustworthiness. + (setq relations (sort relations (lambda (r1 r2) (< (car r1) (car r2))))) + (while (setq relation (pop relations)) + (when (if (boundp (setq cthread (intern (cadr relation) deps))) + (unless (car (symbol-value cthread)) + ;; Make this article the parent of these threads. + (setcar (symbol-value cthread) + (vector gnus-reffed-article-number + (cadddr relation) + "" "" + (cadr relation) + (or (caddr relation) "") 0 0 ""))) + (set cthread (list (vector gnus-reffed-article-number + (cadddr relation) + "" "" (cadr relation) + (or (caddr relation) "") 0 0 "")))) + (push gnus-reffed-article-number gnus-newsgroup-limit) + (push gnus-reffed-article-number gnus-newsgroup-sparse) + (push (cons gnus-reffed-article-number gnus-sparse-mark) + gnus-newsgroup-reads) + (decf gnus-reffed-article-number) + ;; Make this new thread the child of its parent. + (if (boundp (setq pthread (intern (or (caddr relation) "none") deps))) + (setcdr (symbol-value pthread) + (nconc (cdr (symbol-value pthread)) + (list (symbol-value cthread)))) + (set pthread (list nil (symbol-value cthread)))))) + (gnus-message 7 "Making sparse threads...done"))) (defun gnus-build-old-threads () ;; Look at all the articles that refer back to old articles, and - ;; fetch the headers for the articles that aren't there. This will + ;; fetch the headers for the articles that aren't there. This will ;; build complete threads - if the roots haven't been expired by the ;; server, that is. (let (id heads) (mapatoms (lambda (refs) - (if (not (car (symbol-value refs))) - (progn - (setq heads (cdr (symbol-value refs))) - (while heads - (if (not (memq (mail-header-number (car heads)) - gnus-newsgroup-dormant)) - (progn - (setq id (symbol-name refs)) - (while (and (setq id (gnus-build-get-header id)) - (not (car (gnus-gethash - id gnus-newsgroup-dependencies))))) - (setq heads nil)) - (setq heads (cdr heads))))))) + (when (not (car (symbol-value refs))) + (setq heads (cdr (symbol-value refs))) + (while heads + (if (memq (mail-header-number (caar heads)) + gnus-newsgroup-dormant) + (setq heads (cdr heads)) + (setq id (symbol-name refs)) + (while (and (setq id (gnus-build-get-header id)) + (not (car (gnus-gethash + id gnus-newsgroup-dependencies))))) + (setq heads nil))))) gnus-newsgroup-dependencies))) (defun gnus-build-get-header (id) ;; Look through the buffer of NOV lines and find the header to - ;; ID. Enter this line into the dependencies hash table, and return + ;; ID. Enter this line into the dependencies hash table, and return ;; the id of the parent article (if any). (let ((deps gnus-newsgroup-dependencies) found header) @@ -6371,110 +8093,321 @@ If NO-ARTICLE is non-nil, no article is selected initially." (goto-char (point-min)) (while (and (not found) (search-forward id nil t)) (beginning-of-line) - (setq found (looking-at + (setq found (looking-at (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s" (regexp-quote id)))) (or found (beginning-of-line 2))) - (if found - (let (ref) - (beginning-of-line) - (and - (setq header (gnus-nov-parse-line - (read (current-buffer)) deps)) - (setq ref (mail-header-references header)) - (string-match "\\(<[^>]+>\\) *$" ref) - (substring ref (match-beginning 1) (match-end 1)))))) - (and header - (setq gnus-newsgroup-headers (cons header gnus-newsgroup-headers) - gnus-newsgroup-ancient (cons (mail-header-number header) - gnus-newsgroup-ancient)))))) - -;; Re-build the thread containing ID. + (when found + (beginning-of-line) + (and + (setq header (gnus-nov-parse-line + (read (current-buffer)) deps)) + (gnus-parent-id (mail-header-references header))))) + (when header + (let ((number (mail-header-number header))) + (push number gnus-newsgroup-limit) + (push header gnus-newsgroup-headers) + (if (memq number gnus-newsgroup-unselected) + (progn + (push number gnus-newsgroup-unreads) + (setq gnus-newsgroup-unselected + (delq number gnus-newsgroup-unselected))) + (push number gnus-newsgroup-ancient))))))) + +(defun gnus-summary-update-article (article &optional iheader) + "Update ARTICLE in the summary buffer." + (set-buffer gnus-summary-buffer) + (let* ((header (or iheader (gnus-summary-article-header article))) + (id (mail-header-id header)) + (data (gnus-data-find article)) + (thread (gnus-id-to-thread id)) + (references (mail-header-references header)) + (parent + (gnus-id-to-thread + (or (gnus-parent-id + (if (and references + (not (equal "" references))) + references)) + "none"))) + (buffer-read-only nil) + (old (car thread)) + (number (mail-header-number header)) + pos) + (when thread + ;; !!! Should this be in or not? + (unless iheader + (setcar thread nil)) + (when parent + (delq thread parent)) + (if (gnus-summary-insert-subject id header iheader) + ;; Set the (possibly) new article number in the data structure. + (gnus-data-set-number data (gnus-id-to-article id)) + (setcar thread old) + nil)))) + (defun gnus-rebuild-thread (id) + "Rebuild the thread containing ID." + (let ((buffer-read-only nil) + current thread data) + (if (not gnus-show-threads) + (setq thread (list (car (gnus-id-to-thread id)))) + ;; Get the thread this article is part of. + (setq thread (gnus-remove-thread id))) + (setq current (save-excursion + (and (zerop (forward-line -1)) + (gnus-summary-article-number)))) + ;; If this is a gathered thread, we have to go some re-gathering. + (when (stringp (car thread)) + (let ((subject (car thread)) + roots thr) + (setq thread (cdr thread)) + (while thread + (unless (memq (setq thr (gnus-id-to-thread + (gnus-root-id + (mail-header-id (caar thread))))) + roots) + (push thr roots)) + (setq thread (cdr thread))) + ;; We now have all (unique) roots. + (if (= (length roots) 1) + ;; All the loose roots are now one solid root. + (setq thread (car roots)) + (setq thread (cons subject (gnus-sort-threads roots)))))) + (let (threads) + ;; We then insert this thread into the summary buffer. + (let (gnus-newsgroup-data gnus-newsgroup-threads) + (gnus-summary-prepare-threads (gnus-cut-threads (list thread))) + (setq data (nreverse gnus-newsgroup-data)) + (setq threads gnus-newsgroup-threads)) + ;; We splice the new data into the data structure. + (gnus-data-enter-list current data) + (gnus-data-compute-positions) + (setq gnus-newsgroup-threads (nconc threads gnus-newsgroup-threads))))) + +(defun gnus-number-to-header (number) + "Return the header for article NUMBER." + (let ((headers gnus-newsgroup-headers)) + (while (and headers + (not (= number (mail-header-number (car headers))))) + (pop headers)) + (when headers + (car headers)))) + +(defun gnus-id-to-thread (id) + "Return the (sub-)thread where ID appears." + (gnus-gethash id gnus-newsgroup-dependencies)) + +(defun gnus-id-to-article (id) + "Return the article number of ID." + (let ((thread (gnus-id-to-thread id))) + (when (and thread + (car thread)) + (mail-header-number (car thread))))) + +(defun gnus-id-to-header (id) + "Return the article headers of ID." + (car (gnus-id-to-thread id))) + +(defun gnus-article-displayed-root-p (article) + "Say whether ARTICLE is a root(ish) article." + (let ((level (gnus-summary-thread-level article)) + (refs (mail-header-references (gnus-summary-article-header article))) + particle) + (cond + ((null level) nil) + ((zerop level) t) + ((null refs) t) + ((null (gnus-parent-id refs)) t) + ((and (= 1 level) + (null (setq particle (gnus-id-to-article + (gnus-parent-id refs)))) + (null (gnus-summary-thread-level particle))))))) + +(defun gnus-root-id (id) + "Return the id of the root of the thread where ID appears." + (let (last-id prev) + (while (and id (setq prev (car (gnus-gethash + id gnus-newsgroup-dependencies)))) + (setq last-id id + id (gnus-parent-id (mail-header-references prev)))) + last-id)) + +(defun gnus-remove-thread (id &optional dont-remove) + "Remove the thread that has ID in it." (let ((dep gnus-newsgroup-dependencies) - (buffer-read-only nil) - parent headers refs thread art) - (while (and id (setq headers - (car (setq art (gnus-gethash (downcase id) dep))))) - (setq parent art) - (setq id (and (setq refs (mail-header-references headers)) - (string-match "\\(<[^>]+>\\) *$" refs) - (substring refs (match-beginning 1) (match-end 1))))) - (setq thread (gnus-make-sub-thread (car parent))) - (gnus-rebuild-remove-articles thread) - (let ((beg (point))) - (gnus-summary-prepare-threads (list thread)) - (gnus-summary-update-lines beg (point))))) - -;; Delete all lines in the summary buffer that correspond to articles -;; in this thread. -(defun gnus-rebuild-remove-articles (thread) - (and (gnus-summary-goto-subject (mail-header-number (car thread))) - (gnus-delete-line)) - (mapcar (lambda (th) (gnus-rebuild-remove-articles th)) (cdr thread))) + headers thread last-id) + ;; First go up in this thread until we find the root. + (setq last-id (gnus-root-id id)) + (setq headers (list (car (gnus-id-to-thread last-id)) + (caadr (gnus-id-to-thread last-id)))) + ;; We have now found the real root of this thread. It might have + ;; been gathered into some loose thread, so we have to search + ;; through the threads to find the thread we wanted. + (let ((threads gnus-newsgroup-threads) + sub) + (while threads + (setq sub (car threads)) + (if (stringp (car sub)) + ;; This is a gathered threads, so we look at the roots + ;; below it to find whether this article in in this + ;; gathered root. + (progn + (setq sub (cdr sub)) + (while sub + (when (member (caar sub) headers) + (setq thread (car threads) + threads nil + sub nil)) + (setq sub (cdr sub)))) + ;; It's an ordinary thread, so we check it. + (when (eq (car sub) (car headers)) + (setq thread sub + threads nil))) + (setq threads (cdr threads))) + ;; If this article is in no thread, then it's a root. + (if thread + (unless dont-remove + (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads))) + (setq thread (gnus-gethash last-id dep))) + (when thread + (prog1 + thread ; We return this thread. + (unless dont-remove + (if (stringp (car thread)) + (progn + ;; If we use dummy roots, then we have to remove the + ;; dummy root as well. + (when (eq gnus-summary-make-false-root 'dummy) + ;; Uhm. + ) + (setq thread (cdr thread)) + (while thread + (gnus-remove-thread-1 (car thread)) + (setq thread (cdr thread)))) + (gnus-remove-thread-1 thread)))))))) + +(defun gnus-remove-thread-1 (thread) + "Remove the thread THREAD recursively." + (let ((number (mail-header-number (car thread))) + pos) + (when (setq pos (text-property-any + (point-min) (point-max) 'gnus-number number)) + (goto-char pos) + (gnus-delete-line) + (gnus-data-remove number)) + (setq thread (cdr thread)) + (while thread + (gnus-remove-thread-1 (pop thread))))) (defun gnus-sort-threads (threads) - ;; Sort threads as specified in `gnus-thread-sort-functions'. - (let ((fun gnus-thread-sort-functions)) - (while fun - (gnus-message 6 "Sorting with %S..." fun) - (setq threads (sort threads (car fun)) - fun (cdr fun)))) - (if gnus-thread-sort-functions - (gnus-message 6 "Sorting...done")) - threads) - + "Sort THREADS." + (if (not gnus-thread-sort-functions) + threads + (let ((func (if (= 1 (length gnus-thread-sort-functions)) + (car gnus-thread-sort-functions) + `(lambda (t1 t2) + ,(gnus-make-sort-function + (reverse gnus-thread-sort-functions)))))) + (gnus-message 7 "Sorting threads...") + (prog1 + (sort threads func) + (gnus-message 7 "Sorting threads...done"))))) + +(defun gnus-sort-articles (articles) + "Sort ARTICLES." + (when gnus-article-sort-functions + (let ((func (if (= 1 (length gnus-article-sort-functions)) + (car gnus-article-sort-functions) + `(lambda (t1 t2) + ,(gnus-make-sort-function + (reverse gnus-article-sort-functions)))))) + (gnus-message 7 "Sorting articles...") + (prog1 + (setq gnus-newsgroup-headers (sort articles func)) + (gnus-message 7 "Sorting articles...done"))))) + +(defun gnus-make-sort-function (funs) + "Return a composite sort condition based on the functions in FUNC." + (if (cdr funs) + `(or (,(car funs) t1 t2) + (and (not (,(car funs) t2 t1)) + ,(gnus-make-sort-function (cdr funs)))) + `(,(car funs) t1 t2))) + ;; Written by Hallvard B Furuseth . (defmacro gnus-thread-header (thread) ;; Return header of first article in THREAD. - ;; Note that THREAD must never, evr be anything else than a variable - + ;; Note that THREAD must never, ever be anything else than a variable - ;; using some other form will lead to serious barfage. (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread))) ;; (8% speedup to gnus-summary-prepare, just for fun :-) - (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207" ; + (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207" ; (vector thread) 2)) +(defsubst gnus-article-sort-by-number (h1 h2) + "Sort articles by article number." + (< (mail-header-number h1) + (mail-header-number h2))) + (defun gnus-thread-sort-by-number (h1 h2) "Sort threads by root article number." - (< (mail-header-number (gnus-thread-header h1)) - (mail-header-number (gnus-thread-header h2)))) + (gnus-article-sort-by-number + (gnus-thread-header h1) (gnus-thread-header h2))) -(defun gnus-thread-sort-by-author (h1 h2) - "Sort threads by root author." +(defsubst gnus-article-sort-by-author (h1 h2) + "Sort articles by root author." (string-lessp - (let ((extract (funcall + (let ((extract (funcall gnus-extract-address-components - (mail-header-from (gnus-thread-header h1))))) + (mail-header-from h1)))) (or (car extract) (cdr extract))) (let ((extract (funcall - gnus-extract-address-components - (mail-header-from (gnus-thread-header h2))))) + gnus-extract-address-components + (mail-header-from h2)))) (or (car extract) (cdr extract))))) +(defun gnus-thread-sort-by-author (h1 h2) + "Sort threads by root author." + (gnus-article-sort-by-author + (gnus-thread-header h1) (gnus-thread-header h2))) + +(defsubst gnus-article-sort-by-subject (h1 h2) + "Sort articles by root subject." + (string-lessp + (downcase (gnus-simplify-subject-re (mail-header-subject h1))) + (downcase (gnus-simplify-subject-re (mail-header-subject h2))))) + (defun gnus-thread-sort-by-subject (h1 h2) "Sort threads by root subject." + (gnus-article-sort-by-subject + (gnus-thread-header h1) (gnus-thread-header h2))) + +(defsubst gnus-article-sort-by-date (h1 h2) + "Sort articles by root article date." (string-lessp - (downcase (gnus-simplify-subject-re - (mail-header-subject (gnus-thread-header h1)))) - (downcase (gnus-simplify-subject-re - (mail-header-subject (gnus-thread-header h2)))))) + (inline (gnus-sortable-date (mail-header-date h1))) + (inline (gnus-sortable-date (mail-header-date h2))))) (defun gnus-thread-sort-by-date (h1 h2) "Sort threads by root article date." - (string-lessp - (gnus-sortable-date (mail-header-date (gnus-thread-header h1))) - (gnus-sortable-date (mail-header-date (gnus-thread-header h2))))) + (gnus-article-sort-by-date + (gnus-thread-header h1) (gnus-thread-header h2))) -(defun gnus-thread-sort-by-score (h1 h2) - "Sort threads by root article score. +(defsubst gnus-article-sort-by-score (h1 h2) + "Sort articles by root article score. Unscored articles will be counted as having a score of zero." - (> (or (cdr (assq (mail-header-number (gnus-thread-header h1)) + (> (or (cdr (assq (mail-header-number h1) gnus-newsgroup-scored)) gnus-summary-default-score 0) - (or (cdr (assq (mail-header-number (gnus-thread-header h2)) + (or (cdr (assq (mail-header-number h2) gnus-newsgroup-scored)) gnus-summary-default-score 0))) +(defun gnus-thread-sort-by-score (h1 h2) + "Sort threads by root article score." + (gnus-article-sort-by-score + (gnus-thread-header h1) (gnus-thread-header h2))) + (defun gnus-thread-sort-by-total-score (h1 h2) "Sort threads by the sum of all scores in the thread. Unscored articles will be counted as having a score of zero." @@ -6482,12 +8415,15 @@ Unscored articles will be counted as having a score of zero." (defun gnus-thread-total-score (thread) ;; This function find the total score of THREAD. - (if (consp thread) - (if (stringp (car thread)) - (apply gnus-thread-score-function 0 - (mapcar 'gnus-thread-total-score-1 (cdr thread))) - (gnus-thread-total-score-1 thread)) - (gnus-thread-total-score-1 (list thread)))) + (cond ((null thread) + 0) + ((consp thread) + (if (stringp (car thread)) + (apply gnus-thread-score-function 0 + (mapcar 'gnus-thread-total-score-1 (cdr thread))) + (gnus-thread-total-score-1 thread))) + (t + (gnus-thread-total-score-1 (list thread))))) (defun gnus-thread-total-score-1 (root) ;; This function find the total score of the thread below ROOT. @@ -6496,303 +8432,418 @@ Unscored articles will be counted as having a score of zero." (or (cdr (assq (mail-header-number root) gnus-newsgroup-scored)) gnus-summary-default-score 0) (mapcar 'gnus-thread-total-score - (cdr (gnus-gethash (downcase (mail-header-id root)) + (cdr (gnus-gethash (mail-header-id root) gnus-newsgroup-dependencies))))) ;; Added by Per Abrahamsen . -(defvar gnus-tmp-prev-subject "") - -(defun gnus-summary-prepare-threads (threads &optional cull) - "Prepare summary buffer from THREADS and indentation LEVEL. -THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])' +(defvar gnus-tmp-prev-subject nil) +(defvar gnus-tmp-false-parent nil) +(defvar gnus-tmp-root-expunged nil) +(defvar gnus-tmp-dummy-line nil) + +(defun gnus-summary-prepare-threads (threads) + "Prepare summary buffer from THREADS and indentation LEVEL. +THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])' or a straight list of headers." - (gnus-message 5 "Generating summary...") - (let ((level 0) - thread header number subject stack state gnus-tmp-gathered) + (gnus-message 7 "Generating summary...") + + (setq gnus-newsgroup-threads threads) + (beginning-of-line) + + (let ((gnus-tmp-level 0) + (default-score (or gnus-summary-default-score 0)) + (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight)) + thread number subject stack state gnus-tmp-gathered beg-match + new-roots gnus-tmp-new-adopts thread-end + gnus-tmp-header gnus-tmp-unread + gnus-tmp-replied gnus-tmp-subject-or-nil + gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score + gnus-tmp-score-char gnus-tmp-from gnus-tmp-name + gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket) + + (setq gnus-tmp-prev-subject nil) + (if (vectorp (car threads)) ;; If this is a straight (sic) list of headers, then a ;; threaded summary display isn't required, so we just create ;; an unthreaded one. - (gnus-summary-prepare-unthreaded threads cull) + (gnus-summary-prepare-unthreaded threads) ;; Do the threaded display. - (while (or threads stack) - - (if threads - ;; If there are some threads, we do them before the - ;; threads on the stack. - (setq thread threads - header (car (car thread))) - ;; There were no current threads, so we pop something off - ;; the stack. - (setq state (car stack) - level (car state) - thread (cdr state) - stack (cdr stack) - header (car (car thread)))) - - (if (stringp header) - (progn - ;; The header is a dummy root. - (cond - ((eq gnus-summary-make-false-root 'adopt) - ;; We let the first article adopt the rest. - (let ((th (car (cdr (car thread))))) - (while (cdr th) - (setq th (cdr th))) - (setcdr th (cdr (cdr (car thread)))) - (setq gnus-tmp-gathered - (nconc (mapcar - (lambda (h) (mail-header-number (car h))) - (cdr (cdr (car thread)))) - gnus-tmp-gathered)) - (setcdr (cdr (car thread)) nil)) - (setq level -1)) - ((eq gnus-summary-make-false-root 'empty) - ;; We print adopted articles with empty subject fields. - (setq gnus-tmp-gathered - (nconc (mapcar - (lambda (h) (mail-header-number (car h))) - (cdr (cdr (car thread)))) - gnus-tmp-gathered)) - (setq level -1)) - ((eq gnus-summary-make-false-root 'dummy) - ;; We output a dummy root. - (gnus-summary-insert-dummy-line - nil header (mail-header-number - (car (car (cdr (car thread))))))) - (t - ;; We do not make a root for the gathered - ;; sub-threads at all. - (setq level -1)))) - - (setq number (mail-header-number header) - subject (mail-header-subject header)) - - ;; Do the async thing. - (and gnus-newsgroup-async - (setq gnus-newsgroup-threads - (cons (cons number (mail-header-lines header)) - gnus-newsgroup-threads))) - - ;; We may have to root out some bad articles... - (and cull - (= level 0) - (cond ((and (memq (setq number (mail-header-number header)) - gnus-newsgroup-dormant) - (null thread)) - (setq header nil)) - ((and gnus-summary-expunge-below - (< (or (cdr (assq number gnus-newsgroup-scored)) - gnus-summary-default-score 0) - gnus-summary-expunge-below)) - (setq header nil) - (setq gnus-newsgroup-unreads - (delq number gnus-newsgroup-unreads)) - (setq gnus-newsgroup-reads - (cons (cons number gnus-low-score-mark) - gnus-newsgroup-reads))))) - - (and - header - (progn - (inline - (gnus-summary-insert-line - nil header level nil - (cond - ((memq number gnus-newsgroup-marked) gnus-ticked-mark) - ((memq number gnus-newsgroup-dormant) gnus-dormant-mark) - ((memq number gnus-newsgroup-unreads) gnus-unread-mark) - ((memq number gnus-newsgroup-expirable) gnus-expirable-mark) - (t (or (cdr (assq number gnus-newsgroup-reads)) - gnus-ancient-mark))) - (memq number gnus-newsgroup-replied) - (memq number gnus-newsgroup-expirable) - (cond - ((and gnus-thread-ignore-subject - (not (string= - (gnus-simplify-subject-re gnus-tmp-prev-subject) - (gnus-simplify-subject-re subject)))) - subject) - ((zerop level) - (if (and (eq gnus-summary-make-false-root 'empty) - (memq number gnus-tmp-gathered)) - gnus-summary-same-subject - subject)) - (t gnus-summary-same-subject)) - (and (eq gnus-summary-make-false-root 'adopt) + (while (or threads stack gnus-tmp-new-adopts new-roots) + + (if (and (= gnus-tmp-level 0) + (not (setq gnus-tmp-dummy-line nil)) + (or (not stack) + (= (caar stack) 0)) + (not gnus-tmp-false-parent) + (or gnus-tmp-new-adopts new-roots)) + (if gnus-tmp-new-adopts + (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1) + thread (list (car gnus-tmp-new-adopts)) + gnus-tmp-header (caar thread) + gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts)) + (if new-roots + (setq thread (list (car new-roots)) + gnus-tmp-header (caar thread) + new-roots (cdr new-roots)))) + + (if threads + ;; If there are some threads, we do them before the + ;; threads on the stack. + (setq thread threads + gnus-tmp-header (caar thread)) + ;; There were no current threads, so we pop something off + ;; the stack. + (setq state (car stack) + gnus-tmp-level (car state) + thread (cdr state) + stack (cdr stack) + gnus-tmp-header (caar thread)))) + + (setq gnus-tmp-false-parent nil) + (setq gnus-tmp-root-expunged nil) + (setq thread-end nil) + + (if (stringp gnus-tmp-header) + ;; The header is a dummy root. + (cond + ((eq gnus-summary-make-false-root 'adopt) + ;; We let the first article adopt the rest. + (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts + (cddar thread))) + (setq gnus-tmp-gathered + (nconc (mapcar + (lambda (h) (mail-header-number (car h))) + (cddar thread)) + gnus-tmp-gathered)) + (setq thread (cons (list (caar thread) + (cadar thread)) + (cdr thread))) + (setq gnus-tmp-level -1 + gnus-tmp-false-parent t)) + ((eq gnus-summary-make-false-root 'empty) + ;; We print adopted articles with empty subject fields. + (setq gnus-tmp-gathered + (nconc (mapcar + (lambda (h) (mail-header-number (car h))) + (cddar thread)) + gnus-tmp-gathered)) + (setq gnus-tmp-level -1)) + ((eq gnus-summary-make-false-root 'dummy) + ;; We remember that we probably want to output a dummy + ;; root. + (setq gnus-tmp-dummy-line gnus-tmp-header) + (setq gnus-tmp-prev-subject gnus-tmp-header)) + (t + ;; We do not make a root for the gathered + ;; sub-threads at all. + (setq gnus-tmp-level -1))) + + (setq number (mail-header-number gnus-tmp-header) + subject (mail-header-subject gnus-tmp-header)) + + (cond + ;; If the thread has changed subject, we might want to make + ;; this subthread into a root. + ((and (null gnus-thread-ignore-subject) + (not (zerop gnus-tmp-level)) + gnus-tmp-prev-subject + (not (inline + (gnus-subject-equal gnus-tmp-prev-subject subject)))) + (setq new-roots (nconc new-roots (list (car thread))) + thread-end t + gnus-tmp-header nil)) + ;; If the article lies outside the current limit, + ;; then we do not display it. + ((and (not (memq number gnus-newsgroup-limit)) + (not gnus-tmp-dummy-line)) + (setq gnus-tmp-gathered + (nconc (mapcar + (lambda (h) (mail-header-number (car h))) + (cdar thread)) + gnus-tmp-gathered)) + (setq gnus-tmp-new-adopts (if (cdar thread) + (append gnus-tmp-new-adopts + (cdar thread)) + gnus-tmp-new-adopts) + thread-end t + gnus-tmp-header nil) + (when (zerop gnus-tmp-level) + (setq gnus-tmp-root-expunged t))) + ;; Perhaps this article is to be marked as read? + ((and gnus-summary-mark-below + (< (or (cdr (assq number gnus-newsgroup-scored)) + default-score) + gnus-summary-mark-below) + ;; Don't touch sparse articles. + (not (memq number gnus-newsgroup-sparse)) + (not (memq number gnus-newsgroup-ancient))) + (setq gnus-newsgroup-unreads + (delq number gnus-newsgroup-unreads)) + (if gnus-newsgroup-auto-expire + (push number gnus-newsgroup-expirable) + (push (cons number gnus-low-score-mark) + gnus-newsgroup-reads)))) + + (when gnus-tmp-header + ;; We may have an old dummy line to output before this + ;; article. + (when gnus-tmp-dummy-line + (gnus-summary-insert-dummy-line + gnus-tmp-dummy-line (mail-header-number gnus-tmp-header)) + (setq gnus-tmp-dummy-line nil)) + + ;; Compute the mark. + (setq + gnus-tmp-unread + (cond + ((memq number gnus-newsgroup-unreads) gnus-unread-mark) + ((memq number gnus-newsgroup-marked) gnus-ticked-mark) + ((memq number gnus-newsgroup-dormant) gnus-dormant-mark) + ((memq number gnus-newsgroup-expirable) gnus-expirable-mark) + (t (or (cdr (assq number gnus-newsgroup-reads)) + gnus-ancient-mark)))) + + (push (gnus-data-make number gnus-tmp-unread (1+ (point)) + gnus-tmp-header gnus-tmp-level) + gnus-newsgroup-data) + + ;; Actually insert the line. + (setq + gnus-tmp-subject-or-nil + (cond + ((and gnus-thread-ignore-subject + gnus-tmp-prev-subject + (not (inline (gnus-subject-equal + gnus-tmp-prev-subject subject)))) + subject) + ((zerop gnus-tmp-level) + (if (and (eq gnus-summary-make-false-root 'empty) + (memq number gnus-tmp-gathered) + gnus-tmp-prev-subject + (inline (gnus-subject-equal + gnus-tmp-prev-subject subject))) + gnus-summary-same-subject + subject)) + (t gnus-summary-same-subject))) + (if (and (eq gnus-summary-make-false-root 'adopt) + (= gnus-tmp-level 1) (memq number gnus-tmp-gathered)) - (cdr (assq number gnus-newsgroup-scored)) - (memq number gnus-newsgroup-processable)) - - (setq gnus-tmp-prev-subject subject))))) - - (if (nth 1 thread) - (setq stack (cons (cons (max 0 level) (nthcdr 1 thread)) stack))) - (setq level (1+ level)) - (setq threads (cdr (car thread)))))) - (gnus-message 5 "Generating summary...done")) - - - -(defun gnus-summary-prepare-unthreaded (headers &optional cull) - (let (header number) - - ;; Do the async thing, if that is required. - (if gnus-newsgroup-async - (setq gnus-newsgroup-threads - (mapcar (lambda (h) - (cons (mail-header-number h) (mail-header-lines h))) - headers))) + (setq gnus-tmp-opening-bracket ?\< + gnus-tmp-closing-bracket ?\>) + (setq gnus-tmp-opening-bracket ?\[ + gnus-tmp-closing-bracket ?\])) + (setq + gnus-tmp-indentation + (aref gnus-thread-indent-array gnus-tmp-level) + gnus-tmp-lines (mail-header-lines gnus-tmp-header) + gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored)) + gnus-summary-default-score 0) + gnus-tmp-score-char + (if (or (null gnus-summary-default-score) + (<= (abs (- gnus-tmp-score gnus-summary-default-score)) + gnus-summary-zcore-fuzz)) ? + (if (< gnus-tmp-score gnus-summary-default-score) + gnus-score-below-mark gnus-score-over-mark)) + gnus-tmp-replied + (cond ((memq number gnus-newsgroup-processable) + gnus-process-mark) + ((memq number gnus-newsgroup-cached) + gnus-cached-mark) + ((memq number gnus-newsgroup-replied) + gnus-replied-mark) + ((memq number gnus-newsgroup-saved) + gnus-saved-mark) + (t gnus-unread-mark)) + gnus-tmp-from (mail-header-from gnus-tmp-header) + gnus-tmp-name + (cond + ((string-match "(.+)" gnus-tmp-from) + (substring gnus-tmp-from + (1+ (match-beginning 0)) (1- (match-end 0)))) + ((string-match "<[^>]+> *$" gnus-tmp-from) + (setq beg-match (match-beginning 0)) + (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from) + (substring gnus-tmp-from (1+ (match-beginning 0)) + (1- (match-end 0)))) + (substring gnus-tmp-from 0 beg-match))) + (t gnus-tmp-from))) + (when (string= gnus-tmp-name "") + (setq gnus-tmp-name gnus-tmp-from)) + (or (numberp gnus-tmp-lines) (setq gnus-tmp-lines 0)) + (gnus-put-text-property + (point) + (progn (eval gnus-summary-line-format-spec) (point)) + 'gnus-number number) + (when gnus-visual-p + (forward-line -1) + (run-hooks 'gnus-summary-update-hook) + (forward-line 1)) + + (setq gnus-tmp-prev-subject subject))) + + (when (nth 1 thread) + (push (cons (max 0 gnus-tmp-level) (nthcdr 1 thread)) stack)) + (incf gnus-tmp-level) + (setq threads (if thread-end nil (cdar thread))) + (unless threads + (setq gnus-tmp-level 0))))) + (gnus-message 7 "Generating summary...done")) + +(defun gnus-summary-prepare-unthreaded (headers) + "Generate an unthreaded summary buffer based on HEADERS." + (let (header number mark) (while headers - (setq header (car headers) - headers (cdr headers) - number (mail-header-number header)) - ;; We may have to root out some bad articles... - (cond - ((and cull - (memq (setq number (mail-header-number header)) - gnus-newsgroup-dormant))) - ((and cull gnus-summary-expunge-below - (< (or (cdr (assq number gnus-newsgroup-scored)) - gnus-summary-default-score 0) - gnus-summary-expunge-below)) - (setq gnus-newsgroup-unreads - (delq number gnus-newsgroup-unreads)) - (setq gnus-newsgroup-reads - (cons (cons number gnus-low-score-mark) - gnus-newsgroup-reads))) - (t - (gnus-summary-insert-line - nil header 0 nil - (cond ((memq number gnus-newsgroup-marked) gnus-ticked-mark) + (when (memq (setq number (mail-header-number + (setq header (pop headers)))) + gnus-newsgroup-limit) + ;; Mark article as read when it has a low score. + (when (and gnus-summary-mark-below + (< (or (cdr (assq number gnus-newsgroup-scored)) + gnus-summary-default-score 0) + gnus-summary-mark-below) + (not (memq number gnus-newsgroup-ancient))) + (setq gnus-newsgroup-unreads + (delq number gnus-newsgroup-unreads)) + (if gnus-newsgroup-auto-expire + (push number gnus-newsgroup-expirable) + (push (cons number gnus-low-score-mark) + gnus-newsgroup-reads))) + + (setq mark + (cond + ((memq number gnus-newsgroup-marked) gnus-ticked-mark) ((memq number gnus-newsgroup-dormant) gnus-dormant-mark) ((memq number gnus-newsgroup-unreads) gnus-unread-mark) ((memq number gnus-newsgroup-expirable) gnus-expirable-mark) (t (or (cdr (assq number gnus-newsgroup-reads)) - gnus-ancient-mark))) - (memq number gnus-newsgroup-replied) + gnus-ancient-mark)))) + (setq gnus-newsgroup-data + (cons (gnus-data-make number mark (1+ (point)) header 0) + gnus-newsgroup-data)) + (gnus-summary-insert-line + header 0 nil mark (memq number gnus-newsgroup-replied) (memq number gnus-newsgroup-expirable) (mail-header-subject header) nil (cdr (assq number gnus-newsgroup-scored)) - (memq number gnus-newsgroup-processable))))))) + (memq number gnus-newsgroup-processable)))))) (defun gnus-select-newsgroup (group &optional read-all) "Select newsgroup GROUP. If READ-ALL is non-nil, all articles in the group are selected." (let* ((entry (gnus-gethash group gnus-newsrc-hashtb)) (info (nth 2 entry)) - articles) + articles fetched-articles cached) (or (gnus-check-server (setq gnus-current-select-method (gnus-find-method-for-group group))) (error "Couldn't open server")) - + (or (and entry (not (eq (car entry) t))) ; Either it's active... - (gnus-activate-group group) ; Or we can activate it... - (progn ; Or we bug out. - (kill-buffer (current-buffer)) - (error "Couldn't request group %s: %s" + (gnus-activate-group group) ; Or we can activate it... + (progn ; Or we bug out. + (when (equal major-mode 'gnus-summary-mode) + (kill-buffer (current-buffer))) + (error "Couldn't request group %s: %s" group (gnus-status-message group)))) + (unless (gnus-request-group group t) + (when (equal major-mode 'gnus-summary-mode) + (kill-buffer (current-buffer))) + (error "Couldn't request group %s: %s" + group (gnus-status-message group))) + (setq gnus-newsgroup-name group) (setq gnus-newsgroup-unselected nil) (setq gnus-newsgroup-unreads (gnus-list-of-unread-articles group)) (and gnus-asynchronous - (gnus-check-backend-function + (gnus-check-backend-function 'request-asynchronous gnus-newsgroup-name) (setq gnus-newsgroup-async (gnus-request-asynchronous gnus-newsgroup-name))) + ;; Adjust and set lists of article marks. + (when info + (gnus-adjust-marked-articles info)) + + ;; Kludge to avoid having cached articles nixed out in virtual groups. + (when (gnus-virtual-group-p group) + (setq cached gnus-newsgroup-cached)) + + (setq gnus-newsgroup-unreads + (gnus-set-difference + (gnus-set-difference gnus-newsgroup-unreads gnus-newsgroup-marked) + gnus-newsgroup-dormant)) + + (setq gnus-newsgroup-processable nil) + (setq articles (gnus-articles-to-read group read-all)) - (cond - ((null articles) - (gnus-message 3 "Couldn't select newsgroup") + (cond + ((null articles) + ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display") 'quit) ((eq articles 0) nil) (t ;; Init the dependencies hash table. - (setq gnus-newsgroup-dependencies + (setq gnus-newsgroup-dependencies (gnus-make-hashtable (length articles))) ;; Retrieve the headers and read them in. - (gnus-message 5 "Fetching headers...") - (setq gnus-newsgroup-headers - (if (eq 'nov (setq gnus-headers-retrieved-by - ;; This is a naughty hack. To get the - ;; retrieval of old headers to work, we - ;; set `nntp-nov-gap' to nil (locally), - ;; and then just retrieve the headers. - ;; Mucho magic. - (if gnus-fetch-old-headers - (let (nntp-nov-gap) - (gnus-retrieve-headers - (if (not (eq 1 (car articles))) - (cons 1 articles) - articles) - gnus-newsgroup-name)) - (gnus-retrieve-headers - articles gnus-newsgroup-name)))) - (progn - (gnus-get-newsgroup-headers-xover articles)) - ;; If we were to fetch old headers, but the backend didn't - ;; support XOVER, then it is possible we fetched one article - ;; that we shouldn't have. If that's the case, we remove it. - (if (or (not gnus-fetch-old-headers) - (eq 1 (car articles))) - () - (save-excursion - (set-buffer nntp-server-buffer) - (goto-char (point-min)) - (and - (looking-at "[0-9]+[ \t]+1[ \t]") ; This is not a NOV line. - (delete-region ; So we delete this head. - (point) - (search-forward "\n.\n" nil t))))) + (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name) + (setq gnus-newsgroup-headers + (if (eq 'nov + (setq gnus-headers-retrieved-by + (gnus-retrieve-headers + articles gnus-newsgroup-name + ;; We might want to fetch old headers, but + ;; not if there is only 1 article. + (and gnus-fetch-old-headers + (or (and + (not (eq gnus-fetch-old-headers 'some)) + (not (numberp gnus-fetch-old-headers))) + (> (length articles) 1)))))) + (gnus-get-newsgroup-headers-xover articles) (gnus-get-newsgroup-headers))) - (gnus-message 5 "Fetching headers...done") + (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name) + + ;; Kludge to avoid having cached articles nixed out in virtual groups. + (when cached + (setq gnus-newsgroup-cached cached)) + + ;; Set the initial limit. + (setq gnus-newsgroup-limit (copy-sequence articles)) ;; Remove canceled articles from the list of unread articles. (setq gnus-newsgroup-unreads - (gnus-set-sorted-intersection + (gnus-set-sorted-intersection gnus-newsgroup-unreads - (mapcar (lambda (headers) (mail-header-number headers)) - gnus-newsgroup-headers))) - ;; Adjust and set lists of article marks. - (and info - (let (marked) - (gnus-adjust-marked-articles info) - (setq gnus-newsgroup-marked - (copy-sequence - (cdr (assq 'tick (setq marked (nth 3 info)))))) - (setq gnus-newsgroup-replied - (copy-sequence (cdr (assq 'reply marked)))) - (setq gnus-newsgroup-expirable - (copy-sequence (cdr (assq 'expire marked)))) - (setq gnus-newsgroup-killed - (copy-sequence (cdr (assq 'killed marked)))) - (setq gnus-newsgroup-bookmarks - (copy-sequence (cdr (assq 'bookmark marked)))) - (setq gnus-newsgroup-dormant - (copy-sequence (cdr (assq 'dormant marked)))) - (setq gnus-newsgroup-scored - (copy-sequence (cdr (assq 'score marked)))) - (setq gnus-newsgroup-processable nil))) + (setq fetched-articles + (mapcar (lambda (headers) (mail-header-number headers)) + gnus-newsgroup-headers)))) + ;; Removed marked articles that do not exist. + (gnus-update-missing-marks + (gnus-sorted-complement fetched-articles articles)) + ;; We might want to build some more threads first. + (and gnus-fetch-old-headers + (eq gnus-headers-retrieved-by 'nov) + (gnus-build-old-threads)) ;; Check whether auto-expire is to be done in this group. (setq gnus-newsgroup-auto-expire - (or (and (stringp gnus-auto-expirable-newsgroups) - (string-match gnus-auto-expirable-newsgroups group)) - (memq 'auto-expire (nth 5 info)))) + (gnus-group-auto-expirable-p group)) + ;; Set up the article buffer now, if necessary. + (unless gnus-single-article-buffer + (gnus-article-setup-buffer)) ;; First and last article in this newsgroup. - (and gnus-newsgroup-headers - (setq gnus-newsgroup-begin - (mail-header-number (car gnus-newsgroup-headers))) - (setq gnus-newsgroup-end - (mail-header-number - (gnus-last-element gnus-newsgroup-headers)))) + (when gnus-newsgroup-headers + (setq gnus-newsgroup-begin + (mail-header-number (car gnus-newsgroup-headers)) + gnus-newsgroup-end + (mail-header-number + (gnus-last-element gnus-newsgroup-headers)))) (setq gnus-reffed-article-number -1) ;; GROUP is successfully selected. (or gnus-newsgroup-headers t))))) @@ -6800,46 +8851,46 @@ If READ-ALL is non-nil, all articles in the group are selected." (defun gnus-articles-to-read (group read-all) ;; Find out what articles the user wants to read. (let* ((articles - ;; Select all articles if `read-all' is non-nil, or if all the - ;; unread articles are dormant articles. + ;; Select all articles if `read-all' is non-nil, or if there + ;; are no unread articles. (if (or read-all - (= (length gnus-newsgroup-unreads) - (length gnus-newsgroup-dormant))) - (gnus-uncompress-range - (gnus-gethash group gnus-active-hashtb)) - gnus-newsgroup-unreads)) + (and (zerop (length gnus-newsgroup-marked)) + (zerop (length gnus-newsgroup-unreads)))) + (gnus-uncompress-range (gnus-active group)) + (sort (append gnus-newsgroup-dormant gnus-newsgroup-marked + (copy-sequence gnus-newsgroup-unreads)) + '<))) (scored-list (gnus-killed-articles gnus-newsgroup-killed articles)) (scored (length scored-list)) (number (length articles)) (marked (+ (length gnus-newsgroup-marked) (length gnus-newsgroup-dormant))) (select - (cond + (cond ((numberp read-all) read-all) (t (condition-case () - (cond ((and (or (<= scored marked) - (= scored number)) - (numberp gnus-large-newsgroup) - (> number gnus-large-newsgroup)) - (let ((input - (read-string - (format - "How many articles from %s (default %d): " - gnus-newsgroup-name number)))) - (if (string-match "^[ \t]*$" input) - number input))) - ((and (> scored marked) (< scored number)) - (let ((input - (read-string - (format - "%s %s (%d scored, %d total): " - "How many articles from" - group scored number)))) - (if (string-match "^[ \t]*$" input) - number input))) - (t number)) + (cond + ((and (or (<= scored marked) (= scored number)) + (numberp gnus-large-newsgroup) + (> number gnus-large-newsgroup)) + (let ((input + (read-string + (format + "How many articles from %s (default %d): " + gnus-newsgroup-name number)))) + (if (string-match "^[ \t]*$" input) number input))) + ((and (> scored marked) (< scored number) + (> (- scored number) 20)) + (let ((input + (read-string + (format "%s %s (%d scored, %d total): " + "How many articles from" + group scored number)))) + (if (string-match "^[ \t]*$" input) + number input))) + (t number)) (quit nil)))))) (setq select (if (stringp select) (string-to-number select) select)) (if (or (null select) (zerop select)) @@ -6851,7 +8902,7 @@ If READ-ALL is non-nil, all articles in the group are selected." (setq articles (copy-sequence articles))) (if (< (abs select) number) - (if (< select 0) + (if (< select 0) ;; Select the N oldest articles. (setcdr (nthcdr (1- (abs select)) articles) nil) ;; Select the N most recent articles. @@ -6870,313 +8921,302 @@ If READ-ALL is non-nil, all articles in the group are selected." (setq articles (cdr articles))) out)) -(defun gnus-adjust-marked-articles (info &optional active) - "Remove all marked articles that are no longer legal." - (let ((marked-lists (nth 3 info)) - (active (or active (gnus-gethash (car info) gnus-active-hashtb))) - m prev) - ;; There are many types of marked articles. +(defun gnus-uncompress-marks (marks) + "Uncompress the mark ranges in MARKS." + (let ((uncompressed '(score bookmark)) + out) + (while marks + (if (memq (caar marks) uncompressed) + (push (car marks) out) + (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out)) + (setq marks (cdr marks))) + out)) + +(defun gnus-adjust-marked-articles (info) + "Set all article lists and remove all marks that are no longer legal." + (let* ((marked-lists (gnus-info-marks info)) + (active (gnus-active (gnus-info-group info))) + (min (car active)) + (max (cdr active)) + (types gnus-article-mark-lists) + (uncompressed '(score bookmark)) + marks var articles article mark) + (while marked-lists - (setq m (cdr (setq prev (car marked-lists)))) - (cond ((or (eq 'tick (car prev)) (eq 'dormant (car prev))) - ;; Make sure that all ticked articles are a subset of the - ;; unread/unselected articles. - ;;(while m - ;; (if (or (memq (car m) gnus-newsgroup-unreads) - ;; (memq (car m) gnus-newsgroup-unselected)) - ;; (setq prev m) - ;; (setcdr prev (cdr m))) - ;; (setq m (cdr m))) - ) - ((eq 'score (car prev)) - ;; Scored articles should be a subset of - ;; unread/unselected articles. - (while m - (if (or (memq (car (car m)) gnus-newsgroup-unreads) - (memq (car (car m)) gnus-newsgroup-unreads)) - (setq prev m) - (setcdr prev (cdr m))) - (setq m (cdr m)))) - ((eq 'bookmark (car prev)) - ;; Bookmarks should be a subset of active articles. - (while m - (if (< (car (car m)) (car active)) - (setcdr prev (cdr m)) - (setq prev m)) - (setq m (cdr m)))) - ((eq 'killed (car prev)) - ;; Articles that have been through the kill process are - ;; to be a subset of active articles. - (while (and m (< (or (and (numberp (car m)) (car m)) - (cdr (car m))) - (car active))) - (setcdr prev (cdr m)) - (setq m (cdr m))) - (if (and m (< (or (and (numberp (car m)) (car m)) - (car (car m))) - (car active))) - (setcar (if (numberp (car m)) m (car m)) (car active)))) - ((or (eq 'reply (car prev)) (eq 'expire (car prev))) - ;; The replied and expirable articles have to be articles - ;; that are active. - (while m - (if (< (car m) (car active)) - (setcdr prev (cdr m)) - (setq prev m)) - (setq m (cdr m))))) - (setq marked-lists (cdr marked-lists))) - ;; Remove all lists that are empty. - (setq marked-lists (nth 3 info)) - (if marked-lists - (progn - (while (= 1 (length (car marked-lists))) - (setq marked-lists (cdr marked-lists))) - (setq m (cdr (setq prev marked-lists))) + (setq marks (pop marked-lists)) + (set (setq var (intern (format "gnus-newsgroup-%s" + (car (rassq (setq mark (car marks)) + types))))) + (if (memq (car marks) uncompressed) (cdr marks) + (gnus-uncompress-range (cdr marks)))) + + (setq articles (symbol-value var)) + + ;; All articles have to be subsets of the active articles. + (cond + ;; Adjust "simple" lists. + ((memq mark '(tick dormant expirable reply killed save)) + (while articles + (when (or (< (setq article (pop articles)) min) (> article max)) + (set var (delq article (symbol-value var)))))) + ;; Adjust assocs. + ((memq mark '(score bookmark)) + (while articles + (when (or (not (consp (setq article (pop articles)))) + (< (car article) min) + (> (car article) max)) + (set var (delq article (symbol-value var)))))))))) + +(defun gnus-update-missing-marks (missing) + "Go through the list of MISSING articles and remove them mark lists." + (when missing + (let ((types gnus-article-mark-lists) + var m) + ;; Go through all types. + (while types + (setq var (intern (format "gnus-newsgroup-%s" (car (pop types))))) + (when (symbol-value var) + ;; This list has articles. So we delete all missing articles + ;; from it. + (setq m missing) (while m - (if (= 1 (length (car m))) - (setcdr prev (cdr m)) - (setq prev m)) - (setq m (cdr m))) - (setcar (nthcdr 3 info) marked-lists))) - ;; Finally, if there are no marked lists at all left, and if there - ;; are no elements after the lists in the info list, we just chop - ;; the info list off before the marked lists. - (and (null marked-lists) - (not (nthcdr 4 info)) - (setcdr (nthcdr 2 info) nil))) - info) - -(defun gnus-set-marked-articles - (info ticked replied expirable killed dormant bookmark score) + (set var (delq (pop m) (symbol-value var))))))))) + +(defun gnus-update-marks () "Enter the various lists of marked articles into the newsgroup info list." - (let (newmarked) - (and ticked (setq newmarked (cons (cons 'tick ticked) nil))) - (and replied (setq newmarked (cons (cons 'reply replied) newmarked))) - (and expirable (setq newmarked (cons (cons 'expire expirable) - newmarked))) - (and killed (setq newmarked (cons (cons 'killed killed) newmarked))) - (and dormant (setq newmarked (cons (cons 'dormant dormant) newmarked))) - (and bookmark (setq newmarked (cons (cons 'bookmark bookmark) - newmarked))) - (and score (setq newmarked (cons (cons 'score score) newmarked))) - (if (nthcdr 3 info) - (progn + (let ((types gnus-article-mark-lists) + (info (gnus-get-info gnus-newsgroup-name)) + (uncompressed '(score bookmark killed)) + type list newmarked symbol) + (when info + ;; Add all marks lists that are non-nil to the list of marks lists. + (while types + (setq type (pop types)) + (when (setq list (symbol-value + (setq symbol + (intern (format "gnus-newsgroup-%s" + (car type)))))) + (push (cons (cdr type) + (if (memq (cdr type) uncompressed) list + (gnus-compress-sequence + (set symbol (sort list '<)) t))) + newmarked))) + + ;; Enter these new marks into the info of the group. + (if (nthcdr 3 info) (setcar (nthcdr 3 info) newmarked) - (and (not newmarked) - (not (nthcdr 4 info)) - (setcdr (nthcdr 2 info) nil))) - (if newmarked - (setcdr (nthcdr 2 info) (list newmarked)))))) + ;; Add the marks lists to the end of the info. + (when newmarked + (setcdr (nthcdr 2 info) (list newmarked)))) + + ;; Cut off the end of the info if there's nothing else there. + (let ((i 5)) + (while (and (> i 2) + (not (nth i info))) + (when (nthcdr (decf i) info) + (setcdr (nthcdr i info) nil))))))) (defun gnus-add-marked-articles (group type articles &optional info force) ;; Add ARTICLES of TYPE to the info of GROUP. - ;; If INFO is non-nil, use that info. If FORCE is non-nil, don't + ;; If INFO is non-nil, use that info. If FORCE is non-nil, don't ;; add, but replace marked articles of TYPE with ARTICLES. - (let ((info (or info (nth 2 (gnus-gethash group gnus-newsrc-hashtb)))) + (let ((info (or info (gnus-get-info group))) + (uncompressed '(score bookmark killed)) marked m) (or (not info) (and (not (setq marked (nthcdr 3 info))) - (setcdr (nthcdr 2 info) (list (list (cons type articles))))) + (or (null articles) + (setcdr (nthcdr 2 info) + (list (list (cons type (gnus-compress-sequence + articles t))))))) (and (not (setq m (assq type (car marked)))) - (setcar marked (cons (cons type articles) (car marked)))) + (or (null articles) + (setcar marked + (cons (cons type (gnus-compress-sequence articles t) ) + (car marked))))) (if force - (setcdr m articles) - (nconc m articles))))) - + (if (null articles) + (setcar (nthcdr 3 info) + (delq (assq type (car marked)) (car marked))) + (setcdr m (gnus-compress-sequence articles t))) + (setcdr m (gnus-compress-sequence + (sort (nconc (gnus-uncompress-range (cdr m)) + (copy-sequence articles)) '<) t)))))) + (defun gnus-set-mode-line (where) "This function sets the mode line of the article or summary buffers. If WHERE is `summary', the summary mode line format will be used." - (if (memq where gnus-updated-mode-lines) - (let (mode-string) - (save-excursion - (set-buffer gnus-summary-buffer) - (let* ((mformat (if (eq where 'article) - gnus-article-mode-line-format-spec - gnus-summary-mode-line-format-spec)) - (buffer-name (if (eq where 'article) - (buffer-name - (get-buffer gnus-article-buffer)) - (buffer-name))) - (group-name gnus-newsgroup-name) - (article-number (or gnus-current-article 0)) - (unread (- (length gnus-newsgroup-unreads) - (length gnus-newsgroup-dormant))) - (unread-and-unticked - (- unread (length gnus-newsgroup-marked))) - (unselected (length gnus-newsgroup-unselected)) - (unread-and-unselected - (cond ((and (zerop unread-and-unticked) - (zerop unselected)) "") - ((zerop unselected) - (format "{%d more}" unread-and-unticked)) - (t (format "{%d(+%d) more}" - unread-and-unticked unselected)))) - (subject - (if gnus-current-headers - (mail-header-subject gnus-current-headers) "")) - (max-len (and gnus-mode-non-string-length - (- (frame-width) gnus-mode-non-string-length))) - header);; passed as argument to any user-format-funcs - (setq mode-string (eval mformat)) - (or (numberp max-len) - (setq max-len (length mode-string))) - (if (< max-len 4) (setq max-len 4)) - (if (> (length mode-string) max-len) - ;; modified by MORIOKA Tomohiko - ;; function `substring' might cut on a middle - ;; of multi-octet character. - (setq mode-string - (concat (gnus-truncate-string mode-string (- max-len 3)) - "..."))) - (setq mode-string (format (format "%%-%ds" max-len) - mode-string)))) - (setq mode-line-buffer-identification mode-string) - (set-buffer-modified-p t)))) + ;; Is this mode line one we keep updated? + (when (memq where gnus-updated-mode-lines) + (let (mode-string) + (save-excursion + ;; We evaluate this in the summary buffer since these + ;; variables are buffer-local to that buffer. + (set-buffer gnus-summary-buffer) + ;; We bind all these variables that are used in the `eval' form + ;; below. + (let* ((mformat (symbol-value + (intern + (format "gnus-%s-mode-line-format-spec" where)))) + (gnus-tmp-group-name gnus-newsgroup-name) + (gnus-tmp-article-number (or gnus-current-article 0)) + (gnus-tmp-unread gnus-newsgroup-unreads) + (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads)) + (gnus-tmp-unselected (length gnus-newsgroup-unselected)) + (gnus-tmp-unread-and-unselected + (cond ((and (zerop gnus-tmp-unread-and-unticked) + (zerop gnus-tmp-unselected)) "") + ((zerop gnus-tmp-unselected) + (format "{%d more}" gnus-tmp-unread-and-unticked)) + (t (format "{%d(+%d) more}" + gnus-tmp-unread-and-unticked + gnus-tmp-unselected)))) + (gnus-tmp-subject + (if (and gnus-current-headers + (vectorp gnus-current-headers)) + (gnus-mode-string-quote + (mail-header-subject gnus-current-headers)) "")) + max-len + gnus-tmp-header);; passed as argument to any user-format-funcs + (setq mode-string (eval mformat)) + (setq max-len (max 4 (if gnus-mode-non-string-length + (- (window-width) + gnus-mode-non-string-length) + (length mode-string)))) + ;; We might have to chop a bit of the string off... + (when (> (length mode-string) max-len) + (setq mode-string + (concat (gnus-truncate-string mode-string (- max-len 3)) + "..."))) + ;; Pad the mode string a bit. + (setq mode-string (format (format "%%-%ds" max-len) mode-string)))) + ;; Update the mode line. + (setq mode-line-buffer-identification + (gnus-mode-line-buffer-identification + (list mode-string))) + (set-buffer-modified-p t)))) (defun gnus-create-xref-hashtb (from-newsgroup headers unreads) "Go through the HEADERS list and add all Xrefs to a hash table. The resulting hash table is returned, or nil if no Xrefs were found." - (let* ((from-method (gnus-find-method-for-group from-newsgroup)) - (prefix (if (and - (gnus-group-foreign-p from-newsgroup) - (not (memq 'virtual - (assoc (symbol-name (car from-method)) - gnus-valid-select-methods)))) - (gnus-group-real-prefix from-newsgroup))) + (let* ((virtual (gnus-virtual-group-p from-newsgroup)) + (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup))) (xref-hashtb (make-vector 63 0)) start group entry number xrefs header) (while headers - (setq header (car headers)) - (if (and (setq xrefs (mail-header-xref header)) - (not (memq (mail-header-number header) unreads))) - (progn - (setq start 0) - (while (string-match "\\([^ ]+\\):\\([0-9]+\\)" xrefs start) - (setq start (match-end 0)) - (setq group (concat prefix (substring xrefs (match-beginning 1) - (match-end 1)))) - (setq number - (string-to-int (substring xrefs (match-beginning 2) - (match-end 2)))) - (if (setq entry (gnus-gethash group xref-hashtb)) - (setcdr entry (cons number (cdr entry))) - (gnus-sethash group (cons number nil) xref-hashtb))))) - (setq headers (cdr headers))) - (if start xref-hashtb nil))) - -(defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads expirable) + (setq header (pop headers)) + (when (and (setq xrefs (mail-header-xref header)) + (not (memq (setq number (mail-header-number header)) + unreads))) + (setq start 0) + (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start) + (setq start (match-end 0)) + (setq group (if prefix + (concat prefix (substring xrefs (match-beginning 1) + (match-end 1))) + (substring xrefs (match-beginning 1) (match-end 1)))) + (setq number + (string-to-int (substring xrefs (match-beginning 2) + (match-end 2)))) + (if (setq entry (gnus-gethash group xref-hashtb)) + (setcdr entry (cons number (cdr entry))) + (gnus-sethash group (cons number nil) xref-hashtb))))) + (and start xref-hashtb))) + +(defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads) "Look through all the headers and mark the Xrefs as read." - (let ((virtual (memq 'virtual - (assoc (symbol-name (car (gnus-find-method-for-group - from-newsgroup))) - gnus-valid-select-methods))) - name entry info xref-hashtb idlist method - nth4) + (let ((virtual (gnus-virtual-group-p from-newsgroup)) + name entry info xref-hashtb idlist method nth4) (save-excursion (set-buffer gnus-group-buffer) - (if (setq xref-hashtb - (gnus-create-xref-hashtb from-newsgroup headers unreads)) - (mapatoms - (lambda (group) - (if (string= from-newsgroup (setq name (symbol-name group))) - () - (setq idlist (symbol-value group)) - ;; Dead groups are not updated. - (if (and (prog1 - (setq entry (gnus-gethash name gnus-newsrc-hashtb) - info (nth 2 entry)) - (if (stringp (setq nth4 (nth 4 info))) - (setq nth4 (gnus-server-to-method nth4)))) - ;; Only do the xrefs if the group has the same - ;; select method as the group we have just read. - (or (gnus-methods-equal-p - nth4 (gnus-find-method-for-group from-newsgroup)) - virtual - (equal nth4 - (setq method (gnus-find-method-for-group - from-newsgroup))) - (and (equal (car nth4) (car method)) - (equal (nth 1 nth4) (nth 1 method)))) - gnus-use-cross-reference - (or (not (eq gnus-use-cross-reference t)) - virtual - ;; Only do cross-references on subscribed - ;; groups, if that is what is wanted. - (<= (nth 1 info) gnus-level-subscribed))) - (gnus-group-make-articles-read name idlist expirable)))) - xref-hashtb))))) - -(defun gnus-group-make-articles-read (group articles expirable) + (when (setq xref-hashtb + (gnus-create-xref-hashtb from-newsgroup headers unreads)) + (mapatoms + (lambda (group) + (unless (string= from-newsgroup (setq name (symbol-name group))) + (setq idlist (symbol-value group)) + ;; Dead groups are not updated. + (and (prog1 + (setq entry (gnus-gethash name gnus-newsrc-hashtb) + info (nth 2 entry)) + (if (stringp (setq nth4 (gnus-info-method info))) + (setq nth4 (gnus-server-to-method nth4)))) + ;; Only do the xrefs if the group has the same + ;; select method as the group we have just read. + (or (gnus-methods-equal-p + nth4 (gnus-find-method-for-group from-newsgroup)) + virtual + (equal nth4 (setq method (gnus-find-method-for-group + from-newsgroup))) + (and (equal (car nth4) (car method)) + (equal (nth 1 nth4) (nth 1 method)))) + gnus-use-cross-reference + (or (not (eq gnus-use-cross-reference t)) + virtual + ;; Only do cross-references on subscribed + ;; groups, if that is what is wanted. + (<= (gnus-info-level info) gnus-level-subscribed)) + (gnus-group-make-articles-read name idlist)))) + xref-hashtb))))) + +(defun gnus-group-make-articles-read (group articles) (let* ((num 0) (entry (gnus-gethash group gnus-newsrc-hashtb)) (info (nth 2 entry)) - (active (gnus-gethash group gnus-active-hashtb)) - exps expirable range) + (active (gnus-active group)) + range) ;; First peel off all illegal article numbers. (if active (let ((ids articles) - (ticked (cdr (assq 'tick (nth 3 info)))) - (dormant (cdr (assq 'dormant (nth 3 info)))) id first) - (setq exps nil) (while ids (setq id (car ids)) (if (and first (> id (cdr active))) (progn ;; We'll end up in this situation in one particular - ;; obscure situation. If you re-scan a group and get + ;; obscure situation. If you re-scan a group and get ;; a new article that is cross-posted to a different ;; group that has not been re-scanned, you might get ;; crossposted article that has a higher number than - ;; Gnus believes possible. So we re-activate this - ;; group as well. This might mean doing the + ;; Gnus believes possible. So we re-activate this + ;; group as well. This might mean doing the ;; crossposting thingy will *increase* the number - ;; of articles in some groups. Tsk, tsk. + ;; of articles in some groups. Tsk, tsk. (setq active (or (gnus-activate-group group) active)))) (if (or (> id (cdr active)) - (< id (car active)) - (memq id ticked) - (memq id dormant)) + (< id (car active))) (setq articles (delq id articles))) - (and (memq id expirable) - (setq exps (cons id exps))) (setq ids (cdr ids))))) - ;; Update expirable articles. - (gnus-add-marked-articles nil 'expirable exps info) + ;; If the read list is nil, we init it. (and active - (null (nth 2 info)) + (null (gnus-info-read info)) (> (car active) 1) - (setcar (nthcdr 2 info) (cons 1 (1- (car active))))) - (setcar (nthcdr 2 info) - (setq range - (gnus-add-to-range - (nth 2 info) - (setq articles (sort articles '<))))) + (gnus-info-set-read info (cons 1 (1- (car active))))) + ;; Then we add the read articles to the range. + (gnus-info-set-read + info + (setq range + (gnus-add-to-range + (gnus-info-read info) (setq articles (sort articles '<))))) ;; Then we have to re-compute how many unread ;; articles there are in this group. (if active (progn - (cond + (cond ((not range) (setq num (- (1+ (cdr active)) (car active)))) ((not (listp (cdr range))) - (setq num (- (cdr active) (- (1+ (cdr range)) + (setq num (- (cdr active) (- (1+ (cdr range)) (car range))))) (t (while range (if (numberp (car range)) (setq num (1+ num)) - (setq num (+ num (- (1+ (cdr (car range))) - (car (car range)))))) + (setq num (+ num (- (1+ (cdar range)) (caar range))))) (setq range (cdr range))) (setq num (- (cdr active) num)))) ;; Update the number of unread articles. - (setcar - entry - (max 0 (- num - (length (cdr (assq 'tick (nth 3 info)))) - (length - (cdr (assq 'dormant (nth 3 info))))))) + (setcar entry num) ;; Update the group buffer. (gnus-group-update-group group t))))) @@ -7194,125 +9234,142 @@ The resulting hash table is returned, or nil if no Xrefs were found." (defvar gnus-newsgroup-none-id 0) -(defun gnus-get-newsgroup-headers () - (setq gnus-article-internal-prepare-hook nil) +(defun gnus-get-newsgroup-headers (&optional dependencies force-new) (let ((cur nntp-server-buffer) - (dependencies gnus-newsgroup-dependencies) - headers id dep end ref) + (dependencies + (or dependencies + (save-excursion (set-buffer gnus-summary-buffer) + gnus-newsgroup-dependencies))) + headers id id-dep ref-dep end ref) (save-excursion (set-buffer nntp-server-buffer) - ;; Allow the user to mangle the headers before parsing them. (run-hooks 'gnus-parse-headers-hook) - (goto-char (point-min)) - ;; Search to the beginning of the next header. Error messages - ;; do not begin with 2 or 3. - (while (re-search-forward "^[23][0-9]+ " nil t) - (let ((header (make-vector 9 nil)) - (case-fold-search t) - (p (point)) - in-reply-to) + (let ((case-fold-search t) + in-reply-to header p lines) + (goto-char (point-min)) + ;; Search to the beginning of the next header. Error messages + ;; do not begin with 2 or 3. + (while (re-search-forward "^[23][0-9]+ " nil t) (setq id nil ref nil) - (mail-header-set-number header (read cur)) ;; This implementation of this function, with nine ;; search-forwards instead of the one re-search-forward and ;; a case (which basically was the old function) is actually - ;; about twice as fast, even though it looks messier. You - ;; can't have everything, I guess. Speed and elegance - ;; doesn't always come hand in hand. - (save-restriction - (narrow-to-region (point) (or (save-excursion - (search-forward "\n.\n" nil t)) - (point))) - (if (search-forward "\nfrom: " nil t) - (mail-header-set-from header (gnus-header-value)) - (mail-header-set-from header "(nobody)")) - (goto-char p) - (if (search-forward "\nsubject: " nil t) - (mail-header-set-subject header (gnus-header-value)) - (mail-header-set-subject header "(none)")) - (goto-char p) - (and (search-forward "\nxref: " nil t) - (mail-header-set-xref header (gnus-header-value))) - (goto-char p) - (or (numberp (and (search-forward "\nlines: " nil t) - (mail-header-set-lines header (read cur)))) - (mail-header-set-lines header 0)) - (goto-char p) - (and (search-forward "\ndate: " nil t) - (mail-header-set-date header (gnus-header-value))) - (goto-char p) - (if (search-forward "\nmessage-id: " nil t) - (mail-header-set-id header (setq id (gnus-header-value))) - ;; If there was no message-id, we just fake one to make - ;; subsequent routines simpler. - (mail-header-set-id - header - (setq id (concat "none+" - (int-to-string - (setq gnus-newsgroup-none-id - (1+ gnus-newsgroup-none-id))))))) - (goto-char p) - (if (search-forward "\nreferences: " nil t) - (progn - (mail-header-set-references header (gnus-header-value)) - (setq end (match-end 0)) - (save-excursion - (setq ref - (downcase - (buffer-substring - (progn - (end-of-line) - (search-backward ">" end t) - (1+ (point))) - (progn - (search-backward "<" end t) - (point))))))) - ;; Get the references from the in-reply-to header if there - ;; ware no references and the in-reply-to header looks - ;; promising. - (if (and (search-forward "\nin-reply-to: " nil t) - (setq in-reply-to (gnus-header-value)) - (string-match "<[^>]+>" in-reply-to)) + ;; about twice as fast, even though it looks messier. You + ;; can't have everything, I guess. Speed and elegance + ;; doesn't always go hand in hand. + (setq + header + (vector + ;; Number. + (prog1 + (read cur) + (end-of-line) + (setq p (point)) + (narrow-to-region (point) + (or (and (search-forward "\n.\n" nil t) + (- (point) 2)) + (point)))) + ;; Subject. + (progn + (goto-char p) + (if (search-forward "\nsubject: " nil t) + (gnus-header-value) "(none)")) + ;; From. + (progn + (goto-char p) + (if (search-forward "\nfrom: " nil t) + (gnus-header-value) "(nobody)")) + ;; Date. + (progn + (goto-char p) + (if (search-forward "\ndate: " nil t) + (gnus-header-value) "")) + ;; Message-ID. + (progn + (goto-char p) + (if (search-forward "\nmessage-id: " nil t) + (setq id (gnus-header-value)) + ;; If there was no message-id, we just fake one to make + ;; subsequent routines simpler. + (setq id (concat "none+" + (int-to-string + (setq gnus-newsgroup-none-id + (1+ gnus-newsgroup-none-id))))))) + ;; References. + (progn + (goto-char p) + (if (search-forward "\nreferences: " nil t) (progn - (mail-header-set-references - header - (setq ref (substring in-reply-to (match-beginning 0) - (match-end 0)))) - (setq ref (downcase ref))) - (setq ref "none"))) - ;; We do some threading while we read the headers. The - ;; message-id and the last reference are both entered into - ;; the same hash table. Some tippy-toeing around has to be - ;; done in case an article has arrived before the article - ;; which it refers to. - (if (boundp (setq dep (intern (downcase id) dependencies))) - (if (car (symbol-value dep)) - ;; An article with this Message-ID has already - ;; been seen, so we ignore this one, except we add - ;; any additional Xrefs (in case the two articles - ;; came from different servers. - (progn - (mail-header-set-xref - (car (symbol-value dep)) - (concat (or (mail-header-xref - (car (symbol-value dep))) "") - (or (mail-header-xref header) ""))) - (setq header nil)) - (setcar (symbol-value dep) header)) - (set dep (list header))) - (if header - (progn - (if (boundp (setq dep (intern ref dependencies))) - (setcdr (symbol-value dep) - (cons header (cdr (symbol-value dep)))) - (set dep (list nil header))) - (setq headers (cons header headers)))) - (goto-char (point-max)))))) - (nreverse headers))) + (setq end (point)) + (prog1 + (gnus-header-value) + (setq ref + (buffer-substring + (progn + (end-of-line) + (search-backward ">" end t) + (1+ (point))) + (progn + (search-backward "<" end t) + (point)))))) + ;; Get the references from the in-reply-to header if there + ;; were no references and the in-reply-to header looks + ;; promising. + (if (and (search-forward "\nin-reply-to: " nil t) + (setq in-reply-to (gnus-header-value)) + (string-match "<[^>]+>" in-reply-to)) + (setq ref (substring in-reply-to (match-beginning 0) + (match-end 0))) + (setq ref "")))) + ;; Chars. + 0 + ;; Lines. + (progn + (goto-char p) + (if (search-forward "\nlines: " nil t) + (if (numberp (setq lines (read cur))) + lines 0) + 0)) + ;; Xref. + (progn + (goto-char p) + (and (search-forward "\nxref: " nil t) + (gnus-header-value))))) + ;; We do the threading while we read the headers. The + ;; message-id and the last reference are both entered into + ;; the same hash table. Some tippy-toeing around has to be + ;; done in case an article has arrived before the article + ;; which it refers to. + (if (boundp (setq id-dep (intern id dependencies))) + (if (and (car (symbol-value id-dep)) + (not force-new)) + ;; An article with this Message-ID has already + ;; been seen, so we ignore this one, except we add + ;; any additional Xrefs (in case the two articles + ;; came from different servers). + (progn + (mail-header-set-xref + (car (symbol-value id-dep)) + (concat (or (mail-header-xref + (car (symbol-value id-dep))) "") + (or (mail-header-xref header) ""))) + (setq header nil)) + (setcar (symbol-value id-dep) header)) + (set id-dep (list header))) + (when header + (if (boundp (setq ref-dep (intern ref dependencies))) + (setcdr (symbol-value ref-dep) + (nconc (cdr (symbol-value ref-dep)) + (list (symbol-value id-dep)))) + (set ref-dep (list nil (symbol-value id-dep)))) + (setq headers (cons header headers))) + (goto-char (point-max)) + (widen)) + (nreverse headers))))) ;; The following macros and functions were written by Felix Lee -;; . +;; . (defmacro gnus-nov-read-integer () '(prog1 @@ -7329,14 +9386,15 @@ The resulting hash table is returned, or nil if no Xrefs were found." '(buffer-substring (point) (if (gnus-nov-skip-field) (1- (point)) eol))) ;; Goes through the xover lines and returns a list of vectors -(defun gnus-get-newsgroup-headers-xover (sequence) +(defun gnus-get-newsgroup-headers-xover (sequence &optional + force-new dependencies) "Parse the news overview data in the server buffer, and return a list of headers that match SEQUENCE (see `nntp-retrieve-headers')." ;; Get the Xref when the users reads the articles since most/some ;; NNTP servers do not include Xrefs when using XOVER. (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs)) (let ((cur nntp-server-buffer) - (dependencies gnus-newsgroup-dependencies) + (dependencies (or dependencies gnus-newsgroup-dependencies)) number headers header) (save-excursion (set-buffer nntp-server-buffer) @@ -7347,12 +9405,13 @@ list of headers that match SEQUENCE (see `nntp-retrieve-headers')." (setq number (read cur)) (while (and sequence (< (car sequence) number)) (setq sequence (cdr sequence))) - (and sequence + (and sequence (eq number (car sequence)) (progn (setq sequence (cdr sequence)) - (if (setq header - (inline (gnus-nov-parse-line number dependencies))) + (if (setq header + (inline (gnus-nov-parse-line + number dependencies force-new))) (setq headers (cons header headers))))) (forward-line 1)) (setq headers (nreverse headers))) @@ -7360,11 +9419,11 @@ list of headers that match SEQUENCE (see `nntp-retrieve-headers')." ;; This function has to be called with point after the article number ;; on the beginning of the line. -(defun gnus-nov-parse-line (number dependencies) +(defun gnus-nov-parse-line (number dependencies &optional force-new) (let ((none 0) - (eol (gnus-point-at-eol)) + (eol (gnus-point-at-eol)) (buffer (current-buffer)) - header ref id dep) + header ref id id-dep ref-dep) ;; overview: [num subject from date id refs chars lines misc] (narrow-to-region (point) eol) @@ -7372,27 +9431,24 @@ list of headers that match SEQUENCE (see `nntp-retrieve-headers')." (condition-case nil (setq header - (vector + (vector number ; number - (gnus-nov-field) ; subject - (gnus-nov-field) ; from + (gnus-nov-field) ; subject + (gnus-nov-field) ; from (gnus-nov-field) ; date (setq id (or (gnus-nov-field) (concat "none+" - (int-to-string + (int-to-string (setq none (1+ none)))))) ; id (progn (save-excursion (let ((beg (point))) (search-forward "\t" eol) (if (search-backward ">" beg t) - (setq ref - (downcase - (buffer-substring - (1+ (point)) - (progn - (search-backward "<" beg t) - (point))))) + (setq ref + (buffer-substring + (1+ (point)) + (search-backward "<" beg t))) (setq ref nil)))) (gnus-nov-field)) ; refs (gnus-nov-read-integer) ; chars @@ -7401,37 +9457,37 @@ list of headers that match SEQUENCE (see `nntp-retrieve-headers')." nil (gnus-nov-field)) ; misc )) - (error (progn - (ding) - (message "Strange nov line.") + (error (progn + (gnus-error 4 "Strange nov line") (setq header nil) (goto-char eol)))) (widen) ;; We build the thread tree. - (and header - (if (boundp (setq dep (intern (downcase id) dependencies))) - (if (car (symbol-value dep)) - ;; An article with this Message-ID has already been seen, - ;; so we ignore this one, except we add any additional - ;; Xrefs (in case the two articles came from different - ;; servers. - (progn - (mail-header-set-xref - (car (symbol-value dep)) - (concat (or (mail-header-xref (car (symbol-value dep))) "") - (or (mail-header-xref header) ""))) - (setq header nil)) - (setcar (symbol-value dep) header)) - (set dep (list header)))) - (if header - (progn - (if (boundp (setq dep (intern (or ref "none") - dependencies))) - (setcdr (symbol-value dep) - (cons header (cdr (symbol-value dep)))) - (set dep (list nil header))))) + (when header + (if (boundp (setq id-dep (intern id dependencies))) + (if (and (car (symbol-value id-dep)) + (not force-new)) + ;; An article with this Message-ID has already been seen, + ;; so we ignore this one, except we add any additional + ;; Xrefs (in case the two articles came from different + ;; servers. + (progn + (mail-header-set-xref + (car (symbol-value id-dep)) + (concat (or (mail-header-xref + (car (symbol-value id-dep))) "") + (or (mail-header-xref header) ""))) + (setq header nil)) + (setcar (symbol-value id-dep) header)) + (set id-dep (list header)))) + (when header + (if (boundp (setq ref-dep (intern (or ref "none") dependencies))) + (setcdr (symbol-value ref-dep) + (nconc (cdr (symbol-value ref-dep)) + (list (symbol-value id-dep)))) + (set ref-dep (list nil (symbol-value id-dep))))) header)) (defun gnus-article-get-xrefs () @@ -7446,97 +9502,104 @@ This is meant to be called in `gnus-article-internal-prepare-hook'." (let ((case-fold-search t) xref) (save-restriction - (gnus-narrow-to-headers) + (nnheader-narrow-to-headers) (goto-char (point-min)) (if (or (and (eq (downcase (following-char)) ?x) (looking-at "Xref:")) (search-forward "\nXref:" nil t)) (progn (goto-char (1+ (match-end 0))) - (setq xref (buffer-substring (point) + (setq xref (buffer-substring (point) (progn (end-of-line) (point)))) (mail-header-set-xref headers xref)))))))) -(defalias 'gnus-find-header-by-number 'gnus-get-header-by-number) -(make-obsolete 'gnus-find-header-by-number 'gnus-get-header-by-number) - -(defun gnus-make-headers-hashtable-by-number () - "Make hashtable for the variable gnus-newsgroup-headers by number." - (save-excursion - (set-buffer gnus-summary-buffer) - (let ((headers gnus-newsgroup-headers) - header) - (setq gnus-newsgroup-headers-hashtb-by-number - (gnus-make-hashtable (length headers))) - (while headers - (setq header (car headers)) - (gnus-sethash (int-to-string (mail-header-number header)) - header gnus-newsgroup-headers-hashtb-by-number) - (setq headers (cdr headers)))))) - -(defun gnus-more-header-backward () - "Find new header backward." - (let ((first (car (gnus-gethash gnus-newsgroup-name gnus-active-hashtb))) - (artnum gnus-newsgroup-begin) - (header nil)) - (while (and (not header) - (> artnum first)) - (setq artnum (1- artnum)) - (setq header (gnus-read-header artnum))) - header)) - -(defun gnus-more-header-forward (&optional backward) - "Find new header forward. -If BACKWARD, find new header backward instead." - (if backward - (gnus-more-header-backward) - (let ((last (cdr (gnus-gethash gnus-newsgroup-name gnus-active-hashtb))) - (artnum gnus-newsgroup-end) - (header nil)) - (while (and (not header) - (< artnum last)) - (setq artnum (1+ artnum)) - (setq header (gnus-read-header artnum))) - header))) - -(defun gnus-extend-newsgroup (header &optional backward) - "Extend newsgroup selection with HEADER. -Optional argument BACKWARD means extend toward backward." - (if header - (let ((artnum (mail-header-number header))) - (setq gnus-newsgroup-headers - (if backward - (cons header gnus-newsgroup-headers) - (nconc gnus-newsgroup-headers (list header)))) - (setq gnus-newsgroup-unselected - (delq artnum gnus-newsgroup-unselected)) - (setq gnus-newsgroup-begin (min gnus-newsgroup-begin artnum)) - (setq gnus-newsgroup-end (max gnus-newsgroup-end artnum))))) +(defun gnus-summary-insert-subject (id &optional old-header use-old-header) + "Find article ID and insert the summary line for that article." + (let ((header (if (and old-header use-old-header) + old-header (gnus-read-header id))) + (number (and (numberp id) id)) + pos) + (when header + ;; Rebuild the thread that this article is part of and go to the + ;; article we have fetched. + (when (and (not gnus-show-threads) + old-header) + (when (setq pos (text-property-any + (point-min) (point-max) 'gnus-number + (mail-header-number old-header))) + (goto-char pos) + (gnus-delete-line) + (gnus-data-remove (mail-header-number old-header)))) + (when old-header + (mail-header-set-number header (mail-header-number old-header))) + (setq gnus-newsgroup-sparse + (delq (setq number (mail-header-number header)) + gnus-newsgroup-sparse)) + (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient)) + (gnus-rebuild-thread (mail-header-id header)) + (gnus-summary-goto-subject number nil t)) + (when (and (numberp number) + (> number 0)) + ;; We have to update the boundaries even if we can't fetch the + ;; article if ID is a number -- so that the next `P' or `N' + ;; command will fetch the previous (or next) article even + ;; if the one we tried to fetch this time has been canceled. + (and (> number gnus-newsgroup-end) + (setq gnus-newsgroup-end number)) + (and (< number gnus-newsgroup-begin) + (setq gnus-newsgroup-begin number)) + (setq gnus-newsgroup-unselected + (delq number gnus-newsgroup-unselected))) + ;; Report back a success? + (and header (mail-header-number header)))) (defun gnus-summary-work-articles (n) - "Return a list of articles to be worked upon. The prefix argument, + "Return a list of articles to be worked upon. The prefix argument, the list of process marked articles, and the current article will be taken into consideration." - (let (articles) - (if (and n (numberp n)) - (let ((backward (< n 0)) - (n (abs n))) - (save-excursion - (while (and (> n 0) - (setq articles (cons (gnus-summary-article-number) - articles)) - (gnus-summary-search-forward nil nil backward)) - (setq n (1- n)))) - (sort articles (function <))) - (or (reverse gnus-newsgroup-processable) - (list (gnus-summary-article-number)))))) + (cond + (n + ;; A numerical prefix has been given. + (let ((backward (< n 0)) + (n (abs (prefix-numeric-value n))) + articles article) + (save-excursion + (while + (and (> n 0) + (push (setq article (gnus-summary-article-number)) + articles) + (if backward + (gnus-summary-find-prev nil article) + (gnus-summary-find-next nil article))) + (decf n))) + (nreverse articles))) + ((and (boundp 'transient-mark-mode) + transient-mark-mode + mark-active) + ;; Work on the region between point and mark. + (let ((max (max (point) (mark))) + articles article) + (save-excursion + (goto-char (min (point) (mark))) + (while + (and + (push (setq article (gnus-summary-article-number)) articles) + (gnus-summary-find-next nil article) + (< (point) max))) + (nreverse articles)))) + (gnus-newsgroup-processable + ;; There are process-marked articles present. + (reverse gnus-newsgroup-processable)) + (t + ;; Just return the current article. + (list (gnus-summary-article-number))))) (defun gnus-summary-search-group (&optional backward use-level) "Search for next unread newsgroup. If optional argument BACKWARD is non-nil, search backward instead." (save-excursion (set-buffer gnus-group-buffer) - (if (gnus-group-search-forward + (if (gnus-group-search-forward backward nil (if use-level (gnus-group-group-level) nil)) (gnus-group-group-name)))) @@ -7548,78 +9611,100 @@ If EXCLUDE-GROUP, do not go to this group." (save-excursion (gnus-group-best-unread-group exclude-group)))) -(defun gnus-subject-equal (s1 s2) - (cond - ((null gnus-summary-gather-subject-limit) - (equal (gnus-simplify-subject-re s1) - (gnus-simplify-subject-re s2))) - ((eq gnus-summary-gather-subject-limit 'fuzzy) - (equal (gnus-simplify-subject-fuzzy s1) - (gnus-simplify-subject-fuzzy s2))) - ((numberp gnus-summary-gather-subject-limit) - (equal (gnus-limit-string s1 gnus-summary-gather-subject-limit) - (gnus-limit-string s2 gnus-summary-gather-subject-limit))) - (t - (equal s1 s2)))) - -(defun gnus-summary-search-subject (&optional backward unread subject) - "Search for article forward. -If BACKWARD is non-nil, search backward. -If UNREAD is non-nil, only unread articles are selected. -If SUBJECT is non-nil, the article which has the same subject will be -searched for." - (let ((func (if backward 'previous-single-property-change - 'next-single-property-change)) - (beg (point)) - (did t) - pos psubject) - (beginning-of-line) - (and gnus-summary-check-current unread - (eq (get-text-property (point) 'gnus-mark) gnus-unread-mark) - (setq did nil)) - (if (not did) - () - (forward-char (if backward (if (bobp) 0 -1) (if (eobp) 0 1))) - (while - (and - (setq pos (funcall func (point) 'gnus-number)) - (goto-char (if backward (1- pos) pos)) - (setq did - (not (and - (or (not unread) - (eq (get-text-property (point) 'gnus-mark) - gnus-unread-mark)) - (or (not subject) - (and (setq psubject - (inline (gnus-summary-subject-string))) - (inline - (gnus-subject-equal subject psubject))))))) - (if backward (if (bobp) nil (forward-char -1) t) - (if (eobp) nil (forward-char 1) t))))) - (if did - (progn (goto-char beg) nil) - (prog1 - (get-text-property (point) 'gnus-number) - (gnus-summary-show-thread) - (gnus-summary-position-cursor))))) - -(defun gnus-summary-pseudo-article () - "The thread level of the article on the current line." - (get-text-property (gnus-point-at-bol) 'gnus-pseudo)) - -(defalias 'gnus-summary-score 'gnus-summary-article-score) -(make-obsolete 'gnus-summary-score 'gnus-summary-article-score) -(defun gnus-summary-article-score () - "Return current article score." - (or (cdr (assq (gnus-summary-article-number) gnus-newsgroup-scored)) - gnus-summary-default-score 0)) +(defun gnus-summary-find-next (&optional unread article backward) + (if backward (gnus-summary-find-prev) + (let* ((dummy (gnus-summary-article-intangible-p)) + (article (or article (gnus-summary-article-number))) + (arts (gnus-data-find-list article)) + result) + (when (and (not dummy) + (or (not gnus-summary-check-current) + (not unread) + (not (gnus-data-unread-p (car arts))))) + (setq arts (cdr arts))) + (when (setq result + (if unread + (progn + (while arts + (when (gnus-data-unread-p (car arts)) + (setq result (car arts) + arts nil)) + (setq arts (cdr arts))) + result) + (car arts))) + (goto-char (gnus-data-pos result)) + (gnus-data-number result))))) + +(defun gnus-summary-find-prev (&optional unread article) + (let* ((eobp (eobp)) + (article (or article (gnus-summary-article-number))) + (arts (gnus-data-find-list article (gnus-data-list 'rev))) + result) + (when (and (not eobp) + (or (not gnus-summary-check-current) + (not unread) + (not (gnus-data-unread-p (car arts))))) + (setq arts (cdr arts))) + (if (setq result + (if unread + (progn + (while arts + (and (gnus-data-unread-p (car arts)) + (setq result (car arts) + arts nil)) + (setq arts (cdr arts))) + result) + (car arts))) + (progn + (goto-char (gnus-data-pos result)) + (gnus-data-number result))))) + +(defun gnus-summary-find-subject (subject &optional unread backward article) + (let* ((simp-subject (gnus-simplify-subject-fully subject)) + (article (or article (gnus-summary-article-number))) + (articles (gnus-data-list backward)) + (arts (gnus-data-find-list article articles)) + result) + (when (or (not gnus-summary-check-current) + (not unread) + (not (gnus-data-unread-p (car arts)))) + (setq arts (cdr arts))) + (while arts + (and (or (not unread) + (gnus-data-unread-p (car arts))) + (vectorp (gnus-data-header (car arts))) + (gnus-subject-equal + simp-subject (mail-header-subject (gnus-data-header (car arts))) t) + (setq result (car arts) + arts nil)) + (setq arts (cdr arts))) + (and result + (goto-char (gnus-data-pos result)) + (gnus-data-number result)))) + +(defun gnus-summary-search-forward (&optional unread subject backward) + "Search forward for an article. +If UNREAD, look for unread articles. If SUBJECT, look for +articles with that subject. If BACKWARD, search backward instead." + (cond (subject (gnus-summary-find-subject subject unread backward)) + (backward (gnus-summary-find-prev unread)) + (t (gnus-summary-find-next unread)))) + +(defun gnus-recenter (&optional n) + "Center point in window and redisplay frame. +Also do horizontal recentering." + (interactive "P") + (when (and gnus-auto-center-summary + (not (eq gnus-auto-center-summary 'vertical))) + (gnus-horizontal-recenter)) + (recenter n)) (defun gnus-summary-recenter () "Center point in the summary window. If `gnus-auto-center-summary' is nil, or the article buffer isn't -displayed, no centering will be performed." +displayed, no centering will be performed." ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle). - ;; Recenter only when requested. Suggested by popovich@park.cs.columbia.edu. + ;; Recenter only when requested. Suggested by popovich@park.cs.columbia.edu. (let* ((top (cond ((< (window-height) 4) 0) ((< (window-height) 7) 1) (t 2))) @@ -7628,21 +9713,56 @@ displayed, no centering will be performed." (forward-line (- height)) (point))) (window (get-buffer-window (current-buffer)))) - (and - ;; The user has to want it, - gnus-auto-center-summary - ;; the article buffer must be displayed, - (get-buffer-window gnus-article-buffer) - ;; Set the window start to either `bottom', which is the biggest - ;; possible valid number, or the second line from the top, - ;; whichever is the least. - (set-window-start - window (min bottom (save-excursion (forward-line (- top)) (point))))))) + ;; The user has to want it. + (when gnus-auto-center-summary + (when (get-buffer-window gnus-article-buffer) + ;; Only do recentering when the article buffer is displayed, + ;; Set the window start to either `bottom', which is the biggest + ;; possible valid number, or the second line from the top, + ;; whichever is the least. + (set-window-start + window (min bottom (save-excursion + (forward-line (- top)) (point))))) + ;; Do horizontal recentering while we're at it. + (when (and (get-buffer-window (current-buffer) t) + (not (eq gnus-auto-center-summary 'vertical))) + (let ((selected (selected-window))) + (select-window (get-buffer-window (current-buffer) t)) + (gnus-summary-position-point) + (gnus-horizontal-recenter) + (select-window selected)))))) + +(defun gnus-horizontal-recenter () + "Recenter the current buffer horizontally." + (if (< (current-column) (/ (window-width) 2)) + (set-window-hscroll (get-buffer-window (current-buffer) t) 0) + (let* ((orig (point)) + (end (window-end (get-buffer-window (current-buffer) t))) + (max 0)) + ;; Find the longest line currently displayed in the window. + (goto-char (window-start)) + (while (and (not (eobp)) + (< (point) end)) + (end-of-line) + (setq max (max max (current-column))) + (forward-line 1)) + (goto-char orig) + ;; Scroll horizontally to center (sort of) the point. + (if (> max (window-width)) + (set-window-hscroll + (get-buffer-window (current-buffer) t) + (min (- (current-column) (/ (window-width) 3)) + (+ 2 (- max (window-width))))) + (set-window-hscroll (get-buffer-window (current-buffer) t) 0)) + max))) ;; Function written by Stainless Steel Rat . (defun gnus-short-group-name (group &optional levels) "Collapse GROUP name LEVELS." - (let* ((name "") (foreign "") (depth -1) (skip 1) + (let* ((name "") + (foreign "") + (depth 0) + (skip 1) (levels (or levels (progn (while (string-match "\\." group skip) @@ -7653,7 +9773,8 @@ displayed, no centering will be performed." (setq foreign (substring group 0 (match-end 0)) group (substring group (match-end 0)))) (while group - (if (and (string-match "\\." group) (> levels 0)) + (if (and (string-match "\\." group) + (> levels (- gnus-group-uncollapsed-levels 1))) (setq name (concat name (substring group 0 1)) group (substring group (match-end 0)) levels (- levels 1) @@ -7682,31 +9803,29 @@ displayed, no centering will be performed." ;; difference between the ranges of read articles in this group and ;; the range of active articles. (defun gnus-list-of-unread-articles (group) - (let* ((read (nth 2 (nth 2 (gnus-gethash group gnus-newsrc-hashtb)))) - (active (gnus-gethash group gnus-active-hashtb)) + (let* ((read (gnus-info-read (gnus-get-info group))) + (active (gnus-active group)) (last (cdr active)) first nlast unread) - ;; If none are read, then all are unread. + ;; If none are read, then all are unread. (if (not read) (setq first (car active)) ;; If the range of read articles is a single range, then the ;; first unread article is the article after the last read - ;; article. Sounds logical, doesn't it? + ;; article. Sounds logical, doesn't it? (if (not (listp (cdr read))) (setq first (1+ (cdr read))) ;; `read' is a list of ranges. - (if (/= (setq nlast (or (and (numberp (car read)) (car read)) - (car (car read)))) 1) + (if (/= (setq nlast (or (and (numberp (car read)) (car read)) + (caar read))) 1) (setq first 1)) (while read - (if first + (if first (while (< first nlast) (setq unread (cons first unread)) (setq first (1+ first)))) - (setq first (1+ (if (atom (car read)) (car read) (cdr (car read))))) - (setq nlast (if (atom (car (cdr read))) - (car (cdr read)) - (car (car (cdr read))))) + (setq first (1+ (if (atom (car read)) (car read) (cdar read)))) + (setq nlast (if (atom (cadr read)) (cadr read) (caadr read))) (setq read (cdr read))))) ;; And add the last unread articles. (while (<= first last) @@ -7716,29 +9835,43 @@ displayed, no centering will be performed." (nreverse unread))) (defun gnus-list-of-read-articles (group) - (let ((info (nth 2 (gnus-gethash group gnus-newsrc-hashtb))) - (active (gnus-gethash group gnus-active-hashtb))) + "Return a list of unread, unticked and non-dormant articles." + (let* ((info (gnus-get-info group)) + (marked (gnus-info-marks info)) + (active (gnus-active group))) (and info active - (gnus-sorted-complement - (gnus-uncompress-range active) - (gnus-list-of-unread-articles group))))) + (gnus-set-difference + (gnus-sorted-complement + (gnus-uncompress-range active) + (gnus-list-of-unread-articles group)) + (append + (gnus-uncompress-range (cdr (assq 'dormant marked))) + (gnus-uncompress-range (cdr (assq 'tick marked)))))))) ;; Various summary commands -(defun gnus-summary-universal-argument () - "Perform any operation on all articles marked with the process mark." - (interactive) +(defun gnus-summary-universal-argument (arg) + "Perform any operation on all articles that are process/prefixed." + (interactive "P") (gnus-set-global-variables) - (let ((articles (reverse gnus-newsgroup-processable)) - func) - (or articles (error "No articles marked")) - (or (setq func (key-binding (read-key-sequence "C-c C-u"))) - (error "Undefined key")) - (while articles - (gnus-summary-goto-subject (car articles)) - (command-execute func) - (gnus-summary-remove-process-mark (car articles)) - (setq articles (cdr articles))))) + (let ((articles (gnus-summary-work-articles arg)) + func article) + (if (eq + (setq + func + (key-binding + (read-key-sequence + (substitute-command-keys + "\\\\[gnus-summary-universal-argument]" + )))) + 'undefined) + (gnus-error 1 "Undefined key") + (save-excursion + (while articles + (gnus-summary-goto-subject (setq article (pop articles))) + (command-execute func) + (gnus-summary-remove-process-mark article))))) + (gnus-summary-position-point)) (defun gnus-summary-toggle-truncation (&optional arg) "Toggle truncation of summary lines. @@ -7749,74 +9882,68 @@ With arg, turn line truncation on iff arg is positive." (> (prefix-numeric-value arg) 0))) (redraw-display)) -(defun gnus-summary-reselect-current-group (&optional all) - "Once exit and then reselect the current newsgroup. +(defun gnus-summary-reselect-current-group (&optional all rescan) + "Exit and then reselect the current newsgroup. The prefix argument ALL means to select all articles." (interactive "P") (gnus-set-global-variables) + (when (gnus-ephemeral-group-p gnus-newsgroup-name) + (error "Ephemeral groups can't be reselected")) (let ((current-subject (gnus-summary-article-number)) (group gnus-newsgroup-name)) (setq gnus-newsgroup-begin nil) - (gnus-summary-exit t) + (gnus-summary-exit) ;; We have to adjust the point of group mode buffer because the ;; current point was moved to the next unread newsgroup by ;; exiting. (gnus-summary-jump-to-group group) + (when rescan + (save-excursion + (gnus-group-get-new-news-this-group 1))) (gnus-group-read-group all t) - (gnus-summary-goto-subject current-subject))) + (gnus-summary-goto-subject current-subject nil t))) (defun gnus-summary-rescan-group (&optional all) "Exit the newsgroup, ask for new articles, and select the newsgroup." (interactive "P") - (gnus-set-global-variables) - ;; Fix by Ilja Weis . - (let ((group gnus-newsgroup-name)) - (gnus-summary-exit) - (gnus-summary-jump-to-group group) - (save-excursion - (set-buffer gnus-group-buffer) - (gnus-group-get-new-news-this-group 1)) - (gnus-summary-jump-to-group group) - (gnus-group-read-group all))) + (gnus-summary-reselect-current-group all t)) (defun gnus-summary-update-info () (let* ((group gnus-newsgroup-name)) - (if gnus-newsgroup-kill-headers - (setq gnus-newsgroup-killed - (gnus-compress-sequence - (nconc - (gnus-set-sorted-intersection - (gnus-uncompress-range gnus-newsgroup-killed) - (setq gnus-newsgroup-unselected - (sort gnus-newsgroup-unselected '<))) - (setq gnus-newsgroup-unreads - (sort gnus-newsgroup-unreads '<))) t))) - (or (listp (cdr gnus-newsgroup-killed)) - (setq gnus-newsgroup-killed (list gnus-newsgroup-killed))) + (when gnus-newsgroup-kill-headers + (setq gnus-newsgroup-killed + (gnus-compress-sequence + (nconc + (gnus-set-sorted-intersection + (gnus-uncompress-range gnus-newsgroup-killed) + (setq gnus-newsgroup-unselected + (sort gnus-newsgroup-unselected '<))) + (setq gnus-newsgroup-unreads + (sort gnus-newsgroup-unreads '<))) t))) + (unless (listp (cdr gnus-newsgroup-killed)) + (setq gnus-newsgroup-killed (list gnus-newsgroup-killed))) (let ((headers gnus-newsgroup-headers)) - (gnus-close-group group) (run-hooks 'gnus-exit-group-hook) - (gnus-update-read-articles - group gnus-newsgroup-unreads gnus-newsgroup-unselected - gnus-newsgroup-marked - t gnus-newsgroup-replied gnus-newsgroup-expirable - gnus-newsgroup-killed gnus-newsgroup-dormant - gnus-newsgroup-bookmarks - (and gnus-save-score gnus-newsgroup-scored)) - (and gnus-use-cross-reference - (gnus-mark-xrefs-as-read - group headers gnus-newsgroup-unreads gnus-newsgroup-expirable)) + (unless gnus-save-score + (setq gnus-newsgroup-scored nil)) + ;; Set the new ranges of read articles. + (gnus-update-read-articles + group (append gnus-newsgroup-unreads gnus-newsgroup-unselected)) + ;; Set the current article marks. + (gnus-update-marks) + ;; Do the cross-ref thing. + (when gnus-use-cross-reference + (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads)) ;; Do adaptive scoring, and possibly save score files. - (and gnus-newsgroup-adaptive - (gnus-score-adaptive)) - (and gnus-use-scoring - (fboundp 'gnus-score-save) - (funcall 'gnus-score-save)) + (when gnus-newsgroup-adaptive + (gnus-score-adaptive)) + (when gnus-use-scoring + (gnus-score-save)) ;; Do not switch windows but change the buffer to work. (set-buffer gnus-group-buffer) (or (gnus-ephemeral-group-p gnus-newsgroup-name) (gnus-group-update-group group))))) - + (defun gnus-summary-exit (&optional temporary) "Exit reading current newsgroup, and then return to group selection mode. gnus-exit-group-hook is called with no arguments if that value is non-nil." @@ -7828,46 +9955,66 @@ gnus-exit-group-hook is called with no arguments if that value is non-nil." (mode major-mode) (buf (current-buffer))) (run-hooks 'gnus-summary-prepare-exit-hook) + ;; If we have several article buffers, we kill them at exit. + (unless gnus-single-article-buffer + (gnus-kill-buffer gnus-original-article-buffer) + (setq gnus-article-current nil)) + (when gnus-use-cache + (gnus-cache-possibly-remove-articles) + (gnus-cache-save-buffers)) + (when gnus-use-trees + (gnus-tree-close group)) ;; Make all changes in this group permanent. - (gnus-summary-update-info) - (set-buffer buf) - (and gnus-use-cache (gnus-cache-possibly-remove-articles)) + (unless quit-config + (gnus-summary-update-info)) + (gnus-close-group group) ;; Make sure where I was, and go to next newsgroup. (set-buffer gnus-group-buffer) - (or quit-config - (progn - (gnus-group-jump-to-group group) - (gnus-group-next-unread-group 1))) + (unless quit-config + (gnus-group-jump-to-group group)) + (run-hooks 'gnus-summary-exit-hook) + (unless quit-config + (gnus-group-next-unread-group 1)) (if temporary nil ;Nothing to do. - ;; We set all buffer-local variables to nil. It is unclear why - ;; this is needed, but if we don't, buffer-local variables are - ;; not garbage-collected, it seems. This would the lead to en - ;; ever-growing Emacs. + ;; If we have several article buffers, we kill them at exit. + (unless gnus-single-article-buffer + (gnus-kill-buffer gnus-article-buffer) + (gnus-kill-buffer gnus-original-article-buffer) + (setq gnus-article-current nil)) (set-buffer buf) - (gnus-summary-clear-local-variables) - ;; We clear the global counterparts of the buffer-local - ;; variables as well, just to be on the safe side. - (gnus-configure-windows 'group 'force) - (gnus-summary-clear-local-variables) - ;; Return to group mode buffer. - (if (eq mode 'gnus-summary-mode) - (gnus-kill-buffer buf)) - (if (get-buffer gnus-article-buffer) + (if (not gnus-kill-summary-on-exit) + (gnus-deaden-summary) + ;; We set all buffer-local variables to nil. It is unclear why + ;; this is needed, but if we don't, buffer-local variables are + ;; not garbage-collected, it seems. This would the lead to en + ;; ever-growing Emacs. + (gnus-summary-clear-local-variables) + (when (get-buffer gnus-article-buffer) (bury-buffer gnus-article-buffer)) + ;; We clear the global counterparts of the buffer-local + ;; variables as well, just to be on the safe side. + (gnus-configure-windows 'group 'force) + (gnus-summary-clear-local-variables) + ;; Return to group mode buffer. + (if (eq mode 'gnus-summary-mode) + (gnus-kill-buffer buf))) (setq gnus-current-select-method gnus-select-method) (pop-to-buffer gnus-group-buffer) + ;; Clear the current group name. (if (not quit-config) (progn (gnus-group-jump-to-group group) - (gnus-group-next-unread-group 1)) + (gnus-group-next-unread-group 1) + (gnus-configure-windows 'group 'force)) (if (not (buffer-name (car quit-config))) (gnus-configure-windows 'group 'force) (set-buffer (car quit-config)) (and (eq major-mode 'gnus-summary-mode) (gnus-set-global-variables)) (gnus-configure-windows (cdr quit-config)))) - (run-hooks 'gnus-summary-exit-hook)))) + (unless quit-config + (setq gnus-newsgroup-name nil))))) (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update) (defun gnus-summary-exit-no-update (&optional no-questions) @@ -7876,37 +10023,140 @@ gnus-exit-group-hook is called with no arguments if that value is non-nil." (gnus-set-global-variables) (let* ((group gnus-newsgroup-name) (quit-config (gnus-group-quit-config group))) - (if (or no-questions - gnus-expert-user - (gnus-y-or-n-p "Do you really wanna quit reading this group? ")) - (progn - (gnus-close-group group) - (gnus-summary-clear-local-variables) - (set-buffer gnus-group-buffer) - (gnus-summary-clear-local-variables) - ;; Return to group selection mode. - (gnus-configure-windows 'group 'force) - (if (get-buffer gnus-summary-buffer) - (kill-buffer gnus-summary-buffer)) - (if (get-buffer gnus-article-buffer) - (bury-buffer gnus-article-buffer)) - (if (equal (gnus-group-group-name) group) - (gnus-group-next-unread-group 1)) - (if quit-config - (progn - (if (not (buffer-name (car quit-config))) - (gnus-configure-windows 'group 'force) - (set-buffer (car quit-config)) - (and (eq major-mode 'gnus-summary-mode) - (gnus-set-global-variables)) - (gnus-configure-windows (cdr quit-config))))))))) + (when (or no-questions + gnus-expert-user + (gnus-y-or-n-p "Do you really wanna quit reading this group? ")) + ;; If we have several article buffers, we kill them at exit. + (unless gnus-single-article-buffer + (gnus-kill-buffer gnus-article-buffer) + (gnus-kill-buffer gnus-original-article-buffer) + (setq gnus-article-current nil)) + (if (not gnus-kill-summary-on-exit) + (gnus-deaden-summary) + (gnus-close-group group) + (gnus-summary-clear-local-variables) + (set-buffer gnus-group-buffer) + (gnus-summary-clear-local-variables) + (when (get-buffer gnus-summary-buffer) + (kill-buffer gnus-summary-buffer))) + (unless gnus-single-article-buffer + (setq gnus-article-current nil)) + (when gnus-use-trees + (gnus-tree-close group)) + (when (get-buffer gnus-article-buffer) + (bury-buffer gnus-article-buffer)) + ;; Return to the group buffer. + (gnus-configure-windows 'group 'force) + ;; Clear the current group name. + (setq gnus-newsgroup-name nil) + (when (equal (gnus-group-group-name) group) + (gnus-group-next-unread-group 1)) + (when quit-config + (if (not (buffer-name (car quit-config))) + (gnus-configure-windows 'group 'force) + (set-buffer (car quit-config)) + (when (eq major-mode 'gnus-summary-mode) + (gnus-set-global-variables)) + (gnus-configure-windows (cdr quit-config))))))) + +;;; Dead summaries. + +(defvar gnus-dead-summary-mode-map nil) + +(if gnus-dead-summary-mode-map + nil + (setq gnus-dead-summary-mode-map (make-keymap)) + (suppress-keymap gnus-dead-summary-mode-map) + (substitute-key-definition + 'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map) + (let ((keys '("\C-d" "\r" "\177"))) + (while keys + (define-key gnus-dead-summary-mode-map + (pop keys) 'gnus-summary-wake-up-the-dead)))) + +(defvar gnus-dead-summary-mode nil + "Minor mode for Gnus summary buffers.") + +(defun gnus-dead-summary-mode (&optional arg) + "Minor mode for Gnus summary buffers." + (interactive "P") + (when (eq major-mode 'gnus-summary-mode) + (make-local-variable 'gnus-dead-summary-mode) + (setq gnus-dead-summary-mode + (if (null arg) (not gnus-dead-summary-mode) + (> (prefix-numeric-value arg) 0))) + (when gnus-dead-summary-mode + (unless (assq 'gnus-dead-summary-mode minor-mode-alist) + (push '(gnus-dead-summary-mode " Dead") minor-mode-alist)) + (unless (assq 'gnus-dead-summary-mode minor-mode-map-alist) + (push (cons 'gnus-dead-summary-mode gnus-dead-summary-mode-map) + minor-mode-map-alist))))) + +(defun gnus-deaden-summary () + "Make the current summary buffer into a dead summary buffer." + ;; Kill any previous dead summary buffer. + (when (and gnus-dead-summary + (buffer-name gnus-dead-summary)) + (save-excursion + (set-buffer gnus-dead-summary) + (when gnus-dead-summary-mode + (kill-buffer (current-buffer))))) + ;; Make this the current dead summary. + (setq gnus-dead-summary (current-buffer)) + (gnus-dead-summary-mode 1) + (let ((name (buffer-name))) + (when (string-match "Summary" name) + (rename-buffer + (concat (substring name 0 (match-beginning 0)) "Dead " + (substring name (match-beginning 0))) t)))) + +(defun gnus-kill-or-deaden-summary (buffer) + "Kill or deaden the summary BUFFER." + (when (and (buffer-name buffer) + (not gnus-single-article-buffer)) + (save-excursion + (set-buffer buffer) + (gnus-kill-buffer gnus-article-buffer) + (gnus-kill-buffer gnus-original-article-buffer))) + (cond (gnus-kill-summary-on-exit + (when (and gnus-use-trees + (and (get-buffer buffer) + (buffer-name (get-buffer buffer)))) + (save-excursion + (set-buffer (get-buffer buffer)) + (gnus-tree-close gnus-newsgroup-name))) + (gnus-kill-buffer buffer)) + ((and (get-buffer buffer) + (buffer-name (get-buffer buffer))) + (save-excursion + (set-buffer buffer) + (gnus-deaden-summary))))) + +(defun gnus-summary-wake-up-the-dead (&rest args) + "Wake up the dead summary buffer." + (interactive) + (gnus-dead-summary-mode -1) + (let ((name (buffer-name))) + (when (string-match "Dead " name) + (rename-buffer + (concat (substring name 0 (match-beginning 0)) + (substring name (match-end 0))) t))) + (gnus-message 3 "This dead summary is now alive again")) ;; Suggested by Andrew Eskilsson . -(defun gnus-summary-fetch-faq (group) - "Fetch the FAQ for the current group." - (interactive (list gnus-newsgroup-name)) +(defun gnus-summary-fetch-faq (&optional faq-dir) + "Fetch the FAQ for the current group. +If FAQ-DIR (the prefix), prompt for a directory to search for the faq +in." + (interactive + (list + (if current-prefix-arg + (completing-read + "Faq dir: " (and (listp gnus-group-faq-directory) + gnus-group-faq-directory))))) (let (gnus-faq-buffer) - (and (setq gnus-faq-buffer (gnus-group-fetch-faq group)) + (and (setq gnus-faq-buffer + (gnus-group-fetch-faq gnus-newsgroup-name faq-dir)) (gnus-configure-windows 'summary-faq)))) ;; Suggested by Per Abrahamsen . @@ -7919,14 +10169,14 @@ gnus-exit-group-hook is called with no arguments if that value is non-nil." "Describe summary mode commands briefly." (interactive) (gnus-message 6 - (substitute-command-keys "\\\\[gnus-summary-next-page]:Select \\[gnus-summary-next-unread-article]:Forward \\[gnus-summary-prev-unread-article]:Backward \\[gnus-summary-exit]:Exit \\[gnus-info-find-node]:Run Info \\[gnus-summary-describe-briefly]:This help"))) + (substitute-command-keys "\\\\[gnus-summary-next-page]:Select \\[gnus-summary-next-unread-article]:Forward \\[gnus-summary-prev-unread-article]:Backward \\[gnus-summary-exit]:Exit \\[gnus-info-find-node]:Run Info \\[gnus-summary-describe-briefly]:This help"))) ;; Walking around group mode buffer from summary mode. (defun gnus-summary-next-group (&optional no-article target-group backward) "Exit current newsgroup and then select next unread newsgroup. If prefix argument NO-ARTICLE is non-nil, no article is selected -initially. If NEXT-GROUP, go to this group. If BACKWARD, go to +initially. If NEXT-GROUP, go to this group. If BACKWARD, go to previous group instead." (interactive "P") (gnus-set-global-variables) @@ -7942,9 +10192,9 @@ previous group instead." ;; Then we find what group we are supposed to enter. (set-buffer gnus-group-buffer) (gnus-group-jump-to-group current-group) - (setq target-group - (or target-group - (if (eq gnus-keep-same-level 'best) + (setq target-group + (or target-group + (if (eq gnus-keep-same-level 'best) (gnus-summary-best-group gnus-newsgroup-name) (gnus-summary-search-group backward gnus-keep-same-level)))) (if (not target-group) @@ -7966,67 +10216,6 @@ previous group instead." (setq current-group target-group target-group nil))))))) -(defun gnus-summary-next-group-old (&optional no-article group backward) - "Exit current newsgroup and then select next unread newsgroup. -If prefix argument NO-ARTICLE is non-nil, no article is selected initially. -If BACKWARD, go to previous group instead." - (interactive "P") - (gnus-set-global-variables) - (let ((ingroup gnus-newsgroup-name) - (sumbuf (current-buffer)) - num) - (set-buffer gnus-group-buffer) - (if (and group - (or (and (numberp (setq num (car (gnus-gethash - group gnus-newsrc-hashtb)))) - (< num 1)) - (null num))) - (progn - (gnus-group-jump-to-group group) - (setq group nil)) - (gnus-group-jump-to-group ingroup)) - (gnus-summary-search-group backward) - (let ((group (or group (gnus-summary-search-group backward)))) - (set-buffer sumbuf) - (gnus-summary-exit t) ;Update all information. - (if (null group) - (gnus-summary-exit-no-update t) - (gnus-group-jump-to-group ingroup) - (setq group (gnus-summary-search-group backward)) - (gnus-message 5 "Selecting %s..." group) - (set-buffer gnus-group-buffer) - ;; We are now in group mode buffer. - ;; Make sure group mode buffer point is on GROUP. - (gnus-group-jump-to-group group) - (if (not (eq gnus-auto-select-next 'quietly)) - (progn - (gnus-summary-read-group group nil no-article sumbuf) - (and (string= gnus-newsgroup-name ingroup) - (bufferp sumbuf) (buffer-name sumbuf) - (progn - (set-buffer (setq gnus-summary-buffer sumbuf)) - (gnus-summary-exit-no-update t)))) - (let ((prevgroup group)) - (gnus-group-jump-to-group ingroup) - (setq group (gnus-summary-search-group backward)) - (gnus-summary-read-group group nil no-article sumbuf) - (while (and (string= gnus-newsgroup-name ingroup) - (bufferp sumbuf) - (buffer-name sumbuf) - (not (string= prevgroup (gnus-group-group-name)))) - (set-buffer gnus-group-buffer) - (gnus-summary-read-group - (setq prevgroup (gnus-group-group-name)) - nil no-article sumbuf)) - (and (string= prevgroup (gnus-group-group-name)) - ;; We have reached the final group in the group - ;; buffer. - (progn - (if (buffer-name sumbuf) - (progn - (set-buffer sumbuf) - (gnus-summary-exit))))))))))) - (defun gnus-summary-prev-group (&optional no-article) "Exit current newsgroup and then select previous unread newsgroup. If prefix argument NO-ARTICLE is non-nil, no article is selected initially." @@ -8038,20 +10227,33 @@ If prefix argument NO-ARTICLE is non-nil, no article is selected initially." (defun gnus-summary-first-subject (&optional unread) "Go to the first unread subject. If UNREAD is non-nil, go to the first unread article. -Returns nil if there are no unread articles." +Returns the article selected or nil if there are no unread articles." (interactive "P") (prog1 - (cond ((not unread) - (goto-char (point-min))) - ((gnus-goto-char - (text-property-any - (point-min) (point-max) 'gnus-mark gnus-unread-mark)) - t) - (t - ;; There are no unread articles. - (gnus-message 3 "No more unread articles") - nil)) - (gnus-summary-position-cursor))) + (cond + ;; Empty summary. + ((null gnus-newsgroup-data) + (gnus-message 3 "No articles in the group") + nil) + ;; Pick the first article. + ((not unread) + (goto-char (gnus-data-pos (car gnus-newsgroup-data))) + (gnus-data-number (car gnus-newsgroup-data))) + ;; No unread articles. + ((null gnus-newsgroup-unreads) + (gnus-message 3 "No more unread articles") + nil) + ;; Find the first unread article. + (t + (let ((data gnus-newsgroup-data)) + (while (and data + (not (gnus-data-unread-p (car data)))) + (setq data (cdr data))) + (if data + (progn + (goto-char (gnus-data-pos (car data))) + (gnus-data-number (car data))))))) + (gnus-summary-position-point))) (defun gnus-summary-next-subject (n &optional unread dont-display) "Go to next N'th summary line. @@ -8063,14 +10265,15 @@ returned." (let ((backward (< n 0)) (n (abs n))) (while (and (> n 0) - (gnus-summary-search-forward unread nil backward)) + (if backward + (gnus-summary-find-prev unread) + (gnus-summary-find-next unread))) (setq n (1- n))) (if (/= 0 n) (gnus-message 7 "No more%s articles" (if unread " unread" ""))) - (or dont-display - (progn - (gnus-summary-recenter) - (gnus-summary-position-cursor))) + (unless dont-display + (gnus-summary-recenter) + (gnus-summary-position-point)) n)) (defun gnus-summary-next-unread-subject (n) @@ -8089,33 +10292,24 @@ If optional argument UNREAD is non-nil, only unread article is selected." (interactive "p") (gnus-summary-next-subject (- n) t)) -(defun gnus-summary-goto-subject (article) - "Go the subject line of ARTICLE." - (interactive - (list - (string-to-int - (completing-read "Article number: " - (mapcar - (lambda (headers) - (list - (int-to-string (mail-header-number headers)))) - gnus-newsgroup-headers) - nil 'require-match)))) - (or article (error "No article number")) - (let ((b (point))) - (if (not (gnus-goto-char (text-property-any (point-min) (point-max) - 'gnus-number article))) - () - (gnus-summary-show-thread) - ;; Skip dummy articles. - (if (eq (gnus-summary-article-mark) gnus-dummy-mark) - (forward-line 1)) - (prog1 - (if (not (eobp)) - article - (goto-char b) - nil) - (gnus-summary-position-cursor))))) +(defun gnus-summary-goto-subject (article &optional force silent) + "Go the subject line of ARTICLE. +If FORCE, also allow jumping to articles not currently shown." + (let ((b (point)) + (data (gnus-data-find article))) + ;; We read in the article if we have to. + (and (not data) + force + (gnus-summary-insert-subject article (and (vectorp force) force) t) + (setq data (gnus-data-find article))) + (goto-char b) + (if (not data) + (progn + (unless silent + (gnus-message 3 "Can't find article %d" article)) + nil) + (goto-char (gnus-data-pos data)) + article))) ;; Walking around summary lines with displaying articles. @@ -8134,20 +10328,19 @@ Given a prefix, will force an `article' buffer configuration." (if (null article) nil (prog1 - (gnus-article-prepare article all-header) - (gnus-summary-show-thread) - (if (eq (gnus-summary-article-mark) gnus-dummy-mark) - (progn - (forward-line 1) - (gnus-summary-position-cursor))) + (if gnus-summary-display-article-function + (funcall gnus-summary-display-article-function article all-header) + (gnus-article-prepare article all-header)) (run-hooks 'gnus-select-article-hook) + (unless (zerop gnus-current-article) + (gnus-summary-goto-subject gnus-current-article)) (gnus-summary-recenter) - (gnus-summary-goto-subject article) + (when gnus-use-trees + (gnus-possibly-generate-tree article) + (gnus-highlight-selected-tree article)) ;; Successfully display article. - (gnus-summary-update-line) - (gnus-article-set-window-start - (cdr (assq article gnus-newsgroup-bookmarks))) - t))) + (gnus-article-set-window-start + (cdr (assq article gnus-newsgroup-bookmarks)))))) (defun gnus-summary-select-article (&optional all-headers force pseudo article) "Select the current article. @@ -8155,132 +10348,158 @@ If ALL-HEADERS is non-nil, show all header fields. If FORCE is non-nil, the article will be re-fetched even if it already present in the article buffer. If PSEUDO is non-nil, pseudo-articles will also be displayed." - (and (not pseudo) (gnus-summary-pseudo-article) - (error "This is a pseudo-article.")) + ;; Make sure we are in the summary buffer to work around bbdb bug. + (unless (eq major-mode 'gnus-summary-mode) + (set-buffer gnus-summary-buffer)) (let ((article (or article (gnus-summary-article-number))) (all-headers (not (not all-headers))) ;Must be T or NIL. - did) + gnus-summary-display-article-function + did) + (and (not pseudo) + (gnus-summary-article-pseudo-p article) + (error "This is a pseudo-article.")) (prog1 (save-excursion (set-buffer gnus-summary-buffer) - (if (or (null gnus-current-article) - (null gnus-article-current) - (null (get-buffer gnus-article-buffer)) - (not (eq article (cdr gnus-article-current))) - (not (equal (car gnus-article-current) gnus-newsgroup-name)) + (if (or (and gnus-single-article-buffer + (or (null gnus-current-article) + (null gnus-article-current) + (null (get-buffer gnus-article-buffer)) + (not (eq article (cdr gnus-article-current))) + (not (equal (car gnus-article-current) + gnus-newsgroup-name)))) + (and (not gnus-single-article-buffer) + (or (null gnus-current-article) + (not (eq gnus-current-article article)))) force) ;; The requested article is different from the current article. - (progn - (gnus-summary-display-article article all-headers) + (prog1 + (gnus-summary-display-article article all-headers) (setq did article)) - (if (or all-headers gnus-show-all-headers) + (if (or all-headers gnus-show-all-headers) (gnus-article-show-all-headers)) - nil)) - (if did - (gnus-article-set-window-start + 'old)) + (if did + (gnus-article-set-window-start (cdr (assq article gnus-newsgroup-bookmarks))))))) (defun gnus-summary-set-current-mark (&optional current-mark) "Obsolete function." nil) -(defun gnus-summary-next-article (&optional unread subject backward) +(defun gnus-summary-next-article (&optional unread subject backward push) "Select the next article. If UNREAD, only unread articles are selected. If SUBJECT, only articles with SUBJECT are selected. If BACKWARD, the previous article is selected instead of the next." (interactive "P") (gnus-set-global-variables) - (let (header) - (cond - ;; Is there such an article? - ((and (gnus-summary-search-forward unread subject backward) - (or (gnus-summary-display-article (gnus-summary-article-number)) - (eq (gnus-summary-article-mark) gnus-canceled-mark))) - (gnus-summary-position-cursor)) - ;; If not, we try the first unread, if that is wanted. - ((and subject - gnus-auto-select-same - (or (gnus-summary-first-unread-article) - (eq (gnus-summary-article-mark) gnus-canceled-mark))) - (gnus-summary-position-cursor) - (gnus-message 6 "Wrapped")) - ;; Try to get next/previous article not displayed in this group. - ((and gnus-auto-extend-newsgroup - (not unread) (not subject) - (setq header (gnus-more-header-forward backward))) - (gnus-extend-newsgroup header backward) - (let ((buffer-read-only nil)) - (goto-char (if backward (point-min) (point-max))) - (gnus-summary-prepare-threads (list header))) - (gnus-summary-goto-article (if backward gnus-newsgroup-begin - gnus-newsgroup-end))) - ;; Go to next/previous group. - (t - (or (gnus-ephemeral-group-p gnus-newsgroup-name) - (gnus-summary-jump-to-group gnus-newsgroup-name)) - (let ((cmd last-command-char) - (group - (if (eq gnus-keep-same-level 'best) - (gnus-summary-best-group gnus-newsgroup-name) - (gnus-summary-search-group backward gnus-keep-same-level)))) - ;; For some reason, the group window gets selected. We change - ;; it back. - (select-window (get-buffer-window (current-buffer))) - ;; Keep just the event type of CMD. - ;(and (listp cmd) (setq cmd (car cmd))) - ;; Select next unread newsgroup automagically. - (cond - ((not gnus-auto-select-next) - (gnus-message 7 "No more%s articles" (if unread " unread" ""))) - ((eq gnus-auto-select-next 'quietly) - ;; Select quietly. - (if (gnus-ephemeral-group-p gnus-newsgroup-name) - (gnus-summary-exit) - (gnus-message 7 "No more%s articles (%s)..." - (if unread " unread" "") - (if group (concat "selecting " group) - "exiting")) - (gnus-summary-next-group nil group backward))) - (t - (let ((keystrokes '(?\C-n ?\C-p)) - key) - (while (or (null key) (memq key keystrokes)) - (gnus-message - 7 "No more%s articles%s" (if unread " unread" "") - (if (and group - (not (gnus-ephemeral-group-p gnus-newsgroup-name))) - (format " (Type %s for %s [%s])" - (single-key-description cmd) group - (car (gnus-gethash group gnus-newsrc-hashtb))) - (format " (Type %s to exit %s)" - (single-key-description cmd) - gnus-newsgroup-name))) - ;; Confirm auto selection. - (let* ((event (read-char))) - (setq key (if (listp event) (car event) event)) - (if (memq key keystrokes) - (let ((obuf (current-buffer))) - (switch-to-buffer gnus-group-buffer) - (and group - (gnus-group-jump-to-group group)) - (condition-case () - (execute-kbd-macro (char-to-string key)) - (error (ding) nil)) - (setq group (gnus-group-group-name)) - (switch-to-buffer obuf))))) - (if (equal key cmd) - (if (or (not group) - (gnus-ephemeral-group-p gnus-newsgroup-name)) - (gnus-summary-exit) - (gnus-summary-next-group nil group backward)) - (execute-kbd-macro (char-to-string key))))))))))) + (cond + ;; Is there such an article? + ((and (gnus-summary-search-forward unread subject backward) + (or (gnus-summary-display-article (gnus-summary-article-number)) + (eq (gnus-summary-article-mark) gnus-canceled-mark))) + (gnus-summary-position-point)) + ;; If not, we try the first unread, if that is wanted. + ((and subject + gnus-auto-select-same + (or (gnus-summary-first-unread-article) + (eq (gnus-summary-article-mark) gnus-canceled-mark))) + (gnus-summary-position-point) + (gnus-message 6 "Wrapped")) + ;; Try to get next/previous article not displayed in this group. + ((and gnus-auto-extend-newsgroup + (not unread) (not subject)) + (gnus-summary-goto-article + (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end)) + nil t)) + ;; Go to next/previous group. + (t + (or (gnus-ephemeral-group-p gnus-newsgroup-name) + (gnus-summary-jump-to-group gnus-newsgroup-name)) + (let ((cmd last-command-char) + (group + (if (eq gnus-keep-same-level 'best) + (gnus-summary-best-group gnus-newsgroup-name) + (gnus-summary-search-group backward gnus-keep-same-level)))) + ;; For some reason, the group window gets selected. We change + ;; it back. + (select-window (get-buffer-window (current-buffer))) + ;; Select next unread newsgroup automagically. + (cond + ((or (not gnus-auto-select-next) + (not cmd)) + (gnus-message 7 "No more%s articles" (if unread " unread" ""))) + ((or (eq gnus-auto-select-next 'quietly) + (and (eq gnus-auto-select-next 'slightly-quietly) + push) + (and (eq gnus-auto-select-next 'almost-quietly) + (gnus-summary-last-article-p))) + ;; Select quietly. + (if (gnus-ephemeral-group-p gnus-newsgroup-name) + (gnus-summary-exit) + (gnus-message 7 "No more%s articles (%s)..." + (if unread " unread" "") + (if group (concat "selecting " group) + "exiting")) + (gnus-summary-next-group nil group backward))) + (t + (gnus-summary-walk-group-buffer + gnus-newsgroup-name cmd unread backward))))))) + +(defun gnus-summary-walk-group-buffer (from-group cmd unread backward) + (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1)) + (?\C-p (gnus-group-prev-unread-group 1)))) + keve key group ended) + (save-excursion + (set-buffer gnus-group-buffer) + (gnus-summary-jump-to-group from-group) + (setq group + (if (eq gnus-keep-same-level 'best) + (gnus-summary-best-group gnus-newsgroup-name) + (gnus-summary-search-group backward gnus-keep-same-level)))) + (while (not ended) + (gnus-message + 5 "No more%s articles%s" (if unread " unread" "") + (if (and group + (not (gnus-ephemeral-group-p gnus-newsgroup-name))) + (format " (Type %s for %s [%s])" + (single-key-description cmd) group + (car (gnus-gethash group gnus-newsrc-hashtb))) + (format " (Type %s to exit %s)" + (single-key-description cmd) + gnus-newsgroup-name))) + ;; Confirm auto selection. + (setq key (car (setq keve (gnus-read-event-char)))) + (setq ended t) + (cond + ((assq key keystrokes) + (let ((obuf (current-buffer))) + (switch-to-buffer gnus-group-buffer) + (and group + (gnus-group-jump-to-group group)) + (eval (cadr (assq key keystrokes))) + (setq group (gnus-group-group-name)) + (switch-to-buffer obuf)) + (setq ended nil)) + ((equal key cmd) + (if (or (not group) + (gnus-ephemeral-group-p gnus-newsgroup-name)) + (gnus-summary-exit) + (gnus-summary-next-group nil group backward))) + (t + (push (cdr keve) unread-command-events)))))) + +(defun gnus-read-event-char () + "Get the next event." + (let ((event (read-event))) + (cons (and (numberp event) event) event))) (defun gnus-summary-next-unread-article () "Select unread article after current one." (interactive) (gnus-summary-next-article t (and gnus-auto-select-same - (gnus-summary-subject-string)))) + (gnus-summary-article-subject)))) (defun gnus-summary-prev-article (&optional unread subject) "Select the article after the current one. @@ -8292,39 +10511,47 @@ If UNREAD is non-nil, only unread articles are selected." "Select unred article before current one." (interactive) (gnus-summary-prev-article t (and gnus-auto-select-same - (gnus-summary-subject-string)))) + (gnus-summary-article-subject)))) (defun gnus-summary-next-page (&optional lines circular) - "Show next page of selected article. -If end of article, select next article. -Argument LINES specifies lines to be scrolled up. -If CIRCULAR is non-nil, go to the start of the article instead of -instead of selecting the next article when reaching the end of the -current article." + "Show next page of the selected article. +If at the end of the current article, select the next article. +LINES says how many lines should be scrolled up. + +If CIRCULAR is non-nil, go to the start of the article instead of +selecting the next article when reaching the end of the current +article." (interactive "P") (setq gnus-summary-buffer (current-buffer)) (gnus-set-global-variables) (let ((article (gnus-summary-article-number)) (endp nil)) (gnus-configure-windows 'article) - (if (or (null gnus-current-article) - (null gnus-article-current) - (/= article (cdr gnus-article-current)) - (not (equal (car gnus-article-current) gnus-newsgroup-name))) - ;; Selected subject is different from current article's. - (gnus-summary-display-article article) - (gnus-eval-in-buffer-window - gnus-article-buffer - (setq endp (gnus-article-next-page lines))) - (if endp - (cond (circular - (gnus-summary-beginning-of-article)) - (lines - (gnus-message 3 "End of message")) - ((null lines) - (gnus-summary-next-unread-article))))) + (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark) + (if (and (eq gnus-summary-goto-unread 'never) + (not (gnus-summary-last-article-p article))) + (gnus-summary-next-article) + (gnus-summary-next-unread-article)) + (if (or (null gnus-current-article) + (null gnus-article-current) + (/= article (cdr gnus-article-current)) + (not (equal (car gnus-article-current) gnus-newsgroup-name))) + ;; Selected subject is different from current article's. + (gnus-summary-display-article article) + (gnus-eval-in-buffer-window gnus-article-buffer + (setq endp (gnus-article-next-page lines))) + (if endp + (cond (circular + (gnus-summary-beginning-of-article)) + (lines + (gnus-message 3 "End of message")) + ((null lines) + (if (and (eq gnus-summary-goto-unread 'never) + (not (gnus-summary-last-article-p article))) + (gnus-summary-next-article) + (gnus-summary-next-unread-article))))))) (gnus-summary-recenter) - (gnus-summary-position-cursor))) + (gnus-summary-position-point))) (defun gnus-summary-prev-page (&optional lines) "Show previous page of selected article. @@ -8341,8 +10568,8 @@ Argument LINES specifies lines to be scrolled down." (gnus-summary-display-article article) (gnus-summary-recenter) (gnus-eval-in-buffer-window gnus-article-buffer - (gnus-article-prev-page lines)))) - (gnus-summary-position-cursor)) + (gnus-article-prev-page lines)))) + (gnus-summary-position-point)) (defun gnus-summary-scroll-up (lines) "Scroll up (or down) one line current article. @@ -8350,43 +10577,43 @@ Argument LINES specifies lines to be scrolled up (or down if negative)." (interactive "p") (gnus-set-global-variables) (gnus-configure-windows 'article) - (or (gnus-summary-select-article nil nil 'pseudo) - (gnus-eval-in-buffer-window - gnus-article-buffer - (cond ((> lines 0) - (if (gnus-article-next-page lines) - (gnus-message 3 "End of message"))) - ((< lines 0) - (gnus-article-prev-page (- lines)))))) + (gnus-summary-show-thread) + (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old) + (gnus-eval-in-buffer-window gnus-article-buffer + (cond ((> lines 0) + (if (gnus-article-next-page lines) + (gnus-message 3 "End of message"))) + ((< lines 0) + (gnus-article-prev-page (- lines)))))) (gnus-summary-recenter) - (gnus-summary-position-cursor)) + (gnus-summary-position-point)) (defun gnus-summary-next-same-subject () "Select next article which has the same subject as current one." (interactive) (gnus-set-global-variables) - (gnus-summary-next-article nil (gnus-summary-subject-string))) + (gnus-summary-next-article nil (gnus-summary-article-subject))) (defun gnus-summary-prev-same-subject () "Select previous article which has the same subject as current one." (interactive) (gnus-set-global-variables) - (gnus-summary-prev-article nil (gnus-summary-subject-string))) + (gnus-summary-prev-article nil (gnus-summary-article-subject))) (defun gnus-summary-next-unread-same-subject () "Select next unread article which has the same subject as current one." (interactive) (gnus-set-global-variables) - (gnus-summary-next-article t (gnus-summary-subject-string))) + (gnus-summary-next-article t (gnus-summary-article-subject))) (defun gnus-summary-prev-unread-same-subject () "Select previous unread article which has the same subject as current one." (interactive) (gnus-set-global-variables) - (gnus-summary-prev-article t (gnus-summary-subject-string))) + (gnus-summary-prev-article t (gnus-summary-article-subject))) (defun gnus-summary-first-unread-article () - "Select the first unread article. + "Select the first unread article. Return nil if there are no unread articles." (interactive) (gnus-set-global-variables) @@ -8396,46 +10623,52 @@ Return nil if there are no unread articles." (gnus-summary-show-thread) (gnus-summary-first-subject t) (gnus-summary-display-article (gnus-summary-article-number)))) - (gnus-summary-position-cursor))) + (gnus-summary-position-point))) (defun gnus-summary-best-unread-article () "Select the unread article with the highest score." (interactive) (gnus-set-global-variables) (let ((best -1000000) + (data gnus-newsgroup-data) article score) - (save-excursion - (or (gnus-summary-first-subject t) + (while data + (and (gnus-data-unread-p (car data)) + (> (setq score + (gnus-summary-article-score (gnus-data-number (car data)))) + best) + (setq best score + article (gnus-data-number (car data)))) + (setq data (cdr data))) + (prog1 + (if article + (gnus-summary-goto-article article) (error "No unread articles")) - (while - (and - (progn - (and (> (setq score (gnus-summary-article-score)) best) - (setq best score - article (gnus-summary-article-number))) - t) - (gnus-summary-search-subject nil t)))) - (if (not article) - (error "No unread articles") - (gnus-summary-goto-article article)) - (gnus-summary-position-cursor))) + (gnus-summary-position-point)))) -(defun gnus-summary-goto-article (article &optional all-headers) +(defun gnus-summary-last-subject () + "Go to the last displayed subject line in the group." + (let ((article (gnus-data-number (car (gnus-data-list t))))) + (when article + (gnus-summary-goto-subject article)))) + +(defun gnus-summary-goto-article (article &optional all-headers force) "Fetch ARTICLE and display it if it exists. If ALL-HEADERS is non-nil, no header lines are hidden." (interactive (list (string-to-int - (completing-read + (completing-read "Article number: " - (mapcar (lambda (headers) - (list (int-to-string (mail-header-number headers)))) - gnus-newsgroup-headers) - nil 'require-match)))) + (mapcar (lambda (number) (list (int-to-string number))) + gnus-newsgroup-limit))) + current-prefix-arg + t)) (prog1 - (and (gnus-summary-goto-subject article) - (gnus-summary-display-article article all-headers)) - (gnus-summary-position-cursor))) + (if (gnus-summary-goto-subject article force) + (gnus-summary-display-article article all-headers) + (gnus-message 4 "Couldn't go to article %s" article) nil) + (gnus-summary-position-point))) (defun gnus-summary-goto-last-article () "Go to the previously read article." @@ -8443,7 +10676,7 @@ If ALL-HEADERS is non-nil, no header lines are hidden." (prog1 (and gnus-last-article (gnus-summary-goto-article gnus-last-article)) - (gnus-summary-position-cursor))) + (gnus-summary-position-point))) (defun gnus-summary-pop-article (number) "Pop one article off the history and go to the previous. @@ -8455,7 +10688,366 @@ NUMBER articles will be popped off." (if to (gnus-summary-goto-article (car to)) (error "Article history empty"))) - (gnus-summary-position-cursor)) + (gnus-summary-position-point)) + +;; Summary commands and functions for limiting the summary buffer. + +(defun gnus-summary-limit-to-articles (n) + "Limit the summary buffer to the next N articles. +If not given a prefix, use the process marked articles instead." + (interactive "P") + (gnus-set-global-variables) + (prog1 + (let ((articles (gnus-summary-work-articles n))) + (setq gnus-newsgroup-processable nil) + (gnus-summary-limit articles)) + (gnus-summary-position-point))) + +(defun gnus-summary-pop-limit (&optional total) + "Restore the previous limit. +If given a prefix, remove all limits." + (interactive "P") + (gnus-set-global-variables) + (when total + (setq gnus-newsgroup-limits + (list (mapcar (lambda (h) (mail-header-number h)) + gnus-newsgroup-headers)))) + (unless gnus-newsgroup-limits + (error "No limit to pop")) + (prog1 + (gnus-summary-limit nil 'pop) + (gnus-summary-position-point))) + +(defun gnus-summary-limit-to-subject (subject &optional header) + "Limit the summary buffer to articles that have subjects that match a regexp." + (interactive "sRegexp: ") + (unless header + (setq header "subject")) + (when (not (equal "" subject)) + (prog1 + (let ((articles (gnus-summary-find-matching + (or header "subject") subject 'all))) + (or articles (error "Found no matches for \"%s\"" subject)) + (gnus-summary-limit articles)) + (gnus-summary-position-point)))) + +(defun gnus-summary-limit-to-author (from) + "Limit the summary buffer to articles that have authors that match a regexp." + (interactive "sRegexp: ") + (gnus-summary-limit-to-subject from "from")) + +(defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread) +(make-obsolete + 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread) + +(defun gnus-summary-limit-to-unread (&optional all) + "Limit the summary buffer to articles that are not marked as read. +If ALL is non-nil, limit strictly to unread articles." + (interactive "P") + (if all + (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark)) + (gnus-summary-limit-to-marks + ;; Concat all the marks that say that an article is read and have + ;; those removed. + (list gnus-del-mark gnus-read-mark gnus-ancient-mark + gnus-killed-mark gnus-kill-file-mark + gnus-low-score-mark gnus-expirable-mark + gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark) + 'reverse))) + +(defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-to-marks) +(make-obsolete 'gnus-summary-delete-marked-with 'gnus-summary-limit-to-marks) + +(defun gnus-summary-limit-to-marks (marks &optional reverse) + "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\"). +If REVERSE, limit the summary buffer to articles that are not marked +with MARKS. MARKS can either be a string of marks or a list of marks. +Returns how many articles were removed." + (interactive "sMarks: ") + (gnus-set-global-variables) + (prog1 + (let ((data gnus-newsgroup-data) + (marks (if (listp marks) marks + (append marks nil))) ; Transform to list. + articles) + (while data + (and (if reverse (not (memq (gnus-data-mark (car data)) marks)) + (memq (gnus-data-mark (car data)) marks)) + (setq articles (cons (gnus-data-number (car data)) articles))) + (setq data (cdr data))) + (gnus-summary-limit articles)) + (gnus-summary-position-point))) + +(defun gnus-summary-limit-to-score (&optional score) + "Limit to articles with score at or above SCORE." + (interactive "P") + (gnus-set-global-variables) + (setq score (if score + (prefix-numeric-value score) + (or gnus-summary-default-score 0))) + (let ((data gnus-newsgroup-data) + articles) + (while data + (when (>= (gnus-summary-article-score (gnus-data-number (car data))) + score) + (push (gnus-data-number (car data)) articles)) + (setq data (cdr data))) + (prog1 + (gnus-summary-limit articles) + (gnus-summary-position-point)))) + +(defun gnus-summary-limit-include-dormant () + "Display all the hidden articles that are marked as dormant." + (interactive) + (gnus-set-global-variables) + (or gnus-newsgroup-dormant + (error "There are no dormant articles in this group")) + (prog1 + (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit)) + (gnus-summary-position-point))) + +(defun gnus-summary-limit-exclude-dormant () + "Hide all dormant articles." + (interactive) + (gnus-set-global-variables) + (prog1 + (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse) + (gnus-summary-position-point))) + +(defun gnus-summary-limit-exclude-childless-dormant () + "Hide all dormant articles that have no children." + (interactive) + (gnus-set-global-variables) + (let ((data (gnus-data-list t)) + articles d children) + ;; Find all articles that are either not dormant or have + ;; children. + (while (setq d (pop data)) + (when (or (not (= (gnus-data-mark d) gnus-dormant-mark)) + (and (setq children + (gnus-article-children (gnus-data-number d))) + (let (found) + (while children + (when (memq (car children) articles) + (setq children nil + found t)) + (pop children)) + found))) + (push (gnus-data-number d) articles))) + ;; Do the limiting. + (prog1 + (gnus-summary-limit articles) + (gnus-summary-position-point)))) + +(defun gnus-summary-limit-mark-excluded-as-read (&optional all) + "Mark all unread excluded articles as read. +If ALL, mark even excluded ticked and dormants as read." + (interactive "P") + (let ((articles (gnus-sorted-complement + (sort + (mapcar (lambda (h) (mail-header-number h)) + gnus-newsgroup-headers) + '<) + (sort gnus-newsgroup-limit '<))) + article) + (setq gnus-newsgroup-unreads nil) + (if all + (setq gnus-newsgroup-dormant nil + gnus-newsgroup-marked nil + gnus-newsgroup-reads + (nconc + (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles) + gnus-newsgroup-reads)) + (while (setq article (pop articles)) + (unless (or (memq article gnus-newsgroup-dormant) + (memq article gnus-newsgroup-marked)) + (push (cons article gnus-catchup-mark) gnus-newsgroup-reads)))))) + +(defun gnus-summary-limit (articles &optional pop) + (if pop + ;; We pop the previous limit off the stack and use that. + (setq articles (car gnus-newsgroup-limits) + gnus-newsgroup-limits (cdr gnus-newsgroup-limits)) + ;; We use the new limit, so we push the old limit on the stack. + (setq gnus-newsgroup-limits + (cons gnus-newsgroup-limit gnus-newsgroup-limits))) + ;; Set the limit. + (setq gnus-newsgroup-limit articles) + (let ((total (length gnus-newsgroup-data)) + (data (gnus-data-find-list (gnus-summary-article-number))) + found) + ;; This will do all the work of generating the new summary buffer + ;; according to the new limit. + (gnus-summary-prepare) + ;; Hide any threads, possibly. + (and gnus-show-threads + gnus-thread-hide-subtree + (gnus-summary-hide-all-threads)) + ;; Try to return to the article you were at, or one in the + ;; neighborhood. + (if data + ;; We try to find some article after the current one. + (while data + (and (gnus-summary-goto-subject + (gnus-data-number (car data)) nil t) + (setq data nil + found t)) + (setq data (cdr data)))) + (or found + ;; If there is no data, that means that we were after the last + ;; article. The same goes when we can't find any articles + ;; after the current one. + (progn + (goto-char (point-max)) + (gnus-summary-find-prev))) + ;; We return how many articles were removed from the summary + ;; buffer as a result of the new limit. + (- total (length gnus-newsgroup-data)))) + +(defsubst gnus-invisible-cut-children (threads) + (let ((num 0)) + (while threads + (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit) + (incf num)) + (pop threads)) + (< num 2))) + +(defsubst gnus-cut-thread (thread) + "Go forwards in the thread until we find an article that we want to display." + (when (or (eq gnus-fetch-old-headers 'some) + (eq gnus-build-sparse-threads 'some) + (eq gnus-build-sparse-threads 'more)) + ;; Deal with old-fetched headers and sparse threads. + (while (and + thread + (or + (memq (mail-header-number (car thread)) gnus-newsgroup-sparse) + (memq (mail-header-number (car thread)) gnus-newsgroup-ancient)) + (or (<= (length (cdr thread)) 1) + (gnus-invisible-cut-children (cdr thread)))) + (setq thread (cadr thread)))) + thread) + +(defun gnus-cut-threads (threads) + "Cut off all uninteresting articles from the beginning of threads." + (when (or (eq gnus-fetch-old-headers 'some) + (eq gnus-build-sparse-threads 'some) + (eq gnus-build-sparse-threads 'more)) + (let ((th threads)) + (while th + (setcar th (gnus-cut-thread (car th))) + (setq th (cdr th))))) + ;; Remove nixed out threads. + (delq nil threads)) + +(defun gnus-summary-initial-limit (&optional show-if-empty) + "Figure out what the initial limit is supposed to be on group entry. +This entails weeding out unwanted dormants, low-scored articles, +fetch-old-headers verbiage, and so on." + ;; Most groups have nothing to remove. + (if (or gnus-inhibit-limiting + (and (null gnus-newsgroup-dormant) + (not (eq gnus-fetch-old-headers 'some)) + (null gnus-summary-expunge-below) + (not (eq gnus-build-sparse-threads 'some)) + (not (eq gnus-build-sparse-threads 'more)) + (null gnus-thread-expunge-below) + (not gnus-use-nocem))) + () ; Do nothing. + (push gnus-newsgroup-limit gnus-newsgroup-limits) + (setq gnus-newsgroup-limit nil) + (mapatoms + (lambda (node) + (unless (car (symbol-value node)) + ;; These threads have no parents -- they are roots. + (let ((nodes (cdr (symbol-value node))) + thread) + (while nodes + (if (and gnus-thread-expunge-below + (< (gnus-thread-total-score (car nodes)) + gnus-thread-expunge-below)) + (gnus-expunge-thread (pop nodes)) + (setq thread (pop nodes)) + (gnus-summary-limit-children thread)))))) + gnus-newsgroup-dependencies) + ;; If this limitation resulted in an empty group, we might + ;; pop the previous limit and use it instead. + (when (and (not gnus-newsgroup-limit) + show-if-empty) + (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits))) + gnus-newsgroup-limit)) + +(defun gnus-summary-limit-children (thread) + "Return 1 if this subthread is visible and 0 if it is not." + ;; First we get the number of visible children to this thread. This + ;; is done by recursing down the thread using this function, so this + ;; will really go down to a leaf article first, before slowly + ;; working its way up towards the root. + (when thread + (let ((children + (if (cdr thread) + (apply '+ (mapcar 'gnus-summary-limit-children + (cdr thread))) + 0)) + (number (mail-header-number (car thread))) + score) + (if (or + ;; If this article is dormant and has absolutely no visible + ;; children, then this article isn't visible. + (and (memq number gnus-newsgroup-dormant) + (= children 0)) + ;; If this is "fetch-old-headered" and there is only one + ;; visible child (or less), then we don't want this article. + (and (eq gnus-fetch-old-headers 'some) + (memq number gnus-newsgroup-ancient) + (zerop children)) + ;; If this is a sparsely inserted article with no children, + ;; we don't want it. + (and (eq gnus-build-sparse-threads 'some) + (memq number gnus-newsgroup-sparse) + (zerop children)) + ;; If we use expunging, and this article is really + ;; low-scored, then we don't want this article. + (when (and gnus-summary-expunge-below + (< (setq score + (or (cdr (assq number gnus-newsgroup-scored)) + gnus-summary-default-score)) + gnus-summary-expunge-below)) + ;; We increase the expunge-tally here, but that has + ;; nothing to do with the limits, really. + (incf gnus-newsgroup-expunged-tally) + ;; We also mark as read here, if that's wanted. + (when (and gnus-summary-mark-below + (< score gnus-summary-mark-below)) + (setq gnus-newsgroup-unreads + (delq number gnus-newsgroup-unreads)) + (if gnus-newsgroup-auto-expire + (push number gnus-newsgroup-expirable) + (push (cons number gnus-low-score-mark) + gnus-newsgroup-reads))) + t) + (and gnus-use-nocem + (gnus-nocem-unwanted-article-p (mail-header-id (car thread))))) + ;; Nope, invisible article. + 0 + ;; Ok, this article is to be visible, so we add it to the limit + ;; and return 1. + (setq gnus-newsgroup-limit (cons number gnus-newsgroup-limit)) + 1)))) + +(defun gnus-expunge-thread (thread) + "Mark all articles in THREAD as read." + (let* ((number (mail-header-number (car thread)))) + (incf gnus-newsgroup-expunged-tally) + ;; We also mark as read here, if that's wanted. + (setq gnus-newsgroup-unreads + (delq number gnus-newsgroup-unreads)) + (if gnus-newsgroup-auto-expire + (push number gnus-newsgroup-expirable) + (push (cons number gnus-low-score-mark) + gnus-newsgroup-reads))) + ;; Go recursively through all subthreads. + (mapcar 'gnus-expunge-thread (cdr thread))) ;; Summary article oriented commands @@ -8464,118 +11056,141 @@ NUMBER articles will be popped off." The difference between N and the number of articles fetched is returned." (interactive "p") (gnus-set-global-variables) - (while - (and + (while + (and (> n 0) - (let ((ref (mail-header-references (gnus-get-header-by-num - (gnus-summary-article-number))))) - (if (and ref (not (equal ref "")) - (string-match "<[^<>]*>[ \t]*$" ref)) - (gnus-summary-refer-article - (substring ref (match-beginning 0) (match-end 0))) + (let* ((header (gnus-summary-article-header)) + (ref + ;; If we try to find the parent of the currently + ;; displayed article, then we take a look at the actual + ;; References header, since this is slightly more + ;; reliable than the References field we got from the + ;; server. + (if (and (eq (mail-header-number header) + (cdr gnus-article-current)) + (equal gnus-newsgroup-name + (car gnus-article-current))) + (save-excursion + (set-buffer gnus-original-article-buffer) + (nnheader-narrow-to-headers) + (prog1 + (message-fetch-field "references") + (widen))) + ;; It's not the current article, so we take a bet on + ;; the value we got from the server. + (mail-header-references header)))) + (if (setq ref (or ref (mail-header-references header))) + (or (gnus-summary-refer-article (gnus-parent-id ref)) + (gnus-message 1 "Couldn't find parent")) (gnus-message 1 "No references in article %d" (gnus-summary-article-number)) nil))) (setq n (1- n))) - (gnus-summary-position-cursor) + (gnus-summary-position-point) n) - + +(defun gnus-summary-refer-references () + "Fetch all articles mentioned in the References header. +Return how many articles were fetched." + (interactive) + (gnus-set-global-variables) + (let ((ref (mail-header-references (gnus-summary-article-header))) + (current (gnus-summary-article-number)) + (n 0)) + ;; For each Message-ID in the References header... + (while (string-match "<[^>]*>" ref) + (incf n) + ;; ... fetch that article. + (gnus-summary-refer-article + (prog1 (match-string 0 ref) + (setq ref (substring ref (match-end 0)))))) + (gnus-summary-goto-subject current) + (gnus-summary-position-point) + n)) + (defun gnus-summary-refer-article (message-id) - "Refer article specified by MESSAGE-ID. -NOTE: This command only works with newsgroups that use real or simulated NNTP." + "Fetch an article specified by MESSAGE-ID." (interactive "sMessage-ID: ") - (if (or (not (stringp message-id)) - (zerop (length message-id))) - () + (when (and (stringp message-id) + (not (zerop (length message-id)))) ;; Construct the correct Message-ID if necessary. ;; Suggested by tale@pawl.rpi.edu. - (or (string-match "^<" message-id) - (setq message-id (concat "<" message-id))) - (or (string-match ">$" message-id) - (setq message-id (concat message-id ">"))) - (let ((header (car (gnus-gethash (downcase message-id) - gnus-newsgroup-dependencies)))) + (unless (string-match "^<" message-id) + (setq message-id (concat "<" message-id))) + (unless (string-match ">$" message-id) + (setq message-id (concat message-id ">"))) + (let* ((header (gnus-id-to-header message-id)) + (sparse (and header + (memq (mail-header-number header) + gnus-newsgroup-sparse)))) (if header - (or (gnus-summary-goto-article (mail-header-number header)) - ;; The header has been read, but the article had been - ;; expunged, so we insert it again. - (progn - (gnus-summary-insert-line - nil header 0 nil gnus-read-mark nil nil - (mail-header-subject header)) - (forward-line -1) - (mail-header-number header))) - (let ((gnus-override-method gnus-refer-article-method) - (gnus-ancient-mark gnus-read-mark) - (tmp-point (window-start - (get-buffer-window gnus-article-buffer))) - number tmp-buf) - (and gnus-refer-article-method - (gnus-check-server gnus-refer-article-method)) - ;; Save the old article buffer. - (save-excursion - (set-buffer (gnus-article-setup-buffer)) - (gnus-kill-buffer " *temp Article*") - (setq tmp-buf (rename-buffer " *temp Article*"))) (prog1 - (if (gnus-article-prepare - message-id nil (gnus-read-header message-id)) - (progn - (setq number (mail-header-number gnus-current-headers)) - (gnus-rebuild-thread message-id) - (gnus-summary-goto-subject number) - (if (null gnus-use-full-window) - (progn - (delete-windows-on tmp-buf) - (gnus-configure-windows 'article 'force))) - (gnus-summary-recenter) - (gnus-article-set-window-start - (cdr (assq number gnus-newsgroup-bookmarks))) - (and gnus-visual - (run-hooks 'gnus-visual-mark-article-hook)) - message-id) - ;; We restore the old article buffer. - (save-excursion - (kill-buffer gnus-article-buffer) - (set-buffer tmp-buf) - (rename-buffer gnus-article-buffer) - (let ((buffer-read-only nil)) - (and tmp-point - (set-window-start (get-buffer-window (current-buffer)) - tmp-point))))))))))) - -(defun gnus-summary-enter-digest-group () + ;; The article is present in the buffer, to we just go to it. + (gnus-summary-goto-article + (mail-header-number header) nil header) + (when sparse + (gnus-summary-update-article (mail-header-number header)))) + ;; We fetch the article + (let ((gnus-override-method + (and (gnus-news-group-p gnus-newsgroup-name) + gnus-refer-article-method)) + number) + ;; Start the special refer-article method, if necessary. + (when (and gnus-refer-article-method + (gnus-news-group-p gnus-newsgroup-name)) + (gnus-check-server gnus-refer-article-method)) + ;; Fetch the header, and display the article. + (if (setq number (gnus-summary-insert-subject message-id)) + (gnus-summary-select-article nil nil nil number) + (gnus-message 3 "Couldn't fetch article %s" message-id))))))) + +(defun gnus-summary-enter-digest-group (&optional force) "Enter a digest group based on the current article." - (interactive) + (interactive "P") (gnus-set-global-variables) (gnus-summary-select-article) - ;; We do not want a narrowed article. - (gnus-summary-stop-page-breaking) - (let ((name (format "%s-%d" - (gnus-group-prefixed-name - gnus-newsgroup-name (list 'nndoc "")) + (let ((name (format "%s-%d" + (gnus-group-prefixed-name + gnus-newsgroup-name (list 'nndoc "")) gnus-current-article)) (ogroup gnus-newsgroup-name) - (buf (current-buffer))) - (if (gnus-group-read-ephemeral-group - name (list 'nndoc name - (list 'nndoc-address (get-buffer gnus-article-buffer)) - '(nndoc-article-type digest)) - t) - (setcdr (nthcdr 4 (nth 2 (gnus-gethash name gnus-newsrc-hashtb))) - (list (list (cons 'to-group ogroup)))) - (switch-to-buffer buf) - (gnus-set-global-variables) - (gnus-configure-windows 'summary) - (gnus-message 3 "Article not a digest?")))) - -(defun gnus-summary-isearch-article () - "Do incremental search forward on current article." - (interactive) + (case-fold-search t) + (buf (current-buffer)) + dig) + (save-excursion + (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*")) + (insert-buffer-substring gnus-original-article-buffer) + (narrow-to-region + (goto-char (point-min)) + (or (search-forward "\n\n" nil t) (point))) + (goto-char (point-min)) + (delete-matching-lines "^\\(Path\\):\\|^From ") + (widen)) + (unwind-protect + (if (gnus-group-read-ephemeral-group + name `(nndoc ,name (nndoc-address + ,(get-buffer dig)) + (nndoc-article-type ,(if force 'digest 'guess))) t) + ;; Make all postings to this group go to the parent group. + (nconc (gnus-info-params (gnus-get-info name)) + (list (cons 'to-group ogroup))) + ;; Couldn't select this doc group. + (switch-to-buffer buf) + (gnus-set-global-variables) + (gnus-configure-windows 'summary) + (gnus-message 3 "Article couldn't be entered?")) + (kill-buffer dig)))) + +(defun gnus-summary-isearch-article (&optional regexp-p) + "Do incremental search forward on the current article. +If REGEXP-P (the prefix) is non-nil, do regexp isearch." + (interactive "P") (gnus-set-global-variables) (gnus-summary-select-article) - (gnus-eval-in-buffer-window - gnus-article-buffer (isearch-forward))) + (gnus-configure-windows 'article) + (gnus-eval-in-buffer-window gnus-article-buffer + (goto-char (point-min)) + (isearch-forward regexp-p))) (defun gnus-summary-search-article-forward (regexp &optional backward) "Search for an article containing REGEXP forward. @@ -8592,9 +11207,7 @@ If BACKWARD, search backward instead." (if (string-equal regexp "") (setq regexp (or gnus-last-search-regexp "")) (setq gnus-last-search-regexp regexp)) - (if (gnus-summary-search-article regexp backward) - (gnus-article-set-window-start - (cdr (assq (gnus-summary-article-number) gnus-newsgroup-bookmarks))) + (unless (gnus-summary-search-article regexp backward) (error "Search failed: \"%s\"" regexp))) (defun gnus-summary-search-article-backward (regexp) @@ -8610,62 +11223,96 @@ If BACKWARD, search backward instead." (defun gnus-summary-search-article (regexp &optional backward) "Search for an article containing REGEXP. Optional argument BACKWARD means do search for backward. -gnus-select-article-hook is not called during the search." +`gnus-select-article-hook' is not called during the search." (let ((gnus-select-article-hook nil) ;Disable hook. + (gnus-article-display-hook nil) (gnus-mark-article-hook nil) ;Inhibit marking as read. (re-search (if backward - (function re-search-backward) (function re-search-forward))) - (found nil) - (last nil)) - ;; Hidden thread subtrees must be searched for ,too. - (gnus-summary-show-all-threads) - (if (eobp) (forward-line -1)) - ;; First of all, search current article. - ;; We don't want to read article again from NNTP server nor reset - ;; current point. - (gnus-summary-select-article) - (gnus-message 9 "Searching article: %d..." gnus-current-article) - (setq last gnus-current-article) - (gnus-eval-in-buffer-window - gnus-article-buffer - (save-restriction - (widen) - ;; Begin search from current point. - (setq found (funcall re-search regexp nil t)))) - ;; Then search next articles. - (while (and (not found) - (gnus-summary-display-article - (gnus-summary-search-subject backward nil nil))) - (gnus-message 9 "Searching article: %d..." gnus-current-article) - (gnus-eval-in-buffer-window - gnus-article-buffer - (save-restriction - (widen) - (goto-char (if backward (point-max) (point-min))) - (setq found (funcall re-search regexp nil t))))) - (message "") - ;; Adjust article pointer. - (or (eq last gnus-current-article) - (setq gnus-last-article last)) - ;; Return T if found such article. - found)) + 're-search-backward 're-search-forward)) + (sum (current-buffer)) + (found nil)) + (gnus-save-hidden-threads + (gnus-summary-select-article) + (set-buffer gnus-article-buffer) + (when backward + (forward-line -1)) + (while (not found) + (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current)) + (if (if backward + (re-search-backward regexp nil t) + (re-search-forward regexp nil t)) + ;; We found the regexp. + (progn + (setq found 'found) + (beginning-of-line) + (set-window-start + (get-buffer-window (current-buffer)) + (point)) + (forward-line 1) + (set-buffer sum)) + ;; We didn't find it, so we go to the next article. + (set-buffer sum) + (if (not (if backward (gnus-summary-find-prev) + (gnus-summary-find-next))) + ;; No more articles. + (setq found t) + ;; Select the next article and adjust point. + (gnus-summary-select-article) + (set-buffer gnus-article-buffer) + (widen) + (goto-char (if backward (point-max) (point-min)))))) + (gnus-message 7 "")) + ;; Return whether we found the regexp. + (when (eq found 'found) + (gnus-summary-show-thread) + (gnus-summary-goto-subject gnus-current-article) + (gnus-summary-position-point) + t))) + +(defun gnus-summary-find-matching (header regexp &optional backward unread + not-case-fold) + "Return a list of all articles that match REGEXP on HEADER. +The search stars on the current article and goes forwards unless +BACKWARD is non-nil. If BACKWARD is `all', do all articles. +If UNREAD is non-nil, only unread articles will +be taken into consideration. If NOT-CASE-FOLD, case won't be folded +in the comparisons." + (let ((data (if (eq backward 'all) gnus-newsgroup-data + (gnus-data-find-list + (gnus-summary-article-number) (gnus-data-list backward)))) + (func `(lambda (h) (,(intern (concat "mail-header-" header)) h))) + (case-fold-search (not not-case-fold)) + articles d) + (or (fboundp (intern (concat "mail-header-" header))) + (error "%s is not a valid header" header)) + (while data + (setq d (car data)) + (and (or (not unread) ; We want all articles... + (gnus-data-unread-p d)) ; Or just unreads. + (vectorp (gnus-data-header d)) ; It's not a pseudo. + (string-match regexp (funcall func (gnus-data-header d))) ; Match. + (setq articles (cons (gnus-data-number d) articles))) ; Success! + (setq data (cdr data))) + (nreverse articles))) (defun gnus-summary-execute-command (header regexp command &optional backward) "Search forward for an article whose HEADER matches REGEXP and execute COMMAND. If HEADER is an empty string (or nil), the match is done on the entire -article. If BACKWARD (the prefix) is non-nil, search backward instead." +article. If BACKWARD (the prefix) is non-nil, search backward instead." (interactive (list (let ((completion-ignore-case t)) - (completing-read + (completing-read "Header name: " (mapcar (lambda (string) (list string)) '("Number" "Subject" "From" "Lines" "Date" - "Message-ID" "Xref" "References")) + "Message-ID" "Xref" "References" "Body")) nil 'require-match)) (read-string "Regexp: ") (read-key-sequence "Command: ") current-prefix-arg)) + (when (equal header "Body") + (setq header "")) (gnus-set-global-variables) ;; Hidden thread subtrees must be searched as well. (gnus-summary-show-all-threads) @@ -8675,8 +11322,7 @@ article. If BACKWARD (the prefix) is non-nil, search backward instead." (gnus-message 6 "Executing %s..." (key-description command)) ;; We'd like to execute COMMAND interactively so as to give arguments. (gnus-execute header regexp - (` (lambda () - (call-interactively '(, (key-binding command))))) + `(lambda () (call-interactively ',(key-binding command))) backward) (gnus-message 6 "Executing %s...done" (key-description command))))) @@ -8686,11 +11332,10 @@ article. If BACKWARD (the prefix) is non-nil, search backward instead." (gnus-set-global-variables) (gnus-summary-select-article) (gnus-configure-windows 'article) - (gnus-eval-in-buffer-window - gnus-article-buffer - (widen) - (goto-char (point-min)) - (and gnus-break-pages (gnus-narrow-to-page)))) + (gnus-eval-in-buffer-window gnus-article-buffer + (widen) + (goto-char (point-min)) + (and gnus-break-pages (gnus-narrow-to-page)))) (defun gnus-summary-end-of-article () "Scroll to the end of the article." @@ -8698,20 +11343,31 @@ article. If BACKWARD (the prefix) is non-nil, search backward instead." (gnus-set-global-variables) (gnus-summary-select-article) (gnus-configure-windows 'article) - (gnus-eval-in-buffer-window - gnus-article-buffer - (widen) - (goto-char (point-max)) - (recenter -3) - (and gnus-break-pages (gnus-narrow-to-page)))) - -(defun gnus-summary-show-article () - "Force re-fetching of the current article." - (interactive) + (gnus-eval-in-buffer-window gnus-article-buffer + (widen) + (goto-char (point-max)) + (recenter -3) + (and gnus-break-pages (gnus-narrow-to-page)))) + +(defun gnus-summary-show-article (&optional arg) + "Force re-fetching of the current article. +If ARG (the prefix) is non-nil, show the raw article without any +article massaging functions being run." + (interactive "P") (gnus-set-global-variables) - (gnus-summary-select-article nil 'force) - (gnus-configure-windows 'article) - (gnus-summary-position-cursor)) + (if (not arg) + ;; Select the article the normal way. + (gnus-summary-select-article nil 'force) + ;; Bind the article treatment functions to nil. + (let ((gnus-have-all-headers t) + gnus-article-display-hook + gnus-article-prepare-hook + gnus-break-pages + gnus-visual) + (gnus-summary-select-article nil 'force))) + (gnus-summary-goto-subject gnus-current-article) +; (gnus-configure-windows 'article) + (gnus-summary-position-point)) (defun gnus-summary-verbose-headers (&optional arg) "Toggle permanent full header display. @@ -8735,27 +11391,25 @@ If ARG is a negative number, hide the unwanted header lines." (gnus-set-global-variables) (save-excursion (set-buffer gnus-article-buffer) - (let ((buffer-read-only nil)) - (if (numberp arg) - (if (> arg 0) (remove-text-properties (point-min) (point-max) - gnus-hidden-properties) - (if (< arg 0) (run-hooks 'gnus-article-display-hook))) - (if (text-property-any (point-min) (point-max) 'invisible t) - (remove-text-properties - (point-min) (point-max) gnus-hidden-properties) - ;; We hide the headers. This song and dance act below is - ;; done because `gnus-have-all-headers' is buffer-local to - ;; the summary buffer, and we only want to temporarily - ;; change it in that buffer. Ugh. - (let ((have gnus-have-all-headers)) - (save-excursion - (set-buffer gnus-summary-buffer) - (setq gnus-have-all-headers nil) - (save-excursion - (set-buffer gnus-article-buffer) - (run-hooks 'gnus-article-display-hook)) - (setq gnus-have-all-headers have))))) - (set-window-point (get-buffer-window (current-buffer)) (point-min))))) + (let* ((buffer-read-only nil) + (inhibit-point-motion-hooks t) + (hidden (text-property-any + (goto-char (point-min)) (search-forward "\n\n") + 'invisible t)) + e) + (goto-char (point-min)) + (when (search-forward "\n\n" nil t) + (delete-region (point-min) (1- (point)))) + (goto-char (point-min)) + (save-excursion + (set-buffer gnus-original-article-buffer) + (goto-char (point-min)) + (setq e (1- (or (search-forward "\n\n" nil t) (point-max))))) + (insert-buffer-substring gnus-original-article-buffer 1 e) + (let ((gnus-inhibit-hiding t)) + (run-hooks 'gnus-article-display-hook)) + (if (or (not hidden) (and (numberp arg) (< arg 0))) + (gnus-article-hide-headers))))) (defun gnus-summary-show-all-headers () "Make all header lines visible." @@ -8781,130 +11435,216 @@ forward." (gnus-set-global-variables) (gnus-summary-select-article) (let ((mail-header-separator "")) - (gnus-eval-in-buffer-window - gnus-article-buffer - (save-restriction - (widen) - (let ((start (window-start))) - (news-caesar-buffer-body arg) - (set-window-start (get-buffer-window (current-buffer)) start)))))) + (gnus-eval-in-buffer-window gnus-article-buffer + (save-restriction + (widen) + (let ((start (window-start)) + buffer-read-only) + (message-caesar-buffer-body arg) + (set-window-start (get-buffer-window (current-buffer)) start)))))) (defun gnus-summary-stop-page-breaking () "Stop page breaking in the current article." (interactive) (gnus-set-global-variables) (gnus-summary-select-article) - (gnus-eval-in-buffer-window gnus-article-buffer (widen))) - -;; Suggested by Brian Edmonds . + (gnus-eval-in-buffer-window gnus-article-buffer + (widen))) -(defun gnus-summary-move-article (&optional n to-newsgroup select-method) +(defun gnus-summary-move-article (&optional n to-newsgroup select-method action) "Move the current article to a different newsgroup. If N is a positive number, move the N next articles. If N is a negative number, move the N previous articles. If N is nil and any articles have been marked with the process mark, move those articles instead. -If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to. -If SELECT-METHOD is symbol, do not move to a specific newsgroup, but +If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to. +If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but re-spool using this method. + For this function to work, both the current newsgroup and the newsgroup that you want to move to have to support the `request-move' -and `request-accept' functions. (Ie. mail newsgroups at present.)" +and `request-accept' functions." (interactive "P") + (unless action (setq action 'move)) (gnus-set-global-variables) - (or (gnus-check-backend-function 'request-move-article gnus-newsgroup-name) - (error "The current newsgroup does not support article moving")) + ;; Check whether the source group supports the required functions. + (cond ((and (eq action 'move) + (not (gnus-check-backend-function + 'request-move-article gnus-newsgroup-name))) + (error "The current group does not support article moving")) + ((and (eq action 'crosspost) + (not (gnus-check-backend-function + 'request-replace-article gnus-newsgroup-name))) + (error "The current group does not support article editing"))) (let ((articles (gnus-summary-work-articles n)) (prefix (gnus-group-real-prefix gnus-newsgroup-name)) - art-group to-method sel-met) - (if (and (not to-newsgroup) (not select-method)) - (setq to-newsgroup - (completing-read - (format "Where do you want to move %s? %s" - (if (> (length articles) 1) - (format "these %d articles" (length articles)) - "this article") - (if gnus-current-move-group - (format "(%s default) " gnus-current-move-group) - "")) - gnus-active-hashtb nil nil prefix))) - (if to-newsgroup - (progn - (if (or (string= to-newsgroup "") (string= to-newsgroup prefix)) - (setq to-newsgroup (or gnus-current-move-group ""))) - (or (gnus-gethash to-newsgroup gnus-active-hashtb) - (gnus-activate-group to-newsgroup) - (error "No such group: %s" to-newsgroup)) - (setq gnus-current-move-group to-newsgroup))) - (setq to-method (if select-method (list select-method "") - (gnus-find-method-for-group to-newsgroup))) + (names '((move "Move" "Moving") + (copy "Copy" "Copying") + (crosspost "Crosspost" "Crossposting"))) + (copy-buf (save-excursion + (nnheader-set-temp-buffer " *copy article*"))) + art-group to-method new-xref article to-groups) + (unless (assq action names) + (error "Unknown action %s" action)) + ;; Read the newsgroup name. + (when (and (not to-newsgroup) + (not select-method)) + (setq to-newsgroup + (gnus-read-move-group-name + (cadr (assq action names)) + (symbol-value (intern (format "gnus-current-%s-group" action))) + articles prefix)) + (set (intern (format "gnus-current-%s-group" action)) to-newsgroup)) + (setq to-method (or select-method + (gnus-group-name-to-method to-newsgroup))) + ;; Check the method we are to move this article to... (or (gnus-check-backend-function 'request-accept-article (car to-method)) (error "%s does not support article copying" (car to-method))) (or (gnus-check-server to-method) (error "Can't open server %s" (car to-method))) - (gnus-message 6 "Moving to %s: %s..." - (or select-method to-newsgroup) articles) + (gnus-message 6 "%s to %s: %s..." + (caddr (assq action names)) + (or (car select-method) to-newsgroup) articles) (while articles - (if (setq art-group - (gnus-request-move-article - (car articles) ; Article to move - gnus-newsgroup-name ; From newsgroup - (nth 1 (gnus-find-method-for-group - gnus-newsgroup-name)) ; Server - (list 'gnus-request-accept-article - (if select-method - (list 'quote select-method) - to-newsgroup) - (not (cdr articles))) ; Accept form - (not (cdr articles)))) ; Only save nov last time - (let* ((buffer-read-only nil) - (entry - (or - (gnus-gethash (car art-group) gnus-newsrc-hashtb) - (gnus-gethash - (gnus-group-prefixed-name - (car art-group) - (if select-method (list select-method "") + (setq article (pop articles)) + (setq + art-group + (cond + ;; Move the article. + ((eq action 'move) + (gnus-request-move-article + article ; Article to move + gnus-newsgroup-name ; From newsgrouo + (nth 1 (gnus-find-method-for-group + gnus-newsgroup-name)) ; Server + (list 'gnus-request-accept-article + to-newsgroup (list 'quote select-method) + (not articles)) ; Accept form + (not articles))) ; Only save nov last time + ;; Copy the article. + ((eq action 'copy) + (save-excursion + (set-buffer copy-buf) + (gnus-request-article-this-buffer article gnus-newsgroup-name) + (gnus-request-accept-article + to-newsgroup select-method (not articles)))) + ;; Crosspost the article. + ((eq action 'crosspost) + (let ((xref (mail-header-xref (gnus-summary-article-header article)))) + (setq new-xref (concat gnus-newsgroup-name ":" article)) + (if (and xref (not (string= xref ""))) + (progn + (when (string-match "^Xref: " xref) + (setq xref (substring xref (match-end 0)))) + (setq new-xref (concat xref " " new-xref))) + (setq new-xref (concat (system-name) " " new-xref))) + (save-excursion + (set-buffer copy-buf) + (gnus-request-article-this-buffer article gnus-newsgroup-name) + (nnheader-replace-header "xref" new-xref) + (gnus-request-accept-article + to-newsgroup select-method (not articles))))))) + (if (not art-group) + (gnus-message 1 "Couldn't %s article %s" + (cadr (assq action names)) article) + (let* ((entry + (or + (gnus-gethash (car art-group) gnus-newsrc-hashtb) + (gnus-gethash + (gnus-group-prefixed-name + (car art-group) + (or select-method (gnus-find-method-for-group to-newsgroup))) - gnus-newsrc-hashtb))) - (info (nth 2 entry)) - (article (car articles))) - (gnus-summary-goto-subject article) - (beginning-of-line) - (delete-region (point) (progn (forward-line 1) (point))) - ;; Update the group that has been moved to. - (if (not info) - () ; This group does not exist yet. - (if (not (memq article gnus-newsgroup-unreads)) - (setcar (cdr (cdr info)) - (gnus-add-to-range (nth 2 info) - (list (cdr art-group))))) - ;; Copy any marks over to the new group. - (let ((marks '((tick . gnus-newsgroup-marked) - (dormant . gnus-newsgroup-dormant) - (expire . gnus-newsgroup-expirable) - (bookmark . gnus-newsgroup-bookmarks) - (reply . gnus-newsgroup-replied))) - (to-article (cdr art-group))) - (while marks - (if (memq article (symbol-value (cdr (car marks)))) - (gnus-add-marked-articles - (car info) (car (car marks)) (list to-article) info)) - (setq marks (cdr marks))))) - ;; Update marks. - (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)) - (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads)) - (setq gnus-newsgroup-dormant - (delq article gnus-newsgroup-dormant)) - (setq gnus-newsgroup-reads - (cons (cons article gnus-canceled-mark) - gnus-newsgroup-reads))) - (gnus-message 1 "Couldn't move article %s" (car articles))) - (gnus-summary-remove-process-mark (car articles)) - (setq articles (cdr articles))) + gnus-newsrc-hashtb))) + (info (nth 2 entry)) + (to-group (gnus-info-group info))) + ;; Update the group that has been moved to. + (when (and info + (memq action '(move copy))) + (unless (member to-group to-groups) + (push to-group to-groups)) + + (unless (memq article gnus-newsgroup-unreads) + (gnus-info-set-read + info (gnus-add-to-range (gnus-info-read info) + (list (cdr art-group))))) + + ;; Copy any marks over to the new group. + (let ((marks gnus-article-mark-lists) + (to-article (cdr art-group))) + + ;; See whether the article is to be put in the cache. + (when gnus-use-cache + (gnus-cache-possibly-enter-article + to-group to-article + (let ((header (copy-sequence + (gnus-summary-article-header article)))) + (mail-header-set-number header to-article) + header) + (memq article gnus-newsgroup-marked) + (memq article gnus-newsgroup-dormant) + (memq article gnus-newsgroup-unreads))) + + (while marks + (when (memq article (symbol-value + (intern (format "gnus-newsgroup-%s" + (caar marks))))) + ;; If the other group is the same as this group, + ;; then we have to add the mark to the list. + (when (equal to-group gnus-newsgroup-name) + (set (intern (format "gnus-newsgroup-%s" (caar marks))) + (cons to-article + (symbol-value + (intern (format "gnus-newsgroup-%s" + (caar marks))))))) + ;; Copy mark to other group. + (gnus-add-marked-articles + to-group (cdar marks) (list to-article) info)) + (setq marks (cdr marks))))) + + ;; Update the Xref header in this article to point to + ;; the new crossposted article we have just created. + (when (eq action 'crosspost) + (save-excursion + (set-buffer copy-buf) + (gnus-request-article-this-buffer article gnus-newsgroup-name) + (nnheader-replace-header + "xref" (concat new-xref " " (gnus-group-prefixed-name + (car art-group) to-method) + ":" (cdr art-group))) + (gnus-request-replace-article + article gnus-newsgroup-name (current-buffer))))) + + (gnus-summary-goto-subject article) + (when (eq action 'move) + (gnus-summary-mark-article article gnus-canceled-mark))) + (gnus-summary-remove-process-mark article)) + ;; Re-activate all groups that have been moved to. + (while to-groups + (gnus-activate-group (pop to-groups))) + + (gnus-kill-buffer copy-buf) + (gnus-summary-position-point) (gnus-set-mode-line 'summary))) -(defun gnus-summary-respool-article (&optional n respool-method) +(defun gnus-summary-copy-article (&optional n to-newsgroup select-method) + "Move the current article to a different newsgroup. +If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to. +If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but +re-spool using this method." + (interactive "P") + (gnus-summary-move-article n nil select-method 'copy)) + +(defun gnus-summary-crosspost-article (&optional n) + "Crosspost the current article to some other group." + (interactive "P") + (gnus-summary-move-article n nil nil 'crosspost)) + +(defvar gnus-summary-respool-default-method nil + "Default method for respooling an article. +If nil, use to the current newsgroup method.") + +(defun gnus-summary-respool-article (&optional n method) "Respool the current article. The article will be squeezed through the mail spooling process again, which means that it will be put in some mail newsgroup or other @@ -8918,119 +11658,43 @@ Respooling can be done both from mail groups and \"real\" newsgroups. In the former case, the articles in question will be moved from the current group into whatever groups they are destined to. In the latter case, they will be copied into the relevant groups." - (interactive "P") - (gnus-set-global-variables) - (let ((respool-methods (gnus-methods-using 'respool)) - (methname - (symbol-name (car (gnus-find-method-for-group gnus-newsgroup-name))))) - (or respool-method - (setq respool-method - (completing-read - "What method do you want to use when respooling? " - respool-methods nil t methname))) - (or (string= respool-method "") - (if (assoc (symbol-name - (car (gnus-find-method-for-group gnus-newsgroup-name))) - respool-methods) - (gnus-summary-move-article n nil (intern respool-method)) - (gnus-summary-copy-article n nil (intern respool-method)))))) - -;; Suggested by gregj@unidata.com (Gregory J. Grubbs). -(defun gnus-summary-copy-article (&optional n to-newsgroup select-method) - "Move the current article to a different newsgroup. -If N is a positive number, move the N next articles. -If N is a negative number, move the N previous articles. -If N is nil and any articles have been marked with the process mark, -move those articles instead. -If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to. -If SELECT-METHOD is symbol, do not move to a specific newsgroup, but -re-spool using this method. -For this function to work, the newsgroup that you want to move to have -to support the `request-move' and `request-accept' -functions. (Ie. mail newsgroups at present.)" - (interactive "P") + (interactive + (list current-prefix-arg + (let* ((methods (gnus-methods-using 'respool)) + (methname + (symbol-name (or gnus-summary-respool-default-method + (car (gnus-find-method-for-group + gnus-newsgroup-name))))) + (method + (gnus-completing-read + methname "What backend do you want to use when respooling?" + methods nil t nil 'gnus-method-history)) + ms) + (cond + ((zerop (length (setq ms (gnus-servers-using-backend method)))) + (list (intern method) "")) + ((= 1 (length ms)) + (car ms)) + (t + (cdr (completing-read + "Server name: " + (mapcar (lambda (m) (cons (cadr m) m)) ms) nil t))))))) (gnus-set-global-variables) - (let ((articles (gnus-summary-work-articles n)) - (copy-buf (get-buffer-create "*copy work*")) - (prefix (gnus-group-real-prefix gnus-newsgroup-name)) - art-group to-method) - (buffer-disable-undo copy-buf) - (if (and (not to-newsgroup) (not select-method)) - (setq to-newsgroup - (completing-read - (format "Where do you want to copy %s? %s" - (if (> (length articles) 1) - (format "these %d articles" (length articles)) - "this article") - (if gnus-current-move-group - (format "(%s default) " gnus-current-move-group) - "")) - gnus-active-hashtb nil nil prefix))) - (if to-newsgroup - (progn - (if (or (string= to-newsgroup "") (string= to-newsgroup prefix)) - (setq to-newsgroup (or gnus-current-move-group ""))) - (or (gnus-gethash to-newsgroup gnus-active-hashtb) - (gnus-activate-group to-newsgroup) - (error "No such group: %s" to-newsgroup)) - (setq gnus-current-move-group to-newsgroup))) - (setq to-method (if select-method (list select-method "") - (gnus-find-method-for-group to-newsgroup))) - (or (gnus-check-backend-function 'request-accept-article (car to-method)) - (error "%s does not support article copying" (car to-method))) - (or (gnus-check-server to-method) - (error "Can't open server %s" (car to-method))) - (while articles - (gnus-message 6 "Copying to %s: %s..." - (or select-method to-newsgroup) articles) - (if (setq art-group - (save-excursion - (set-buffer copy-buf) - (gnus-request-article-this-buffer - (car articles) gnus-newsgroup-name) - (gnus-request-accept-article - (if select-method (list 'quote select-method) to-newsgroup) - (not (cdr articles))))) - (let* ((entry - (or - (gnus-gethash (car art-group) gnus-newsrc-hashtb) - (gnus-gethash - (gnus-group-prefixed-name - (car art-group) - (if select-method (list select-method "") - (gnus-find-method-for-group to-newsgroup))) - gnus-newsrc-hashtb))) - (info (nth 2 entry)) - (article (car articles))) - ;; We copy the info over to the new group. - (if (not info) - () ; This group does not exist (yet). - (if (not (memq article gnus-newsgroup-unreads)) - (setcar (cdr (cdr info)) - (gnus-add-to-range (nth 2 info) - (list (cdr art-group))))) - ;; Copy any marks over to the new group. - (let ((marks '((tick . gnus-newsgroup-marked) - (dormant . gnus-newsgroup-dormant) - (expire . gnus-newsgroup-expirable) - (bookmark . gnus-newsgroup-bookmarks) - (reply . gnus-newsgroup-replied))) - (to-article (cdr art-group))) - (while marks - (if (memq article (symbol-value (cdr (car marks)))) - (gnus-add-marked-articles - (car info) (car (car marks)) (list to-article) info)) - (setq marks (cdr marks)))))) - (gnus-message 1 "Couldn't copy article %s" (car articles))) - (gnus-summary-remove-process-mark (car articles)) - (setq articles (cdr articles))) - (kill-buffer copy-buf))) + (unless method + (error "No method given for respooling")) + (if (assoc (symbol-name + (car (gnus-find-method-for-group gnus-newsgroup-name))) + (gnus-methods-using 'respool)) + (gnus-summary-move-article n nil method) + (gnus-summary-copy-article n nil method))) (defun gnus-summary-import-article (file) "Import a random file into a mail newsgroup." (interactive "fImport file: ") + (gnus-set-global-variables) (let ((group gnus-newsgroup-name) - atts) + (now (current-time)) + atts lines) (or (gnus-check-backend-function 'request-accept-article group) (error "%s does not support article importing" group)) (or (file-readable-p file) @@ -9042,45 +11706,61 @@ functions. (Ie. mail newsgroups at present.)" (erase-buffer) (insert-file-contents file) (goto-char (point-min)) - (if (nnheader-article-p) - () - (setq atts (file-attributes file)) + (unless (nnheader-article-p) + ;; This doesn't look like an article, so we fudge some headers. + (setq atts (file-attributes file) + lines (count-lines (point-min) (point-max))) (insert "From: " (read-string "From: ") "\n" "Subject: " (read-string "Subject: ") "\n" - "Date: " (current-time-string (nth 5 atts)) "\n" + "Date: " (timezone-make-date-arpa-standard + (current-time-string (nth 5 atts)) + (current-time-zone now) + (current-time-zone now)) "\n" + "Message-ID: " (message-make-message-id) "\n" + "Lines: " (int-to-string lines) "\n" "Chars: " (int-to-string (nth 7 atts)) "\n\n")) - (gnus-request-accept-article group t) + (gnus-request-accept-article group nil t) (kill-buffer (current-buffer))))) -(defun gnus-summary-expire-articles () +(defun gnus-summary-expire-articles (&optional now) "Expire all articles that are marked as expirable in the current group." (interactive) - (if (not (gnus-check-backend-function - 'request-expire-articles gnus-newsgroup-name)) - () - (let* ((info (nth 2 (gnus-gethash gnus-newsgroup-name - gnus-newsrc-hashtb))) - (total (memq 'total-expire (nth 5 info))) + (gnus-set-global-variables) + (when (gnus-check-backend-function + 'request-expire-articles gnus-newsgroup-name) + ;; This backend supports expiry. + (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name)) (expirable (if total (gnus-list-of-read-articles gnus-newsgroup-name) (setq gnus-newsgroup-expirable (sort gnus-newsgroup-expirable '<)))) + (expiry-wait (if now 'immediate + (gnus-group-get-parameter + gnus-newsgroup-name 'expiry-wait))) es) - (if (not expirable) - () + (when expirable + ;; There are expirable articles in this group, so we run them + ;; through the expiry process. (gnus-message 6 "Expiring articles...") ;; The list of articles that weren't expired is returned. - (setq es (gnus-request-expire-articles expirable gnus-newsgroup-name)) + (if expiry-wait + (let ((nnmail-expiry-wait-function nil) + (nnmail-expiry-wait expiry-wait)) + (setq es (gnus-request-expire-articles + expirable gnus-newsgroup-name))) + (setq es (gnus-request-expire-articles + expirable gnus-newsgroup-name))) (or total (setq gnus-newsgroup-expirable es)) ;; We go through the old list of expirable, and mark all ;; really expired articles as nonexistent. - (or (eq es expirable) ;If nothing was expired, we don't mark. - (let ((gnus-use-cache nil)) - (while expirable - (or (memq (car expirable) es) - (gnus-summary-mark-article - (car expirable) gnus-canceled-mark)) - (setq expirable (cdr expirable))))) + (unless (eq es expirable) ;If nothing was expired, we don't mark. + (let ((gnus-use-cache nil)) + (while expirable + (unless (memq (car expirable) es) + (when (gnus-data-find (car expirable)) + (gnus-summary-mark-article + (car expirable) gnus-canceled-mark))) + (setq expirable (cdr expirable))))) (gnus-message 6 "Expiring articles...done"))))) (defun gnus-summary-expire-articles-now () @@ -9088,47 +11768,48 @@ functions. (Ie. mail newsgroups at present.)" This means that *all* articles that are marked as expirable will be deleted forever, right now." (interactive) + (gnus-set-global-variables) (or gnus-expert-user (gnus-y-or-n-p - "Are you really, really, really sure you want to expunge? ") + "Are you really, really, really sure you want to delete all these messages? ") (error "Phew!")) - (let ((nnmail-expiry-wait -1) - (nnmail-expiry-wait-function nil)) - (gnus-summary-expire-articles))) + (gnus-summary-expire-articles t)) ;; Suggested by Jack Vinson . (defun gnus-summary-delete-article (&optional n) "Delete the N next (mail) articles. -This command actually deletes articles. This is not a marking -command. The article will disappear forever from you life, never to -return. +This command actually deletes articles. This is not a marking +command. The article will disappear forever from your life, never to +return. If N is negative, delete backwards. If N is nil and articles have been marked with the process mark, delete these instead." (interactive "P") - (or (gnus-check-backend-function 'request-expire-articles + (gnus-set-global-variables) + (or (gnus-check-backend-function 'request-expire-articles gnus-newsgroup-name) (error "The current newsgroup does not support article deletion.")) ;; Compute the list of articles to delete. (let ((articles (gnus-summary-work-articles n)) not-deleted) (if (and gnus-novice-user - (not (gnus-y-or-n-p + (not (gnus-y-or-n-p (format "Do you really want to delete %s forever? " - (if (> (length articles) 1) "these articles" + (if (> (length articles) 1) + (format "these %s articles" (length articles)) "this article"))))) () ;; Delete the articles. - (setq not-deleted (gnus-request-expire-articles + (setq not-deleted (gnus-request-expire-articles articles gnus-newsgroup-name 'force)) (while articles - (gnus-summary-remove-process-mark (car articles)) + (gnus-summary-remove-process-mark (car articles)) ;; The backend might not have been able to delete the article - ;; after all. + ;; after all. (or (memq (car articles) not-deleted) (gnus-summary-mark-article (car articles) gnus-canceled-mark)) (setq articles (cdr articles)))) - (gnus-summary-position-cursor) + (gnus-summary-position-point) (gnus-set-mode-line 'summary) not-deleted)) @@ -9138,21 +11819,24 @@ This will have permanent effect only in mail groups. If FORCE is non-nil, allow editing of articles even in read-only groups." (interactive "P") - (or force - (not (gnus-group-read-only-p)) + (save-excursion + (set-buffer gnus-summary-buffer) + (gnus-set-global-variables) + (when (and (not force) + (gnus-group-read-only-p)) (error "The current newsgroup does not support article editing.")) - (gnus-summary-select-article t) - (gnus-configure-windows 'article) - (select-window (get-buffer-window gnus-article-buffer)) - (gnus-message 6 "C-c C-c to end edits") - (setq buffer-read-only nil) - (text-mode) - (use-local-map (copy-keymap (current-local-map))) - (local-set-key "\C-c\C-c" 'gnus-summary-edit-article-done) - (buffer-enable-undo) - (widen) - (goto-char (point-min)) - (search-forward "\n\n" nil t)) + (gnus-summary-select-article t nil t) + (gnus-configure-windows 'article) + (select-window (get-buffer-window gnus-article-buffer)) + (gnus-message 6 "C-c C-c to end edits") + (setq buffer-read-only nil) + (text-mode) + (use-local-map (copy-keymap (current-local-map))) + (local-set-key "\C-c\C-c" 'gnus-summary-edit-article-done) + (buffer-enable-undo) + (widen) + (goto-char (point-min)) + (search-forward "\n\n" nil t))) (defun gnus-summary-edit-article-done () "Make edits to the current article permanent." @@ -9160,21 +11844,36 @@ groups." (if (gnus-group-read-only-p) (progn (gnus-summary-edit-article-postpone) - (message "The current newsgroup does not support article editing.") - (ding)) - (let ((buf (buffer-substring-no-properties (point-min) (point-max)))) + (gnus-error + 1 "The current newsgroup does not support article editing.")) + (let ((buf (format "%s" (buffer-string)))) (erase-buffer) (insert buf) - (if (not (gnus-request-replace-article - (cdr gnus-article-current) (car gnus-article-current) + (if (not (gnus-request-replace-article + (cdr gnus-article-current) (car gnus-article-current) (current-buffer))) (error "Couldn't replace article.") (gnus-article-mode) (use-local-map gnus-article-mode-map) (setq buffer-read-only t) (buffer-disable-undo (current-buffer)) - (gnus-configure-windows 'summary)) - (and gnus-visual (run-hooks 'gnus-visual-mark-article-hook))))) + (gnus-configure-windows 'summary) + (gnus-summary-update-article (cdr gnus-article-current)) + (when gnus-use-cache + (gnus-cache-update-article + (car gnus-article-current) (cdr gnus-article-current))) + (when gnus-keep-backlog + (gnus-backlog-remove-article + (car gnus-article-current) (cdr gnus-article-current)))) + (save-excursion + (when (get-buffer gnus-original-article-buffer) + (set-buffer gnus-original-article-buffer) + (setq gnus-original-article nil))) + (setq gnus-article-current nil + gnus-current-article nil) + (run-hooks 'gnus-article-display-hook) + (and (gnus-visual-p 'summary-highlight 'highlight) + (run-hooks 'gnus-visual-mark-article-hook))))) (defun gnus-summary-edit-article-postpone () "Postpone changes to the current article." @@ -9184,11 +11883,13 @@ groups." (setq buffer-read-only t) (buffer-disable-undo (current-buffer)) (gnus-configure-windows 'summary) - (and gnus-visual (run-hooks 'gnus-visual-mark-article-hook))) + (and (gnus-visual-p 'summary-highlight 'highlight) + (run-hooks 'gnus-visual-mark-article-hook))) -(defun gnus-summary-fancy-query () - "Query where the fancy respool algorithm would put this article." +(defun gnus-summary-respool-query () + "Query where the respool algorithm would put this article." (interactive) + (gnus-set-global-variables) (gnus-summary-select-article) (save-excursion (set-buffer gnus-article-buffer) @@ -9196,129 +11897,41 @@ groups." (goto-char (point-min)) (search-forward "\n\n") (narrow-to-region (point-min) (point)) - (pp-eval-expression (list 'quote (nnmail-split-fancy)))))) - -;; Summary score commands. - -;; Suggested by boubaker@cenatls.cena.dgac.fr. - -(defun gnus-summary-raise-score (n) - "Raise the score of the current article by N." - (interactive "p") - (gnus-summary-set-score (+ (gnus-summary-article-score) n))) - -(defun gnus-summary-set-score (n) - "Set the score of the current article to N." - (interactive "p") - ;; Skip dummy header line. - (save-excursion - (gnus-summary-show-thread) - (if (eq (gnus-summary-article-mark) gnus-dummy-mark) - (forward-line 1)) - (let ((buffer-read-only nil)) - ;; Set score. - (gnus-summary-update-mark - (if (= n (or gnus-summary-default-score 0)) ? - (if (< n (or gnus-summary-default-score 0)) - gnus-score-below-mark gnus-score-over-mark)) 'score)) - (let* ((article (gnus-summary-article-number)) - (score (assq article gnus-newsgroup-scored))) - (if score (setcdr score n) - (setq gnus-newsgroup-scored - (cons (cons article n) gnus-newsgroup-scored)))) - (gnus-summary-update-line))) - -(defun gnus-summary-current-score () - "Return the score of the current article." - (interactive) - (message "%s" (gnus-summary-article-score))) + (pp-eval-expression + (list 'quote (mapcar 'car (nnmail-article-group 'identity))))))) ;; Summary marking commands. -(defun gnus-summary-raise-same-subject-and-select (score) - "Raise articles which has the same subject with SCORE and select the next." - (interactive "p") - (let ((subject (gnus-summary-subject-string))) - (gnus-summary-raise-score score) - (while (gnus-summary-search-subject nil nil subject) - (gnus-summary-raise-score score)) - (gnus-summary-next-article t))) - -(defun gnus-summary-raise-same-subject (score) - "Raise articles which has the same subject with SCORE." - (interactive "p") - (let ((subject (gnus-summary-subject-string))) - (gnus-summary-raise-score score) - (while (gnus-summary-search-subject nil nil subject) - (gnus-summary-raise-score score)) - (gnus-summary-next-subject 1 t))) - -(defun gnus-score-default (level) - (if level (prefix-numeric-value level) - gnus-score-interactive-default-score)) - -(defun gnus-summary-raise-thread (&optional score) - "Raise the score of the articles in the current thread with SCORE." - (interactive "P") - (setq score (gnus-score-default score)) - (let (e) - (save-excursion - (let ((level (gnus-summary-thread-level))) - (gnus-summary-raise-score score) - (while (and (zerop (gnus-summary-next-subject 1 nil t)) - (> (gnus-summary-thread-level) level)) - (gnus-summary-raise-score score)) - (setq e (point)))) - (let ((gnus-summary-check-current t)) - (or (zerop (gnus-summary-next-subject 1 t)) - (goto-char e)))) - (gnus-summary-recenter) - (gnus-summary-position-cursor) - (gnus-set-mode-line 'summary)) - -(defun gnus-summary-lower-same-subject-and-select (score) - "Raise articles which has the same subject with SCORE and select the next." - (interactive "p") - (gnus-summary-raise-same-subject-and-select (- score))) - -(defun gnus-summary-lower-same-subject (score) - "Raise articles which has the same subject with SCORE." - (interactive "p") - (gnus-summary-raise-same-subject (- score))) - -(defun gnus-summary-lower-thread (&optional score) - "Lower score of articles in the current thread with SCORE." - (interactive "P") - (gnus-summary-raise-thread (- (1- (gnus-score-default score))))) - (defun gnus-summary-kill-same-subject-and-select (&optional unmark) "Mark articles which has the same subject as read, and then select the next. If UNMARK is positive, remove any kind of mark. If UNMARK is negative, tick articles." (interactive "P") + (gnus-set-global-variables) (if unmark (setq unmark (prefix-numeric-value unmark))) (let ((count (gnus-summary-mark-same-subject - (gnus-summary-subject-string) unmark))) - ;; Select next unread article. If auto-select-same mode, should + (gnus-summary-article-subject) unmark))) + ;; Select next unread article. If auto-select-same mode, should ;; select the first unread article. (gnus-summary-next-article t (and gnus-auto-select-same - (gnus-summary-subject-string))) + (gnus-summary-article-subject))) (gnus-message 7 "%d article%s marked as %s" count (if (= count 1) " is" "s are") (if unmark "unread" "read")))) (defun gnus-summary-kill-same-subject (&optional unmark) - "Mark articles which has the same subject as read. + "Mark articles which has the same subject as read. If UNMARK is positive, remove any kind of mark. If UNMARK is negative, tick articles." (interactive "P") + (gnus-set-global-variables) (if unmark (setq unmark (prefix-numeric-value unmark))) (let ((count (gnus-summary-mark-same-subject - (gnus-summary-subject-string) unmark))) + (gnus-summary-article-subject) unmark))) ;; If marked as read, go to next unread subject. (if (null unmark) ;; Go to next unread subject. @@ -9332,27 +11945,27 @@ If optional argument UNMARK is positive, remove any kinds of marks. If optional argument UNMARK is negative, mark articles as unread instead." (let ((count 1)) (save-excursion - (cond + (cond ((null unmark) ; Mark as read. - (while (and + (while (and (progn (gnus-summary-mark-article-as-read gnus-killed-mark) (gnus-summary-show-thread) t) - (gnus-summary-search-forward nil subject)) + (gnus-summary-find-subject subject)) (setq count (1+ count)))) ((> unmark 0) ; Tick. (while (and (progn (gnus-summary-mark-article-as-unread gnus-ticked-mark) (gnus-summary-show-thread) t) - (gnus-summary-search-forward nil subject)) + (gnus-summary-find-subject subject)) (setq count (1+ count)))) (t ; Mark as unread. (while (and (progn (gnus-summary-mark-article-as-unread gnus-unread-mark) (gnus-summary-show-thread) t) - (gnus-summary-search-forward nil subject)) + (gnus-summary-find-subject subject)) (setq count (1+ count))))) (gnus-set-mode-line 'summary) ;; Return the number of marked articles. @@ -9364,9 +11977,10 @@ If N is negative, mark backward instead. If UNMARK is non-nil, remove the process mark instead. The difference between N and the actual number of articles marked is returned." (interactive "p") + (gnus-set-global-variables) (let ((backward (< n 0)) (n (abs n))) - (while (and + (while (and (> n 0) (if unmark (gnus-summary-remove-process-mark @@ -9376,7 +11990,7 @@ number of articles marked is returned." (setq n (1- n))) (if (/= 0 n) (gnus-message 7 "No more articles")) (gnus-summary-recenter) - (gnus-summary-position-cursor) + (gnus-summary-position-point) n)) (defun gnus-summary-unmark-as-processable (n) @@ -9384,35 +11998,37 @@ number of articles marked is returned." If N is negative, mark backward instead. The difference between N and the actual number of articles marked is returned." (interactive "p") + (gnus-set-global-variables) (gnus-summary-mark-as-processable n t)) (defun gnus-summary-unmark-all-processable () "Remove the process mark from all articles." (interactive) + (gnus-set-global-variables) (save-excursion (while gnus-newsgroup-processable (gnus-summary-remove-process-mark (car gnus-newsgroup-processable)))) - (gnus-summary-position-cursor)) + (gnus-summary-position-point)) (defun gnus-summary-mark-as-expirable (n) "Mark N articles forward as expirable. -If N is negative, mark backward instead. The difference between N and +If N is negative, mark backward instead. The difference between N and the actual number of articles marked is returned." (interactive "p") + (gnus-set-global-variables) (gnus-summary-mark-forward n gnus-expirable-mark)) (defun gnus-summary-mark-article-as-replied (article) "Mark ARTICLE replied and update the summary line." (setq gnus-newsgroup-replied (cons article gnus-newsgroup-replied)) (let ((buffer-read-only nil)) - (if (gnus-summary-goto-subject article) - (progn - (gnus-summary-update-mark gnus-replied-mark 'replied) - t)))) + (when (gnus-summary-goto-subject article) + (gnus-summary-update-secondary-mark article)))) (defun gnus-summary-set-bookmark (article) "Set a bookmark in current article." (interactive (list (gnus-summary-article-number))) + (gnus-set-global-variables) (if (or (not (get-buffer gnus-article-buffer)) (not gnus-current-article) (not gnus-article-current) @@ -9420,13 +12036,13 @@ the actual number of articles marked is returned." (error "No current article selected")) ;; Remove old bookmark, if one exists. (let ((old (assq article gnus-newsgroup-bookmarks))) - (if old (setq gnus-newsgroup-bookmarks + (if old (setq gnus-newsgroup-bookmarks (delq old gnus-newsgroup-bookmarks)))) - ;; Set the new bookmark, which is on the form + ;; Set the new bookmark, which is on the form ;; (article-number . line-number-in-body). - (setq gnus-newsgroup-bookmarks - (cons - (cons article + (setq gnus-newsgroup-bookmarks + (cons + (cons article (save-excursion (set-buffer gnus-article-buffer) (count-lines @@ -9442,11 +12058,12 @@ the actual number of articles marked is returned." (defun gnus-summary-remove-bookmark (article) "Remove the bookmark from the current article." (interactive (list (gnus-summary-article-number))) + (gnus-set-global-variables) ;; Remove old bookmark, if one exists. (let ((old (assq article gnus-newsgroup-bookmarks))) - (if old + (if old (progn - (setq gnus-newsgroup-bookmarks + (setq gnus-newsgroup-bookmarks (delq old gnus-newsgroup-bookmarks)) (gnus-message 6 "Removed bookmark.")) (gnus-message 6 "No bookmark in current article.")))) @@ -9457,41 +12074,34 @@ the actual number of articles marked is returned." If N is negative, mark backward instead. The difference between N and the actual number of articles marked is returned." (interactive "p") + (gnus-set-global-variables) (gnus-summary-mark-forward n gnus-dormant-mark)) (defun gnus-summary-set-process-mark (article) "Set the process mark on ARTICLE and update the summary line." - (setq gnus-newsgroup-processable - (cons article + (setq gnus-newsgroup-processable + (cons article (delq article gnus-newsgroup-processable))) - (let ((buffer-read-only nil)) - (if (gnus-summary-goto-subject article) - (progn - (gnus-summary-show-thread) - (and (eq (gnus-summary-article-mark) gnus-dummy-mark) - (forward-line 1)) - (gnus-summary-update-mark gnus-process-mark 'replied) - t)))) + (when (gnus-summary-goto-subject article) + (gnus-summary-show-thread) + (gnus-summary-update-secondary-mark article))) (defun gnus-summary-remove-process-mark (article) "Remove the process mark from ARTICLE and update the summary line." (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable)) - (let ((buffer-read-only nil)) - (if (gnus-summary-goto-subject article) - (progn - (gnus-summary-show-thread) - (and (eq (gnus-summary-article-mark) gnus-dummy-mark) - (forward-line 1)) - (gnus-summary-update-mark ? 'replied) - (if (memq article gnus-newsgroup-replied) - (gnus-summary-update-mark gnus-replied-mark 'replied)) - t)))) + (when (gnus-summary-goto-subject article) + (gnus-summary-show-thread) + (gnus-summary-update-secondary-mark article))) + +(defun gnus-summary-set-saved-mark (article) + "Set the process mark on ARTICLE and update the summary line." + (push article gnus-newsgroup-saved) + (when (gnus-summary-goto-subject article) + (gnus-summary-update-secondary-mark article))) (defun gnus-summary-mark-forward (n &optional mark no-expire) "Mark N articles as read forwards. -If N is negative, mark backwards instead. -Mark with MARK. If MARK is ? , ?! or ??, articles will be -marked as unread. +If N is negative, mark backwards instead. Mark with MARK, ?r by default. The difference between N and the actual number of articles marked is returned." (interactive "p") @@ -9499,18 +12109,22 @@ returned." (let ((backward (< n 0)) (gnus-summary-goto-unread (and gnus-summary-goto-unread + (not (eq gnus-summary-goto-unread 'never)) (not (memq mark (list gnus-unread-mark gnus-ticked-mark gnus-dormant-mark))))) (n (abs n)) (mark (or mark gnus-del-mark))) (while (and (> n 0) (gnus-summary-mark-article nil mark no-expire) - (zerop (gnus-summary-next-subject - (if backward -1 1) gnus-summary-goto-unread t))) + (zerop (gnus-summary-next-subject + (if backward -1 1) + (and gnus-summary-goto-unread + (not (eq gnus-summary-goto-unread 'never))) + t))) (setq n (1- n))) (if (/= 0 n) (gnus-message 7 "No more %sarticles" (if mark "" "unread "))) (gnus-summary-recenter) - (gnus-summary-position-cursor) + (gnus-summary-position-point) (gnus-set-mode-line 'summary) n)) @@ -9522,77 +12136,79 @@ returned." (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)) (setq gnus-newsgroup-reads (cons (cons article mark) gnus-newsgroup-reads)) - ;; Possibly remove from cache, if that is used. + ;; Possibly remove from cache, if that is used. (and gnus-use-cache (gnus-cache-enter-remove-article article)) - (and gnus-newsgroup-auto-expire - (or (= mark gnus-killed-mark) (= mark gnus-del-mark) - (= mark gnus-catchup-mark) (= mark gnus-low-score-mark) - (= mark gnus-read-mark)) - (progn - (setq mark gnus-expirable-mark) - (setq gnus-newsgroup-expirable - (cons article gnus-newsgroup-expirable)))) - (while (eq (gnus-summary-article-mark) gnus-dummy-mark) - (forward-line 1)) - ;; Fix the mark. + ;; Allow the backend to change the mark. + (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark)) + ;; Check for auto-expiry. + (when (and gnus-newsgroup-auto-expire + (or (= mark gnus-killed-mark) (= mark gnus-del-mark) + (= mark gnus-catchup-mark) (= mark gnus-low-score-mark) + (= mark gnus-ancient-mark) + (= mark gnus-read-mark) (= mark gnus-souped-mark))) + (setq mark gnus-expirable-mark) + (push article gnus-newsgroup-expirable)) + ;; Set the mark in the buffer. (gnus-summary-update-mark mark 'unread) t)) (defun gnus-summary-mark-article-as-unread (mark) "Mark the current article quickly as unread with MARK." (let ((article (gnus-summary-article-number))) - (or (memq article gnus-newsgroup-unreads) - (setq gnus-newsgroup-unreads (cons article gnus-newsgroup-unreads))) - (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)) - (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)) - (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)) - (setq gnus-newsgroup-reads - (delq (assq article gnus-newsgroup-reads) - gnus-newsgroup-reads)) - (if (= mark gnus-ticked-mark) - (setq gnus-newsgroup-marked (cons article gnus-newsgroup-marked))) - (if (= mark gnus-dormant-mark) - (setq gnus-newsgroup-dormant (cons article gnus-newsgroup-dormant))) - - ;; See whether the article is to be put in the cache. - (and gnus-use-cache - (vectorp (gnus-get-header-by-num article)) - (save-excursion - (gnus-cache-possibly-enter-article - gnus-newsgroup-name article - (gnus-get-header-by-num article) - (= mark gnus-ticked-mark) - (= mark gnus-dormant-mark) (= mark gnus-unread-mark)))) - - (while (eq (gnus-summary-article-mark) gnus-dummy-mark) - (forward-line 1)) - ;; Fix the mark. - (gnus-summary-update-mark mark 'unread) + (if (< article 0) + (gnus-error 1 "Unmarkable article") + (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)) + (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)) + (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)) + (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads)) + (cond ((= mark gnus-ticked-mark) + (push article gnus-newsgroup-marked)) + ((= mark gnus-dormant-mark) + (push article gnus-newsgroup-dormant)) + (t + (push article gnus-newsgroup-unreads))) + (setq gnus-newsgroup-reads + (delq (assq article gnus-newsgroup-reads) + gnus-newsgroup-reads)) + + ;; See whether the article is to be put in the cache. + (and gnus-use-cache + (vectorp (gnus-summary-article-header article)) + (save-excursion + (gnus-cache-possibly-enter-article + gnus-newsgroup-name article + (gnus-summary-article-header article) + (= mark gnus-ticked-mark) + (= mark gnus-dormant-mark) (= mark gnus-unread-mark)))) + + ;; Fix the mark. + (gnus-summary-update-mark mark 'unread)) t)) (defun gnus-summary-mark-article (&optional article mark no-expire) "Mark ARTICLE with MARK. MARK can be any character. -Four MARK strings are reserved: `? ' (unread), `?!' (ticked), `??' -(dormant) and `?E' (expirable). +Four MARK strings are reserved: `? ' (unread), `?!' (ticked), +`??' (dormant) and `?E' (expirable). If MARK is nil, then the default character `?D' is used. If ARTICLE is nil, then the article on the current line will be -marked." +marked." + ;; The mark might be a string. (and (stringp mark) (setq mark (aref mark 0))) ;; If no mark is given, then we check auto-expiring. (and (not no-expire) - gnus-newsgroup-auto-expire + gnus-newsgroup-auto-expire (or (not mark) - (and (numberp mark) + (and (numberp mark) (or (= mark gnus-killed-mark) (= mark gnus-del-mark) (= mark gnus-catchup-mark) (= mark gnus-low-score-mark) - (= mark gnus-read-mark)))) + (= mark gnus-read-mark) (= mark gnus-souped-mark)))) (setq mark gnus-expirable-mark)) (let* ((mark (or mark gnus-del-mark)) (article (or article (gnus-summary-article-number)))) (or article (error "No article on current line")) - (if (or (= mark gnus-unread-mark) - (= mark gnus-ticked-mark) + (if (or (= mark gnus-unread-mark) + (= mark gnus-ticked-mark) (= mark gnus-dormant-mark)) (gnus-mark-article-as-unread article mark) (gnus-mark-article-as-read article mark)) @@ -9600,40 +12216,54 @@ marked." ;; See whether the article is to be put in the cache. (and gnus-use-cache (not (= mark gnus-canceled-mark)) - (vectorp (gnus-get-header-by-num article)) + (vectorp (gnus-summary-article-header article)) (save-excursion - (gnus-cache-possibly-enter-article - gnus-newsgroup-name article - (gnus-get-header-by-num article) + (gnus-cache-possibly-enter-article + gnus-newsgroup-name article + (gnus-summary-article-header article) (= mark gnus-ticked-mark) (= mark gnus-dormant-mark) (= mark gnus-unread-mark)))) - (if (gnus-summary-goto-subject article) + (if (gnus-summary-goto-subject article nil t) (let ((buffer-read-only nil)) (gnus-summary-show-thread) - (and (eq (gnus-summary-article-mark) gnus-dummy-mark) - (forward-line 1)) ;; Fix the mark. (gnus-summary-update-mark mark 'unread) t)))) +(defun gnus-summary-update-secondary-mark (article) + "Update the secondary (read, process, cache) mark." + (gnus-summary-update-mark + (cond ((memq article gnus-newsgroup-processable) + gnus-process-mark) + ((memq article gnus-newsgroup-cached) + gnus-cached-mark) + ((memq article gnus-newsgroup-replied) + gnus-replied-mark) + ((memq article gnus-newsgroup-saved) + gnus-saved-mark) + (t gnus-unread-mark)) + 'replied) + (when (gnus-visual-p 'summary-highlight 'highlight) + (run-hooks 'gnus-summary-update-hook)) + t) + (defun gnus-summary-update-mark (mark type) (beginning-of-line) (let ((forward (cdr (assq type gnus-summary-mark-positions))) - (buffer-read-only nil) - plist) - (if (not forward) - () - (forward-char forward) - (setq plist (text-properties-at (point))) - (delete-char 1) - (insert mark) - (and plist (add-text-properties (1- (point)) (point) plist)) - (and (eq type 'unread) - (progn - (add-text-properties (1- (point)) (point) (list 'gnus-mark mark)) - (gnus-summary-update-line (eq mark gnus-unread-mark))))))) - + (buffer-read-only nil)) + (when (and forward + (<= (+ forward (point)) (point-max))) + ;; Go to the right position on the line. + (goto-char (+ forward (point))) + ;; Replace the old mark with the new mark. + (subst-char-in-region (point) (1+ (point)) (following-char) mark) + ;; Optionally update the marks by some user rule. + (when (eq type 'unread) + (gnus-data-set-mark + (gnus-data-find (gnus-summary-article-number)) mark) + (gnus-summary-update-line (eq mark gnus-unread-mark)))))) + (defun gnus-mark-article-as-read (article &optional mark) "Enter ARTICLE in the pertinent lists and remove it from others." ;; Make the article expirable. @@ -9645,31 +12275,31 @@ marked." (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads)) (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)) (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)) - (setq gnus-newsgroup-reads - (cons (cons article mark) gnus-newsgroup-reads)) - ;; Possibly remove from cache, if that is used. - (and gnus-use-cache (gnus-cache-enter-remove-article article)))) + (push (cons article mark) gnus-newsgroup-reads) + ;; Possibly remove from cache, if that is used. + (when gnus-use-cache + (gnus-cache-enter-remove-article article)))) (defun gnus-mark-article-as-unread (article &optional mark) "Enter ARTICLE in the pertinent lists and remove it from others." (let ((mark (or mark gnus-ticked-mark))) - ;; Add to unread list. - (or (memq article gnus-newsgroup-unreads) - (setq gnus-newsgroup-unreads (cons article gnus-newsgroup-unreads))) (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)) (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)) (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)) + (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads)) + (cond ((= mark gnus-ticked-mark) + (push article gnus-newsgroup-marked)) + ((= mark gnus-dormant-mark) + (push article gnus-newsgroup-dormant)) + (t + (push article gnus-newsgroup-unreads))) (setq gnus-newsgroup-reads (delq (assq article gnus-newsgroup-reads) - gnus-newsgroup-reads)) - (if (= mark gnus-ticked-mark) - (setq gnus-newsgroup-marked (cons article gnus-newsgroup-marked))) - (if (= mark gnus-dormant-mark) - (setq gnus-newsgroup-dormant (cons article gnus-newsgroup-dormant))))) + gnus-newsgroup-reads)))) -(defalias 'gnus-summary-mark-as-unread-forward +(defalias 'gnus-summary-mark-as-unread-forward 'gnus-summary-tick-article-forward) -(make-obsolete 'gnus-summary-mark-as-unread-forward +(make-obsolete 'gnus-summary-mark-as-unread-forward 'gnus-summary-tick-article-forward) (defun gnus-summary-tick-article-forward (n) "Tick N articles forwards. @@ -9678,9 +12308,9 @@ The difference between N and the number of articles ticked is returned." (interactive "p") (gnus-summary-mark-forward n gnus-ticked-mark)) -(defalias 'gnus-summary-mark-as-unread-backward +(defalias 'gnus-summary-mark-as-unread-backward 'gnus-summary-tick-article-backward) -(make-obsolete 'gnus-summary-mark-as-unread-backward +(make-obsolete 'gnus-summary-mark-as-unread-backward 'gnus-summary-tick-article-backward) (defun gnus-summary-tick-article-backward (n) "Tick N articles backwards. @@ -9694,6 +12324,7 @@ The difference between N and the number of articles ticked is returned." "Mark current article as unread. Optional 1st argument ARTICLE specifies article number to be marked as unread. Optional 2nd argument CLEAR-MARK remove any kinds of mark." + (interactive) (gnus-summary-mark-article article (if clear-mark gnus-unread-mark gnus-ticked-mark))) @@ -9733,10 +12364,15 @@ The difference between N and the number of marks cleared is returned." (defun gnus-summary-mark-unread-as-read () "Intended to be used by `gnus-summary-mark-article-hook'." - (or (memq gnus-current-article gnus-newsgroup-marked) - (memq gnus-current-article gnus-newsgroup-dormant) - (memq gnus-current-article gnus-newsgroup-expirable) - (gnus-summary-mark-article gnus-current-article gnus-read-mark))) + (when (memq gnus-current-article gnus-newsgroup-unreads) + (gnus-summary-mark-article gnus-current-article gnus-read-mark))) + +(defun gnus-summary-mark-read-and-unread-as-read () + "Intended to be used by `gnus-summary-mark-article-hook'." + (let ((mark (gnus-summary-article-mark))) + (when (or (gnus-unread-mark-p mark) + (gnus-read-mark-p mark)) + (gnus-summary-mark-article gnus-current-article gnus-read-mark)))) (defun gnus-summary-mark-region-as-read (point mark all) "Mark all unread articles between point and mark as read. @@ -9744,106 +12380,18 @@ If given a prefix, mark all articles between point and mark as read, even ticked and dormant ones." (interactive "r\nP") (save-excursion - (goto-char point) - (beginning-of-line) - (while (and - (< (point) mark) - (progn - (and - (or all - (and - (not (memq (gnus-summary-article-number) - gnus-newsgroup-marked)) - (not (memq (gnus-summary-article-number) - gnus-newsgroup-dormant)))) - (gnus-summary-mark-article - (gnus-summary-article-number) gnus-del-mark)) - t) - (zerop (forward-line 1)))))) - -;; Fix by Per Abrahamsen . -(defalias 'gnus-summary-delete-marked-as-read - 'gnus-summary-remove-lines-marked-as-read) -(make-obsolete 'gnus-summary-delete-marked-as-read - 'gnus-summary-remove-lines-marked-as-read) -(defun gnus-summary-remove-lines-marked-as-read () - "Remove lines that are marked as read." - (interactive) - (gnus-summary-remove-lines-marked-with - (concat (mapconcat - (lambda (char) (char-to-string (symbol-value char))) - '(gnus-del-mark gnus-read-mark gnus-ancient-mark - gnus-killed-mark gnus-kill-file-mark - gnus-low-score-mark gnus-expirable-mark - gnus-canceled-mark gnus-catchup-mark) - "")))) - -(defalias 'gnus-summary-delete-marked-with - 'gnus-summary-remove-lines-marked-with) -(make-obsolete 'gnus-summary-delete-marked-with - 'gnus-summary-remove-lines-marked-with) -;; Rewrite by Daniel Quinlan . -(defun gnus-summary-remove-lines-marked-with (marks) - "Remove lines that are marked with MARKS (e.g. \"DK\")." - (interactive "sMarks: ") - ;; Fix by Sudish Joseph . - (gnus-set-global-variables) - (let ((buffer-read-only nil) - (orig-article - (let ((gnus-summary-check-current t)) - (gnus-summary-search-forward t) - (gnus-summary-article-number))) - (marks (concat "^[" marks "]"))) - (goto-char (point-min)) - (if gnus-newsgroup-adaptive - (gnus-score-remove-lines-adaptive marks) - (while (re-search-forward marks nil t) - (gnus-delete-line))) - ;; If we use dummy roots, we have to do an additional sweep over - ;; the buffer. - (if (not (eq gnus-summary-make-false-root 'dummy)) - () - (goto-char (point-min)) - (setq marks (concat "^[" (char-to-string gnus-dummy-mark) "]")) - (while (re-search-forward marks nil t) - (if (gnus-subject-equal - (gnus-summary-subject-string) - (progn - (forward-line 1) - (gnus-summary-subject-string))) - () - (forward-line -1) - (gnus-delete-line)))) - (or (zerop (buffer-size)) - (gnus-summary-goto-subject orig-article) - (if (eobp) - (gnus-summary-prev-subject 1) - (gnus-summary-position-cursor))))) - -(defun gnus-summary-expunge-below (&optional score) - "Remove articles with score less than SCORE." - (interactive "P") - (gnus-set-global-variables) - (setq score (if score - (prefix-numeric-value score) - (or gnus-summary-default-score 0))) - (save-excursion - (set-buffer gnus-summary-buffer) - (goto-char (point-min)) - (let ((buffer-read-only nil) - beg) - (while (not (eobp)) - (if (< (gnus-summary-article-score) score) - (progn - (setq beg (point)) - (forward-line 1) - (delete-region beg (point))) - (forward-line 1))) - ;; Adjust point. - (or (zerop (buffer-size)) - (if (eobp) - (gnus-summary-prev-subject 1) - (gnus-summary-position-cursor)))))) + (let (article) + (goto-char point) + (beginning-of-line) + (while (and + (< (point) mark) + (progn + (when (or all + (memq (setq article (gnus-summary-article-number)) + gnus-newsgroup-unreads)) + (gnus-summary-mark-article article gnus-del-mark)) + t) + (gnus-summary-find-next)))))) (defun gnus-summary-mark-below (score mark) "Mark articles with score less than SCORE with MARK." @@ -9855,10 +12403,11 @@ even ticked and dormant ones." (save-excursion (set-buffer gnus-summary-buffer) (goto-char (point-min)) - (while (not (eobp)) - (and (< (gnus-summary-article-score) score) - (gnus-summary-mark-article nil mark)) - (forward-line 1)))) + (while + (progn + (and (< (gnus-summary-article-score) score) + (gnus-summary-mark-article nil mark)) + (gnus-summary-find-next))))) (defun gnus-summary-kill-below (&optional score) "Mark articles with score below SCORE as read." @@ -9888,15 +12437,15 @@ even ticked and dormant ones." (save-excursion (set-buffer gnus-summary-buffer) (goto-char (point-min)) - (while (not (eobp)) - (if (> (gnus-summary-article-score) score) - (progn - (gnus-summary-mark-article nil mark) - (forward-line 1)) - (forward-line 1))))) + (while (and (progn + (if (> (gnus-summary-article-score) score) + (gnus-summary-mark-article nil mark)) + t) + (gnus-summary-find-next))))) -;; Suggested by Daniel Quinlan . -(defun gnus-summary-show-all-expunged () +;; Suggested by Daniel Quinlan . +(defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged) +(defun gnus-summary-limit-include-expunged () "Display all the hidden articles that were expunged for low scores." (interactive) (gnus-set-global-variables) @@ -9904,57 +12453,22 @@ even ticked and dormant ones." (let ((scored gnus-newsgroup-scored) headers h) (while scored - (or (gnus-summary-goto-subject (car (car scored))) - (and (setq h (gnus-get-header-by-num (car (car scored)))) - (< (cdr (car scored)) gnus-summary-expunge-below) + (or (gnus-summary-goto-subject (caar scored)) + (and (setq h (gnus-summary-article-header (caar scored))) + (< (cdar scored) gnus-summary-expunge-below) (setq headers (cons h headers)))) (setq scored (cdr scored))) (or headers (error "No expunged articles hidden.")) (goto-char (point-min)) - (save-excursion - (gnus-summary-update-lines - (point) - (progn - (gnus-summary-prepare-unthreaded (nreverse headers)) - (point))))) - (goto-char (point-min)) - (gnus-summary-position-cursor))) - -(defun gnus-summary-show-all-dormant () - "Display all the hidden articles that are marked as dormant." - (interactive) - (gnus-set-global-variables) - (let ((buffer-read-only nil)) - (let ((dormant gnus-newsgroup-dormant) - headers h) - (while dormant - (or (gnus-summary-goto-subject (car dormant)) - (and (setq h (gnus-get-header-by-num (car dormant))) - (setq headers (cons h headers)))) - (setq dormant (cdr dormant))) - (or headers (error "No dormant articles hidden.")) - (goto-char (point-min)) - (save-excursion - (gnus-summary-update-lines - (point) - (progn - (gnus-summary-prepare-unthreaded (nreverse headers)) - (point))))) + (gnus-summary-prepare-unthreaded (nreverse headers))) (goto-char (point-min)) - (gnus-summary-position-cursor))) - -(defun gnus-summary-hide-all-dormant () - "Hide all dormant articles." - (interactive) - (gnus-set-global-variables) - (gnus-summary-remove-lines-marked-with (char-to-string gnus-dormant-mark)) - (gnus-summary-position-cursor)) + (gnus-summary-position-point))) (defun gnus-summary-catchup (&optional all quietly to-here not-mark) "Mark all articles not marked as unread in this newsgroup as read. If prefix argument ALL is non-nil, all articles are marked as read. If QUIETLY is non-nil, no questions will be asked. -If TO-HERE is non-nil, it should be a point in the buffer. All +If TO-HERE is non-nil, it should be a point in the buffer. All articles before this point will be marked as read. The number of articles marked as read is returned." (interactive "P") @@ -9967,31 +12481,30 @@ The number of articles marked as read is returned." (if all "Mark absolutely all articles as read? " "Mark all unread articles as read? "))) - (if (and not-mark + (if (and not-mark (not gnus-newsgroup-adaptive) (not gnus-newsgroup-auto-expire)) (progn - (and all (setq gnus-newsgroup-marked nil - gnus-newsgroup-dormant nil)) - (setq gnus-newsgroup-unreads - (append gnus-newsgroup-marked gnus-newsgroup-dormant))) + (when all + (setq gnus-newsgroup-marked nil + gnus-newsgroup-dormant nil)) + (setq gnus-newsgroup-unreads nil)) ;; We actually mark all articles as canceled, which we - ;; have to do when using auto-expiry or adaptive scoring. + ;; have to do when using auto-expiry or adaptive scoring. (gnus-summary-show-all-threads) (if (gnus-summary-first-subject (not all)) - (while (and + (while (and (if to-here (< (point) to-here) t) (gnus-summary-mark-article-as-read gnus-catchup-mark) - (gnus-summary-search-subject nil (not all))))) - (or to-here - (setq gnus-newsgroup-unreads - (append gnus-newsgroup-marked - gnus-newsgroup-dormant))))) + (gnus-summary-find-next (not all))))) + (unless to-here + (setq gnus-newsgroup-unreads nil)) + (gnus-set-mode-line 'summary))) (let ((method (gnus-find-method-for-group gnus-newsgroup-name))) (if (and (not to-here) (eq 'nnvirtual (car method))) (nnvirtual-catchup-group (gnus-group-real-name gnus-newsgroup-name) (nth 1 method) all))) - (gnus-summary-position-cursor))) + (gnus-summary-position-point))) (defun gnus-summary-catchup-to-here (&optional all) "Mark all unticked articles before the current one as read. @@ -9999,12 +12512,12 @@ If ALL is non-nil, also mark ticked and dormant articles as read." (interactive "P") (gnus-set-global-variables) (save-excursion - (and (zerop (forward-line -1)) - (progn - (end-of-line) - (gnus-summary-catchup all t (point)) - (gnus-set-mode-line 'summary)))) - (gnus-summary-position-cursor)) + (gnus-save-hidden-threads + (let ((beg (point))) + ;; We check that there are unread articles. + (when (or all (gnus-summary-find-prev)) + (gnus-summary-catchup all t beg))))) + (gnus-summary-position-point)) (defun gnus-summary-catchup-all (&optional quietly) "Mark all articles in this newsgroup as read." @@ -10019,8 +12532,7 @@ If prefix argument ALL is non-nil, all articles are marked as read." (gnus-set-global-variables) (gnus-summary-catchup all quietly nil 'fast) ;; Select next newsgroup or exit. - (if (and (eq gnus-auto-select-next 'quietly) - (not (gnus-ephemeral-group-p gnus-newsgroup-name))) + (if (eq gnus-auto-select-next 'quietly) (gnus-summary-next-group nil) (gnus-summary-exit))) @@ -10034,14 +12546,111 @@ If prefix argument ALL is non-nil, all articles are marked as read." (defun gnus-summary-catchup-and-goto-next-group (&optional all) "Mark all articles in this group as read and select the next group. If given a prefix, mark all articles, unread as well as ticked, as -read." +read." (interactive "P") (gnus-set-global-variables) - (gnus-summary-catchup all) - (gnus-summary-next-group)) + (save-excursion + (gnus-summary-catchup all)) + (gnus-summary-next-article t nil nil t)) ;; Thread-based commands. +(defun gnus-summary-articles-in-thread (&optional article) + "Return a list of all articles in the current thread. +If ARTICLE is non-nil, return all articles in the thread that starts +with that article." + (let* ((article (or article (gnus-summary-article-number))) + (data (gnus-data-find-list article)) + (top-level (gnus-data-level (car data))) + (top-subject + (cond ((null gnus-thread-operation-ignore-subject) + (gnus-simplify-subject-re + (mail-header-subject (gnus-data-header (car data))))) + ((eq gnus-thread-operation-ignore-subject 'fuzzy) + (gnus-simplify-subject-fuzzy + (mail-header-subject (gnus-data-header (car data))))) + (t nil))) + (end-point (save-excursion + (if (gnus-summary-go-to-next-thread) + (point) (point-max)))) + articles) + (while (and data + (< (gnus-data-pos (car data)) end-point)) + (when (or (not top-subject) + (string= top-subject + (if (eq gnus-thread-operation-ignore-subject 'fuzzy) + (gnus-simplify-subject-fuzzy + (mail-header-subject + (gnus-data-header (car data)))) + (gnus-simplify-subject-re + (mail-header-subject + (gnus-data-header (car data))))))) + (push (gnus-data-number (car data)) articles)) + (unless (and (setq data (cdr data)) + (> (gnus-data-level (car data)) top-level)) + (setq data nil))) + ;; Return the list of articles. + (nreverse articles))) + +(defun gnus-summary-rethread-current () + "Rethread the thread the current article is part of." + (interactive) + (gnus-set-global-variables) + (let* ((gnus-show-threads t) + (article (gnus-summary-article-number)) + (id (mail-header-id (gnus-summary-article-header))) + (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id))))) + (unless id + (error "No article on the current line")) + (gnus-rebuild-thread id) + (gnus-summary-goto-subject article))) + +(defun gnus-summary-reparent-thread () + "Make current article child of the marked (or previous) article. + +Note that the re-threading will only work if `gnus-thread-ignore-subject' +is non-nil or the Subject: of both articles are the same." + (interactive) + (or (not (gnus-group-read-only-p)) + (error "The current newsgroup does not support article editing.")) + (or (<= (length gnus-newsgroup-processable) 1) + (error "No more than one article may be marked.")) + (save-window-excursion + (let ((gnus-article-buffer " *reparent*") + (current-article (gnus-summary-article-number)) + ; first grab the marked article, otherwise one line up. + (parent-article (if (not (null gnus-newsgroup-processable)) + (car gnus-newsgroup-processable) + (save-excursion + (if (eq (forward-line -1) 0) + (gnus-summary-article-number) + (error "Beginning of summary buffer.")))))) + (or (not (eq current-article parent-article)) + (error "An article may not be self-referential.")) + (let ((message-id (mail-header-id + (gnus-summary-article-header parent-article)))) + (or (and message-id (not (equal message-id ""))) + (error "No message-id in desired parent.")) + (gnus-summary-select-article t t nil current-article) + (set-buffer gnus-article-buffer) + (setq buffer-read-only nil) + (let ((buf (format "%s" (buffer-string)))) + (erase-buffer) + (insert buf)) + (goto-char (point-min)) + (if (search-forward-regexp "^References: " nil t) + (insert message-id " " ) + (insert "References: " message-id "\n")) + (or (gnus-request-replace-article current-article + (car gnus-article-current) + gnus-article-buffer) + (error "Couldn't replace article.")) + (set-buffer gnus-summary-buffer) + (gnus-summary-unmark-all-processable) + (gnus-summary-rethread-current) + (gnus-message 3 "Article %d is now the child of article %d." + current-article parent-article))))) + (defun gnus-summary-toggle-threads (&optional arg) "Toggle showing conversation threads. If ARG is positive number, turn showing conversation threads on." @@ -10053,7 +12662,7 @@ If ARG is positive number, turn showing conversation threads on." (> (prefix-numeric-value arg) 0))) (gnus-summary-prepare) (gnus-summary-goto-subject current) - (gnus-summary-position-cursor))) + (gnus-summary-position-point))) (defun gnus-summary-show-all-threads () "Show all threads." @@ -10062,7 +12671,7 @@ If ARG is positive number, turn showing conversation threads on." (save-excursion (let ((buffer-read-only nil)) (subst-char-in-region (point-min) (point-max) ?\^M ?\n t))) - (gnus-summary-position-cursor)) + (gnus-summary-position-point)) (defun gnus-summary-show-thread () "Show thread subtrees. @@ -10070,7 +12679,7 @@ Returns nil if no thread was there to be shown." (interactive) (gnus-set-global-variables) (let ((buffer-read-only nil) - (orig (prog1 (point) (gnus-summary-hide-thread))) + (orig (point)) ;; first goto end then to beg, to have point at beg after let (end (progn (end-of-line) (point))) (beg (progn (beginning-of-line) (point)))) @@ -10079,7 +12688,7 @@ Returns nil if no thread was there to be shown." (search-forward "\r" end t) (subst-char-in-region beg end ?\^M ?\n t) (goto-char orig) - (gnus-summary-position-cursor)))) + (gnus-summary-position-point)))) (defun gnus-summary-hide-all-threads () "Hide all thread subtrees." @@ -10088,9 +12697,9 @@ Returns nil if no thread was there to be shown." (save-excursion (goto-char (point-min)) (gnus-summary-hide-thread) - (while (and (not (eobp)) (zerop (forward-line 1))) + (while (zerop (gnus-summary-next-thread 1 t)) (gnus-summary-hide-thread))) - (gnus-summary-position-cursor)) + (gnus-summary-position-point)) (defun gnus-summary-hide-thread () "Hide thread subtrees. @@ -10099,56 +12708,91 @@ Returns nil if no threads were there to be hidden." (gnus-set-global-variables) (let ((buffer-read-only nil) (start (point)) - (level (gnus-summary-thread-level)) - (end (point))) + (article (gnus-summary-article-number))) + (goto-char start) ;; Go forward until either the buffer ends or the subthread - ;; ends. - (if (eobp) - () - (while (and (zerop (forward-line 1)) - (> (gnus-summary-thread-level) level)) - (setq end (point))) + ;; ends. + (when (and (not (eobp)) + (or (zerop (gnus-summary-next-thread 1 t)) + (goto-char (point-max)))) (prog1 - (save-excursion - (goto-char end) - (search-backward "\n" start t)) - (subst-char-in-region start end ?\n ?\^M t) - (forward-line -1) - (gnus-summary-position-cursor))))) + (if (and (> (point) start) + (search-backward "\n" start t)) + (progn + (subst-char-in-region start (point) ?\n ?\^M) + (gnus-summary-goto-subject article)) + (goto-char start) + nil) + ;;(gnus-summary-position-point) + )))) (defun gnus-summary-go-to-next-thread (&optional previous) "Go to the same level (or less) next thread. If PREVIOUS is non-nil, go to previous thread instead. Return the article number moved to, or nil if moving was impossible." (let ((level (gnus-summary-thread-level)) - (article (gnus-summary-article-number))) - (if previous - (while (and (zerop (forward-line -1)) - (> (gnus-summary-thread-level) level))) - (while (and (save-excursion - (forward-line 1) - (not (eobp))) - (zerop (forward-line 1)) - (> (gnus-summary-thread-level) level)))) - (gnus-summary-recenter) - (gnus-summary-position-cursor) - (let ((oart (gnus-summary-article-number))) - (and (/= oart article) oart)))) + (way (if previous -1 1)) + (beg (point))) + (forward-line way) + (while (and (not (eobp)) + (< level (gnus-summary-thread-level))) + (forward-line way)) + (if (eobp) + (progn + (goto-char beg) + nil) + (setq beg (point)) + (prog1 + (gnus-summary-article-number) + (goto-char beg))))) -(defun gnus-summary-next-thread (n) +(defun gnus-summary-go-to-next-thread-old (&optional previous) + "Go to the same level (or less) next thread. +If PREVIOUS is non-nil, go to previous thread instead. +Return the article number moved to, or nil if moving was impossible." + (if (and (eq gnus-summary-make-false-root 'dummy) + (gnus-summary-article-intangible-p)) + (let ((beg (point))) + (while (and (zerop (forward-line 1)) + (not (gnus-summary-article-intangible-p)) + (not (zerop (save-excursion + (gnus-summary-thread-level)))))) + (if (eobp) + (progn + (goto-char beg) + nil) + (point))) + (let* ((level (gnus-summary-thread-level)) + (article (gnus-summary-article-number)) + (data (cdr (gnus-data-find-list article (gnus-data-list previous)))) + oart) + (while data + (if (<= (gnus-data-level (car data)) level) + (setq oart (gnus-data-number (car data)) + data nil) + (setq data (cdr data)))) + (and oart + (gnus-summary-goto-subject oart))))) + +(defun gnus-summary-next-thread (n &optional silent) "Go to the same level next N'th thread. If N is negative, search backward instead. Returns the difference between N and the number of skips actually -done." +done. + +If SILENT, don't output messages." (interactive "p") (gnus-set-global-variables) (let ((backward (< n 0)) - (n (abs n))) + (n (abs n)) + old dum int) (while (and (> n 0) (gnus-summary-go-to-next-thread backward)) - (setq n (1- n))) - (gnus-summary-position-cursor) - (if (/= 0 n) (gnus-message 7 "No more threads")) + (decf n)) + (unless silent + (gnus-summary-position-point)) + (when (and (not silent) (/= 0 n)) + (gnus-message 7 "No more threads")) n)) (defun gnus-summary-prev-thread (n) @@ -10159,28 +12803,17 @@ done." (gnus-set-global-variables) (gnus-summary-next-thread (- n))) -(defun gnus-summary-go-down-thread (&optional same) - "Go down one level in the current thread. -If SAME is non-nil, also move to articles of the same level." - (let ((level (gnus-summary-thread-level)) - (start (point))) - (if (and (zerop (forward-line 1)) - (> (gnus-summary-thread-level) level)) - t - (goto-char start) - nil))) +(defun gnus-summary-go-down-thread () + "Go down one level in the current thread." + (let ((children (gnus-summary-article-children))) + (and children + (gnus-summary-goto-subject (car children))))) (defun gnus-summary-go-up-thread () "Go up one level in the current thread." - (let ((level (gnus-summary-thread-level)) - (start (point))) - (while (and (zerop (forward-line -1)) - (>= (gnus-summary-thread-level) level))) - (if (>= (gnus-summary-thread-level) level) - (progn - (goto-char start) - nil) - t))) + (let ((parent (gnus-summary-article-parent))) + (and parent + (gnus-summary-goto-subject parent)))) (defun gnus-summary-down-thread (n) "Go down thread N steps. @@ -10195,7 +12828,7 @@ taken." (if up (gnus-summary-go-up-thread) (gnus-summary-go-down-thread))) (setq n (1- n))) - (gnus-summary-position-cursor) + (gnus-summary-position-point) (if (/= 0 n) (gnus-message 7 "Can't go further")) n)) @@ -10208,31 +12841,35 @@ taken." (gnus-set-global-variables) (gnus-summary-down-thread (- n))) +(defun gnus-summary-top-thread () + "Go to the top of the thread." + (interactive) + (gnus-set-global-variables) + (while (gnus-summary-go-up-thread)) + (gnus-summary-article-number)) + (defun gnus-summary-kill-thread (&optional unmark) "Mark articles under current thread as read. If the prefix argument is positive, remove any kinds of marks. If the prefix argument is negative, tick articles instead." (interactive "P") (gnus-set-global-variables) - (if unmark - (setq unmark (prefix-numeric-value unmark))) - (let ((killing t) - (level (gnus-summary-thread-level))) + (when unmark + (setq unmark (prefix-numeric-value unmark))) + (let ((articles (gnus-summary-articles-in-thread))) (save-excursion ;; Expand the thread. (gnus-summary-show-thread) - (while killing - ;; Mark the article... - (cond ((null unmark) (gnus-summary-mark-article-as-read - gnus-killed-mark)) - ((> unmark 0) (gnus-summary-mark-article-as-unread - gnus-unread-mark)) - (t (gnus-summary-mark-article-as-unread gnus-ticked-mark))) - ;; ...and go forward until either the buffer ends or the subtree - ;; ends. - (if (not (and (zerop (forward-line 1)) - (> (gnus-summary-thread-level) level))) - (setq killing nil)))) + ;; Mark all the articles. + (while articles + (gnus-summary-goto-subject (car articles)) + (cond ((null unmark) + (gnus-summary-mark-article-as-read gnus-killed-mark)) + ((> unmark 0) + (gnus-summary-mark-article-as-unread gnus-unread-mark)) + (t + (gnus-summary-mark-article-as-unread gnus-ticked-mark))) + (setq articles (cdr articles)))) ;; Hide killed subtrees. (and (null unmark) gnus-thread-hide-killed @@ -10249,128 +12886,82 @@ If the prefix argument is negative, tick articles instead." "Sort summary buffer by article number. Argument REVERSE means reverse order." (interactive "P") - (gnus-set-global-variables) - (gnus-summary-sort - ;; `gnus-summary-article-number' is a macro, and `sort-subr' wants - ;; a function, so we wrap it. - (cons (lambda () (gnus-summary-article-number)) - 'gnus-thread-sort-by-number) reverse)) + (gnus-summary-sort 'number reverse)) (defun gnus-summary-sort-by-author (&optional reverse) "Sort summary buffer by author name alphabetically. If case-fold-search is non-nil, case of letters is ignored. Argument REVERSE means reverse order." (interactive "P") - (gnus-set-global-variables) - (gnus-summary-sort - (cons - (lambda () - (let* ((header (gnus-get-header-by-num (gnus-summary-article-number))) - extract) - (if (not (vectorp header)) - "" - (setq extract (funcall gnus-extract-address-components - (mail-header-from header))) - (concat (or (car extract) (cdr extract)) - "\r" (int-to-string (mail-header-number header)) - "\r" (mail-header-subject header))))) - 'gnus-thread-sort-by-author) - reverse)) + (gnus-summary-sort 'author reverse)) (defun gnus-summary-sort-by-subject (&optional reverse) "Sort summary buffer by subject alphabetically. `Re:'s are ignored. If case-fold-search is non-nil, case of letters is ignored. Argument REVERSE means reverse order." (interactive "P") - (gnus-set-global-variables) - (gnus-summary-sort - (cons - (lambda () - (let* ((header (gnus-get-header-by-num (gnus-summary-article-number))) - extract) - (if (not (vectorp header)) - "" - (setq extract (funcall gnus-extract-address-components - (mail-header-from header))) - (concat - (downcase (gnus-simplify-subject (gnus-summary-subject-string) t)) - "\r" (int-to-string (mail-header-number header)) - "\r" (or (car extract) (cdr extract)))))) - 'gnus-thread-sort-by-subject) - reverse)) + (gnus-summary-sort 'subject reverse)) (defun gnus-summary-sort-by-date (&optional reverse) "Sort summary buffer by date. Argument REVERSE means reverse order." (interactive "P") - (gnus-set-global-variables) - (gnus-summary-sort - (cons - (lambda () - (gnus-sortable-date - (mail-header-date - (gnus-get-header-by-num (gnus-summary-article-number))))) - 'gnus-thread-sort-by-date) - reverse)) + (gnus-summary-sort 'date reverse)) (defun gnus-summary-sort-by-score (&optional reverse) "Sort summary buffer by score. Argument REVERSE means reverse order." (interactive "P") - (gnus-set-global-variables) - (gnus-summary-sort - (cons (lambda () (gnus-summary-article-score)) - 'gnus-thread-sort-by-score) - (not reverse))) + (gnus-summary-sort 'score reverse)) -(defvar gnus-summary-already-sorted nil) (defun gnus-summary-sort (predicate reverse) - ;; Sort summary buffer by PREDICATE. REVERSE means reverse order. - (if gnus-summary-already-sorted - () - (let (buffer-read-only) - (if (not gnus-show-threads) - ;; We do untreaded sorting... - (progn - (goto-char (point-min)) - (sort-subr reverse 'forward-line 'end-of-line (car predicate))) - ;; ... or we do threaded sorting. - (let ((gnus-thread-sort-functions (list (cdr predicate))) - (gnus-summary-prepare-hook nil) - (gnus-summary-already-sorted nil)) - ;; We do that by simply regenerating the threads. - (gnus-summary-prepare) - (and gnus-show-threads - gnus-thread-hide-subtree - (gnus-summary-hide-all-threads)) - ;; If in async mode, we send some info to the backend. - (and gnus-newsgroup-async - (setq gnus-newsgroup-threads (nreverse gnus-newsgroup-threads)) - (gnus-request-asynchronous - gnus-newsgroup-name - (if (and gnus-asynchronous-article-function - (fboundp gnus-asynchronous-article-function)) - (funcall gnus-asynchronous-article-function - gnus-newsgroup-threads) - gnus-newsgroup-threads)))))))) + "Sort summary buffer by PREDICATE. REVERSE means reverse order." + (gnus-set-global-variables) + (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate))) + (article (intern (format "gnus-article-sort-by-%s" predicate))) + (gnus-thread-sort-functions + (list + (if (not reverse) + thread + `(lambda (t1 t2) + (,thread t2 t1))))) + (gnus-article-sort-functions + (list + (if (not reverse) + article + `(lambda (t1 t2) + (,article t2 t1))))) + (buffer-read-only) + (gnus-summary-prepare-hook nil)) + ;; We do the sorting by regenerating the threads. + (gnus-summary-prepare) + ;; Hide subthreads if needed. + (when (and gnus-show-threads gnus-thread-hide-subtree) + (gnus-summary-hide-all-threads))) + ;; If in async mode, we send some info to the backend. + (when gnus-newsgroup-async + (gnus-request-asynchronous + gnus-newsgroup-name gnus-newsgroup-data))) - (defun gnus-sortable-date (date) "Make sortable string by string-lessp from DATE. Timezone package is used." - (let* ((date (timezone-fix-time date nil nil)) ;[Y M D H M S] - (year (aref date 0)) - (month (aref date 1)) - (day (aref date 2))) - (timezone-make-sortable-date - year month day - (timezone-make-time-string - (aref date 3) (aref date 4) (aref date 5))))) - - + (condition-case () + (progn + (setq date (inline (timezone-fix-time + date nil + (aref (inline (timezone-parse-date date)) 4)))) + (inline + (timezone-make-sortable-date + (aref date 0) (aref date 1) (aref date 2) + (inline + (timezone-make-time-string + (aref date 3) (aref date 4) (aref date 5)))))) + (error ""))) + ;; Summary saving commands. -(defun gnus-summary-save-article (&optional n) +(defun gnus-summary-save-article (&optional n not-saved) "Save the current article using the default saver function. If N is a positive number, save the N next articles. If N is a negative number, save the N previous articles. @@ -10379,38 +12970,53 @@ save those articles instead. The variable `gnus-default-article-saver' specifies the saver function." (interactive "P") (gnus-set-global-variables) - (let ((articles (gnus-summary-work-articles n))) + (let ((articles (gnus-summary-work-articles n)) + (save-buffer (save-excursion + (nnheader-set-temp-buffer " *Gnus Save*"))) + file header article) (while articles - (let ((header (gnus-get-header-by-num (car articles)))) - (if (vectorp header) - (progn - (save-window-excursion - (gnus-summary-select-article t nil nil (car articles))) - (or gnus-save-all-headers - (gnus-article-hide-headers t)) - ;; Remove any X-Gnus lines. - (save-excursion - (save-restriction - (set-buffer gnus-article-buffer) - (let ((buffer-read-only nil)) - (goto-char (point-min)) - (narrow-to-region (point) (or (search-forward "\n\n" nil t) - (point-max))) - (while (re-search-forward "^X-Gnus" nil t) - (beginning-of-line) - (delete-region (point) - (progn (forward-line 1) (point)))) - (widen)))) - (save-window-excursion - (if gnus-default-article-saver - (funcall gnus-default-article-saver) - (error "No default saver is defined.")))) + (setq header (gnus-summary-article-header + (setq article (pop articles)))) + (if (not (vectorp header)) + ;; This is a pseudo-article. (if (assq 'name header) (gnus-copy-file (cdr (assq 'name header))) - (gnus-message 1 "Article %d is unsavable" (car articles))))) - (gnus-summary-remove-process-mark (car articles)) - (setq articles (cdr articles))) - (gnus-summary-position-cursor) + (gnus-message 1 "Article %d is unsaveable" article)) + ;; This is a real article. + (save-window-excursion + (gnus-summary-select-article t nil nil article)) + (save-excursion + (set-buffer save-buffer) + (erase-buffer) + (insert-buffer-substring gnus-original-article-buffer)) + (unless gnus-save-all-headers + ;; Remove headers accoring to `gnus-saved-headers'. + (let ((gnus-visible-headers + (or gnus-saved-headers gnus-visible-headers)) + (gnus-article-buffer save-buffer)) + (gnus-article-hide-headers 1 t))) + (save-window-excursion + (if (not gnus-default-article-saver) + (error "No default saver is defined.") + ;; !!! Magic! The saving functions all save + ;; `gnus-original-article-buffer' (or so they think), + ;; but we bind that variable to our save-buffer. + (set-buffer gnus-article-buffer) + (let ((gnus-original-article-buffer save-buffer)) + (set-buffer gnus-summary-buffer) + (setq file (funcall + gnus-default-article-saver + (cond + ((not gnus-prompt-before-saving) + 'default) + ((eq gnus-prompt-before-saving 'always) + nil) + (t file))))))) + (gnus-summary-remove-process-mark article) + (unless not-saved + (gnus-summary-set-saved-mark article)))) + (gnus-kill-buffer save-buffer) + (gnus-summary-position-point) n)) (defun gnus-summary-pipe-output (&optional arg) @@ -10422,7 +13028,7 @@ pipe those articles instead." (interactive "P") (gnus-set-global-variables) (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)) - (gnus-summary-save-article arg)) + (gnus-summary-save-article arg t)) (gnus-configure-windows 'pipe)) (defun gnus-summary-save-article-mail (&optional arg) @@ -10458,116 +13064,256 @@ save those articles instead." (let ((gnus-default-article-saver 'gnus-summary-save-in-file)) (gnus-summary-save-article arg))) -(defun gnus-read-save-file-name (prompt default-name) - (let ((methods gnus-split-methods) - split-name) - (if (not gnus-split-methods) - () +(defun gnus-summary-save-article-body-file (&optional arg) + "Append the current article body to a file. +If N is a positive number, save the N next articles. +If N is a negative number, save the N previous articles. +If N is nil and any articles have been marked with the process mark, +save those articles instead." + (interactive "P") + (gnus-set-global-variables) + (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file)) + (gnus-summary-save-article arg))) + +(defun gnus-get-split-value (methods) + "Return a value based on the split METHODS." + (let (split-name method result match) + (when methods (save-excursion - (set-buffer gnus-article-buffer) - (gnus-narrow-to-headers) - (while methods - (goto-char (point-min)) - (and (condition-case () - (re-search-forward (car (car methods)) nil t) - (error nil)) - (setq split-name (cons (nth 1 (car methods)) split-name))) - (setq methods (cdr methods))) - (widen))) - (cond ((null split-name) - (read-file-name - (concat prompt " (default " - (file-name-nondirectory default-name) ") ") - (file-name-directory default-name) - default-name)) - ((= 1 (length split-name)) - (read-file-name - (concat prompt " (default " (car split-name) ") ") - gnus-article-save-directory - (concat gnus-article-save-directory (car split-name)))) - (t - (setq split-name (mapcar (lambda (el) (list el)) - (nreverse split-name))) - (let ((result (completing-read - (concat prompt " ") - split-name nil nil))) - (concat gnus-article-save-directory - (if (string= result "") - (car (car split-name)) - result))))))) + (set-buffer gnus-original-article-buffer) + (save-restriction + (nnheader-narrow-to-headers) + (while methods + (goto-char (point-min)) + (setq method (pop methods)) + (setq match (car method)) + (when (cond + ((stringp match) + ;; Regular expression. + (condition-case () + (re-search-forward match nil t) + (error nil))) + ((gnus-functionp match) + ;; Function. + (save-restriction + (widen) + (setq result (funcall match gnus-newsgroup-name)))) + ((consp match) + ;; Form. + (save-restriction + (widen) + (setq result (eval match))))) + (setq split-name (append (cdr method) split-name)) + (cond ((stringp result) + (push result split-name)) + ((consp result) + (setq split-name (append result split-name))))))))) + split-name)) + +(defun gnus-read-move-group-name (prompt default articles prefix) + "Read a group name." + (let* ((split-name (gnus-get-split-value gnus-move-split-methods)) + (minibuffer-confirm-incomplete nil) ; XEmacs + group-map + (dum (mapatoms + (lambda (g) + (and (boundp g) + (symbol-name g) + (memq 'respool + (assoc (symbol-name + (car (gnus-find-method-for-group + (symbol-name g)))) + gnus-valid-select-methods)) + (push (list (symbol-name g)) group-map))) + gnus-active-hashtb)) + (prom + (format "%s %s to:" + prompt + (if (> (length articles) 1) + (format "these %d articles" (length articles)) + "this article"))) + (to-newsgroup + (cond + ((null split-name) + (gnus-completing-read default prom + group-map nil nil prefix + 'gnus-group-history)) + ((= 1 (length split-name)) + (gnus-completing-read (car split-name) prom group-map + nil nil nil + 'gnus-group-history)) + (t + (gnus-completing-read nil prom + (mapcar (lambda (el) (list el)) + (nreverse split-name)) + nil nil nil + 'gnus-group-history))))) + (when to-newsgroup + (if (or (string= to-newsgroup "") + (string= to-newsgroup prefix)) + (setq to-newsgroup (or default ""))) + (or (gnus-active to-newsgroup) + (gnus-activate-group to-newsgroup) + (if (gnus-y-or-n-p (format "No such group: %s. Create it? " + to-newsgroup)) + (or (and (gnus-request-create-group + to-newsgroup (gnus-group-name-to-method to-newsgroup)) + (gnus-activate-group to-newsgroup nil nil + (gnus-group-name-to-method + to-newsgroup))) + (error "Couldn't create group %s" to-newsgroup))) + (error "No such group: %s" to-newsgroup))) + to-newsgroup)) + +(defun gnus-read-save-file-name (prompt default-name) + (let* ((split-name (gnus-get-split-value gnus-split-methods)) + (file + ;; Let the split methods have their say. + (cond + ;; No split name was found. + ((null split-name) + (read-file-name + (concat prompt " (default " + (file-name-nondirectory default-name) ") ") + (file-name-directory default-name) + default-name)) + ;; A single split name was found + ((= 1 (length split-name)) + (let* ((name (car split-name)) + (dir (cond ((file-directory-p name) + (file-name-as-directory name)) + ((file-exists-p name) name) + (t gnus-article-save-directory)))) + (read-file-name + (concat prompt " (default " name ") ") + dir name))) + ;; A list of splits was found. + (t + (setq split-name (nreverse split-name)) + (let (result) + (let ((file-name-history (nconc split-name file-name-history))) + (setq result + (read-file-name + (concat prompt " (`M-p' for defaults) ") + gnus-article-save-directory + (car split-name)))) + (car (push result file-name-history))))))) + ;; If we have read a directory, we append the default file name. + (when (file-directory-p file) + (setq file (concat (file-name-as-directory file) + (file-name-nondirectory default-name)))) + ;; Possibly translate some charaters. + (nnheader-translate-file-chars file))) + +(defun gnus-article-archive-name (group) + "Return the first instance of an \"Archive-name\" in the current buffer." + (let ((case-fold-search t)) + (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t) + (match-string 1)))) (defun gnus-summary-save-in-rmail (&optional filename) "Append this article to Rmail file. Optional argument FILENAME specifies file name. -Directory to save to is default to `gnus-article-save-directory' which -is initialized from the SAVEDIR environment variable." +Directory to save to is default to `gnus-article-save-directory'." (interactive) (gnus-set-global-variables) (let ((default-name (funcall gnus-rmail-save-name gnus-newsgroup-name gnus-current-headers gnus-newsgroup-last-rmail))) - (or filename - (setq filename (gnus-read-save-file-name - "Save in rmail file:" default-name))) + (setq filename + (cond ((eq filename 'default) + default-name) + (filename filename) + (t (gnus-read-save-file-name + "Save in rmail file:" default-name)))) (gnus-make-directory (file-name-directory filename)) - (gnus-eval-in-buffer-window - gnus-article-buffer - (save-excursion - (save-restriction - (widen) - (gnus-output-to-rmail filename)))) + (gnus-eval-in-buffer-window gnus-original-article-buffer + (save-excursion + (save-restriction + (widen) + (gnus-output-to-rmail filename)))) ;; Remember the directory name to save articles (setq gnus-newsgroup-last-rmail filename))) (defun gnus-summary-save-in-mail (&optional filename) "Append this article to Unix mail file. Optional argument FILENAME specifies file name. -Directory to save to is default to `gnus-article-save-directory' which -is initialized from the SAVEDIR environment variable." +Directory to save to is default to `gnus-article-save-directory'." (interactive) (gnus-set-global-variables) (let ((default-name (funcall gnus-mail-save-name gnus-newsgroup-name gnus-current-headers gnus-newsgroup-last-mail))) - (or filename - (setq filename (gnus-read-save-file-name - "Save in Unix mail file:" default-name))) + (setq filename + (cond ((eq filename 'default) + default-name) + (filename filename) + (t (gnus-read-save-file-name + "Save in Unix mail file:" default-name)))) (setq filename (expand-file-name filename (and default-name (file-name-directory default-name)))) (gnus-make-directory (file-name-directory filename)) - (gnus-eval-in-buffer-window - gnus-article-buffer - (save-excursion - (save-restriction - (widen) - (if (and (file-readable-p filename) (mail-file-babyl-p filename)) - (gnus-output-to-rmail filename) - (rmail-output filename 1 t t))))) + (gnus-eval-in-buffer-window gnus-original-article-buffer + (save-excursion + (save-restriction + (widen) + (if (and (file-readable-p filename) (mail-file-babyl-p filename)) + (gnus-output-to-rmail filename) + (let ((mail-use-rfc822 t)) + (rmail-output filename 1 t t)))))) ;; Remember the directory name to save articles. (setq gnus-newsgroup-last-mail filename))) (defun gnus-summary-save-in-file (&optional filename) "Append this article to file. Optional argument FILENAME specifies file name. -Directory to save to is default to `gnus-article-save-directory' which -is initialized from the SAVEDIR environment variable." +Directory to save to is default to `gnus-article-save-directory'." + (interactive) + (gnus-set-global-variables) + (let ((default-name + (funcall gnus-file-save-name gnus-newsgroup-name + gnus-current-headers gnus-newsgroup-last-file))) + (setq filename + (cond ((eq filename 'default) + default-name) + (filename filename) + (t (gnus-read-save-file-name + "Save in file:" default-name)))) + (gnus-make-directory (file-name-directory filename)) + (gnus-eval-in-buffer-window gnus-original-article-buffer + (save-excursion + (save-restriction + (widen) + (gnus-output-to-file filename)))) + ;; Remember the directory name to save articles. + (setq gnus-newsgroup-last-file filename))) + +(defun gnus-summary-save-body-in-file (&optional filename) + "Append this article body to a file. +Optional argument FILENAME specifies file name. +The directory to save in defaults to `gnus-article-save-directory'." (interactive) (gnus-set-global-variables) (let ((default-name (funcall gnus-file-save-name gnus-newsgroup-name gnus-current-headers gnus-newsgroup-last-file))) - (or filename - (setq filename (gnus-read-save-file-name - "Save in file:" default-name))) + (setq filename + (cond ((eq filename 'default) + default-name) + (filename filename) + (t (gnus-read-save-file-name + "Save body in file:" default-name)))) (gnus-make-directory (file-name-directory filename)) - (gnus-eval-in-buffer-window - gnus-article-buffer - (save-excursion - (save-restriction - (widen) - (gnus-output-to-file filename)))) + (gnus-eval-in-buffer-window gnus-original-article-buffer + (save-excursion + (save-restriction + (widen) + (goto-char (point-min)) + (and (search-forward "\n\n" nil t) + (narrow-to-region (point) (point-max))) + (gnus-output-to-file filename)))) ;; Remember the directory name to save articles. (setq gnus-newsgroup-last-file filename))) @@ -10575,28 +13321,31 @@ is initialized from the SAVEDIR environment variable." "Pipe this article to subprocess." (interactive) (gnus-set-global-variables) - (let ((command (read-string "Shell command on article: " - gnus-last-shell-command))) - (if (string-equal command "") - (setq command gnus-last-shell-command)) - (gnus-eval-in-buffer-window - gnus-article-buffer - (save-restriction - (widen) - (shell-command-on-region (point-min) (point-max) command nil))) - (setq gnus-last-shell-command command))) + (setq command + (cond ((eq command 'default) + gnus-last-shell-command) + (command command) + (t (read-string "Shell command on article: " + gnus-last-shell-command)))) + (if (string-equal command "") + (setq command gnus-last-shell-command)) + (gnus-eval-in-buffer-window gnus-article-buffer + (save-restriction + (widen) + (shell-command-on-region (point-min) (point-max) command nil))) + (setq gnus-last-shell-command command)) ;; Summary extract commands (defun gnus-summary-insert-pseudos (pslist &optional not-view) (let ((buffer-read-only nil) (article (gnus-summary-article-number)) - b) + after-article b e) (or (gnus-summary-goto-subject article) (error (format "No such article: %d" article))) - (gnus-summary-position-cursor) + (gnus-summary-position-point) ;; If all commands are to be bunched up on one line, we collect - ;; them here. + ;; them here. (if gnus-view-pseudos-separately () (let ((ps (setq pslist (sort pslist 'gnus-pseudos<))) @@ -10606,9 +13355,9 @@ is initialized from the SAVEDIR environment variable." (setq files (list (cdr (assq 'name (car ps))))) (while (and ps (cdr ps) (string= (or action "1") - (or (cdr (assq 'action (car (cdr ps)))) "2"))) - (setq files (cons (cdr (assq 'name (car (cdr ps)))) files)) - (setcdr ps (cdr (cdr ps)))) + (or (cdr (assq 'action (cadr ps))) "2"))) + (setq files (cons (cdr (assq 'name (cadr ps))) files)) + (setcdr ps (cddr ps))) (if (not files) () (if (not (string-match "%s" action)) @@ -10618,7 +13367,7 @@ is initialized from the SAVEDIR environment variable." (setcdr (assq 'execute (car ps)) (funcall (if (string-match "%s" action) 'format 'concat) - action + action (mapconcat (lambda (f) f) files " "))))) (setq ps (cdr ps))))) (if (and gnus-view-pseudos (not not-view)) @@ -10629,23 +13378,23 @@ is initialized from the SAVEDIR environment variable." (setq pslist (cdr pslist))) (save-excursion (while pslist - (gnus-summary-goto-subject (or (cdr (assq 'article (car pslist))) - (gnus-summary-article-number))) + (setq after-article (or (cdr (assq 'article (car pslist))) + (gnus-summary-article-number))) + (gnus-summary-goto-subject after-article) (forward-line 1) (setq b (point)) - (insert " " (file-name-nondirectory + (insert " " (file-name-nondirectory (cdr (assq 'name (car pslist)))) ": " (or (cdr (assq 'execute (car pslist))) "") "\n") - (add-text-properties - b (1+ b) (list 'gnus-number gnus-reffed-article-number - 'gnus-mark gnus-unread-mark - 'gnus-level 0 - 'gnus-pseudo (car pslist))) - (forward-line -1) - (gnus-sethash (int-to-string gnus-reffed-article-number) - (car pslist) gnus-newsgroup-headers-hashtb-by-number) - (setq gnus-newsgroup-unreads - (cons gnus-reffed-article-number gnus-newsgroup-unreads)) + (setq e (point)) + (forward-line -1) ; back to `b' + (gnus-add-text-properties + b (1- e) (list 'gnus-number gnus-reffed-article-number + gnus-mouse-face-prop gnus-mouse-face)) + (gnus-data-enter + after-article gnus-reffed-article-number + gnus-unread-mark b (car pslist) 0 (- e b)) + (push gnus-reffed-article-number gnus-newsgroup-unreads) (setq gnus-reffed-article-number (1- gnus-reffed-article-number)) (setq pslist (cdr pslist))))))) @@ -10664,13 +13413,20 @@ is initialized from the SAVEDIR environment variable." (save-excursion (gnus-article-setup-buffer) (set-buffer gnus-article-buffer) + (setq buffer-read-only nil) (let ((command (if automatic command (read-string "Command: " command))) - (buffer-read-only nil)) + ;; Just binding this here doesn't help, because there might + ;; be output from the process after exiting the scope of + ;; this `let'. + ;; (buffer-read-only nil) + ) (erase-buffer) (insert "$ " command "\n\n") (if gnus-view-pseudo-asynchronously - (start-process "gnus-execute" nil "sh" "-c" command) - (call-process "sh" nil t nil "-c" command))))) + (start-process "gnus-execute" nil shell-file-name + shell-command-switch command) + (call-process shell-file-name nil t nil + shell-command-switch command))))) (defun gnus-copy-file (file &optional to) "Copy FILE to TO." @@ -10679,7 +13435,7 @@ is initialized from the SAVEDIR environment variable." (read-file-name "Copy file to: " default-directory))) (gnus-set-global-variables) (or to (setq to (read-file-name "Copy file to: " default-directory))) - (and (file-directory-p to) + (and (file-directory-p to) (setq to (concat (file-name-as-directory to) (file-name-nondirectory file)))) (copy-file file to)) @@ -10696,12 +13452,9 @@ is initialized from the SAVEDIR environment variable." "Edit a local kill file applied to the current newsgroup." (interactive) (gnus-set-global-variables) - (setq gnus-current-headers - (gnus-gethash - (int-to-string (gnus-summary-article-number)) - gnus-newsgroup-headers-hashtb-by-number)) + (setq gnus-current-headers (gnus-summary-article-header)) (gnus-set-global-variables) - (gnus-group-edit-local-kill + (gnus-group-edit-local-kill (gnus-summary-article-number) gnus-newsgroup-name)) @@ -10711,64 +13464,30 @@ is initialized from the SAVEDIR environment variable." (put 'gnus-article-mode 'mode-class 'special) -(defvar gnus-bugaboo nil) - (if gnus-article-mode-map nil (setq gnus-article-mode-map (make-keymap)) (suppress-keymap gnus-article-mode-map) - (define-key gnus-article-mode-map " " 'gnus-article-next-page) - (define-key gnus-article-mode-map "\177" 'gnus-article-prev-page) - (define-key gnus-article-mode-map "\C-c^" 'gnus-article-refer-article) - (define-key gnus-article-mode-map "h" 'gnus-article-show-summary) - (define-key gnus-article-mode-map "s" 'gnus-article-show-summary) - (define-key gnus-article-mode-map "\C-c\C-m" 'gnus-article-mail) - (define-key gnus-article-mode-map "?" 'gnus-article-describe-briefly) - (define-key gnus-article-mode-map gnus-mouse-2 'gnus-article-push-button) - (define-key gnus-article-mode-map "\r" 'gnus-article-press-button) - (define-key gnus-article-mode-map "\t" 'gnus-article-next-button) - (define-key gnus-article-mode-map "\C-c\C-b" 'gnus-bug) - - ;; Duplicate almost all summary keystrokes in the article mode map. - (let ((commands - (list - "p" "N" "P" "\M-\C-n" "\M-\C-p" - "\M-n" "\M-p" "." "," "\M-s" "\M-r" "<" ">" "j" - "u" "!" "U" "d" "D" "E" "\M-u" "\M-U" "k" "\C-k" "\M-\C-k" - "\M-\C-l" "e" "#" "\M-#" "\M-\C-t" "\M-\C-s" "\M-\C-h" - "\M-\C-f" "\M-\C-b" "\M-\C-u" "\M-\C-d" "&" "\C-w" - "\C-t" "?" "\C-c\M-\C-s" "\C-c\C-s\C-n" "\C-c\C-s\C-a" - "\C-c\C-s\C-s" "\C-c\C-s\C-d" "\C-c\C-s\C-i" "\C-x\C-s" - "\M-g" "w" "\C-c\C-r" "\M-t" "C" - "o" "\C-o" "|" "\M-k" "\M-K" "V" "\C-c\C-d" - "\C-c\C-i" "x" "X" "t" "g" "?" "l" - "\C-c\C-v\C-v" "\C-d" "v" -;; "Mt" "M!" "Md" "Mr" -;; "Mc" "M " "Me" "Mx" "M?" "Mb" "MB" "M#" "M\M-#" "M\M-r" -;; "M\M-\C-r" "MD" "M\M-D" "MS" "MC" "MH" "M\C-c" "Mk" "MK" -;; "Ms" "Mc" "Mu" "Mm" "Mk" "Gn" "Gp" "GN" "GP" "G\C-n" "G\C-p" -;; "G\M-n" "G\M-p" "Gf" "Gb" "Gg" "Gl" "Gp" "Tk" "Tl" "Ti" "TT" -;; "Ts" "TS" "Th" "TH" "Tn" "Tp" "Tu" "Td" "T#" "A " "An" "A\177" "Ap" -;; "A\r" "A<" "A>" "Ab" "Ae" "A^" "Ar" "Aw" "Ac" "Ag" "At" "Am" -;; "As" "Wh" "Ws" "Wc" "Wo" "Ww" "Wd" "Wq" "Wf" "Wt" "W\C-t" -;; "WT" "WA" "Wa" "WH" "WC" "WS" "Wb" "Hv" "Hf" "Hd" "Hh" "Hi" -;; "Be" "B\177" "Bm" "Br" "Bw" "Bc" "Bq" "Bi" "Oo" "Om" "Or" -;; "Of" "Oh" "Ov" "Op" "Vu" "V\C-s" "V\C-r" "Vr" "V&" "VT" "Ve" -;; "VD" "Vk" "VK" "Vsn" "Vsa" "Vss" "Vsd" "Vsi" - ))) - (while (and gnus-bugaboo commands) ; disabled - (define-key gnus-article-mode-map (car commands) - 'gnus-article-summary-command) - (setq commands (cdr commands)))) - - (let ((commands (list "q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F" -;; "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP" - "=" "n" "^" "\M-^"))) - (while (and gnus-bugaboo commands) ; disabled - (define-key gnus-article-mode-map (car commands) - 'gnus-article-summary-command-nosave) - (setq commands (cdr commands))))) + (gnus-define-keys gnus-article-mode-map + " " gnus-article-goto-next-page + "\177" gnus-article-goto-prev-page + [delete] gnus-article-goto-prev-page + "\C-c^" gnus-article-refer-article + "h" gnus-article-show-summary + "s" gnus-article-show-summary + "\C-c\C-m" gnus-article-mail + "?" gnus-article-describe-briefly + gnus-mouse-2 gnus-article-push-button + "\r" gnus-article-press-button + "\t" gnus-article-next-button + "\M-\t" gnus-article-prev-button + "<" beginning-of-buffer + ">" end-of-buffer + "\C-c\C-b" gnus-bug) + + (substitute-key-definition + 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)) (defun gnus-article-mode () "Major mode for displaying an article. @@ -10786,7 +13505,9 @@ The following commands are available: \\[gnus-article-describe-briefly]\t Describe the current mode briefly \\[gnus-info-find-node]\t Go to the Gnus info node" (interactive) - (if gnus-visual (gnus-article-make-menu-bar)) + (when (and menu-bar-mode + (gnus-visual-p 'article-menu 'menu)) + (gnus-article-make-menu-bar)) (kill-all-local-variables) (gnus-simplify-mode-line) (setq mode-name "Article") @@ -10803,28 +13524,49 @@ The following commands are available: (run-hooks 'gnus-article-mode-hook)) (defun gnus-article-setup-buffer () - "Initialize article mode buffer." - ;; Returns the article buffer. - (if (get-buffer gnus-article-buffer) + "Initialize the article buffer." + (let* ((name (if gnus-single-article-buffer "*Article*" + (concat "*Article " gnus-newsgroup-name "*"))) + (original + (progn (string-match "\\*Article" name) + (concat " *Original Article" + (substring name (match-end 0)))))) + (setq gnus-article-buffer name) + (setq gnus-original-article-buffer original) + ;; This might be a variable local to the summary buffer. + (unless gnus-single-article-buffer (save-excursion - (set-buffer gnus-article-buffer) - (buffer-disable-undo (current-buffer)) - (setq buffer-read-only t) - (gnus-add-current-to-buffer-list) - (or (eq major-mode 'gnus-article-mode) - (gnus-article-mode)) - (current-buffer)) + (set-buffer gnus-summary-buffer) + (setq gnus-article-buffer name) + (setq gnus-original-article-buffer original) + (gnus-set-global-variables)) + (make-local-variable 'gnus-summary-buffer)) + ;; Init original article buffer. (save-excursion - (set-buffer (get-buffer-create gnus-article-buffer)) - (gnus-add-current-to-buffer-list) - (gnus-article-mode) - (current-buffer)))) + (set-buffer (get-buffer-create gnus-original-article-buffer)) + (buffer-disable-undo (current-buffer)) + (setq major-mode 'gnus-original-article-mode) + (make-local-variable 'gnus-original-article)) + (if (get-buffer name) + (save-excursion + (set-buffer name) + (buffer-disable-undo (current-buffer)) + (setq buffer-read-only t) + (gnus-add-current-to-buffer-list) + (or (eq major-mode 'gnus-article-mode) + (gnus-article-mode)) + (current-buffer)) + (save-excursion + (set-buffer (get-buffer-create name)) + (gnus-add-current-to-buffer-list) + (gnus-article-mode) + (current-buffer))))) ;; Set article window start at LINE, where LINE is the number of lines ;; from the head of the article. (defun gnus-article-set-window-start (&optional line) - (set-window-start - (get-buffer-window gnus-article-buffer) + (set-window-start + (get-buffer-window gnus-article-buffer t) (save-excursion (set-buffer gnus-article-buffer) (goto-char (point-min)) @@ -10835,90 +13577,217 @@ The following commands are available: (forward-line line) (point))))) +(defun gnus-kill-all-overlays () + "Delete all overlays in the current buffer." + (when (fboundp 'overlay-lists) + (let* ((overlayss (overlay-lists)) + (buffer-read-only nil) + (overlays (nconc (car overlayss) (cdr overlayss)))) + (while overlays + (delete-overlay (pop overlays)))))) + (defun gnus-request-article-this-buffer (article group) "Get an article and insert it into this buffer." - (setq group (or group gnus-newsgroup-name)) - - ;; Open server if it has closed. - (gnus-check-server (gnus-find-method-for-group group)) - - ;; Using `gnus-request-article' directly will insert the article into - ;; `nntp-server-buffer' - so we'll save some time by not having to - ;; copy it from the server buffer into the article buffer. - - ;; We only request an article by message-id when we do not have the - ;; headers for it, so we'll have to get those. - (and (stringp article) - (let ((gnus-override-method gnus-refer-article-method)) - (gnus-read-header article))) - - ;; If the article number is negative, that means that this article - ;; doesn't belong in this newsgroup (possibly), so we find its - ;; message-id and request it by id instead of number. - (if (not (numberp article)) - () - (save-excursion - (set-buffer gnus-summary-buffer) - (let ((header (gnus-get-header-by-num article))) - (if (< article 0) - (if (vectorp header) - ;; It's a real article. - (setq article (mail-header-id header)) - ;; It is an extracted pseudo-article. - (setq article 'pseudo) - (gnus-request-pseudo-article header))) - - (let ((method (gnus-find-method-for-group gnus-newsgroup-name))) - (if (not (eq (car method) 'nneething)) - () - (let ((dir (concat (file-name-as-directory (nth 1 method)) - (mail-header-subject header)))) - (if (file-directory-p dir) - (progn - (setq article 'nneething) - (gnus-group-enter-directory dir))))))))) - - ;; Check the cache. - (if (and gnus-use-cache - (numberp article) - (gnus-cache-request-article article group)) - 'article - ;; Get the article and put into the article buffer. - (if (or (stringp article) (numberp article)) - (progn + (let (do-update-line) + (prog1 + (save-excursion (erase-buffer) - ;; There may be some overlays that we have to kill... - (insert "i") - (let ((overlays (and (fboundp 'overlays-at) - (overlays-at (point-min))))) - (while overlays - (delete-overlay (car overlays)) - (setq overlays (cdr overlays)))) - (erase-buffer) - (let ((gnus-override-method - (and (stringp article) gnus-refer-article-method))) - (and (gnus-request-article article group (current-buffer)) - 'article))) - article))) + (gnus-kill-all-overlays) + (setq group (or group gnus-newsgroup-name)) + + ;; Open server if it has closed. + (gnus-check-server (gnus-find-method-for-group group)) + + ;; Using `gnus-request-article' directly will insert the article into + ;; `nntp-server-buffer' - so we'll save some time by not having to + ;; copy it from the server buffer into the article buffer. + + ;; We only request an article by message-id when we do not have the + ;; headers for it, so we'll have to get those. + (when (stringp article) + (let ((gnus-override-method gnus-refer-article-method)) + (gnus-read-header article))) + + ;; If the article number is negative, that means that this article + ;; doesn't belong in this newsgroup (possibly), so we find its + ;; message-id and request it by id instead of number. + (when (and (numberp article) + gnus-summary-buffer + (get-buffer gnus-summary-buffer) + (buffer-name (get-buffer gnus-summary-buffer))) + (save-excursion + (set-buffer gnus-summary-buffer) + (let ((header (gnus-summary-article-header article))) + (if (< article 0) + (cond + ((memq article gnus-newsgroup-sparse) + ;; This is a sparse gap article. + (setq do-update-line article) + (setq article (mail-header-id header)) + (let ((gnus-override-method gnus-refer-article-method)) + (gnus-read-header article)) + (setq gnus-newsgroup-sparse + (delq article gnus-newsgroup-sparse))) + ((vectorp header) + ;; It's a real article. + (setq article (mail-header-id header))) + (t + ;; It is an extracted pseudo-article. + (setq article 'pseudo) + (gnus-request-pseudo-article header)))) + + (let ((method (gnus-find-method-for-group + gnus-newsgroup-name))) + (if (not (eq (car method) 'nneething)) + () + (let ((dir (concat (file-name-as-directory (nth 1 method)) + (mail-header-subject header)))) + (if (file-directory-p dir) + (progn + (setq article 'nneething) + (gnus-group-enter-directory dir))))))))) + + (cond + ;; Refuse to select canceled articles. + ((and (numberp article) + gnus-summary-buffer + (get-buffer gnus-summary-buffer) + (buffer-name (get-buffer gnus-summary-buffer)) + (eq (cdr (save-excursion + (set-buffer gnus-summary-buffer) + (assq article gnus-newsgroup-reads))) + gnus-canceled-mark)) + nil) + ;; We first check `gnus-original-article-buffer'. + ((and (get-buffer gnus-original-article-buffer) + (numberp article) + (save-excursion + (set-buffer gnus-original-article-buffer) + (and (equal (car gnus-original-article) group) + (eq (cdr gnus-original-article) article)))) + (insert-buffer-substring gnus-original-article-buffer) + 'article) + ;; Check the backlog. + ((and gnus-keep-backlog + (gnus-backlog-request-article group article (current-buffer))) + 'article) + ;; Check the cache. + ((and gnus-use-cache + (numberp article) + (gnus-cache-request-article article group)) + 'article) + ;; Get the article and put into the article buffer. + ((or (stringp article) (numberp article)) + (let ((gnus-override-method + (and (stringp article) gnus-refer-article-method)) + (buffer-read-only nil)) + (erase-buffer) + (gnus-kill-all-overlays) + (if (gnus-request-article article group (current-buffer)) + (progn + (and gnus-keep-backlog + (numberp article) + (gnus-backlog-enter-article + group article (current-buffer))) + 'article)))) + ;; It was a pseudo. + (t article))) + + ;; Take the article from the original article buffer + ;; and place it in the buffer it's supposed to be in. + (when (and (get-buffer gnus-article-buffer) + ;;(numberp article) + (equal (buffer-name (current-buffer)) + (buffer-name (get-buffer gnus-article-buffer)))) + (save-excursion + (if (get-buffer gnus-original-article-buffer) + (set-buffer (get-buffer gnus-original-article-buffer)) + (set-buffer (get-buffer-create gnus-original-article-buffer)) + (buffer-disable-undo (current-buffer)) + (setq major-mode 'gnus-original-article-mode) + (setq buffer-read-only t) + (gnus-add-current-to-buffer-list)) + (let (buffer-read-only) + (erase-buffer) + (insert-buffer-substring gnus-article-buffer)) + (setq gnus-original-article (cons group article)))) + + ;; Update sparse articles. + (when (and do-update-line + (or (numberp article) + (stringp article))) + (let ((buf (current-buffer))) + (set-buffer gnus-summary-buffer) + (gnus-summary-update-article do-update-line) + (gnus-summary-goto-subject do-update-line nil t) + (set-window-point (get-buffer-window (current-buffer) t) + (point)) + (set-buffer buf)))))) -(defun gnus-read-header (id) +(defun gnus-read-header (id &optional header) "Read the headers of article ID and enter them into the Gnus system." - (let (header) - (if (not (setq header - (car (if (let ((gnus-nov-is-evil t)) - (gnus-retrieve-headers - (list id) gnus-newsgroup-name)) - (gnus-get-newsgroup-headers))))) - nil - (if (stringp id) - (mail-header-set-number header gnus-reffed-article-number)) - (setq gnus-newsgroup-headers (cons header gnus-newsgroup-headers)) - (gnus-sethash (int-to-string (mail-header-number header)) header - gnus-newsgroup-headers-hashtb-by-number) - (if (stringp id) - (setq gnus-reffed-article-number (1- gnus-reffed-article-number))) - (setq gnus-current-headers header) - header))) + (let ((group gnus-newsgroup-name) + (gnus-override-method + (and (gnus-news-group-p gnus-newsgroup-name) + gnus-refer-article-method)) + where) + ;; First we check to see whether the header in question is already + ;; fetched. + (if (stringp id) + ;; This is a Message-ID. + (setq header (or header (gnus-id-to-header id))) + ;; This is an article number. + (setq header (or header (gnus-summary-article-header id)))) + (if (and header + (not (memq (mail-header-number header) gnus-newsgroup-sparse))) + ;; We have found the header. + header + ;; We have to really fetch the header to this article. + (when (setq where (gnus-request-head id group)) + (save-excursion + (set-buffer nntp-server-buffer) + (goto-char (point-max)) + (insert ".\n") + (goto-char (point-min)) + (insert "211 ") + (princ (cond + ((numberp id) id) + ((cdr where) (cdr where)) + (header (mail-header-number header)) + (t gnus-reffed-article-number)) + (current-buffer)) + (insert " Article retrieved.\n")) + ;(when (and header + ; (memq (mail-header-number header) gnus-newsgroup-sparse)) + ; (setcar (gnus-id-to-thread id) nil)) + (if (not (setq header (car (gnus-get-newsgroup-headers)))) + () ; Malformed head. + (unless (memq (mail-header-number header) gnus-newsgroup-sparse) + (if (and (stringp id) + (not (string= (gnus-group-real-name group) + (car where)))) + ;; If we fetched by Message-ID and the article came + ;; from a different group, we fudge some bogus article + ;; numbers for this article. + (mail-header-set-number header gnus-reffed-article-number)) + (decf gnus-reffed-article-number) + (gnus-remove-header (mail-header-number header)) + (push header gnus-newsgroup-headers) + (setq gnus-current-headers header) + (push (mail-header-number header) gnus-newsgroup-limit)) + header))))) + +(defun gnus-remove-header (number) + "Remove header NUMBER from `gnus-newsgroup-headers'." + (if (and gnus-newsgroup-headers + (= number (mail-header-number (car gnus-newsgroup-headers)))) + (pop gnus-newsgroup-headers) + (let ((headers gnus-newsgroup-headers)) + (while (and (cdr headers) + (not (= number (mail-header-number (cadr headers))))) + (pop headers)) + (when (cdr headers) + (setcdr headers (cddr headers)))))) (defun gnus-article-prepare (article &optional all-headers header) "Prepare ARTICLE in article mode buffer. @@ -10927,15 +13796,14 @@ If ARTICLE is an id, HEADER should be the article headers. If ALL-HEADERS is non-nil, no headers are hidden." (save-excursion ;; Make sure we start in a summary buffer. - (or (eq major-mode 'gnus-summary-mode) - (set-buffer gnus-summary-buffer)) + (unless (eq major-mode 'gnus-summary-mode) + (set-buffer gnus-summary-buffer)) (setq gnus-summary-buffer (current-buffer)) ;; Make sure the connection to the server is alive. - (or (gnus-server-opened (gnus-find-method-for-group gnus-newsgroup-name)) - (progn - (gnus-check-server - (gnus-find-method-for-group gnus-newsgroup-name)) - (gnus-request-group gnus-newsgroup-name t))) + (unless (gnus-server-opened + (gnus-find-method-for-group gnus-newsgroup-name)) + (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name)) + (gnus-request-group gnus-newsgroup-name t)) (let* ((article (if header (mail-header-number header) article)) (summary-buffer (current-buffer)) (internal-hook gnus-article-internal-prepare-hook) @@ -10944,21 +13812,25 @@ If ALL-HEADERS is non-nil, no headers are hidden." (save-excursion (gnus-article-setup-buffer) (set-buffer gnus-article-buffer) + ;; Deactivate active regions. + (when (and (boundp 'transient-mark-mode) + transient-mark-mode) + (setq mark-active nil)) (if (not (setq result (let ((buffer-read-only nil)) - (gnus-request-article-this-buffer + (gnus-request-article-this-buffer article group)))) ;; There is no such article. (save-excursion - (if (not (numberp article)) - () - (setq gnus-article-current + (when (and (numberp article) + (not (memq article gnus-newsgroup-sparse))) + (setq gnus-article-current (cons gnus-newsgroup-name article)) (set-buffer gnus-summary-buffer) (setq gnus-current-article article) (gnus-summary-mark-article article gnus-canceled-mark)) - (gnus-message 1 "No such article (may be canceled)") - (ding) - nil) + (unless (memq article gnus-newsgroup-sparse) + (gnus-error + 1 "No such article (may have expired or been canceled)"))) (if (or (eq result 'pseudo) (eq result 'nneething)) (progn (save-excursion @@ -10987,44 +13859,49 @@ If ALL-HEADERS is non-nil, no headers are hidden." gnus-newsgroup-history (cons gnus-current-article gnus-newsgroup-history) gnus-current-article article - gnus-current-headers - (gnus-get-header-by-num gnus-current-article) - gnus-article-current + gnus-current-headers + (gnus-summary-article-header gnus-current-article) + gnus-article-current (cons gnus-newsgroup-name gnus-current-article)) + (unless (vectorp gnus-current-headers) + (setq gnus-current-headers nil)) (gnus-summary-show-thread) (run-hooks 'gnus-mark-article-hook) (gnus-set-mode-line 'summary) - (and gnus-visual + (and (gnus-visual-p 'article-highlight 'highlight) (run-hooks 'gnus-visual-mark-article-hook)) ;; Set the global newsgroup variables here. ;; Suggested by Jim Sisolak ;; . (gnus-set-global-variables) - (setq gnus-have-all-headers + (setq gnus-have-all-headers (or all-headers gnus-show-all-headers)) - (and gnus-use-cache - (vectorp (gnus-get-header-by-number article)) + (and gnus-use-cache + (vectorp (gnus-summary-article-header article)) (gnus-cache-possibly-enter-article group article - (gnus-get-header-by-number article) + (gnus-summary-article-header article) (memq article gnus-newsgroup-marked) (memq article gnus-newsgroup-dormant) (memq article gnus-newsgroup-unreads))))) - ;; Hooks for getting information from the article. - ;; This hook must be called before being narrowed. - (let (buffer-read-only) - (run-hooks 'internal-hook) - (run-hooks 'gnus-article-prepare-hook) - ;; Decode MIME message. - (if (and gnus-show-mime - (or (not gnus-strict-mime) - (gnus-fetch-field "Mime-Version"))) - (funcall gnus-show-mime-method)) - ;; Perform the article display hooks. - (run-hooks 'gnus-article-display-hook)) - ;; Do page break. - (goto-char (point-min)) - (and gnus-break-pages (gnus-narrow-to-page)) + (when (or (numberp article) + (stringp article)) + ;; Hooks for getting information from the article. + ;; This hook must be called before being narrowed. + (let (buffer-read-only) + (run-hooks 'internal-hook) + (run-hooks 'gnus-article-prepare-hook) + ;; Decode MIME message. + (if gnus-show-mime + (if (or (not gnus-strict-mime) + (gnus-fetch-field "Mime-Version")) + (funcall gnus-show-mime-method) + (funcall gnus-decode-encoded-word-method))) + ;; Perform the article display hooks. + (run-hooks 'gnus-article-display-hook)) + ;; Do page break. + (goto-char (point-min)) + (and gnus-break-pages (gnus-narrow-to-page))) (gnus-set-mode-line 'article) (gnus-configure-windows 'article) (goto-char (point-min)) @@ -11032,88 +13909,171 @@ If ALL-HEADERS is non-nil, no headers are hidden." (defun gnus-article-show-all-headers () "Show all article headers in article mode buffer." - (save-excursion + (save-excursion (gnus-article-setup-buffer) (set-buffer gnus-article-buffer) (let ((buffer-read-only nil)) - (remove-text-properties (point-min) (point-max) - gnus-hidden-properties)))) + (gnus-unhide-text (point-min) (point-max))))) (defun gnus-article-hide-headers-if-wanted () "Hide unwanted headers if `gnus-have-all-headers' is nil. Provided for backwards compatibility." (or (save-excursion (set-buffer gnus-summary-buffer) gnus-have-all-headers) + gnus-inhibit-hiding (gnus-article-hide-headers))) -(defun gnus-article-hide-headers (&optional delete) - "Hide unwanted headers and possibly sort them as well." - (interactive "P") +(defsubst gnus-article-header-rank () + "Give the rank of the string HEADER as given by `gnus-sorted-header-list'." + (let ((list gnus-sorted-header-list) + (i 0)) + (while list + (when (looking-at (car list)) + (setq list nil)) + (setq list (cdr list)) + (incf i)) + i)) + +(defun gnus-article-hide-headers (&optional arg delete) + "Toggle whether to hide unwanted headers and possibly sort them as well. +If given a negative prefix, always show; if given a positive prefix, +always hide." + (interactive (gnus-hidden-arg)) + (if (gnus-article-check-hidden-text 'headers arg) + ;; Show boring headers as well. + (gnus-article-show-hidden-text 'boring-headers) + ;; This function might be inhibited. + (unless gnus-inhibit-hiding + (save-excursion + (set-buffer gnus-article-buffer) + (save-restriction + (let ((buffer-read-only nil) + (props (nconc (list 'gnus-type 'headers) + gnus-hidden-properties)) + (max (1+ (length gnus-sorted-header-list))) + (ignored (when (not (stringp gnus-visible-headers)) + (cond ((stringp gnus-ignored-headers) + gnus-ignored-headers) + ((listp gnus-ignored-headers) + (mapconcat 'identity gnus-ignored-headers + "\\|"))))) + (visible + (cond ((stringp gnus-visible-headers) + gnus-visible-headers) + ((and gnus-visible-headers + (listp gnus-visible-headers)) + (mapconcat 'identity gnus-visible-headers "\\|")))) + (inhibit-point-motion-hooks t) + want-list beg) + ;; First we narrow to just the headers. + (widen) + (goto-char (point-min)) + ;; Hide any "From " lines at the beginning of (mail) articles. + (while (looking-at "From ") + (forward-line 1)) + (unless (bobp) + (if delete + (delete-region (point-min) (point)) + (gnus-hide-text (point-min) (point) props))) + ;; Then treat the rest of the header lines. + (narrow-to-region + (point) + (progn (search-forward "\n\n" nil t) (forward-line -1) (point))) + ;; Then we use the two regular expressions + ;; `gnus-ignored-headers' and `gnus-visible-headers' to + ;; select which header lines is to remain visible in the + ;; article buffer. + (goto-char (point-min)) + (while (re-search-forward "^[^ \t]*:" nil t) + (beginning-of-line) + ;; We add the headers we want to keep to a list and delete + ;; them from the buffer. + (gnus-put-text-property + (point) (1+ (point)) 'message-rank + (if (or (and visible (looking-at visible)) + (and ignored + (not (looking-at ignored)))) + (gnus-article-header-rank) + (+ 2 max))) + (forward-line 1)) + (message-sort-headers-1) + (when (setq beg (text-property-any + (point-min) (point-max) 'message-rank (+ 2 max))) + ;; We make the unwanted headers invisible. + (if delete + (delete-region beg (point-max)) + ;; Suggested by Sudish Joseph . + (gnus-hide-text-type beg (point-max) 'headers)) + ;; Work around XEmacs lossage. + (gnus-put-text-property (point-min) beg 'invisible nil)))))))) + +(defun gnus-article-hide-boring-headers (&optional arg) + "Toggle hiding of headers that aren't very interesting. +If given a negative prefix, always show; if given a positive prefix, +always hide." + (interactive (gnus-hidden-arg)) + (unless (gnus-article-check-hidden-text 'boring-headers arg) + (save-excursion + (set-buffer gnus-article-buffer) + (save-restriction + (let ((buffer-read-only nil) + (list gnus-boring-article-headers) + (inhibit-point-motion-hooks t) + elem) + (nnheader-narrow-to-headers) + (while list + (setq elem (pop list)) + (goto-char (point-min)) + (cond + ;; Hide empty headers. + ((eq elem 'empty) + (while (re-search-forward "^[^:]+:[ \t]\n[^ \t]" nil t) + (forward-line -1) + (gnus-hide-text-type + (progn (beginning-of-line) (point)) + (progn + (end-of-line) + (if (re-search-forward "^[^ \t]" nil t) + (match-beginning 0) + (point-max))) + 'boring-headers))) + ;; Hide boring Newsgroups header. + ((eq elem 'newsgroups) + (when (equal (message-fetch-field "newsgroups") + (gnus-group-real-name gnus-newsgroup-name)) + (gnus-article-hide-header "newsgroups"))) + ((eq elem 'followup-to) + (when (equal (message-fetch-field "followup-to") + (message-fetch-field "newsgroups")) + (gnus-article-hide-header "followup-to"))) + ((eq elem 'reply-to) + (let ((from (message-fetch-field "from")) + (reply-to (message-fetch-field "reply-to"))) + (when (and + from reply-to + (equal + (nth 1 (funcall gnus-extract-address-components from)) + (nth 1 (funcall gnus-extract-address-components + reply-to)))) + (gnus-article-hide-header "reply-to")))) + ((eq elem 'date) + (let ((date (message-fetch-field "date"))) + (when (and date + (< (gnus-days-between date (current-time-string)) + 4)) + (gnus-article-hide-header "date"))))))))))) + +(defun gnus-article-hide-header (header) (save-excursion - (set-buffer gnus-article-buffer) - (save-restriction - (let ((sorted gnus-sorted-header-list) - (buffer-read-only nil) - want-list beg want-l) - ;; First we narrow to just the headers. - (widen) - (goto-char (point-min)) - ;; Hide any "From " lines at the beginning of (mail) articles. - (while (looking-at "From ") - (forward-line 1)) - (or (bobp) - (add-text-properties (point-min) (point) gnus-hidden-properties)) - ;; Then treat the rest of the header lines. - (narrow-to-region - (point) - (progn (search-forward "\n\n" nil t) (forward-line -1) (point))) - ;; Then we use the two regular expressions - ;; `gnus-ignored-headers' and `gnus-visible-headers' to - ;; select which header lines is to remain visible in the - ;; article buffer. - (goto-char (point-min)) - (while (re-search-forward "^[^ \t]*:" nil t) - (beginning-of-line) - ;; We add the headers we want to keep to a list and delete - ;; them from the buffer. - (if (or (and (stringp gnus-visible-headers) - (looking-at gnus-visible-headers)) - (and (not (stringp gnus-visible-headers)) - (stringp gnus-ignored-headers) - (not (looking-at gnus-ignored-headers)))) - (progn - (setq beg (point)) - (forward-line 1) - ;; Be sure to get multi-line headers... - (re-search-forward "^[^ \t]*:" nil t) - (beginning-of-line) - (setq want-list - (cons (buffer-substring beg (point)) want-list)) - (delete-region beg (point)) - (goto-char beg)) - (forward-line 1))) - ;; Next we perform the sorting by looking at - ;; `gnus-sorted-header-list'. - (goto-char (point-min)) - (while (and sorted want-list) - (setq want-l want-list) - (while (and want-l - (not (string-match (car sorted) (car want-l)))) - (setq want-l (cdr want-l))) - (if want-l - (progn - (insert (car want-l)) - (setq want-list (delq (car want-l) want-list)))) - (setq sorted (cdr sorted))) - ;; Any headers that were not matched by the sorted list we - ;; just tack on the end of the visible header list. - (while want-list - (insert (car want-list)) - (setq want-list (cdr want-list))) - ;; And finally we make the unwanted headers invisible. - (if delete - (delete-region (point) (point-max)) - ;; Suggested by Sudish Joseph . - (add-text-properties (point) (point-max) gnus-hidden-properties)))))) + (goto-char (point-min)) + (when (re-search-forward (concat "^" header ":") nil t) + (gnus-hide-text-type + (progn (beginning-of-line) (point)) + (progn + (end-of-line) + (if (re-search-forward "^[^ \t]" nil t) + (match-beginning 0) + (point-max))) + 'boring-headers)))) ;; Written by Per Abrahamsen . (defun gnus-article-treat-overstrike () @@ -11125,21 +14085,18 @@ Provided for backwards compatibility." (while (search-forward "\b" nil t) (let ((next (following-char)) (previous (char-after (- (point) 2)))) - (cond ((eq next previous) - (put-text-property (- (point) 2) (point) - 'invisible t) - (put-text-property (point) (1+ (point)) - 'face 'bold)) - ((eq next ?_) - (put-text-property (1- (point)) (1+ (point)) - 'invisible t) - (put-text-property (1- (point)) (point) - 'face 'underline)) - ((eq previous ?_) - (put-text-property (- (point) 2) (point) - 'invisible t) - (put-text-property (point) (1+ (point)) - 'face 'underline)))))))) + (cond + ((eq next previous) + (gnus-put-text-property (- (point) 2) (point) 'invisible t) + (gnus-put-text-property (point) (1+ (point)) 'face 'bold)) + ((eq next ?_) + (gnus-put-text-property (1- (point)) (1+ (point)) 'invisible t) + (gnus-put-text-property + (- (point) 2) (1- (point)) 'face 'underline)) + ((eq previous ?_) + (gnus-put-text-property (- (point) 2) (point) 'invisible t) + (gnus-put-text-property + (point) (1+ (point)) 'face 'underline)))))))) (defun gnus-article-word-wrap () "Format too long lines." @@ -11147,6 +14104,7 @@ Provided for backwards compatibility." (save-excursion (set-buffer gnus-article-buffer) (let ((buffer-read-only nil)) + (widen) (goto-char (point-min)) (search-forward "\n\n" nil t) (end-of-line 1) @@ -11169,39 +14127,86 @@ Provided for backwards compatibility." (while (search-forward "\r" nil t) (replace-match "" t t))))) +(defun gnus-article-remove-trailing-blank-lines () + "Remove all trailing blank lines from the article." + (interactive) + (save-excursion + (set-buffer gnus-article-buffer) + (let ((buffer-read-only nil)) + (goto-char (point-max)) + (delete-region + (point) + (progn + (while (looking-at "^[ \t]*$") + (forward-line -1)) + (forward-line 1) + (point)))))) + (defun gnus-article-display-x-face (&optional force) "Look for an X-Face header and display it if present." (interactive (list 'force)) (save-excursion (set-buffer gnus-article-buffer) + ;; Delete the old process, if any. + (when (process-status "gnus-x-face") + (delete-process "gnus-x-face")) (let ((inhibit-point-motion-hooks t) (case-fold-search nil) from) (save-restriction + (nnheader-narrow-to-headers) + (setq from (message-fetch-field "from")) (goto-char (point-min)) - (search-forward "\n\n") - (narrow-to-region (point-min) (point)) - (goto-char (point-min)) - (setq from (mail-fetch-field "from")) - (if (not (and gnus-article-x-face-command - (or force - (not gnus-article-x-face-too-ugly) - (and gnus-article-x-face-too-ugly from - (not (string-match gnus-article-x-face-too-ugly - from)))) - (progn - (goto-char (point-min)) - (re-search-forward "^X-Face: " nil t)))) - nil + (when (and gnus-article-x-face-command + (or force + ;; Check whether this face is censored. + (not gnus-article-x-face-too-ugly) + (and gnus-article-x-face-too-ugly from + (not (string-match gnus-article-x-face-too-ugly + from)))) + ;; Has to be present. + (re-search-forward "^X-Face: " nil t)) + ;; We now have the area of the buffer where the X-Face is stored. (let ((beg (point)) (end (1- (re-search-forward "^\\($\\|[^ \t]\\)" nil t)))) + ;; We display the face. (if (symbolp gnus-article-x-face-command) - (and (or (fboundp gnus-article-x-face-command) - (error "%s is not a function" - gnus-article-x-face-command)) - (funcall gnus-article-x-face-command beg end)) - (call-process-region beg end "sh" nil 0 nil - "-c" gnus-article-x-face-command)))))))) + ;; The command is a lisp function, so we call it. + (if (gnus-functionp gnus-article-x-face-command) + (funcall gnus-article-x-face-command beg end) + (error "%s is not a function" gnus-article-x-face-command)) + ;; The command is a string, so we interpret the command + ;; as a, well, command, and fork it off. + (let ((process-connection-type nil)) + (process-kill-without-query + (start-process + "gnus-x-face" nil shell-file-name shell-command-switch + gnus-article-x-face-command)) + (process-send-region "gnus-x-face" beg end) + (process-send-eof "gnus-x-face"))))))))) + +(defalias 'gnus-headers-decode-quoted-printable 'gnus-decode-rfc1522) +(defun gnus-decode-rfc1522 () + "Hack to remove QP encoding from headers." + (let ((case-fold-search t) + (inhibit-point-motion-hooks t) + (buffer-read-only nil) + string) + (save-restriction + (narrow-to-region + (goto-char (point-min)) + (or (search-forward "\n\n" nil t) (point-max))) + + (while (re-search-forward + "=\\?iso-8859-1\\?q\\?\\([^?\t\n]*\\)\\?=" nil t) + (setq string (match-string 1)) + (narrow-to-region (match-beginning 0) (match-end 0)) + (delete-region (point-min) (point-max)) + (insert string) + (gnus-mime-decode-quoted-printable (goto-char (point-min)) (point-max)) + (subst-char-in-region (point-min) (point-max) ?_ ? ) + (widen) + (goto-char (point-min)))))) (defun gnus-article-de-quoted-unreadable (&optional force) "Do a naive translation of a quoted-printable-encoded article. @@ -11209,137 +14214,331 @@ This is in no way, shape or form meant as a replacement for real MIME processing, but is simply a stop-gap measure until MIME support is written. If FORCE, decode the article whether it is marked as quoted-printable -or not." +or not." (interactive (list 'force)) (save-excursion (set-buffer gnus-article-buffer) (let ((case-fold-search t) (buffer-read-only nil) (type (gnus-fetch-field "content-transfer-encoding"))) - (if (or force (and type (string-match "quoted-printable" type))) - (progn - (goto-char (point-min)) - (search-forward "\n\n" nil 'move) - (gnus-mime-decode-quoted-printable (point) (point-max))))))) + (gnus-decode-rfc1522) + (when (or force + (and type (string-match "quoted-printable" (downcase type)))) + (goto-char (point-min)) + (search-forward "\n\n" nil 'move) + (gnus-mime-decode-quoted-printable (point) (point-max)))))) (defun gnus-mime-decode-quoted-printable (from to) - ;; Decode quoted-printable from region between FROM and TO. + "Decode Quoted-Printable in the region between FROM and TO." + (interactive "r") + (goto-char from) + (while (search-forward "=" to t) + (cond ((eq (following-char) ?\n) + (delete-char -1) + (delete-char 1)) + ((looking-at "[0-9A-F][0-9A-F]") + (subst-char-in-region + (1- (point)) (point) ?= + (hexl-hex-string-to-integer + (buffer-substring (point) (+ 2 (point))))) + (delete-char 2)) + ((looking-at "=") + (delete-char 1)) + ((gnus-message 3 "Malformed MIME quoted-printable message"))))) + +(defun gnus-article-hide-pgp (&optional arg) + "Toggle hiding of any PGP headers and signatures in the current article. +If given a negative prefix, always show; if given a positive prefix, +always hide." + (interactive (gnus-hidden-arg)) + (unless (gnus-article-check-hidden-text 'pgp arg) + (save-excursion + (set-buffer gnus-article-buffer) + (let ((props (nconc (list 'gnus-type 'pgp) gnus-hidden-properties)) + buffer-read-only beg end) + (widen) + (goto-char (point-min)) + ;; Hide the "header". + (and (search-forward "\n-----BEGIN PGP SIGNED MESSAGE-----\n" nil t) + (gnus-hide-text (match-beginning 0) (match-end 0) props)) + (setq beg (point)) + ;; Hide the actual signature. + (and (search-forward "\n-----BEGIN PGP SIGNATURE-----\n" nil t) + (setq end (1+ (match-beginning 0))) + (gnus-hide-text + end + (if (search-forward "\n-----END PGP SIGNATURE-----\n" nil t) + (match-end 0) + ;; Perhaps we shouldn't hide to the end of the buffer + ;; if there is no end to the signature? + (point-max)) + props)) + ;; Hide "- " PGP quotation markers. + (when (and beg end) + (narrow-to-region beg end) + (goto-char (point-min)) + (while (re-search-forward "^- " nil t) + (gnus-hide-text (match-beginning 0) (match-end 0) props)) + (widen)))))) + +(defun gnus-article-hide-signature (&optional arg) + "Hide the signature in the current article. +If given a negative prefix, always show; if given a positive prefix, +always hide." + (interactive (gnus-hidden-arg)) + (unless (gnus-article-check-hidden-text 'signature arg) + (save-excursion + (set-buffer gnus-article-buffer) + (save-restriction + (let ((buffer-read-only nil)) + (when (gnus-narrow-to-signature) + (gnus-hide-text-type (point-min) (point-max) 'signature))))))) + +(defun gnus-article-strip-leading-blank-lines () + "Remove all blank lines from the beginning of the article." + (interactive) + (save-excursion + (set-buffer gnus-article-buffer) + (let (buffer-read-only) + (goto-char (point-min)) + (when (search-forward "\n\n" nil t) + (while (looking-at "[ \t]$") + (gnus-delete-line)))))) + +(defvar mime::preview/content-list) +(defvar mime::preview-content-info/point-min) +(defun gnus-narrow-to-signature () + "Narrow to the signature." + (widen) + (if (and (boundp 'mime::preview/content-list) + mime::preview/content-list) + (let ((pcinfo (car (last mime::preview/content-list)))) + (condition-case () + (narrow-to-region + (funcall (intern "mime::preview-content-info/point-min") pcinfo) + (point-max)) + (error nil)))) + (goto-char (point-max)) + (when (re-search-backward gnus-signature-separator nil t) + (forward-line 1) + (when (or (null gnus-signature-limit) + (and (numberp gnus-signature-limit) + (< (- (point-max) (point)) gnus-signature-limit)) + (and (gnus-functionp gnus-signature-limit) + (funcall gnus-signature-limit)) + (and (stringp gnus-signature-limit) + (not (re-search-forward gnus-signature-limit nil t)))) + (narrow-to-region (point) (point-max)) + t))) + +(defun gnus-hidden-arg () + "Return the current prefix arg as a number, or 0 if no prefix." + (list (if current-prefix-arg + (prefix-numeric-value current-prefix-arg) + 0))) + +(defun gnus-article-check-hidden-text (type arg) + "Return nil if hiding is necessary. +Arg can be nil or a number. Nil and positive means hide, negative +means show, 0 means toggle." + (save-excursion + (set-buffer gnus-article-buffer) + (let ((hide (gnus-article-hidden-text-p type))) + (cond + ((or (null arg) + (> arg 0)) + nil) + ((< arg 0) + (gnus-article-show-hidden-text type)) + (t + (if (eq hide 'hidden) + (gnus-article-show-hidden-text type) + nil)))))) + +(defun gnus-article-hidden-text-p (type) + "Say whether the current buffer contains hidden text of type TYPE." + (let ((pos (text-property-any (point-min) (point-max) 'gnus-type type))) + (when pos + (if (get-text-property pos 'invisible) + 'hidden + 'shown)))) + +(defun gnus-article-hide (&optional arg force) + "Hide all the gruft in the current article. +This means that PGP stuff, signatures, cited text and (some) +headers will be hidden. +If given a prefix, show the hidden text instead." + (interactive (list current-prefix-arg 'force)) + (gnus-article-hide-headers arg) + (gnus-article-hide-pgp arg) + (gnus-article-hide-citation-maybe arg force) + (gnus-article-hide-signature arg)) + +(defun gnus-article-show-hidden-text (type &optional hide) + "Show all hidden text of type TYPE. +If HIDE, hide the text instead." (save-excursion - (goto-char from) - (while (search-forward "=" to t) - (cond ((eq (following-char) ?\n) - (delete-char -1) - (delete-char 1)) - ((looking-at "[0-9A-F][0-9A-F]") - (delete-char -1) - (insert (hexl-hex-string-to-integer - (buffer-substring (point) (+ 2 (point))))) - (delete-char 2)) - ((looking-at "=") - (delete-char 1)) - ((gnus-message 3 "Malformed MIME quoted-printable message")))))) + (set-buffer gnus-article-buffer) + (let ((buffer-read-only nil) + (inhibit-point-motion-hooks t) + (beg (point-min))) + (while (gnus-goto-char (text-property-any + beg (point-max) 'gnus-type type)) + (setq beg (point)) + (forward-char) + (if hide + (gnus-hide-text beg (point) gnus-hidden-properties) + (gnus-unhide-text beg (point))) + (setq beg (point))) + t))) (defvar gnus-article-time-units - (list (cons 'year (* 365.25 24 60 60)) - (cons 'week (* 7 24 60 60)) - (cons 'day (* 24 60 60)) - (cons 'hour (* 60 60)) - (cons 'minute 60) - (cons 'second 1))) - -(defun gnus-article-date-ut (&optional type) + `((year . ,(* 365.25 24 60 60)) + (week . ,(* 7 24 60 60)) + (day . ,(* 24 60 60)) + (hour . ,(* 60 60)) + (minute . 60) + (second . 1)) + "Mapping from time units to seconds.") + +(defun gnus-article-date-ut (&optional type highlight) "Convert DATE date to universal time in the current article. If TYPE is `local', convert to local time; if it is `lapsed', output how much time has lapsed since DATE." - (interactive (list 'ut)) - (let ((date (mail-header-date (or gnus-current-headers - (gnus-get-header-by-number - (gnus-summary-article-number))""))) - (date-regexp "^Date: \\|^X-Sent: ")) - (if (or (not date) - (string= date "")) - () + (interactive (list 'ut t)) + (let* ((header (or gnus-current-headers + (gnus-summary-article-header) "")) + (date (and (vectorp header) (mail-header-date header))) + (date-regexp "^Date: \\|^X-Sent: ") + (now (current-time)) + (inhibit-point-motion-hooks t) + bface eface) + (when (and date (not (string= date ""))) (save-excursion (set-buffer gnus-article-buffer) - (let ((buffer-read-only nil)) - (goto-char (point-min)) - (if (and (re-search-forward date-regexp nil t) - (progn - (beginning-of-line) - (looking-at date-regexp))) - (delete-region (gnus-point-at-bol) - (progn (end-of-line) (1+ (point)))) - (goto-char (point-min)) - (goto-char (- (search-forward "\n\n") 2))) - (insert - (cond - ((eq type 'local) - (concat "Date: " (condition-case () - (timezone-make-date-arpa-standard date) - (error date)) - "\n")) - ((eq type 'ut) - (concat "Date: " - (condition-case () - (timezone-make-date-arpa-standard date nil "UT") + (save-restriction + (nnheader-narrow-to-headers) + (let ((buffer-read-only nil)) + ;; Delete any old Date headers. + (if (re-search-forward date-regexp nil t) + (progn + (setq bface (get-text-property (gnus-point-at-bol) 'face) + eface (get-text-property (1- (gnus-point-at-eol)) + 'face)) + (message-remove-header date-regexp t) + (beginning-of-line)) + (goto-char (point-max))) + (insert (gnus-make-date-line date type)) + ;; Do highlighting. + (forward-line -1) + (when (and (gnus-visual-p 'article-highlight 'highlight) + (looking-at "\\([^:]+\\): *\\(.*\\)$")) + (gnus-put-text-property (match-beginning 1) (match-end 1) + 'face bface) + (gnus-put-text-property (match-beginning 2) (match-end 2) + 'face eface)))))))) + +(defun gnus-make-date-line (date type) + "Return a DATE line of TYPE." + (cond + ;; Convert to the local timezone. We have to slap a + ;; `condition-case' round the calls to the timezone + ;; functions since they aren't particularly resistant to + ;; buggy dates. + ((eq type 'local) + (concat "Date: " (condition-case () + (timezone-make-date-arpa-standard date) (error date)) - "\n")) - ((eq type 'lapsed) - ;; If the date is seriously mangled, the timezone - ;; functions are liable to bug out, so we condition-case - ;; the entire thing. We call (current-time) once, rather than - ;; letting current-time-string and current-time-zone default to - ;; it, because that avoids a rare race condition when the time - ;; zone changes between those two calls. - (let* ((now (current-time)) - (real-sec (condition-case () - (- (gnus-seconds-since-epoch - (timezone-make-date-arpa-standard - (current-time-string now) - (current-time-zone now) "UT")) - (gnus-seconds-since-epoch - (timezone-make-date-arpa-standard - date nil "UT"))) - (error 0))) - (sec (abs real-sec)) - num prev) - (if (zerop sec) - "X-Sent: Now\n" - (concat - "X-Sent: " - (mapconcat - (lambda (unit) - (if (zerop (setq num (ffloor (/ sec (cdr unit))))) - "" - (setq sec (- sec (* num (cdr unit)))) - (prog1 - (concat (if prev ", " "") (int-to-string - (floor num)) - " " (symbol-name (car unit)) - (if (> num 1) "s" "")) - (setq prev t)))) - gnus-article-time-units "") - (if (> real-sec 0) - " ago\n" - " in the future\n"))))) - (t - (error "Unknown conversion type: %s" type))))))))) + "\n")) + ;; Convert to Universal Time. + ((eq type 'ut) + (concat "Date: " + (condition-case () + (timezone-make-date-arpa-standard date nil "UT") + (error date)) + "\n")) + ;; Get the original date from the article. + ((eq type 'original) + (concat "Date: " date "\n")) + ;; Do an X-Sent lapsed format. + ((eq type 'lapsed) + ;; If the date is seriously mangled, the timezone + ;; functions are liable to bug out, so we condition-case + ;; the entire thing. + (let* ((now (current-time)) + (real-time + (condition-case () + (gnus-time-minus + (gnus-encode-date + (timezone-make-date-arpa-standard + (current-time-string now) + (current-time-zone now) "UT")) + (gnus-encode-date + (timezone-make-date-arpa-standard + date nil "UT"))) + (error '(0 0)))) + (real-sec (+ (* (float (car real-time)) 65536) + (cadr real-time))) + (sec (abs real-sec)) + num prev) + (cond + ((equal real-time '(0 0)) + "X-Sent: Unknown\n") + ((zerop sec) + "X-Sent: Now\n") + (t + (concat + "X-Sent: " + ;; This is a bit convoluted, but basically we go + ;; through the time units for years, weeks, etc, + ;; and divide things to see whether that results + ;; in positive answers. + (mapconcat + (lambda (unit) + (if (zerop (setq num (ffloor (/ sec (cdr unit))))) + ;; The (remaining) seconds are too few to + ;; be divided into this time unit. + "" + ;; It's big enough, so we output it. + (setq sec (- sec (* num (cdr unit)))) + (prog1 + (concat (if prev ", " "") (int-to-string + (floor num)) + " " (symbol-name (car unit)) + (if (> num 1) "s" "")) + (setq prev t)))) + gnus-article-time-units "") + ;; If dates are odd, then it might appear like the + ;; article was sent in the future. + (if (> real-sec 0) + " ago\n" + " in the future\n")))))) + (t + (error "Unknown conversion type: %s" type)))) -(defun gnus-article-date-local () +(defun gnus-article-date-local (&optional highlight) "Convert the current article date to the local timezone." - (interactive) - (gnus-article-date-ut 'local)) + (interactive (list t)) + (gnus-article-date-ut 'local highlight)) + +(defun gnus-article-date-original (&optional highlight) + "Convert the current article date to what it was originally. +This is only useful if you have used some other date conversion +function and want to see what the date was before converting." + (interactive (list t)) + (gnus-article-date-ut 'original highlight)) -(defun gnus-article-date-lapsed () +(defun gnus-article-date-lapsed (&optional highlight) "Convert the current article date to time lapsed since it was sent." - (interactive) - (gnus-article-date-ut 'lapsed)) + (interactive (list t)) + (gnus-article-date-ut 'lapsed highlight)) (defun gnus-article-maybe-highlight () "Do some article highlighting if `gnus-visual' is non-nil." - (if gnus-visual (gnus-article-highlight-some))) + (if (gnus-visual-p 'article-highlight 'highlight) + (gnus-article-highlight-some))) -;; Article savers. +;;; Article savers. (defun gnus-output-to-rmail (file-name) "Append the current article to an Rmail file named FILE-NAME." @@ -11394,20 +14593,14 @@ how much time has lapsed since DATE." (defun gnus-output-to-file (file-name) "Append the current article to a file named FILE-NAME." - (setq file-name (expand-file-name file-name)) - (let ((artbuf (current-buffer)) - (tmpbuf (get-buffer-create " *Gnus-output*"))) - (save-excursion - (set-buffer tmpbuf) - (buffer-disable-undo (current-buffer)) - (erase-buffer) + (let ((artbuf (current-buffer))) + (nnheader-temp-write nil (insert-buffer-substring artbuf) ;; Append newline at end of the buffer as separator, and then ;; save it to file. (goto-char (point-max)) (insert "\n") - (append-to-file (point-min) (point-max) file-name)) - (kill-buffer tmpbuf))) + (append-to-file (point-min) (point-max) file-name)))) (defun gnus-convert-article-to-rmail () "Convert article in current buffer to Rmail message format." @@ -11422,66 +14615,59 @@ how much time has lapsed since DATE." (insert "\^_"))) (defun gnus-narrow-to-page (&optional arg) - "Make text outside current page invisible except for page delimiter. -A numeric arg specifies to move forward or backward by that many pages, -thus showing a page other than the one point was originally in." + "Narrow the article buffer to a page. +If given a numerical ARG, move forward ARG pages." (interactive "P") (setq arg (if arg (prefix-numeric-value arg) 0)) (save-excursion - (forward-page -1) ;Beginning of current page. + (set-buffer gnus-article-buffer) + (goto-char (point-min)) (widen) - (if (> arg 0) - (forward-page arg) - (if (< arg 0) - (forward-page (1- arg)))) - ;; Find the end of the page. - (forward-page) - ;; If we stopped due to end of buffer, stay there. - ;; If we stopped after a page delimiter, put end of restriction - ;; at the beginning of that line. - ;; These are commented out. - ;; (if (save-excursion (beginning-of-line) - ;; (looking-at page-delimiter)) - ;; (beginning-of-line)) - (narrow-to-region (point) - (progn - ;; Find the top of the page. - (forward-page -1) - ;; If we found beginning of buffer, stay there. - ;; If extra text follows page delimiter on same line, - ;; include it. - ;; Otherwise, show text starting with following line. - (if (and (eolp) (not (bobp))) - (forward-line 1)) - (point))))) - -(defun gnus-gmt-to-local () - "Rewrite Date header described in GMT to local in current buffer. -Intended to be used with gnus-article-prepare-hook." - (save-excursion - (save-restriction - (widen) - (goto-char (point-min)) - (narrow-to-region (point-min) - (progn (search-forward "\n\n" nil 'move) (point))) - (goto-char (point-min)) - (if (re-search-forward "^Date:[ \t]\\(.*\\)$" nil t) - (let ((buffer-read-only nil) - (date (buffer-substring-no-properties - (match-beginning 1) (match-end 1)))) - (delete-region (match-beginning 1) (match-end 1)) - (insert - (timezone-make-date-arpa-standard - date))))))) - + (when (gnus-visual-p 'page-marker) + (let ((buffer-read-only nil)) + (gnus-remove-text-with-property 'gnus-prev) + (gnus-remove-text-with-property 'gnus-next))) + (when + (cond ((< arg 0) + (re-search-backward page-delimiter nil 'move (1+ (abs arg)))) + ((> arg 0) + (re-search-forward page-delimiter nil 'move arg))) + (goto-char (match-end 0))) + (narrow-to-region + (point) + (if (re-search-forward page-delimiter nil 'move) + (match-beginning 0) + (point))) + (when (and (gnus-visual-p 'page-marker) + (not (= (point-min) 1))) + (save-excursion + (goto-char (point-min)) + (gnus-insert-prev-page-button))) + (when (and (gnus-visual-p 'page-marker) + (not (= (1- (point-max)) (buffer-size)))) + (save-excursion + (goto-char (point-max)) + (gnus-insert-next-page-button))))) ;; Article mode commands +(defun gnus-article-goto-next-page () + "Show the next page of the article." + (interactive) + (when (gnus-article-next-page) + (gnus-article-read-summary-keys nil (gnus-character-to-event ?n)))) + +(defun gnus-article-goto-prev-page () + "Show the next page of the article." + (interactive) + (if (bobp) (gnus-article-read-summary-keys nil (gnus-character-to-event ?n)) + (gnus-article-prev-page nil))) + (defun gnus-article-next-page (&optional lines) - "Show next page of current article. -If end of article, return non-nil. Otherwise return nil. + "Show the next page of the current article. +If end of article, return non-nil. Otherwise return nil. Argument LINES specifies lines to be scrolled up." - (interactive "P") + (interactive "p") (move-to-window-line -1) ;; Fixed by enami@ptgd.sony.co.jp (enami tsugutomo) (if (save-excursion @@ -11502,12 +14688,13 @@ Argument LINES specifies lines to be scrolled up." (end-of-buffer ;; Long lines may cause an end-of-buffer error. (goto-char (point-max)))) + (move-to-window-line 0) nil)) (defun gnus-article-prev-page (&optional lines) "Show previous page of current article. Argument LINES specifies lines to be scrolled down." - (interactive "P") + (interactive "p") (move-to-window-line 0) (if (and gnus-break-pages (bobp) @@ -11516,18 +14703,24 @@ Argument LINES specifies lines to be scrolled down." (gnus-narrow-to-page -1) ;Go to previous page. (goto-char (point-max)) (recenter -1)) - (scroll-down lines))) + (prog1 + (condition-case () + (scroll-down lines) + (error nil)) + (move-to-window-line 0)))) (defun gnus-article-refer-article () "Read article specified by message-id around point." (interactive) - (search-forward ">" nil t) ;Move point to end of "<....>". - (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t) - (let ((message-id - (buffer-substring (match-beginning 1) (match-end 1)))) - (set-buffer gnus-summary-buffer) - (gnus-summary-refer-article message-id)) - (error "No references around point"))) + (let ((point (point))) + (search-forward ">" nil t) ;Move point to end of "<....>". + (if (re-search-backward "\\(<[^<> \t\n]+>\\)" nil t) + (let ((message-id (match-string 1))) + (goto-char point) + (set-buffer gnus-summary-buffer) + (gnus-summary-refer-article message-id)) + (goto-char (point)) + (error "No references around point")))) (defun gnus-article-show-summary () "Reconfigure windows to show summary buffer." @@ -11539,7 +14732,7 @@ Argument LINES specifies lines to be scrolled down." "Describe article mode commands briefly." (interactive) (gnus-message 6 - (substitute-command-keys "\\\\[gnus-article-next-page]:Next page \\[gnus-article-prev-page]:Prev page \\[gnus-article-show-summary]:Show summary \\[gnus-info-find-node]:Run Info \\[gnus-article-describe-briefly]:This help"))) + (substitute-command-keys "\\\\[gnus-article-next-page]:Next page \\[gnus-article-prev-page]:Prev page \\[gnus-article-show-summary]:Show summary \\[gnus-info-find-node]:Run Info \\[gnus-article-describe-briefly]:This help"))) (defun gnus-article-summary-command () "Execute the last keystroke in the summary buffer." @@ -11562,8 +14755,47 @@ Argument LINES specifies lines to be scrolled down." (setq func (lookup-key (current-local-map) (this-command-keys))) (call-interactively func))) +(defun gnus-article-read-summary-keys (&optional arg key not-restore-window) + "Read a summary buffer key sequence and execute it from the article buffer." + (interactive "P") + (let ((nosaves + '("q" "Q" "c" "r" "R" "\C-c\C-f" "m" "a" "f" "F" + "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP" + "=" "^" "\M-^" "|")) + keys) + (save-excursion + (set-buffer gnus-summary-buffer) + (push (or key last-command-event) unread-command-events) + (setq keys (read-key-sequence nil))) + (message "") + + (if (member keys nosaves) + (let (func) + (pop-to-buffer gnus-summary-buffer 'norecord) + (if (setq func (lookup-key (current-local-map) keys)) + (call-interactively func) + (ding))) + (let ((obuf (current-buffer)) + (owin (current-window-configuration)) + (opoint (point)) + func in-buffer) + (if not-restore-window + (pop-to-buffer gnus-summary-buffer 'norecord) + (switch-to-buffer gnus-summary-buffer 'norecord)) + (setq in-buffer (current-buffer)) + (if (setq func (lookup-key (current-local-map) keys)) + (call-interactively func) + (ding)) + (when (eq in-buffer (current-buffer)) + (set-buffer obuf) + (unless not-restore-window + (set-window-configuration owin)) + (set-window-point (get-buffer-window (current-buffer)) opoint)))))) + -;; Basic ideas by emv@math.lsa.umich.edu (Edward Vielmetti) +;;; +;;; Kill file handling. +;;; ;;;###autoload (defalias 'gnus-batch-kill 'gnus-batch-score) @@ -11572,7 +14804,7 @@ Argument LINES specifies lines to be scrolled down." "Run batched scoring. Usage: emacs -batch -l gnus -f gnus-batch-score ... Newsgroups is a list of strings in Bnews format. If you want to score -the comp hierarchy, you'd say \"comp.all\". If you would not like to +the comp hierarchy, you'd say \"comp.all\". If you would not like to score the alt hierarchy, you'd say \"!alt.all\"." (interactive) (let* ((yes-and-no @@ -11595,7 +14827,7 @@ score the alt hierarchy, you'd say \"!alt.all\"." ;; Apply kills to specified newsgroups in command line arguments. (setq newsrc (cdr gnus-newsrc-alist)) (while newsrc - (setq group (car (car newsrc))) + (setq group (caar newsrc)) (setq entry (gnus-gethash group gnus-newsrc-hashtb)) (if (and (<= (nth 1 (car newsrc)) gnus-level-subscribed) (and (car entry) @@ -11604,7 +14836,7 @@ score the alt hierarchy, you'd say \"!alt.all\"." (if yes (string-match yes group) t) (or (null no) (not (string-match no group)))) (progn - (gnus-summary-read-group group nil t) + (gnus-summary-read-group group nil t nil t) (and (eq (current-buffer) (get-buffer gnus-summary-buffer)) (gnus-summary-exit)))) (setq newsrc (cdr newsrc))) @@ -11621,13 +14853,12 @@ Returns the number of articles marked as read." 0)) (defun gnus-kill-save-kill-buffer () - (save-excursion - (let ((file (gnus-newsgroup-kill-file gnus-newsgroup-name))) - (if (get-file-buffer file) - (progn - (set-buffer (get-file-buffer file)) - (and (buffer-modified-p) (save-buffer)) - (kill-buffer (current-buffer))))))) + (let ((file (gnus-newsgroup-kill-file gnus-newsgroup-name))) + (when (get-file-buffer file) + (save-excursion + (set-buffer (get-file-buffer file)) + (and (buffer-modified-p) (save-buffer)) + (kill-buffer (current-buffer)))))) (defvar gnus-kill-file-name "KILL" "Suffix of the kill files.") @@ -11635,21 +14866,22 @@ Returns the number of articles marked as read." (defun gnus-newsgroup-kill-file (newsgroup) "Return the name of a kill file name for NEWSGROUP. If NEWSGROUP is nil, return the global kill file name instead." - (cond ((or (null newsgroup) - (string-equal newsgroup "")) - ;; The global KILL file is placed at top of the directory. - (expand-file-name gnus-kill-file-name - (or gnus-kill-files-directory "~/News"))) - ((gnus-use-long-file-name 'not-kill) - ;; Append ".KILL" to newsgroup name. - (expand-file-name (concat (gnus-newsgroup-savable-name newsgroup) - "." gnus-kill-file-name) - (or gnus-kill-files-directory "~/News"))) - (t - ;; Place "KILL" under the hierarchical directory. - (expand-file-name (concat (gnus-newsgroup-directory-form newsgroup) - "/" gnus-kill-file-name) - (or gnus-kill-files-directory "~/News"))))) + (cond + ;; The global KILL file is placed at top of the directory. + ((or (null newsgroup) + (string-equal newsgroup "")) + (expand-file-name gnus-kill-file-name + gnus-kill-files-directory)) + ;; Append ".KILL" to newsgroup name. + ((gnus-use-long-file-name 'not-kill) + (expand-file-name (concat (gnus-newsgroup-savable-name newsgroup) + "." gnus-kill-file-name) + gnus-kill-files-directory)) + ;; Place "KILL" under the hierarchical directory. + (t + (expand-file-name (concat (gnus-newsgroup-directory-form newsgroup) + "/" gnus-kill-file-name) + gnus-kill-files-directory)))) ;;; @@ -11660,9 +14892,16 @@ If NEWSGROUP is nil, return the global kill file name instead." (defvar gnus-dribble-eval-file nil) (defun gnus-dribble-file-name () - (concat gnus-current-startup-file "-dribble")) + "Return the dribble file for the current .newsrc." + (concat + (if gnus-dribble-directory + (concat (file-name-as-directory gnus-dribble-directory) + (file-name-nondirectory gnus-current-startup-file)) + gnus-current-startup-file) + "-dribble")) (defun gnus-dribble-enter (string) + "Enter STRING into the dribble buffer." (if (and (not gnus-dribble-ignore) gnus-dribble-buffer (buffer-name gnus-dribble-buffer)) @@ -11673,33 +14912,42 @@ If NEWSGROUP is nil, return the global kill file name instead." (set-buffer obuf)))) (defun gnus-dribble-read-file () + "Read the dribble file from disk." (let ((dribble-file (gnus-dribble-file-name))) - (save-excursion - (set-buffer (setq gnus-dribble-buffer - (get-buffer-create + (save-excursion + (set-buffer (setq gnus-dribble-buffer + (get-buffer-create (file-name-nondirectory dribble-file)))) (gnus-add-current-to-buffer-list) (erase-buffer) - (set-visited-file-name dribble-file) + (setq buffer-file-name dribble-file) + (auto-save-mode t) (buffer-disable-undo (current-buffer)) (bury-buffer (current-buffer)) (set-buffer-modified-p nil) (let ((auto (make-auto-save-file-name)) - (gnus-dribble-ignore t)) - (if (or (file-exists-p auto) (file-exists-p dribble-file)) - (progn - (if (file-newer-than-file-p auto dribble-file) - (setq dribble-file auto)) - (insert-file-contents dribble-file) - (if (not (zerop (buffer-size))) - (set-buffer-modified-p t)) - (if (gnus-y-or-n-p - "Auto-save file exists. Do you want to read it? ") - (setq gnus-dribble-eval-file t)))))))) + (gnus-dribble-ignore t) + modes) + (when (or (file-exists-p auto) (file-exists-p dribble-file)) + ;; Load whichever file is newest -- the auto save file + ;; or the "real" file. + (if (file-newer-than-file-p auto dribble-file) + (insert-file-contents auto) + (insert-file-contents dribble-file)) + (unless (zerop (buffer-size)) + (set-buffer-modified-p t)) + ;; Set the file modes to reflect the .newsrc file modes. + (save-buffer) + (when (and (file-exists-p gnus-current-startup-file) + (setq modes (file-modes gnus-current-startup-file))) + (set-file-modes dribble-file modes)) + ;; Possibly eval the file later. + (when (gnus-y-or-n-p + "Auto-save file exists. Do you want to read it? ") + (setq gnus-dribble-eval-file t))))))) (defun gnus-dribble-eval-file () - (if (not gnus-dribble-eval-file) - () + (when gnus-dribble-eval-file (setq gnus-dribble-eval-file nil) (save-excursion (let ((gnus-dribble-ignore t)) @@ -11707,33 +14955,33 @@ If NEWSGROUP is nil, return the global kill file name instead." (eval-buffer (current-buffer)))))) (defun gnus-dribble-delete-file () - (if (file-exists-p (gnus-dribble-file-name)) - (delete-file (gnus-dribble-file-name))) - (if gnus-dribble-buffer - (save-excursion - (set-buffer gnus-dribble-buffer) - (let ((auto (make-auto-save-file-name))) - (if (file-exists-p auto) - (delete-file auto)) - (erase-buffer) - (set-buffer-modified-p nil))))) + (when (file-exists-p (gnus-dribble-file-name)) + (delete-file (gnus-dribble-file-name))) + (when gnus-dribble-buffer + (save-excursion + (set-buffer gnus-dribble-buffer) + (let ((auto (make-auto-save-file-name))) + (if (file-exists-p auto) + (delete-file auto)) + (erase-buffer) + (set-buffer-modified-p nil))))) (defun gnus-dribble-save () - (if (and gnus-dribble-buffer - (buffer-name gnus-dribble-buffer)) - (save-excursion - (set-buffer gnus-dribble-buffer) - (save-buffer)))) + (when (and gnus-dribble-buffer + (buffer-name gnus-dribble-buffer)) + (save-excursion + (set-buffer gnus-dribble-buffer) + (save-buffer)))) (defun gnus-dribble-clear () - (save-excursion - (if (gnus-buffer-exists-p gnus-dribble-buffer) - (progn - (set-buffer gnus-dribble-buffer) - (erase-buffer) - (set-buffer-modified-p nil) - (setq buffer-saved-size (buffer-size)))))) + (when (gnus-buffer-exists-p gnus-dribble-buffer) + (save-excursion + (set-buffer gnus-dribble-buffer) + (erase-buffer) + (set-buffer-modified-p nil) + (setq buffer-saved-size (buffer-size))))) + ;;; ;;; Server Communication ;;; @@ -11757,7 +15005,7 @@ If CONFIRM is non-nil, the user will be asked for an NNTP server." gnus-secondary-servers)) nil nil gnus-nntp-server)))) - (if (and gnus-nntp-server + (if (and gnus-nntp-server (stringp gnus-nntp-server) (not (string= gnus-nntp-server ""))) (setq gnus-select-method @@ -11765,8 +15013,8 @@ If CONFIRM is non-nil, the user will be asked for an NNTP server." (string= gnus-nntp-server "::")) (list 'nnspool (system-name))) ((string-match "^:" gnus-nntp-server) - (list 'nnmh gnus-nntp-server - (list 'nnmh-directory + (list 'nnmh gnus-nntp-server + (list 'nnmh-directory (file-name-as-directory (expand-file-name (concat "~/" (substring @@ -11786,190 +15034,279 @@ If CONFIRM is non-nil, the user will be asked for an NNTP server." (require 'nntp))) (setq gnus-current-select-method gnus-select-method) (run-hooks 'gnus-open-server-hook) - (or + (or ;; gnus-open-server-hook might have opened it - (gnus-server-opened gnus-select-method) + (gnus-server-opened gnus-select-method) (gnus-open-server gnus-select-method) (gnus-y-or-n-p (format - "%s open error: '%s'. Continue? " - (nth 1 gnus-select-method) + "%s (%s) open error: '%s'. Continue? " + (car gnus-select-method) (cadr gnus-select-method) (gnus-status-message gnus-select-method))) - (progn - (gnus-message 1 "Couldn't open server on %s" - (nth 1 gnus-select-method)) - (ding) - nil))))) - -(defun gnus-check-server (&optional method) - "If the news server is down, start it up again." - (let ((method (if method method gnus-select-method))) - (and (stringp method) - (setq method (gnus-server-to-method method))) + (gnus-error 1 "Couldn't open server on %s" + (nth 1 gnus-select-method)))))) + +(defun gnus-check-group (group) + "Try to make sure that the server where GROUP exists is alive." + (let ((method (gnus-find-method-for-group group))) + (or (gnus-server-opened method) + (gnus-open-server method)))) + +(defun gnus-check-server (&optional method silent) + "Check whether the connection to METHOD is down. +If METHOD is nil, use `gnus-select-method'. +If it is down, start it up (again)." + (let ((method (or method gnus-select-method))) + ;; Transform virtual server names into select methods. + (when (stringp method) + (setq method (gnus-server-to-method method))) (if (gnus-server-opened method) - ;; Stream is already opened. + ;; The stream is already opened. t - ;; Open server. - (gnus-message 5 "Opening server %s on %s..." (car method) (nth 1 method)) + ;; Open the server. + (unless silent + (gnus-message 5 "Opening %s server%s..." (car method) + (if (equal (nth 1 method) "") "" + (format " on %s" (nth 1 method))))) (run-hooks 'gnus-open-server-hook) (prog1 (gnus-open-server method) - (message ""))))) - -(defun gnus-nntp-message (&optional message) - "Check the status of the NNTP server. -If the status of the server is clear and MESSAGE is non-nil, MESSAGE -is returned insted of the status string." - (let ((status (gnus-status-message (gnus-find-method-for-group - gnus-newsgroup-name))) - (message (or message ""))) - (if (and (stringp status) (> (length status) 0)) - status message))) - -(defun gnus-get-function (method function) - (and (stringp method) - (setq method (gnus-server-to-method method))) + (unless silent + (message "")))))) + +(defun gnus-get-function (method function &optional noerror) + "Return a function symbol based on METHOD and FUNCTION." + ;; Translate server names into methods. + (unless method + (error "Attempted use of a nil select method")) + (when (stringp method) + (setq method (gnus-server-to-method method))) (let ((func (intern (format "%s-%s" (car method) function)))) - (if (not (fboundp func)) - (progn - (require (car method)) - (if (not (fboundp func)) - (error "No such function: %s" func)))) + ;; If the functions isn't bound, we require the backend in + ;; question. + (unless (fboundp func) + (require (car method)) + (when (and (not (fboundp func)) + (not noerror)) + ;; This backend doesn't implement this function. + (error "No such function: %s" func))) func)) + +;;; ;;; Interface functions to the backends. +;;; (defun gnus-open-server (method) - (funcall (gnus-get-function method 'open-server) - (nth 1 method) (nthcdr 2 method))) + "Open a connection to METHOD." + (when (stringp method) + (setq method (gnus-server-to-method method))) + (let ((elem (assoc method gnus-opened-servers))) + ;; If this method was previously denied, we just return nil. + (if (eq (nth 1 elem) 'denied) + (progn + (gnus-message 1 "Denied server") + nil) + ;; Open the server. + (let ((result + (funcall (gnus-get-function method 'open-server) + (nth 1 method) (nthcdr 2 method)))) + ;; If this hasn't been opened before, we add it to the list. + (unless elem + (setq elem (list method nil) + gnus-opened-servers (cons elem gnus-opened-servers))) + ;; Set the status of this server. + (setcar (cdr elem) (if result 'ok 'denied)) + ;; Return the result from the "open" call. + result)))) (defun gnus-close-server (method) + "Close the connection to METHOD." + (when (stringp method) + (setq method (gnus-server-to-method method))) (funcall (gnus-get-function method 'close-server) (nth 1 method))) (defun gnus-request-list (method) + "Request the active file from METHOD." + (when (stringp method) + (setq method (gnus-server-to-method method))) (funcall (gnus-get-function method 'request-list) (nth 1 method))) (defun gnus-request-list-newsgroups (method) + "Request the newsgroups file from METHOD." + (when (stringp method) + (setq method (gnus-server-to-method method))) (funcall (gnus-get-function method 'request-list-newsgroups) (nth 1 method))) (defun gnus-request-newgroups (date method) - (funcall (gnus-get-function method 'request-newgroups) + "Request all new groups since DATE from METHOD." + (when (stringp method) + (setq method (gnus-server-to-method method))) + (funcall (gnus-get-function method 'request-newgroups) date (nth 1 method))) (defun gnus-server-opened (method) + "Check whether a connection to METHOD has been opened." + (when (stringp method) + (setq method (gnus-server-to-method method))) (funcall (gnus-get-function method 'server-opened) (nth 1 method))) (defun gnus-status-message (method) + "Return the status message from METHOD. +If METHOD is a string, it is interpreted as a group name. The method +this group uses will be queried." (let ((method (if (stringp method) (gnus-find-method-for-group method) method))) (funcall (gnus-get-function method 'status-message) (nth 1 method)))) -(defun gnus-request-group (group &optional dont-check) - (let ((method (gnus-find-method-for-group group))) - (funcall (gnus-get-function method 'request-group) +(defun gnus-request-group (group &optional dont-check method) + "Request GROUP. If DONT-CHECK, no information is required." + (let ((method (or method (gnus-find-method-for-group group)))) + (when (stringp method) + (setq method (gnus-server-to-method method))) + (funcall (gnus-get-function method 'request-group) (gnus-group-real-name group) (nth 1 method) dont-check))) (defun gnus-request-asynchronous (group &optional articles) + "Request that GROUP behave asynchronously. +ARTICLES is the `data' of the group." (let ((method (gnus-find-method-for-group group))) - (funcall (gnus-get-function method 'request-asynchronous) + (funcall (gnus-get-function method 'request-asynchronous) (gnus-group-real-name group) (nth 1 method) articles))) (defun gnus-list-active-group (group) + "Request active information on GROUP." (let ((method (gnus-find-method-for-group group)) (func 'list-active-group)) - (and (gnus-check-backend-function func group) - (funcall (gnus-get-function method func) - (gnus-group-real-name group) (nth 1 method))))) + (when (gnus-check-backend-function func group) + (funcall (gnus-get-function method func) + (gnus-group-real-name group) (nth 1 method))))) (defun gnus-request-group-description (group) + "Request a description of GROUP." (let ((method (gnus-find-method-for-group group)) (func 'request-group-description)) - (and (gnus-check-backend-function func group) - (funcall (gnus-get-function method func) - (gnus-group-real-name group) (nth 1 method))))) + (when (gnus-check-backend-function func group) + (funcall (gnus-get-function method func) + (gnus-group-real-name group) (nth 1 method))))) (defun gnus-close-group (group) + "Request the GROUP be closed." (let ((method (gnus-find-method-for-group group))) - (funcall (gnus-get-function method 'close-group) + (funcall (gnus-get-function method 'close-group) (gnus-group-real-name group) (nth 1 method)))) -(defun gnus-retrieve-headers (articles group) +(defun gnus-retrieve-headers (articles group &optional fetch-old) + "Request headers for ARTICLES in GROUP. +If FETCH-OLD, retrieve all headers (or some subset thereof) in the group." (let ((method (gnus-find-method-for-group group))) (if (and gnus-use-cache (numberp (car articles))) - (gnus-cache-retrieve-headers articles group) - (funcall (gnus-get-function method 'retrieve-headers) - articles (gnus-group-real-name group) (nth 1 method))))) + (gnus-cache-retrieve-headers articles group fetch-old) + (funcall (gnus-get-function method 'retrieve-headers) + articles (gnus-group-real-name group) (nth 1 method) + fetch-old)))) (defun gnus-retrieve-groups (groups method) + "Request active information on GROUPS from METHOD." + (when (stringp method) + (setq method (gnus-server-to-method method))) (funcall (gnus-get-function method 'retrieve-groups) groups (nth 1 method))) +(defun gnus-request-type (group &optional article) + "Return the type (`post' or `mail') of GROUP (and ARTICLE)." + (let ((method (gnus-find-method-for-group group))) + (if (not (gnus-check-backend-function 'request-type (car method))) + 'unknown + (funcall (gnus-get-function method 'request-type) + (gnus-group-real-name group) article)))) + +(defun gnus-request-update-mark (group article mark) + "Return the type (`post' or `mail') of GROUP (and ARTICLE)." + (let ((method (gnus-find-method-for-group group))) + (if (not (gnus-check-backend-function 'request-update-mark (car method))) + mark + (funcall (gnus-get-function method 'request-update-mark) + (gnus-group-real-name group) article mark)))) + (defun gnus-request-article (article group &optional buffer) + "Request the ARTICLE in GROUP. +ARTICLE can either be an article number or an article Message-ID. +If BUFFER, insert the article in that group." (let ((method (gnus-find-method-for-group group))) - (funcall (gnus-get-function method 'request-article) + (funcall (gnus-get-function method 'request-article) article (gnus-group-real-name group) (nth 1 method) buffer))) (defun gnus-request-head (article group) - (let ((method (gnus-find-method-for-group group))) - (funcall (gnus-get-function method 'request-head) - article (gnus-group-real-name group) (nth 1 method)))) + "Request the head of ARTICLE in GROUP." + (let* ((method (gnus-find-method-for-group group)) + (head (gnus-get-function method 'request-head t))) + (if (fboundp head) + (funcall head article (gnus-group-real-name group) (nth 1 method)) + (let ((res (gnus-request-article article group))) + (when res + (save-excursion + (set-buffer nntp-server-buffer) + (goto-char (point-min)) + (when (search-forward "\n\n" nil t) + (delete-region (1- (point)) (point-max))) + (nnheader-fold-continuation-lines))) + res)))) (defun gnus-request-body (article group) + "Request the body of ARTICLE in GROUP." (let ((method (gnus-find-method-for-group group))) - (funcall (gnus-get-function method 'request-body) + (funcall (gnus-get-function method 'request-body) article (gnus-group-real-name group) (nth 1 method)))) -;; Fix by Sudish Joseph . -(defun gnus-request-post-buffer (post group subject header artbuf - info follow-to respect-poster) - (let* ((info (or info (and group (nth 2 (gnus-gethash - group gnus-newsrc-hashtb))))) - (method - (if (and gnus-post-method - ;; Fix by Sudish Joseph . - (memq 'post (assoc - (format "%s" (car (gnus-find-method-for-group - gnus-newsgroup-name))) - gnus-valid-select-methods))) - gnus-post-method - (gnus-find-method-for-group gnus-newsgroup-name)))) - (or (gnus-check-server method) - (error "Can't open server %s:%s" (car method) (nth 1 method))) - (let ((mail-self-blind nil) - (mail-archive-file-name nil)) - (funcall (gnus-get-function method 'request-post-buffer) - post group subject header artbuf info follow-to - respect-poster)))) - -(defun gnus-request-post (method &optional force) - (and (stringp method) - (setq method (gnus-server-to-method method))) - (and (not force) gnus-post-method - (memq 'post (assoc (format "%s" (car method)) - gnus-valid-select-methods)) - (setq method gnus-post-method)) - (funcall (gnus-get-function method 'request-post) - (nth 1 method))) +(defun gnus-request-post (method) + "Post the current buffer using METHOD." + (when (stringp method) + (setq method (gnus-server-to-method method))) + (funcall (gnus-get-function method 'request-post) (nth 1 method))) + +(defun gnus-request-scan (group method) + "Request a SCAN being performed in GROUP from METHOD. +If GROUP is nil, all groups on METHOD are scanned." + (let ((method (if group (gnus-find-method-for-group group) method))) + (funcall (gnus-get-function method 'request-scan) + (and group (gnus-group-real-name group)) (nth 1 method)))) + +(defsubst gnus-request-update-info (info method) + "Request that METHOD update INFO." + (when (stringp method) + (setq method (gnus-server-to-method method))) + (when (gnus-check-backend-function 'request-update-info (car method)) + (funcall (gnus-get-function method 'request-update-info) + (gnus-group-real-name (gnus-info-group info)) + info (nth 1 method)))) (defun gnus-request-expire-articles (articles group &optional force) (let ((method (gnus-find-method-for-group group))) - (funcall (gnus-get-function method 'request-expire-articles) + (funcall (gnus-get-function method 'request-expire-articles) articles (gnus-group-real-name group) (nth 1 method) force))) -(defun gnus-request-move-article +(defun gnus-request-move-article (article group server accept-function &optional last) (let ((method (gnus-find-method-for-group group))) - (funcall (gnus-get-function method 'request-move-article) - article (gnus-group-real-name group) + (funcall (gnus-get-function method 'request-move-article) + article (gnus-group-real-name group) (nth 1 method) accept-function last))) -(defun gnus-request-accept-article (group &optional last) +(defun gnus-request-accept-article (group method &optional last) + ;; Make sure there's a newline at the end of the article. + (when (stringp method) + (setq method (gnus-server-to-method method))) + (when (and (not method) + (stringp group)) + (setq method (gnus-group-name-to-method group))) (goto-char (point-max)) - (or (bolp) (insert "\n")) - (let ((func (if (symbolp group) group - (car (gnus-find-method-for-group group))))) + (unless (bolp) + (insert "\n")) + (let ((func (car (or method (gnus-find-method-for-group group))))) (funcall (intern (format "%s-request-accept-article" func)) (if (stringp group) (gnus-group-real-name group) group) + (cadr method) last))) (defun gnus-request-replace-article (article group buffer) @@ -11977,166 +15314,228 @@ is returned insted of the status string." (funcall (intern (format "%s-request-replace-article" func)) article (gnus-group-real-name group) buffer))) -(defun gnus-request-create-group (group) +(defun gnus-request-associate-buffer (group) + (let ((method (gnus-find-method-for-group group))) + (funcall (gnus-get-function method 'request-associate-buffer) + (gnus-group-real-name group)))) + +(defun gnus-request-restore-buffer (article group) + "Request a new buffer restored to the state of ARTICLE." (let ((method (gnus-find-method-for-group group))) - (funcall (gnus-get-function method 'request-create-group) + (funcall (gnus-get-function method 'request-restore-buffer) + article (gnus-group-real-name group) (nth 1 method)))) + +(defun gnus-request-create-group (group &optional method) + (when (stringp method) + (setq method (gnus-server-to-method method))) + (let ((method (or method (gnus-find-method-for-group group)))) + (funcall (gnus-get-function method 'request-create-group) (gnus-group-real-name group) (nth 1 method)))) +(defun gnus-request-delete-group (group &optional force) + (let ((method (gnus-find-method-for-group group))) + (funcall (gnus-get-function method 'request-delete-group) + (gnus-group-real-name group) force (nth 1 method)))) + +(defun gnus-request-rename-group (group new-name) + (let ((method (gnus-find-method-for-group group))) + (funcall (gnus-get-function method 'request-rename-group) + (gnus-group-real-name group) + (gnus-group-real-name new-name) (nth 1 method)))) + (defun gnus-member-of-valid (symbol group) + "Find out if GROUP has SYMBOL as part of its \"valid\" spec." (memq symbol (assoc - (format "%s" (car (gnus-find-method-for-group group))) + (symbol-name (car (gnus-find-method-for-group group))) gnus-valid-select-methods))) -(defun gnus-secondary-method-p (method) - (let ((methods gnus-secondary-select-methods) - (gmethod (gnus-server-get-method nil method))) - (while (and methods - (not (equal (gnus-server-get-method nil (car methods)) - gmethod))) - (setq methods (cdr methods))) - methods)) +(defun gnus-method-option-p (method option) + "Return non-nil if select METHOD has OPTION as a parameter." + (when (stringp method) + (setq method (gnus-server-to-method method))) + (memq option (assoc (format "%s" (car method)) + gnus-valid-select-methods))) + +(defun gnus-server-extend-method (group method) + ;; This function "extends" a virtual server. If the server is + ;; "hello", and the select method is ("hello" (my-var "something")) + ;; in the group "alt.alt", this will result in a new virtual server + ;; called "hello+alt.alt". + (let ((entry + (gnus-copy-sequence + (if (equal (car method) "native") gnus-select-method + (cdr (assoc (car method) gnus-server-alist)))))) + (setcar (cdr entry) (concat (nth 1 entry) "+" group)) + (nconc entry (cdr method)))) + +(defun gnus-group-name-to-method (group) + "Return a select method suitable for GROUP." + (if (string-match ":" group) + (let ((server (substring group 0 (match-beginning 0)))) + (if (string-match "\\+" server) + (list (intern (substring server 0 (match-beginning 0))) + (substring server (match-end 0))) + (list (intern server) ""))) + gnus-select-method)) (defun gnus-find-method-for-group (group &optional info) + "Find the select method that GROUP uses." (or gnus-override-method (and (not group) gnus-select-method) - (let ((info (or info (nth 2 (gnus-gethash group gnus-newsrc-hashtb)))) + (let ((info (or info (gnus-get-info group))) method) (if (or (not info) - (not (setq method (nth 4 info)))) - (setq method gnus-select-method) + (not (setq method (gnus-info-method info))) + (equal method "native")) + gnus-select-method (setq method (cond ((stringp method) (gnus-server-to-method method)) ((stringp (car method)) (gnus-server-extend-method group method)) (t - method)))) - (gnus-server-add-address method)))) + method))) + (cond ((equal (cadr method) "") + method) + ((null (cadr method)) + (list (car method) "")) + (t + (gnus-server-add-address method))))))) (defun gnus-check-backend-function (func group) + "Check whether GROUP supports function FUNC." (let ((method (if (stringp group) (car (gnus-find-method-for-group group)) group))) (fboundp (intern (format "%s-%s" method func))))) -(defun gnus-methods-using (method) +(defun gnus-methods-using (feature) + "Find all methods that have FEATURE." (let ((valids gnus-valid-select-methods) outs) (while valids - (if (memq method (car valids)) + (if (memq feature (car valids)) (setq outs (cons (car valids) outs))) (setq valids (cdr valids))) outs)) -;;; + +;;; ;;; Active & Newsrc File Handling ;;; -;; Newsrc related functions. -;; Gnus internal format of gnus-newsrc-alist: -;; (("alt.general" 3 (1 . 1)) -;; ("alt.misc" 3 ((1 . 10) (12 . 15))) -;; ("alt.test" 7 (1 . 99) (45 57 93)) ...) -;; The first item is the group name; the second is the subscription -;; level; the third is either a range of a list of ranges of read -;; articles, the optional fourth element is a list of marked articles, -;; the optional fifth element is the select method. -;; -;; Gnus internal format of gnus-newsrc-hashtb: -;; (95 ("alt.general" 3 (1 . 1)) ("alt.misc" 3 ((1 . 10) (12 . 15))) ...) -;; This is the entry for "alt.misc". The first element is the number -;; of unread articles in "alt.misc". The cdr of this entry is the -;; element *before* "alt.misc" in gnus-newsrc-alist, which makes is -;; trivial to remove or add new elements into gnus-newsrc-alist -;; without scanning the entire list. So, to get the actual information -;; of "alt.misc", you'd say something like -;; (nth 2 (gnus-gethash "alt.misc" gnus-newsrc-hashtb)) -;; -;; Gnus internal format of gnus-active-hashtb: -;; ((1 . 1)) -;; (5 . 10)) -;; (67 . 99)) ...) -;; The only element in each entry in this hash table is a range of -;; (possibly) available articles. (Articles in this range may have -;; been expired or canceled.) -;; -;; Gnus internal format of gnus-killed-list and gnus-zombie-list: -;; ("alt.misc" "alt.test" "alt.general" ...) - -(defun gnus-setup-news (&optional rawfile level) +(defun gnus-setup-news (&optional rawfile level dont-connect) "Setup news information. If RAWFILE is non-nil, the .newsrc file will also be read. If LEVEL is non-nil, the news will be set up at level LEVEL." (let ((init (not (and gnus-newsrc-alist gnus-active-hashtb (not rawfile))))) - ;; Clear some variables to re-initialize news information. - (if init (setq gnus-newsrc-alist nil - gnus-active-hashtb nil)) - ;; Read the newsrc file and create `gnus-newsrc-hashtb'. - (if init (gnus-read-newsrc-file rawfile)) + (when init + ;; Clear some variables to re-initialize news information. + (setq gnus-newsrc-alist nil + gnus-active-hashtb nil) + ;; Read the newsrc file and create `gnus-newsrc-hashtb'. + (gnus-read-newsrc-file rawfile)) + + (when (and (not (assoc "archive" gnus-server-alist)) + gnus-message-archive-method) + (push (cons "archive" gnus-message-archive-method) + gnus-server-alist)) ;; If we don't read the complete active file, we fill in the - ;; hashtb here. + ;; hashtb here. (if (or (null gnus-read-active-file) (eq gnus-read-active-file 'some)) (gnus-update-active-hashtb-from-killed)) ;; Read the active file and create `gnus-active-hashtb'. ;; If `gnus-read-active-file' is nil, then we just create an empty - ;; hash table. The partial filling out of the hash table will be + ;; hash table. The partial filling out of the hash table will be ;; done in `gnus-get-unread-articles'. - (and gnus-read-active-file + (and gnus-read-active-file (not level) (gnus-read-active-file)) (or gnus-active-hashtb (setq gnus-active-hashtb (make-vector 4095 0))) + ;; Initialize the cache. + (when gnus-use-cache + (gnus-cache-open)) + ;; Possibly eval the dribble file. - (and init gnus-use-dribble-file (gnus-dribble-eval-file)) + (and init (or gnus-use-dribble-file gnus-slave) (gnus-dribble-eval-file)) + + ;; Slave Gnusii should then clear the dribble buffer. + (when (and init gnus-slave) + (gnus-dribble-clear)) (gnus-update-format-specifications) + ;; See whether we need to read the description file. + (if (and (string-match "%[-,0-9]*D" gnus-group-line-format) + (not gnus-description-hashtb) + (not dont-connect) + gnus-read-active-file) + (gnus-read-all-descriptions-files)) + ;; Find new newsgroups and treat them. - (if (and init gnus-check-new-newsgroups gnus-read-active-file (not level) + (if (and init gnus-check-new-newsgroups (not level) (gnus-check-server gnus-select-method)) (gnus-find-new-newsgroups)) + ;; We might read in new NoCeM messages here. + (when (and gnus-use-nocem + (not level) + (not dont-connect)) + (gnus-nocem-scan-groups)) + ;; Find the number of unread articles in each non-dead group. (let ((gnus-read-active-file (and (not level) gnus-read-active-file))) - (gnus-get-unread-articles (or level (1+ gnus-level-subscribed)))) + (gnus-get-unread-articles level)) - (if (and init gnus-check-bogus-newsgroups + (if (and init gnus-check-bogus-newsgroups gnus-read-active-file (not level) (gnus-server-opened gnus-select-method)) (gnus-check-bogus-newsgroups)))) -(defun gnus-find-new-newsgroups () +(defun gnus-find-new-newsgroups (&optional arg) "Search for new newsgroups and add them. Each new newsgroup will be treated with `gnus-subscribe-newsgroup-method.' -The `-n' option line from .newsrc is respected." - (interactive) - (or (gnus-check-first-time-used) - (if (or (consp gnus-check-new-newsgroups) - (eq gnus-check-new-newsgroups 'ask-server)) +The `-n' option line from .newsrc is respected. +If ARG (the prefix), use the `ask-server' method to query +the server for new groups." + (interactive "P") + (let ((check (if (or (and arg (not (listp gnus-check-new-newsgroups))) + (null gnus-read-active-file) + (eq gnus-read-active-file 'some)) + 'ask-server gnus-check-new-newsgroups))) + (unless (gnus-check-first-time-used) + (if (or (consp check) + (eq check 'ask-server)) + ;; Ask the server for new groups. (gnus-ask-server-for-new-groups) + ;; Go through the active hashtb and look for new groups. (let ((groups 0) group new-newsgroups) (gnus-message 5 "Looking for new newsgroups...") - (or gnus-have-read-active-file (gnus-read-active-file)) + (unless gnus-have-read-active-file + (gnus-read-active-file)) (setq gnus-newsrc-last-checked-date (current-time-string)) - (if (not gnus-killed-hashtb) (gnus-make-hashtable-from-killed)) + (unless gnus-killed-hashtb + (gnus-make-hashtable-from-killed)) ;; Go though every newsgroup in `gnus-active-hashtb' and compare ;; with `gnus-newsrc-hashtb' and `gnus-killed-hashtb'. (mapatoms (lambda (sym) (if (or (null (setq group (symbol-name sym))) + (not (boundp sym)) (null (symbol-value sym)) (gnus-gethash group gnus-killed-hashtb) (gnus-gethash group gnus-newsrc-hashtb)) () (let ((do-sub (gnus-matches-options-n group))) - (cond + (cond ((eq do-sub 'subscribe) (setq groups (1+ groups)) (gnus-sethash group group gnus-killed-hashtb) @@ -12150,13 +15549,13 @@ The `-n' option line from .newsrc is respected." (setq new-newsgroups (cons group new-newsgroups)) (funcall gnus-subscribe-newsgroup-method group))))))) gnus-active-hashtb) - (if new-newsgroups - (gnus-subscribe-hierarchical-interactive new-newsgroups)) + (when new-newsgroups + (gnus-subscribe-hierarchical-interactive new-newsgroups)) ;; Suggested by Per Abrahamsen . (if (> groups 0) - (gnus-message 6 "%d new newsgroup%s arrived." + (gnus-message 6 "%d new newsgroup%s arrived." groups (if (> groups 1) "s have" " has")) - (gnus-message 6 "No new newsgroups.")))))) + (gnus-message 6 "No new newsgroups."))))))) (defun gnus-matches-options-n (group) ;; Returns `subscribe' if the group is to be unconditionally @@ -12168,78 +15567,87 @@ The `-n' option line from .newsrc is respected." ((and gnus-options-subscribe (string-match gnus-options-subscribe group)) 'subscribe) + ((and gnus-auto-subscribed-groups + (string-match gnus-auto-subscribed-groups group)) + 'subscribe) ((and gnus-options-not-subscribe (string-match gnus-options-not-subscribe group)) 'ignore) ;; Then we go through the list that was retrieved from the .newsrc - ;; file. This list has elements on the form - ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list + ;; file. This list has elements on the form + ;; `(REGEXP . {ignore,subscribe})'. The first match found (the list ;; is in the reverse order of the options line) is returned. (t (let ((regs gnus-newsrc-options-n)) (while (and regs - (not (string-match (car (car regs)) group))) + (not (string-match (caar regs) group))) (setq regs (cdr regs))) - (and regs (cdr (car regs))))))) + (and regs (cdar regs)))))) (defun gnus-ask-server-for-new-groups () (let* ((date (or gnus-newsrc-last-checked-date (current-time-string))) - (methods (cons gnus-select-method - (append - (and (consp gnus-check-new-newsgroups) - gnus-check-new-newsgroups) - gnus-secondary-select-methods))) + (methods (cons gnus-select-method + (nconc + (when gnus-message-archive-method + (list "archive")) + (append + (and (consp gnus-check-new-newsgroups) + gnus-check-new-newsgroups) + gnus-secondary-select-methods)))) (groups 0) (new-date (current-time-string)) - (hashtb (gnus-make-hashtable 100)) - group new-newsgroups got-new method) - ;; Go through both primary and secondary select methods and - ;; request new newsgroups. - (while methods - (setq method (gnus-server-get-method nil (car methods))) - (and (gnus-check-server method) - (gnus-request-newgroups date method) - (save-excursion - (setq got-new t) - (set-buffer nntp-server-buffer) - ;; Enter all the new groups in a hashtable. - (gnus-active-to-gnus-format method hashtb 'ignore))) - (setq methods (cdr methods))) - (and got-new (setq gnus-newsrc-last-checked-date new-date)) - ;; Now all new groups from all select methods are in `hashtb'. - (mapatoms - (lambda (group-sym) - (setq group (symbol-name group-sym)) - (if (or (null group) - (null (symbol-value group-sym)) - (gnus-gethash group gnus-newsrc-hashtb) - (member group gnus-zombie-list) - (member group gnus-killed-list)) - ;; The group is already known. - () - (and (symbol-value group-sym) - (gnus-sethash group (symbol-value group-sym) gnus-active-hashtb)) - (let ((do-sub (gnus-matches-options-n group))) - (cond ((eq do-sub 'subscribe) - (setq groups (1+ groups)) - (gnus-sethash group group gnus-killed-hashtb) - (funcall - gnus-subscribe-options-newsgroup-method group)) - ((eq do-sub 'ignore) - nil) - (t - (setq groups (1+ groups)) - (gnus-sethash group group gnus-killed-hashtb) - (if gnus-subscribe-hierarchical-interactive - (setq new-newsgroups (cons group new-newsgroups)) - (funcall gnus-subscribe-newsgroup-method group))))))) - hashtb) - (if new-newsgroups - (gnus-subscribe-hierarchical-interactive new-newsgroups)) + group new-newsgroups got-new method hashtb + gnus-override-subscribe-method) + ;; Go through both primary and secondary select methods and + ;; request new newsgroups. + (while (setq method (gnus-server-get-method nil (pop methods))) + (setq new-newsgroups nil) + (setq gnus-override-subscribe-method method) + (when (and (gnus-check-server method) + (gnus-request-newgroups date method)) + (save-excursion + (setq got-new t) + (setq hashtb (gnus-make-hashtable 100)) + (set-buffer nntp-server-buffer) + ;; Enter all the new groups into a hashtable. + (gnus-active-to-gnus-format method hashtb 'ignore)) + ;; Now all new groups from `method' are in `hashtb'. + (mapatoms + (lambda (group-sym) + (if (or (null (setq group (symbol-name group-sym))) + (not (boundp group-sym)) + (null (symbol-value group-sym)) + (gnus-gethash group gnus-newsrc-hashtb) + (member group gnus-zombie-list) + (member group gnus-killed-list)) + ;; The group is already known. + () + ;; Make this group active. + (when (symbol-value group-sym) + (gnus-set-active group (symbol-value group-sym))) + ;; Check whether we want it or not. + (let ((do-sub (gnus-matches-options-n group))) + (cond + ((eq do-sub 'subscribe) + (incf groups) + (gnus-sethash group group gnus-killed-hashtb) + (funcall gnus-subscribe-options-newsgroup-method group)) + ((eq do-sub 'ignore) + nil) + (t + (incf groups) + (gnus-sethash group group gnus-killed-hashtb) + (if gnus-subscribe-hierarchical-interactive + (push group new-newsgroups) + (funcall gnus-subscribe-newsgroup-method group))))))) + hashtb)) + (when new-newsgroups + (gnus-subscribe-hierarchical-interactive new-newsgroups))) ;; Suggested by Per Abrahamsen . - (if (> groups 0) - (gnus-message 6 "%d new newsgroup%s arrived." - groups (if (> groups 1) "s have" " has"))) + (when (> groups 0) + (gnus-message 6 "%d new newsgroup%s arrived." + groups (if (> groups 1) "s have" " has"))) + (and got-new (setq gnus-newsrc-last-checked-date new-date)) got-new)) (defun gnus-check-first-time-used () @@ -12249,7 +15657,8 @@ The `-n' option line from .newsrc is respected." (file-exists-p (concat gnus-startup-file ".eld"))) nil (gnus-message 6 "First time user; subscribing you to default groups") - (or gnus-have-read-active-file (gnus-read-active-file)) + (unless (gnus-read-active-file-p) + (gnus-read-active-file)) (setq gnus-newsrc-last-checked-date (current-time-string)) (let ((groups gnus-default-subscribed-newsgroups) group) @@ -12261,7 +15670,7 @@ The `-n' option line from .newsrc is respected." (if (null (setq group (symbol-name sym))) () (let ((do-sub (gnus-matches-options-n group))) - (cond + (cond ((eq do-sub 'subscribe) (gnus-sethash group group gnus-killed-hashtb) (funcall gnus-subscribe-options-newsgroup-method group)) @@ -12271,8 +15680,8 @@ The `-n' option line from .newsrc is respected." (setq gnus-killed-list (cons group gnus-killed-list))))))) gnus-active-hashtb) (while groups - (if (gnus-gethash (car groups) gnus-active-hashtb) - (gnus-group-change-level + (if (gnus-active (car groups)) + (gnus-group-change-level (car groups) gnus-level-default-subscribed gnus-level-killed)) (setq groups (cdr groups))) (gnus-group-make-help-group) @@ -12280,28 +15689,28 @@ The `-n' option line from .newsrc is respected." (gnus-message 7 "`A k' to list killed groups")))))) (defun gnus-subscribe-group (group previous &optional method) - (gnus-group-change-level + (gnus-group-change-level (if method (list t group gnus-level-default-subscribed nil nil method) - group) + group) gnus-level-default-subscribed gnus-level-killed previous t)) ;; `gnus-group-change-level' is the fundamental function for changing -;; subscription levels of newsgroups. This might mean just changing +;; subscription levels of newsgroups. This might mean just changing ;; from level 1 to 2, which is pretty trivial, from 2 to 6 or back ;; again, which subscribes/unsubscribes a group, which is equally -;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and +;; trivial. Changing from 1-7 to 8-9 means that you kill a group, and ;; from 8-9 to 1-7 means that you remove the group from the list of ;; killed (or zombie) groups and add them to the (kinda) subscribed -;; groups. And last but not least, moving from 8 to 9 and 9 to 8, +;; groups. And last but not least, moving from 8 to 9 and 9 to 8, ;; which is trivial. ;; ENTRY can either be a string (newsgroup name) or a list (if ;; FROMKILLED is t, it's a list on the format (NUM INFO-LIST), ;; otherwise it's a list in the format of the `gnus-newsrc-hashtb' -;; entries. +;; entries. ;; LEVEL is the new level of the group, OLDLEVEL is the old level and ;; PREVIOUS is the group (in hashtb entry format) to insert this group -;; after. +;; after. (defun gnus-group-change-level (entry level &optional oldlevel previous fromkilled) (let (group info active num) @@ -12311,150 +15720,150 @@ The `-n' option line from .newsrc is respected." (setq group (car (nth 2 entry)))) (setq group entry)) (if (and (stringp entry) - oldlevel + oldlevel (< oldlevel gnus-level-zombie)) (setq entry (gnus-gethash entry gnus-newsrc-hashtb))) (if (and (not oldlevel) (consp entry)) - (setq oldlevel (car (cdr (nth 2 entry))))) + (setq oldlevel (gnus-info-level (nth 2 entry))) + (setq oldlevel (or oldlevel 9))) (if (stringp previous) (setq previous (gnus-gethash previous gnus-newsrc-hashtb))) (if (and (>= oldlevel gnus-level-zombie) (gnus-gethash group gnus-newsrc-hashtb)) ;; We are trying to subscribe a group that is already - ;; subscribed. - () ; Do nothing. + ;; subscribed. + () ; Do nothing. (or (gnus-ephemeral-group-p group) (gnus-dribble-enter - (format "(gnus-group-change-level %S %S %S %S %S)" + (format "(gnus-group-change-level %S %S %S %S %S)" group level oldlevel (car (nth 2 previous)) fromkilled))) - + ;; Then we remove the newgroup from any old structures, if needed. ;; If the group was killed, we remove it from the killed or zombie - ;; list. If not, and it is in fact going to be killed, we remove + ;; list. If not, and it is in fact going to be killed, we remove ;; it from the newsrc hash table and assoc. - (cond ((>= oldlevel gnus-level-zombie) - (if (= oldlevel gnus-level-zombie) - (setq gnus-zombie-list (delete group gnus-zombie-list)) - (setq gnus-killed-list (delete group gnus-killed-list)))) - (t - (if (and (>= level gnus-level-zombie) - entry) - (progn - (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb) - (if (nth 3 entry) - (setcdr (gnus-gethash (car (nth 3 entry)) - gnus-newsrc-hashtb) - (cdr entry))) - (setcdr (cdr entry) (cdr (cdr (cdr entry)))))))) + (cond + ((>= oldlevel gnus-level-zombie) + (if (= oldlevel gnus-level-zombie) + (setq gnus-zombie-list (delete group gnus-zombie-list)) + (setq gnus-killed-list (delete group gnus-killed-list)))) + (t + (if (and (>= level gnus-level-zombie) + entry) + (progn + (gnus-sethash (car (nth 2 entry)) nil gnus-newsrc-hashtb) + (if (nth 3 entry) + (setcdr (gnus-gethash (car (nth 3 entry)) + gnus-newsrc-hashtb) + (cdr entry))) + (setcdr (cdr entry) (cdddr entry)))))) ;; Finally we enter (if needed) the list where it is supposed to - ;; go, and change the subscription level. If it is to be killed, + ;; go, and change the subscription level. If it is to be killed, ;; we enter it into the killed or zombie list. - (cond ((>= level gnus-level-zombie) - ;; Remove from the hash table. - (gnus-sethash group nil gnus-newsrc-hashtb) - (or (gnus-group-foreign-p group) - ;; We do not enter foreign groups into the list of dead - ;; groups. - (if (= level gnus-level-zombie) - (setq gnus-zombie-list (cons group gnus-zombie-list)) - (setq gnus-killed-list (cons group gnus-killed-list))))) - (t - ;; If the list is to be entered into the newsrc assoc, and - ;; it was killed, we have to create an entry in the newsrc - ;; hashtb format and fix the pointers in the newsrc assoc. - (if (>= oldlevel gnus-level-zombie) - (progn - (if (listp entry) - (progn - (setq info (cdr entry)) - (setq num (car entry))) - (setq active (gnus-gethash group gnus-active-hashtb)) - (setq num - (if active (- (1+ (cdr active)) (car active)) t)) - ;; Check whether the group is foreign. If so, the - ;; foreign select method has to be entered into the - ;; info. - (let ((method (gnus-group-method-name group))) - (if (eq method gnus-select-method) - (setq info (list group level nil)) - (setq info (list group level nil nil method))))) - (or previous - (setq previous - (let ((p gnus-newsrc-alist)) - (while (cdr (cdr p)) - (setq p (cdr p))) - p))) - (setq entry (cons info (cdr (cdr previous)))) - (if (cdr previous) - (progn - (setcdr (cdr previous) entry) - (gnus-sethash group (cons num (cdr previous)) - gnus-newsrc-hashtb)) - (setcdr previous entry) - (gnus-sethash group (cons num previous) - gnus-newsrc-hashtb)) - (if (cdr entry) - (setcdr (gnus-gethash (car (car (cdr entry))) - gnus-newsrc-hashtb) - entry))) - ;; It was alive, and it is going to stay alive, so we - ;; just change the level and don't change any pointers or - ;; hash table entries. - (setcar (cdr (car (cdr (cdr entry)))) level))))))) + (cond + ((>= level gnus-level-zombie) + ;; Remove from the hash table. + (gnus-sethash group nil gnus-newsrc-hashtb) + ;; We do not enter foreign groups into the list of dead + ;; groups. + (unless (gnus-group-foreign-p group) + (if (= level gnus-level-zombie) + (setq gnus-zombie-list (cons group gnus-zombie-list)) + (setq gnus-killed-list (cons group gnus-killed-list))))) + (t + ;; If the list is to be entered into the newsrc assoc, and + ;; it was killed, we have to create an entry in the newsrc + ;; hashtb format and fix the pointers in the newsrc assoc. + (if (< oldlevel gnus-level-zombie) + ;; It was alive, and it is going to stay alive, so we + ;; just change the level and don't change any pointers or + ;; hash table entries. + (setcar (cdaddr entry) level) + (if (listp entry) + (setq info (cdr entry) + num (car entry)) + (setq active (gnus-active group)) + (setq num + (if active (- (1+ (cdr active)) (car active)) t)) + ;; Check whether the group is foreign. If so, the + ;; foreign select method has to be entered into the + ;; info. + (let ((method (or gnus-override-subscribe-method + (gnus-group-method group)))) + (if (eq method gnus-select-method) + (setq info (list group level nil)) + (setq info (list group level nil nil method))))) + (unless previous + (setq previous + (let ((p gnus-newsrc-alist)) + (while (cddr p) + (setq p (cdr p))) + p))) + (setq entry (cons info (cddr previous))) + (if (cdr previous) + (progn + (setcdr (cdr previous) entry) + (gnus-sethash group (cons num (cdr previous)) + gnus-newsrc-hashtb)) + (setcdr previous entry) + (gnus-sethash group (cons num previous) + gnus-newsrc-hashtb)) + (when (cdr entry) + (setcdr (gnus-gethash (caadr entry) gnus-newsrc-hashtb) entry))))) + (when gnus-group-change-level-function + (funcall gnus-group-change-level-function group level oldlevel))))) (defun gnus-kill-newsgroup (newsgroup) - "Obsolete function. Kills a newsgroup." + "Obsolete function. Kills a newsgroup." (gnus-group-change-level (gnus-gethash newsgroup gnus-newsrc-hashtb) gnus-level-killed)) (defun gnus-check-bogus-newsgroups (&optional confirm) "Remove bogus newsgroups. If CONFIRM is non-nil, the user has to confirm the deletion of every -newsgroup." +newsgroup." (let ((newsrc (cdr gnus-newsrc-alist)) - bogus group entry) + bogus group entry info) (gnus-message 5 "Checking bogus newsgroups...") - (or gnus-have-read-active-file (gnus-read-active-file)) - ;; Find all bogus newsgroup that are subscribed. - (while newsrc - (setq group (car (car newsrc))) - (if (or (gnus-gethash group gnus-active-hashtb) ; Active - (nth 4 (car newsrc)) ; Foreign - (and confirm - (not (gnus-y-or-n-p - (format "Remove bogus newsgroup: %s " group))))) - ;; Don't remove. - () - ;; Found a bogus newsgroup. - (setq bogus (cons group bogus))) - (setq newsrc (cdr newsrc))) - ;; Remove all bogus subscribed groups by first killing them, and - ;; then removing them from the list of killed groups. - (while bogus - (and (setq entry (gnus-gethash (car bogus) gnus-newsrc-hashtb)) - (progn - (gnus-group-change-level entry gnus-level-killed) - (setq gnus-killed-list (delete (car bogus) gnus-killed-list)))) - (setq bogus (cdr bogus))) - ;; Then we remove all bogus groups from the list of killed and - ;; zombie groups. They are are removed without confirmation. - (let ((dead-lists '(gnus-killed-list gnus-zombie-list)) - killed) - (while dead-lists - (setq killed (symbol-value (car dead-lists))) - (while killed - (setq group (car killed)) - (or (gnus-gethash group gnus-active-hashtb) + (unless (gnus-read-active-file-p) + (gnus-read-active-file)) + (when (gnus-read-active-file-p) + ;; Find all bogus newsgroup that are subscribed. + (while newsrc + (setq info (pop newsrc) + group (gnus-info-group info)) + (unless (or (gnus-active group) ; Active + (gnus-info-method info) ; Foreign + (and confirm + (not (gnus-y-or-n-p + (format "Remove bogus newsgroup: %s " group))))) + ;; Found a bogus newsgroup. + (push group bogus))) + ;; Remove all bogus subscribed groups by first killing them, and + ;; then removing them from the list of killed groups. + (while bogus + (when (setq entry (gnus-gethash (setq group (pop bogus)) + gnus-newsrc-hashtb)) + (gnus-group-change-level entry gnus-level-killed) + (setq gnus-killed-list (delete group gnus-killed-list)))) + ;; Then we remove all bogus groups from the list of killed and + ;; zombie groups. They are are removed without confirmation. + (let ((dead-lists '(gnus-killed-list gnus-zombie-list)) + killed) + (while dead-lists + (setq killed (symbol-value (car dead-lists))) + (while killed + (unless (gnus-active (setq group (pop killed))) ;; The group is bogus. + ;; !!!Slow as hell. (set (car dead-lists) - (delete group (symbol-value (car dead-lists))))) - (setq killed (cdr killed))) - (setq dead-lists (cdr dead-lists)))) - (gnus-message 5 "Checking bogus newsgroups...done"))) + (delete group (symbol-value (car dead-lists)))))) + (setq dead-lists (cdr dead-lists)))) + (gnus-message 5 "Checking bogus newsgroups...done")))) (defun gnus-check-duplicate-killed-groups () "Remove duplicates from the list of killed groups." @@ -12465,95 +15874,167 @@ newsgroup." (setcdr killed (delete (car killed) (cdr killed))) (setq killed (cdr killed))))) +;; We want to inline a function from gnus-cache, so we cheat here: +(eval-when-compile + (provide 'gnus) + (require 'gnus-cache)) + +(defun gnus-get-unread-articles-in-group (info active &optional update) + (when active + ;; Allow the backend to update the info in the group. + (when (and update + (gnus-request-update-info + info (gnus-find-method-for-group (gnus-info-group info)))) + (gnus-activate-group (gnus-info-group info) nil t)) + (let* ((range (gnus-info-read info)) + (num 0)) + ;; If a cache is present, we may have to alter the active info. + (when (and gnus-use-cache info) + (inline (gnus-cache-possibly-alter-active + (gnus-info-group info) active))) + ;; Modify the list of read articles according to what articles + ;; are available; then tally the unread articles and add the + ;; number to the group hash table entry. + (cond + ((zerop (cdr active)) + (setq num 0)) + ((not range) + (setq num (- (1+ (cdr active)) (car active)))) + ((not (listp (cdr range))) + ;; Fix a single (num . num) range according to the + ;; active hash table. + ;; Fix by Carsten Bormann . + (and (< (cdr range) (car active)) (setcdr range (1- (car active)))) + (and (> (cdr range) (cdr active)) (setcdr range (cdr active))) + ;; Compute number of unread articles. + (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range)))))) + (t + ;; The read list is a list of ranges. Fix them according to + ;; the active hash table. + ;; First peel off any elements that are below the lower + ;; active limit. + (while (and (cdr range) + (>= (car active) + (or (and (atom (cadr range)) (cadr range)) + (caadr range)))) + (if (numberp (car range)) + (setcar range + (cons (car range) + (or (and (numberp (cadr range)) + (cadr range)) + (cdadr range)))) + (setcdr (car range) + (or (and (numberp (nth 1 range)) (nth 1 range)) + (cdadr range)))) + (setcdr range (cddr range))) + ;; Adjust the first element to be the same as the lower limit. + (if (and (not (atom (car range))) + (< (cdar range) (car active))) + (setcdr (car range) (1- (car active)))) + ;; Then we want to peel off any elements that are higher + ;; than the upper active limit. + (let ((srange range)) + ;; Go past all legal elements. + (while (and (cdr srange) + (<= (or (and (atom (cadr srange)) + (cadr srange)) + (caadr srange)) (cdr active))) + (setq srange (cdr srange))) + (if (cdr srange) + ;; Nuke all remaining illegal elements. + (setcdr srange nil)) + + ;; Adjust the final element. + (if (and (not (atom (car srange))) + (> (cdar srange) (cdr active))) + (setcdr (car srange) (cdr active)))) + ;; Compute the number of unread articles. + (while range + (setq num (+ num (- (1+ (or (and (atom (car range)) (car range)) + (cdar range))) + (or (and (atom (car range)) (car range)) + (caar range))))) + (setq range (cdr range))) + (setq num (max 0 (- (cdr active) num))))) + ;; Set the number of unread articles. + (when info + (setcar (gnus-gethash (gnus-info-group info) gnus-newsrc-hashtb) num)) + num))) + ;; Go though `gnus-newsrc-alist' and compare with `gnus-active-hashtb' ;; and compute how many unread articles there are in each group. -(defun gnus-get-unread-articles (&optional level) +(defun gnus-get-unread-articles (&optional level) (let* ((newsrc (cdr gnus-newsrc-alist)) - (level (or level (1+ gnus-level-subscribed))) + (level (or level gnus-activate-level (1+ gnus-level-subscribed))) (foreign-level - (min - (cond ((and gnus-activate-foreign-newsgroups + (min + (cond ((and gnus-activate-foreign-newsgroups (not (numberp gnus-activate-foreign-newsgroups))) (1+ gnus-level-subscribed)) ((numberp gnus-activate-foreign-newsgroups) gnus-activate-foreign-newsgroups) (t 0)) level)) - info group active virtuals method) + info group active method) (gnus-message 5 "Checking new news...") (while newsrc - (setq info (car newsrc) - group (car info) - active (gnus-gethash group gnus-active-hashtb)) + (setq active (gnus-active (setq group (gnus-info-group + (setq info (pop newsrc)))))) - ;; Check newsgroups. If the user doesn't want to check them, or + ;; Check newsgroups. If the user doesn't want to check them, or ;; they can't be checked (for instance, if the news server can't ;; be reached) we just set the number of unread articles in this - ;; newsgroup to t. This means that Gnus thinks that there are + ;; newsgroup to t. This means that Gnus thinks that there are ;; unread articles, but it has no idea how many. - (if (and (setq method (nth 4 info)) - (not (gnus-server-equal gnus-select-method - (gnus-server-get-method nil method))) + (if (and (setq method (gnus-info-method info)) + (not (gnus-server-equal + gnus-select-method + (setq method (gnus-server-get-method nil method)))) (not (gnus-secondary-method-p method))) - ;; These groups are foreign. Check the level. - (if (<= (nth 1 info) foreign-level) - (if (eq (car (if (stringp method) - (gnus-server-to-method method) - (nth 4 info))) 'nnvirtual) - ;; We have to activate the virtual groups after all - ;; the others, so we just pop them on a list for - ;; now. - (setq virtuals (cons info virtuals)) - (and (setq active (gnus-activate-group (car info))) - ;; Close the groups as we look at them! - (gnus-close-group group)))) - - ;; These groups are native or secondary. - (if (and (not gnus-read-active-file) - (<= (nth 1 info) level)) - (progn - (or gnus-read-active-file (gnus-check-server method)) - (setq active (gnus-activate-group (car info)))))) - + ;; These groups are foreign. Check the level. + (when (<= (gnus-info-level info) foreign-level) + (setq active (gnus-activate-group group 'scan)) + (unless (inline (gnus-virtual-group-p group)) + (inline (gnus-close-group group))) + (when (fboundp (intern (concat (symbol-name (car method)) + "-request-update-info"))) + (inline (gnus-request-update-info info method)))) + ;; These groups are native or secondary. + (when (and (<= (gnus-info-level info) level) + (not gnus-read-active-file)) + (setq active (gnus-activate-group group 'scan)) + (inline (gnus-close-group group)))) + + ;; Get the number of unread articles in the group. (if active - (gnus-get-unread-articles-in-group info active) + (inline (gnus-get-unread-articles-in-group info active)) ;; The group couldn't be reached, so we nix out the number of ;; unread articles and stuff. - (gnus-sethash group nil gnus-active-hashtb) - (setcar (gnus-gethash group gnus-newsrc-hashtb) t)) - - (setq newsrc (cdr newsrc))) - - ;; Activate the virtual groups. This has to be done after all the - ;; other groups. - ;; !!! If one virtual group contains another virtual group, even - ;; doing it this way might cause problems. - (while virtuals - (and (setq active (gnus-activate-group (car (car virtuals)))) - (gnus-get-unread-articles-in-group (car virtuals) active)) - (setq virtuals (cdr virtuals))) + (gnus-set-active group nil) + (setcar (gnus-gethash group gnus-newsrc-hashtb) t))) (gnus-message 5 "Checking new news...done"))) -;; Create a hash table out of the newsrc alist. The `car's of the +;; Create a hash table out of the newsrc alist. The `car's of the ;; alist elements are used as keys. (defun gnus-make-hashtable-from-newsrc-alist () (let ((alist gnus-newsrc-alist) (ohashtb gnus-newsrc-hashtb) prev) (setq gnus-newsrc-hashtb (gnus-make-hashtable (length alist))) - (setq alist - (setq prev (setq gnus-newsrc-alist - (if (equal (car (car gnus-newsrc-alist)) + (setq alist + (setq prev (setq gnus-newsrc-alist + (if (equal (caar gnus-newsrc-alist) "dummy.group") gnus-newsrc-alist (cons (list "dummy.group" 0 nil) alist))))) (while alist - (gnus-sethash (car (car alist)) - (cons (and ohashtb (car (gnus-gethash - (car (car alist)) ohashtb))) - prev) gnus-newsrc-hashtb) + (gnus-sethash + (caar alist) + (cons (and ohashtb (car (gnus-gethash (caar alist) ohashtb))) + prev) + gnus-newsrc-hashtb) (setq prev alist alist (cdr alist))))) @@ -12561,122 +16042,31 @@ newsgroup." "Create a hash table from the killed and zombie lists." (let ((lists '(gnus-killed-list gnus-zombie-list)) list) - (setq gnus-killed-hashtb - (gnus-make-hashtable + (setq gnus-killed-hashtb + (gnus-make-hashtable (+ (length gnus-killed-list) (length gnus-zombie-list)))) - (while lists - (setq list (symbol-value (car lists))) - (setq lists (cdr lists)) + (while (setq list (pop lists)) + (setq list (symbol-value list)) (while list - (gnus-sethash (car list) (car list) gnus-killed-hashtb) - (setq list (cdr list)))))) - -(defun gnus-get-unread-articles-in-group (info active) - (let* ((range (nth 2 info)) - (num 0) - (marked (nth 3 info))) - ;; If a cache is present, we may have to alter the active info. - (and gnus-use-cache - (gnus-cache-possibly-alter-active (car info) active)) - ;; Modify the list of read articles according to what articles - ;; are available; then tally the unread articles and add the - ;; number to the group hash table entry. - (cond - ((zerop (cdr active)) - (setq num 0)) - ((not range) - (setq num (- (1+ (cdr active)) (car active)))) - ((not (listp (cdr range))) - ;; Fix a single (num . num) range according to the - ;; active hash table. - ;; Fix by Carsten Bormann . - (and (< (cdr range) (car active)) (setcdr range (1- (car active)))) - (and (> (cdr range) (cdr active)) (setcdr range (cdr active))) - ;; Compute number of unread articles. - (setq num (max 0 (- (cdr active) (- (1+ (cdr range)) (car range)))))) - (t - ;; The read list is a list of ranges. Fix them according to - ;; the active hash table. - ;; First peel off any elements that are below the lower - ;; active limit. - (while (and (cdr range) - (>= (car active) - (or (and (atom (car (cdr range))) (car (cdr range))) - (car (car (cdr range)))))) - (if (numberp (car range)) - (setcar range - (cons (car range) - (or (and (numberp (car (cdr range))) - (car (cdr range))) - (cdr (car (cdr range)))))) - (setcdr (car range) - (or (and (numberp (nth 1 range)) (nth 1 range)) - (cdr (car (cdr range)))))) - (setcdr range (cdr (cdr range)))) - ;; Adjust the first element to be the same as the lower limit. - (if (and (not (atom (car range))) - (< (cdr (car range)) (car active))) - (setcdr (car range) (1- (car active)))) - ;; Then we want to peel off any elements that are higher - ;; than the upper active limit. - (let ((srange range)) - ;; Go past all legal elements. - (while (and (cdr srange) - (<= (or (and (atom (car (cdr srange))) - (car (cdr srange))) - (car (car (cdr srange)))) (cdr active))) - (setq srange (cdr srange))) - (if (cdr srange) - ;; Nuke all remaining illegal elements. - (setcdr srange nil)) - - ;; Adjust the final element. - (if (and (not (atom (car srange))) - (> (cdr (car srange)) (cdr active))) - (setcdr (car srange) (cdr active)))) - ;; Compute the number of unread articles. - (while range - (setq num (+ num (- (1+ (or (and (atom (car range)) (car range)) - (cdr (car range)))) - (or (and (atom (car range)) (car range)) - (car (car range)))))) - (setq range (cdr range))) - (setq num (max 0 (- (cdr active) num))))) - (and info - (progn - (and (assq 'tick marked) - (inline (gnus-remove-illegal-marked-articles - (assq 'tick marked) (nth 2 info)))) - (and (assq 'dormant marked) - (inline (gnus-remove-illegal-marked-articles - (assq 'dormant marked) (nth 2 info)))) - (setcar - (gnus-gethash (car info) gnus-newsrc-hashtb) - (setq num (max 0 (- num (length (cdr (assq 'tick marked))) - (length (cdr (assq 'dormant marked))))))))) - num)) - -(defun gnus-remove-illegal-marked-articles (marked ranges) - (let ((m (cdr marked))) - ;; Make sure that all ticked articles are a subset of the unread - ;; articles. - (while m - (if (gnus-member-of-range (car m) ranges) - (setcdr marked (cdr m)) - (setq marked m)) - (setq m (cdr m))))) - -(defun gnus-activate-group (group) + (gnus-sethash (car list) (pop list) gnus-killed-hashtb))))) + +(defun gnus-activate-group (group &optional scan dont-check method) ;; Check whether a group has been activated or not. - (let ((method (gnus-find-method-for-group group)) + ;; If SCAN, request a scan of that group as well. + (let ((method (or method (gnus-find-method-for-group group))) active) (and (gnus-check-server method) ;; We escape all bugs and quit here to make it possible to ;; continue if a group is so out-there that it reports bugs ;; and stuff. + (progn + (and scan + (gnus-check-backend-function 'request-scan (car method)) + (gnus-request-scan group method)) + t) (condition-case () - (gnus-request-group group) - (error nil) + (gnus-request-group group dont-check method) + ; (error nil) (quit nil)) (save-excursion (set-buffer nntp-server-buffer) @@ -12685,34 +16075,29 @@ newsgroup." (and (looking-at "[0-9]+ [0-9]+ \\([0-9]+\\) [0-9]+") (progn (goto-char (match-beginning 1)) - (gnus-sethash + (gnus-set-active group (setq active (cons (read (current-buffer)) - (read (current-buffer)))) - gnus-active-hashtb)) - ;; Return the new active info. - active))))) - -(defun gnus-update-read-articles - (group unread unselected ticked &optional domarks replied expirable killed - dormant bookmark score) + (read (current-buffer))))) + ;; Return the new active info. + active)))))) + +(defun gnus-update-read-articles (group unread) "Update the list of read and ticked articles in GROUP using the UNREAD and TICKED lists. Note: UNSELECTED has to be sorted over `<'. Returns whether the updating was successful." - (let* ((active (or gnus-newsgroup-active - (gnus-gethash group gnus-active-hashtb))) + (let* ((active (or gnus-newsgroup-active (gnus-active group))) (entry (gnus-gethash group gnus-newsrc-hashtb)) (info (nth 2 entry)) - (marked (nth 3 info)) (prev 1) - (unread (sort (copy-sequence unread) (function <))) + (unread (sort (copy-sequence unread) '<)) read) (if (or (not info) (not active)) ;; There is no info on this group if it was, in fact, - ;; killed. Gnus stores no information on killed groups, so - ;; there's nothing to be done. + ;; killed. Gnus stores no information on killed groups, so + ;; there's nothing to be done. ;; One could store the information somewhere temporarily, - ;; perhaps... Hmmm... + ;; perhaps... Hmmm... () ;; Remove any negative articles numbers. (while (and unread (< (car unread) 0)) @@ -12720,42 +16105,21 @@ Returns whether the updating was successful." ;; Remove any expired article numbers (while (and unread (< (car unread) (car active))) (setq unread (cdr unread))) - (while (and ticked (< (car ticked) (car active))) - (setq ticked (cdr ticked))) - (while (and dormant (< (car dormant) (car active))) - (setq dormant (cdr dormant))) - (setq unread (sort (append unselected unread) '<)) - ;; Weed out duplicates. - (let ((un unread)) - (while (cdr un) - (if (eq (car un) (car (cdr un))) - (setcdr un (cdr (cdr un))) - (setq un (cdr un))))) ;; Compute the ranges of read articles by looking at the list of - ;; unread articles. + ;; unread articles. (while unread (if (/= (car unread) prev) (setq read (cons (if (= prev (1- (car unread))) prev (cons prev (1- (car unread)))) read))) (setq prev (1+ (car unread))) (setq unread (cdr unread))) - (if (<= prev (cdr active)) - (setq read (cons (cons prev (cdr active)) read))) + (when (<= prev (cdr active)) + (setq read (cons (cons prev (cdr active)) read))) ;; Enter this list into the group info. - (setcar (cdr (cdr info)) - (if (> (length read) 1) (nreverse read) read)) - ;; Enter the list of ticked articles. - (gnus-set-marked-articles - info ticked - (if domarks replied (cdr (assq 'reply marked))) - (if domarks expirable (cdr (assq 'expire marked))) - (if domarks killed (cdr (assq 'killed marked))) - (if domarks dormant (cdr (assq 'dormant marked))) - (if domarks bookmark (cdr (assq 'bookmark marked))) - (if domarks score (cdr (assq 'score marked)))) + (gnus-info-set-read + info (if (> (length read) 1) (nreverse read) read)) ;; Set the number of unread articles in gnus-newsrc-hashtb. - (gnus-get-unread-articles-in-group - info (gnus-gethash group gnus-active-hashtb)) + (gnus-get-unread-articles-in-group info (gnus-active group)) t))) (defun gnus-make-articles-unread (group articles) @@ -12763,16 +16127,15 @@ Returns whether the updating was successful." (let* ((info (nth 2 (or (gnus-gethash group gnus-newsrc-hashtb) (gnus-gethash (gnus-group-real-name group) gnus-newsrc-hashtb)))) - (ranges (nth 2 info)) - news) + (ranges (gnus-info-read info)) + news article) (while articles - (and (gnus-member-of-range (car articles) ranges) - (setq news (cons (car articles) news))) - (setq articles (cdr articles))) - (if (not news) - () - (setcar (nthcdr 2 info) - (gnus-remove-from-range (nth 2 info) (nreverse news))) + (when (gnus-member-of-range + (setq article (pop articles)) ranges) + (setq news (cons article news)))) + (when news + (gnus-info-set-read + info (gnus-remove-from-range (gnus-info-read info) (nreverse news))) (gnus-group-update-group group t)))) ;; Enter all dead groups into the hashtb. @@ -12787,86 +16150,118 @@ Returns whether the updating was successful." (setq killed (cdr killed))) (setq lists (cdr lists))))) +(defun gnus-get-killed-groups () + "Go through the active hashtb and all all unknown groups as killed." + ;; First make sure active file has been read. + (unless (gnus-read-active-file-p) + (let ((gnus-read-active-file t)) + (gnus-read-active-file))) + (or gnus-killed-hashtb (gnus-make-hashtable-from-killed)) + ;; Go through all newsgroups that are known to Gnus - enlarge kill list. + (mapatoms + (lambda (sym) + (let ((groups 0) + (group (symbol-name sym))) + (if (or (null group) + (gnus-gethash group gnus-killed-hashtb) + (gnus-gethash group gnus-newsrc-hashtb)) + () + (let ((do-sub (gnus-matches-options-n group))) + (if (or (eq do-sub 'subscribe) (eq do-sub 'ignore)) + () + (setq groups (1+ groups)) + (setq gnus-killed-list + (cons group gnus-killed-list)) + (gnus-sethash group group gnus-killed-hashtb)))))) + gnus-active-hashtb)) + ;; Get the active file(s) from the backend(s). (defun gnus-read-active-file () (gnus-group-set-mode-line) - (let ((methods (if (gnus-check-server gnus-select-method) - ;; The native server is available. - (cons gnus-select-method gnus-secondary-select-methods) - ;; The native server is down, so we just do the - ;; secondary ones. - gnus-secondary-select-methods)) + (let ((methods + (append + (if (gnus-check-server gnus-select-method) + ;; The native server is available. + (cons gnus-select-method gnus-secondary-select-methods) + ;; The native server is down, so we just do the + ;; secondary ones. + gnus-secondary-select-methods) + ;; Also read from the archive server. + (when gnus-message-archive-method + (list "archive")))) list-type) (setq gnus-have-read-active-file nil) (save-excursion (set-buffer nntp-server-buffer) (while methods - (let* ((method (gnus-server-get-method nil (car methods))) + (let* ((method (if (stringp (car methods)) + (gnus-server-get-method nil (car methods)) + (car methods))) (where (nth 1 method)) (mesg (format "Reading active file%s via %s..." (if (and where (not (zerop (length where)))) (concat " from " where) "") (car method)))) (gnus-message 5 mesg) - (if (not (gnus-check-server method)) - () - (cond + (when (gnus-check-server method) + ;; Request that the backend scan its incoming messages. + (and (gnus-check-backend-function 'request-scan (car method)) + (gnus-request-scan nil method)) + (cond ((and (eq gnus-read-active-file 'some) (gnus-check-backend-function 'retrieve-groups (car method))) (let ((newsrc (cdr gnus-newsrc-alist)) (gmethod (gnus-server-get-method nil method)) - groups) - (while newsrc - (and (gnus-server-equal - (gnus-find-method-for-group - (car (car newsrc)) (car newsrc)) - gmethod) - (setq groups (cons (gnus-group-real-name - (car (car newsrc))) groups))) - (setq newsrc (cdr newsrc))) - (gnus-check-server method) - (setq list-type (gnus-retrieve-groups groups method)) - (cond - ((not list-type) - (gnus-message - 1 "Cannot read partial active file from %s server." - (car method)) - (ding) - (sit-for 2)) - ((eq list-type 'active) - (gnus-active-to-gnus-format method gnus-active-hashtb)) - (t - (gnus-groups-to-gnus-format method gnus-active-hashtb))))) + groups info) + (while (setq info (pop newsrc)) + (when (gnus-server-equal + (gnus-find-method-for-group + (gnus-info-group info) info) + gmethod) + (push (gnus-group-real-name (gnus-info-group info)) + groups))) + (when groups + (gnus-check-server method) + (setq list-type (gnus-retrieve-groups groups method)) + (cond + ((not list-type) + (gnus-error + 1.2 "Cannot read partial active file from %s server." + (car method))) + ((eq list-type 'active) + (gnus-active-to-gnus-format method gnus-active-hashtb)) + (t + (gnus-groups-to-gnus-format method gnus-active-hashtb)))))) (t (if (not (gnus-request-list method)) - (progn - (gnus-message 1 "Cannot read active file from %s server." - (car method)) - (ding)) - (gnus-active-to-gnus-format method) + (unless (equal method gnus-message-archive-method) + (gnus-error 1 "Cannot read active file from %s server." + (car method))) + (gnus-message 5 mesg) + (gnus-active-to-gnus-format method gnus-active-hashtb) ;; We mark this active file as read. - (setq gnus-have-read-active-file - (cons method gnus-have-read-active-file)) + (push method gnus-have-read-active-file) (gnus-message 5 "%sdone" mesg)))))) (setq methods (cdr methods)))))) ;; Read an active file and place the results in `gnus-active-hashtb'. -(defun gnus-active-to-gnus-format (method &optional hashtb ignore-errors) +(defun gnus-active-to-gnus-format (&optional method hashtb ignore-errors) + (unless method + (setq method gnus-select-method)) (let ((cur (current-buffer)) - (hashtb (or hashtb - (if (and gnus-active-hashtb + (hashtb (or hashtb + (if (and gnus-active-hashtb (not (equal method gnus-select-method))) gnus-active-hashtb (setq gnus-active-hashtb (if (equal method gnus-select-method) - (gnus-make-hashtable + (gnus-make-hashtable (count-lines (point-min) (point-max))) - (gnus-make-hashtable 4096)))))) - (flag-hashtb (gnus-make-hashtable 60))) + (gnus-make-hashtable 4096))))))) ;; Delete unnecessary lines. (goto-char (point-min)) (while (search-forward "\nto." nil t) - (delete-region (1+ (match-beginning 0)) + (delete-region (1+ (match-beginning 0)) (progn (forward-line 1) (point)))) (or (string= gnus-ignored-newsgroups "") (progn @@ -12879,7 +16274,7 @@ Returns whether the updating was successful." (while (re-search-backward "[][';?()#]" nil t) (insert ?\\)) ;; If these are groups from a foreign select method, we insert the - ;; group prefix in front of the group names. + ;; group prefix in front of the group names. (and method (not (gnus-server-equal (gnus-server-get-method nil method) (gnus-server-get-method nil gnus-select-method))) @@ -12893,7 +16288,7 @@ Returns whether the updating was successful." (if (string-match "%[oO]" gnus-group-line-format) ;; Suggested by Brian Edmonds . ;; If we want information on moderated groups, we use this - ;; loop... + ;; loop... (let* ((mod-hashtb (make-vector 7 0)) (m (intern "m" mod-hashtb)) group max min) @@ -12904,7 +16299,7 @@ Returns whether the updating was successful." (setq group (let ((obarray hashtb)) (read cur))) (if (and (numberp (setq max (read cur))) (numberp (setq min (read cur))) - (progn + (progn (skip-chars-forward " \t") (not (or (= (following-char) ?=) @@ -12914,9 +16309,9 @@ Returns whether the updating was successful." (set group nil)) ;; Enter moderated groups into a list. (if (eq (let ((obarray mod-hashtb)) (read cur)) m) - (setq gnus-moderated-list + (setq gnus-moderated-list (cons (symbol-name group) gnus-moderated-list)))) - (error + (error (and group (symbolp group) (set group nil)))) @@ -12934,7 +16329,7 @@ Returns whether the updating was successful." (setq group (let ((obarray hashtb)) (read cur))) (if (and (numberp (setq max (read cur))) (numberp (setq min (read cur))) - (progn + (progn (skip-chars-forward " \t") (not (or (= (following-char) ?=) @@ -12942,14 +16337,14 @@ Returns whether the updating was successful." (= (following-char) ?j))))) (set group (cons min max)) (set group nil))) - (error - (progn + (error + (progn (and group (symbolp group) (set group nil)) (or ignore-errors (gnus-message 3 "Warning - illegal active: %s" - (buffer-substring + (buffer-substring (gnus-point-at-bol) (gnus-point-at-eol))))))) (widen) (forward-line 1)))))) @@ -12957,13 +16352,13 @@ Returns whether the updating was successful." (defun gnus-groups-to-gnus-format (method &optional hashtb) ;; Parse a "groups" active file. (let ((cur (current-buffer)) - (hashtb (or hashtb + (hashtb (or hashtb (if (and method gnus-active-hashtb) gnus-active-hashtb (setq gnus-active-hashtb - (gnus-make-hashtable + (gnus-make-hashtable (count-lines (point-min) (point-max))))))) - (prefix (and method + (prefix (and method (not (gnus-server-equal (gnus-server-get-method nil method) (gnus-server-get-method nil gnus-select-method))) @@ -12984,7 +16379,7 @@ Returns whether the updating was successful." (skip-chars-forward " \t") (insert prefix) (goto-char opoint) - (set (let ((obarray hashtb)) (read cur)) + (set (let ((obarray hashtb)) (read cur)) (cons min max))) (error (and group (symbolp group) (set group nil)))) (forward-line 1))) @@ -13012,19 +16407,20 @@ If FORCE is non-nil, the .newsrc file is read." (let* ((newsrc-file gnus-current-startup-file) (quick-file (concat newsrc-file ".el"))) (save-excursion - ;; We always load the .newsrc.eld file. If always contains + ;; We always load the .newsrc.eld file. If always contains ;; much information that can not be gotten from the .newsrc ;; file (ticked articles, killed groups, foreign methods, etc.) (gnus-read-newsrc-el-file quick-file) - - (if (or force - (and (file-newer-than-file-p newsrc-file quick-file) - (file-newer-than-file-p newsrc-file - (concat quick-file "d"))) - (not gnus-newsrc-alist)) - ;; We read the .newsrc file. Note that if there if a + + (if (and (file-exists-p gnus-current-startup-file) + (or force + (and (file-newer-than-file-p newsrc-file quick-file) + (file-newer-than-file-p newsrc-file + (concat quick-file "d"))) + (not gnus-newsrc-alist))) + ;; We read the .newsrc file. Note that if there if a ;; .newsrc.eld file exists, it has already been read, and - ;; the `gnus-newsrc-hashtb' has been created. While reading + ;; the `gnus-newsrc-hashtb' has been created. While reading ;; the .newsrc file, Gnus will only use the information it ;; can find there for changing the data already read - ;; ie. reading the .newsrc file will not trash the data @@ -13035,7 +16431,63 @@ If FORCE is non-nil, the .newsrc file is read." (buffer-disable-undo (current-buffer)) (gnus-newsrc-to-gnus-format) (kill-buffer (current-buffer)) - (gnus-message 5 "Reading %s...done" newsrc-file)))))) + (gnus-message 5 "Reading %s...done" newsrc-file))) + + ;; Read any slave files. + (unless gnus-slave + (gnus-master-read-slave-newsrc)) + + ;; Convert old to new. + (gnus-convert-old-newsrc)))) + +(defun gnus-continuum-version (version) + "Return VERSION as a floating point number." + (when (or (string-match "^\\([^ ]+\\)? ?Gnus v?\\([0-9.]+\\)$" version) + (string-match "^\\(.?\\)gnus-\\([0-9.]+\\)$" version)) + (let* ((alpha (and (match-beginning 1) (match-string 1 version))) + (number (match-string 2 version)) + major minor least) + (string-match "\\([0-9]\\)\\.\\([0-9]+\\)\\.?\\([0-9]+\\)?" number) + (setq major (string-to-number (match-string 1 number))) + (setq minor (string-to-number (match-string 2 number))) + (setq least (if (match-beginning 3) + (string-to-number (match-string 3 number)) + 0)) + (string-to-number + (if (zerop major) + (format "%s00%02d%02d" + (cond + ((member alpha '("(ding)" "d")) "4.99") + ((member alpha '("September" "s")) "5.01") + ((member alpha '("Red" "r")) "5.03")) + minor least) + (format "%d.%02d%02d" major minor least)))))) + +(defun gnus-convert-old-newsrc () + "Convert old newsrc into the new format, if needed." + (let ((fcv (and gnus-newsrc-file-version + (gnus-continuum-version gnus-newsrc-file-version)))) + (cond + ;; No .newsrc.eld file was loaded. + ((null fcv) nil) + ;; Gnus 5 .newsrc.eld was loaded. + ((< fcv (gnus-continuum-version "September Gnus v0.1")) + (gnus-convert-old-ticks))))) + +(defun gnus-convert-old-ticks () + (let ((newsrc (cdr gnus-newsrc-alist)) + marks info dormant ticked) + (while (setq info (pop newsrc)) + (when (setq marks (gnus-info-marks info)) + (setq dormant (cdr (assq 'dormant marks)) + ticked (cdr (assq 'tick marks))) + (when (or dormant ticked) + (gnus-info-set-read + info + (gnus-add-to-range + (gnus-info-read info) + (nconc (gnus-uncompress-range dormant) + (gnus-uncompress-range ticked))))))))) (defun gnus-read-newsrc-el-file (file) (let ((ding-file (concat file "d"))) @@ -13044,22 +16496,21 @@ If FORCE is non-nil, the .newsrc file is read." (let (gnus-newsrc-assoc) (condition-case nil (load ding-file t t t) - (error nil)) - (and gnus-newsrc-assoc (setq gnus-newsrc-alist gnus-newsrc-assoc))) - (let ((inhibit-quit t)) - (gnus-uncompress-newsrc-alist)) + (error + (gnus-error 1 "Error in %s" ding-file))) + (when gnus-newsrc-assoc + (setq gnus-newsrc-alist gnus-newsrc-assoc))) (gnus-make-hashtable-from-newsrc-alist) - (if (not (file-newer-than-file-p file ding-file)) - () + (when (file-newer-than-file-p file ding-file) ;; Old format quick file (gnus-message 5 "Reading %s..." file) ;; The .el file is newer than the .eld file, so we read that one - ;; as well. + ;; as well. (gnus-read-old-newsrc-el-file file)))) ;; Parse the old-style quick startup file (defun gnus-read-old-newsrc-el-file (file) - (let (newsrc killed marked group m) + (let (newsrc killed marked group m info) (prog1 (let ((gnus-killed-assoc nil) gnus-marked-assoc gnus-newsrc-alist gnus-newsrc-assoc) @@ -13071,38 +16522,37 @@ If FORCE is non-nil, the .newsrc file is read." killed gnus-killed-assoc marked gnus-marked-assoc))) (setq gnus-newsrc-alist nil) - (while newsrc - (setq group (car newsrc)) - (let ((info (nth 2 (gnus-gethash (car group) gnus-newsrc-hashtb)))) - (if info - (progn - (setcar (nthcdr 2 info) (cdr (cdr group))) - (setcar (cdr info) - (if (nth 1 group) gnus-level-default-subscribed - gnus-level-default-unsubscribed)) - (setq gnus-newsrc-alist (cons info gnus-newsrc-alist))) - (setq gnus-newsrc-alist - (cons - (setq info - (list (car group) - (if (nth 1 group) gnus-level-default-subscribed - gnus-level-default-unsubscribed) - (cdr (cdr group)))) - gnus-newsrc-alist))) - (if (setq m (assoc (car group) marked)) - (setcdr (cdr (cdr info)) - (cons (list (cons 'tick (cdr m))) nil)))) - (setq newsrc (cdr newsrc))) + (while (setq group (pop newsrc)) + (if (setq info (gnus-get-info (car group))) + (progn + (gnus-info-set-read info (cddr group)) + (gnus-info-set-level + info (if (nth 1 group) gnus-level-default-subscribed + gnus-level-default-unsubscribed)) + (setq gnus-newsrc-alist (cons info gnus-newsrc-alist))) + (push (setq info + (list (car group) + (if (nth 1 group) gnus-level-default-subscribed + gnus-level-default-unsubscribed) + (cddr group))) + gnus-newsrc-alist)) + ;; Copy marks into info. + (when (setq m (assoc (car group) marked)) + (unless (nthcdr 3 info) + (nconc info (list nil))) + (gnus-info-set-marks + info (list (cons 'tick (gnus-compress-sequence + (sort (cdr m) '<) t)))))) (setq newsrc killed) (while newsrc - (setcar newsrc (car (car newsrc))) + (setcar newsrc (caar newsrc)) (setq newsrc (cdr newsrc))) (setq gnus-killed-list killed)) ;; The .el file version of this variable does not begin with ;; "options", while the .eld version does, so we just add it if it ;; isn't there. (and - gnus-newsrc-options + gnus-newsrc-options (progn (and (not (string-match "^ *options" gnus-newsrc-options)) (setq gnus-newsrc-options (concat "options " gnus-newsrc-options))) @@ -13114,7 +16564,7 @@ If FORCE is non-nil, the .newsrc file is read." (setq gnus-newsrc-alist (nreverse gnus-newsrc-alist)) (gnus-make-hashtable-from-newsrc-alist))) - + (defun gnus-make-newsrc-file (file) "Make server dependent file name by catenating FILE and server host name." (let* ((file (expand-file-name file nil)) @@ -13124,40 +16574,6 @@ If FORCE is non-nil, the .newsrc file is read." (file-exists-p (concat real-file ".eld"))) real-file file))) -(defun gnus-uncompress-newsrc-alist () - ;; Uncompress all lists of marked articles in the newsrc assoc. - (let ((newsrc gnus-newsrc-alist) - marked) - (while newsrc - (if (not (setq marked (nth 3 (car newsrc)))) - () - (while marked - (or (eq 'score (car (car marked))) - (eq 'bookmark (car (car marked))) - (eq 'killed (car (car marked))) - (setcdr (car marked) (gnus-uncompress-range (cdr (car marked))))) - (setq marked (cdr marked)))) - (setq newsrc (cdr newsrc))))) - -(defun gnus-compress-newsrc-alist () - ;; Compress all lists of marked articles in the newsrc assoc. - (let ((newsrc gnus-newsrc-alist) - marked) - (while newsrc - (if (not (setq marked (nth 3 (car newsrc)))) - () - (while marked - (or (eq 'score (car (car marked))) - (eq 'bookmark (car (car marked))) - (eq 'killed (car (car marked))) - (setcdr (car marked) - (condition-case () - (gnus-compress-sequence - (sort (cdr (car marked)) '<) t) - (error (cdr (car marked)))))) - (setq marked (cdr marked)))) - (setq newsrc (cdr newsrc))))) - (defun gnus-newsrc-to-gnus-format () (setq gnus-newsrc-options "") (setq gnus-newsrc-options-n nil) @@ -13173,7 +16589,7 @@ If FORCE is non-nil, the .newsrc file is read." ;; can `eq' against it later. (set (setq options-symbol (intern "options" gnus-active-hashtb)) nil) (set (setq Options-symbol (intern "Options" gnus-active-hashtb)) nil) - + (while (not (eobp)) ;; We first read the first word on the line by narrowing and ;; then reading into `gnus-active-hashtb'. Most groups will @@ -13183,13 +16599,13 @@ If FORCE is non-nil, the .newsrc file is read." (point) (progn (skip-chars-forward "^ \t!:\n") (point))) (goto-char (point-min)) - (setq symbol + (setq symbol (and (/= (point-min) (point-max)) (let ((obarray gnus-active-hashtb)) (read buf)))) (widen) ;; Now, the symbol we have read is either `options' or a group - ;; name. If it is an options line, we just add it to a string. - (cond + ;; name. If it is an options line, we just add it to a string. + (cond ((or (eq symbol options-symbol) (eq symbol Options-symbol)) (setq gnus-newsrc-options @@ -13198,7 +16614,7 @@ If FORCE is non-nil, the .newsrc file is read." ;; .newsrc files only contain a single options line, we ;; don't give a damn, frankly, my dear. (concat gnus-newsrc-options - (buffer-substring + (buffer-substring (gnus-point-at-bol) ;; Options may continue on the next line. (or (and (re-search-forward "^[^ \t]" nil 'move) @@ -13206,6 +16622,9 @@ If FORCE is non-nil, the .newsrc file is read." (point))))) (forward-line -1)) (symbol + ;; Group names can be just numbers. + (when (numberp symbol) + (setq symbol (intern (int-to-string symbol) gnus-active-hashtb))) (or (boundp symbol) (set symbol nil)) ;; It was a group name. (setq subscribed (= (following-char) ?:) @@ -13221,10 +16640,10 @@ If FORCE is non-nil, the .newsrc file is read." ;; We are now at the beginning of the list of read articles. ;; We read them range by range. (while - (cond + (cond ((looking-at "[0-9]+") ;; We narrow and read a number instead of buffer-substring/ - ;; string-to-int because it's faster. narrow/widen is + ;; string-to-int because it's faster. narrow/widen is ;; faster than save-restriction/narrow, and save-restriction ;; produces a garbage object. (setq num1 (progn @@ -13238,14 +16657,14 @@ If FORCE is non-nil, the .newsrc file is read." (forward-char 1) (if (not (looking-at "[0-9]+")) ;; This is a buggy line, by we pretend that - ;; it's kinda OK. Perhaps the user should be - ;; dinged? + ;; it's kinda OK. Perhaps the user should be + ;; dinged? (setq reads (cons num1 reads)) - (setq reads - (cons + (setq reads + (cons (cons num1 (progn - (narrow-to-region (match-beginning 0) + (narrow-to-region (match-beginning 0) (match-end 0)) (read buf))) reads)) @@ -13261,73 +16680,70 @@ If FORCE is non-nil, the .newsrc file is read." nil) (t ;; Not numbers and not eol, so this might be a buggy - ;; line... - (or (eobp) + ;; line... + (or (eobp) ;; If it was eob instead of ?\n, we allow it. (progn ;; The line was buggy. (setq group nil) - (gnus-message 3 "Mangled line: %s" - (buffer-substring (gnus-point-at-bol) - (gnus-point-at-eol))) - (ding) - (sit-for 1))) + (gnus-error 3.1 "Mangled line: %s" + (buffer-substring (gnus-point-at-bol) + (gnus-point-at-eol))))) nil)) - ;; Skip past ", ". Spaces are illegal in these ranges, but + ;; Skip past ", ". Spaces are illegal in these ranges, but ;; we allow them, because it's a common mistake to put a ;; space after the comma. (skip-chars-forward ", ")) ;; We have already read .newsrc.eld, so we gently update the ;; data in the hash table with the information we have just - ;; read. - (if (not group) - () - (let ((info (nth 2 (gnus-gethash group gnus-newsrc-hashtb))) + ;; read. + (when group + (let ((info (gnus-get-info group)) level) (if info ;; There is an entry for this file in the alist. (progn - (setcar (nthcdr 2 info) (nreverse reads)) + (gnus-info-set-read info (nreverse reads)) ;; We update the level very gently. In fact, we ;; only change it if there's been a status change ;; from subscribed to unsubscribed, or vice versa. - (setq level (nth 1 info)) + (setq level (gnus-info-level info)) (cond ((and (<= level gnus-level-subscribed) (not subscribed)) (setq level (if reads - gnus-level-default-unsubscribed + gnus-level-default-unsubscribed (1+ gnus-level-default-unsubscribed)))) ((and (> level gnus-level-subscribed) subscribed) (setq level gnus-level-default-subscribed))) - (setcar (cdr info) level)) + (gnus-info-set-level info level)) ;; This is a new group. - (setq info (list group + (setq info (list group (if subscribed - gnus-level-default-subscribed + gnus-level-default-subscribed (if reads (1+ gnus-level-subscribed) gnus-level-default-unsubscribed)) (nreverse reads)))) (setq newsrc (cons info newsrc)))))) (forward-line 1)) - + (setq newsrc (nreverse newsrc)) (if (not already-read) () ;; We now have two newsrc lists - `newsrc', which is what we ;; have read from .newsrc, and `gnus-newsrc-alist', which is - ;; what we've read from .newsrc.eld. We have to merge these - ;; lists. We do this by "attaching" any (foreign) groups in the - ;; gnus-newsrc-alist to the (native) group that precedes them. + ;; what we've read from .newsrc.eld. We have to merge these + ;; lists. We do this by "attaching" any (foreign) groups in the + ;; gnus-newsrc-alist to the (native) group that precedes them. (let ((rc (cdr gnus-newsrc-alist)) (prev gnus-newsrc-alist) entry mentry) (while rc (or (null (nth 4 (car rc))) ; It's a native group. - (assoc (car (car rc)) newsrc) ; It's already in the alist. - (if (setq entry (assoc (car (car prev)) newsrc)) + (assoc (caar rc) newsrc) ; It's already in the alist. + (if (setq entry (assoc (caar prev) newsrc)) (setcdr (setq mentry (memq entry newsrc)) (cons (car rc) (cdr mentry))) (setq newsrc (cons (car rc) newsrc)))) @@ -13348,14 +16764,14 @@ If FORCE is non-nil, the .newsrc file is read." ;; (regexp2 . subscribe)...) ;; When handling new newsgroups, groups that match a `ignore' regexp ;; will be ignored, and groups that match a `subscribe' regexp will be -;; subscribed. A line like +;; subscribed. A line like ;; options -n !all rec.all ;; will lead to a list that looks like -;; (("^rec\\..+" . subscribe) +;; (("^rec\\..+" . subscribe) ;; ("^.+" . ignore)) ;; So all "rec.*" groups will be subscribed, while all the other -;; groups will be ignored. Note that "options -n !all rec.all" is very -;; different from "options -n rec.all !all". +;; groups will be ignored. Note that "options -n !all rec.all" is very +;; different from "options -n rec.all !all". (defun gnus-newsrc-parse-options (options) (let (out eol) (save-excursion @@ -13379,7 +16795,7 @@ If FORCE is non-nil, the .newsrc file is read." ;; We are only interested in "options -n" lines - we ;; ignore the other option lines. (while (re-search-forward "[ \t]-n" nil t) - (setq eol + (setq eol (or (save-excursion (and (re-search-forward "[ \t]-n" (gnus-point-at-eol) t) (- (point) 2))) @@ -13388,59 +16804,61 @@ If FORCE is non-nil, the .newsrc file is read." (while (re-search-forward "[^ \t,\n]+" eol t) (if (= (char-after (match-beginning 0)) ?!) ;; If the word begins with a bang (!), this is a "not" - ;; spec. We put this spec (minus the bang) and the + ;; spec. We put this spec (minus the bang) and the ;; symbol `ignore' into the list. - (setq out (cons (cons (concat - "^" (buffer-substring + (setq out (cons (cons (concat + "^" (buffer-substring (1+ (match-beginning 0)) (match-end 0))) 'ignore) out)) ;; There was no bang, so this is a "yes" spec. - (setq out (cons (cons (concat - "^" (buffer-substring (match-beginning 0) - (match-end 0))) + (setq out (cons (cons (concat "^" (match-string 0)) 'subscribe) out))))) - + (setq gnus-newsrc-options-n out)))) - -(defun gnus-save-newsrc-file () +(defun gnus-save-newsrc-file (&optional force) "Save .newsrc file." ;; Note: We cannot save .newsrc file if all newsgroups are removed ;; from the variable gnus-newsrc-alist. - (and (or gnus-newsrc-alist gnus-killed-list) - gnus-current-startup-file - (progn - (run-hooks 'gnus-save-newsrc-hook) - (save-excursion - (if (and gnus-use-dribble-file - (or (not gnus-dribble-buffer) - (not (buffer-name gnus-dribble-buffer)) - (zerop (save-excursion - (set-buffer gnus-dribble-buffer) - (buffer-size))))) - (gnus-message 4 "(No changes need to be saved)") - (if gnus-save-newsrc-file - (progn - (gnus-message 5 "Saving %s..." gnus-current-startup-file) - ;; Make backup file of master newsrc. - (gnus-gnus-to-newsrc-format) - (gnus-message 5 "Saving %s...done" - gnus-current-startup-file))) - ;; Quickly loadable .newsrc. - (set-buffer (get-buffer-create " *Gnus-newsrc*")) - (make-local-variable 'version-control) - (setq version-control 'never) - (setq buffer-file-name (concat gnus-current-startup-file ".eld")) - (gnus-add-current-to-buffer-list) - (buffer-disable-undo (current-buffer)) - (erase-buffer) - (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file) - (gnus-gnus-to-quick-newsrc-format) - (save-buffer) - (kill-buffer (current-buffer)) - (gnus-message 5 "Saving %s.eld...done" gnus-current-startup-file) - (gnus-dribble-delete-file)))))) + (when (and (or gnus-newsrc-alist gnus-killed-list) + gnus-current-startup-file) + (save-excursion + (if (and (or gnus-use-dribble-file gnus-slave) + (not force) + (or (not gnus-dribble-buffer) + (not (buffer-name gnus-dribble-buffer)) + (zerop (save-excursion + (set-buffer gnus-dribble-buffer) + (buffer-size))))) + (gnus-message 4 "(No changes need to be saved)") + (run-hooks 'gnus-save-newsrc-hook) + (if gnus-slave + (gnus-slave-save-newsrc) + ;; Save .newsrc. + (when gnus-save-newsrc-file + (gnus-message 5 "Saving %s..." gnus-current-startup-file) + (gnus-gnus-to-newsrc-format) + (gnus-message 5 "Saving %s...done" gnus-current-startup-file)) + ;; Save .newsrc.eld. + (set-buffer (get-buffer-create " *Gnus-newsrc*")) + (make-local-variable 'version-control) + (setq version-control 'never) + (setq buffer-file-name + (concat gnus-current-startup-file ".eld")) + (setq default-directory (file-name-directory buffer-file-name)) + (gnus-add-current-to-buffer-list) + (buffer-disable-undo (current-buffer)) + (erase-buffer) + (gnus-message 5 "Saving %s.eld..." gnus-current-startup-file) + (gnus-gnus-to-quick-newsrc-format) + (run-hooks 'gnus-save-quick-newsrc-hook) + (save-buffer) + (kill-buffer (current-buffer)) + (gnus-message + 5 "Saving %s.eld...done" gnus-current-startup-file)) + (gnus-dribble-delete-file) + (gnus-group-set-mode-line))))) (defun gnus-gnus-to-quick-newsrc-format () "Insert Gnus variables such as gnus-newsrc-alist in lisp format." @@ -13449,97 +16867,162 @@ If FORCE is non-nil, the .newsrc file is read." (insert ";; to read .newsrc.\n") (insert "(setq gnus-newsrc-file-version " (prin1-to-string gnus-version) ")\n") - (let ((variables gnus-variable-list) - (inhibit-quit t) + (let ((variables + (if gnus-save-killed-list gnus-variable-list + ;; Remove the `gnus-killed-list' from the list of variables + ;; to be saved, if required. + (delq 'gnus-killed-list (copy-sequence gnus-variable-list)))) + ;; Peel off the "dummy" group. (gnus-newsrc-alist (cdr gnus-newsrc-alist)) variable) - ;; insert lisp expressions. - (gnus-compress-newsrc-alist) + ;; Insert the variables into the file. (while variables - (setq variable (car variables)) - (and (boundp variable) - (symbol-value variable) - (or gnus-save-killed-list (not (eq variable 'gnus-killed-list))) - (insert "(setq " (symbol-name variable) " '" - (prin1-to-string (symbol-value variable)) - ")\n")) - (setq variables (cdr variables))) - (gnus-uncompress-newsrc-alist))) - + (when (and (boundp (setq variable (pop variables))) + (symbol-value variable)) + (insert "(setq " (symbol-name variable) " '") + (prin1 (symbol-value variable) (current-buffer)) + (insert ")\n"))))) (defun gnus-gnus-to-newsrc-format () ;; Generate and save the .newsrc file. - (let ((newsrc (cdr gnus-newsrc-alist)) - info ranges range) - (save-excursion - (set-buffer (create-file-buffer gnus-current-startup-file)) + (save-excursion + (set-buffer (create-file-buffer gnus-current-startup-file)) + (let ((newsrc (cdr gnus-newsrc-alist)) + (standard-output (current-buffer)) + info ranges range method) (setq buffer-file-name gnus-current-startup-file) + (setq default-directory (file-name-directory buffer-file-name)) (buffer-disable-undo (current-buffer)) (erase-buffer) ;; Write options. (if gnus-newsrc-options (insert gnus-newsrc-options)) ;; Write subscribed and unsubscribed. - (while newsrc - (setq info (car newsrc)) - (if (not (nth 4 info)) ;Don't write foreign groups to .newsrc. - (progn - (insert (car info) (if (> (nth 1 info) gnus-level-subscribed) - "!" ":")) - (if (setq ranges (nth 2 info)) - (progn - (insert " ") - (if (not (listp (cdr ranges))) - (if (= (car ranges) (cdr ranges)) - (insert (int-to-string (car ranges))) - (insert (int-to-string (car ranges)) "-" - (int-to-string (cdr ranges)))) - (while ranges - (setq range (car ranges) - ranges (cdr ranges)) - (if (or (atom range) (= (car range) (cdr range))) - (insert (int-to-string - (or (and (atom range) range) - (car range)))) - (insert (int-to-string (car range)) "-" - (int-to-string (cdr range)))) - (if ranges (insert ",")))))) - (insert "\n"))) - (setq newsrc (cdr newsrc))) + (while (setq info (pop newsrc)) + ;; Don't write foreign groups to .newsrc. + (when (or (null (setq method (gnus-info-method info))) + (equal method "native") + (gnus-server-equal method gnus-select-method)) + (insert (gnus-info-group info) + (if (> (gnus-info-level info) gnus-level-subscribed) + "!" ":")) + (when (setq ranges (gnus-info-read info)) + (insert " ") + (if (not (listp (cdr ranges))) + (if (= (car ranges) (cdr ranges)) + (princ (car ranges)) + (princ (car ranges)) + (insert "-") + (princ (cdr ranges))) + (while (setq range (pop ranges)) + (if (or (atom range) (= (car range) (cdr range))) + (princ (or (and (atom range) range) (car range))) + (princ (car range)) + (insert "-") + (princ (cdr range))) + (if ranges (insert ","))))) + (insert "\n"))) (make-local-variable 'version-control) (setq version-control 'never) ;; It has been reported that sometime the modtime on the .newsrc - ;; file seems to be off. We really do want to overwrite it, so - ;; we clear the modtime here before saving. It's a bit odd, - ;; though... + ;; file seems to be off. We really do want to overwrite it, so + ;; we clear the modtime here before saving. It's a bit odd, + ;; though... ;; sometimes the modtime clear isn't sufficient. most brute force: ;; delete the silly thing entirely first. but this fails to provide ;; such niceties as .newsrc~ creation. (if gnus-modtime-botch (delete-file gnus-startup-file) (clear-visited-file-modtime)) + (run-hooks 'gnus-save-standard-newsrc-hook) (save-buffer) (kill-buffer (current-buffer))))) + +;;; +;;; Slave functions. +;;; + +(defun gnus-slave-save-newsrc () + (save-excursion + (set-buffer gnus-dribble-buffer) + (let ((slave-name + (make-temp-name (concat gnus-current-startup-file "-slave-")))) + (write-region (point-min) (point-max) slave-name nil 'nomesg)))) + +(defun gnus-master-read-slave-newsrc () + (let ((slave-files + (directory-files + (file-name-directory gnus-current-startup-file) + t (concat + "^" (regexp-quote + (concat + (file-name-nondirectory gnus-current-startup-file) + "-slave-"))) + t)) + file) + (if (not slave-files) + () ; There are no slave files to read. + (gnus-message 7 "Reading slave newsrcs...") + (save-excursion + (set-buffer (get-buffer-create " *gnus slave*")) + (buffer-disable-undo (current-buffer)) + (setq slave-files + (sort (mapcar (lambda (file) + (list (nth 5 (file-attributes file)) file)) + slave-files) + (lambda (f1 f2) + (or (< (caar f1) (caar f2)) + (< (nth 1 (car f1)) (nth 1 (car f2))))))) + (while slave-files + (erase-buffer) + (setq file (nth 1 (car slave-files))) + (insert-file-contents file) + (if (condition-case () + (progn + (eval-buffer (current-buffer)) + t) + (error + (gnus-error 3.2 "Possible error in %s" file) + nil)) + (or gnus-slave ; Slaves shouldn't delete these files. + (condition-case () + (delete-file file) + (error nil)))) + (setq slave-files (cdr slave-files)))) + (gnus-message 7 "Reading slave newsrcs...done")))) + + +;;; +;;; Group description. +;;; + (defun gnus-read-all-descriptions-files () - (let ((methods (cons gnus-select-method gnus-secondary-select-methods))) + (let ((methods (cons gnus-select-method + (nconc + (when gnus-message-archive-method + (list "archive")) + gnus-secondary-select-methods)))) (while methods (gnus-read-descriptions-file (car methods)) (setq methods (cdr methods))) t)) (defun gnus-read-descriptions-file (&optional method) - (let ((method (or method gnus-select-method))) + (let ((method (or method gnus-select-method)) + group) + (when (stringp method) + (setq method (gnus-server-to-method method))) ;; We create the hashtable whether we manage to read the desc file ;; to avoid trying to re-read after a failed read. (or gnus-description-hashtb - (setq gnus-description-hashtb + (setq gnus-description-hashtb (gnus-make-hashtable (length gnus-active-hashtb)))) ;; Mark this method's desc file as read. (gnus-sethash (gnus-group-prefixed-name "" method) "Has read" gnus-description-hashtb) (gnus-message 5 "Reading descriptions file via %s..." (car method)) - (cond + (cond ((not (gnus-check-server method)) (gnus-message 1 "Couldn't open server") nil) @@ -13547,634 +17030,172 @@ If FORCE is non-nil, the .newsrc file is read." (gnus-message 1 "Couldn't read newsgroups descriptions") nil) (t - (let (group) - (save-excursion - (save-restriction - (set-buffer nntp-server-buffer) - (goto-char (point-min)) - (if (or (search-forward "\n.\n" nil t) + (save-excursion + (save-restriction + (set-buffer nntp-server-buffer) + (goto-char (point-min)) + (when (or (search-forward "\n.\n" nil t) (goto-char (point-max))) - (progn - (beginning-of-line) - (narrow-to-region (point-min) (point)))) - (goto-char (point-min)) - (while (not (eobp)) - ;; If we get an error, we set group to 0, which is not a - ;; symbol... - (setq group - (condition-case () - (let ((obarray gnus-description-hashtb)) - ;; Group is set to a symbol interned in this - ;; hash table. - (read nntp-server-buffer)) - (error 0))) - (skip-chars-forward " \t") - ;; ... which leads to this line being effectively ignored. - (and (symbolp group) - (set group (buffer-substring - (point) (progn (end-of-line) (point))))) - (forward-line 1)))) - (gnus-message 5 "Reading descriptions file...done") - t))))) + (beginning-of-line) + (narrow-to-region (point-min) (point))) + ;; If these are groups from a foreign select method, we insert the + ;; group prefix in front of the group names. + (and method (not (gnus-server-equal + (gnus-server-get-method nil method) + (gnus-server-get-method nil gnus-select-method))) + (let ((prefix (gnus-group-prefixed-name "" method))) + (goto-char (point-min)) + (while (and (not (eobp)) + (progn (insert prefix) + (zerop (forward-line 1))))))) + (goto-char (point-min)) + (while (not (eobp)) + ;; If we get an error, we set group to 0, which is not a + ;; symbol... + (setq group + (condition-case () + (let ((obarray gnus-description-hashtb)) + ;; Group is set to a symbol interned in this + ;; hash table. + (read nntp-server-buffer)) + (error 0))) + (skip-chars-forward " \t") + ;; ... which leads to this line being effectively ignored. + (and (symbolp group) + (set group (buffer-substring + (point) (progn (end-of-line) (point))))) + (forward-line 1)))) + (gnus-message 5 "Reading descriptions file...done") + t)))) (defun gnus-group-get-description (group) - ;; Get the description of a group by sending XGTITLE to the server. - (and (gnus-request-group-description group) - (save-excursion - (set-buffer nntp-server-buffer) - (goto-char (point-min)) - (and (looking-at "[^ \t]+[ \t]+\\(.*\\)") - (buffer-substring (match-beginning 1) (match-end 1)))))) + "Get the description of a group by sending XGTITLE to the server." + (when (gnus-request-group-description group) + (save-excursion + (set-buffer nntp-server-buffer) + (goto-char (point-min)) + (when (looking-at "[^ \t]+[ \t]+\\(.*\\)") + (match-string 1))))) + ;;; -;;; Server +;;; Buffering of read articles. ;;; -(defvar gnus-server-mode-hook nil - "Hook run in `gnus-server-mode' buffers.") - -(defconst gnus-server-line-format " {%(%h:%w%)}\n" - "Format of server lines. -It works along the same lines as a normal formatting string, -with some simple extensions.") - -(defvar gnus-server-mode-line-format "Gnus List of servers" - "The format specification for the server mode line.") - -(defconst gnus-server-line-format-alist - (list (list ?h 'how ?s) - (list ?n 'name ?s) - (list ?w 'where ?s) - )) - -(defconst gnus-server-mode-line-format-alist - (list (list ?S 'news-server ?s) - (list ?M 'news-method ?s) - (list ?u 'user-defined ?s))) - -(defvar gnus-server-line-format-spec nil) -(defvar gnus-server-mode-line-format-spec nil) -(defvar gnus-server-killed-servers nil) - -(defvar gnus-server-mode-map nil) -(put 'gnus-server-mode 'mode-class 'special) - -(if gnus-server-mode-map - nil - (setq gnus-server-mode-map (make-sparse-keymap)) - (suppress-keymap gnus-server-mode-map) - (define-key gnus-server-mode-map " " 'gnus-server-read-server) - (define-key gnus-server-mode-map "\r" 'gnus-server-read-server) - (define-key gnus-server-mode-map gnus-mouse-2 'gnus-server-pick-server) - (define-key gnus-server-mode-map "q" 'gnus-server-exit) - (define-key gnus-server-mode-map "l" 'gnus-server-list-servers) - (define-key gnus-server-mode-map "k" 'gnus-server-kill-server) - (define-key gnus-server-mode-map "y" 'gnus-server-yank-server) - (define-key gnus-server-mode-map "c" 'gnus-server-copy-server) - (define-key gnus-server-mode-map "a" 'gnus-server-add-server) - (define-key gnus-server-mode-map "e" 'gnus-server-edit-server)) - -(defun gnus-server-mode () - "Major mode for listing and editing servers. - -All normal editing commands are switched off. -\\ - -For more in-depth information on this mode, read the manual (`\\[gnus-info-find-node]'). - -The following commands are available: - -\\{gnus-server-mode-map}" - (interactive) - (if gnus-visual (gnus-server-make-menu-bar)) - (kill-all-local-variables) - (gnus-simplify-mode-line) - (setq major-mode 'gnus-server-mode) - (setq mode-name "Server") - ; (gnus-group-set-mode-line) - (setq mode-line-process nil) - (use-local-map gnus-server-mode-map) - (buffer-disable-undo (current-buffer)) - (setq truncate-lines t) - (setq buffer-read-only t) - (run-hooks 'gnus-server-mode-hook)) - -(defun gnus-server-insert-server-line (sformat name method) - (let* ((sformat (or sformat gnus-server-line-format-spec)) - (how (car method)) - (where (nth 1 method)) - b) - (beginning-of-line) - (setq b (point)) - ;; Insert the text. - (insert (eval sformat)) - (add-text-properties b (1+ b) (list 'gnus-server (intern name))))) - -(defun gnus-server-setup-buffer () - (if (get-buffer gnus-server-buffer) - () - (save-excursion - (set-buffer (get-buffer-create gnus-server-buffer)) - (gnus-server-mode) - (and gnus-carpal (gnus-carpal-setup-buffer 'server))))) - -(defun gnus-server-prepare () - (setq gnus-server-mode-line-format-spec - (gnus-parse-format gnus-server-mode-line-format - gnus-server-mode-line-format-alist)) - (setq gnus-server-line-format-spec - (gnus-parse-format gnus-server-line-format - gnus-server-line-format-alist)) - (let ((alist gnus-server-alist) - (buffer-read-only nil)) - (erase-buffer) - (while alist - (gnus-server-insert-server-line nil (car (car alist)) (cdr (car alist))) - (setq alist (cdr alist)))) - (goto-char (point-min)) - (gnus-server-position-cursor)) - -(defun gnus-server-server-name () - (let ((server (get-text-property (gnus-point-at-bol) 'gnus-server))) - (and server (symbol-name server)))) +(defvar gnus-backlog-buffer " *Gnus Backlog*") +(defvar gnus-backlog-articles nil) +(defvar gnus-backlog-hashtb nil) -(defalias 'gnus-server-position-cursor 'gnus-goto-colon) - -(defconst gnus-server-edit-buffer "*Gnus edit server*") +(defun gnus-backlog-buffer () + "Return the backlog buffer." + (or (get-buffer gnus-backlog-buffer) + (save-excursion + (set-buffer (get-buffer-create gnus-backlog-buffer)) + (buffer-disable-undo (current-buffer)) + (setq buffer-read-only t) + (gnus-add-current-to-buffer-list) + (get-buffer gnus-backlog-buffer)))) + +(defun gnus-backlog-setup () + "Initialize backlog variables." + (unless gnus-backlog-hashtb + (setq gnus-backlog-hashtb (make-vector 1023 0)))) + +(gnus-add-shutdown 'gnus-backlog-shutdown 'gnus) + +(defun gnus-backlog-shutdown () + "Clear all backlog variables and buffers." + (when (get-buffer gnus-backlog-buffer) + (kill-buffer gnus-backlog-buffer)) + (setq gnus-backlog-hashtb nil + gnus-backlog-articles nil)) + +(defun gnus-backlog-enter-article (group number buffer) + (gnus-backlog-setup) + (let ((ident (intern (concat group ":" (int-to-string number)) + gnus-backlog-hashtb)) + b) + (if (memq ident gnus-backlog-articles) + () ; It's already kept. + ;; Remove the oldest article, if necessary. + (and (numberp gnus-keep-backlog) + (>= (length gnus-backlog-articles) gnus-keep-backlog) + (gnus-backlog-remove-oldest-article)) + (setq gnus-backlog-articles (cons ident gnus-backlog-articles)) + ;; Insert the new article. + (save-excursion + (set-buffer (gnus-backlog-buffer)) + (let (buffer-read-only) + (goto-char (point-max)) + (or (bolp) (insert "\n")) + (setq b (point)) + (insert-buffer-substring buffer) + ;; Tag the beginning of the article with the ident. + (gnus-put-text-property b (1+ b) 'gnus-backlog ident)))))) -(defun gnus-server-update-server (server) +(defun gnus-backlog-remove-oldest-article () (save-excursion - (set-buffer gnus-server-buffer) - (let ((buffer-read-only nil) - (info (cdr (assoc server gnus-server-alist)))) - (gnus-dribble-enter - (concat "(gnus-server-set-info \"" server "\" '" - (prin1-to-string info) ")")) - ;; Buffer may be narrowed. - (save-restriction - (widen) - (if (gnus-server-goto-server server) - (delete-region (progn (beginning-of-line) (point)) - (progn (forward-line 1) (point)))) - (let ((entry (assoc server gnus-server-alist))) - (gnus-server-insert-server-line nil (car entry) (cdr entry)) - (gnus-server-position-cursor)))))) - -(defun gnus-server-set-info (server info) - ;; Enter a select method into the virtual server alist. - (gnus-dribble-enter - (concat "(gnus-server-set-info \"" server "\" '" - (prin1-to-string info) ")")) - (let* ((server (nth 1 info)) - (entry (assoc server gnus-server-alist))) - (if entry (setcdr entry info) - (setq gnus-server-alist - (nconc gnus-server-alist (list (cons server info))))))) - -(defun gnus-server-to-method (server) - ;; Map virtual server names to select methods. - (or (and (equal server "native") gnus-select-method) - (cdr (assoc server gnus-server-alist)))) - -(defun gnus-server-extend-method (group method) - ;; This function "extends" a virtual server. If the server is - ;; "hello", and the select method is ("hello" (my-var "something")) - ;; in the group "alt.alt", this will result in a new virtual server - ;; called "helly+alt.alt". - (let ((entry - (gnus-copy-sequence - (if (equal (car method) "native") gnus-select-method - (cdr (assoc (car method) gnus-server-alist)))))) - (setcar (cdr entry) (concat (nth 1 entry) "+" group)) - (nconc entry (cdr method)))) - -(defun gnus-server-get-method (group method) - ;; Input either a server name, and extended server name, or a - ;; select method, and return a select method. - (cond ((stringp method) - (gnus-server-to-method method)) - ((and (stringp (car method)) group) - (gnus-server-extend-method group method)) - (t - (gnus-server-add-address method)))) - -(defun gnus-server-add-address (method) - (let ((method-name (symbol-name (car method)))) - (if (and (memq 'address (assoc method-name gnus-valid-select-methods)) - (not (assq (intern (concat method-name "-address")) method))) - (append method (list (list (intern (concat method-name "-address")) - (nth 1 method)))) - method))) - -(defun gnus-server-equal (s1 s2) - (or (equal s1 s2) - (and (= (length s1) (length s2)) - (progn - (while (and s1 (member (car s1) s2)) - (setq s1 (cdr s1))) - (null s1))))) - -;;; Interactive server functions. - -(defun gnus-server-kill-server (server) - "Kill the server on the current line." - (interactive (list (gnus-server-server-name))) - (or (gnus-server-goto-server server) - (if server (error "No such server: %s" server) - (error "No server on the current line"))) - (gnus-dribble-enter "") - (let ((buffer-read-only nil)) - (delete-region (progn (beginning-of-line) (point)) - (progn (forward-line 1) (point)))) - (setq gnus-server-killed-servers - (cons (assoc server gnus-server-alist) gnus-server-killed-servers)) - (setq gnus-server-alist (delq (car gnus-server-killed-servers) - gnus-server-alist)) - (gnus-server-position-cursor)) - -(defun gnus-server-yank-server () - "Yank the previously killed server." - (interactive) - (or gnus-server-killed-servers - (error "No killed servers to be yanked")) - (let ((alist gnus-server-alist) - (server (gnus-server-server-name)) - (killed (car gnus-server-killed-servers))) - (if (not server) - (setq gnus-server-alist (nconc gnus-server-alist (list killed))) - (if (string= server (car (car gnus-server-alist))) - (setq gnus-server-alist (cons killed gnus-server-alist)) - (while (and (cdr alist) - (not (string= server (car (car (cdr alist)))))) - (setq alist (cdr alist))) - (setcdr alist (cons killed (cdr alist))))) - (gnus-server-update-server (car killed)) - (setq gnus-server-killed-servers (cdr gnus-server-killed-servers)) - (gnus-server-position-cursor))) - -(defun gnus-server-exit () - "Return to the group buffer." - (interactive) - (kill-buffer (current-buffer)) - (switch-to-buffer gnus-group-buffer)) - -(defun gnus-server-list-servers () - "List all available servers." - (interactive) - (let ((cur (gnus-server-server-name))) - (gnus-server-prepare) - (if cur (gnus-server-goto-server cur) - (goto-char (point-max)) - (forward-line -1)) - (gnus-server-position-cursor))) - -(defun gnus-server-copy-server (from to) - (interactive - (list - (or (gnus-server-server-name) - (error "No server on the current line")) - (read-string "Copy to: "))) - (or from (error "No server on current line")) - (or (and to (not (string= to ""))) (error "No name to copy to")) - (and (assoc to gnus-server-alist) (error "%s already exists" to)) - (or (assoc from gnus-server-alist) - (error "%s: no such server" from)) - (let ((to-entry (gnus-copy-sequence (assoc from gnus-server-alist)))) - (setcar to-entry to) - (setcar (nthcdr 2 to-entry) to) - (setq gnus-server-killed-servers - (cons to-entry gnus-server-killed-servers)) - (gnus-server-yank-server))) - -(defun gnus-server-add-server (how where) - (interactive - (list (intern (completing-read "Server method: " - gnus-valid-select-methods nil t)) - (read-string "Server name: "))) - (setq gnus-server-killed-servers - (cons (list where how where) gnus-server-killed-servers)) - (gnus-server-yank-server)) - -(defun gnus-server-goto-server (server) - "Jump to a server line." - (interactive - (list (completing-read "Goto server: " gnus-server-alist nil t))) - (let ((to (text-property-any (point-min) (point-max) - 'gnus-server (intern server)))) - (and to - (progn - (goto-char to) - (gnus-server-position-cursor))))) - -(defun gnus-server-edit-server (server) - "Edit the server on the current line." - (interactive (list (gnus-server-server-name))) - (or server - (error "No server on current line")) - (let ((winconf (current-window-configuration))) - (get-buffer-create gnus-server-edit-buffer) - (gnus-configure-windows 'edit-server) - (gnus-add-current-to-buffer-list) - (emacs-lisp-mode) - (make-local-variable 'gnus-prev-winconf) - (setq gnus-prev-winconf winconf) - (use-local-map (copy-keymap (current-local-map))) - (let ((done-func '(lambda () - "Exit editing mode and update the information." - (interactive) - (gnus-server-edit-server-done 'group)))) - (setcar (cdr (nth 4 done-func)) server) - (local-set-key "\C-c\C-c" done-func)) - (erase-buffer) - (insert ";; Type `C-c C-c' after you have edited the server.\n\n") - (insert (pp-to-string (cdr (assoc server gnus-server-alist)))))) - -(defun gnus-server-edit-server-done (server) - (interactive) - (set-buffer (get-buffer-create gnus-server-edit-buffer)) - (goto-char (point-min)) - (let ((form (read (current-buffer))) - (winconf gnus-prev-winconf)) - (gnus-server-set-info server form) - (kill-buffer (current-buffer)) - (and winconf (set-window-configuration winconf)) - (set-buffer gnus-server-buffer) - (gnus-server-update-server (gnus-server-server-name)) - (gnus-server-list-servers) - (gnus-server-position-cursor))) - -(defun gnus-server-read-server (server) - "Browse a server." - (interactive (list (gnus-server-server-name))) - (gnus-browse-foreign-server (gnus-server-to-method server) (current-buffer))) - -(defun gnus-mouse-pick-server (e) - (interactive "e") - (mouse-set-point e) - (gnus-server-read-server (gnus-server-server-name))) - -;;; -;;; entry points into gnus-score.el -;;; - -;;; Finding score files. - -(defvar gnus-global-score-files nil - "*List of global score files and directories. -Set this variable if you want to use people's score files. One entry -for each score file or each score file directory. Gnus will decide -by itself what score files are applicable to which group. - -Say you want to use the single score file -\"/ftp.ifi.uio.no@ftp:/pub/larsi/ding/score/soc.motss.SCORE\" and all -score files in the \"/ftp.some-where:/pub/score\" directory. - - (setq gnus-global-score-files - '(\"/ftp.ifi.uio.no:/pub/larsi/ding/score/soc.motss.SCORE\" - \"/ftp.some-where:/pub/score\"))") - -(defun gnus-score-score-files (group) - "Return a list of all possible score files." - ;; Search and set any global score files. - (and gnus-global-score-files - (or gnus-internal-global-score-files - (gnus-score-search-global-directories gnus-global-score-files))) - ;; Fix the kill-file dir variable. - (setq gnus-kill-files-directory - (file-name-as-directory - (or gnus-kill-files-directory "~/News/"))) - ;; If we can't read it, there are no score files. - (if (not (file-exists-p (expand-file-name gnus-kill-files-directory))) - (setq gnus-score-file-list nil) - (if (gnus-use-long-file-name 'not-score) - ;; We want long file names. - (if (or (not gnus-score-file-list) - (not (car gnus-score-file-list)) - (gnus-file-newer-than gnus-kill-files-directory - (car gnus-score-file-list))) - (setq gnus-score-file-list - (cons (nth 5 (file-attributes gnus-kill-files-directory)) - (nreverse - (directory-files - gnus-kill-files-directory t - (gnus-score-file-regexp)))))) - ;; We do not use long file names, so we have to do some - ;; directory traversing. - (let ((mdir (length (expand-file-name gnus-kill-files-directory))) - (suffixes (list gnus-score-file-suffix gnus-adaptive-file-suffix)) - dir files suffix) - (while suffixes - (setq dir (expand-file-name - (concat gnus-kill-files-directory - (gnus-replace-chars-in-string group ?. ?/)))) - (setq dir (gnus-replace-chars-in-string dir ?: ?/)) - (setq suffix (car suffixes) - suffixes (cdr suffixes)) - (if (file-exists-p (concat dir "/" suffix)) - (setq files (cons (concat dir "/" suffix) files))) - (while (>= (1+ (length dir)) mdir) - (and (file-exists-p (concat dir "/all/" suffix)) - (setq files (cons (concat dir "/all/" suffix) files))) - (string-match "/[^/]*$" dir) - (setq dir (substring dir 0 (match-beginning 0))))) - (setq gnus-score-file-list - (cons nil (nreverse files))))) - (cdr gnus-score-file-list))) - -(defun gnus-score-file-regexp () - (concat "\\(" gnus-score-file-suffix - "\\|" gnus-adaptive-file-suffix "\\)$")) - -(defun gnus-score-find-bnews (group) - "Return a list of score files for GROUP. -The score files are those files in the ~/News directory which matches -GROUP using BNews sys file syntax." - (let* ((sfiles (append (gnus-score-score-files group) - gnus-internal-global-score-files)) - (kill-dir (file-name-as-directory - (expand-file-name gnus-kill-files-directory))) - (klen (length kill-dir)) - ofiles not-match regexp) - (save-excursion - (set-buffer (get-buffer-create "*gnus score files*")) - (buffer-disable-undo (current-buffer)) - ;; Go through all score file names and create regexp with them - ;; as the source. - (while sfiles - (erase-buffer) - (insert (car sfiles)) - (goto-char (point-min)) - ;; First remove the suffix itself. - (re-search-forward (concat "." (gnus-score-file-regexp))) - (replace-match "" t t) - (goto-char (point-min)) - (if (looking-at (regexp-quote kill-dir)) - ;; If the file name was just "SCORE", `klen' is one character - ;; too much. - (delete-char (min (1- (point-max)) klen)) - (goto-char (point-max)) - (search-backward "/") - (delete-region (1+ (point)) (point-min))) - ;; If short file names were used, we have to translate slashes. - (goto-char (point-min)) - (while (re-search-forward "[/:]" nil t) - (replace-match "." t t)) - ;; Kludge to get rid of "nntp+" problems. - (goto-char (point-min)) - (and (looking-at "nn[a-z]+\\+") - (progn - (search-forward "+") - (forward-char -1) - (insert "\\"))) - ;; Translate ".all" to "[./].*"; - (while (search-forward ".all" nil t) - (replace-match "[./:].*" t t)) - (goto-char (point-min)) - ;; Translate "all" to ".*". - (while (search-forward "all" nil t) - (replace-match ".*" t t)) - (goto-char (point-min)) - ;; Deal with "not."s. - (if (looking-at "not.") - (progn - (setq not-match t) - (setq regexp (buffer-substring 5 (point-max)))) - (setq regexp (buffer-substring 1 (point-max))) - (setq not-match nil)) - ;; Finally - if this resulting regexp matches the group name, - ;; we add this score file to the list of score files - ;; applicable to this group. - (if (or (and not-match - (not (string-match regexp group))) - (and (not not-match) - (string-match regexp group))) - (setq ofiles (cons (car sfiles) ofiles))) - (setq sfiles (cdr sfiles))) - (kill-buffer (current-buffer)) - ;; Slight kludge here - the last score file returned should be - ;; the local score file, whether it exists or not. This is so - ;; that any score commands the user enters will go to the right - ;; file, and not end up in some global score file. - (let ((localscore - (expand-file-name - (if (gnus-use-long-file-name 'not-score) - (concat gnus-kill-files-directory group "." - gnus-score-file-suffix) - (concat gnus-kill-files-directory - (gnus-replace-chars-in-string group ?. ?/ ?: ?/) - "/" gnus-score-file-suffix))))) - ;; The local score file might already be there, but it's - ;; supposed to be the very last file, so we delete it from the - ;; list if it's already there, and add it to the head of the - ;; list. - (setq ofiles (cons localscore (delete localscore ofiles)))) - (nreverse ofiles)))) - -(defun gnus-score-find-single (group) - "Return list containing the score file for GROUP." - (list (gnus-score-file-name group gnus-adaptive-file-suffix) - (gnus-score-file-name group))) - -(defun gnus-score-find-hierarchical (group) - "Return list of score files for GROUP. -This includes the score file for the group and all its parents." - (let ((all (copy-sequence '(nil))) - (start 0)) - (while (string-match "\\." group (1+ start)) - (setq start (match-beginning 0)) - (setq all (cons (substring group 0 start) all))) - (setq all (cons group all)) - (nconc - (mapcar (lambda (newsgroup) - (gnus-score-file-name newsgroup gnus-adaptive-file-suffix)) - (setq all (nreverse all))) - (mapcar 'gnus-score-file-name all)))) - -(defvar gnus-score-file-alist-cache nil) - -(defun gnus-score-find-alist (group) - "Return list of score files for GROUP. -The list is determined from the variable gnus-score-file-alist." - (let ((alist gnus-score-file-multiple-match-alist) - score-files) - ;; if this group has been seen before, return the cached entry - (if (setq score-files (assoc group gnus-score-file-alist-cache)) - (cdr score-files) ;ensures caching groups with no matches - ;; handle the multiple match alist - (while alist - (and (string-match (car (car alist)) group) - (setq score-files - (nconc score-files (copy-sequence (cdr (car alist)))))) - (setq alist (cdr alist))) - (setq alist gnus-score-file-single-match-alist) - ;; handle the single match alist - (while alist - (and (string-match (car (car alist)) group) - ;; progn used just in case ("regexp") has no files - ;; and score-files is still nil. -sj - ;; this can be construed as a "stop searching here" feature :> - ;; and used to simplify regexps in the single-alist - (progn - (setq score-files - (nconc score-files (copy-sequence (cdr (car alist))))) - (setq alist nil))) - (setq alist (cdr alist))) - ;; cache the score files - (setq gnus-score-file-alist-cache - (cons (cons group score-files) gnus-score-file-alist-cache)) - score-files))) - - -(defun gnus-possibly-score-headers (&optional trace) - (let ((func gnus-score-find-score-files-function) - score-files) - (and func (not (listp func)) - (setq func (list func))) - ;; Go through all the functions for finding score files (or actual - ;; scores) and add them to a list. - (setq score-files (gnus-score-find-alist gnus-newsgroup-name)) - (while func - (and (symbolp (car func)) - (fboundp (car func)) - (setq score-files - (nconc score-files (funcall (car func) gnus-newsgroup-name)))) - (setq func (cdr func))) - (if score-files (gnus-score-headers score-files trace)))) - -(defun gnus-score-file-name (newsgroup &optional suffix) - "Return the name of a score file for NEWSGROUP." - (let ((suffix (or suffix gnus-score-file-suffix))) - (cond - ((or (null newsgroup) - (string-equal newsgroup "")) - ;; The global score file is placed at top of the directory. - (expand-file-name - suffix (or gnus-kill-files-directory "~/News"))) - ((gnus-use-long-file-name 'not-score) - ;; Append ".SCORE" to newsgroup name. - (expand-file-name (concat (gnus-newsgroup-savable-name newsgroup) - "." suffix) - (or gnus-kill-files-directory "~/News"))) - (t - ;; Place "SCORE" under the hierarchical directory. - (expand-file-name (concat (gnus-newsgroup-directory-form newsgroup) - "/" suffix) - (or gnus-kill-files-directory "~/News")))))) - -(defun gnus-score-search-global-directories (files) - "Scan all global score directories for score files." - ;; Set the variable `gnus-internal-global-score-files' to all - ;; available global score files. - (interactive (list gnus-global-score-files)) - (let (out) - (while files - (if (string-match "/$" (car files)) - (setq out (nconc (directory-files - (car files) t - (concat (gnus-score-file-regexp) "$")))) - (setq out (cons (car files) out))) - (setq files (cdr files))) - (setq gnus-internal-global-score-files out))) + (set-buffer (gnus-backlog-buffer)) + (goto-char (point-min)) + (if (zerop (buffer-size)) + () ; The buffer is empty. + (let ((ident (get-text-property (point) 'gnus-backlog)) + buffer-read-only) + ;; Remove the ident from the list of articles. + (when ident + (setq gnus-backlog-articles (delq ident gnus-backlog-articles))) + ;; Delete the article itself. + (delete-region + (point) (next-single-property-change + (1+ (point)) 'gnus-backlog nil (point-max))))))) + +(defun gnus-backlog-remove-article (group number) + "Remove article NUMBER in GROUP from the backlog." + (when (numberp number) + (gnus-backlog-setup) + (let ((ident (intern (concat group ":" (int-to-string number)) + gnus-backlog-hashtb)) + beg end) + (when (memq ident gnus-backlog-articles) + ;; It was in the backlog. + (save-excursion + (set-buffer (gnus-backlog-buffer)) + (let (buffer-read-only) + (when (setq beg (text-property-any + (point-min) (point-max) 'gnus-backlog + ident)) + ;; Find the end (i. e., the beginning of the next article). + (setq end + (next-single-property-change + (1+ beg) 'gnus-backlog (current-buffer) (point-max))) + (delete-region beg end) + ;; Return success. + t))))))) + +(defun gnus-backlog-request-article (group number buffer) + (when (numberp number) + (gnus-backlog-setup) + (let ((ident (intern (concat group ":" (int-to-string number)) + gnus-backlog-hashtb)) + beg end) + (when (memq ident gnus-backlog-articles) + ;; It was in the backlog. + (save-excursion + (set-buffer (gnus-backlog-buffer)) + (if (not (setq beg (text-property-any + (point-min) (point-max) 'gnus-backlog + ident))) + ;; It wasn't in the backlog after all. + (ignore + (setq gnus-backlog-articles (delq ident gnus-backlog-articles))) + ;; Find the end (i. e., the beginning of the next article). + (setq end + (next-single-property-change + (1+ beg) 'gnus-backlog (current-buffer) (point-max))))) + (let ((buffer-read-only nil)) + (erase-buffer) + (insert-buffer-substring gnus-backlog-buffer beg end) + t))))) ;; Allow redefinition of Gnus functions. diff --git a/lisp/nndir.el b/lisp/nndir.el index 5946754bee0..dd7fa8ade8b 100644 --- a/lisp/nndir.el +++ b/lisp/nndir.el @@ -1,9 +1,7 @@ ;;; nndir.el --- single directory newsgroup access for Gnus - -;; Copyright (C) 1995 Free Software Foundation, Inc. +;; Copyright (C) 1995,96 Free Software Foundation, Inc. ;; Author: Lars Magne Ingebrigtsen -;; Masanobu UMEDA ;; Keywords: news ;; This file is part of GNU Emacs. @@ -30,113 +28,71 @@ (require 'nnheader) (require 'nnmh) (require 'nnml) +(require 'nnoo) +(eval-when-compile (require 'cl)) -(eval-and-compile - (autoload 'mail-send-and-exit "sendmail")) +(nnoo-declare nndir + nnml nnmh) - +(defvoo nndir-directory nil + "Where nndir will look for groups." + nnml-current-directory nnmh-current-directory) -(defconst nndir-version "nndir 1.0") +(defvoo nndir-nov-is-evil nil + "*Non-nil means that nndir will never retrieve NOV headers." + nnml-nov-is-evil) -(defvar nndir-current-directory nil - "Current news group directory.") + -(defvar nndir-status-string "") +(defvoo nndir-current-group "" nil nnml-current-group nnmh-current-group) +(defvoo nndir-top-directory nil nil nnml-directory nnmh-directory) +(defvoo nndir-get-new-mail nil nil nnml-get-new-mail nnmh-get-new-mail) -(defvar nndir-nov-is-evil nil - "*Non-nil means that nndir will never retrieve NOV headers.") +(defvoo nndir-status-string "" nil nnmh-status-string) +(defconst nndir-version "nndir 1.0") ;;; Interface functions. - -(defun nndir-retrieve-headers (sequence &optional newsgroup server) - (nndir-execute-nnml-command - '(nnml-retrieve-headers sequence group server) server)) - -(defun nndir-open-server (host &optional service) - "Open nndir backend." - (setq nndir-status-string "") - (nnheader-init-server-buffer)) - -(defun nndir-close-server (&optional server) - "Close news server." - t) - -(defun nndir-server-opened (&optional server) - "Return server process status, T or NIL. -If the stream is opened, return T, otherwise return NIL." - (and nntp-server-buffer - (get-buffer nntp-server-buffer))) - -(defun nndir-status-message (&optional server) - "Return server status response as string." - nndir-status-string) - -(defun nndir-request-article (id &optional newsgroup server buffer) - (nndir-execute-nnmh-command - '(nnmh-request-article id group server buffer) server)) - -(defun nndir-request-group (group &optional server dont-check) - "Select news GROUP." - (nndir-execute-nnmh-command - '(nnmh-request-group group "" dont-check) server)) - -(defun nndir-request-list (&optional server dir) - "Get list of active articles in all newsgroups." - (nndir-execute-nnmh-command - '(nnmh-request-list nil dir) server)) - -(defun nndir-request-newgroups (date &optional server) - (nndir-execute-nnmh-command - '(nnmh-request-newgroups date server) server)) - -(defun nndir-request-post (&optional server) - "Post a new news in current buffer." - (mail-send-and-exit nil)) - -(defalias 'nndir-request-post-buffer 'nnmail-request-post-buffer) - -(defun nndir-request-expire-articles (articles newsgroup &optional server force) - "Expire all articles in the ARTICLES list in group GROUP." - (setq nndir-status-string "nndir: expire not possible") - nil) - -(defun nndir-close-group (group &optional server) - t) - -(defun nndir-request-move-article (article group server accept-form) - (setq nndir-status-string "nndir: move not possible") - nil) - -(defun nndir-request-accept-article (group) - (setq nndir-status-string "nndir: accept not possible") - nil) - - -;;; Low-Level Interface - -(defun nndir-execute-nnmh-command (command server) - (let ((dir (expand-file-name server))) - (and (string-match "/$" dir) - (setq dir (substring dir 0 (match-beginning 0)))) - (string-match "/[^/]+$" dir) - (let ((group (substring dir (1+ (match-beginning 0)))) - (nnmh-directory (substring dir 0 (1+ (match-beginning 0)))) - (nnmh-get-new-mail nil)) - (eval command)))) - -(defun nndir-execute-nnml-command (command server) - (let ((dir (expand-file-name server))) - (and (string-match "/$" dir) - (setq dir (substring dir 0 (match-beginning 0)))) - (string-match "/[^/]+$" dir) - (let ((group (substring dir (1+ (match-beginning 0)))) - (nnml-directory (substring dir 0 (1+ (match-beginning 0)))) - (nnml-nov-is-evil nndir-nov-is-evil) - (nnml-get-new-mail nil)) - (eval command)))) +(nnoo-define-basics nndir) + +(deffoo nndir-open-server (server &optional defs) + (setq nndir-directory + (or (cadr (assq 'nndir-directory defs)) + server)) + (unless (assq 'nndir-directory defs) + (push `(nndir-directory ,server) defs)) + (push `(nndir-current-group + ,(file-name-nondirectory (directory-file-name nndir-directory))) + defs) + (push `(nndir-top-directory + ,(file-name-directory (directory-file-name nndir-directory))) + defs) + (nnoo-change-server 'nndir server defs) + (let (err) + (cond + ((not (condition-case arg + (file-exists-p nndir-directory) + (ftp-error (setq err (format "%s" arg))))) + (nndir-close-server) + (nnheader-report + 'nndir (or err "No such file or directory: %s" nndir-directory))) + ((not (file-directory-p (file-truename nndir-directory))) + (nndir-close-server) + (nnheader-report 'nndir "Not a directory: %s" nndir-directory)) + (t + (nnheader-report 'nndir "Opened server %s using directory %s" + server nndir-directory) + t)))) + +(nnoo-map-functions nndir + (nnml-retrieve-headers 0 nndir-current-group 0 0) + (nnmh-request-article 0 nndir-current-group 0 0) + (nnmh-request-group nndir-current-group 0 0) + (nnmh-close-group nndir-current-group 0) + (nnmh-request-list (nnoo-current-server 'nndir) nndir-directory) + (nnmh-request-newsgroups (nnoo-current-server 'nndir) nndir-directory)) (provide 'nndir) diff --git a/lisp/nndoc.el b/lisp/nndoc.el index 575b671dbe5..1f4bb877d10 100644 --- a/lisp/nndoc.el +++ b/lisp/nndoc.el @@ -1,6 +1,5 @@ ;;; nndoc.el --- single file access for Gnus - -;; Copyright (C) 1995 Free Software Foundation, Inc. +;; Copyright (C) 1995,96 Free Software Foundation, Inc. ;; Author: Lars Magne Ingebrigtsen ;; Masanobu UMEDA @@ -28,239 +27,203 @@ ;;; Code: (require 'nnheader) -(require 'rmail) +(require 'message) (require 'nnmail) - -(defvar nndoc-article-type 'mbox - "*Type of the file - one of `mbox', `babyl' or `digest'.") - -(defvar nndoc-digest-type 'traditional - "Type of the last digest. Auto-detected from the article header. -Possible values: - `traditional' -- the \"lots of dashes\" (30+) rules used; - we currently also do unconditional RFC 934 unquoting. - `rfc1341' -- RFC 1341 digest (MIME, unique boundary, no quoting).") - -(defconst nndoc-type-to-regexp - (list (list 'mbox - (concat "^" rmail-unix-mail-delimiter) - (concat "^" rmail-unix-mail-delimiter) - nil "^$" nil nil nil) - (list 'babyl "\^_\^L *\n" "\^_" "^[0-9].*\n" "^$" nil nil - "\\*\\*\\* EOOH \\*\\*\\*\n\\(^.+\n\\)*") - (list 'digest - "^------------------------------*[\n \t]+" - "^------------------------------*[\n \t]+" - nil "^ ?$" - "^------------------------------*[\n \t]+" - "^End of" nil)) - "Regular expressions for articles of the various types.") +(require 'nnoo) +(eval-when-compile (require 'cl)) + +(nnoo-declare nndoc) + +(defvoo nndoc-article-type 'guess + "*Type of the file. +One of `mbox', `babyl', `digest', `news', `rnews', `mmdf', `forward', +`mime-digest', `standard-digest', `slack-digest', `clari-briefs' or +`guess'.") + +(defvoo nndoc-post-type 'mail + "*Whether the nndoc group is `mail' or `post'.") + +(defvar nndoc-type-alist + `((mmdf + (article-begin . "^\^A\^A\^A\^A\n") + (body-end . "^\^A\^A\^A\^A\n")) + (news + (article-begin . "^Path:")) + (rnews + (article-begin . "^#! *rnews +\\([0-9]+\\) *\n") + (body-end-function . nndoc-rnews-body-end)) + (mbox + (article-begin . + ,(let ((delim (concat "^" message-unix-mail-delimiter))) + (if (string-match "\n\\'" delim) + (substring delim 0 (match-beginning 0)) + delim))) + (body-end-function . nndoc-mbox-body-end)) + (babyl + (article-begin . "\^_\^L *\n") + (body-end . "\^_") + (body-begin-function . nndoc-babyl-body-begin) + (head-begin-function . nndoc-babyl-head-begin)) + (forward + (article-begin . "^-+ Start of forwarded message -+\n+") + (body-end . "^-+ End of forwarded message -+$") + (prepare-body . nndoc-unquote-dashes)) + (clari-briefs + (article-begin . "^ \\*") + (body-end . "^\t------*[ \t]^*\n^ \\*") + (body-begin . "^\t") + (head-end . "^\t") + (generate-head . nndoc-generate-clari-briefs-head) + (article-transform . nndoc-transform-clari-briefs)) + (slack-digest + (article-begin . "^------------------------------*[\n \t]+") + (head-end . "^ ?$") + (body-end-function . nndoc-digest-body-end) + (body-begin . "^ ?$") + (file-end . "^End of") + (prepare-body . nndoc-unquote-dashes)) + (mime-digest + (article-begin . "") + (head-end . "^ ?$") + (body-end . "") + (file-end . "")) + (standard-digest + (first-article . ,(concat "^" (make-string 70 ?-) "\n\n+")) + (article-begin . ,(concat "\n\n" (make-string 30 ?-) "\n\n+")) + (prepare-body . nndoc-unquote-dashes) + (body-end-function . nndoc-digest-body-end) + (head-end . "^ ?$") + (body-begin . "^ ?\n") + (file-end . "^End of .*digest.*[0-9].*\n\\*\\*\\|^End of.*Digest *$")) + (guess + (guess . nndoc-guess-type)) + (digest + (guess . nndoc-guess-digest-type)) + )) -(defvar nndoc-article-begin nil) -(defvar nndoc-article-end nil) -(defvar nndoc-head-begin nil) -(defvar nndoc-head-end nil) -(defvar nndoc-first-article nil) -(defvar nndoc-end-of-file nil) -(defvar nndoc-body-begin nil) - -(defvar nndoc-current-server nil) -(defvar nndoc-server-alist nil) -(defvar nndoc-server-variables - (list - (list 'nndoc-article-type nndoc-article-type) - '(nndoc-article-begin nil) - '(nndoc-article-end nil) - '(nndoc-head-begin nil) - '(nndoc-head-end nil) - '(nndoc-first-article nil) - '(nndoc-current-buffer nil) - '(nndoc-group-alist nil) - '(nndoc-end-of-file nil) - '(nndoc-body-begin nil) - '(nndoc-address nil))) +(defvoo nndoc-file-begin nil) +(defvoo nndoc-first-article nil) +(defvoo nndoc-article-end nil) +(defvoo nndoc-article-begin nil) +(defvoo nndoc-head-begin nil) +(defvoo nndoc-head-end nil) +(defvoo nndoc-file-end nil) +(defvoo nndoc-body-begin nil) +(defvoo nndoc-body-end-function nil) +(defvoo nndoc-body-begin-function nil) +(defvoo nndoc-head-begin-function nil) +(defvoo nndoc-body-end nil) +(defvoo nndoc-dissection-alist nil) +(defvoo nndoc-prepare-body nil) +(defvoo nndoc-generate-head nil) +(defvoo nndoc-article-transform nil) + +(defvoo nndoc-status-string "") +(defvoo nndoc-group-alist nil) +(defvoo nndoc-current-buffer nil + "Current nndoc news buffer.") +(defvoo nndoc-address nil) (defconst nndoc-version "nndoc 1.0" "nndoc version.") -(defvar nndoc-current-buffer nil - "Current nndoc news buffer.") - -(defvar nndoc-address nil) - -(defvar nndoc-status-string "") - -(defvar nndoc-group-alist nil) - ;;; Interface functions -(defun nndoc-retrieve-headers (sequence &optional newsgroup server) - (save-excursion - (set-buffer nntp-server-buffer) - (erase-buffer) - (let ((prev 2) - article p beg lines) - (nndoc-possibly-change-buffer newsgroup server) - (if (stringp (car sequence)) - 'headers - (set-buffer nndoc-current-buffer) - (widen) - (goto-char (point-min)) - (re-search-forward (or nndoc-first-article - nndoc-article-begin) nil t) - (or (not nndoc-head-begin) - (re-search-forward nndoc-head-begin nil t)) - (re-search-forward nndoc-head-end nil t) - (while sequence - (setq article (car sequence)) - (set-buffer nndoc-current-buffer) - (if (not (nndoc-forward-article (max 0 (- article prev)))) - () - (setq p (point)) - (setq beg (or (and - (re-search-backward nndoc-article-begin nil t) - (match-end 0)) - (point-min))) - (goto-char p) - (setq lines (count-lines - (point) - (or - (and (re-search-forward nndoc-article-end nil t) - (goto-char (match-beginning 0))) - (goto-char (point-max))))) - - (set-buffer nntp-server-buffer) - (insert (format "221 %d Article retrieved.\n" article)) - (insert-buffer-substring nndoc-current-buffer beg p) - (goto-char (point-max)) - (or (= (char-after (1- (point))) ?\n) (insert "\n")) - (insert (format "Lines: %d\n" lines)) - (insert ".\n")) - - (setq prev article - sequence (cdr sequence))) - - ;; Fold continuation lines. - (set-buffer nntp-server-buffer) - (goto-char (point-min)) - (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t) - (replace-match " " t t)) - 'headers)))) - -(defun nndoc-open-server (server &optional defs) - (nnheader-init-server-buffer) - (if (equal server nndoc-current-server) - t - (if nndoc-current-server - (setq nndoc-server-alist - (cons (list nndoc-current-server - (nnheader-save-variables nndoc-server-variables)) - nndoc-server-alist))) - (let ((state (assoc server nndoc-server-alist))) - (if state - (progn - (nnheader-restore-variables (nth 1 state)) - (setq nndoc-server-alist (delq state nndoc-server-alist))) - (nnheader-set-init-variables nndoc-server-variables defs))) - (setq nndoc-current-server server) - (let ((defs (cdr (assq nndoc-article-type nndoc-type-to-regexp)))) - (setq nndoc-article-begin (nth 0 defs)) - (setq nndoc-article-end (nth 1 defs)) - (setq nndoc-head-begin (nth 2 defs)) - (setq nndoc-head-end (nth 3 defs)) - (setq nndoc-first-article (nth 4 defs)) - (setq nndoc-end-of-file (nth 5 defs)) - (setq nndoc-body-begin (nth 6 defs))) - t)) +(nnoo-define-basics nndoc) -(defun nndoc-close-server (&optional server) - t) - -(defun nndoc-server-opened (&optional server) - (and (equal server nndoc-current-server) - nntp-server-buffer - (buffer-name nntp-server-buffer))) - -(defun nndoc-status-message (&optional server) - nndoc-status-string) - -(defun nndoc-request-article (article &optional newsgroup server buffer) +(deffoo nndoc-retrieve-headers (articles &optional newsgroup server fetch-old) + (when (nndoc-possibly-change-buffer newsgroup server) + (save-excursion + (set-buffer nntp-server-buffer) + (erase-buffer) + (let (article entry) + (if (stringp (car articles)) + 'headers + (while articles + (when (setq entry (cdr (assq (setq article (pop articles)) + nndoc-dissection-alist))) + (insert (format "221 %d Article retrieved.\n" article)) + (if nndoc-generate-head + (funcall nndoc-generate-head article) + (insert-buffer-substring + nndoc-current-buffer (car entry) (nth 1 entry))) + (goto-char (point-max)) + (or (= (char-after (1- (point))) ?\n) (insert "\n")) + (insert (format "Lines: %d\n" (nth 4 entry))) + (insert ".\n"))) + + (nnheader-fold-continuation-lines) + 'headers))))) + +(deffoo nndoc-request-article (article &optional newsgroup server buffer) (nndoc-possibly-change-buffer newsgroup server) (save-excursion - (let ((buffer (or buffer nntp-server-buffer))) + (let ((buffer (or buffer nntp-server-buffer)) + (entry (cdr (assq article nndoc-dissection-alist))) + beg) (set-buffer buffer) (erase-buffer) (if (stringp article) nil - (nndoc-insert-article article) - ;; Unquote quoted non-separators in digests. - (if (and (eq nndoc-article-type 'digest) - (eq nndoc-digest-type 'traditional)) - (progn - (goto-char (point-min)) - (while (re-search-forward "^- -"nil t) - (replace-match "-" t t)))) - ;; Some assholish digests do not have a blank line after the - ;; headers. Aargh! - (goto-char (point-min)) - (if (search-forward "\n\n" nil t) - () ; We let this one pass. - (if (re-search-forward "^[ \t]+$" nil t) - (replace-match "" t t) ; We nix out a line of blanks. - (while (and (looking-at "[^ ]+:") - (zerop (forward-line 1)))) - ;; We just insert a couple of lines. If you read digests - ;; that are so badly formatted, you don't deserve any - ;; better. Blphphpht! - (insert "\n\n"))) + (insert-buffer-substring + nndoc-current-buffer (car entry) (nth 1 entry)) + (insert "\n") + (setq beg (point)) + (insert-buffer-substring + nndoc-current-buffer (nth 2 entry) (nth 3 entry)) + (goto-char beg) + (when nndoc-prepare-body + (funcall nndoc-prepare-body)) + (when nndoc-article-transform + (funcall nndoc-article-transform article)) t)))) -(defun nndoc-request-group (group &optional server dont-check) +(deffoo nndoc-request-group (group &optional server dont-check) "Select news GROUP." - (save-excursion - (if (not (nndoc-possibly-change-buffer group server)) - (progn - (setq nndoc-status-string "No such file or buffer") - nil) - (nndoc-set-header-dependent-regexps) ; hack for MIME digests - (if dont-check - t - (save-excursion - (set-buffer nntp-server-buffer) - (erase-buffer) - (let ((number (nndoc-number-of-articles))) - (if (zerop number) - (progn - (nndoc-close-group group) - nil) - (insert (format "211 %d %d %d %s\n" number 1 number group)) - t))))))) - -(defun nndoc-close-group (group &optional server) + (let (number) + (cond + ((not (nndoc-possibly-change-buffer group server)) + (nnheader-report 'nndoc "No such file or buffer: %s" + nndoc-address)) + (dont-check + (nnheader-report 'nndoc "Selected group %s" group) + t) + ((zerop (setq number (length nndoc-dissection-alist))) + (nndoc-close-group group) + (nnheader-report 'nndoc "No articles in group %s" group)) + (t + (nnheader-insert "211 %d %d %d %s\n" number 1 number group))))) + +(deffoo nndoc-request-type (group &optional article) + (cond ((not article) 'unknown) + (nndoc-post-type nndoc-post-type) + (t 'unknown))) + +(deffoo nndoc-close-group (group &optional server) (nndoc-possibly-change-buffer group server) - (kill-buffer nndoc-current-buffer) + (and nndoc-current-buffer + (buffer-name nndoc-current-buffer) + (kill-buffer nndoc-current-buffer)) (setq nndoc-group-alist (delq (assoc group nndoc-group-alist) nndoc-group-alist)) (setq nndoc-current-buffer nil) - (setq nndoc-current-server nil) + (nnoo-close-server 'nndoc server) + (setq nndoc-dissection-alist nil) t) -(defun nndoc-request-list (&optional server) +(deffoo nndoc-request-list (&optional server) nil) -(defun nndoc-request-newgroups (date &optional server) +(deffoo nndoc-request-newgroups (date &optional server) nil) -(defun nndoc-request-list-newsgroups (&optional server) +(deffoo nndoc-request-list-newsgroups (&optional server) nil) -(defalias 'nndoc-request-post 'nnmail-request-post) -(defalias 'nndoc-request-post-buffer 'nnmail-request-post-buffer) - ;;; Internal functions. @@ -269,6 +232,7 @@ Possible values: (cond ;; The current buffer is this group's buffer. ((and nndoc-current-buffer + (buffer-name nndoc-current-buffer) (eq nndoc-current-buffer (setq buf (cdr (assoc group nndoc-group-alist)))))) ;; We change buffers by taking an old from the group alist. @@ -281,121 +245,231 @@ Possible values: (and (stringp nndoc-address) (file-exists-p nndoc-address) (not (file-directory-p nndoc-address)))) - (setq nndoc-group-alist - (cons (cons group (setq nndoc-current-buffer - (get-buffer-create - (concat " *nndoc " group "*")))) - nndoc-group-alist)) + (push (cons group (setq nndoc-current-buffer + (get-buffer-create + (concat " *nndoc " group "*")))) + nndoc-group-alist) + (setq nndoc-dissection-alist nil) (save-excursion (set-buffer nndoc-current-buffer) (buffer-disable-undo (current-buffer)) (erase-buffer) (if (stringp nndoc-address) (insert-file-contents nndoc-address) - (save-excursion - (set-buffer nndoc-address) - (widen)) - (insert-buffer-substring nndoc-address)) - t))))) - -;; MIME (RFC 1341) digest hack by Ulrik Dickow . -(defun nndoc-set-header-dependent-regexps () - (if (not (eq nndoc-article-type 'digest)) - () - (let ((case-fold-search t) ; We match a bit too much, keep it simple. - (boundary-id) (b-delimiter)) + (insert-buffer-substring nndoc-address))))) + ;; Initialize the nndoc structures according to this new document. + (when (and nndoc-current-buffer + (not nndoc-dissection-alist)) (save-excursion (set-buffer nndoc-current-buffer) - (goto-char (point-min)) - (if (and - (re-search-forward - (concat "\n\n\\|^Content-Type: *multipart/digest;[ \t\n]*[ \t]" - "boundary=\"\\([^\"\n]*[^\" \t\n]\\)\"") - nil t) - (match-beginning 1)) - (setq nndoc-digest-type 'rfc1341 - boundary-id (format "%s" - (buffer-substring - (match-beginning 1) (match-end 1))) - b-delimiter (concat "\n--" boundary-id "[\n \t]+") - nndoc-article-begin b-delimiter ; Too strict: "[ \t]*$" - nndoc-article-end (concat "\n--" boundary-id - "\\(--\\)?[\n \t]+") - nndoc-first-article b-delimiter ; ^eof ends article too. - nndoc-end-of-file (concat "\n--" boundary-id "--[ \t]*$")) - (setq nndoc-digest-type 'traditional)))))) - -(defun nndoc-forward-article (n) - (while (and (> n 0) - (re-search-forward nndoc-article-begin nil t) - (or (not nndoc-head-begin) - (re-search-forward nndoc-head-begin nil t)) - (re-search-forward nndoc-head-end nil t)) - (setq n (1- n))) - (zerop n)) - -(defun nndoc-number-of-articles () - (save-excursion - (set-buffer nndoc-current-buffer) - (widen) - (goto-char (point-min)) - (let ((num 0)) - (if (re-search-forward (or nndoc-first-article - nndoc-article-begin) nil t) - (progn - (setq num 1) - (while (and (re-search-forward nndoc-article-begin nil t) - (or (not nndoc-end-of-file) - (not (looking-at nndoc-end-of-file))) - (or (not nndoc-head-begin) - (re-search-forward nndoc-head-begin nil t)) - (re-search-forward nndoc-head-end nil t)) - (setq num (1+ num))))) - num))) - -(defun nndoc-narrow-to-article (article) - (save-excursion - (set-buffer nndoc-current-buffer) - (widen) + (nndoc-set-delims) + (nndoc-dissect-buffer))) + (unless nndoc-current-buffer + (nndoc-close-server)) + ;; Return whether we managed to select a file. + nndoc-current-buffer)) + +;; MIME (RFC 1341) digest hack by Ulrik Dickow . +(defun nndoc-guess-digest-type () + "Guess what digest type the current document is." + (let ((case-fold-search t) ; We match a bit too much, keep it simple. + boundary-id b-delimiter entry) (goto-char (point-min)) - (while (and (re-search-forward nndoc-article-begin nil t) - (not (zerop (setq article (1- article)))))) - (if (not (zerop article)) - () - (narrow-to-region - (match-end 0) - (or (and (re-search-forward nndoc-article-end nil t) - (match-beginning 0)) - (point-max))) - t))) - -;; Insert article ARTICLE in the current buffer. -(defun nndoc-insert-article (article) - (let ((ibuf (current-buffer))) + (cond + ;; MIME digest. + ((and + (re-search-forward + (concat "^Content-Type: *multipart/digest;[ \t\n]*[ \t]" + "boundary=\"\\([^\"\n]*[^\" \t\n]\\)\"") + nil t) + (match-beginning 1)) + (setq boundary-id (match-string 1) + b-delimiter (concat "\n--" boundary-id "[\n \t]+")) + (setq entry (assq 'mime-digest nndoc-type-alist)) + (setcdr entry + (list + (cons 'head-end "^ ?$") + (cons 'body-begin "^ ?\n") + (cons 'article-begin b-delimiter) + (cons 'body-end-function 'nndoc-digest-body-end) +; (cons 'body-end +; (concat "\n--" boundary-id "\\(--\\)?[\n \t]+")) + (cons 'file-end (concat "\n--" boundary-id "--[ \t]*$")))) + 'mime-digest) + ;; Standard digest. + ((and (re-search-forward (concat "^" (make-string 70 ?-) "\n\n") nil t) + (re-search-forward + (concat "\n\n" (make-string 30 ?-) "\n\n") nil t)) + 'standard-digest) + ;; Stupid digest. + (t + 'slack-digest)))) + +(defun nndoc-guess-type () + "Guess what document type is in the current buffer." + (goto-char (point-min)) + (cond + ((looking-at message-unix-mail-delimiter) + 'mbox) + ((looking-at "\^A\^A\^A\^A$") + 'mmdf) + ((looking-at "^Path:.*\n") + 'news) + ((looking-at "#! *rnews") + 'rnews) + ((re-search-forward "\^_\^L *\n" nil t) + 'babyl) + ((save-excursion + (and (re-search-forward "^-+ Start of forwarded message -+\n+" nil t) + (not (re-search-forward "^Subject:.*digest" nil t)))) + 'forward) + ((let ((case-fold-search nil)) + (re-search-forward "^\t[^a-z]+ ([^a-z]+) --" nil t)) + 'clari-briefs) + (t + 'digest))) + +(defun nndoc-set-delims () + "Set the nndoc delimiter variables according to the type of the document." + (let ((vars '(nndoc-file-begin + nndoc-first-article + nndoc-article-end nndoc-head-begin nndoc-head-end + nndoc-file-end nndoc-article-begin + nndoc-body-begin nndoc-body-end-function nndoc-body-end + nndoc-prepare-body nndoc-article-transform + nndoc-generate-head nndoc-body-begin-function + nndoc-head-begin-function))) + (while vars + (set (pop vars) nil))) + (let* (defs guess) + ;; Guess away until we find the real file type. + (while (setq defs (cdr (assq nndoc-article-type nndoc-type-alist)) + guess (assq 'guess defs)) + (setq nndoc-article-type (funcall (cdr guess)))) + ;; Set the nndoc variables. + (while defs + (set (intern (format "nndoc-%s" (caar defs))) + (cdr (pop defs)))))) + +(defun nndoc-search (regexp) + (prog1 + (re-search-forward regexp nil t) + (beginning-of-line))) + +(defun nndoc-dissect-buffer () + "Go through the document and partition it into heads/bodies/articles." + (let ((i 0) + (first t) + head-begin head-end body-begin body-end) + (setq nndoc-dissection-alist nil) (save-excursion (set-buffer nndoc-current-buffer) - (widen) (goto-char (point-min)) - (while (and (re-search-forward nndoc-article-begin nil t) - (not (zerop (setq article (1- article)))))) - (if (not (zerop article)) - () - (narrow-to-region - (match-end 0) - (or (and (re-search-forward nndoc-article-end nil t) - (match-beginning 0)) - (point-max))) + ;; Find the beginning of the file. + (when nndoc-file-begin + (nndoc-search nndoc-file-begin)) + ;; Go through the file. + (while (if (and first nndoc-first-article) + (nndoc-search nndoc-first-article) + (nndoc-search nndoc-article-begin)) + (setq first nil) + (cond (nndoc-head-begin-function + (funcall nndoc-head-begin-function)) + (nndoc-head-begin + (nndoc-search nndoc-head-begin))) + (if (and nndoc-file-end + (looking-at nndoc-file-end)) + (goto-char (point-max)) + (setq head-begin (point)) + (nndoc-search (or nndoc-head-end "^$")) + (setq head-end (point)) + (if nndoc-body-begin-function + (funcall nndoc-body-begin-function) + (nndoc-search (or nndoc-body-begin "^\n"))) + (setq body-begin (point)) + (or (and nndoc-body-end-function + (funcall nndoc-body-end-function)) + (and nndoc-body-end + (nndoc-search nndoc-body-end)) + (nndoc-search nndoc-article-begin) + (progn + (goto-char (point-max)) + (when nndoc-file-end + (and (re-search-backward nndoc-file-end nil t) + (beginning-of-line))))) + (setq body-end (point)) + (push (list (incf i) head-begin head-end body-begin body-end + (count-lines body-begin body-end)) + nndoc-dissection-alist)))))) + +(defun nndoc-unquote-dashes () + "Unquote quoted non-separators in digests." + (while (re-search-forward "^- -"nil t) + (replace-match "-" t t))) + +(defun nndoc-digest-body-end () + (and (re-search-forward nndoc-article-begin nil t) + (goto-char (match-beginning 0)))) + +(defun nndoc-mbox-body-end () + (let ((beg (point)) + len end) + (when + (save-excursion + (and (re-search-backward nndoc-article-begin nil t) + (setq end (point)) + (search-forward "\n\n" beg t) + (re-search-backward + "^Content-Length:[ \t]*\\([0-9]+\\) *$" end t) + (setq len (string-to-int (match-string 1))) + (search-forward "\n\n" beg t) + (or (= (setq len (+ (point) len)) (point-max)) + (and (< len (point-max)) + (goto-char len) + (looking-at nndoc-article-begin))))) + (goto-char len)))) + +(defun nndoc-rnews-body-end () + (and (re-search-backward nndoc-article-begin nil t) + (forward-line 1) + (goto-char (+ (point) (string-to-int (match-string 1)))))) + +(defun nndoc-transform-clari-briefs (article) + (goto-char (point-min)) + (when (looking-at " *\\*\\(.*\\)\n") + (replace-match "" t t)) + (nndoc-generate-clari-briefs-head article)) + +(defun nndoc-generate-clari-briefs-head (article) + (let ((entry (cdr (assq article nndoc-dissection-alist))) + subject from) + (save-excursion + (set-buffer nndoc-current-buffer) + (save-restriction + (narrow-to-region (car entry) (nth 3 entry)) (goto-char (point-min)) - (and nndoc-head-begin - (re-search-forward nndoc-head-begin nil t) - (narrow-to-region (point) (point-max))) - (or (re-search-forward nndoc-head-end nil t) - (goto-char (point-max))) - (append-to-buffer ibuf (point-min) (point)) - (and nndoc-body-begin - (re-search-forward nndoc-body-begin nil t)) - (append-to-buffer ibuf (point) (point-max)) - t)))) + (when (looking-at " *\\*\\(.*\\)$") + (setq subject (match-string 1)) + (when (string-match "[ \t]+$" subject) + (setq subject (substring subject 0 (match-beginning 0))))) + (when + (let ((case-fold-search nil)) + (re-search-forward + "^\t\\([^a-z]+\\(,[^(]+\\)? ([^a-z]+)\\) --" nil t)) + (setq from (match-string 1))))) + (insert "From: " "clari@clari.net (" (or from "unknown") ")" + "\nSubject: " (or subject "(no subject)") "\n"))) + +(defun nndoc-babyl-body-begin () + (re-search-forward "^\n" nil t) + (when (looking-at "\*\*\* EOOH \*\*\*") + (re-search-forward "^\n" nil t))) + +(defun nndoc-babyl-head-begin () + (when (re-search-forward "^[0-9].*\n" nil t) + (when (looking-at "\*\*\* EOOH \*\*\*") + (forward-line 1)) + t)) (provide 'nndoc) diff --git a/lisp/nneething.el b/lisp/nneething.el index 6ef2276d72c..691c84f0ecc 100644 --- a/lisp/nneething.el +++ b/lisp/nneething.el @@ -1,6 +1,5 @@ ;;; nneething.el --- random file access for Gnus - -;; Copyright (C) 1995 Free Software Foundation, Inc. +;; Copyright (C) 1995,96 Free Software Foundation, Inc. ;; Author: Lars Magne Ingebrigtsen ;; Masanobu UMEDA @@ -33,103 +32,90 @@ (require 'nnheader) (require 'nnmail) +(require 'nnoo) +(eval-when-compile (require 'cl)) + +(nnoo-declare nneething) -(defvar nneething-map-file-directory "~/.nneething/" - "*Map files directory.") +(defvoo nneething-map-file-directory "~/.nneething/" + "*Where nneething stores the map files.") -(defvar nneething-exclude-files "~$" - "*Regexp saying what files to exclude from the group.") +(defvoo nneething-map-file ".nneething" + "*Name of the map files.") -(defvar nneething-map-file ".nneething" - "*Name of map files.") +(defvoo nneething-exclude-files nil + "*Regexp saying what files to exclude from the group. +If this variable is nil, no files will be excluded.") +;;; Internal variables. + (defconst nneething-version "nneething 1.0" "nneething version.") -(defvar nneething-current-directory nil +(defvoo nneething-current-directory nil "Current news group directory.") -(defvar nneething-status-string "") -(defvar nneething-group-alist nil) +(defvoo nneething-status-string "") +(defvoo nneething-group-alist nil) - +(defvoo nneething-message-id-number 0) +(defvoo nneething-work-buffer " *nneething work*") -(defvar nneething-directory nil) -(defvar nneething-group nil) -(defvar nneething-map nil) -(defvar nneething-read-only nil) -(defvar nneething-active nil) -(defvar nneething-server-variables - (list - (list 'nneething-directory nneething-directory) - '(nneething-current-directory nil) - '(nneething-status-string "") - '(nneething-group-alist))) +(defvoo nneething-directory nil) +(defvoo nneething-group nil) +(defvoo nneething-map nil) +(defvoo nneething-read-only nil) +(defvoo nneething-active nil) ;;; Interface functions. -(defun nneething-retrieve-headers (sequence &optional newsgroup server) - (nneething-possibly-change-directory newsgroup) +(nnoo-define-basics nneething) + +(deffoo nneething-retrieve-headers (articles &optional group server fetch-old) + (nneething-possibly-change-directory group) (save-excursion (set-buffer nntp-server-buffer) (erase-buffer) - (let* ((number (length sequence)) + (let* ((number (length articles)) (count 0) (large (and (numberp nnmail-large-newsgroup) (> number nnmail-large-newsgroup))) article file) - (if (stringp (car sequence)) + (if (stringp (car articles)) 'headers - (while sequence - (setq article (car sequence)) + (while (setq article (pop articles)) (setq file (nneething-file-name article)) - (if (and (file-exists-p file) - (not (zerop (nth 7 (file-attributes file))))) - (progn - (insert (format "221 %d Article retrieved.\n" article)) - (nneething-insert-head file) - (insert ".\n"))) + (when (and (file-exists-p file) + (or (file-directory-p file) + (not (zerop (nth 7 (file-attributes file)))))) + (insert (format "221 %d Article retrieved.\n" article)) + (nneething-insert-head file) + (insert ".\n")) - (setq sequence (cdr sequence) - count (1+ count)) + (incf count) (and large (zerop (% count 20)) (message "nneething: Receiving headers... %d%%" (/ (* count 100) number)))) - (and large (message "nneething: Receiving headers...done")) + (when large + (message "nneething: Receiving headers...done")) - ;; Fold continuation lines. - (goto-char (point-min)) - (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t) - (replace-match " " t t)) + (nnheader-fold-continuation-lines) 'headers)))) -(defun nneething-open-server (server &optional defs) - (setq nneething-status-string "") - (nnheader-init-server-buffer)) - -(defun nneething-close-server (&optional server) - t) - -(defun nneething-server-opened (&optional server) - t) - -(defun nneething-status-message (&optional server) - nneething-status-string) - -(defun nneething-request-article (id &optional newsgroup server buffer) - (nneething-possibly-change-directory newsgroup) - (let ((file (if (stringp id) nil (nneething-file-name id))) +(deffoo nneething-request-article (id &optional group server buffer) + (nneething-possibly-change-directory group) + (let ((file (unless (stringp id) (nneething-file-name id))) (nntp-server-buffer (or buffer nntp-server-buffer))) (and (stringp file) ; We did not request by Message-ID. (file-exists-p file) ; The file exists. @@ -139,50 +125,41 @@ (or (nnheader-article-p) ; Either it's a real article... (progn (goto-char (point-min)) - (nneething-make-head file) ; ... or we fake some headers. + (nneething-make-head file (current-buffer)) ; ... or we fake some headers. (insert "\n"))) t)))) -(defun nneething-request-group (group &optional dir dont-check) +(deffoo nneething-request-group (group &optional dir dont-check) (nneething-possibly-change-directory group dir) - (or dont-check (nneething-create-mapping)) - (save-excursion - (set-buffer nntp-server-buffer) - (erase-buffer) + (unless dont-check + (nneething-create-mapping) (if (> (car nneething-active) (cdr nneething-active)) - (insert (format "211 0 1 0 %s\n" group)) - (insert (format "211 %d %d %d %s\n" - (- (1+ (cdr nneething-active)) (car nneething-active)) - (car nneething-active) (cdr nneething-active) - group))) - t)) - -(defun nneething-request-list (&optional server dir) - (save-excursion - (set-buffer nntp-server-buffer) - (erase-buffer)) - nil) + (nnheader-insert "211 0 1 0 %s\n" group) + (nnheader-insert + "211 %d %d %d %s\n" + (- (1+ (cdr nneething-active)) (car nneething-active)) + (car nneething-active) (cdr nneething-active) + group))) + t) -(defun nneething-request-newgroups (date &optional server) - (save-excursion - (set-buffer nntp-server-buffer) - (erase-buffer)) - nil) +(deffoo nneething-request-list (&optional server dir) + (nnheader-report 'nneething "LIST is not implemented.")) -(defun nneething-request-post (&optional server) - (mail-send-and-exit nil)) +(deffoo nneething-request-newgroups (date &optional server) + (nnheader-report 'nneething "NEWSGROUPS is not implemented.")) -(defalias 'nneething-request-post-buffer 'nnmail-request-post-buffer) +(deffoo nneething-request-type (group &optional article) + 'unknown) -(defun nneething-close-group (group &optional server) +(deffoo nneething-close-group (group &optional server) + (setq nneething-current-directory nil) t) ;;; Internal functions. (defun nneething-possibly-change-directory (group &optional dir) - (if (not group) - () + (when group (if (and nneething-group (string= group nneething-group)) t @@ -198,42 +175,58 @@ (setq nneething-map nil) (setq nneething-active (cons 1 0)) (nneething-create-mapping) - (setq nneething-group-alist - (cons (list group dir nneething-map nneething-active) - nneething-group-alist))))))) + (push (list group dir nneething-map nneething-active) + nneething-group-alist)))))) (defun nneething-map-file () ;; We make sure that the .nneething directory exists. - (make-directory nneething-map-file-directory 'parents) + (unless (file-exists-p nneething-map-file-directory) + (make-directory nneething-map-file-directory 'parents)) ;; We store it in a special directory under the user's home dir. (concat (file-name-as-directory nneething-map-file-directory) nneething-group nneething-map-file)) (defun nneething-create-mapping () - ;; Read nneething-active and nneething-map + ;; Read nneething-active and nneething-map. (let ((map-file (nneething-map-file)) (files (directory-files nneething-directory)) - touched) + touched map-files) (if (file-exists-p map-file) (condition-case nil (load map-file nil t t) (error nil))) (or nneething-active (setq nneething-active (cons 1 0))) - ;; Remove files matching that regexp. - (let ((f files) - prev) - (while f - (if (string-match nneething-exclude-files (car f)) - (if prev (setcdr prev (cdr f)) - (setq files (cdr files))) - (setq prev f)) - (setq f (cdr f)))) - ;; Remove files that have disappeared from the map. + ;; Old nneething had a different map format. + (when (and (cdar nneething-map) + (atom (cdar nneething-map))) + (setq nneething-map + (mapcar (lambda (n) + (list (cdr n) (car n) + (nth 5 (file-attributes + (nneething-file-name (car n)))))) + nneething-map))) + ;; Remove files matching the exclusion regexp. + (when nneething-exclude-files + (let ((f files) + prev) + (while f + (if (string-match nneething-exclude-files (car f)) + (if prev (setcdr prev (cdr f)) + (setq files (cdr files))) + (setq prev f)) + (setq f (cdr f))))) + ;; Remove deleted files from the map. (let ((map nneething-map) prev) (while map - (if (member (car (car map)) files) - (setq prev map) + (if (and (member (cadar map) files) + ;; We also remove files that have changed mod times. + (equal (nth 5 (file-attributes + (nneething-file-name (cadar map)))) + (caddar map))) + (progn + (push (cadar map) map-files) + (setq prev map)) (setq touched t) (if prev (setcdr prev (cdr map)) @@ -241,60 +234,87 @@ (setq map (cdr map)))) ;; Find all new files and enter them into the map. (while files - (or (assoc (car files) nneething-map) ; If already in the map, ignore. - (progn - (setq touched t) - (setcdr nneething-active (1+ (cdr nneething-active))) - (setq nneething-map - (cons (cons (car files) (cdr nneething-active)) nneething-map)))) + (unless (member (car files) map-files) + ;; This file is not in the map, so we enter it. + (setq touched t) + (setcdr nneething-active (1+ (cdr nneething-active))) + (push (list (cdr nneething-active) (car files) + (nth 5 (file-attributes + (nneething-file-name (car files))))) + nneething-map)) (setq files (cdr files))) - (if (or (not touched) nneething-read-only) - () + (when (and touched + (not nneething-read-only)) (save-excursion - (set-buffer (get-buffer-create " *nneething map*")) - (buffer-disable-undo (current-buffer)) - (erase-buffer) + (nnheader-set-temp-buffer " *nneething map*") (insert "(setq nneething-map '" (prin1-to-string nneething-map) ")\n" "(setq nneething-active '" (prin1-to-string nneething-active) ")\n") (write-region (point-min) (point-max) map-file nil 'nomesg) (kill-buffer (current-buffer)))))) -(defvar nneething-message-id-number 0) -(defvar nneething-work-buffer " *nneething work*") - (defun nneething-insert-head (file) - (and (nneething-get-head file) - (insert-buffer-substring nneething-work-buffer))) + "Insert the head of FILE." + (when (nneething-get-head file) + (insert-buffer-substring nneething-work-buffer) + (goto-char (point-max)))) -(defun nneething-make-head (file) +(defun nneething-make-head (file &optional buffer) + "Create a head by looking at the file attributes of FILE." (let ((atts (file-attributes file))) - (insert "Subject: " (file-name-nondirectory file) "\n" - "Message-ID: \n" - "Date: " (current-time-string (nth 5 atts)) "\n" - (nneething-from-line (nth 2 atts)) - "Chars: " (int-to-string (nth 7 atts)) "\n"))) - -(defun nneething-from-line (uid) - (let ((login (condition-case nil - (user-login-name uid) + (insert + "Subject: " (file-name-nondirectory file) "\n" + "Message-ID: \n" + (if (equal '(0 0) (nth 5 atts)) "" + (concat "Date: " (current-time-string (nth 5 atts)) "\n")) + (or (if buffer + (save-excursion + (set-buffer buffer) + (if (re-search-forward "<[a-zA-Z0-9_]@[-a-zA-Z0-9_]>" 1000 t) + (concat "From: " (match-string 0) "\n")))) + (nneething-from-line (nth 2 atts) file)) + (if (> (string-to-int (int-to-string (nth 7 atts))) 0) + (concat "Chars: " (int-to-string (nth 7 atts)) "\n") + "") + (if buffer + (save-excursion + (set-buffer buffer) + (concat "Lines: " (int-to-string + (count-lines (point-min) (point-max))) "\n")) + "") + ))) + +(defun nneething-from-line (uid &optional file) + "Return a From header based of UID." + (let* ((login (condition-case nil + (user-login-name uid) + (error + (cond ((= uid (user-uid)) (user-login-name)) + ((zerop uid) "root") + (t (int-to-string uid)))))) + (name (condition-case nil + (user-full-name uid) (error - (cond ((= uid (user-uid)) (user-login-name)) - ((zerop uid) "root") - (t (int-to-string uid)))))) - (name (condition-case nil - (user-full-name uid) - (error - (cond ((= uid (user-uid)) (user-full-name)) - ((zerop uid) "Ms. Root")))))) - (concat "From: " login "@" (system-name) + (cond ((= uid (user-uid)) (user-full-name)) + ((zerop uid) "Ms. Root"))))) + (host (if (string-match "\\`/[^/@]*@\\([^:/]+\\):" file) + (prog1 + (substring file + (match-beginning 1) + (match-end 1)) + (if (string-match "/\\(users\\|home\\)/\\([^/]+\\)/" file) + (setq login (substring file + (match-beginning 2) + (match-end 2)) + name nil))) + (system-name)))) + (concat "From: " login "@" host (if name (concat " (" name ")") "") "\n"))) (defun nneething-get-head (file) + "Either find the head in FILE or make a head for FILE." (save-excursion (set-buffer (get-buffer-create nneething-work-buffer)) (setq case-fold-search nil) @@ -319,16 +339,16 @@ (1- (point))) (point-max))) (point-max)) - (erase-buffer) - (nneething-make-head file)) + (goto-char (point-min)) + (nneething-make-head file (current-buffer)) + (delete-region (point) (point-max))) t)))) -(defun nneething-number-to-file (number) - (car (rassq number nneething-map))) - (defun nneething-file-name (article) + "Return the file name of ARTICLE." (concat (file-name-as-directory nneething-directory) - (if (numberp article) (nneething-number-to-file article) + (if (numberp article) + (cadr (assq article nneething-map)) article))) (provide 'nneething) diff --git a/lisp/nnfolder.el b/lisp/nnfolder.el index ed338a53d12..90c1396ff34 100644 --- a/lisp/nnfolder.el +++ b/lisp/nnfolder.el @@ -1,11 +1,10 @@ ;;; nnfolder.el --- mail folder access for Gnus - -;; Copyright (C) 1995 Free Software Foundation, Inc. +;; Copyright (C) 1995,96 Free Software Foundation, Inc. ;; Author: Scott Byer ;; Lars Magne Ingebrigtsen ;; Masanobu UMEDA -;; Keywords: news, mail +;; Keywords: mail ;; This file is part of GNU Emacs. @@ -34,45 +33,52 @@ ;;; Code: (require 'nnheader) -(require 'rmail) +(require 'message) (require 'nnmail) +(require 'nnoo) +(eval-when-compile (require 'cl)) + +(nnoo-declare nnfolder) -(defvar nnfolder-directory (expand-file-name "~/Mail/") - "The name of the mail box file in the users home directory.") +(defvoo nnfolder-directory (expand-file-name message-directory) + "The name of the nnfolder directory.") -(defvar nnfolder-active-file - (concat (file-name-as-directory nnfolder-directory) "active") +(defvoo nnfolder-active-file + (nnheader-concat nnfolder-directory "active") "The name of the active file.") ;; I renamed this variable to something more in keeping with the general GNU ;; style. -SLB -(defvar nnfolder-ignore-active-file nil - "If non-nil, causes nnfolder to do some extra work in order to determine the true active ranges of an mbox file. -Note that the active file is still saved, but it's values are not -used. This costs some extra time when scanning an mbox when opening -it.") - -;; Note that this variable may not be completely implemented yet. -SLB - -(defvar nnfolder-always-close nil - "If non-nil, nnfolder attempts to only ever have one mbox open at a time. -This is a straight space/performance trade off, as the mboxes will have to -be scanned every time they are read in. If nil (default), nnfolder will -attempt to keep the buffers around (saving the nnfolder's buffer upon group -close, but not killing it), speeding some things up tremendously, especially -such things as moving mail. All buffers always get killed upon server close.") - -(defvar nnfolder-newsgroups-file - (concat (file-name-as-directory nnfolder-directory) "newsgroups") +(defvoo nnfolder-ignore-active-file nil + "If non-nil, causes nnfolder to do some extra work in order to determine +the true active ranges of an mbox file. Note that the active file is still +saved, but it's values are not used. This costs some extra time when +scanning an mbox when opening it.") + +(defvoo nnfolder-distrust-mbox nil + "If non-nil, causes nnfolder to not trust the user with respect to +inserting unaccounted for mail in the middle of an mbox file. This can greatly +slow down scans, which now must scan the entire file for unmarked messages. +When nil, scans occur forward from the last marked message, a huge +time saver for large mailboxes.") + +(defvoo nnfolder-newsgroups-file + (concat (file-name-as-directory nnfolder-directory) "newsgroups") "Mail newsgroups description file.") -(defvar nnfolder-get-new-mail t +(defvoo nnfolder-get-new-mail t "If non-nil, nnfolder will check the incoming mail file and split the mail.") -(defvar nnfolder-prepare-save-mail-hook nil +(defvoo nnfolder-prepare-save-mail-hook nil "Hook run narrowed to an article before saving.") +(defvoo nnfolder-save-buffer-hook nil + "Hook run before saving the nnfolder mbox buffer.") + +(defvoo nnfolder-inhibit-expiry nil + "If non-nil, inhibit expiry.") + (defconst nnfolder-version "nnfolder 1.0" @@ -81,230 +87,222 @@ such things as moving mail. All buffers always get killed upon server close.") (defconst nnfolder-article-marker "X-Gnus-Article-Number: " "String used to demarcate what the article number for a message is.") -(defvar nnfolder-current-group nil) -(defvar nnfolder-current-buffer nil) -(defvar nnfolder-status-string "") -(defvar nnfolder-group-alist nil) -(defvar nnfolder-buffer-alist nil) -(defvar nnfolder-active-timestamp nil) - -(defmacro nnfolder-article-string (article) - (` (concat "\n" nnfolder-article-marker (int-to-string (, article)) " "))) - - - -(defvar nnfolder-current-server nil) -(defvar nnfolder-server-alist nil) -(defvar nnfolder-server-variables - (list - (list 'nnfolder-directory nnfolder-directory) - (list 'nnfolder-active-file nnfolder-active-file) - (list 'nnfolder-newsgroups-file nnfolder-newsgroups-file) - (list 'nnfolder-get-new-mail nnfolder-get-new-mail) - '(nnfolder-current-group nil) - '(nnfolder-current-buffer nil) - '(nnfolder-status-string "") - '(nnfolder-group-alist nil) - '(nnfolder-buffer-alist nil) - '(nnfolder-active-timestamp nil))) +(defvoo nnfolder-current-group nil) +(defvoo nnfolder-current-buffer nil) +(defvoo nnfolder-status-string "") +(defvoo nnfolder-group-alist nil) +(defvoo nnfolder-buffer-alist nil) +(defvoo nnfolder-scantime-alist nil) ;;; Interface functions -(defun nnfolder-retrieve-headers (sequence &optional newsgroup server) +(nnoo-define-basics nnfolder) + +(deffoo nnfolder-retrieve-headers (articles &optional group server fetch-old) (save-excursion (set-buffer nntp-server-buffer) (erase-buffer) - (let ((delim-string (concat "^" rmail-unix-mail-delimiter)) + (let ((delim-string (concat "^" message-unix-mail-delimiter)) article art-string start stop) - (nnfolder-possibly-change-group newsgroup) - (set-buffer nnfolder-current-buffer) - (goto-char (point-min)) - (if (stringp (car sequence)) - 'headers - (while sequence - (setq article (car sequence)) - (setq art-string (nnfolder-article-string article)) - (set-buffer nnfolder-current-buffer) - (if (or (search-forward art-string nil t) - ;; Don't search the whole file twice! Also, articles - ;; probably have some locality by number, so searching - ;; backwards will be faster. Especially if we're at the - ;; beginning of the buffer :-). -SLB - (search-backward art-string nil t)) - (progn - (setq start (or (re-search-backward delim-string nil t) - (point))) - (search-forward "\n\n" nil t) - (setq stop (1- (point))) - (set-buffer nntp-server-buffer) - (insert (format "221 %d Article retrieved.\n" article)) - (insert-buffer-substring nnfolder-current-buffer start stop) - (goto-char (point-max)) - (insert ".\n"))) - (setq sequence (cdr sequence))) - - ;; Fold continuation lines. - (set-buffer nntp-server-buffer) + (nnfolder-possibly-change-group group server) + (when nnfolder-current-buffer + (set-buffer nnfolder-current-buffer) (goto-char (point-min)) - (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t) - (replace-match " " t t)) - 'headers)))) - -(defun nnfolder-open-server (server &optional defs) - (nnheader-init-server-buffer) - (if (equal server nnfolder-current-server) - t - (if nnfolder-current-server - (setq nnfolder-server-alist - (cons (list nnfolder-current-server - (nnheader-save-variables nnfolder-server-variables)) - nnfolder-server-alist))) - (let ((state (assoc server nnfolder-server-alist))) - (if state - (progn - (nnheader-restore-variables (nth 1 state)) - (setq nnfolder-server-alist (delq state nnfolder-server-alist))) - (nnheader-set-init-variables nnfolder-server-variables defs))) - (setq nnfolder-current-server server))) - -(defun nnfolder-close-server (&optional server) - t) - -(defun nnfolder-server-opened (&optional server) - (and (equal server nnfolder-current-server) - nntp-server-buffer - (buffer-name nntp-server-buffer))) - -(defun nnfolder-request-close () + (if (stringp (car articles)) + 'headers + (while articles + (setq article (car articles)) + (setq art-string (nnfolder-article-string article)) + (set-buffer nnfolder-current-buffer) + (if (or (search-forward art-string nil t) + ;; Don't search the whole file twice! Also, articles + ;; probably have some locality by number, so searching + ;; backwards will be faster. Especially if we're at the + ;; beginning of the buffer :-). -SLB + (search-backward art-string nil t)) + (progn + (setq start (or (re-search-backward delim-string nil t) + (point))) + (search-forward "\n\n" nil t) + (setq stop (1- (point))) + (set-buffer nntp-server-buffer) + (insert (format "221 %d Article retrieved.\n" article)) + (insert-buffer-substring nnfolder-current-buffer start stop) + (goto-char (point-max)) + (insert ".\n"))) + (setq articles (cdr articles))) + + (set-buffer nntp-server-buffer) + (nnheader-fold-continuation-lines) + 'headers))))) + +(deffoo nnfolder-open-server (server &optional defs) + (nnoo-change-server 'nnfolder server defs) + (when (not (file-exists-p nnfolder-directory)) + (condition-case () + (make-directory nnfolder-directory t) + (error t))) + (cond + ((not (file-exists-p nnfolder-directory)) + (nnfolder-close-server) + (nnheader-report 'nnfolder "Couldn't create directory: %s" + nnfolder-directory)) + ((not (file-directory-p (file-truename nnfolder-directory))) + (nnfolder-close-server) + (nnheader-report 'nnfolder "Not a directory: %s" nnfolder-directory)) + (t + (nnheader-report 'nnfolder "Opened server %s using directory %s" + server nnfolder-directory) + t))) + +(deffoo nnfolder-request-close () (let ((alist nnfolder-buffer-alist)) (while alist - (nnfolder-close-group (car (car alist)) nil t) + (nnfolder-close-group (caar alist) nil t) (setq alist (cdr alist)))) + (nnoo-close-server 'nnfolder) (setq nnfolder-buffer-alist nil nnfolder-group-alist nil)) -(defun nnfolder-status-message (&optional server) - nnfolder-status-string) - -(defun nnfolder-request-article (article &optional newsgroup server buffer) - (nnfolder-possibly-change-group newsgroup) - (if (stringp article) - nil - (save-excursion - (set-buffer nnfolder-current-buffer) - (goto-char (point-min)) - (if (search-forward (nnfolder-article-string article) nil t) - (let (start stop) - (re-search-backward (concat "^" rmail-unix-mail-delimiter) nil t) - (setq start (point)) - (forward-line 1) - (or (and (re-search-forward - (concat "^" rmail-unix-mail-delimiter) nil t) - (forward-line -1)) - (goto-char (point-max))) - (setq stop (point)) - (let ((nntp-server-buffer (or buffer nntp-server-buffer))) - (set-buffer nntp-server-buffer) - (erase-buffer) - (insert-buffer-substring nnfolder-current-buffer start stop) +(deffoo nnfolder-request-article (article &optional group server buffer) + (nnfolder-possibly-change-group group server) + (save-excursion + (set-buffer nnfolder-current-buffer) + (goto-char (point-min)) + (if (search-forward (nnfolder-article-string article) nil t) + (let (start stop) + (re-search-backward (concat "^" message-unix-mail-delimiter) nil t) + (setq start (point)) + (forward-line 1) + (or (and (re-search-forward + (concat "^" message-unix-mail-delimiter) nil t) + (forward-line -1)) + (goto-char (point-max))) + (setq stop (point)) + (let ((nntp-server-buffer (or buffer nntp-server-buffer))) + (set-buffer nntp-server-buffer) + (erase-buffer) + (insert-buffer-substring nnfolder-current-buffer start stop) + (goto-char (point-min)) + (while (looking-at "From ") + (delete-char 5) + (insert "X-From-Line: ") + (forward-line 1)) + (if (numberp article) + (cons nnfolder-current-group article) (goto-char (point-min)) - (while (looking-at "From ") - (delete-char 5) - (insert "X-From-Line: ") - (forward-line 1)) - t)))))) + (search-forward (concat "\n" nnfolder-article-marker)) + (cons nnfolder-current-group + (string-to-int + (buffer-substring + (point) (progn (end-of-line) (point))))))))))) -(defun nnfolder-request-group (group &optional server dont-check) +(deffoo nnfolder-request-group (group &optional server dont-check) (save-excursion (nnmail-activate 'nnfolder) - (nnfolder-possibly-change-group group) - (and (assoc group nnfolder-group-alist) - (progn - (if dont-check - t - (nnfolder-get-new-mail group) - (let* ((active (assoc group nnfolder-group-alist)) - (group (car active)) - (range (car (cdr active))) - (minactive (car range)) - (maxactive (cdr range))) - ;; I've been getting stray 211 lines in my nnfolder active - ;; file. So, let's make sure that doesn't happen. -SLB - (set-buffer nntp-server-buffer) - (erase-buffer) - (if (not active) - () - (insert (format "211 %d %d %d %s\n" - (1+ (- maxactive minactive)) - minactive maxactive group)) - t))))))) + (if (not (assoc group nnfolder-group-alist)) + (nnheader-report 'nnfolder "No such group: %s" group) + (nnfolder-possibly-change-group group server) + (if dont-check + (progn + (nnheader-report 'nnfolder "Selected group %s" group) + t) + (let* ((active (assoc group nnfolder-group-alist)) + (group (car active)) + (range (cadr active))) + (cond + ((null active) + (nnheader-report 'nnfolder "No such group: %s" group)) + ((null nnfolder-current-group) + (nnheader-report 'nnfolder "Empty group: %s" group)) + (t + (nnheader-report 'nnfolder "Selected group %s" group) + (nnheader-insert "211 %d %d %d %s\n" + (1+ (- (cdr range) (car range))) + (car range) (cdr range) group)))))))) + +(deffoo nnfolder-request-scan (&optional group server) + (nnfolder-possibly-change-group group server t) + (nnmail-get-new-mail + 'nnfolder + (lambda () + (let ((bufs nnfolder-buffer-alist)) + (save-excursion + (while bufs + (if (not (buffer-name (nth 1 (car bufs)))) + (setq nnfolder-buffer-alist + (delq (car bufs) nnfolder-buffer-alist)) + (set-buffer (nth 1 (car bufs))) + (nnfolder-save-buffer) + (kill-buffer (current-buffer))) + (setq bufs (cdr bufs)))))) + nnfolder-directory + group)) ;; Don't close the buffer if we're not shutting down the server. This way, ;; we can keep the buffer in the group buffer cache, and not have to grovel ;; over the buffer again unless we add new mail to it or modify it in some ;; way. -(defun nnfolder-close-group (group &optional server force) +(deffoo nnfolder-close-group (group &optional server force) ;; Make sure we _had_ the group open. - (if (or (assoc group nnfolder-buffer-alist) - (equal group nnfolder-current-group)) - (progn - (nnfolder-possibly-change-group group) - (save-excursion - (set-buffer nnfolder-current-buffer) - ;; If the buffer was modified, write the file out now. - (and (buffer-modified-p) (save-buffer)) - (if (or force - nnfolder-always-close) - ;; If we're shutting the server down, we need to kill the - ;; buffer and remove it from the open buffer list. Or, of - ;; course, if we're trying to minimize our space impact. - (progn - (kill-buffer (current-buffer)) - (setq nnfolder-buffer-alist (delq (assoc group - nnfolder-buffer-alist) - nnfolder-buffer-alist))))))) + (when (or (assoc group nnfolder-buffer-alist) + (equal group nnfolder-current-group)) + (let ((inf (assoc group nnfolder-buffer-alist))) + (when inf + (when nnfolder-current-group + (push (list nnfolder-current-group nnfolder-current-buffer) + nnfolder-buffer-alist)) + (setq nnfolder-buffer-alist + (delq inf nnfolder-buffer-alist)) + (setq nnfolder-current-buffer (cadr inf) + nnfolder-current-group (car inf)))) + (when (and nnfolder-current-buffer + (buffer-name nnfolder-current-buffer)) + (save-excursion + (set-buffer nnfolder-current-buffer) + ;; If the buffer was modified, write the file out now. + (nnfolder-save-buffer) + ;; If we're shutting the server down, we need to kill the + ;; buffer and remove it from the open buffer list. Or, of + ;; course, if we're trying to minimize our space impact. + (kill-buffer (current-buffer)) + (setq nnfolder-buffer-alist (delq (assoc group nnfolder-buffer-alist) + nnfolder-buffer-alist))))) (setq nnfolder-current-group nil nnfolder-current-buffer nil) t) -(defun nnfolder-request-create-group (group &optional server) +(deffoo nnfolder-request-create-group (group &optional server) + (nnfolder-possibly-change-group nil server) (nnmail-activate 'nnfolder) - (or (assoc group nnfolder-group-alist) - (let (active) - (setq nnfolder-group-alist - (cons (list group (setq active (cons 1 0))) - nnfolder-group-alist)) - (nnmail-save-active nnfolder-group-alist nnfolder-active-file))) + (when group + (unless (assoc group nnfolder-group-alist) + (push (list group (cons 1 0)) nnfolder-group-alist) + (nnmail-save-active nnfolder-group-alist nnfolder-active-file))) t) -(defun nnfolder-request-list (&optional server) - (if server (nnfolder-get-new-mail)) +(deffoo nnfolder-request-list (&optional server) + (nnfolder-possibly-change-group nil server) (save-excursion (nnmail-find-file nnfolder-active-file) (setq nnfolder-group-alist (nnmail-get-active)))) -(defun nnfolder-request-newgroups (date &optional server) +(deffoo nnfolder-request-newgroups (date &optional server) + (nnfolder-possibly-change-group nil server) (nnfolder-request-list server)) -(defun nnfolder-request-list-newsgroups (&optional server) +(deffoo nnfolder-request-list-newsgroups (&optional server) + (nnfolder-possibly-change-group nil server) (save-excursion (nnmail-find-file nnfolder-newsgroups-file))) -(defun nnfolder-request-post (&optional server) - (mail-send-and-exit nil)) - -(defalias 'nnfolder-request-post-buffer 'nnmail-request-post-buffer) - -(defun nnfolder-request-expire-articles +(deffoo nnfolder-request-expire-articles (articles newsgroup &optional server force) - (nnfolder-possibly-change-group newsgroup) - (let* ((days (or (and nnmail-expiry-wait-function - (funcall nnmail-expiry-wait-function newsgroup)) - nnmail-expiry-wait)) - (is-old t) + (nnfolder-possibly-change-group newsgroup server) + (let* ((is-old t) rest) (nnmail-activate 'nnfolder) @@ -313,22 +311,21 @@ such things as moving mail. All buffers always get killed upon server close.") (while (and articles is-old) (goto-char (point-min)) (if (search-forward (nnfolder-article-string (car articles)) nil t) - (if (or force - (setq is-old - (> (nnmail-days-between - (current-time-string) - (buffer-substring - (point) (progn (end-of-line) (point)))) - days))) + (if (setq is-old + (nnmail-expired-article-p + newsgroup + (buffer-substring + (point) (progn (end-of-line) (point))) + force nnfolder-inhibit-expiry)) (progn - (and gnus-verbose-backends - (message "Deleting article %s..." (car articles))) + (nnheader-message 5 "Deleting article %d..." + (car articles) newsgroup) (nnfolder-delete-mail)) (setq rest (cons (car articles) rest)))) (setq articles (cdr articles))) - (and (buffer-modified-p) (save-buffer)) + (nnfolder-save-buffer) ;; Find the lowest active article in this group. - (let* ((active (car (cdr (assoc newsgroup nnfolder-group-alist)))) + (let* ((active (cadr (assoc newsgroup nnfolder-group-alist))) (marker (concat "\n" nnfolder-article-marker)) (number "[0-9]+") (activemin (cdr active))) @@ -343,9 +340,9 @@ such things as moving mail. All buffers always get killed upon server close.") (nnmail-save-active nnfolder-group-alist nnfolder-active-file) (nconc rest articles)))) -(defun nnfolder-request-move-article +(deffoo nnfolder-request-move-article (article group server accept-form &optional last) - (nnfolder-possibly-change-group group) + (nnfolder-possibly-change-group group server) (let ((buf (get-buffer-create " *nnfolder move*")) result) (and @@ -365,25 +362,23 @@ such things as moving mail. All buffers always get killed upon server close.") (kill-buffer buf) result) (save-excursion - (nnfolder-possibly-change-group group) + (nnfolder-possibly-change-group group server) (set-buffer nnfolder-current-buffer) (goto-char (point-min)) (if (search-forward (nnfolder-article-string article) nil t) (nnfolder-delete-mail)) - (and last - (buffer-modified-p) - (save-buffer)))) + (and last (nnfolder-save-buffer)))) result)) -(defun nnfolder-request-accept-article (group &optional last) +(deffoo nnfolder-request-accept-article (group &optional server last) + (nnfolder-possibly-change-group group server) + (nnmail-check-syntax) (and (stringp group) (nnfolder-possibly-change-group group)) (let ((buf (current-buffer)) result) (goto-char (point-min)) - (cond ((looking-at "X-From-Line: ") - (replace-match "From ")) - ((not (looking-at "From ")) - (insert "From nobody " (current-time-string) "\n"))) + (when (looking-at "X-From-Line: ") + (replace-match "From ")) (and (nnfolder-request-list) (save-excursion @@ -396,11 +391,13 @@ such things as moving mail. All buffers always get killed upon server close.") (setq result (car (nnfolder-save-mail (and (stringp group) group))))) (save-excursion (set-buffer nnfolder-current-buffer) - (and last (buffer-modified-p) (save-buffer)))) + (and last (nnfolder-save-buffer)))) (nnmail-save-active nnfolder-group-alist nnfolder-active-file) + (unless result + (nnheader-report 'nnfolder "Couldn't store article")) result)) -(defun nnfolder-request-replace-article (article group buffer) +(deffoo nnfolder-request-replace-article (article group buffer) (nnfolder-possibly-change-group group) (save-excursion (set-buffer nnfolder-current-buffer) @@ -409,85 +406,140 @@ such things as moving mail. All buffers always get killed upon server close.") nil (nnfolder-delete-mail t t) (insert-buffer-substring buffer) - (and (buffer-modified-p) (save-buffer)) + (nnfolder-save-buffer) t))) +(deffoo nnfolder-request-delete-group (group &optional force server) + (nnfolder-close-group group server t) + ;; Delete all articles in GROUP. + (if (not force) + () ; Don't delete the articles. + ;; Delete the file that holds the group. + (condition-case nil + (delete-file (nnfolder-group-pathname group)) + (error nil))) + ;; Remove the group from all structures. + (setq nnfolder-group-alist + (delq (assoc group nnfolder-group-alist) nnfolder-group-alist) + nnfolder-current-group nil + nnfolder-current-buffer nil) + ;; Save the active file. + (nnmail-save-active nnfolder-group-alist nnfolder-active-file) + t) + +(deffoo nnfolder-request-rename-group (group new-name &optional server) + (nnfolder-possibly-change-group group server) + (save-excursion + (set-buffer nnfolder-current-buffer) + (and (file-writable-p buffer-file-name) + (condition-case () + (progn + (rename-file + buffer-file-name + (nnfolder-group-pathname new-name)) + t) + (error nil)) + ;; That went ok, so we change the internal structures. + (let ((entry (assoc group nnfolder-group-alist))) + (and entry (setcar entry new-name)) + (setq nnfolder-current-buffer nil + nnfolder-current-group nil) + ;; Save the new group alist. + (nnmail-save-active nnfolder-group-alist nnfolder-active-file) + ;; We kill the buffer instead of renaming it and stuff. + (kill-buffer (current-buffer)) + t)))) + ;;; Internal functions. +(defun nnfolder-article-string (article) + (if (numberp article) + (concat "\n" nnfolder-article-marker (int-to-string article) " ") + (concat "\nMessage-ID: " article))) + (defun nnfolder-delete-mail (&optional force leave-delim) - ;; Beginning of the article. + "Delete the message that point is in." (save-excursion - (save-restriction - (narrow-to-region - (save-excursion - (re-search-backward (concat "^" rmail-unix-mail-delimiter) nil t) - (if leave-delim (progn (forward-line 1) (point)) - (match-beginning 0))) - (progn - (forward-line 1) - (or (and (re-search-forward (concat "^" rmail-unix-mail-delimiter) - nil t) - (if (and (not (bobp)) leave-delim) - (progn (forward-line -2) (point)) - (match-beginning 0))) - (point-max)))) - (delete-region (point-min) (point-max))))) - -(defun nnfolder-possibly-change-group (group) - (or (file-exists-p nnfolder-directory) - (make-directory (directory-file-name nnfolder-directory))) - (nnfolder-possibly-activate-groups nil) - (or (assoc group nnfolder-group-alist) - (not (file-exists-p (concat (file-name-as-directory nnfolder-directory) - group))) - (progn - (setq nnfolder-group-alist - (cons (list group (cons 1 0)) nnfolder-group-alist)) - (nnmail-save-active nnfolder-group-alist nnfolder-active-file))) - (let (inf file) - (if (and (equal group nnfolder-current-group) - nnfolder-current-buffer - (buffer-name nnfolder-current-buffer)) - () - (setq nnfolder-current-group group) - - ;; If we have to change groups, see if we don't already have the mbox - ;; in memory. If we do, verify the modtime and destroy the mbox if - ;; needed so we can rescan it. - (if (setq inf (assoc group nnfolder-buffer-alist)) - (setq nnfolder-current-buffer (nth 1 inf))) - - ;; If the buffer is not live, make sure it isn't in the alist. If it - ;; is live, verify that nobody else has touched the file since last - ;; time. - (if (or (not (and nnfolder-current-buffer - (buffer-name nnfolder-current-buffer))) - (not (and (bufferp nnfolder-current-buffer) - (verify-visited-file-modtime - nnfolder-current-buffer)))) - (progn - (if (and nnfolder-current-buffer - (buffer-name nnfolder-current-buffer) - (bufferp nnfolder-current-buffer)) - (kill-buffer nnfolder-current-buffer)) - (setq nnfolder-buffer-alist (delq inf nnfolder-buffer-alist)) - (setq inf nil))) - - (if inf + (delete-region + (save-excursion + (re-search-backward (concat "^" message-unix-mail-delimiter) nil t) + (if leave-delim (progn (forward-line 1) (point)) + (match-beginning 0))) + (progn + (forward-line 1) + (if (re-search-forward (concat "^" message-unix-mail-delimiter) nil t) + (if (and (not (bobp)) leave-delim) + (progn (forward-line -2) (point)) + (match-beginning 0)) + (point-max)))))) + +;; When scanning, we're not looking t immediately switch into the group - if +;; we know our information is up to date, don't even bother reading the file. +(defun nnfolder-possibly-change-group (group &optional server scanning) + (when (and server + (not (nnfolder-server-opened server))) + (nnfolder-open-server server)) + (when (and group (or nnfolder-current-buffer + (not (equal group nnfolder-current-group)))) + (unless (file-exists-p nnfolder-directory) + (make-directory (directory-file-name nnfolder-directory) t)) + (nnfolder-possibly-activate-groups nil) + (or (assoc group nnfolder-group-alist) + (not (file-exists-p + (nnfolder-group-pathname group))) + (progn + (setq nnfolder-group-alist + (cons (list group (cons 1 0)) nnfolder-group-alist)) + (nnmail-save-active nnfolder-group-alist nnfolder-active-file))) + (let (inf file) + (if (and (equal group nnfolder-current-group) + nnfolder-current-buffer + (buffer-name nnfolder-current-buffer)) () - (save-excursion - (setq file (concat (file-name-as-directory nnfolder-directory) - group)) - (if (file-directory-p (file-truename file)) - () - (if (not (file-exists-p file)) + (setq nnfolder-current-group group) + + ;; If we have to change groups, see if we don't already have the mbox + ;; in memory. If we do, verify the modtime and destroy the mbox if + ;; needed so we can rescan it. + (if (setq inf (assoc group nnfolder-buffer-alist)) + (setq nnfolder-current-buffer (nth 1 inf))) + + ;; If the buffer is not live, make sure it isn't in the alist. If it + ;; is live, verify that nobody else has touched the file since last + ;; time. + (if (or (not (and nnfolder-current-buffer + (buffer-name nnfolder-current-buffer))) + (not (and (bufferp nnfolder-current-buffer) + (verify-visited-file-modtime + nnfolder-current-buffer)))) + (progn + (if (and nnfolder-current-buffer + (buffer-name nnfolder-current-buffer) + (bufferp nnfolder-current-buffer)) + (kill-buffer nnfolder-current-buffer)) + (setq nnfolder-buffer-alist (delq inf nnfolder-buffer-alist)) + (setq inf nil))) + + (if inf + () + (save-excursion + (setq file (nnfolder-group-pathname group)) + (if (file-directory-p (file-truename file)) + () + (unless (file-exists-p file) + (unless (file-exists-p (file-name-directory file)) + (make-directory (file-name-directory file) t)) (write-region 1 1 file t 'nomesg)) - (setq nnfolder-current-buffer - (set-buffer (nnfolder-read-folder file))) - (setq nnfolder-buffer-alist (cons (list group (current-buffer)) - nnfolder-buffer-alist))))))) - (setq nnfolder-current-group group)) + (setq nnfolder-current-buffer + (nnfolder-read-folder file scanning)) + (if nnfolder-current-buffer + (progn + (set-buffer nnfolder-current-buffer) + (setq nnfolder-buffer-alist + (cons (list group nnfolder-current-buffer) + nnfolder-buffer-alist))))))))) + (setq nnfolder-current-group group))) (defun nnfolder-save-mail (&optional group) "Called narrowed to an article." @@ -495,10 +547,22 @@ such things as moving mail. All buffers always get killed upon server close.") (if group (list (list group "")) nnmail-split-methods)) (group-art-list (nreverse (nnmail-article-group 'nnfolder-active-number))) + (delim (concat "^" message-unix-mail-delimiter)) save-list group-art) + (goto-char (point-min)) + ;; This might come from somewhere else. + (unless (looking-at delim) + (insert "From nobody " (current-time-string) "\n") + (goto-char (point-min))) + ;; Quote all "From " lines in the article. + (forward-line 1) + (while (re-search-forward delim nil t) + (beginning-of-line) + (insert "> ")) (setq save-list group-art-list) (nnmail-insert-lines) (nnmail-insert-xref group-art-list) + (run-hooks 'nnmail-prepare-save-mail-hook) (run-hooks 'nnfolder-prepare-save-mail-hook) ;; Insert the mail into each of the destination groups. @@ -513,14 +577,21 @@ such things as moving mail. All buffers always get killed upon server close.") (while (search-backward (concat "\n" nnfolder-article-marker) nil t) (delete-region (1+ (point)) (progn (forward-line 2) (point)))) - ;; Insert the new newsgroup marker. (nnfolder-possibly-change-group (car group-art)) + ;; Insert the new newsgroup marker. (nnfolder-insert-newsgroup-line group-art) + (unless nnfolder-current-buffer + (nnfolder-close-group (car group-art)) + (nnfolder-request-create-group (car group-art)) + (nnfolder-possibly-change-group (car group-art))) (let ((beg (point-min)) (end (point-max)) (obuf (current-buffer))) (set-buffer nnfolder-current-buffer) (goto-char (point-max)) + (unless (eolp) + (insert "\n")) + (insert "\n") (insert-buffer-substring obuf beg end) (set-buffer obuf))) @@ -545,22 +616,22 @@ such things as moving mail. All buffers always get killed upon server close.") (nnmail-activate 'nnfolder))) (defun nnfolder-active-number (group) - (save-excursion - ;; Find the next article number in GROUP. - (prog1 - (let ((active (car (cdr (assoc group nnfolder-group-alist))))) - (if active - (setcdr active (1+ (cdr active))) - ;; This group is new, so we create a new entry for it. - ;; This might be a bit naughty... creating groups on the drop of - ;; a hat, but I don't know... - (setq nnfolder-group-alist - (cons (list group (setq active (cons 1 1))) - nnfolder-group-alist))) - (cdr active)) - (nnmail-save-active nnfolder-group-alist nnfolder-active-file) - (nnfolder-possibly-activate-groups group) - ))) + (when group + (save-excursion + ;; Find the next article number in GROUP. + (prog1 + (let ((active (cadr (assoc group nnfolder-group-alist)))) + (if active + (setcdr active (1+ (cdr active))) + ;; This group is new, so we create a new entry for it. + ;; This might be a bit naughty... creating groups on the drop of + ;; a hat, but I don't know... + (setq nnfolder-group-alist + (cons (list group (setq active (cons 1 1))) + nnfolder-group-alist))) + (cdr active)) + (nnmail-save-active nnfolder-group-alist nnfolder-active-file) + (nnfolder-possibly-activate-groups group))))) ;; This method has a problem if you've accidentally let the active list get @@ -578,128 +649,134 @@ such things as moving mail. All buffers always get killed upon server close.") ;; shouldn't cost us much extra time at all, but will be a lot less ;; vulnerable to glitches between the mbox and the active file. -(defun nnfolder-read-folder (file) - (save-excursion - (nnfolder-possibly-activate-groups nil) - ;; We should be paranoid here and make sure the group is in the alist, - ;; and add it if it isn't. - ;;(if (not (assoc nnfoler-current-group nnfolder-group-alist) - (set-buffer (setq nnfolder-current-buffer - (nnheader-find-file-noselect file nil 'raw))) - (buffer-disable-undo (current-buffer)) - (let ((delim (concat "^" rmail-unix-mail-delimiter)) - (marker (concat "\n" nnfolder-article-marker)) - (number "[0-9]+") - (active (car (cdr (assoc nnfolder-current-group - nnfolder-group-alist)))) - activenumber activemin start end) - (goto-char (point-min)) - ;; - ;; Anytime the active number is 1 or 0, it is suspect. In that case, - ;; search the file manually to find the active number. Or, of course, - ;; if we're being paranoid. (This would also be the place to build - ;; other lists from the header markers, such as expunge lists, etc., if - ;; we ever desired to abandon the active file entirely for mboxes.) - (setq activenumber (cdr active)) - (if (or nnfolder-ignore-active-file - (< activenumber 2)) - (progn - (setq activemin (max (1- (lsh 1 23)) - (1- (lsh 1 24)) - (1- (lsh 1 25)))) - (while (and (search-forward marker nil t) - (re-search-forward number nil t)) - (let ((newnum (string-to-number (buffer-substring - (match-beginning 0) - (match-end 0))))) - (setq activenumber (max activenumber newnum)) - (setq activemin (min activemin newnum)))) - (setcar active (max 1 (min activemin activenumber))) - (setcdr active (max activenumber (cdr active))) - (goto-char (point-min)))) - - ;; Keep track of the active number on our own, and insert it back into - ;; the active list when we're done. Also, prime the pump to cut down on - ;; the number of searches we do. - (setq end (point-marker)) - (set-marker end (or (and (re-search-forward delim nil t) - (match-beginning 0)) - (point-max))) - (while (not (= end (point-max))) - (setq start (marker-position end)) - (goto-char end) - ;; There may be more than one "From " line, so we skip past - ;; them. - (while (looking-at delim) - (forward-line 1)) - (set-marker end (or (and (re-search-forward delim nil t) - (match-beginning 0)) - (point-max))) - (goto-char start) - (if (not (search-forward marker end t)) - (progn - (narrow-to-region start end) - (nnmail-insert-lines) - (nnfolder-insert-newsgroup-line - (cons nil (nnfolder-active-number nnfolder-current-group))) - (widen)))) - - ;; Make absolutely sure that the active list reflects reality! - (nnmail-save-active nnfolder-group-alist nnfolder-active-file) - (current-buffer)))) - -(defun nnfolder-get-new-mail (&optional group) - "Read new incoming mail." - (let* ((spools (nnmail-get-spool-files group)) - (group-in group) - incomings incoming) - (if (or (not nnfolder-get-new-mail) (not nnmail-spool-file)) - () - ;; We first activate all the groups. - (nnfolder-possibly-activate-groups nil) - ;; The we go through all the existing spool files and split the - ;; mail from each. - (while spools - (and - (file-exists-p (car spools)) - (> (nth 7 (file-attributes (car spools))) 0) - (progn - (and gnus-verbose-backends - (message "nnfolder: Reading incoming mail...")) - (if (not (setq incoming - (nnmail-move-inbox - (car spools) - (concat (file-name-as-directory nnfolder-directory) - "Incoming")))) - () - (setq incomings (cons incoming incomings)) - (setq group (nnmail-get-split-group (car spools) group-in)) - (nnmail-split-incoming incoming 'nnfolder-save-mail nil group)))) - (setq spools (cdr spools))) - ;; If we did indeed read any incoming spools, we save all info. - (if incoming - (progn - (nnmail-save-active nnfolder-group-alist nnfolder-active-file) - (run-hooks 'nnmail-read-incoming-hook) - (and gnus-verbose-backends - (message "nnfolder: Reading incoming mail...done")))) - (let ((bufs nnfolder-buffer-alist)) - (save-excursion - (while bufs - (if (not (buffer-name (nth 1 (car bufs)))) - (setq nnfolder-buffer-alist - (delq (car bufs) nnfolder-buffer-alist)) - (set-buffer (nth 1 (car bufs))) - (and (buffer-modified-p) (save-buffer))) - (setq bufs (cdr bufs))))) - (while incomings - (setq incoming (car incomings)) - (and - nnmail-delete-incoming - (file-writable-p incoming) - (file-exists-p incoming) - (delete-file incoming)) - (setq incomings (cdr incomings)))))) +(defun nnfolder-read-folder (file &optional scanning) + ;; This is an attempt at a serious shortcut - don't even read in the file + ;; if we know we've seen it since the last time it was touched. + (let ((scantime (cadr (assoc nnfolder-current-group + nnfolder-scantime-alist))) + (modtime (nth 5 (or (file-attributes file) '(nil nil nil nil nil))))) + (if (and scanning scantime + (eq (car scantime) (car modtime)) + (eq (cdr scantime) (cadr modtime))) + nil + (save-excursion + (nnfolder-possibly-activate-groups nil) + ;; Read in the file. + (set-buffer (setq nnfolder-current-buffer + (nnheader-find-file-noselect file nil 'raw))) + (buffer-disable-undo (current-buffer)) + ;; If the file hasn't been touched since the last time we scanned it, + ;; don't bother doing anything with it. + (let ((delim (concat "^" message-unix-mail-delimiter)) + (marker (concat "\n" nnfolder-article-marker)) + (number "[0-9]+") + (active (cadr (assoc nnfolder-current-group + nnfolder-group-alist))) + (scantime (assoc nnfolder-current-group nnfolder-scantime-alist)) + (minid (lsh -1 -1)) + maxid start end newscantime) + + (setq maxid (or (cdr active) 0)) + (goto-char (point-min)) + + ;; Anytime the active number is 1 or 0, it is suspect. In that + ;; case, search the file manually to find the active number. Or, + ;; of course, if we're being paranoid. (This would also be the + ;; place to build other lists from the header markers, such as + ;; expunge lists, etc., if we ever desired to abandon the active + ;; file entirely for mboxes.) + (when (or nnfolder-ignore-active-file + (< maxid 2)) + (while (and (search-forward marker nil t) + (re-search-forward number nil t)) + (let ((newnum (string-to-number (match-string 0)))) + (setq maxid (max maxid newnum)) + (setq minid (min minid newnum)))) + (setcar active (max 1 (min minid maxid))) + (setcdr active (max maxid (cdr active))) + (goto-char (point-min))) + + ;; As long as we trust that the user will only insert unmarked mail + ;; at the end, go to the end and search backwards for the last + ;; marker. Find the start of that message, and begin to search for + ;; unmarked messages from there. + (if (not (or nnfolder-distrust-mbox + (< maxid 2))) + (progn + (goto-char (point-max)) + (if (not (re-search-backward marker nil t)) + (goto-char (point-min)) + (if (not (re-search-backward delim nil t)) + (goto-char (point-min)))))) + + ;; Keep track of the active number on our own, and insert it back + ;; into the active list when we're done. Also, prime the pump to + ;; cut down on the number of searches we do. + (setq end (point-marker)) + (set-marker end (or (and (re-search-forward delim nil t) + (match-beginning 0)) + (point-max))) + (while (not (= end (point-max))) + (setq start (marker-position end)) + (goto-char end) + ;; There may be more than one "From " line, so we skip past + ;; them. + (while (looking-at delim) + (forward-line 1)) + (set-marker end (or (and (re-search-forward delim nil t) + (match-beginning 0)) + (point-max))) + (goto-char start) + (if (not (search-forward marker end t)) + (progn + (narrow-to-region start end) + (nnmail-insert-lines) + (nnfolder-insert-newsgroup-line + (cons nil (nnfolder-active-number nnfolder-current-group))) + (widen)))) + + ;; Make absolutely sure that the active list reflects reality! + (nnmail-save-active nnfolder-group-alist nnfolder-active-file) + ;; Set the scantime for this group. + (setq newscantime (visited-file-modtime)) + (if scantime + (setcdr scantime (list newscantime)) + (push (list nnfolder-current-group newscantime) + nnfolder-scantime-alist)) + (current-buffer)))))) + +;;;###autoload +(defun nnfolder-generate-active-file () + "Look for mbox folders in the nnfolder directory and make them into groups." + (interactive) + (nnmail-activate 'nnfolder) + (let ((files (directory-files nnfolder-directory)) + file) + (while (setq file (pop files)) + (when (and (not (backup-file-name-p file)) + (nnheader-mail-file-mbox-p file)) + (nnheader-message 5 "Adding group %s..." file) + (push (list file (cons 1 0)) nnfolder-group-alist) + (nnfolder-possibly-change-group file) +;; (nnfolder-read-folder file) + (nnfolder-close-group file)) + (message "")))) + +(defun nnfolder-group-pathname (group) + "Make pathname for GROUP." + (let ((dir (file-name-as-directory (expand-file-name nnfolder-directory)))) + ;; If this file exists, we use it directly. + (if (or nnmail-use-long-file-names + (file-exists-p (concat dir group))) + (concat dir group) + ;; If not, we translate dots into slashes. + (concat dir (nnheader-replace-chars-in-string group ?. ?/))))) + +(defun nnfolder-save-buffer () + "Save the buffer." + (when (buffer-modified-p) + (run-hooks 'nnfolder-save-buffer-hook) + (save-buffer))) (provide 'nnfolder) diff --git a/lisp/nnheader.el b/lisp/nnheader.el index 671530620e1..3c6aaa9a509 100644 --- a/lisp/nnheader.el +++ b/lisp/nnheader.el @@ -1,6 +1,5 @@ ;;; nnheader.el --- header access macros for Gnus and its backends - -;; Copyright (C) 1987,88,89,90,93,94,95 Free Software Foundation, Inc. +;; Copyright (C) 1987,88,89,90,93,94,95,96 Free Software Foundation, Inc. ;; Author: Masanobu UMEDA ;; Lars Magne Ingebrigtsen @@ -25,10 +24,10 @@ ;;; Commentary: -;; These macros may look very much like the ones in GNUS 4.1. They +;; These macros may look very much like the ones in GNUS 4.1. They ;; are, in a way, but you should note that the indices they use have -;; been changed from the internal GNUS format to the NOV format. Makes -;; it possible to read headers from XOVER much faster. +;; been changed from the internal GNUS format to the NOV format. The +;; makes it possible to read headers from XOVER much faster. ;; ;; The format of a header is now: ;; [number subject from date id references chars lines xref] @@ -38,110 +37,237 @@ ;;; Code: -(defalias 'nntp-header-number 'mail-header-number) +(require 'mail-utils) +(eval-when-compile (require 'cl)) + +(defvar nnheader-max-head-length 4096 + "*Max length of the head of articles.") + +(defvar nnheader-file-name-translation-alist nil + "*Alist that says how to translate characters in file names. +For instance, if \":\" is illegal as a file character in file names +on your system, you could say something like: + +\(setq nnheader-file-name-translation-alist '((?: . ?_)))") + +;;; Header access macros. + (defmacro mail-header-number (header) "Return article number in HEADER." - (` (aref (, header) 0))) + `(aref ,header 0)) -(defalias 'nntp-set-header-number 'mail-header-set-number) (defmacro mail-header-set-number (header number) "Set article number of HEADER to NUMBER." - (` (aset (, header) 0 (, number)))) + `(aset ,header 0 ,number)) -(defalias 'nntp-header-subject 'mail-header-subject) (defmacro mail-header-subject (header) "Return subject string in HEADER." - (` (aref (, header) 1))) + `(aref ,header 1)) -(defalias 'nntp-set-header-subject 'mail-header-set-subject) (defmacro mail-header-set-subject (header subject) "Set article subject of HEADER to SUBJECT." - (` (aset (, header) 1 (, subject)))) + `(aset ,header 1 ,subject)) -(defalias 'nntp-header-from 'mail-header-from) (defmacro mail-header-from (header) "Return author string in HEADER." - (` (aref (, header) 2))) + `(aref ,header 2)) -(defalias 'nntp-set-header-from 'mail-header-set-from) (defmacro mail-header-set-from (header from) "Set article author of HEADER to FROM." - (` (aset (, header) 2 (, from)))) + `(aset ,header 2 ,from)) -(defalias 'nntp-header-date 'mail-header-date) (defmacro mail-header-date (header) "Return date in HEADER." - (` (aref (, header) 3))) + `(aref ,header 3)) -(defalias 'nntp-set-header-date 'mail-header-set-date) (defmacro mail-header-set-date (header date) "Set article date of HEADER to DATE." - (` (aset (, header) 3 (, date)))) + `(aset ,header 3 ,date)) -(defalias 'nntp-header-id 'mail-header-id) +(defalias 'mail-header-message-id 'mail-header-id) (defmacro mail-header-id (header) "Return Id in HEADER." - (` (aref (, header) 4))) + `(aref ,header 4)) -(defalias 'nntp-set-header-id 'mail-header-set-id) +(defalias 'mail-header-set-message-id 'mail-header-set-id) (defmacro mail-header-set-id (header id) "Set article Id of HEADER to ID." - (` (aset (, header) 4 (, id)))) + `(aset ,header 4 ,id)) -(defalias 'nntp-header-references 'mail-header-references) (defmacro mail-header-references (header) "Return references in HEADER." - (` (aref (, header) 5))) + `(aref ,header 5)) -(defalias 'nntp-set-header-references 'mail-header-set-references) (defmacro mail-header-set-references (header ref) "Set article references of HEADER to REF." - (` (aset (, header) 5 (, ref)))) + `(aset ,header 5 ,ref)) -(defalias 'nntp-header-chars 'mail-header-chars) (defmacro mail-header-chars (header) "Return number of chars of article in HEADER." - (` (aref (, header) 6))) + `(aref ,header 6)) -(defalias 'nntp-set-header-chars 'mail-header-set-chars) (defmacro mail-header-set-chars (header chars) "Set number of chars in article of HEADER to CHARS." - (` (aset (, header) 6 (, chars)))) + `(aset ,header 6 ,chars)) -(defalias 'nntp-header-lines 'mail-header-lines) (defmacro mail-header-lines (header) "Return lines in HEADER." - (` (aref (, header) 7))) + `(aref ,header 7)) -(defalias 'nntp-set-header-lines 'mail-header-set-lines) (defmacro mail-header-set-lines (header lines) "Set article lines of HEADER to LINES." - (` (aset (, header) 7 (, lines)))) + `(aset ,header 7 ,lines)) -(defalias 'nntp-header-xref 'mail-header-xref) (defmacro mail-header-xref (header) "Return xref string in HEADER." - (` (aref (, header) 8))) + `(aref ,header 8)) -(defalias 'nntp-set-header-xref 'mail-header-set-xref) (defmacro mail-header-set-xref (header xref) "Set article xref of HEADER to xref." - (` (aset (, header) 8 (, xref)))) + `(aset ,header 8 ,xref)) + +(defun make-mail-header (&optional init) + "Create a new mail header structure initialized with INIT." + (make-vector 9 init)) + +;; Parsing headers and NOV lines. +(defsubst nnheader-header-value () + (buffer-substring (match-end 0) (gnus-point-at-eol))) + +(defvar nnheader-newsgroup-none-id 1) + +(defun nnheader-parse-head (&optional naked) + (let ((case-fold-search t) + (cur (current-buffer)) + (buffer-read-only nil) + end ref in-reply-to lines p) + (goto-char (point-min)) + (when naked + (insert "\n")) + ;; Search to the beginning of the next header. Error messages + ;; do not begin with 2 or 3. + (prog1 + (when (or naked (re-search-forward "^[23][0-9]+ " nil t)) + ;; This implementation of this function, with nine + ;; search-forwards instead of the one re-search-forward and + ;; a case (which basically was the old function) is actually + ;; about twice as fast, even though it looks messier. You + ;; can't have everything, I guess. Speed and elegance + ;; doesn't always go hand in hand. + (vector + ;; Number. + (if naked + (progn + (setq p (point-min)) + 0) + (prog1 + (read cur) + (end-of-line) + (setq p (point)) + (narrow-to-region (point) + (or (and (search-forward "\n.\n" nil t) + (- (point) 2)) + (point))))) + ;; Subject. + (progn + (goto-char p) + (if (search-forward "\nsubject: " nil t) + (nnheader-header-value) "(none)")) + ;; From. + (progn + (goto-char p) + (if (search-forward "\nfrom: " nil t) + (nnheader-header-value) "(nobody)")) + ;; Date. + (progn + (goto-char p) + (if (search-forward "\ndate: " nil t) + (nnheader-header-value) "")) + ;; Message-ID. + (progn + (goto-char p) + (if (search-forward "\nmessage-id: " nil t) + (nnheader-header-value) + ;; If there was no message-id, we just fake one to make + ;; subsequent routines simpler. + (concat "none+" + (int-to-string + (incf nnheader-newsgroup-none-id))))) + ;; References. + (progn + (goto-char p) + (if (search-forward "\nreferences: " nil t) + (nnheader-header-value) + ;; Get the references from the in-reply-to header if there + ;; were no references and the in-reply-to header looks + ;; promising. + (if (and (search-forward "\nin-reply-to: " nil t) + (setq in-reply-to (nnheader-header-value)) + (string-match "<[^>]+>" in-reply-to)) + (substring in-reply-to (match-beginning 0) + (match-end 0)) + ""))) + ;; Chars. + 0 + ;; Lines. + (progn + (goto-char p) + (if (search-forward "\nlines: " nil t) + (if (numberp (setq lines (read cur))) + lines 0) + 0)) + ;; Xref. + (progn + (goto-char p) + (and (search-forward "\nxref: " nil t) + (nnheader-header-value))))) + (when naked + (goto-char (point-min)) + (delete-char 1))))) + +(defun nnheader-insert-nov (header) + (princ (mail-header-number header) (current-buffer)) + (insert + "\t" + (or (mail-header-subject header) "(none)") "\t" + (or (mail-header-from header) "(nobody)") "\t" + (or (mail-header-date header) "") "\t" + (or (mail-header-id header) + (nnmail-message-id)) "\t" + (or (mail-header-references header) "") "\t") + (princ (or (mail-header-chars header) 0) (current-buffer)) + (insert "\t") + (princ (or (mail-header-lines header) 0) (current-buffer)) + (insert "\t") + (when (mail-header-xref header) + (insert "Xref: " (mail-header-xref header) "\t")) + (insert "\n")) + +(defun nnheader-insert-article-line (article) + (goto-char (point-min)) + (insert "220 ") + (princ article (current-buffer)) + (insert " Article retrieved.\n") + (search-forward "\n\n" nil 'move) + (delete-region (point) (point-max)) + (forward-char -1) + (insert ".")) ;; Various cruft the backends and Gnus need to communicate. (defvar nntp-server-buffer nil) -(defvar gnus-verbose-backends t - "*If non-nil, Gnus backends will generate lots of comments.") +(defvar gnus-verbose-backends 7 + "*A number that says how talkative the Gnus backends should be.") (defvar gnus-nov-is-evil nil "If non-nil, Gnus backends will never output headers in the NOV format.") (defvar news-reply-yank-from nil) (defvar news-reply-yank-message-id nil) -;; All backends use this function, so I moved it to this file. +(defvar nnheader-callback-function nil) (defun nnheader-init-server-buffer () + "Initialize the Gnus-backend communication buffer." (save-excursion (setq nntp-server-buffer (get-buffer-create " *nntpd*")) (set-buffer nntp-server-buffer) @@ -151,62 +277,41 @@ (setq case-fold-search t) ;Should ignore case. t)) -(defun nnheader-set-init-variables (server defs) - (let ((s server) - val) - ;; First we set the server variables in the sequence required. We - ;; use the definitions from the `defs' list where that is - ;; possible. - (while s - (set (car (car s)) - (if (setq val (assq (car (car s)) defs)) - (nth 1 val) - (nth 1 (car s)))) - (setq s (cdr s))) - ;; The we go through the defs list and set any variables that were - ;; not set in the first sweep. - (while defs - (if (not (assq (car (car defs)) server)) - (set (car (car defs)) - (if (and (symbolp (nth 1 (car defs))) - (not (boundp (nth 1 (car defs))))) - (nth 1 (car defs)) - (eval (nth 1 (car defs)))))) - (setq defs (cdr defs))))) - -(defun nnheader-save-variables (server) - (let (out) - (while server - (setq out (cons (list (car (car server)) - (symbol-value (car (car server)))) - out)) - (setq server (cdr server))) - (nreverse out))) - -(defun nnheader-restore-variables (state) - (while state - (set (car (car state)) (nth 1 (car state))) - (setq state (cdr state)))) -(defvar nnheader-max-head-length 4096 - "The maximum length of a HEAD.") +;;; Various functions the backends use. + +(defun nnheader-file-error (file) + "Return a string that says what is wrong with FILE." + (format + (cond + ((not (file-exists-p file)) + "%s does not exist") + ((file-directory-p file) + "%s is a directory") + ((not (file-readable-p file)) + "%s is not readable")) + file)) (defun nnheader-insert-head (file) "Insert the head of the article." - (if (eq nnheader-max-head-length t) - ;; Just read the entire file. - (insert-file-contents-literally file) - ;; Read 1K blocks until we find a separator. - (let ((beg 0) - (chop 1024)) - (while (and (eq chop (nth 1 (insert-file-contents-literally - file nil beg (setq beg (+ beg chop))))) - (prog1 (not (search-forward "\n\n" nil t)) - (goto-char (point-max))) - (or (null nnheader-max-head-length) - (< beg nnheader-max-head-length))))))) + (when (file-exists-p file) + (if (eq nnheader-max-head-length t) + ;; Just read the entire file. + (nnheader-insert-file-contents-literally file) + ;; Read 1K blocks until we find a separator. + (let ((beg 0) + format-alist + (chop 1024)) + (while (and (eq chop (nth 1 (insert-file-contents + file nil beg (incf beg chop)))) + (prog1 (not (search-forward "\n\n" nil t)) + (goto-char (point-max))) + (or (null nnheader-max-head-length) + (< beg nnheader-max-head-length)))))) + t)) (defun nnheader-article-p () + "Say whether the current buffer looks like an article." (goto-char (point-min)) (if (not (search-forward "\n\n" nil t)) nil @@ -218,152 +323,264 @@ (eobp) (widen)))) -;; Written by Erik Naggum . -(defun nnheader-insert-file-contents-literally (filename &optional visit beg end replace) - "Like `insert-file-contents', q.v., but only reads in the file. -A buffer may be modified in several ways after reading into the buffer due -to advanced Emacs features, such as file-name-handlers, format decoding, -find-file-hooks, etc. - This function ensures that none of these modifications will take place." - (let ( ; (file-name-handler-alist nil) - (format-alist nil) - (after-insert-file-functions nil) - (find-buffer-file-type-function - (if (fboundp 'find-buffer-file-type) - (symbol-function 'find-buffer-file-type) - nil))) - (unwind-protect - (progn - (fset 'find-buffer-file-type (lambda (filename) t)) - (insert-file-contents filename visit beg end replace)) - (if find-buffer-file-type-function - (fset 'find-buffer-file-type find-buffer-file-type-function) - (fmakunbound 'find-buffer-file-type))))) - -(defun nnheader-find-file-noselect (filename &optional nowarn rawfile) - "Read file FILENAME into a buffer and return the buffer. -If a buffer exists visiting FILENAME, return that one, but -verify that the file has not changed since visited or saved. -The buffer is not selected, just returned to the caller." - (setq filename - (abbreviate-file-name - (expand-file-name filename))) - (if (file-directory-p filename) - (if find-file-run-dired - (dired-noselect filename) - (error "%s is a directory." filename)) - (let* ((buf (get-file-buffer filename)) - (truename (abbreviate-file-name (file-truename filename))) - (number (nthcdr 10 (file-attributes truename))) - ;; Find any buffer for a file which has same truename. - (other (and (not buf) - (if (fboundp 'find-buffer-visiting) - (find-buffer-visiting filename) - (get-file-buffer filename)))) - error) - ;; Let user know if there is a buffer with the same truename. - (if other - (progn - (or nowarn - (string-equal filename (buffer-file-name other)) - (message "%s and %s are the same file" - filename (buffer-file-name other))) - ;; Optionally also find that buffer. - (if (or (and (boundp 'find-file-existing-other-name) - find-file-existing-other-name) - find-file-visit-truename) - (setq buf other)))) - (if buf - (or nowarn - (verify-visited-file-modtime buf) - (cond ((not (file-exists-p filename)) - (error "File %s no longer exists!" filename)) - ((yes-or-no-p - (if (string= (file-name-nondirectory filename) - (buffer-name buf)) - (format - (if (buffer-modified-p buf) - "File %s changed on disk. Discard your edits? " - "File %s changed on disk. Reread from disk? ") - (file-name-nondirectory filename)) - (format - (if (buffer-modified-p buf) - "File %s changed on disk. Discard your edits in %s? " - "File %s changed on disk. Reread from disk into %s? ") - (file-name-nondirectory filename) - (buffer-name buf)))) - (save-excursion - (set-buffer buf) - (revert-buffer t t))))) - (save-excursion -;;; The truename stuff makes this obsolete. -;;; (let* ((link-name (car (file-attributes filename))) -;;; (linked-buf (and (stringp link-name) -;;; (get-file-buffer link-name)))) -;;; (if (bufferp linked-buf) -;;; (message "Symbolic link to file in buffer %s" -;;; (buffer-name linked-buf)))) - (setq buf (create-file-buffer filename)) - ;; (set-buffer-major-mode buf) - (set-buffer buf) - (erase-buffer) - (if rawfile - (condition-case () - (nnheader-insert-file-contents-literally filename t) - (file-error - ;; Unconditionally set error - (setq error t))) - (condition-case () - (insert-file-contents filename t) - (file-error - ;; Run find-file-not-found-hooks until one returns non-nil. - (or t ; (run-hook-with-args-until-success 'find-file-not-found-hooks) - ;; If they fail too, set error. - (setq error t))))) - ;; Find the file's truename, and maybe use that as visited name. - (setq buffer-file-truename truename) - (setq buffer-file-number number) - ;; On VMS, we may want to remember which directory in a search list - ;; the file was found in. - (and (eq system-type 'vax-vms) - (let (logical) - (if (string-match ":" (file-name-directory filename)) - (setq logical (substring (file-name-directory filename) - 0 (match-beginning 0)))) - (not (member logical find-file-not-true-dirname-list))) - (setq buffer-file-name buffer-file-truename)) - (if find-file-visit-truename - (setq buffer-file-name - (setq filename - (expand-file-name buffer-file-truename)))) - ;; Set buffer's default directory to that of the file. - (setq default-directory (file-name-directory filename)) - ;; Turn off backup files for certain file names. Since - ;; this is a permanent local, the major mode won't eliminate it. - (and (not (funcall backup-enable-predicate buffer-file-name)) - (progn - (make-local-variable 'backup-inhibited) - (setq backup-inhibited t))) - (if rawfile - nil - (after-find-file error (not nowarn))))) - buf))) - (defun nnheader-insert-references (references message-id) + "Insert a References header based on REFERENCES and MESSAGE-ID." (if (and (not references) (not message-id)) - () ; This is illegal, but not all articles have Message-IDs. + () ; This is illegal, but not all articles have Message-IDs. (mail-position-on-field "References") - ;; Fold long references line to follow RFC1036. - (let ((begin (gnus-point-at-bol)) + (let ((begin (save-excursion (beginning-of-line) (point))) (fill-column 78) (fill-prefix "\t")) (if references (insert references)) (if (and references message-id) (insert " ")) (if message-id (insert message-id)) + ;; Fold long References lines to conform to RFC1036 (sort of). ;; The region must end with a newline to fill the region ;; without inserting extra newline. (fill-region-as-paragraph begin (1+ (point)))))) +(defun nnheader-replace-header (header new-value) + "Remove HEADER and insert the NEW-VALUE." + (save-excursion + (save-restriction + (nnheader-narrow-to-headers) + (prog1 + (message-remove-header header) + (goto-char (point-max)) + (insert header ": " new-value "\n"))))) + +(defun nnheader-narrow-to-headers () + "Narrow to the head of an article." + (widen) + (narrow-to-region + (goto-char (point-min)) + (if (search-forward "\n\n" nil t) + (1- (point)) + (point-max))) + (goto-char (point-min))) + +(defun nnheader-set-temp-buffer (name) + "Set-buffer to an empty (possibly new) buffer called NAME with undo disabled." + (set-buffer (get-buffer-create name)) + (buffer-disable-undo (current-buffer)) + (erase-buffer) + (current-buffer)) + +(defmacro nnheader-temp-write (file &rest forms) + "Create a new buffer, evaluate FORM there, and write the buffer to FILE." + `(save-excursion + (let ((nnheader-temp-file ,file) + (nnheader-temp-cur-buffer + (nnheader-set-temp-buffer + (generate-new-buffer-name " *nnheader temp*")))) + (when (and nnheader-temp-file + (not (file-directory-p (file-name-directory + nnheader-temp-file)))) + (make-directory (file-name-directory nnheader-temp-file) t)) + (unwind-protect + (prog1 + (progn + ,@forms) + (when nnheader-temp-file + (set-buffer nnheader-temp-cur-buffer) + (write-region (point-min) (point-max) + nnheader-temp-file nil 'nomesg))) + (when (buffer-name nnheader-temp-cur-buffer) + (kill-buffer nnheader-temp-cur-buffer)))))) + +(put 'nnheader-temp-write 'lisp-indent-function 1) +(put 'nnheader-temp-write 'lisp-indent-hook 1) +(put 'nnheader-temp-write 'edebug-form-spec '(form body)) + +(defvar jka-compr-compression-info-list) +(defvar nnheader-numerical-files + (if (boundp 'jka-compr-compression-info-list) + (concat "\\([0-9]+\\)\\(" + (mapconcat (lambda (i) (aref i 0)) + jka-compr-compression-info-list "\\|") + "\\)?") + "[0-9]+$") + "Regexp that match numerical files.") + +(defvar nnheader-numerical-short-files (concat "^" nnheader-numerical-files) + "Regexp that matches numerical file names.") + +(defvar nnheader-numerical-full-files (concat "/" nnheader-numerical-files) + "Regexp that matches numerical full file paths.") + +(defsubst nnheader-file-to-number (file) + "Take a file name and return the article number." + (if (not (boundp 'jka-compr-compression-info-list)) + (string-to-int file) + (string-match nnheader-numerical-short-files file) + (string-to-int (match-string 0 file)))) + +(defun nnheader-directory-files-safe (&rest args) + ;; It has been reported numerous times that `directory-files' + ;; fails with an alarming frequency on NFS mounted file systems. + ;; This function executes that function twice and returns + ;; the longest result. + (let ((first (apply 'directory-files args)) + (second (apply 'directory-files args))) + (if (> (length first) (length second)) + first + second))) + +(defun nnheader-directory-articles (dir) + "Return a list of all article files in a directory." + (mapcar 'nnheader-file-to-number + (nnheader-directory-files-safe + dir nil nnheader-numerical-short-files t))) + +(defun nnheader-article-to-file-alist (dir) + "Return an alist of article/file pairs in DIR." + (mapcar (lambda (file) (cons (nnheader-file-to-number file) file)) + (nnheader-directory-files-safe + dir nil nnheader-numerical-short-files t))) + +(defun nnheader-fold-continuation-lines () + "Fold continuation lines in the current buffer." + (goto-char (point-min)) + (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t) + (replace-match " " t t))) + +(defun nnheader-translate-file-chars (file) + (if (null nnheader-file-name-translation-alist) + ;; No translation is necessary. + file + ;; We translate -- but only the file name. We leave the directory + ;; alone. + (let* ((i 0) + trans leaf path len) + (if (string-match "/[^/]+\\'" file) + ;; This is needed on NT's and stuff. + (setq leaf (substring file (1+ (match-beginning 0))) + path (substring file 0 (1+ (match-beginning 0)))) + ;; Fall back on this. + (setq leaf (file-name-nondirectory file) + path (file-name-directory file))) + (setq len (length leaf)) + (while (< i len) + (when (setq trans (cdr (assq (aref leaf i) + nnheader-file-name-translation-alist))) + (aset leaf i trans)) + (incf i)) + (concat path leaf)))) + +(defun nnheader-report (backend &rest args) + "Report an error from the BACKEND. +The first string in ARGS can be a format string." + (set (intern (format "%s-status-string" backend)) + (if (< (length args) 2) + (car args) + (apply 'format args))) + nil) + +(defun nnheader-get-report (backend) + (message "%s" (symbol-value (intern (format "%s-status-string" backend))))) + +(defun nnheader-insert (format &rest args) + "Clear the communicaton buffer and insert FORMAT and ARGS into the buffer. +If FORMAT isn't a format string, it and all ARGS will be inserted +without formatting." + (save-excursion + (set-buffer nntp-server-buffer) + (erase-buffer) + (if (string-match "%" format) + (insert (apply 'format format args)) + (apply 'insert format args)) + t)) + +(defun nnheader-mail-file-mbox-p (file) + "Say whether FILE looks like an Unix mbox file." + (when (and (file-exists-p file) + (file-readable-p file) + (file-regular-p file)) + (save-excursion + (nnheader-set-temp-buffer " *mail-file-mbox-p*") + (nnheader-insert-file-contents-literally file) + (goto-char (point-min)) + (prog1 + (looking-at message-unix-mail-delimiter) + (kill-buffer (current-buffer)))))) + +(defun nnheader-replace-chars-in-string (string from to) + "Replace characters in STRING from FROM to TO." + (let ((string (substring string 0)) ;Copy string. + (len (length string)) + (idx 0)) + ;; Replace all occurrences of FROM with TO. + (while (< idx len) + (if (= (aref string idx) from) + (aset string idx to)) + (setq idx (1+ idx))) + string)) + +(defun nnheader-file-to-group (file &optional top) + "Return a group name based on FILE and TOP." + (nnheader-replace-chars-in-string + (if (not top) + file + (condition-case () + (substring (expand-file-name file) + (length + (expand-file-name + (file-name-as-directory top)))) + (error ""))) + ?/ ?.)) + +(defun nnheader-message (level &rest args) + "Message if the Gnus backends are talkative." + (if (or (not (numberp gnus-verbose-backends)) + (<= level gnus-verbose-backends)) + (apply 'message args) + (apply 'format args))) + +(defun nnheader-be-verbose (level) + "Return whether the backends should be verbose on LEVEL." + (or (not (numberp gnus-verbose-backends)) + (<= level gnus-verbose-backends))) + +(defun nnheader-group-pathname (group dir &optional file) + "Make pathname for GROUP." + (concat + (let ((dir (file-name-as-directory (expand-file-name dir)))) + ;; If this directory exists, we use it directly. + (if (file-directory-p (concat dir group)) + (concat dir group "/") + ;; If not, we translate dots into slashes. + (concat dir (nnheader-replace-chars-in-string group ?. ?/) "/"))) + (cond ((null file) "") + ((numberp file) (int-to-string file)) + (t file)))) + +(defun nnheader-functionp (form) + "Return non-nil if FORM is funcallable." + (or (and (symbolp form) (fboundp form)) + (and (listp form) (eq (car form) 'lambda)))) + +(defun nnheader-concat (dir file) + "Concat DIR as directory to FILE." + (concat (file-name-as-directory dir) file)) + +(defun nnheader-ms-strip-cr () + "Strip ^M from the end of all lines." + (save-excursion + (goto-char (point-min)) + (while (re-search-forward "\r$" nil t) + (delete-backward-char 1)))) + +(fset 'nnheader-run-at-time 'run-at-time) +(fset 'nnheader-cancel-timer 'cancel-timer) +(fset 'nnheader-find-file-noselect 'find-file-noselect) +(fset 'nnheader-insert-file-contents-literally + 'insert-file-contents-literally) + +(when (string-match "XEmacs\\|Lucid" emacs-version) + (require 'nnheaderxm)) + +(run-hooks 'nnheader-load-hook) + (provide 'nnheader) ;;; nnheader.el ends here diff --git a/lisp/nnkiboze.el b/lisp/nnkiboze.el index 4260e5fc46f..b314d58d1a9 100644 --- a/lisp/nnkiboze.el +++ b/lisp/nnkiboze.el @@ -1,6 +1,5 @@ ;;; nnkiboze.el --- select virtual news access for Gnus - -;; Copyright (C) 1995 Free Software Foundation, Inc. +;; Copyright (C) 1995,96 Free Software Foundation, Inc. ;; Author: Lars Magne Ingebrigtsen ;; Keywords: news @@ -34,25 +33,35 @@ (require 'nnheader) (require 'gnus) (require 'gnus-score) +(require 'nnoo) +(eval-when-compile (require 'cl)) -(defvar nnkiboze-directory - (expand-file-name (or gnus-article-save-directory "~/News/")) +(nnoo-declare nnkiboze) +(defvoo nnkiboze-directory gnus-directory "nnkiboze will put its files in this directory.") +(defvoo nnkiboze-level 9 + "*The maximum level to be searched for articles.") + +(defvoo nnkiboze-remove-read-articles t + "*If non-nil, nnkiboze will remove read articles from the kiboze group.") + (defconst nnkiboze-version "nnkiboze 1.0" "Version numbers of this version of nnkiboze.") -(defvar nnkiboze-current-group nil) -(defvar nnkiboze-current-score-group "") -(defvar nnkiboze-status-string "") +(defvoo nnkiboze-current-group nil) +(defvoo nnkiboze-current-score-group "") +(defvoo nnkiboze-status-string "") ;;; Interface functions. -(defun nnkiboze-retrieve-headers (articles &optional group server) +(nnoo-define-basics nnkiboze) + +(deffoo nnkiboze-retrieve-headers (articles &optional group server fetch-old) (nnkiboze-possibly-change-newsgroups group) (if gnus-nov-is-evil nil @@ -78,36 +87,22 @@ (if (not (eobp)) (delete-region (point) (point-max))) 'nov)))))) -(defun nnkiboze-open-server (newsgroups &optional something) - "Open a virtual newsgroup that contains NEWSGROUPS." +(deffoo nnkiboze-open-server (newsgroups &optional something) (gnus-make-directory nnkiboze-directory) (nnheader-init-server-buffer)) -(defun nnkiboze-close-server (&rest dum) - "Close news server." - t) - -(defalias 'nnkiboze-request-quit (symbol-function 'nnkiboze-close-server)) - -(defun nnkiboze-server-opened (&optional server) - "Return server process status, T or NIL. -If the stream is opened, return T, otherwise return NIL." +(deffoo nnkiboze-server-opened (&optional server) (and nntp-server-buffer (get-buffer nntp-server-buffer))) -(defun nnkiboze-status-message (&optional server) - "Return server status response as string." - nnkiboze-status-string) - -(defun nnkiboze-request-article (article &optional newsgroup server buffer) - "Select article by message number." +(deffoo nnkiboze-request-article (article &optional newsgroup server buffer) (nnkiboze-possibly-change-newsgroups newsgroup) (if (not (numberp article)) ;; This is a real kludge. It might not work at times, but it ;; does no harm I think. The only alternative is to offer no ;; article fetching by message-id at all. (nntp-request-article article newsgroup gnus-nntp-server buffer) - (let* ((header (gnus-get-header-by-number article)) + (let* ((header (gnus-summary-article-header article)) (xref (mail-header-xref header)) igroup iarticle) (or xref (error "nnkiboze: No xref")) @@ -119,7 +114,7 @@ If the stream is opened, return T, otherwise return NIL." (and (gnus-request-group igroup t) (gnus-request-article iarticle igroup buffer))))) -(defun nnkiboze-request-group (group &optional server dont-check) +(deffoo nnkiboze-request-group (group &optional server dont-check) "Make GROUP the current newsgroup." (nnkiboze-possibly-change-newsgroups group) (if dont-check @@ -144,15 +139,16 @@ If the stream is opened, return T, otherwise return NIL." (insert (format "211 %d %d %d %s\n" total beg end group))))))) t) -(defun nnkiboze-close-group (group &optional server) +(deffoo nnkiboze-close-group (group &optional server) (nnkiboze-possibly-change-newsgroups group) ;; Remove NOV lines of articles that are marked as read. - (if (or (not (file-exists-p (nnkiboze-nov-file-name))) - (not (eq major-mode 'gnus-summary-mode))) - () + (when (and (file-exists-p (nnkiboze-nov-file-name)) + nnkiboze-remove-read-articles + (eq major-mode 'gnus-summary-mode)) (save-excursion (let ((unreads gnus-newsgroup-unreads) - (unselected gnus-newsgroup-unselected)) + (unselected gnus-newsgroup-unselected) + (version-control 'never)) (set-buffer (get-buffer-create "*nnkiboze work*")) (buffer-disable-undo (current-buffer)) (erase-buffer) @@ -170,22 +166,28 @@ If the stream is opened, return T, otherwise return NIL." (kill-buffer (current-buffer))))) (setq nnkiboze-current-group nil))) -(defun nnkiboze-request-list (&optional server) - (setq nnkiboze-status-string "nnkiboze: LIST is not implemented.") - nil) +(deffoo nnkiboze-request-list (&optional server) + (nnheader-report 'nnkiboze "LIST is not implemented.")) -(defun nnkiboze-request-newgroups (date &optional server) +(deffoo nnkiboze-request-newgroups (date &optional server) "List new groups." - (setq nnkiboze-status-string "NEWGROUPS is not supported.") - nil) + (nnheader-report 'nnkiboze "NEWGROUPS is not supported.")) -(defun nnkiboze-request-list-newsgroups (&optional server) - (setq nnkiboze-status-string "nnkiboze: LIST NEWSGROUPS is not implemented.") - nil) +(deffoo nnkiboze-request-list-newsgroups (&optional server) + (nnheader-report 'nnkiboze "LIST NEWSGROUPS is not implemented.")) -(defalias 'nnkiboze-request-post 'nntp-request-post) - -(defalias 'nnkiboze-request-post-buffer 'nntp-request-post-buffer) +(deffoo nnkiboze-request-delete-group (group &optional force server) + (nnkiboze-possibly-change-newsgroups group) + (when force + (let ((files (list (nnkiboze-nov-file-name) + (concat nnkiboze-directory group ".newsrc") + (nnkiboze-score-file group)))) + (while files + (and (file-exists-p (car files)) + (file-writable-p (car files)) + (delete-file (car files))) + (setq files (cdr files))))) + (setq nnkiboze-current-group nil)) ;;; Internal functions. @@ -207,16 +209,24 @@ Finds out what articles are to be part of the nnkiboze groups." (gnus-expert-user t)) (gnus)) (let* ((gnus-newsrc-alist (gnus-copy-sequence gnus-newsrc-alist)) - (newsrc gnus-newsrc-alist)) + (newsrc gnus-newsrc-alist) + gnus-newsrc-hashtb) + (gnus-make-hashtable-from-newsrc-alist) + ;; We have copied all the newsrc alist info over to local copies + ;; so that we can mess all we want with these lists. (while newsrc - (if (string-match "nnkiboze" (car (car newsrc))) - (nnkiboze-generate-group (car (car newsrc)))) + (if (string-match "nnkiboze" (caar newsrc)) + ;; For each kiboze group, we call this function to generate + ;; it. + (nnkiboze-generate-group (caar newsrc))) (setq newsrc (cdr newsrc))))) (defun nnkiboze-score-file (group) (list (expand-file-name - (concat gnus-kill-files-directory nnkiboze-current-score-group - "." gnus-score-file-suffix)))) + (concat (file-name-as-directory gnus-kill-files-directory) + (nnheader-translate-file-chars + (concat nnkiboze-current-score-group + "." gnus-score-file-suffix)))))) (defun nnkiboze-generate-group (group) (let* ((info (nth 2 (gnus-gethash group gnus-newsrc-hashtb))) @@ -225,15 +235,18 @@ Finds out what articles are to be part of the nnkiboze groups." (regexp (nth 1 (nth 4 info))) (gnus-expert-user t) (gnus-large-newsgroup nil) + (version-control 'never) (gnus-score-find-score-files-function 'nnkiboze-score-file) gnus-select-group-hook gnus-summary-prepare-hook gnus-thread-sort-functions gnus-show-threads gnus-visual method nnkiboze-newsrc nov-buffer gname newsrc active - ginfo lowest) + ginfo lowest glevel) (setq nnkiboze-current-score-group group) (or info (error "No such group: %s" group)) + ;; Load the kiboze newsrc file for this group. (and (file-exists-p newsrc-file) (load newsrc-file)) + ;; We also load the nov file for this group. (save-excursion (set-buffer (setq nov-buffer (find-file-noselect nov-file))) (buffer-disable-undo (current-buffer))) @@ -241,50 +254,76 @@ Finds out what articles are to be part of the nnkiboze groups." ;; kiboze regexp. (mapatoms (lambda (group) - (if (and (string-match regexp (setq gname (symbol-name group))) ; Match - (not (assoc gname nnkiboze-newsrc)) ; It isn't registered - (numberp (car (symbol-value group))) ; It is active - (not (string-match "^nnkiboze:" gname))) ; Exclude kibozes - (setq nnkiboze-newsrc - (cons (cons gname (1- (car (symbol-value group)))) - nnkiboze-newsrc)))) + (and (string-match regexp (setq gname (symbol-name group))) ; Match + (not (assoc gname nnkiboze-newsrc)) ; It isn't registered + (numberp (car (symbol-value group))) ; It is active + (or (> nnkiboze-level 7) + (and (setq glevel (nth 1 (nth 2 (gnus-gethash + gname gnus-newsrc-hashtb)))) + (>= nnkiboze-level glevel))) + (not (string-match "^nnkiboze:" gname)) ; Exclude kibozes + (setq nnkiboze-newsrc + (cons (cons gname (1- (car (symbol-value group)))) + nnkiboze-newsrc)))) gnus-active-hashtb) + ;; `newsrc' is set to the list of groups that possibly are + ;; component groups to this kiboze group. This list has elements + ;; on the form `(GROUP . NUMBER)', where NUMBER is the highest + ;; number that has been kibozed in GROUP in this kiboze group. (setq newsrc nnkiboze-newsrc) (while newsrc (if (not (setq active (gnus-gethash - (car (car newsrc)) gnus-active-hashtb))) + (caar newsrc) gnus-active-hashtb))) + ;; This group isn't active after all, so we remove it from + ;; the list of component groups. (setq nnkiboze-newsrc (delq (car newsrc) nnkiboze-newsrc)) + (setq lowest (cdar newsrc)) + ;; Ok, we have a valid component group, so we jump to it. (switch-to-buffer gnus-group-buffer) - (gnus-group-jump-to-group (car (car newsrc))) - (if (and (setq ginfo (nth 2 (gnus-gethash (gnus-group-group-name) - gnus-newsrc-hashtb))) - (nth 3 ginfo)) - (setcar (nthcdr 3 ginfo) nil)) + (gnus-group-jump-to-group (caar newsrc)) + ;; We set all list of article marks to nil. Since we operate + ;; on copies of the real lists, we can destroy anything we + ;; want here. + (and (setq ginfo (nth 2 (gnus-gethash (gnus-group-group-name) + gnus-newsrc-hashtb))) + (nth 3 ginfo) + (setcar (nthcdr 3 ginfo) nil)) + ;; We set the list of read articles to be what we expect for + ;; this kiboze group -- either nil or `(1 . LOWEST)'. + (and ginfo (setcar (nthcdr 2 ginfo) + (and (not (= lowest 1)) (cons 1 lowest)))) (if (not (and (or (not ginfo) (> (length (gnus-list-of-unread-articles (car ginfo))) 0)) (progn (gnus-group-select-group nil) (eq major-mode 'gnus-summary-mode)))) - () - (setq lowest (cdr (car newsrc))) + () ; No unread articles, or we couldn't enter this group. + ;; We are now in the group where we want to be. (setq method (gnus-find-method-for-group gnus-newsgroup-name)) (and (eq method gnus-select-method) (setq method nil)) + ;; We go through the list of scored articles. (while gnus-newsgroup-scored - (if (> (car (car gnus-newsgroup-scored)) lowest) + (if (> (caar gnus-newsgroup-scored) lowest) + ;; If it has a good score, then we enter this article + ;; into the kiboze group. (nnkiboze-enter-nov nov-buffer - (gnus-get-header-by-number (car (car gnus-newsgroup-scored))) + (gnus-summary-article-header + (caar gnus-newsgroup-scored)) (if method (gnus-group-prefixed-name gnus-newsgroup-name method) gnus-newsgroup-name))) (setq gnus-newsgroup-scored (cdr gnus-newsgroup-scored))) - (gnus-summary-quit))) + ;; That's it. We exit this group. + (gnus-summary-exit-no-update))) (setcdr (car newsrc) (car active)) (setq newsrc (cdr newsrc))) + ;; We save the nov file. (set-buffer nov-buffer) (save-buffer) (kill-buffer (current-buffer)) + ;; We save the kiboze newsrc for this group. (set-buffer (get-buffer-create "*nnkiboze work*")) (buffer-disable-undo (current-buffer)) (erase-buffer) @@ -340,8 +379,9 @@ Finds out what articles are to be part of the nnkiboze groups." (insert prefix))))))) (defun nnkiboze-nov-file-name () - (concat nnkiboze-directory - (nnkiboze-prefixed-name nnkiboze-current-group) ".nov")) + (concat (file-name-as-directory nnkiboze-directory) + (nnheader-translate-file-chars + (concat (nnkiboze-prefixed-name nnkiboze-current-group) ".nov")))) (provide 'nnkiboze) diff --git a/lisp/nnmail.el b/lisp/nnmail.el index 6eb69d33c0b..caf0a7c0c30 100644 --- a/lisp/nnmail.el +++ b/lisp/nnmail.el @@ -1,6 +1,5 @@ ;;; nnmail.el --- mail support functions for the Gnus mail backends - -;; Copyright (C) 1995 Free Software Foundation, Inc. +;; Copyright (C) 1995,96 Free Software Foundation, Inc. ;; Author: Lars Magne Ingebrigtsen ;; Keywords: news, mail @@ -27,9 +26,9 @@ ;;; Code: (require 'nnheader) -(require 'rmail) (require 'timezone) -(require 'sendmail) +(require 'message) +(eval-when-compile (require 'cl)) (defvar nnmail-split-methods '(("mail.misc" "")) @@ -66,19 +65,27 @@ If nil, the first match found will be used.") ;; Added by gord@enci.ucalgary.ca (Gordon Matzigkeit). (defvar nnmail-keep-last-article nil - "*If non-nil, nnmail will never delete the last expired article in a -directory. You may need to set this variable if other programs are putting + "*If non-nil, nnmail will never delete the last expired article in a directory. +You may need to set this variable if other programs are putting new mail into folder numbers that Gnus has marked as expired.") +(defvar nnmail-use-long-file-names nil + "*If non-nil the mail backends will use long file and directory names. +If nil, groups like \"mail.misc\" will end up in directories like +\"mail/misc/\".") + (defvar nnmail-expiry-wait 7 - "*Articles that are older than `nnmail-expiry-wait' days will be expired.") + "*Expirable articles that are older than this will be expired. +This variable can either be a number (which will be interpreted as a +number of days) -- this doesn't have to be an integer. This variable +can also be `immediate' and `never'.") (defvar nnmail-expiry-wait-function nil "*Variable that holds function to specify how old articles should be before they are expired. The function will be called with the name of the group that the expiry is to be performed in, and it should return an integer that says how many days an article can be stored before it is considered -'old'. +\"old\". It can also return the values `never' and `immediate'. Eg.: @@ -86,6 +93,7 @@ Eg.: (lambda (newsgroup) (cond ((string-match \"private\" newsgroup) 31) ((string-match \"junk\" newsgroup) 1) + ((string-match \"important\" newsgroup) 'never) (t 7))))") (defvar nnmail-spool-file @@ -97,6 +105,9 @@ If this variable is nil, no mail backends will read incoming mail. If this variable is a list, all files mentioned in this list will be used as incoming mailboxes.") +(defvar nnmail-crash-box "~/.gnus-crash-box" + "*File where Gnus will store mail while processing it.") + (defvar nnmail-use-procmail nil "*If non-nil, the mail backends will look in `nnmail-procmail-directory' for spool files. The file(s) in `nnmail-spool-file' will also be read.") @@ -105,7 +116,7 @@ The file(s) in `nnmail-spool-file' will also be read.") "*When using procmail (and the like), incoming mail is put in this directory. The Gnus mail backends will read the mail from this directory.") -(defvar nnmail-procmail-suffix ".spool" +(defvar nnmail-procmail-suffix "\\.spool" "*Suffix of files created by procmail (and the like). This variable might be a suffix-regexp to match the suffixes of several files - eg. \".spool[0-9]*\".") @@ -113,10 +124,22 @@ several files - eg. \".spool[0-9]*\".") (defvar nnmail-resplit-incoming nil "*If non-nil, re-split incoming procmail sorted mail.") +(defvar nnmail-delete-file-function 'delete-file + "Function called to delete files in some mail backends.") + +(defvar nnmail-crosspost-link-function 'add-name-to-file + "Function called to create a copy of a file. +This is `add-name-to-file' by default, which means that crossposts +will use hard links. If your file system doesn't allow hard +links, you could set this variable to `copy-file' instead.") + (defvar nnmail-movemail-program "movemail" "*A command to be executed to move mail from the inbox. The default is \"movemail\".") +(defvar nnmail-pop-password-required nil + "*Non-nil if a password is required when reading mail using POP.") + (defvar nnmail-read-incoming-hook nil "*Hook that will be run after the incoming mail has been transferred. The incoming mail is moved from `nnmail-spool-file' (which normally is @@ -127,16 +150,37 @@ running (\"xwatch\", etc.) Eg. -(add-hook 'nnmail-read-incoming-hook +\(add-hook 'nnmail-read-incoming-hook (lambda () (start-process \"mailsend\" nil - \"/local/bin/mailsend\" \"read\" \"mbox\")))") + \"/local/bin/mailsend\" \"read\" \"mbox\"))) + +If you have xwatch running, this will alert it that mail has been +read. + +If you use `display-time', you could use something like this: + +\(add-hook 'nnmail-read-incoming-hook + (lambda () + ;; Update the displayed time, since that will clear out + ;; the flag that says you have mail. + (if (eq (process-status \"display-time\") 'run) + (display-time-filter display-time-process \"\"))))") + +(when (eq system-type 'windows-nt) + (add-hook 'nnmail-prepare-incoming-hook 'nnheader-ms-strip-cr)) ;; Suggested by Erik Selberg . (defvar nnmail-prepare-incoming-hook nil "*Hook called before treating incoming mail. The hook is run in a buffer with all the new, incoming mail.") +(defvar nnmail-pre-get-new-mail-hook nil + "Hook called just before starting to handle new incoming mail.") + +(defvar nnmail-post-get-new-mail-hook nil + "Hook called just after finishing handling new incoming mail.") + ;; Suggested by Mejia Pablo J . (defvar nnmail-tmp-directory nil "*If non-nil, use this directory for temporary storage when reading incoming mail.") @@ -165,8 +209,8 @@ GROUP: Mail will be stored in GROUP (a string). \(& SPLIT...): Process each SPLIT expression. FIELD must match a complete field name. VALUE must match a complete -word according to the fundamental mode syntax table. You can use .* -in the regexps to match partial field names or words. +word according to the `nnmail-split-fancy-syntax-table' syntax table. +You can use .* in the regexps to match partial field names or words. FIELD and VALUE can also be lisp symbols, in that case they are expanded as specified in `nnmail-split-abbrev-alist'. @@ -209,8 +253,33 @@ performed.") (defvar nnmail-message-id-cache-file "~/.nnmail-cache" "*The file name of the nnmail Message-ID cache.") -(defvar nnmail-delete-duplicates nil - "*If non-nil, nnmail will delete any duplicate mails it sees.") +(defvar nnmail-treat-duplicates 'warn + "*If non-nil, nnmail keep a cache of Message-IDs to discover mail duplicates. +Three values are legal: nil, which means that nnmail is not to keep a +Message-ID cache; `warn', which means that nnmail should insert extra +headers to warn the user about the duplication (this is the default); +and `delete', which means that nnmail will delete duplicated mails. + +This variable can also be a function. It will be called from a buffer +narrowed to the article in question with the Message-ID as a +parameter. It should return nil, `warn' or `delete'.") + +;;; Internal variables. + +(defvar nnmail-pop-password nil + "*Password to use when reading mail from a POP server, if required.") + +(defvar nnmail-split-fancy-syntax-table + (copy-syntax-table (standard-syntax-table)) + "Syntax table used by `nnmail-split-fancy'.") + +(defvar nnmail-prepare-save-mail-hook nil + "Hook called before saving mail.") + +(defvar nnmail-moved-inboxes nil + "List of inboxes that have been moved.") + +(defvar nnmail-internal-password nil) @@ -222,217 +291,162 @@ performed.") (defun nnmail-request-post (&optional server) (mail-send-and-exit nil)) -(defun nnmail-request-post-buffer (post group subject header article-buffer - info follow-to respect-poster) - (let ((method-address (cdr (assq 'to-address (nth 5 info)))) - from date to reply-to message-of - references message-id cc new-cc sendto elt) - (setq method-address - (if (and (stringp method-address) - (string= method-address "")) - nil method-address)) - (save-excursion - (set-buffer (get-buffer-create "*mail*")) - (mail-mode) - (local-set-key "\C-c\C-c" 'gnus-mail-send-and-exit) - (if (and (buffer-modified-p) - (> (buffer-size) 0) - (not (y-or-n-p "Unsent mail being composed; erase it? "))) - () - (erase-buffer) - (if post - (progn - (mail-setup method-address subject nil nil nil nil) - (auto-save-mode auto-save-default)) - (save-excursion - (set-buffer article-buffer) - (goto-char (point-min)) - (narrow-to-region (point-min) - (progn (search-forward "\n\n") (point))) - (let ((buffer-read-only nil)) - (set-text-properties (point-min) (point-max) nil)) - (setq from (mail-header-from header)) - (setq date (mail-header-date header)) - (and from - (let ((stop-pos - (string-match " *at \\| *@ \\| *(\\| *<" from))) - (setq message-of - (concat (if stop-pos (substring from 0 stop-pos) from) - "'s message of " date)))) - (setq cc (mail-strip-quoted-names (or (mail-fetch-field "cc") ""))) - (setq to (mail-strip-quoted-names (or (mail-fetch-field "to") ""))) - (setq new-cc (rmail-dont-reply-to - (concat (or to "") - (if cc (concat (if to ", " "") cc) "")))) - (let ((rmail-dont-reply-to-names - (regexp-quote (mail-strip-quoted-names - (or method-address reply-to from ""))))) - (setq new-cc (rmail-dont-reply-to new-cc))) - (setq subject (mail-header-subject header)) - (or (string-match "^[Rr][Ee]:" subject) - (setq subject (concat "Re: " subject))) - (setq reply-to (mail-fetch-field "reply-to")) - (setq references (mail-header-references header)) - (setq message-id (mail-header-id header)) - (widen)) - (setq news-reply-yank-from from) - (setq news-reply-yank-message-id message-id) - - ;; Gather the "to" addresses out of the follow-to list and remove - ;; them as we go. - (if (and follow-to (listp follow-to)) - (while (setq elt (assoc "To" follow-to)) - (setq sendto (concat sendto (and sendto ", ") (cdr elt))) - (setq follow-to (delq elt follow-to)))) - (mail-setup (if (and follow-to (listp follow-to)) - sendto - (or method-address reply-to from "")) - subject message-of - (if (zerop (length new-cc)) nil new-cc) - article-buffer nil) - (auto-save-mode auto-save-default) - ;; Note that "To" elements should already be in the message. - (if (and follow-to (listp follow-to)) - (progn - (goto-char (point-min)) - (re-search-forward "^To:" nil t) - (beginning-of-line) - (forward-line 1) - (while follow-to - (insert - (car (car follow-to)) ": " (cdr (car follow-to)) "\n") - (setq follow-to (cdr follow-to))))) - (nnheader-insert-references references message-id))) - (current-buffer)))) - (defun nnmail-find-file (file) "Insert FILE in server buffer safely." (set-buffer nntp-server-buffer) (erase-buffer) - (condition-case () - (progn (insert-file-contents file) t) - (file-error nil))) + (let ((format-alist nil) + (after-insert-file-functions nil)) + (condition-case () + (progn (insert-file-contents file) t) + (file-error nil)))) -(defun nnmail-article-pathname (group mail-dir) +(defun nnmail-group-pathname (group dir &optional file) "Make pathname for GROUP." - (concat (file-name-as-directory (expand-file-name mail-dir)) - (nnmail-replace-chars-in-string group ?. ?/) "/")) - -(defun nnmail-replace-chars-in-string (string from to) - "Replace characters in STRING from FROM to TO." - (let ((string (substring string 0)) ;Copy string. - (len (length string)) - (idx 0)) - ;; Replace all occurrences of FROM with TO. - (while (< idx len) - (if (= (aref string idx) from) - (aset string idx to)) - (setq idx (1+ idx))) - string)) - -(defun nnmail-days-between (date1 date2) - ;; Return the number of days between date1 and date2. - (let ((d1 (mapcar (lambda (s) (and s (string-to-int s)) ) - (timezone-parse-date date1))) - (d2 (mapcar (lambda (s) (and s (string-to-int s)) ) - (timezone-parse-date date2)))) - (- (timezone-absolute-from-gregorian - (nth 1 d1) (nth 2 d1) (car d1)) - (timezone-absolute-from-gregorian - (nth 1 d2) (nth 2 d2) (car d2))))) - -;; Function taken from rmail.el. -(defun nnmail-move-inbox (inbox tofile) + (concat + (let ((dir (file-name-as-directory (expand-file-name dir)))) + ;; If this directory exists, we use it directly. + (if (or nnmail-use-long-file-names + (file-directory-p (concat dir group))) + (concat dir group "/") + ;; If not, we translate dots into slashes. + (concat dir (nnheader-replace-chars-in-string group ?. ?/) "/"))) + (or file ""))) + +(defun nnmail-date-to-time (date) + "Convert DATE into time." + (let* ((d1 (timezone-parse-date date)) + (t1 (timezone-parse-time (aref d1 3)))) + (apply 'encode-time + (mapcar (lambda (el) + (and el (string-to-number el))) + (list + (aref t1 2) (aref t1 1) (aref t1 0) + (aref d1 2) (aref d1 1) (aref d1 0) + (aref d1 4)))))) + +(defun nnmail-time-less (t1 t2) + "Say whether time T1 is less than time T2." + (or (< (car t1) (car t2)) + (and (= (car t1) (car t2)) + (< (nth 1 t1) (nth 1 t2))))) + +(defun nnmail-days-to-time (days) + "Convert DAYS into time." + (let* ((seconds (* 1.0 days 60 60 24)) + (rest (expt 2 16)) + (ms (condition-case nil (round (/ seconds rest)) + (range-error (expt 2 16))))) + (list ms (condition-case nil (round (- seconds (* ms rest))) + (range-error (expt 2 16)))))) + +(defun nnmail-time-since (time) + "Return the time since TIME, which is either an internal time or a date." + (when (stringp time) + ;; Convert date strings to internal time. + (setq time (nnmail-date-to-time time))) + (let* ((current (current-time)) + (rest (if (< (nth 1 current) (nth 1 time)) (expt 2 16)))) + (list (- (+ (car current) (if rest -1 0)) (car time)) + (- (+ (or rest 0) (nth 1 current)) (nth 1 time))))) + +;; Function rewritten from rmail.el. +(defun nnmail-move-inbox (inbox) + "Move INBOX to `nnmail-crash-box'." (let ((inbox (file-truename (expand-file-name (substitute-in-file-name inbox)))) - movemail popmail errors) - ;; Check whether the inbox is to be moved to the special tmp dir. - (if nnmail-tmp-directory - (setq tofile (concat (file-name-as-directory nnmail-tmp-directory) - (file-name-nondirectory tofile)))) - ;; Make the filename unique. - (setq tofile (nnmail-make-complex-temp-name (expand-file-name tofile))) - ;; We create the directory the tofile is to reside in if it - ;; doesn't exist. - (or (file-exists-p (file-name-directory tofile)) - (make-directory tofile 'parents)) + (tofile (file-truename (expand-file-name + (substitute-in-file-name nnmail-crash-box)))) + movemail popmail errors password) ;; If getting from mail spool directory, ;; use movemail to move rather than just renaming, ;; so as to interlock with the mailer. - (or (setq popmail (string-match "^po:" (file-name-nondirectory inbox))) - (setq movemail t)) - (if popmail (setq inbox (file-name-nondirectory inbox))) - (if movemail - ;; On some systems, /usr/spool/mail/foo is a directory - ;; and the actual inbox is /usr/spool/mail/foo/foo. - (if (file-directory-p inbox) - (setq inbox (expand-file-name (user-login-name) inbox)))) - (cond - (popmail - (if (and rmail-pop-password-required (not rmail-pop-password)) - (setq rmail-pop-password - (rmail-read-passwd - (format "Password for %s: " - (substring tofile (+ popmail 3)))))) - (message "Getting mail from post office ...")) - ((or (and (file-exists-p tofile) - (/= 0 (nth 7 (file-attributes tofile)))) - (and (file-exists-p inbox) - (/= 0 (nth 7 (file-attributes inbox))))) - (message "Getting mail from %s..." inbox))) - ;; Set TOFILE if have not already done so, and - ;; rename or copy the file INBOX to TOFILE if and as appropriate. - (cond ((or (file-exists-p tofile) (and (not popmail) - (not (file-exists-p inbox)))) - nil) - ((and (not movemail) (not popmail)) - ;; Try copying. If that fails (perhaps no space), - ;; rename instead. - (condition-case nil - (copy-file inbox tofile nil) - (error - ;; Third arg is t so we can replace existing file TOFILE. - (rename-file inbox tofile t))) - ;; Make the real inbox file empty. - ;; Leaving it deleted could cause lossage - ;; because mailers often won't create the file. - (condition-case () - (write-region (point) (point) inbox) - (file-error nil))) - (t - (unwind-protect - (save-excursion - (setq errors (generate-new-buffer " *nnmail loss*")) - (buffer-disable-undo errors) - (if rmail-pop-password - (call-process - (expand-file-name nnmail-movemail-program exec-directory) - nil errors nil inbox tofile rmail-pop-password) - (call-process - (expand-file-name nnmail-movemail-program exec-directory) - nil errors nil inbox tofile)) - (if (not (buffer-modified-p errors)) - ;; No output => movemail won - nil - (set-buffer errors) - (subst-char-in-region (point-min) (point-max) ?\n ?\ ) - (goto-char (point-max)) - (skip-chars-backward " \t") - (delete-region (point) (point-max)) - (goto-char (point-min)) - (if (looking-at "movemail: ") - (delete-region (point-min) (match-end 0))) - (beep t) - (message "movemail: %s" - (buffer-substring (point-min) - (point-max))) - (sit-for 3) - nil))))) - (and errors - (buffer-name errors) - (kill-buffer errors)) - tofile)) - + (unless (setq popmail (string-match "^po:" (file-name-nondirectory inbox))) + (setq movemail t)) + (when popmail + (setq inbox (file-name-nondirectory inbox))) + (when (and movemail + ;; On some systems, /usr/spool/mail/foo is a directory + ;; and the actual inbox is /usr/spool/mail/foo/foo. + (file-directory-p inbox)) + (setq inbox (expand-file-name (user-login-name) inbox))) + (if (member inbox nnmail-moved-inboxes) + nil + (if popmail + (progn + (setq nnmail-internal-password nnmail-pop-password) + (when (and nnmail-pop-password-required (not nnmail-pop-password)) + (setq nnmail-internal-password + (nnmail-read-passwd + (format "Password for %s: " + (substring inbox (+ popmail 3)))))) + (message "Getting mail from post office ...")) + (when (or (and (file-exists-p tofile) + (/= 0 (nth 7 (file-attributes tofile)))) + (and (file-exists-p inbox) + (/= 0 (nth 7 (file-attributes inbox))))) + (message "Getting mail from %s..." inbox))) + ;; Set TOFILE if have not already done so, and + ;; rename or copy the file INBOX to TOFILE if and as appropriate. + (cond + ((file-exists-p tofile) + ;; The crash box exists already. + t) + ((and (not popmail) + (not (file-exists-p inbox))) + ;; There is no inbox. + (setq tofile nil)) + ((and (not movemail) (not popmail)) + ;; Try copying. If that fails (perhaps no space), + ;; rename instead. + (condition-case nil + (copy-file inbox tofile nil) + (error + ;; Third arg is t so we can replace existing file TOFILE. + (rename-file inbox tofile t))) + (push inbox nnmail-moved-inboxes) + ;; Make the real inbox file empty. + ;; Leaving it deleted could cause lossage + ;; because mailers often won't create the file. + (condition-case () + (write-region (point) (point) inbox) + (file-error nil))) + (t + ;; Use movemail. + (unwind-protect + (save-excursion + (setq errors (generate-new-buffer " *nnmail loss*")) + (buffer-disable-undo errors) + (let ((default-directory "/")) + (apply + 'call-process + (append + (list + (expand-file-name nnmail-movemail-program exec-directory) + nil errors nil inbox tofile) + (when nnmail-internal-password + (list nnmail-internal-password))))) + (if (not (buffer-modified-p errors)) + ;; No output => movemail won + (push inbox nnmail-moved-inboxes) + (set-buffer errors) + (subst-char-in-region (point-min) (point-max) ?\n ?\ ) + (goto-char (point-max)) + (skip-chars-backward " \t") + (delete-region (point) (point-max)) + (goto-char (point-min)) + (if (looking-at "movemail: ") + (delete-region (point-min) (match-end 0))) + (beep t) + (message (concat "movemail: " + (buffer-substring (point-min) + (point-max)))) + (sit-for 3) + (setq tofile nil)))))) + (and errors + (buffer-name errors) + (kill-buffer errors)) + tofile))) (defun nnmail-get-active () "Returns an assoc of group names and active ranges. @@ -444,42 +458,29 @@ nn*-request-list should have been called before calling this function." (goto-char (point-min)) (while (re-search-forward "^\\([^ \t]+\\)[ \t]+\\([0-9]+\\)[ \t]+\\([0-9]+\\)" nil t) - (setq group-assoc - (cons (list (buffer-substring (match-beginning 1) - (match-end 1)) - (cons (string-to-int - (buffer-substring (match-beginning 3) - (match-end 3))) - (string-to-int - (buffer-substring (match-beginning 2) - (match-end 2))))) - group-assoc)))) - - ;; ;; In addition, add all groups mentioned in `nnmail-split-methods'. - ;; (let ((methods (and (not (symbolp nnmail-split-methods)) - ;; nnmail-split-methods))) - ;; (while methods - ;; (if (not (assoc (car (car methods)) group-assoc)) - ;; (setq group-assoc - ;; (cons (list (car (car methods)) (cons 1 0)) - ;; group-assoc))) - ;; (setq methods (cdr methods))) - + ;; We create an alist with `(GROUP (LOW . HIGH))' elements. + (push (list (match-string 1) + (cons (string-to-int (match-string 3)) + (string-to-int (match-string 2)))) + group-assoc))) group-assoc)) (defun nnmail-save-active (group-assoc file-name) - (let (group) - (save-excursion - (set-buffer (get-buffer-create " *nnmail active*")) - (buffer-disable-undo (current-buffer)) - (erase-buffer) - (while group-assoc - (setq group (car group-assoc)) - (insert (format "%s %d %d y\n" (car group) (cdr (car (cdr group)) ) - (car (car (cdr group))))) - (setq group-assoc (cdr group-assoc))) - (write-region 1 (point-max) (expand-file-name file-name) nil 'nomesg) - (kill-buffer (current-buffer))))) + "Save GROUP-ASSOC in ACTIVE-FILE." + (when file-name + (let (group) + (save-excursion + (set-buffer (get-buffer-create " *nnmail active*")) + (buffer-disable-undo (current-buffer)) + (erase-buffer) + (while group-assoc + (setq group (pop group-assoc)) + (insert (format "%s %d %d y\n" (car group) (cdadr group) + (caadr group)))) + (unless (file-exists-p (file-name-directory file-name)) + (make-directory (file-name-directory file-name) t)) + (write-region 1 (point-max) (expand-file-name file-name) nil 'nomesg) + (kill-buffer (current-buffer)))))) (defun nnmail-get-split-group (file group) (if (or (eq nnmail-spool-file 'procmail) @@ -488,7 +489,7 @@ nn*-request-list should have been called before calling this function." ((string-match (concat "^" (expand-file-name (file-name-as-directory nnmail-procmail-directory)) - "\\(.*\\)" nnmail-procmail-suffix "$") + "\\([^/]*\\)" nnmail-procmail-suffix "$") (expand-file-name file)) (substring (expand-file-name file) (match-beginning 1) (match-end 1))) @@ -496,91 +497,252 @@ nn*-request-list should have been called before calling this function." group)) group)) -(defun nnmail-split-incoming (incoming func &optional dont-kill group) +(defun nnmail-process-babyl-mail-format (func) + (let ((case-fold-search t) + start message-id content-length do-search end) + (while (not (eobp)) + (goto-char (point-min)) + (re-search-forward + " \n0, *unseen,+\n\\(\\*\\*\\* EOOH \\*\\*\\*\n\\)?" nil t) + (goto-char (match-end 0)) + (delete-region (match-beginning 0) (match-end 0)) + (setq start (point)) + ;; Skip all the headers in case there are more "From "s... + (or (search-forward "\n\n" nil t) + (search-forward-regexp "^[^:]*\\( .*\\|\\)$" nil t) + (search-forward " ")) + ;; Find the Message-ID header. + (save-excursion + (if (re-search-backward "^Message-ID:[ \t]*\\(<[^>]*>\\)" nil t) + (setq message-id (buffer-substring (match-beginning 1) + (match-end 1))) + ;; There is no Message-ID here, so we create one. + (save-excursion + (when (re-search-backward "^Message-ID:" nil t) + (beginning-of-line) + (insert "Original-"))) + (forward-line -1) + (insert "Message-ID: " (setq message-id (nnmail-message-id)) + "\n"))) + ;; Look for a Content-Length header. + (if (not (save-excursion + (and (re-search-backward + "^Content-Length:[ \t]*\\([0-9]+\\)" start t) + (setq content-length (string-to-int + (buffer-substring + (match-beginning 1) + (match-end 1)))) + ;; We destroy the header, since none of + ;; the backends ever use it, and we do not + ;; want to confuse other mailers by having + ;; a (possibly) faulty header. + (progn (insert "X-") t)))) + (setq do-search t) + (if (or (= (+ (point) content-length) (point-max)) + (save-excursion + (goto-char (+ (point) content-length)) + (looking-at ""))) + (progn + (goto-char (+ (point) content-length)) + (setq do-search nil)) + (setq do-search t))) + ;; Go to the beginning of the next article - or to the end + ;; of the buffer. + (if do-search + (if (re-search-forward "^" nil t) + (goto-char (match-beginning 0)) + (goto-char (1- (point-max))))) + (delete-char 1) ; delete ^_ + (save-excursion + (save-restriction + (narrow-to-region start (point)) + (goto-char (point-min)) + (nnmail-check-duplication message-id func) + (setq end (point-max)))) + (goto-char end)))) + +(defun nnmail-search-unix-mail-delim () + "Put point at the beginning of the next message." + (let ((case-fold-search t) + (delim (concat "^" message-unix-mail-delimiter)) + found) + (while (not found) + (if (re-search-forward delim nil t) + (when (or (looking-at "[^\n :]+ *:") + (looking-at delim) + (looking-at (concat ">" message-unix-mail-delimiter))) + (forward-line -1) + (setq found 'yes)) + (setq found 'no))) + (eq found 'yes))) + +(defun nnmail-process-unix-mail-format (func) + (let ((case-fold-search t) + (delim (concat "^" message-unix-mail-delimiter)) + start message-id content-length end skip head-end) + (goto-char (point-min)) + (if (not (and (re-search-forward delim nil t) + (goto-char (match-beginning 0)))) + ;; Possibly wrong format? + (error "Error, unknown mail format! (Possibly corrupted.)") + ;; Carry on until the bitter end. + (while (not (eobp)) + (setq start (point) + end nil) + ;; Find the end of the head. + (narrow-to-region + start + (if (search-forward "\n\n" nil t) + (1- (point)) + ;; This will never happen, but just to be on the safe side -- + ;; if there is no head-body delimiter, we search a bit manually. + (while (and (looking-at "From \\|[^ \t]+:") + (not (eobp))) + (forward-line 1) + (point)))) + ;; Find the Message-ID header. + (goto-char (point-min)) + (if (re-search-forward "^Message-ID:[ \t]*\\(<[^>]+>\\)" nil t) + (setq message-id (match-string 1)) + (save-excursion + (when (re-search-forward "^Message-ID:" nil t) + (beginning-of-line) + (insert "Original-"))) + ;; There is no Message-ID here, so we create one. + (forward-line 1) + (insert "Message-ID: " (setq message-id (nnmail-message-id)) "\n")) + ;; Look for a Content-Length header. + (goto-char (point-min)) + (if (not (re-search-forward + "^Content-Length:[ \t]*\\([0-9]+\\)" nil t)) + (setq content-length nil) + (setq content-length (string-to-int (match-string 1))) + ;; We destroy the header, since none of the backends ever + ;; use it, and we do not want to confuse other mailers by + ;; having a (possibly) faulty header. + (beginning-of-line) + (insert "X-")) + ;; Find the end of this article. + (goto-char (point-max)) + (widen) + (setq head-end (point)) + ;; We try the Content-Length value. The idea: skip over the header + ;; separator, then check what happens content-length bytes into the + ;; message body. This should be either the end ot the buffer, the + ;; message separator or a blank line followed by the separator. + ;; The blank line should probably be deleted. If neither of the + ;; three is met, the content-length header is probably invalid. + (when content-length + (forward-line 1) + (setq skip (+ (point) content-length)) + (goto-char skip) + (cond ((or (= skip (point-max)) + (= (1+ skip) (point-max))) + (setq end (point-max))) + ((looking-at delim) + (setq end skip)) + ((looking-at + (concat "[ \t]*\n\\(" delim "\\)")) + (setq end (match-beginning 1))) + (t (setq end nil)))) + (if end + (goto-char end) + ;; No Content-Length, so we find the beginning of the next + ;; article or the end of the buffer. + (goto-char head-end) + (or (nnmail-search-unix-mail-delim) + (goto-char (point-max)))) + ;; Allow the backend to save the article. + (save-excursion + (save-restriction + (narrow-to-region start (point)) + (goto-char (point-min)) + (nnmail-check-duplication message-id func) + (setq end (point-max)))) + (goto-char end))))) + +(defun nnmail-process-mmdf-mail-format (func) + (let ((delim "^\^A\^A\^A\^A$") + (case-fold-search t) + start message-id end) + (goto-char (point-min)) + (if (not (and (re-search-forward delim nil t) + (forward-line 1))) + ;; Possibly wrong format? + (error "Error, unknown mail format! (Possibly corrupted.)") + ;; Carry on until the bitter end. + (while (not (eobp)) + (setq start (point)) + ;; Find the end of the head. + (narrow-to-region + start + (if (search-forward "\n\n" nil t) + (1- (point)) + ;; This will never happen, but just to be on the safe side -- + ;; if there is no head-body delimiter, we search a bit manually. + (while (and (looking-at "From \\|[^ \t]+:") + (not (eobp))) + (forward-line 1) + (point)))) + ;; Find the Message-ID header. + (goto-char (point-min)) + (if (re-search-forward "^Message-ID:[ \t]*\\(<[^>]+>\\)" nil t) + (setq message-id (match-string 1)) + ;; There is no Message-ID here, so we create one. + (save-excursion + (when (re-search-backward "^Message-ID:" nil t) + (beginning-of-line) + (insert "Original-"))) + (forward-line 1) + (insert "Message-ID: " (setq message-id (nnmail-message-id)) "\n")) + ;; Find the end of this article. + (goto-char (point-max)) + (widen) + (if (re-search-forward delim nil t) + (beginning-of-line) + (goto-char (point-max))) + ;; Allow the backend to save the article. + (save-excursion + (save-restriction + (narrow-to-region start (point)) + (goto-char (point-min)) + (nnmail-check-duplication message-id func) + (setq end (point-max)))) + (goto-char end) + (forward-line 2))))) + +(defun nnmail-split-incoming (incoming func &optional exit-func group) "Go through the entire INCOMING file and pick out each individual mail. FUNC will be called with the buffer narrowed to each mail." - (let ((delim (concat "^" rmail-unix-mail-delimiter)) - ;; If this is a group-specific split, we bind the split + (let (;; If this is a group-specific split, we bind the split ;; methods to just this group. (nnmail-split-methods (if (and group (or (eq nnmail-spool-file 'procmail) nnmail-use-procmail) (not nnmail-resplit-incoming)) (list (list group "")) - nnmail-split-methods)) - start end content-length do-search message-id) + nnmail-split-methods))) (save-excursion - ;; Open the message-id cache. - (nnmail-cache-open) ;; Insert the incoming file. (set-buffer (get-buffer-create " *nnmail incoming*")) (buffer-disable-undo (current-buffer)) (erase-buffer) - (insert-file-contents incoming) - (goto-char (point-min)) - (save-excursion (run-hooks 'nnmail-prepare-incoming-hook)) - ;; Go to the beginning of the first mail... - (if (and (re-search-forward delim nil t) - (goto-char (match-beginning 0))) - ;; and then carry on until the bitter end. - (while (not (eobp)) - (setq start (point)) - ;; Skip all the headers in case there are more "From "s... - (if (not (search-forward "\n\n" nil t)) - (forward-line 1)) - ;; Find the Message-ID header. - (save-excursion - (if (re-search-backward "^Message-ID:[ \t]*\\(<[^>]*>\\)" nil t) - (setq message-id (buffer-substring (match-beginning 1) - (match-end 1))) - ;; There is no Message-ID here, so we create one. - (forward-line -1) - (insert "Message-ID: " (setq message-id (nnmail-message-id)) - "\n"))) - ;; Look for a Content-Length header. - (if (not (save-excursion - (and (re-search-backward - "^Content-Length: \\([0-9]+\\)" start t) - (setq content-length (string-to-int - (buffer-substring - (match-beginning 1) - (match-end 1)))) - ;; We destroy the header, since none of - ;; the backends ever use it, and we do not - ;; want to confuse other mailers by having - ;; a (possibly) faulty header. - (progn (insert "X-") t)))) - (setq do-search t) - (if (or (= (+ (point) content-length) (point-max)) - (save-excursion - (goto-char (+ (point) content-length)) - (looking-at delim))) - (progn - (goto-char (+ (point) content-length)) - (setq do-search nil)) - (setq do-search t))) - ;; Go to the beginning of the next article - or to the end - ;; of the buffer. - (if do-search - (if (re-search-forward delim nil t) - (goto-char (match-beginning 0)) - (goto-char (point-max)))) - (save-excursion - (save-restriction - (narrow-to-region start (point)) - (goto-char (point-min)) - ;; If this is a duplicate message, then we do not save it. - (if (nnmail-cache-id-exists-p message-id) - (delete-region (point-min) (point-max)) - (nnmail-cache-insert message-id) - (funcall func)) - (setq end (point-max)))) - (goto-char end))) - ;; Close the message-id cache. - (nnmail-cache-close) - (if dont-kill - (current-buffer) - (kill-buffer (current-buffer)))))) + (nnheader-insert-file-contents-literally incoming) + (unless (zerop (buffer-size)) + (goto-char (point-min)) + (save-excursion (run-hooks 'nnmail-prepare-incoming-hook)) + ;; Handle both babyl, MMDF and unix mail formats, since movemail will + ;; use the former when fetching from a mailbox, the latter when + ;; fetches from a file. + (cond ((or (looking-at "\^L") + (looking-at "BABYL OPTIONS:")) + (nnmail-process-babyl-mail-format func)) + ((looking-at "\^A\^A\^A\^A") + (nnmail-process-mmdf-mail-format func)) + (t + (nnmail-process-unix-mail-format func)))) + (if exit-func (funcall exit-func)) + (kill-buffer (current-buffer))))) ;; Mail crossposts suggested by Brian Edmonds . (defun nnmail-article-group (func) @@ -589,20 +751,18 @@ FUNC will be called with the group name to determine the article number." (let ((methods nnmail-split-methods) (obuf (current-buffer)) (beg (point-min)) - end group-art) + end group-art method) (if (and (sequencep methods) (= (length methods) 1)) ;; If there is only just one group to put everything in, we ;; just return a list with just this one method in. (setq group-art - (list (cons (car (car methods)) - (funcall func (car (car methods)))))) + (list (cons (caar methods) (funcall func (caar methods))))) ;; We do actual comparison. (save-excursion ;; Find headers. (goto-char beg) (setq end (if (search-forward "\n\n" nil t) (point) (point-max))) - (set-buffer (get-buffer-create " *nnmail work*")) - (buffer-disable-undo (current-buffer)) + (set-buffer nntp-server-buffer) (erase-buffer) ;; Copy the headers into the work buffer. (insert-buffer-substring obuf beg end) @@ -612,76 +772,76 @@ FUNC will be called with the group name to determine the article number." (replace-match " " t t)) (if (and (symbolp nnmail-split-methods) (fboundp nnmail-split-methods)) + ;; `nnmail-split-methods' is a function, so we just call + ;; this function here and use the result. (setq group-art (mapcar (lambda (group) (cons group (funcall func group))) (condition-case nil - (funcall nnmail-split-methods) + (or (funcall nnmail-split-methods) + '("bogus")) (error - (message "\ -Problems with `nnmail-split-methods', using `bogus' mail group") + (message + "Error in `nnmail-split-methods'; using `bogus' mail group") (sit-for 1) '("bogus"))))) ;; Go through the split methods to find a match. (while (and methods (or nnmail-crosspost (not group-art))) (goto-char (point-max)) - (if (or (cdr methods) - (not (equal "" (nth 1 (car methods))))) - (if (and (condition-case () - (if (stringp (nth 1 (car methods))) - (re-search-backward - (car (cdr (car methods))) nil t) - ;; Suggested by Brian Edmonds - ;; . - (funcall (nth 1 (car methods)) - (car (car methods)))) - (error nil)) - ;; Don't enter the article into the same group twice. - (not (assoc (car (car methods)) group-art))) - (setq group-art - (cons (cons (car (car methods)) - (funcall func (car (car methods)))) - group-art))) - (or group-art - (setq group-art - (list (cons (car (car methods)) - (funcall func (car (car methods)))))))) - (setq methods (cdr methods)))) - (kill-buffer (current-buffer)) + (setq method (pop methods)) + (if (or methods + (not (equal "" (nth 1 method)))) + (when (and + (condition-case () + (if (stringp (nth 1 method)) + (re-search-backward (cadr method) nil t) + ;; Function to say whether this is a match. + (funcall (nth 1 method) (car method))) + (error nil)) + ;; Don't enter the article into the same + ;; group twice. + (not (assoc (car method) group-art))) + (push (cons (car method) (funcall func (car method))) + group-art)) + ;; This is the final group, which is used as a + ;; catch-all. + (unless group-art + (setq group-art + (list (cons (car method) + (funcall func (car method))))))))) group-art)))) (defun nnmail-insert-lines () - "Insert how many lines and chars there are in the body of the mail." + "Insert how many lines there are in the body of the mail. +Return the number of characters in the body." (let (lines chars) (save-excursion (goto-char (point-min)) - (if (search-forward "\n\n" nil t) - (progn - (setq chars (- (point-max) (point))) - (setq lines (- (count-lines (point) (point-max)) 1)) - (forward-char -1) - (save-excursion - (if (re-search-backward "^Lines: " nil t) - (delete-region (point) (progn (forward-line 1) (point))))) - (insert (format "Lines: %d\n" lines)) - chars))))) + (when (search-forward "\n\n" nil t) + (setq chars (- (point-max) (point))) + (setq lines (count-lines (point) (point-max))) + (forward-char -1) + (save-excursion + (when (re-search-backward "^Lines: " nil t) + (delete-region (point) (progn (forward-line 1) (point))))) + (beginning-of-line) + (insert (format "Lines: %d\n" (max lines 0))) + chars)))) (defun nnmail-insert-xref (group-alist) "Insert an Xref line based on the (group . article) alist." (save-excursion (goto-char (point-min)) - (if (search-forward "\n\n" nil t) - (progn - (forward-char -1) - (if (re-search-backward "^Xref: " nil t) - (delete-region (match-beginning 0) - (progn (forward-line 1) (point)))) - (insert (format "Xref: %s" (system-name))) - (while group-alist - (insert (format " %s:%d" (car (car group-alist)) - (cdr (car group-alist)))) - (setq group-alist (cdr group-alist))) - (insert "\n"))))) + (when (search-forward "\n\n" nil t) + (forward-char -1) + (when (re-search-backward "^Xref: " nil t) + (delete-region (match-beginning 0) + (progn (forward-line 1) (point)))) + (insert (format "Xref: %s" (system-name))) + (while group-alist + (insert (format " %s:%d" (caar group-alist) (cdar group-alist))) + (setq group-alist (cdr group-alist))) + (insert "\n")))) ;; Written by byer@mv.us.adobe.com (Scott Byer). (defun nnmail-make-complex-temp-name (prefix) @@ -697,7 +857,12 @@ Problems with `nnmail-split-methods', using `bogus' mail group") (defun nnmail-split-fancy () "Fancy splitting method. See the documentation for the variable `nnmail-split-fancy' for documentation." - (nnmail-split-it nnmail-split-fancy)) + (let ((syntab (syntax-table))) + (unwind-protect + (progn + (set-syntax-table nnmail-split-fancy-syntax-table) + (nnmail-split-it nnmail-split-fancy)) + (set-syntax-table syntab)))) (defvar nnmail-split-cache nil) ;; Alist of split expressions their equivalent regexps. @@ -714,8 +879,9 @@ See the documentation for the variable `nnmail-split-fancy' for documentation." (while (and (not done) (cdr split)) (setq split (cdr split) done (nnmail-split-it (car split)))) - done)) ((assq split nnmail-split-cache) - ;; A compiled match expression. + done)) + ((assq split nnmail-split-cache) + ;; A compiled match expression. (goto-char (point-max)) (if (re-search-backward (cdr (assq split nnmail-split-cache)) nil t) (nnmail-split-it (nth 2 split)))) @@ -733,7 +899,7 @@ See the documentation for the variable `nnmail-split-fancy' for documentation." (cdr (assq value nnmail-split-abbrev-alist)) value) - "\\>\\)"))) + "\\)\\>"))) (setq nnmail-split-cache (cons (cons split regexp) nnmail-split-cache)) (goto-char (point-max)) @@ -744,29 +910,43 @@ See the documentation for the variable `nnmail-split-fancy' for documentation." (defun nnmail-get-spool-files (&optional group) (if (null nnmail-spool-file) ;; No spool file whatsoever. - nil) - (let* ((procmails - ;; If procmail is used to get incoming mail, the files - ;; are stored in this directory. - (and (file-exists-p nnmail-procmail-directory) - (directory-files - nnmail-procmail-directory - t (concat (if group group "") - nnmail-procmail-suffix "$") t))) - (p procmails)) - ;; Remove any directories that inadvertently match the procmail - ;; suffix, which might happen if the suffix is "". - (while p - (and (or (file-directory-p (car p)) - (file-symlink-p (car p))) - (setq procmails (delete (car p) procmails))) - (setq p (cdr p))) - (cond ((listp nnmail-spool-file) - (append nnmail-spool-file procmails)) - ((stringp nnmail-spool-file) - (cons nnmail-spool-file procmails)) - (t - procmails)))) + nil + (let* ((procmails + ;; If procmail is used to get incoming mail, the files + ;; are stored in this directory. + (and (file-exists-p nnmail-procmail-directory) + (or (eq nnmail-spool-file 'procmail) + nnmail-use-procmail) + (directory-files + nnmail-procmail-directory + t (concat (if group (concat "^" group) "") + nnmail-procmail-suffix "$") t))) + (p procmails) + (crash (when (and (file-exists-p nnmail-crash-box) + (> (nth 7 (file-attributes + (file-truename nnmail-crash-box))) 0)) + (list nnmail-crash-box)))) + ;; Remove any directories that inadvertantly match the procmail + ;; suffix, which might happen if the suffix is "". + (while p + (when (file-directory-p (car p)) + (setq procmails (delete (car p) procmails))) + (setq p (cdr p))) + ;; Return the list of spools. + (append + crash + (cond ((and group + (or (eq nnmail-spool-file 'procmail) + nnmail-use-procmail)) + procmails) + ((listp nnmail-spool-file) + (append nnmail-spool-file procmails)) + ((stringp nnmail-spool-file) + (cons nnmail-spool-file procmails)) + ((eq nnmail-spool-file 'pop) + (cons (format "po:%s" (user-login-name)) procmails)) + (t + procmails)))))) ;; Activate a backend only if it isn't already activated. ;; If FORCE, re-read the active file even if the backend is @@ -802,30 +982,7 @@ See the documentation for the variable `nnmail-split-fancy' for documentation." t)) (defun nnmail-message-id () - (concat "<" (nnmail-unique-id) "@totally-fudged-out-message-id>")) - -(defvar nnmail-unique-id-char nil) - -(defun nnmail-number-base36 (num len) - (if (if (< len 0) (<= num 0) (= len 0)) - "" - (concat (nnmail-number-base36 (/ num 36) (1- len)) - (char-to-string (aref "zyxwvutsrqponmlkjihgfedcba9876543210" - (% num 36)))))) - -(defun nnmail-unique-id () - (setq nnmail-unique-id-char - (% (1+ (or nnmail-unique-id-char (logand (random t) (1- (lsh 1 20))))) - ;; (current-time) returns 16-bit ints, - ;; and 2^16*25 just fits into 4 digits i base 36. - (* 25 25))) - (let ((tm (if (fboundp 'current-time) - (current-time) '(12191 46742 287898)))) - (concat - (nnmail-number-base36 (+ (car tm) - (lsh (% nnmail-unique-id-char 25) 16)) 4) - (nnmail-number-base36 (+ (nth 1 tm) - (lsh (/ nnmail-unique-id-char 25) 16)) 4)))) + (concat "<" (message-unique-id) "@totally-fudged-out-message-id>")) ;;; ;;; nnmail duplicate handling @@ -834,7 +991,7 @@ See the documentation for the variable `nnmail-split-fancy' for documentation." (defvar nnmail-cache-buffer nil) (defun nnmail-cache-open () - (if (or (not nnmail-delete-duplicates) + (if (or (not nnmail-treat-duplicates) (and nnmail-cache-buffer (buffer-name nnmail-cache-buffer))) () ; The buffer is open. @@ -845,14 +1002,14 @@ See the documentation for the variable `nnmail-split-fancy' for documentation." (buffer-disable-undo (current-buffer)) (and (file-exists-p nnmail-message-id-cache-file) (insert-file-contents nnmail-message-id-cache-file)) + (set-buffer-modified-p nil) (current-buffer)))) (defun nnmail-cache-close () - (if (or (not nnmail-cache-buffer) - (not nnmail-delete-duplicates) - (not (buffer-name nnmail-cache-buffer)) - (not (buffer-modified-p nnmail-cache-buffer))) - () ; The buffer is closed. + (when (and nnmail-cache-buffer + nnmail-treat-duplicates + (buffer-name nnmail-cache-buffer) + (buffer-modified-p nnmail-cache-buffer)) (save-excursion (set-buffer nnmail-cache-buffer) ;; Weed out the excess number of Message-IDs. @@ -867,23 +1024,174 @@ See the documentation for the variable `nnmail-split-fancy' for documentation." t)) (write-region (point-min) (point-max) nnmail-message-id-cache-file nil 'silent) - (set-buffer-modified-p nil)))) + (set-buffer-modified-p nil) + (setq nnmail-cache-buffer nil) + ;;(kill-buffer (current-buffer)) + ))) (defun nnmail-cache-insert (id) - (and nnmail-delete-duplicates - (save-excursion - (set-buffer nnmail-cache-buffer) - (goto-char (point-max)) - (insert id "\n")))) + (when nnmail-treat-duplicates + (save-excursion + (set-buffer nnmail-cache-buffer) + (goto-char (point-max)) + (insert id "\n")))) (defun nnmail-cache-id-exists-p (id) - (and nnmail-delete-duplicates - (save-excursion - (set-buffer nnmail-cache-buffer) - (goto-char (point-max)) - (search-backward id nil t)))) - - + (when nnmail-treat-duplicates + (save-excursion + (set-buffer nnmail-cache-buffer) + (goto-char (point-max)) + (search-backward id nil t)))) + +(defun nnmail-check-duplication (message-id func) + ;; If this is a duplicate message, then we do not save it. + (let* ((duplication (nnmail-cache-id-exists-p message-id)) + (action (when duplication + (cond + ((memq nnmail-treat-duplicates '(warn delete)) + nnmail-treat-duplicates) + ((nnheader-functionp nnmail-treat-duplicates) + (funcall nnmail-treat-duplicates message-id)) + (t + nnmail-treat-duplicates))))) + (cond + ((not duplication) + (nnmail-cache-insert message-id) + (funcall func)) + ((eq action 'delete) + (delete-region (point-min) (point-max))) + ((eq action 'warn) + ;; We insert a warning. + (let ((case-fold-search t) + (newid (nnmail-message-id))) + (goto-char (point-min)) + (when (re-search-forward "^message-id:" nil t) + (beginning-of-line) + (insert "Original-")) + (beginning-of-line) + (insert + "Message-ID: " newid "\n" + "Gnus-Warning: This is a duplicate of message " message-id "\n") + (nnmail-cache-insert newid) + (funcall func))) + (t + (funcall func))))) + +;;; Get new mail. + +(defun nnmail-get-value (&rest args) + (let ((sym (intern (apply 'format args)))) + (when (boundp sym) + (symbol-value sym)))) + +(defun nnmail-get-new-mail (method exit-func temp + &optional group spool-func) + "Read new incoming mail." + (let* ((spools (nnmail-get-spool-files group)) + (group-in group) + incoming incomings spool) + (when (and (nnmail-get-value "%s-get-new-mail" method) + nnmail-spool-file) + ;; We first activate all the groups. + (nnmail-activate method) + ;; Allow the user to hook. + (run-hooks 'nnmail-pre-get-new-mail-hook) + ;; Open the message-id cache. + (nnmail-cache-open) + ;; The we go through all the existing spool files and split the + ;; mail from each. + (while spools + (setq spool (pop spools)) + ;; We read each spool file if either the spool is a POP-mail + ;; spool, or the file exists. We can't check for the + ;; existance of POPped mail. + (when (or (string-match "^po:" spool) + (and (file-exists-p spool) + (> (nth 7 (file-attributes (file-truename spool))) 0))) + (nnheader-message 3 "%s: Reading incoming mail..." method) + (when (and (nnmail-move-inbox spool) + (file-exists-p nnmail-crash-box)) + ;; There is new mail. We first find out if all this mail + ;; is supposed to go to some specific group. + (setq group (nnmail-get-split-group spool group-in)) + ;; We split the mail + (nnmail-split-incoming + nnmail-crash-box (intern (format "%s-save-mail" method)) + spool-func group) + ;; Check whether the inbox is to be moved to the special tmp dir. + (setq incoming + (nnmail-make-complex-temp-name + (expand-file-name + (if nnmail-tmp-directory + (concat + (file-name-as-directory nnmail-tmp-directory) + (file-name-nondirectory (concat temp "Incoming"))) + (concat temp "Incoming"))))) + (rename-file nnmail-crash-box incoming t) + (push incoming incomings)))) + ;; If we did indeed read any incoming spools, we save all info. + (when incomings + (nnmail-save-active + (nnmail-get-value "%s-group-alist" method) + (nnmail-get-value "%s-active-file" method)) + (when exit-func + (funcall exit-func)) + (run-hooks 'nnmail-read-incoming-hook) + (nnheader-message 3 "%s: Reading incoming mail...done" method)) + ;; Close the message-id cache. + (nnmail-cache-close) + ;; Allow the user to hook. + (run-hooks 'nnmail-post-get-new-mail-hook) + ;; Delete all the temporary files. + (while incomings + (setq incoming (pop incomings)) + (and nnmail-delete-incoming + (file-exists-p incoming) + (file-writable-p incoming) + (delete-file incoming)))))) + +(defun nnmail-expired-article-p (group time force &optional inhibit) + "Say whether an article that is TIME old in GROUP should be expired." + (if force + t + (let ((days (or (and nnmail-expiry-wait-function + (funcall nnmail-expiry-wait-function group)) + nnmail-expiry-wait))) + (cond ((or (eq days 'never) + (and (not force) + inhibit)) + ;; This isn't an expirable group. + nil) + ((eq days 'immediate) + ;; We expire all articles on sight. + t) + ((equal time '(0 0)) + ;; This is an ange-ftp group, and we don't have any dates. + nil) + ((numberp days) + (setq days (nnmail-days-to-time days)) + ;; Compare the time with the current time. + (nnmail-time-less days (nnmail-time-since time))))))) + +(defvar nnmail-read-passwd nil) +(defun nnmail-read-passwd (prompt) + (unless nnmail-read-passwd + (if (load "passwd" t) + (setq nnmail-read-passwd 'read-passwd) + (autoload 'ange-ftp-read-passwd "ange-ftp") + (setq nnmail-read-passwd 'ange-ftp-read-passwd))) + (funcall nnmail-read-passwd prompt)) + +(defun nnmail-check-syntax () + "Check (and modify) the syntax of the message in the current buffer." + (save-restriction + (message-narrow-to-head) + (let ((case-fold-search t)) + (unless (re-search-forward "^Message-Id:" nil t) + (insert "Message-ID: " (nnmail-message-id) "\n"))))) + +(run-hooks 'nnmail-load-hook) + (provide 'nnmail) ;;; nnmail.el ends here diff --git a/lisp/nnmbox.el b/lisp/nnmbox.el index f8560cb3814..171463740db 100644 --- a/lisp/nnmbox.el +++ b/lisp/nnmbox.el @@ -1,6 +1,5 @@ ;;; nnmbox.el --- mail mbox access for Gnus - -;; Copyright (C) 1995 Free Software Foundation, Inc. +;; Copyright (C) 1995,96 Free Software Foundation, Inc. ;; Author: Lars Magne Ingebrigtsen ;; Masanobu UMEDA @@ -31,19 +30,23 @@ ;;; Code: (require 'nnheader) -(require 'rmail) +(require 'message) (require 'nnmail) +(require 'nnoo) +(eval-when-compile (require 'cl)) + +(nnoo-declare nnmbox) -(defvar nnmbox-mbox-file (expand-file-name "~/mbox") +(defvoo nnmbox-mbox-file (expand-file-name "~/mbox") "The name of the mail box file in the user's home directory.") -(defvar nnmbox-active-file (expand-file-name "~/.mbox-active") +(defvoo nnmbox-active-file (expand-file-name "~/.mbox-active") "The name of the active file for the mail box.") -(defvar nnmbox-get-new-mail t +(defvoo nnmbox-get-new-mail t "If non-nil, nnmbox will check the incoming mail file and split the mail.") -(defvar nnmbox-prepare-save-mail-hook nil +(defvoo nnmbox-prepare-save-mail-hook nil "Hook run narrowed to an article before saving.") @@ -51,191 +54,172 @@ (defconst nnmbox-version "nnmbox 1.0" "nnmbox version.") -(defvar nnmbox-current-group nil +(defvoo nnmbox-current-group nil "Current nnmbox news group directory.") (defconst nnmbox-mbox-buffer nil) -(defvar nnmbox-status-string "") - -(defvar nnmbox-group-alist nil) -(defvar nnmbox-active-timestamp nil) +(defvoo nnmbox-status-string "") - - -(defvar nnmbox-current-server nil) -(defvar nnmbox-server-alist nil) -(defvar nnmbox-server-variables - (list - (list 'nnmbox-mbox-file nnmbox-mbox-file) - (list 'nnmbox-active-file nnmbox-active-file) - (list 'nnmbox-get-new-mail nnmbox-get-new-mail) - '(nnmbox-current-group nil) - '(nnmbox-status-string "") - '(nnmbox-group-alist nil))) +(defvoo nnmbox-group-alist nil) +(defvoo nnmbox-active-timestamp nil) ;;; Interface functions -(defun nnmbox-retrieve-headers (sequence &optional newsgroup server) +(nnoo-define-basics nnmbox) + +(deffoo nnmbox-retrieve-headers (sequence &optional newsgroup server fetch-old) (save-excursion (set-buffer nntp-server-buffer) (erase-buffer) (let ((number (length sequence)) (count 0) article art-string start stop) - (nnmbox-possibly-change-newsgroup newsgroup) - (if (stringp (car sequence)) - 'headers - (while sequence - (setq article (car sequence)) - (setq art-string (nnmbox-article-string article)) - (set-buffer nnmbox-mbox-buffer) - (if (or (search-forward art-string nil t) - (progn (goto-char (point-min)) - (search-forward art-string nil t))) - (progn - (setq start - (save-excursion - (re-search-backward - (concat "^" rmail-unix-mail-delimiter) nil t) - (point))) - (search-forward "\n\n" nil t) - (setq stop (1- (point))) - (set-buffer nntp-server-buffer) - (insert (format "221 %d Article retrieved.\n" article)) - (insert-buffer-substring nnmbox-mbox-buffer start stop) - (goto-char (point-max)) - (insert ".\n"))) - (setq sequence (cdr sequence)) - (setq count (1+ count)) - (and (numberp nnmail-large-newsgroup) - (> number nnmail-large-newsgroup) - (zerop (% count 20)) - gnus-verbose-backends - (message "nnmbox: Receiving headers... %d%%" - (/ (* count 100) number)))) - + (nnmbox-possibly-change-newsgroup newsgroup server) + (while sequence + (setq article (car sequence)) + (setq art-string (nnmbox-article-string article)) + (set-buffer nnmbox-mbox-buffer) + (if (or (search-forward art-string nil t) + (progn (goto-char (point-min)) + (search-forward art-string nil t))) + (progn + (setq start + (save-excursion + (re-search-backward + (concat "^" message-unix-mail-delimiter) nil t) + (point))) + (search-forward "\n\n" nil t) + (setq stop (1- (point))) + (set-buffer nntp-server-buffer) + (insert (format "221 %d Article retrieved.\n" article)) + (insert-buffer-substring nnmbox-mbox-buffer start stop) + (goto-char (point-max)) + (insert ".\n"))) + (setq sequence (cdr sequence)) + (setq count (1+ count)) (and (numberp nnmail-large-newsgroup) (> number nnmail-large-newsgroup) - gnus-verbose-backends - (message "nnmbox: Receiving headers...done")) - - ;; Fold continuation lines. - (set-buffer nntp-server-buffer) - (goto-char (point-min)) - (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t) - (replace-match " " t t)) - 'headers)))) - -(defun nnmbox-open-server (server &optional defs) - (nnheader-init-server-buffer) - (if (equal server nnmbox-current-server) - t - (if nnmbox-current-server - (setq nnmbox-server-alist - (cons (list nnmbox-current-server - (nnheader-save-variables nnmbox-server-variables)) - nnmbox-server-alist))) - (let ((state (assoc server nnmbox-server-alist))) - (if state - (progn - (nnheader-restore-variables (nth 1 state)) - (setq nnmbox-server-alist (delq state nnmbox-server-alist))) - (nnheader-set-init-variables nnmbox-server-variables defs))) - (setq nnmbox-current-server server))) - -(defun nnmbox-close-server (&optional server) + (zerop (% count 20)) + (nnheader-message 5 "nnmbox: Receiving headers... %d%%" + (/ (* count 100) number)))) + + (and (numberp nnmail-large-newsgroup) + (> number nnmail-large-newsgroup) + (nnheader-message 5 "nnmbox: Receiving headers...done")) + + (set-buffer nntp-server-buffer) + (nnheader-fold-continuation-lines) + 'headers))) + +(deffoo nnmbox-open-server (server &optional defs) + (nnoo-change-server 'nnmbox server defs) + (cond + ((not (file-exists-p nnmbox-mbox-file)) + (nnmbox-close-server) + (nnheader-report 'nnmbox "No such file: %s" nnmbox-mbox-file)) + ((file-directory-p nnmbox-mbox-file) + (nnmbox-close-server) + (nnheader-report 'nnmbox "Not a regular file: %s" nnmbox-mbox-file)) + (t + (nnheader-report 'nnmbox "Opened server %s using mbox %s" server + nnmbox-mbox-file) + t))) + +(deffoo nnmbox-close-server (&optional server) + (when (and nnmbox-mbox-buffer + (buffer-name nnmbox-mbox-buffer)) + (kill-buffer nnmbox-mbox-buffer)) + (nnoo-close-server 'nnmbox server) t) -(defun nnmbox-server-opened (&optional server) - (and (equal server nnmbox-current-server) +(deffoo nnmbox-server-opened (&optional server) + (and (nnoo-current-server-p 'nnmbox server) nnmbox-mbox-buffer (buffer-name nnmbox-mbox-buffer) nntp-server-buffer (buffer-name nntp-server-buffer))) -(defun nnmbox-status-message (&optional server) - nnmbox-status-string) - -(defun nnmbox-request-article (article &optional newsgroup server buffer) - (nnmbox-possibly-change-newsgroup newsgroup) - (if (stringp article) - nil - (save-excursion - (set-buffer nnmbox-mbox-buffer) - (goto-char (point-min)) - (if (search-forward (nnmbox-article-string article) nil t) - (let (start stop) - (re-search-backward (concat "^" rmail-unix-mail-delimiter) nil t) - (setq start (point)) - (forward-line 1) - (or (and (re-search-forward - (concat "^" rmail-unix-mail-delimiter) nil t) - (forward-line -1)) - (goto-char (point-max))) - (setq stop (point)) - (let ((nntp-server-buffer (or buffer nntp-server-buffer))) - (set-buffer nntp-server-buffer) - (erase-buffer) - (insert-buffer-substring nnmbox-mbox-buffer start stop) - (goto-char (point-min)) - (while (looking-at "From ") - (delete-char 5) - (insert "X-From-Line: ") - (forward-line 1)) - t)))))) - -(defun nnmbox-request-group (group &optional server dont-check) +(deffoo nnmbox-request-article (article &optional newsgroup server buffer) + (nnmbox-possibly-change-newsgroup newsgroup server) (save-excursion - (if (nnmbox-possibly-change-newsgroup group) - (if dont-check - t - (nnmbox-get-new-mail group) - (save-excursion + (set-buffer nnmbox-mbox-buffer) + (goto-char (point-min)) + (if (search-forward (nnmbox-article-string article) nil t) + (let (start stop) + (re-search-backward (concat "^" message-unix-mail-delimiter) nil t) + (setq start (point)) + (forward-line 1) + (or (and (re-search-forward + (concat "^" message-unix-mail-delimiter) nil t) + (forward-line -1)) + (goto-char (point-max))) + (setq stop (point)) + (let ((nntp-server-buffer (or buffer nntp-server-buffer))) (set-buffer nntp-server-buffer) (erase-buffer) - (let ((active (assoc group nnmbox-group-alist))) - (insert (format "211 %d %d %d %s\n" - (1+ (- (cdr (car (cdr active))) - (car (car (cdr active))))) - (car (car (cdr active))) - (cdr (car (cdr active))) - (car active)))) - t))))) - -(defun nnmbox-close-group (group &optional server) + (insert-buffer-substring nnmbox-mbox-buffer start stop) + (goto-char (point-min)) + (while (looking-at "From ") + (delete-char 5) + (insert "X-From-Line: ") + (forward-line 1)) + (if (numberp article) + (cons nnmbox-current-group article) + (nnmbox-article-group-number))))))) + +(deffoo nnmbox-request-group (group &optional server dont-check) + (let ((active (cadr (assoc group nnmbox-group-alist)))) + (cond + ((or (null active) + (null (nnmbox-possibly-change-newsgroup group server))) + (nnheader-report 'nnmbox "No such group: %s" group)) + (dont-check + (nnheader-report 'nnmbox "Selected group %s" group) + (nnheader-insert "")) + (t + (nnheader-report 'nnmbox "Selected group %s" group) + (nnheader-insert "211 %d %d %d %s\n" + (1+ (- (cdr active) (car active))) + (car active) (cdr active) group))))) + +(deffoo nnmbox-request-scan (&optional group server) + (nnmbox-read-mbox) + (nnmail-get-new-mail + 'nnmbox + (lambda () + (save-excursion + (set-buffer nnmbox-mbox-buffer) + (save-buffer))) + nnmbox-mbox-file group + (lambda () + (save-excursion + (let ((in-buf (current-buffer))) + (set-buffer nnmbox-mbox-buffer) + (goto-char (point-max)) + (insert-buffer-substring in-buf))) + (nnmail-save-active nnmbox-group-alist nnmbox-active-file)))) + +(deffoo nnmbox-close-group (group &optional server) t) -(defun nnmbox-request-list (&optional server) - (if server (nnmbox-get-new-mail)) +(deffoo nnmbox-request-list (&optional server) (save-excursion - (or (nnmail-find-file nnmbox-active-file) - (progn - (setq nnmbox-group-alist (nnmail-get-active)) - (nnmail-save-active nnmbox-group-alist nnmbox-active-file) - (nnmail-find-file nnmbox-active-file))))) + (nnmail-find-file nnmbox-active-file) + (setq nnmbox-group-alist (nnmail-get-active)))) -(defun nnmbox-request-newgroups (date &optional server) +(deffoo nnmbox-request-newgroups (date &optional server) (nnmbox-request-list server)) -(defun nnmbox-request-list-newsgroups (&optional server) - (setq nnmbox-status-string "nnmbox: LIST NEWSGROUPS is not implemented.") - nil) +(deffoo nnmbox-request-list-newsgroups (&optional server) + (nnheader-report 'nnmbox "LIST NEWSGROUPS is not implemented.")) -(defun nnmbox-request-post (&optional server) - (mail-send-and-exit nil)) - -(defalias 'nnmbox-request-post-buffer 'nnmail-request-post-buffer) - -(defun nnmbox-request-expire-articles +(deffoo nnmbox-request-expire-articles (articles newsgroup &optional server force) - (nnmbox-possibly-change-newsgroup newsgroup) - (let* ((days (or (and nnmail-expiry-wait-function - (funcall nnmail-expiry-wait-function newsgroup)) - nnmail-expiry-wait)) - (is-old t) + (nnmbox-possibly-change-newsgroup newsgroup server) + (let* ((is-old t) rest) (nnmail-activate 'nnmbox) @@ -244,16 +228,14 @@ (while (and articles is-old) (goto-char (point-min)) (if (search-forward (nnmbox-article-string (car articles)) nil t) - (if (or force - (setq is-old - (> (nnmail-days-between - (current-time-string) - (buffer-substring - (point) (progn (end-of-line) (point)))) - days))) + (if (setq is-old + (nnmail-expired-article-p + newsgroup + (buffer-substring + (point) (progn (end-of-line) (point))) force)) (progn - (and gnus-verbose-backends - (message "Deleting article %s..." (car articles))) + (nnheader-message 5 "Deleting article %d in %s..." + (car articles) newsgroup) (nnmbox-delete-mail)) (setq rest (cons (car articles) rest)))) (setq articles (cdr articles))) @@ -269,9 +251,9 @@ (nnmail-save-active nnmbox-group-alist nnmbox-active-file) (nconc rest articles)))) -(defun nnmbox-request-move-article +(deffoo nnmbox-request-move-article (article group server accept-form &optional last) - (nnmbox-possibly-change-newsgroup group) + (nnmbox-possibly-change-newsgroup group server) (let ((buf (get-buffer-create " *nnmbox move*")) result) (and @@ -298,7 +280,9 @@ (and last (save-buffer)))) result)) -(defun nnmbox-request-accept-article (group &optional last) +(deffoo nnmbox-request-accept-article (group &optional server last) + (nnmbox-possibly-change-newsgroup group server) + (nnmail-check-syntax) (let ((buf (current-buffer)) result) (goto-char (point-min)) @@ -317,13 +301,14 @@ (setq result (nnmbox-save-mail (and (stringp group) group)))) (save-excursion (set-buffer nnmbox-mbox-buffer) + (goto-char (point-max)) (insert-buffer-substring buf) (and last (save-buffer)) result) (nnmail-save-active nnmbox-group-alist nnmbox-active-file)) (car result))) -(defun nnmbox-request-replace-article (article group buffer) +(deffoo nnmbox-request-replace-article (article group buffer) (nnmbox-possibly-change-newsgroup group) (save-excursion (set-buffer nnmbox-mbox-buffer) @@ -335,6 +320,48 @@ (save-buffer) t))) +(deffoo nnmbox-request-delete-group (group &optional force server) + (nnmbox-possibly-change-newsgroup group server) + ;; Delete all articles in GROUP. + (if (not force) + () ; Don't delete the articles. + (save-excursion + (set-buffer nnmbox-mbox-buffer) + (goto-char (point-min)) + ;; Delete all articles in this group. + (let ((ident (concat "\nX-Gnus-Newsgroup: " nnmbox-current-group ":")) + found) + (while (search-forward ident nil t) + (setq found t) + (nnmbox-delete-mail)) + (and found (save-buffer))))) + ;; Remove the group from all structures. + (setq nnmbox-group-alist + (delq (assoc group nnmbox-group-alist) nnmbox-group-alist) + nnmbox-current-group nil) + ;; Save the active file. + (nnmail-save-active nnmbox-group-alist nnmbox-active-file) + t) + +(deffoo nnmbox-request-rename-group (group new-name &optional server) + (nnmbox-possibly-change-newsgroup group server) + (save-excursion + (set-buffer nnmbox-mbox-buffer) + (goto-char (point-min)) + (let ((ident (concat "\nX-Gnus-Newsgroup: " nnmbox-current-group ":")) + (new-ident (concat "\nX-Gnus-Newsgroup: " new-name ":")) + found) + (while (search-forward ident nil t) + (replace-match new-ident t t) + (setq found t)) + (and found (save-buffer)))) + (let ((entry (assoc group nnmbox-group-alist))) + (and entry (setcar entry new-name)) + (setq nnmbox-current-group nil) + ;; Save the new group alist. + (nnmail-save-active nnmbox-group-alist nnmbox-active-file) + t)) + ;;; Internal functions. @@ -352,12 +379,12 @@ (save-restriction (narrow-to-region (save-excursion - (re-search-backward (concat "^" rmail-unix-mail-delimiter) nil t) + (re-search-backward (concat "^" message-unix-mail-delimiter) nil t) (if leave-delim (progn (forward-line 1) (point)) (match-beginning 0))) (progn (forward-line 1) - (or (and (re-search-forward (concat "^" rmail-unix-mail-delimiter) + (or (and (re-search-forward (concat "^" message-unix-mail-delimiter) nil t) (if (and (not (bobp)) leave-delim) (progn (forward-line -2) (point)) @@ -368,7 +395,10 @@ (if (or force (not (re-search-forward "^X-Gnus-Newsgroup: " nil t))) (delete-region (point-min) (point-max)))))) -(defun nnmbox-possibly-change-newsgroup (newsgroup) +(defun nnmbox-possibly-change-newsgroup (newsgroup &optional server) + (when (and server + (not (nnmbox-server-opened server))) + (nnmbox-open-server server)) (if (or (not nnmbox-mbox-buffer) (not (buffer-name nnmbox-mbox-buffer))) (save-excursion @@ -380,21 +410,45 @@ (nnmail-activate 'nnmbox)) (if newsgroup (if (assoc newsgroup nnmbox-group-alist) - (setq nnmbox-current-group newsgroup)))) + (setq nnmbox-current-group newsgroup)) + t)) (defun nnmbox-article-string (article) - (concat "\nX-Gnus-Newsgroup: " nnmbox-current-group ":" - (int-to-string article) " ")) + (if (numberp article) + (concat "\nX-Gnus-Newsgroup: " nnmbox-current-group ":" + (int-to-string article) " ") + (concat "\nMessage-ID: " article))) + +(defun nnmbox-article-group-number () + (save-excursion + (goto-char (point-min)) + (and (re-search-forward "^X-Gnus-Newsgroup: +\\([^:]+\\):\\([0-9]+\\) " + nil t) + (cons (buffer-substring (match-beginning 1) (match-end 1)) + (string-to-int + (buffer-substring (match-beginning 2) (match-end 2))))))) (defun nnmbox-save-mail (&optional group) "Called narrowed to an article." (let* ((nnmail-split-methods (if group (list (list group "")) nnmail-split-methods)) - (group-art (nreverse (nnmail-article-group 'nnmbox-active-number)))) + (group-art (nreverse (nnmail-article-group 'nnmbox-active-number))) + (delim (concat "^" message-unix-mail-delimiter))) + (goto-char (point-min)) + ;; This might come from somewhere else. + (unless (looking-at delim) + (insert "From nobody " (current-time-string) "\n") + (goto-char (point-min))) + ;; Quote all "From " lines in the article. + (forward-line 1) + (while (re-search-forward delim nil t) + (beginning-of-line) + (insert "> ")) (nnmail-insert-lines) (nnmail-insert-xref group-art) (nnmbox-insert-newsgroup-line group-art) - (run-hooks 'nnml-prepare-save-mail-hook) + (run-hooks 'nnmail-prepare-save-mail-hook) + (run-hooks 'nnmbox-prepare-save-mail-hook) group-art)) (defun nnmbox-insert-newsgroup-line (group-art) @@ -405,14 +459,14 @@ (forward-char -1) (while group-art (insert (format "X-Gnus-Newsgroup: %s:%d %s\n" - (car (car group-art)) (cdr (car group-art)) + (caar group-art) (cdar group-art) (current-time-string))) (setq group-art (cdr group-art))))) t)) (defun nnmbox-active-number (group) ;; Find the next article number in GROUP. - (let ((active (car (cdr (assoc group nnmbox-group-alist))))) + (let ((active (cadr (assoc group nnmbox-group-alist)))) (if active (setcdr active (1+ (cdr active))) ;; This group is new, so we create a new entry for it. @@ -433,12 +487,29 @@ (= (buffer-size) (nth 7 (file-attributes nnmbox-mbox-file))))) () (save-excursion - (let ((delim (concat "^" rmail-unix-mail-delimiter)) - start end) + (let ((delim (concat "^" message-unix-mail-delimiter)) + (alist nnmbox-group-alist) + start end number) (set-buffer (setq nnmbox-mbox-buffer - (nnheader-find-file-noselect + (nnheader-find-file-noselect nnmbox-mbox-file nil 'raw))) (buffer-disable-undo (current-buffer)) + + ;; Go through the group alist and compare against + ;; the mbox file. + (while alist + (goto-char (point-max)) + (when (and (re-search-backward + (format "^X-Gnus-Newsgroup: %s:\\([0-9]+\\) " + (caar alist)) nil t) + (>= (setq number + (string-to-number + (buffer-substring + (match-beginning 1) (match-end 1)))) + (cdadar alist))) + (setcdr (cadar alist) (1+ number))) + (setq alist (cdr alist))) + (goto-char (point-min)) (while (re-search-forward delim nil t) (setq start (match-beginning 0)) @@ -457,54 +528,6 @@ (nnmbox-save-mail)))) (goto-char end)))))) -(defun nnmbox-get-new-mail (&optional group) - "Read new incoming mail." - (let* ((spools (nnmail-get-spool-files group)) - (group-in group) - incoming incomings) - (nnmbox-read-mbox) - (if (or (not nnmbox-get-new-mail) (not nnmail-spool-file)) - () - ;; We go through all the existing spool files and split the - ;; mail from each. - (while spools - (and - (file-exists-p (car spools)) - (> (nth 7 (file-attributes (car spools))) 0) - (progn - (and gnus-verbose-backends - (message "nnmbox: Reading incoming mail...")) - (if (not (setq incoming - (nnmail-move-inbox - (car spools) - (concat nnmbox-mbox-file "-Incoming")))) - () - (setq incomings (cons incoming incomings)) - (save-excursion - (setq group (nnmail-get-split-group (car spools) group-in)) - (let ((in-buf (nnmail-split-incoming - incoming 'nnmbox-save-mail t group))) - (set-buffer nnmbox-mbox-buffer) - (goto-char (point-max)) - (insert-buffer-substring in-buf) - (kill-buffer in-buf)))))) - (setq spools (cdr spools))) - ;; If we did indeed read any incoming spools, we save all info. - (and (buffer-modified-p nnmbox-mbox-buffer) - (save-excursion - (nnmail-save-active nnmbox-group-alist nnmbox-active-file) - (set-buffer nnmbox-mbox-buffer) - (save-buffer))) - (if incomings (run-hooks 'nnmail-read-incoming-hook)) - (while incomings - (setq incoming (car incomings)) - (and nnmail-delete-incoming - (file-exists-p incoming) - (file-writable-p incoming) - (delete-file incoming)) - (setq incomings (cdr incomings)))))) - - (provide 'nnmbox) ;;; nnmbox.el ends here diff --git a/lisp/nnmh.el b/lisp/nnmh.el index 0d6d4d070ab..bebc050effe 100644 --- a/lisp/nnmh.el +++ b/lisp/nnmh.el @@ -1,6 +1,5 @@ ;;; nnmh.el --- mhspool access for Gnus - -;; Copyright (C) 1995 Free Software Foundation, Inc. +;; Copyright (C) 1995,96 Free Software Foundation, Inc. ;; Author: Lars Magne Ingebrigtsen ;; Masanobu UMEDA @@ -32,20 +31,23 @@ ;;; Code: (require 'nnheader) -(require 'rmail) (require 'nnmail) (require 'gnus) +(require 'nnoo) +(eval-and-compile (require 'cl)) + +(nnoo-declare nnmh) -(defvar nnmh-directory "~/Mail/" +(defvoo nnmh-directory message-directory "*Mail spool directory.") -(defvar nnmh-get-new-mail t +(defvoo nnmh-get-new-mail t "*If non-nil, nnmh will check the incoming mail file and split the mail.") -(defvar nnmh-prepare-save-mail-hook nil +(defvoo nnmh-prepare-save-mail-hook nil "*Hook run narrowed to an article before saving.") -(defvar nnmh-be-safe nil +(defvoo nnmh-be-safe nil "*If non-nil, nnmh will check all articles to make sure whether they are new or not.") @@ -53,59 +55,49 @@ (defconst nnmh-version "nnmh 1.0" "nnmh version.") -(defvar nnmh-current-directory nil +(defvoo nnmh-current-directory nil "Current news group directory.") -(defvar nnmh-status-string "") -(defvar nnmh-group-alist nil) - - - -(defvar nnmh-current-server nil) -(defvar nnmh-server-alist nil) -(defvar nnmh-server-variables - (list - (list 'nnmh-directory nnmh-directory) - (list 'nnmh-get-new-mail nnmh-get-new-mail) - '(nnmh-current-directory nil) - '(nnmh-status-string "") - '(nnmh-group-alist))) +(defvoo nnmh-status-string "") +(defvoo nnmh-group-alist nil) ;;; Interface functions. -(defun nnmh-retrieve-headers (sequence &optional newsgroup server) +(nnoo-define-basics nnmh) + +(deffoo nnmh-retrieve-headers (articles &optional newsgroup server fetch-old) (save-excursion (set-buffer nntp-server-buffer) (erase-buffer) (let* ((file nil) - (number (length sequence)) + (number (length articles)) (large (and (numberp nnmail-large-newsgroup) (> number nnmail-large-newsgroup))) (count 0) beg article) - (nnmh-possibly-change-directory newsgroup) - (if (stringp (car sequence)) + (nnmh-possibly-change-directory newsgroup server) + ;; We don't support fetching by Message-ID. + (if (stringp (car articles)) 'headers - (while sequence - (setq article (car sequence)) - (setq file - (concat nnmh-current-directory (int-to-string article))) - (if (and (file-exists-p file) - (not (file-directory-p file))) - (progn - (insert (format "221 %d Article retrieved.\n" article)) - (setq beg (point)) - (nnheader-insert-head file) - (goto-char beg) - (if (search-forward "\n\n" nil t) - (forward-char -1) - (goto-char (point-max)) - (insert "\n\n")) - (insert ".\n") - (delete-region (point) (point-max)))) - (setq sequence (cdr sequence)) + (while articles + (when (and (file-exists-p + (setq file (concat (file-name-as-directory + nnmh-current-directory) + (int-to-string + (setq article (pop articles)))))) + (not (file-directory-p file))) + (insert (format "221 %d Article retrieved.\n" article)) + (setq beg (point)) + (nnheader-insert-head file) + (goto-char beg) + (if (search-forward "\n\n" nil t) + (forward-char -1) + (goto-char (point-max)) + (insert "\n\n")) + (insert ".\n") + (delete-region (point) (point-max))) (setq count (1+ count)) (and large @@ -115,42 +107,29 @@ (and large (message "nnmh: Receiving headers...done")) - ;; Fold continuation lines. - (goto-char (point-min)) - (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t) - (replace-match " " t t)) + (nnheader-fold-continuation-lines) 'headers)))) -(defun nnmh-open-server (server &optional defs) - (nnheader-init-server-buffer) - (if (equal server nnmh-current-server) - t - (if nnmh-current-server - (setq nnmh-server-alist - (cons (list nnmh-current-server - (nnheader-save-variables nnmh-server-variables)) - nnmh-server-alist))) - (let ((state (assoc server nnmh-server-alist))) - (if state - (progn - (nnheader-restore-variables (nth 1 state)) - (setq nnmh-server-alist (delq state nnmh-server-alist))) - (nnheader-set-init-variables nnmh-server-variables defs))) - (setq nnmh-current-server server))) - -(defun nnmh-close-server (&optional server) - t) - -(defun nnmh-server-opened (&optional server) - (and (equal server nnmh-current-server) - nntp-server-buffer - (buffer-name nntp-server-buffer))) - -(defun nnmh-status-message (&optional server) - nnmh-status-string) - -(defun nnmh-request-article (id &optional newsgroup server buffer) - (nnmh-possibly-change-directory newsgroup) +(deffoo nnmh-open-server (server &optional defs) + (nnoo-change-server 'nnmh server defs) + (when (not (file-exists-p nnmh-directory)) + (condition-case () + (make-directory nnmh-directory t) + (error t))) + (cond + ((not (file-exists-p nnmh-directory)) + (nnmh-close-server) + (nnheader-report 'nnmh "Couldn't create directory: %s" nnmh-directory)) + ((not (file-directory-p (file-truename nnmh-directory))) + (nnmh-close-server) + (nnheader-report 'nnmh "Not a directory: %s" nnmh-directory)) + (t + (nnheader-report 'nnmh "Opened server %s using directory %s" + server nnmh-directory) + t))) + +(deffoo nnmh-request-article (id &optional newsgroup server buffer) + (nnmh-possibly-change-directory newsgroup server) (let ((file (if (stringp id) nil (concat nnmh-current-directory (int-to-string id)))) @@ -158,105 +137,101 @@ (and (stringp file) (file-exists-p file) (not (file-directory-p file)) - (save-excursion (nnmail-find-file file))))) + (save-excursion (nnmail-find-file file)) + (string-to-int (file-name-nondirectory file))))) -(defun nnmh-request-group (group &optional server dont-check) - (and nnmh-get-new-mail (or dont-check (nnmh-get-new-mail group))) - (let ((pathname (nnmh-article-pathname group nnmh-directory)) +(deffoo nnmh-request-group (group &optional server dont-check) + (let ((pathname (nnmail-group-pathname group nnmh-directory)) dir) - (if (file-directory-p pathname) - (progn - (setq nnmh-current-directory pathname) - (and nnmh-get-new-mail - nnmh-be-safe - (nnmh-update-gnus-unreads group)) - (or dont-check - (progn - (setq dir - (sort - (mapcar - (function - (lambda (name) - (string-to-int name))) - (directory-files pathname nil "^[0-9]+$" t)) - '<)) - (save-excursion - (set-buffer nntp-server-buffer) - (erase-buffer) - (if dir - (insert (format "211 %d %d %d %s\n" (length dir) - (car dir) - (progn (while (cdr dir) - (setq dir (cdr dir))) - (car dir)) - group)) - (insert (format "211 0 1 0 %s\n" group)))))) - t) - (setq nnmh-status-string "No such group") - nil))) - -(defun nnmh-request-list (&optional server dir) - (or dir - (save-excursion - (set-buffer nntp-server-buffer) - (erase-buffer) - (setq dir (file-truename (file-name-as-directory nnmh-directory))))) + (cond + ((not (file-directory-p pathname)) + (nnheader-report + 'nnmh "Can't select group (no such directory): %s" group)) + (t + (setq nnmh-current-directory pathname) + (and nnmh-get-new-mail + nnmh-be-safe + (nnmh-update-gnus-unreads group)) + (cond + (dont-check + (nnheader-report 'nnmh "Selected group %s" group) + t) + (t + (setq dir + (sort + (mapcar (lambda (name) (string-to-int name)) + (directory-files pathname nil "^[0-9]+$" t)) + '<)) + (cond + (dir + (nnheader-report 'nnmh "Selected group %s" group) + (nnheader-insert + "211 %d %d %d %s\n" (length dir) (car dir) + (progn (while (cdr dir) (setq dir (cdr dir))) (car dir)) + group)) + (t + (nnheader-report 'nnmh "Empty group %s" group) + (nnheader-insert (format "211 0 1 0 %s\n" group)))))))))) + +(deffoo nnmh-request-scan (&optional group server) + (nnmail-get-new-mail 'nnmh nil nnmh-directory group)) + +(deffoo nnmh-request-list (&optional server dir) + (nnheader-insert "") + (let ((nnmh-toplev + (or dir (file-truename (file-name-as-directory nnmh-directory))))) + (nnmh-request-list-1 nnmh-toplev)) + (setq nnmh-group-alist (nnmail-get-active)) + t) + +(defvar nnmh-toplev) +(defun nnmh-request-list-1 (dir) (setq dir (expand-file-name dir)) ;; Recurse down all directories. (let ((dirs (and (file-readable-p dir) (> (nth 1 (file-attributes (file-chase-links dir))) 2) - (directory-files dir t nil t)))) - (while dirs - (if (and (not (string-match "/\\.\\.?$" (car dirs))) - (file-directory-p (car dirs)) - (file-readable-p (car dirs))) - (nnmh-request-list nil (car dirs))) - (setq dirs (cdr dirs)))) + (directory-files dir t nil t))) + dir) + ;; Recurse down directories. + (while (setq dir (pop dirs)) + (when (and (not (member (file-name-nondirectory dir) '("." ".."))) + (file-directory-p dir) + (file-readable-p dir)) + (nnmh-request-list-1 dir)))) ;; For each directory, generate an active file line. - (if (not (string= (expand-file-name nnmh-directory) dir)) - (let ((files (mapcar - (lambda (name) (string-to-int name)) - (directory-files dir nil "^[0-9]+$" t)))) - (if (null files) - () - (save-excursion - (set-buffer nntp-server-buffer) - (goto-char (point-max)) - (insert - (format - "%s %d %d y\n" - (progn - (string-match - (file-truename (file-name-as-directory - (expand-file-name nnmh-directory))) dir) - (nnmail-replace-chars-in-string - (substring dir (match-end 0)) ?/ ?.)) - (apply (function max) files) - (apply (function min) files))))))) - (setq nnmh-group-alist (nnmail-get-active)) - (and server nnmh-get-new-mail (nnmh-get-new-mail)) + (unless (string= (expand-file-name nnmh-toplev) dir) + (let ((files (mapcar + (lambda (name) (string-to-int name)) + (directory-files dir nil "^[0-9]+$" t)))) + (when files + (save-excursion + (set-buffer nntp-server-buffer) + (goto-char (point-max)) + (insert + (format + "%s %d %d y\n" + (progn + (string-match + (regexp-quote + (file-truename (file-name-as-directory + (expand-file-name nnmh-toplev)))) dir) + (nnheader-replace-chars-in-string + (substring dir (match-end 0)) ?/ ?.)) + (apply 'max files) + (apply 'min files))))))) t) -(defun nnmh-request-newgroups (date &optional server) +(deffoo nnmh-request-newgroups (date &optional server) (nnmh-request-list server)) -(defun nnmh-request-post (&optional server) - (mail-send-and-exit nil)) - -(defalias 'nnmh-request-post-buffer 'nnmail-request-post-buffer) - -(defun nnmh-request-expire-articles (articles newsgroup &optional server force) - (nnmh-possibly-change-directory newsgroup) - (let* ((days (or (and nnmail-expiry-wait-function - (funcall nnmail-expiry-wait-function newsgroup)) - nnmail-expiry-wait)) - (active-articles +(deffoo nnmh-request-expire-articles (articles newsgroup &optional server force) + (nnmh-possibly-change-directory newsgroup server) + (let* ((active-articles (mapcar (function (lambda (name) (string-to-int name))) (directory-files nnmh-current-directory nil "^[0-9]+$" t))) - (max-article (and active-articles (apply 'max active-articles))) (is-old t) article rest mod-time) (nnmail-activate 'nnmh) @@ -265,36 +240,32 @@ (setq article (concat nnmh-current-directory (int-to-string (car articles)))) (if (setq mod-time (nth 5 (file-attributes article))) - (if (and (or (not nnmail-keep-last-article) - (not max-article) - (not (= (car articles) max-article))) - (not (equal mod-time '(0 0))) - (or force - (setq is-old - (> (nnmail-days-between - (current-time-string) - (current-time-string mod-time)) - days)))) + (if (and (nnmh-deletable-article-p newsgroup (car articles)) + (setq is-old + (nnmail-expired-article-p newsgroup mod-time force))) (progn - (and gnus-verbose-backends - (message "Deleting article %s..." article)) + (nnheader-message 5 "Deleting article %s in %s..." + article newsgroup) (condition-case () - (delete-file article) + (funcall nnmail-delete-file-function article) (file-error + (nnheader-message 1 "Couldn't delete article %s in %s" + article newsgroup) (setq rest (cons (car articles) rest))))) (setq rest (cons (car articles) rest)))) (setq articles (cdr articles))) (message "") (nconc rest articles))) -(defun nnmh-close-group (group &optional server) +(deffoo nnmh-close-group (group &optional server) t) -(defun nnmh-request-move-article +(deffoo nnmh-request-move-article (article group server accept-form &optional last) (let ((buf (get-buffer-create " *nnmh move*")) result) (and + (nnmh-deletable-article-p group article) (nnmh-request-article article group server) (save-excursion (set-buffer buf) @@ -302,65 +273,134 @@ (setq result (eval accept-form)) (kill-buffer (current-buffer)) result) - (condition-case () - (delete-file (concat nnmh-current-directory - (int-to-string article))) - (file-error nil))) + (progn + (nnmh-possibly-change-directory group server) + (condition-case () + (funcall nnmail-delete-file-function + (concat nnmh-current-directory (int-to-string article))) + (file-error nil)))) result)) -(defun nnmh-request-accept-article (group &optional last) +(deffoo nnmh-request-accept-article (group &optional server last noinsert) + (nnmh-possibly-change-directory group server) + (nnmail-check-syntax) (if (stringp group) (and (nnmail-activate 'nnmh) ;; We trick the choosing function into believing that only one ;; group is available. (let ((nnmail-split-methods (list (list group "")))) - (car (nnmh-save-mail)))) + (car (nnmh-save-mail noinsert)))) (and (nnmail-activate 'nnmh) - (car (nnmh-save-mail))))) + (car (nnmh-save-mail noinsert))))) -(defun nnmh-request-replace-article (article group buffer) +(deffoo nnmh-request-replace-article (article group buffer) (nnmh-possibly-change-directory group) (save-excursion (set-buffer buffer) (nnmh-possibly-create-directory group) (condition-case () (progn - (write-region (point-min) (point-max) - (concat nnmh-current-directory (int-to-string article)) - nil (if gnus-verbose-backends nil 'nomesg)) + (write-region + (point-min) (point-max) + (concat nnmh-current-directory (int-to-string article)) + nil (if (nnheader-be-verbose 5) nil 'nomesg)) t) (error nil)))) +(deffoo nnmh-request-create-group (group &optional server) + (nnmail-activate 'nnmh) + (or (assoc group nnmh-group-alist) + (let (active) + (setq nnmh-group-alist (cons (list group (setq active (cons 1 0))) + nnmh-group-alist)) + (nnmh-possibly-create-directory group) + (nnmh-possibly-change-directory group server) + (let ((articles (mapcar + (lambda (file) + (string-to-int file)) + (directory-files + nnmh-current-directory nil "^[0-9]+$")))) + (and articles + (progn + (setcar active (apply 'min articles)) + (setcdr active (apply 'max articles))))))) + t) + +(deffoo nnmh-request-delete-group (group &optional force server) + (nnmh-possibly-change-directory group server) + ;; Delete all articles in GROUP. + (if (not force) + () ; Don't delete the articles. + (let ((articles (directory-files nnmh-current-directory t "^[0-9]+$"))) + (while articles + (and (file-writable-p (car articles)) + (progn + (nnheader-message 5 "Deleting article %s in %s..." + (car articles) group) + (funcall nnmail-delete-file-function (car articles)))) + (setq articles (cdr articles)))) + ;; Try to delete the directory itself. + (condition-case () + (delete-directory nnmh-current-directory) + (error nil))) + ;; Remove the group from all structures. + (setq nnmh-group-alist + (delq (assoc group nnmh-group-alist) nnmh-group-alist) + nnmh-current-directory nil) + t) + +(deffoo nnmh-request-rename-group (group new-name &optional server) + (nnmh-possibly-change-directory group server) + ;; Rename directory. + (and (file-writable-p nnmh-current-directory) + (condition-case () + (progn + (rename-file + (directory-file-name nnmh-current-directory) + (directory-file-name + (nnmail-group-pathname new-name nnmh-directory))) + t) + (error nil)) + ;; That went ok, so we change the internal structures. + (let ((entry (assoc group nnmh-group-alist))) + (and entry (setcar entry new-name)) + (setq nnmh-current-directory nil) + t))) + ;;; Internal functions. -(defun nnmh-possibly-change-directory (newsgroup) +(defun nnmh-possibly-change-directory (newsgroup &optional server) + (when (and server + (not (nnmh-server-opened server))) + (nnmh-open-server server)) (if newsgroup - (let ((pathname (nnmh-article-pathname newsgroup nnmh-directory))) + (let ((pathname (nnmail-group-pathname newsgroup nnmh-directory))) (if (file-directory-p pathname) (setq nnmh-current-directory pathname) (error "No such newsgroup: %s" newsgroup))))) (defun nnmh-possibly-create-directory (group) (let (dir dirs) - (setq dir (nnmh-article-pathname group nnmh-directory)) + (setq dir (nnmail-group-pathname group nnmh-directory)) (while (not (file-directory-p dir)) (setq dirs (cons dir dirs)) (setq dir (file-name-directory (directory-file-name dir)))) (while dirs (if (make-directory (directory-file-name (car dirs))) (error "Could not create directory %s" (car dirs))) - (and gnus-verbose-backends - (message "Creating mail directory %s" (car dirs))) + (nnheader-message 5 "Creating mail directory %s" (car dirs)) (setq dirs (cdr dirs))))) -(defun nnmh-save-mail () +(defun nnmh-save-mail (&optional noinsert) "Called narrowed to an article." (let ((group-art (nreverse (nnmail-article-group 'nnmh-active-number)))) - (nnmail-insert-lines) - (nnmail-insert-xref group-art) + (unless noinsert + (nnmail-insert-lines) + (nnmail-insert-xref group-art)) + (run-hooks 'nnmail-prepare-save-mail-hook) (run-hooks 'nnmh-prepare-save-mail-hook) (goto-char (point-min)) (while (looking-at "From ") @@ -370,13 +410,13 @@ (let ((ga group-art) first) (while ga - (nnmh-possibly-create-directory (car (car ga))) - (let ((file (concat (nnmh-article-pathname - (car (car ga)) nnmh-directory) - (int-to-string (cdr (car ga)))))) + (nnmh-possibly-create-directory (caar ga)) + (let ((file (concat (nnmail-group-pathname + (caar ga) nnmh-directory) + (int-to-string (cdar ga))))) (if first ;; It was already saved, so we just make a hard link. - (add-name-to-file first file t) + (funcall nnmail-crosspost-link-function first file t) ;; Save the article. (write-region (point-min) (point-max) file nil nil) (setq first file))) @@ -385,7 +425,7 @@ (defun nnmh-active-number (group) "Compute the next article number in GROUP." - (let ((active (car (cdr (assoc group nnmh-group-alist))))) + (let ((active (cadr (assoc group nnmh-group-alist)))) ;; The group wasn't known to nnmh, so we just create an active ;; entry for it. (or active @@ -394,59 +434,11 @@ (setq nnmh-group-alist (cons (list group active) nnmh-group-alist)))) (setcdr active (1+ (cdr active))) (while (file-exists-p - (concat (nnmh-article-pathname group nnmh-directory) + (concat (nnmail-group-pathname group nnmh-directory) (int-to-string (cdr active)))) (setcdr active (1+ (cdr active)))) (cdr active))) -(defun nnmh-article-pathname (group mail-dir) - "Make pathname for GROUP." - (let ((mail-dir (file-name-as-directory (expand-file-name mail-dir)))) - (if (file-directory-p (concat mail-dir group)) - (concat mail-dir group "/") - (concat mail-dir (nnmail-replace-chars-in-string group ?. ?/) "/")))) - -(defun nnmh-get-new-mail (&optional group) - "Read new incoming mail." - (let* ((spools (nnmail-get-spool-files group)) - (group-in group) - incoming incomings) - (if (or (not nnmh-get-new-mail) (not nnmail-spool-file)) - () - ;; We first activate all the groups. - (or nnmh-group-alist - (nnmh-request-list)) - ;; The we go through all the existing spool files and split the - ;; mail from each. - (while spools - (and - (file-exists-p (car spools)) - (> (nth 7 (file-attributes (car spools))) 0) - (progn - (and gnus-verbose-backends - (message "nnmh: Reading incoming mail...")) - (if (not (setq incoming - (nnmail-move-inbox - (car spools) - (concat (file-name-as-directory nnmh-directory) - "Incoming")))) - () - (setq incomings (cons incoming incomings)) - (setq group (nnmail-get-split-group (car spools) group-in)) - (nnmail-split-incoming incoming 'nnmh-save-mail nil group)))) - (setq spools (cdr spools))) - ;; If we did indeed read any incoming spools, we save all info. - (if incoming - (message "nnmh: Reading incoming mail...done")) - (while incomings - (setq incoming (car incomings)) - (and nnmail-delete-incoming - (file-exists-p incoming) - (file-writable-p incoming) - (delete-file incoming)) - (setq incomings (cdr incomings)))))) - - (defun nnmh-update-gnus-unreads (group) ;; Go through the .nnmh-articles file and compare with the actual ;; articles in this folder. The articles that are "new" will be @@ -471,7 +463,7 @@ ;; Remove all deleted articles. (let ((art articles)) (while art - (if (not (memq (car (car art)) files)) + (if (not (memq (caar art) files)) (setq articles (delq (car art) articles))) (setq art (cdr art)))) ;; Check whether the highest-numbered articles really are the ones @@ -480,10 +472,10 @@ (while (and art (not (equal (nth 5 (file-attributes - (concat dir (int-to-string (car (car art)))))) - (cdr (car art))))) + (concat dir (int-to-string (caar art))))) + (cdar art)))) (setq articles (delq (car art) articles)) - (setq new (cons (car (car art)) new)) + (setq new (cons (caar art) new)) (setq art (cdr art)))) ;; Go through all the new articles and add them, and their ;; time-stamps to the list. @@ -513,6 +505,14 @@ (write-region (point-min) (point-max) nnmh-file nil 'nomesg) (kill-buffer (current-buffer))))) +(defun nnmh-deletable-article-p (group article) + "Say whether ARTICLE in GROUP can be deleted." + (let ((path (concat nnmh-current-directory (int-to-string article)))) + (and (file-writable-p path) + (or (not nnmail-keep-last-article) + (not (eq (cdr (nth 1 (assoc group nnmh-group-alist))) + article)))))) + (provide 'nnmh) ;;; nnmh.el ends here diff --git a/lisp/nnml.el b/lisp/nnml.el index 2daf354e056..89c97ee9b95 100644 --- a/lisp/nnml.el +++ b/lisp/nnml.el @@ -1,6 +1,5 @@ ;;; nnml.el --- mail spool access for Gnus - -;; Copyright (C) 1995 Free Software Foundation, Inc. +;; Copyright (C) 1995,96 Free Software Foundation, Inc. ;; Author: Lars Magne Ingebrigtsen ;; Masanobu UMEDA @@ -33,20 +32,26 @@ (require 'nnheader) (require 'nnmail) +(require 'nnoo) +(require 'cl) + +(nnoo-declare nnml) -(defvar nnml-directory "~/Mail/" +(defvoo nnml-directory message-directory "Mail spool directory.") -(defvar nnml-active-file (concat nnml-directory "active") +(defvoo nnml-active-file + (concat (file-name-as-directory nnml-directory) "active") "Mail active file.") -(defvar nnml-newsgroups-file (concat nnml-directory "newsgroups") +(defvoo nnml-newsgroups-file + (concat (file-name-as-directory nnml-directory) "newsgroups") "Mail newsgroups description file.") -(defvar nnml-get-new-mail t +(defvoo nnml-get-new-mail t "If non-nil, nnml will check the incoming mail file and split the mail.") -(defvar nnml-nov-is-evil nil +(defvoo nnml-nov-is-evil nil "If non-nil, Gnus will never generate and use nov databases for mail groups. Using nov databases will speed up header fetching considerably. This variable shouldn't be flipped much. If you have, for some reason, @@ -55,47 +60,37 @@ the `nnml-generate-nov-databases' command. The function will go through all nnml directories and generate nov databases for them all. This may very well take some time.") -(defvar nnml-prepare-save-mail-hook nil +(defvoo nnml-prepare-save-mail-hook nil "Hook run narrowed to an article before saving.") +(defvoo nnml-inhibit-expiry nil + "If non-nil, inhibit expiry.") + + (defconst nnml-version "nnml 1.0" "nnml version.") -(defvar nnml-nov-file-name ".overview") - -(defvar nnml-current-directory nil) -(defvar nnml-status-string "") -(defvar nnml-nov-buffer-alist nil) -(defvar nnml-group-alist nil) -(defvar nnml-active-timestamp nil) +(defvoo nnml-nov-file-name ".overview") - +(defvoo nnml-current-directory nil) +(defvoo nnml-current-group nil) +(defvoo nnml-status-string "") +(defvoo nnml-nov-buffer-alist nil) +(defvoo nnml-group-alist nil) +(defvoo nnml-active-timestamp nil) +(defvoo nnml-article-file-alist nil) -;; Server variables. - -(defvar nnml-current-server nil) -(defvar nnml-server-alist nil) -(defvar nnml-server-variables - (list - (list 'nnml-directory nnml-directory) - (list 'nnml-active-file nnml-active-file) - (list 'nnml-newsgroups-file nnml-newsgroups-file) - (list 'nnml-get-new-mail nnml-get-new-mail) - (list 'nnml-nov-is-evil nnml-nov-is-evil) - (list 'nnml-nov-file-name nnml-nov-file-name) - '(nnml-current-directory nil) - '(nnml-status-string "") - '(nnml-nov-buffer-alist nil) - '(nnml-group-alist nil) - '(nnml-active-timestamp nil))) +(defvoo nnml-generate-active-function 'nnml-generate-active-info) ;;; Interface functions. -(defun nnml-retrieve-headers (sequence &optional newsgroup server) +(nnoo-define-basics nnml) + +(deffoo nnml-retrieve-headers (sequence &optional newsgroup server fetch-old) (save-excursion (set-buffer nntp-server-buffer) (erase-buffer) @@ -105,13 +100,18 @@ all. This may very well take some time.") beg article) (if (stringp (car sequence)) 'headers - (nnml-possibly-change-directory newsgroup) - (if (nnml-retrieve-headers-with-nov sequence) + (nnml-possibly-change-directory newsgroup server) + (unless nnml-article-file-alist + (setq nnml-article-file-alist + (nnheader-article-to-file-alist nnml-current-directory))) + (if (nnml-retrieve-headers-with-nov sequence fetch-old) 'nov (while sequence (setq article (car sequence)) - (setq file - (concat nnml-current-directory (int-to-string article))) + (setq file + (concat nnml-current-directory + (or (cdr (assq article nnml-article-file-alist)) + ""))) (if (and (file-exists-p file) (not (file-directory-p file))) (progn @@ -130,102 +130,104 @@ all. This may very well take some time.") (and (numberp nnmail-large-newsgroup) (> number nnmail-large-newsgroup) (zerop (% count 20)) - gnus-verbose-backends - (message "nnml: Receiving headers... %d%%" - (/ (* count 100) number)))) + (nnheader-message 6 "nnml: Receiving headers... %d%%" + (/ (* count 100) number)))) (and (numberp nnmail-large-newsgroup) (> number nnmail-large-newsgroup) - gnus-verbose-backends - (message "nnml: Receiving headers...done")) + (nnheader-message 6 "nnml: Receiving headers...done")) - ;; Fold continuation lines. - (goto-char (point-min)) - (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t) - (replace-match " " t t)) + (nnheader-fold-continuation-lines) 'headers))))) -(defun nnml-open-server (server &optional defs) - (nnheader-init-server-buffer) - (if (equal server nnml-current-server) - t - (if nnml-current-server - (setq nnml-server-alist - (cons (list nnml-current-server - (nnheader-save-variables nnml-server-variables)) - nnml-server-alist))) - (let ((state (assoc server nnml-server-alist))) - (if state - (progn - (nnheader-restore-variables (nth 1 state)) - (setq nnml-server-alist (delq state nnml-server-alist))) - (nnheader-set-init-variables nnml-server-variables defs))) - (setq nnml-current-server server))) - -(defun nnml-close-server (&optional server) - t) - -(defun nnml-server-opened (&optional server) - (and (equal server nnml-current-server) - nntp-server-buffer - (buffer-name nntp-server-buffer))) - -(defun nnml-status-message (&optional server) - nnml-status-string) - -(defun nnml-request-article (id &optional newsgroup server buffer) - (nnml-possibly-change-directory newsgroup) - (let ((file (if (stringp id) - nil - (concat nnml-current-directory (int-to-string id)))) - (nntp-server-buffer (or buffer nntp-server-buffer))) - (if (and (stringp file) - (file-exists-p file) - (not (file-directory-p file))) - (save-excursion - (nnmail-find-file file))))) - -(defun nnml-request-group (group &optional server dont-check) - (if (not (nnml-possibly-change-directory group)) - (progn - (setq nnml-status-string "Invalid group (no such directory)") - nil) - (if dont-check - t - (nnml-get-new-mail group) - (nnmail-activate 'nnml) - (let ((active (nth 1 (assoc group nnml-group-alist)))) - (save-excursion - (set-buffer nntp-server-buffer) - (erase-buffer) - (if (not active) - () - (insert (format "211 %d %d %d %s\n" - (max (1+ (- (cdr active) (car active))) 0) - (car active) (cdr active) group)) - t)))))) - -(defun nnml-close-group (group &optional server) - t) - -(defun nnml-request-close () - (setq nnml-current-server nil) - (setq nnml-server-alist nil) +(deffoo nnml-open-server (server &optional defs) + (nnoo-change-server 'nnml server defs) + (when (not (file-exists-p nnml-directory)) + (condition-case () + (make-directory nnml-directory t) + (error t))) + (cond + ((not (file-exists-p nnml-directory)) + (nnml-close-server) + (nnheader-report 'nnml "Couldn't create directory: %s" nnml-directory)) + ((not (file-directory-p (file-truename nnml-directory))) + (nnml-close-server) + (nnheader-report 'nnml "Not a directory: %s" nnml-directory)) + (t + (nnheader-report 'nnml "Opened server %s using directory %s" + server nnml-directory) + t))) + +(deffoo nnml-request-article (id &optional newsgroup server buffer) + (nnml-possibly-change-directory newsgroup server) + (let* ((nntp-server-buffer (or buffer nntp-server-buffer)) + file path gpath group-num) + (if (stringp id) + (when (and (setq group-num (nnml-find-group-number id)) + (setq file (cdr + (assq (cdr group-num) + (nnheader-article-to-file-alist + (setq gpath + (nnmail-group-pathname + (car group-num) + nnml-directory))))))) + (setq path (concat gpath (int-to-string (cdr group-num))))) + (unless nnml-article-file-alist + (setq nnml-article-file-alist + (nnheader-article-to-file-alist nnml-current-directory))) + (when (setq file (cdr (assq id nnml-article-file-alist))) + (setq path (concat nnml-current-directory file)))) + (cond + ((not path) + (nnheader-report 'nnml "No such article: %s" id)) + ((not (file-exists-p path)) + (nnheader-report 'nnml "No such file: %s" path)) + ((file-directory-p path) + (nnheader-report 'nnml "File is a directory: %s" path)) + ((not (save-excursion (nnmail-find-file path))) + (nnheader-report 'nnml "Couldn't read file: %s" path)) + (t + (nnheader-report 'nnml "Article %s retrieved" id) + ;; We return the article number. + (cons newsgroup (string-to-int (file-name-nondirectory path))))))) + +(deffoo nnml-request-group (group &optional server dont-check) + (cond + ((not (nnml-possibly-change-directory group server)) + (nnheader-report 'nnml "Invalid group (no such directory)")) + ((not (file-directory-p nnml-current-directory)) + (nnheader-report 'nnml "%s is not a directory" nnml-current-directory)) + (dont-check + (nnheader-report 'nnml "Group %s selected" group) + t) + (t + (nnmail-activate 'nnml) + (let ((active (nth 1 (assoc group nnml-group-alist)))) + (if (not active) + (nnheader-report 'nnml "No such group: %s" group) + (nnheader-report 'nnml "Selected group %s" group) + (nnheader-insert "211 %d %d %d %s\n" + (max (1+ (- (cdr active) (car active))) 0) + (car active) (cdr active) group)))))) + +(deffoo nnml-request-scan (&optional group server) + (setq nnml-article-file-alist nil) + (nnmail-get-new-mail 'nnml 'nnml-save-nov nnml-directory group)) + +(deffoo nnml-close-group (group &optional server) + (setq nnml-article-file-alist nil) t) -(defun nnml-request-create-group (group &optional server) +(deffoo nnml-request-create-group (group &optional server) (nnmail-activate 'nnml) (or (assoc group nnml-group-alist) (let (active) (setq nnml-group-alist (cons (list group (setq active (cons 1 0))) nnml-group-alist)) (nnml-possibly-create-directory group) - (nnml-possibly-change-directory group) - (let ((articles (mapcar - (lambda (file) - (string-to-int file)) - (directory-files - nnml-current-directory nil "^[0-9]+$")))) + (nnml-possibly-change-directory group server) + (let ((articles + (nnheader-directory-articles nnml-current-directory ))) (and articles (progn (setcar active (apply 'min articles)) @@ -233,80 +235,69 @@ all. This may very well take some time.") (nnmail-save-active nnml-group-alist nnml-active-file))) t) -(defun nnml-request-list (&optional server) - (if server (nnml-get-new-mail)) +(deffoo nnml-request-list (&optional server) (save-excursion (nnmail-find-file nnml-active-file) (setq nnml-group-alist (nnmail-get-active)))) -(defun nnml-request-newgroups (date &optional server) +(deffoo nnml-request-newgroups (date &optional server) (nnml-request-list server)) -(defun nnml-request-list-newsgroups (&optional server) +(deffoo nnml-request-list-newsgroups (&optional server) (save-excursion (nnmail-find-file nnml-newsgroups-file))) -(defun nnml-request-post (&optional server) - (mail-send-and-exit nil)) - -(defalias 'nnml-request-post-buffer 'nnmail-request-post-buffer) - -(defun nnml-request-expire-articles (articles newsgroup &optional server force) - (nnml-possibly-change-directory newsgroup) - (let* ((days (or (and nnmail-expiry-wait-function - (funcall nnmail-expiry-wait-function newsgroup)) - nnmail-expiry-wait)) - (active-articles - (mapcar - (function - (lambda (name) - (string-to-int name))) - (directory-files nnml-current-directory nil "^[0-9]+$" t))) - (max-article (and active-articles (apply 'max active-articles))) +(deffoo nnml-request-expire-articles (articles newsgroup &optional server force) + (nnml-possibly-change-directory newsgroup server) + (let* ((active-articles + (nnheader-directory-articles nnml-current-directory)) (is-old t) - article rest mod-time) + article rest mod-time number) (nnmail-activate 'nnml) + (unless nnml-article-file-alist + (setq nnml-article-file-alist + (nnheader-article-to-file-alist nnml-current-directory))) + (while (and articles is-old) (setq article (concat nnml-current-directory - (int-to-string (car articles)))) - (if (setq mod-time (nth 5 (file-attributes article))) - (if (and (or (not nnmail-keep-last-article) - (not max-article) - (not (= (car articles) max-article))) - (or force - (and (not (equal mod-time '(0 0))) - (setq is-old - (> (nnmail-days-between - (current-time-string) - (current-time-string mod-time)) - days))))) - (progn - (and gnus-verbose-backends - (message "Deleting article %s..." article)) - (condition-case () - (delete-file article) - (file-error - (setq rest (cons (car articles) rest)))) - (setq active-articles (delq (car articles) active-articles)) - (nnml-nov-delete-article newsgroup (car articles))) - (setq rest (cons (car articles) rest)))) - (setq articles (cdr articles))) + (int-to-string + (setq number (pop articles))))) + (when (setq mod-time (nth 5 (file-attributes article))) + (if (and (nnml-deletable-article-p newsgroup number) + (setq is-old + (nnmail-expired-article-p newsgroup mod-time force + nnml-inhibit-expiry))) + (progn + (nnheader-message 5 "Deleting article %s in %s..." + article newsgroup) + (condition-case () + (funcall nnmail-delete-file-function article) + (file-error + (push number rest))) + (setq active-articles (delq number active-articles)) + (nnml-nov-delete-article newsgroup number)) + (push number rest)))) (let ((active (nth 1 (assoc newsgroup nnml-group-alist)))) - (and active - (setcar active (or (and active-articles - (apply 'min active-articles)) - 0))) + (when active + (setcar active (or (and active-articles + (apply 'min active-articles)) + (1+ (cdr active))))) (nnmail-save-active nnml-group-alist nnml-active-file)) (nnml-save-nov) (message "") (nconc rest articles))) -(defun nnml-request-move-article +(deffoo nnml-request-move-article (article group server accept-form &optional last) (let ((buf (get-buffer-create " *nnml move*")) result) + (nnml-possibly-change-directory group server) + (unless nnml-article-file-alist + (setq nnml-article-file-alist + (nnheader-article-to-file-alist nnml-current-directory))) (and + (nnml-deletable-article-p group article) (nnml-request-article article group server) (save-excursion (set-buffer buf) @@ -315,15 +306,19 @@ all. This may very well take some time.") (kill-buffer (current-buffer)) result) (progn + (nnml-possibly-change-directory group server) (condition-case () - (delete-file (concat nnml-current-directory - (int-to-string article))) + (funcall nnmail-delete-file-function + (concat nnml-current-directory + (int-to-string article))) (file-error nil)) (nnml-nov-delete-article group article) (and last (nnml-save-nov)))) result)) -(defun nnml-request-accept-article (group &optional last) +(deffoo nnml-request-accept-article (group &optional server last) + (nnml-possibly-change-directory group server) + (nnmail-check-syntax) (let (result) (if (stringp group) (and @@ -343,24 +338,23 @@ all. This may very well take some time.") (and last (nnml-save-nov))))) result)) -(defun nnml-request-replace-article (article group buffer) +(deffoo nnml-request-replace-article (article group buffer) (nnml-possibly-change-directory group) (save-excursion (set-buffer buffer) (nnml-possibly-create-directory group) - (if (not (condition-case () - (progn - (write-region (point-min) (point-max) - (concat nnml-current-directory - (int-to-string article)) - nil (if gnus-verbose-backends nil 'nomesg)) - t) - (error nil))) - () - (let ((chars (nnmail-insert-lines)) - (art (concat (int-to-string article) "\t")) - nov-line) - (setq nov-line (nnml-make-nov-line chars)) + (let ((chars (nnmail-insert-lines)) + (art (concat (int-to-string article) "\t")) + headers) + (when (condition-case () + (progn + (write-region + (point-min) (point-max) + (concat nnml-current-directory (int-to-string article)) + nil (if (nnheader-be-verbose 5) nil 'nomesg)) + t) + (error nil)) + (setq headers (nnml-parse-head chars article)) ;; Replace the NOV line in the NOV file. (save-excursion (set-buffer (nnml-open-nov group)) @@ -380,28 +374,140 @@ all. This may very well take some time.") article) (zerop (forward-line 1))))) (beginning-of-line) - (insert (int-to-string article) nov-line) + (nnheader-insert-nov headers) (nnml-save-nov) t))))) +(deffoo nnml-request-delete-group (group &optional force server) + (nnml-possibly-change-directory group server) + (when force + ;; Delete all articles in GROUP. + (let ((articles + (directory-files + nnml-current-directory t + (concat nnheader-numerical-short-files + "\\|" (regexp-quote nnml-nov-file-name) "$"))) + article) + (while articles + (setq article (pop articles)) + (when (file-writable-p article) + (nnheader-message 5 "Deleting article %s in %s..." article group) + (funcall nnmail-delete-file-function article)))) + ;; Try to delete the directory itself. + (condition-case () + (delete-directory nnml-current-directory) + (error nil))) + ;; Remove the group from all structures. + (setq nnml-group-alist + (delq (assoc group nnml-group-alist) nnml-group-alist) + nnml-current-group nil + nnml-current-directory nil) + ;; Save the active file. + (nnmail-save-active nnml-group-alist nnml-active-file) + t) - -;;; Internal functions +(deffoo nnml-request-rename-group (group new-name &optional server) + (nnml-possibly-change-directory group server) + ;; Rename directory. + (and (file-writable-p nnml-current-directory) + (condition-case () + (let ((parent + (file-name-directory + (directory-file-name + (nnmail-group-pathname new-name nnml-directory))))) + (unless (file-exists-p parent) + (make-directory parent t)) + (rename-file + (directory-file-name nnml-current-directory) + (directory-file-name + (nnmail-group-pathname new-name nnml-directory))) + t) + (error nil)) + ;; That went ok, so we change the internal structures. + (let ((entry (assoc group nnml-group-alist))) + (and entry (setcar entry new-name)) + (setq nnml-current-directory nil + nnml-current-group nil) + ;; Save the new group alist. + (nnmail-save-active nnml-group-alist nnml-active-file) + t))) -(defun nnml-retrieve-headers-with-nov (articles) + +;;; Internal functions. + +(defun nnml-deletable-article-p (group article) + "Say whether ARTICLE in GROUP can be deleted." + (let (file path) + (when (setq file (cdr (assq article nnml-article-file-alist))) + (setq path (concat nnml-current-directory file)) + (and (file-writable-p path) + (or (not nnmail-keep-last-article) + (not (eq (cdr (nth 1 (assoc group nnml-group-alist))) + article))))))) + +;; Find an article number in the current group given the Message-ID. +(defun nnml-find-group-number (id) + (save-excursion + (set-buffer (get-buffer-create " *nnml id*")) + (buffer-disable-undo (current-buffer)) + (let ((alist nnml-group-alist) + number) + ;; We want to look through all .overview files, but we want to + ;; start with the one in the current directory. It seems most + ;; likely that the article we are looking for is in that group. + (if (setq number (nnml-find-id nnml-current-group id)) + (cons nnml-current-group number) + ;; It wasn't there, so we look through the other groups as well. + (while (and (not number) + alist) + (or (string= (caar alist) nnml-current-group) + (setq number (nnml-find-id (caar alist) id))) + (or number + (setq alist (cdr alist)))) + (and number + (cons (caar alist) number)))))) + +(defun nnml-find-id (group id) + (erase-buffer) + (let ((nov (concat (nnmail-group-pathname group nnml-directory) + nnml-nov-file-name)) + number found) + (when (file-exists-p nov) + (insert-file-contents nov) + (while (and (not found) + (search-forward id nil t)) ; We find the ID. + ;; And the id is in the fourth field. + (if (search-backward + "\t" (save-excursion (beginning-of-line) (point)) t 4) + (progn + (beginning-of-line) + (setq found t) + ;; We return the article number. + (setq number + (condition-case () + (read (current-buffer)) + (error nil)))))) + number))) + +(defun nnml-retrieve-headers-with-nov (articles &optional fetch-old) (if (or gnus-nov-is-evil nnml-nov-is-evil) nil (let ((first (car articles)) (last (progn (while (cdr articles) (setq articles (cdr articles))) (car articles))) (nov (concat nnml-current-directory nnml-nov-file-name))) - (if (file-exists-p nov) - (save-excursion - (set-buffer nntp-server-buffer) - (erase-buffer) - (insert-file-contents nov) + (when (file-exists-p nov) + (save-excursion + (set-buffer nntp-server-buffer) + (erase-buffer) + (insert-file-contents nov) + (if (and fetch-old + (not (numberp fetch-old))) + t ; Don't remove anything. + (if fetch-old + (setq first (max 1 (- first fetch-old)))) (goto-char (point-min)) - (while (and (not (eobp)) (< first (read (current-buffer)))) + (while (and (not (eobp)) (> first (read (current-buffer)))) (forward-line 1)) (beginning-of-line) (if (not (eobp)) (delete-region 1 (point))) @@ -409,33 +515,38 @@ all. This may very well take some time.") (forward-line 1)) (beginning-of-line) (if (not (eobp)) (delete-region (point) (point-max))) - t))))) + t)))))) -(defun nnml-possibly-change-directory (newsgroup &optional force) - (if newsgroup - (let ((pathname (nnmail-article-pathname newsgroup nnml-directory))) - (and (or force (file-directory-p pathname)) - (setq nnml-current-directory pathname))) - t)) +(defun nnml-possibly-change-directory (group &optional server) + (when (and server + (not (nnml-server-opened server))) + (nnml-open-server server)) + (when group + (let ((pathname (nnmail-group-pathname group nnml-directory))) + (when (not (equal pathname nnml-current-directory)) + (setq nnml-current-directory pathname + nnml-current-group group + nnml-article-file-alist nil)))) + t) (defun nnml-possibly-create-directory (group) (let (dir dirs) - (setq dir (nnmail-article-pathname group nnml-directory)) + (setq dir (nnmail-group-pathname group nnml-directory)) (while (not (file-directory-p dir)) (setq dirs (cons dir dirs)) (setq dir (file-name-directory (directory-file-name dir)))) (while dirs (make-directory (directory-file-name (car dirs))) - (and gnus-verbose-backends - (message "Creating mail directory %s" (car dirs))) + (nnheader-message 5 "Creating mail directory %s" (car dirs)) (setq dirs (cdr dirs))))) (defun nnml-save-mail () "Called narrowed to an article." (let ((group-art (nreverse (nnmail-article-group 'nnml-active-number))) - chars nov-line) + chars headers) (setq chars (nnmail-insert-lines)) (nnmail-insert-xref group-art) + (run-hooks 'nnmail-prepare-save-mail-hook) (run-hooks 'nnml-prepare-save-mail-hook) (goto-char (point-min)) (while (looking-at "From ") @@ -445,161 +556,92 @@ all. This may very well take some time.") (let ((ga group-art) first) (while ga - (nnml-possibly-create-directory (car (car ga))) - (let ((file (concat (nnmail-article-pathname - (car (car ga)) nnml-directory) - (int-to-string (cdr (car ga)))))) + (nnml-possibly-create-directory (caar ga)) + (let ((file (concat (nnmail-group-pathname + (caar ga) nnml-directory) + (int-to-string (cdar ga))))) (if first ;; It was already saved, so we just make a hard link. - (add-name-to-file first file t) + (funcall nnmail-crosspost-link-function first file t) ;; Save the article. (write-region (point-min) (point-max) file nil - (if gnus-verbose-backends nil 'nomesg)) + (if (nnheader-be-verbose 5) nil 'nomesg)) (setq first file))) (setq ga (cdr ga)))) ;; Generate a nov line for this article. We generate the nov ;; line after saving, because nov generation destroys the ;; header. - (setq nov-line (nnml-make-nov-line chars)) + (setq headers (nnml-parse-head chars)) ;; Output the nov line to all nov databases that should have it. (let ((ga group-art)) (while ga - (nnml-add-nov (car (car ga)) (cdr (car ga)) nov-line) + (nnml-add-nov (caar ga) (cdar ga) headers) (setq ga (cdr ga)))) group-art)) (defun nnml-active-number (group) "Compute the next article number in GROUP." - (let ((active (car (cdr (assoc group nnml-group-alist))))) + (let ((active (cadr (assoc group nnml-group-alist)))) ;; The group wasn't known to nnml, so we just create an active ;; entry for it. - (or active - (progn - (setq active (cons 1 0)) - (setq nnml-group-alist (cons (list group active) nnml-group-alist)))) + (unless active + ;; Perhaps the active file was corrupt? See whether + ;; there are any articles in this group. + (nnml-possibly-create-directory group) + (nnml-possibly-change-directory group) + (unless nnml-article-file-alist + (setq nnml-article-file-alist + (sort + (nnheader-article-to-file-alist nnml-current-directory) + (lambda (a1 a2) (< (car a1) (car a2)))))) + (setq active + (if nnml-article-file-alist + (cons (caar nnml-article-file-alist) + (caar (last nnml-article-file-alist))) + (cons 1 0))) + (setq nnml-group-alist (cons (list group active) nnml-group-alist))) (setcdr active (1+ (cdr active))) (while (file-exists-p - (concat (nnmail-article-pathname group nnml-directory) + (concat (nnmail-group-pathname group nnml-directory) (int-to-string (cdr active)))) (setcdr active (1+ (cdr active)))) (cdr active))) -(defun nnml-get-new-mail (&optional group) - "Read new incoming mail." - (let* ((spools (nnmail-get-spool-files group)) - (group-in group) - incoming incomings) - (if (or (not nnml-get-new-mail) (not nnmail-spool-file)) - () - ;; We first activate all the groups. - (nnmail-activate 'nnml) - ;; The we go through all the existing spool files and split the - ;; mail from each. - (while spools - (and - (file-exists-p (car spools)) - (> (nth 7 (file-attributes (car spools))) 0) - (progn - (and gnus-verbose-backends - (message "nnml: Reading incoming mail...")) - (if (not (setq incoming - (nnmail-move-inbox - (car spools) (concat nnml-directory "Incoming")))) - () - (setq group (nnmail-get-split-group (car spools) group-in)) - (nnmail-split-incoming incoming 'nnml-save-mail nil group) - (setq incomings (cons incoming incomings))))) - (setq spools (cdr spools))) - ;; If we did indeed read any incoming spools, we save all info. - (if incoming - (progn - (nnmail-save-active nnml-group-alist nnml-active-file) - (nnml-save-nov) - (run-hooks 'nnmail-read-incoming-hook) - (and gnus-verbose-backends - (message "nnml: Reading incoming mail...done")))) - (while incomings - (setq incoming (car incomings)) - (and nnmail-delete-incoming - (file-exists-p incoming) - (file-writable-p incoming) - (delete-file incoming)) - (setq incomings (cdr incomings)))))) - - -(defun nnml-add-nov (group article line) +(defun nnml-add-nov (group article headers) "Add a nov line for the GROUP base." (save-excursion (set-buffer (nnml-open-nov group)) (goto-char (point-max)) - (insert (int-to-string article) line))) + (mail-header-set-number headers article) + (nnheader-insert-nov headers))) (defsubst nnml-header-value () - (buffer-substring (match-end 0) (save-excursion (end-of-line) (point)))) + (buffer-substring (match-end 0) (progn (end-of-line) (point)))) -(defun nnml-make-nov-line (chars) - "Create a nov from the current headers." - (let ((case-fold-search t) - subject from date id references lines xref in-reply-to char) - (save-excursion - (save-restriction - (goto-char (point-min)) - (narrow-to-region - (point) - (1- (or (search-forward "\n\n" nil t) (point-max)))) - ;; Fold continuation lines. - (goto-char (point-min)) - (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t) - (replace-match " " t t)) - (subst-char-in-region (point-min) (point-max) ?\t ? ) - ;; [number subject from date id references chars lines xref] - (save-excursion - (goto-char (point-min)) - (while (re-search-forward "^\\(from\\|subject\\|message-id\\|date\\|lines\\|xref\\|references\\|in-reply-to\\): " - nil t) - (beginning-of-line) - (setq char (downcase (following-char))) - (cond - ((eq char ?s) - (setq subject (nnml-header-value))) - ((eq char ?f) - (setq from (nnml-header-value))) - ((eq char ?x) - (setq xref (nnml-header-value))) - ((eq char ?l) - (setq lines (nnml-header-value))) - ((eq char ?d) - (setq date (nnml-header-value))) - ((eq char ?m) - (setq id (setq id (nnml-header-value)))) - ((eq char ?r) - (setq references (nnml-header-value))) - ((eq char ?i) - (setq in-reply-to (nnml-header-value)))) - (forward-line 1)) - - (and (not references) - in-reply-to - (string-match "<[^>]+>" in-reply-to) - (setq references - (substring in-reply-to (match-beginning 0) - (match-end 0))))) - ;; [number subject from date id references chars lines xref] - (format "\t%s\t%s\t%s\t%s\t%s\t%d\t%s\t%s\t\n" - (or subject "(none)") - (or from "(nobody)") (or date "") - (or id (concat "nnml-dummy-id-" - (mapconcat - (lambda (time) (int-to-string time)) - (current-time) "-"))) - (or references "") - (or chars 0) (or lines "0") (or xref "")))))) +(defun nnml-parse-head (chars &optional number) + "Parse the head of the current buffer." + (save-excursion + (save-restriction + (goto-char (point-min)) + (narrow-to-region + (point) + (1- (or (search-forward "\n\n" nil t) (point-max)))) + ;; Fold continuation lines. + (goto-char (point-min)) + (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t) + (replace-match " " t t)) + ;; Remove any tabs; they are too confusing. + (subst-char-in-region (point-min) (point-max) ?\t ? ) + (let ((headers (nnheader-parse-head t))) + (mail-header-set-chars headers chars) + (mail-header-set-number headers number) + headers)))) (defun nnml-open-nov (group) (or (cdr (assoc group nnml-nov-buffer-alist)) (let ((buffer (find-file-noselect - (concat (nnmail-article-pathname - group nnml-directory) nnml-nov-file-name)))) + (concat (nnmail-group-pathname group nnml-directory) + nnml-nov-file-name)))) (save-excursion (set-buffer buffer) (buffer-disable-undo (current-buffer))) @@ -610,85 +652,104 @@ all. This may very well take some time.") (defun nnml-save-nov () (save-excursion (while nnml-nov-buffer-alist - (if (buffer-name (cdr (car nnml-nov-buffer-alist))) - (progn - (set-buffer (cdr (car nnml-nov-buffer-alist))) - (and (buffer-modified-p) - (write-region - 1 (point-max) (buffer-file-name) nil 'nomesg)) - (set-buffer-modified-p nil) - (kill-buffer (current-buffer)))) + (when (buffer-name (cdar nnml-nov-buffer-alist)) + (set-buffer (cdar nnml-nov-buffer-alist)) + (and (buffer-modified-p) + (write-region + 1 (point-max) (buffer-file-name) nil 'nomesg)) + (set-buffer-modified-p nil) + (kill-buffer (current-buffer))) (setq nnml-nov-buffer-alist (cdr nnml-nov-buffer-alist))))) ;;;###autoload -(defun nnml-generate-nov-databases (dir) - "Generate nov databases in all nnml mail newsgroups." - (interactive - (progn - (setq nnml-group-alist nil) - (list nnml-directory))) - (nnml-open-server (or nnml-current-server "")) - (let ((dirs (directory-files dir t nil t))) +(defun nnml-generate-nov-databases () + "Generate nov databases in all nnml directories." + (interactive) + ;; Read the active file to make sure we don't re-use articles + ;; numbers in empty groups. + (nnmail-activate 'nnml) + (nnml-open-server (or (nnoo-current-server 'nnml) "")) + (setq nnml-directory (expand-file-name nnml-directory)) + ;; Recurse down the directories. + (nnml-generate-nov-databases-1 nnml-directory) + ;; Save the active file. + (nnmail-save-active nnml-group-alist nnml-active-file)) + +(defun nnml-generate-nov-databases-1 (dir) + (setq dir (file-name-as-directory dir)) + ;; We descend recursively + (let ((dirs (directory-files dir t nil t)) + dir) (while dirs - (if (and (not (string-match "/\\.\\.$" (car dirs))) - (not (string-match "/\\.$" (car dirs))) - (file-directory-p (car dirs))) - (nnml-generate-nov-databases (car dirs))) - (setq dirs (cdr dirs)))) + (setq dir (pop dirs)) + (when (and (not (member (file-name-nondirectory dir) '("." ".."))) + (file-directory-p dir)) + (nnml-generate-nov-databases-1 dir)))) + ;; Do this directory. (let ((files (sort (mapcar - (function - (lambda (name) - (string-to-int name))) + (lambda (name) (string-to-int name)) (directory-files dir nil "^[0-9]+$" t)) - (function <))) - (nov (concat dir "/" nnml-nov-file-name)) - (nov-buffer (get-buffer-create "*nov*")) - nov-line chars) - (if files - (setq nnml-group-alist - (cons (list (nnmail-replace-chars-in-string - (substring (expand-file-name dir) - (length (expand-file-name - nnml-directory))) - ?/ ?.) - (cons (car files) - (let ((f files)) - (while (cdr f) (setq f (cdr f))) - (car f)))) - nnml-group-alist))) - (if files - (save-excursion - (set-buffer nntp-server-buffer) - (if (file-exists-p nov) - (delete-file nov)) - (save-excursion - (set-buffer nov-buffer) - (buffer-disable-undo (current-buffer)) - (erase-buffer)) - (while files - (erase-buffer) - (insert-file-contents (concat dir "/" (int-to-string (car files)))) + '<))) + (when files + (funcall nnml-generate-active-function dir) + ;; Generate the nov file. + (nnml-generate-nov-file dir files)))) + +(defvar files) +(defun nnml-generate-active-info (dir) + ;; Update the active info for this group. + (let ((group (nnheader-file-to-group + (directory-file-name dir) nnml-directory))) + (setq nnml-group-alist + (delq (assoc group nnml-group-alist) nnml-group-alist)) + (push (list group + (cons (car files) + (let ((f files)) + (while (cdr f) (setq f (cdr f))) + (car f)))) + nnml-group-alist))) + +(defun nnml-generate-nov-file (dir files) + (let* ((dir (file-name-as-directory dir)) + (nov (concat dir nnml-nov-file-name)) + (nov-buffer (get-buffer-create " *nov*")) + nov-line chars file headers) + (save-excursion + ;; Init the nov buffer. + (set-buffer nov-buffer) + (buffer-disable-undo (current-buffer)) + (erase-buffer) + (set-buffer nntp-server-buffer) + ;; Delete the old NOV file. + (when (file-exists-p nov) + (funcall nnmail-delete-file-function nov)) + (while files + (unless (file-directory-p + (setq file (concat dir (int-to-string (car files))))) + (erase-buffer) + (insert-file-contents file) + (narrow-to-region + (goto-char (point-min)) + (progn + (search-forward "\n\n" nil t) + (setq chars (- (point-max) (point))) + (max 1 (1- (point))))) + (when (and (not (= 0 chars)) ; none of them empty files... + (not (= (point-min) (point-max)))) (goto-char (point-min)) - (narrow-to-region 1 (save-excursion (search-forward "\n\n" nil t) - (setq chars (- (point-max) - (point))) - (point))) - (if (not (= 0 chars)) ; none of them empty files... - (progn - (setq nov-line (nnml-make-nov-line chars)) - (save-excursion - (set-buffer nov-buffer) - (goto-char (point-max)) - (insert (int-to-string (car files)) nov-line)))) - (widen) - (setq files (cdr files))) - (save-excursion - (set-buffer nov-buffer) - (write-region 1 (point-max) (expand-file-name nov) nil - 'nomesg) - (kill-buffer (current-buffer))))) - (nnmail-save-active nnml-group-alist nnml-active-file))) + (setq headers (nnml-parse-head chars (car files))) + (save-excursion + (set-buffer nov-buffer) + (goto-char (point-max)) + (nnheader-insert-nov headers))) + (widen)) + (setq files (cdr files))) + (save-excursion + (set-buffer nov-buffer) + (write-region 1 (point-max) (expand-file-name nov) nil + 'nomesg) + (kill-buffer (current-buffer)))))) (defun nnml-nov-delete-article (group article) (save-excursion diff --git a/lisp/nnspool.el b/lisp/nnspool.el index 2d2c5ebcf84..82a607efe60 100644 --- a/lisp/nnspool.el +++ b/lisp/nnspool.el @@ -1,6 +1,5 @@ ;;; nnspool.el --- spool access for GNU Emacs - -;; Copyright (C) 1988,89,90,93,94,95 Free Software Foundation, Inc. +;; Copyright (C) 1988,89,90,93,94,95,96 Free Software Foundation, Inc. ;; Author: Masanobu UMEDA ;; Lars Magne Ingebrigtsen @@ -30,45 +29,49 @@ (require 'nnheader) (require 'nntp) (require 'timezone) +(require 'nnoo) +(eval-when-compile (require 'cl)) + +(nnoo-declare nnspool) -(defvar nnspool-inews-program news-inews-program +(defvoo nnspool-inews-program news-inews-program "Program to post news. This is most commonly `inews' or `injnews'.") -(defvar nnspool-inews-switches '("-h") +(defvoo nnspool-inews-switches '("-h" "-S") "Switches for nnspool-request-post to pass to `inews' for posting news. If you are using Cnews, you probably should set this variable to nil.") -(defvar nnspool-spool-directory news-path +(defvoo nnspool-spool-directory (file-name-as-directory news-path) "Local news spool directory.") -(defvar nnspool-nov-directory (concat nnspool-spool-directory "over.view/") +(defvoo nnspool-nov-directory (concat nnspool-spool-directory "over.view/") "Local news nov directory.") -(defvar nnspool-lib-dir "/usr/lib/news/" +(defvoo nnspool-lib-dir "/usr/lib/news/" "Where the local news library files are stored.") -(defvar nnspool-active-file (concat nnspool-lib-dir "active") +(defvoo nnspool-active-file (concat nnspool-lib-dir "active") "Local news active file.") -(defvar nnspool-newsgroups-file (concat nnspool-lib-dir "newsgroups") +(defvoo nnspool-newsgroups-file (concat nnspool-lib-dir "newsgroups") "Local news newsgroups file.") -(defvar nnspool-distributions-file (concat nnspool-lib-dir "distributions") +(defvoo nnspool-distributions-file (concat nnspool-lib-dir "distribs.pat") "Local news distributions file.") -(defvar nnspool-history-file (concat nnspool-lib-dir "history") +(defvoo nnspool-history-file (concat nnspool-lib-dir "history") "Local news history file.") -(defvar nnspool-active-times-file (concat nnspool-lib-dir "active.times") +(defvoo nnspool-active-times-file (concat nnspool-lib-dir "active.times") "Local news active date file.") -(defvar nnspool-large-newsgroup 50 +(defvoo nnspool-large-newsgroup 50 "The number of the articles which indicates a large newsgroup. If the number of the articles is greater than the value, verbose messages will be shown to indicate the current status.") -(defvar nnspool-nov-is-evil nil +(defvoo nnspool-nov-is-evil nil "Non-nil means that nnspool will never return NOV lines instead of headers.") (defconst nnspool-sift-nov-with-sed nil @@ -76,214 +79,195 @@ messages will be shown to indicate the current status.") If nil, nnspool will load the entire file into a buffer and process it there.") +(defvoo nnspool-rejected-article-hook nil + "*A hook that will be run when an article has been rejected by the server.") + (defconst nnspool-version "nnspool 2.0" "Version numbers of this version of NNSPOOL.") -(defvar nnspool-current-directory nil +(defvoo nnspool-current-directory nil "Current news group directory.") -(defvar nnspool-current-group nil) -(defvar nnspool-status-string "") - - - -(defvar nnspool-current-server nil) -(defvar nnspool-server-alist nil) -(defvar nnspool-server-variables - (list - (list 'nnspool-inews-program nnspool-inews-program) - (list 'nnspool-inews-switches nnspool-inews-switches) - (list 'nnspool-spool-directory nnspool-spool-directory) - (list 'nnspool-nov-directory nnspool-nov-directory) - (list 'nnspool-lib-dir nnspool-lib-dir) - (list 'nnspool-active-file nnspool-active-file) - (list 'nnspool-newsgroups-file nnspool-newsgroups-file) - (list 'nnspool-distributions-file nnspool-distributions-file) - (list 'nnspool-history-file nnspool-history-file) - (list 'nnspool-active-times-file nnspool-active-times-file) - (list 'nnspool-large-newsgroup nnspool-large-newsgroup) - (list 'nnspool-nov-is-evil nnspool-nov-is-evil) - (list 'nnspool-sift-nov-with-sed nnspool-sift-nov-with-sed) - '(nnspool-current-directory nil) - '(nnspool-current-group nil) - '(nnspool-status-string ""))) +(defvoo nnspool-current-group nil) +(defvoo nnspool-status-string "") ;;; Interface functions. -(defun nnspool-retrieve-headers (sequence &optional newsgroup server) - "Retrieve the headers for the articles in SEQUENCE. -Newsgroup must be selected before calling this function." +(nnoo-define-basics nnspool) + +(deffoo nnspool-retrieve-headers (articles &optional group server fetch-old) + "Retrieve the headers of ARTICLES." (save-excursion (set-buffer nntp-server-buffer) (erase-buffer) - (let* ((number (length sequence)) - (count 0) - (do-message (and (numberp nnspool-large-newsgroup) - (> number nnspool-large-newsgroup))) - file beg article) - (if (not (nnspool-possibly-change-directory newsgroup)) - () - (if (and (numberp (car sequence)) - (nnspool-retrieve-headers-with-nov sequence)) + (when (nnspool-possibly-change-directory group) + (let* ((number (length articles)) + (count 0) + (default-directory nnspool-current-directory) + (do-message (and (numberp nnspool-large-newsgroup) + (> number nnspool-large-newsgroup))) + file beg article ag) + (if (and (numberp (car articles)) + (nnspool-retrieve-headers-with-nov articles fetch-old)) + ;; We successfully retrieved the NOV headers. 'nov - (while sequence - (setq article (car sequence)) + ;; No NOV headers here, so we do it the hard way. + (while (setq article (pop articles)) (if (stringp article) - (progn - (setq file (nnspool-find-article-by-message-id article)) - (setq article 0)) - (setq file (concat nnspool-current-directory - (int-to-string article)))) - (and file (file-exists-p file) - (progn - (insert (format "221 %d Article retrieved.\n" article)) - (setq beg (point)) - (nnheader-insert-head file) - (goto-char beg) - (search-forward "\n\n" nil t) - (forward-char -1) - (insert ".\n") - (delete-region (point) (point-max)))) - (setq sequence (cdr sequence)) + ;; This is a Message-ID. + (setq ag (nnspool-find-id article) + file (and ag (nnspool-article-pathname + (car ag) (cdr ag))) + article (cdr ag)) + ;; This is an article in the current group. + (setq file (int-to-string article))) + ;; Insert the head of the article. + (when (and file + (file-exists-p file)) + (insert "221 ") + (princ article (current-buffer)) + (insert " Article retrieved.\n") + (setq beg (point)) + (inline (nnheader-insert-head file)) + (goto-char beg) + (search-forward "\n\n" nil t) + (forward-char -1) + (insert ".\n") + (delete-region (point) (point-max))) (and do-message - (zerop (% (setq count (1+ count)) 20)) - (message "NNSPOOL: Receiving headers... %d%%" + (zerop (% (incf count) 20)) + (message "nnspool: Receiving headers... %d%%" (/ (* count 100) number)))) - (and do-message (message "NNSPOOL: Receiving headers...done")) + (and do-message + (message "nnspool: Receiving headers...done")) ;; Fold continuation lines. - (goto-char (point-min)) - (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t) - (replace-match " " t t)) + (nnheader-fold-continuation-lines) 'headers))))) -(defun nnspool-open-server (server &optional defs) - (nnheader-init-server-buffer) - (if (equal server nnspool-current-server) - t - (if nnspool-current-server - (setq nnspool-server-alist - (cons (list nnspool-current-server - (nnheader-save-variables nnspool-server-variables)) - nnspool-server-alist))) - (let ((state (assoc server nnspool-server-alist))) - (if state - (progn - (nnheader-restore-variables (nth 1 state)) - (setq nnspool-server-alist (delq state nnspool-server-alist))) - (nnheader-set-init-variables nnspool-server-variables defs))) - (setq nnspool-current-server server))) - -(defun nnspool-close-server (&optional server) - t) - -(defun nnspool-server-opened (&optional server) - (and (equal server nnspool-current-server) - nntp-server-buffer - (buffer-name nntp-server-buffer))) - -(defun nnspool-status-message (&optional server) - "Return server status response as string." - nnspool-status-string) - -(defun nnspool-request-article (id &optional newsgroup server buffer) +(deffoo nnspool-open-server (server &optional defs) + (nnoo-change-server 'nnspool server defs) + (cond + ((not (file-exists-p nnspool-spool-directory)) + (nnspool-close-server) + (nnheader-report 'nnspool "Spool directory doesn't exist: %s" + nnspool-spool-directory)) + ((not (file-directory-p + (directory-file-name + (file-truename nnspool-spool-directory)))) + (nnspool-close-server) + (nnheader-report 'nnspool "Not a directory: %s" nnspool-spool-directory)) + ((not (file-exists-p nnspool-active-file)) + (nnheader-report 'nnspool "The active file doesn't exist: %s" + nnspool-active-file)) + (t + (nnheader-report 'nnspool "Opened server %s using directory %s" + server nnspool-spool-directory) + t))) + +(deffoo nnspool-request-article (id &optional group server buffer) "Select article by message ID (or number)." - (nnspool-possibly-change-directory newsgroup) - (let ((file (if (stringp id) - (nnspool-find-article-by-message-id id) - (concat nnspool-current-directory (prin1-to-string id)))) - (nntp-server-buffer (or buffer nntp-server-buffer))) - (if (and (stringp file) - (file-exists-p file) - (not (file-directory-p file))) - (save-excursion - (nnspool-find-file file))))) - -(defun nnspool-request-body (id &optional newsgroup server) + (nnspool-possibly-change-directory group) + (let ((nntp-server-buffer (or buffer nntp-server-buffer)) + file ag) + (if (stringp id) + ;; This is a Message-ID. + (when (setq ag (nnspool-find-id id)) + (setq file (nnspool-article-pathname (car ag) (cdr ag)))) + (setq file (nnspool-article-pathname nnspool-current-group id))) + (and file + (file-exists-p file) + (not (file-directory-p file)) + (save-excursion (nnspool-find-file file)) + ;; We return the article number and group name. + (if (numberp id) + (cons nnspool-current-group id) + ag)))) + +(deffoo nnspool-request-body (id &optional group server) "Select article body by message ID (or number)." - (nnspool-possibly-change-directory newsgroup) - (if (nnspool-request-article id) + (nnspool-possibly-change-directory group) + (let ((res (nnspool-request-article id))) + (when res (save-excursion (set-buffer nntp-server-buffer) (goto-char (point-min)) - (if (search-forward "\n\n" nil t) - (delete-region (point-min) (point))) - t))) + (when (search-forward "\n\n" nil t) + (delete-region (point-min) (point))) + res)))) -(defun nnspool-request-head (id &optional newsgroup server) +(deffoo nnspool-request-head (id &optional group server) "Select article head by message ID (or number)." - (nnspool-possibly-change-directory newsgroup) - (if (nnspool-request-article id) + (nnspool-possibly-change-directory group) + (let ((res (nnspool-request-article id))) + (when res (save-excursion (set-buffer nntp-server-buffer) (goto-char (point-min)) - (if (search-forward "\n\n" nil t) - (delete-region (1- (point)) (point-max))) - t))) + (when (search-forward "\n\n" nil t) + (delete-region (1- (point)) (point-max))) + (nnheader-fold-continuation-lines))) + res)) -(defun nnspool-request-group (group &optional server dont-check) +(deffoo nnspool-request-group (group &optional server dont-check) "Select news GROUP." - (let ((pathname (nnspool-article-pathname - (nnspool-replace-chars-in-string group ?. ?/))) + (let ((pathname (nnspool-article-pathname group)) dir) (if (not (file-directory-p pathname)) - (progn - (setq nnspool-status-string - "Invalid group name (no such directory)") - nil) + (nnheader-report + 'nnspool "Invalid group name (no such directory): %s" group) (setq nnspool-current-directory pathname) - (setq nnspool-status-string "") - (if (not dont-check) + (nnheader-report 'nnspool "Selected group %s" group) + (if dont-check (progn - (setq dir (directory-files pathname nil "^[0-9]+$" t)) - ;; yes, completely empty spool directories *are* possible - ;; Fix by Sudish Joseph - (and dir - (setq dir - (sort - (mapcar - (function - (lambda (name) - (string-to-int name))) - dir) - '<))) - (save-excursion - (set-buffer nntp-server-buffer) - (erase-buffer) - (if dir - (insert - (format "211 %d %d %d %s\n" (length dir) (car dir) - (progn (while (cdr dir) (setq dir (cdr dir))) - (car dir)) - group)) - (insert (format "211 0 0 0 %s\n" group)))))) - t))) - -(defun nnspool-close-group (group &optional server) + (nnheader-report 'nnspool "Selected group %s" group) + t) + ;; Yes, completely empty spool directories *are* possible. + ;; Fix by Sudish Joseph + (when (setq dir (directory-files pathname nil "^[0-9]+$" t)) + (setq dir + (sort (mapcar (lambda (name) (string-to-int name)) dir) '<))) + (if dir + (nnheader-insert + "211 %d %d %d %s\n" (length dir) (car dir) + (progn (while (cdr dir) (setq dir (cdr dir))) (car dir)) + group) + (nnheader-report 'nnspool "Empty group %s" group) + (nnheader-insert "211 0 0 0 %s\n" group)))))) + +(deffoo nnspool-request-type (group &optional article) + 'news) + +(deffoo nnspool-close-group (group &optional server) t) -(defun nnspool-request-list (&optional server) +(deffoo nnspool-request-list (&optional server) "List active newsgroups." (save-excursion - (nnspool-find-file nnspool-active-file))) + (or (nnspool-find-file nnspool-active-file) + (nnheader-report 'nnspool (nnheader-file-error nnspool-active-file))))) -(defun nnspool-request-list-newsgroups (&optional server) +(deffoo nnspool-request-list-newsgroups (&optional server) "List newsgroups (defined in NNTP2)." (save-excursion - (nnspool-find-file nnspool-newsgroups-file))) + (or (nnspool-find-file nnspool-newsgroups-file) + (nnheader-report 'nnspool (nnheader-file-error + nnspool-newsgroups-file))))) -(defun nnspool-request-list-distributions (&optional server) +(deffoo nnspool-request-list-distributions (&optional server) "List distributions (defined in NNTP2)." (save-excursion - (nnspool-find-file nnspool-distributions-file))) + (or (nnspool-find-file nnspool-distributions-file) + (nnheader-report 'nnspool (nnheader-file-error + nnspool-distributions-file))))) ;; Suggested by Hallvard B Furuseth . -(defun nnspool-request-newgroups (date &optional server) +(deffoo nnspool-request-newgroups (date &optional server) "List groups created after DATE." (if (nnspool-find-file nnspool-active-times-file) (save-excursion @@ -317,21 +301,33 @@ Newsgroup must be selected before calling this function." t) nil)) -(defun nnspool-request-post (&optional server) +(deffoo nnspool-request-post (&optional server) "Post a new news in current buffer." (save-excursion (let* ((process-connection-type nil) ; t bugs out on Solaris (inews-buffer (generate-new-buffer " *nnspool post*")) - (proc (apply 'start-process "*nnspool inews*" inews-buffer - nnspool-inews-program nnspool-inews-switches))) - (set-process-sentinel proc 'nnspool-inews-sentinel) - (process-send-region proc (point-min) (point-max)) - ;; We slap a condition-case around this, because the process may - ;; have exited already... - (condition-case nil - (process-send-eof proc) - (error nil)) - t))) + (proc + (condition-case err + (apply 'start-process "*nnspool inews*" inews-buffer + nnspool-inews-program nnspool-inews-switches) + (error + (nnheader-report 'nnspool "inews error: %S" err))))) + (if (not proc) + ;; The inews program failed. + () + (nnheader-report 'nnspool "") + (set-process-sentinel proc 'nnspool-inews-sentinel) + (process-send-region proc (point-min) (point-max)) + ;; We slap a condition-case around this, because the process may + ;; have exited already... + (condition-case nil + (process-send-eof proc) + (error nil)) + t)))) + + + +;;; Internal functions. (defun nnspool-inews-sentinel (proc status) (save-excursion @@ -340,69 +336,118 @@ Newsgroup must be selected before calling this function." (if (or (zerop (buffer-size)) (search-forward "spooled" nil t)) (kill-buffer (current-buffer)) - ;; Make status message by unfolding lines. - (subst-char-in-region (point-min) (point-max) ?\n ?\\ 'noundo) - (setq nnspool-status-string (buffer-string)) + ;; Make status message by folding lines. + (while (re-search-forward "[ \t\n]+" nil t) + (replace-match " " t t)) + (nnheader-report 'nnspool "%s" (buffer-string)) (message "nnspool: %s" nnspool-status-string) - ;(kill-buffer (current-buffer)) - ))) - -(defalias 'nnspool-request-post-buffer 'nntp-request-post-buffer) - - -;;; Internal functions. + (ding) + (run-hooks 'nnspool-rejected-article-hook)))) -(defun nnspool-retrieve-headers-with-nov (articles) +(defun nnspool-retrieve-headers-with-nov (articles &optional fetch-old) (if (or gnus-nov-is-evil nnspool-nov-is-evil) nil - (let ((nov (concat (file-name-as-directory nnspool-nov-directory) - (nnspool-replace-chars-in-string - nnspool-current-group ?. ?/) - "/.overview")) - article) - (if (file-exists-p nov) - (save-excursion - (set-buffer nntp-server-buffer) - (erase-buffer) - (if nnspool-sift-nov-with-sed - (nnspool-sift-nov-with-sed articles nov) - (insert-file-contents nov) - ;; First we find the first wanted line. We issue a number - ;; of search-forwards - the first article we are looking - ;; for may be expired, so we have to go on searching until - ;; we find one of the articles we want. - (while (and articles - (setq article (concat (int-to-string - (car articles)) "\t")) - (not (or (looking-at article) - (search-forward (concat "\n" article) - nil t)))) - (setq articles (cdr articles))) - (if (not articles) - () - (beginning-of-line) - (delete-region (point-min) (point)) - ;; Then we find the last wanted line. We go to the end - ;; of the buffer and search backward much the same way - ;; we did to find the first article. - ;; !!! Perhaps it would be better just to do a (last articles), - ;; and go forward successively over each line and - ;; compare to avoid this (reverse), like this: - ;; (while (and (>= last (read nntp-server-buffer))) - ;; (zerop (forward-line 1)))) - (setq articles (reverse articles)) - (goto-char (point-max)) - (while (and articles - (not (search-backward - (concat "\n" (int-to-string (car articles)) - "\t") nil t))) - (setq articles (cdr articles))) - (if articles - (progn - (forward-line 2) - (delete-region (point) (point-max))))) - (or articles (progn (erase-buffer) nil)))))))) - + (let ((nov (nnheader-group-pathname + nnspool-current-group nnspool-nov-directory ".overview")) + (arts articles) + last) + (if (not (file-exists-p nov)) + () + (save-excursion + (set-buffer nntp-server-buffer) + (erase-buffer) + (if nnspool-sift-nov-with-sed + (nnspool-sift-nov-with-sed articles nov) + (insert-file-contents nov) + (if (and fetch-old + (not (numberp fetch-old))) + t ; We want all the headers. + (condition-case () + (progn + ;; First we find the first wanted line. + (nnspool-find-nov-line + (if fetch-old (max 1 (- (car articles) fetch-old)) + (car articles))) + (delete-region (point-min) (point)) + ;; Then we find the last wanted line. + (if (nnspool-find-nov-line + (progn (while (cdr articles) + (setq articles (cdr articles))) + (car articles))) + (forward-line 1)) + (delete-region (point) (point-max)) + ;; If the buffer is empty, this wasn't very successful. + (unless (zerop (buffer-size)) + ;; We check what the last article number was. + ;; The NOV file may be out of sync with the articles + ;; in the group. + (forward-line -1) + (setq last (read (current-buffer))) + (if (= last (car articles)) + ;; Yup, it's all there. + t + ;; Perhaps not. We try to find the missing articles. + (while (and arts + (<= last (car arts))) + (pop arts)) + ;; The articles in `arts' are missing from the buffer. + (while arts + (nnspool-insert-nov-head (pop arts))) + t))) + ;; The NOV file was corrupted. + (error nil))))))))) + +(defun nnspool-insert-nov-head (article) + "Read the head of ARTICLE, convert to NOV headers, and insert." + (save-excursion + (let ((cur (current-buffer)) + buf) + (setq buf (nnheader-set-temp-buffer " *nnspool head*")) + (when (nnheader-insert-head + (nnspool-article-pathname nnspool-current-group article)) + (nnheader-insert-article-line article) + (let ((headers (nnheader-parse-head))) + (set-buffer cur) + (goto-char (point-max)) + (nnheader-insert-nov headers))) + (kill-buffer buf)))) + +(defun nnspool-find-nov-line (article) + (let ((max (point-max)) + (min (goto-char (point-min))) + (cur (current-buffer)) + (prev (point-min)) + num found) + (while (not found) + (goto-char (/ (+ max min) 2)) + (beginning-of-line) + (if (or (= (point) prev) + (eobp)) + (setq found t) + (setq prev (point)) + (cond ((> (setq num (read cur)) article) + (setq max (point))) + ((< num article) + (setq min (point))) + (t + (setq found 'yes))))) + ;; Now we may have found the article we're looking for, or we + ;; may be somewhere near it. + (when (and (not (eq found 'yes)) + (not (eq num article))) + (setq found (point)) + (while (and (< (point) max) + (or (not (numberp num)) + (< num article))) + (forward-line 1) + (setq found (point)) + (or (eobp) + (= (setq num (read cur)) article))) + (unless (eq num article) + (goto-char found))) + (beginning-of-line) + (eq num article))) + (defun nnspool-sift-nov-with-sed (articles file) (let ((first (car articles)) (last (progn (while (cdr articles) (setq articles (cdr articles))) @@ -413,70 +458,41 @@ Newsgroup must be selected before calling this function." file))) ;; Fixed by fdc@cliwe.ping.de (Frank D. Cringle). -(defun nnspool-find-article-by-message-id (id) - "Return full pathname of an article identified by message-ID." +;; Find out what group an article identified by a Message-ID is in. +(defun nnspool-find-id (id) (save-excursion - (let ((buf (get-buffer-create " *nnspool work*"))) - (set-buffer buf) - (erase-buffer) - (call-process "grep" nil t nil id nnspool-history-file) - (goto-char (point-min)) - (if (looking-at "<[^>]+>[ \t]+[-0-9~]+[ \t]+\\([^ \t\n]*\\)") - (concat nnspool-spool-directory - (nnspool-replace-chars-in-string - (buffer-substring (match-beginning 1) (match-end 1)) - ?. ?/)))))) + (set-buffer (get-buffer-create " *nnspool work*")) + (buffer-disable-undo (current-buffer)) + (erase-buffer) + (condition-case () + (call-process "grep" nil t nil id nnspool-history-file) + (error nil)) + (goto-char (point-min)) + (prog1 + (if (looking-at "<[^>]+>[ \t]+[-0-9~]+[ \t]+\\([^ /\t\n]+\\)/\\([0-9]+\\)[ \t\n]") + (cons (match-string 1) (string-to-int (match-string 2)))) + (kill-buffer (current-buffer))))) (defun nnspool-find-file (file) "Insert FILE in server buffer safely." (set-buffer nntp-server-buffer) (erase-buffer) (condition-case () - (progn (insert-file-contents file) t) + (progn (nnheader-insert-file-contents-literally file) t) (file-error nil))) -(defun nnspool-possibly-change-directory (newsgroup) - (if newsgroup - (let ((pathname (nnspool-article-pathname - (nnspool-replace-chars-in-string newsgroup ?. ?/)))) - (if (file-directory-p pathname) - (progn - (setq nnspool-current-directory pathname) - (setq nnspool-current-group newsgroup)) - (setq nnspool-status-string - (format "No such newsgroup: %s" newsgroup)) - nil)) - t)) - -(defun nnspool-article-pathname (group) - "Make pathname for GROUP." - (concat (file-name-as-directory nnspool-spool-directory) group "/")) - -(defun nnspool-replace-chars-in-string (string from to) - "Replace characters in STRING from FROM to TO." - (let ((string (substring string 0)) ;Copy string. - (len (length string)) - (idx 0)) - ;; Replace all occurrences of FROM with TO. - (while (< idx len) - (if (= (aref string idx) from) - (aset string idx to)) - (setq idx (1+ idx))) - string)) - -(defun nnspool-number-base-10 (num pos) - (if (<= pos 0) "" - (setcdr num (+ (* (% (car num) 10) 65536) (cdr num))) - (apply - 'concat - (reverse - (list - (char-to-string - (aref "0123456789" (% (cdr num) 10))) - (progn - (setcdr num (/ (cdr num) 10)) - (setcar num (/ (car num) 10)) - (nnspool-number-base-10 num (1- pos)))))))) +(defun nnspool-possibly-change-directory (group) + (if (not group) + t + (let ((pathname (nnspool-article-pathname group))) + (if (file-directory-p pathname) + (setq nnspool-current-directory pathname + nnspool-current-group group) + (nnheader-report 'nnspool "No such newsgroup: %s" group))))) + +(defun nnspool-article-pathname (group &optional article) + "Find the path for GROUP." + (nnheader-group-pathname group nnspool-spool-directory article)) (defun nnspool-seconds-since-epoch (date) (let* ((tdate (mapcar (lambda (ti) (and ti (string-to-int ti))) @@ -485,9 +501,10 @@ Newsgroup must be selected before calling this function." (timezone-parse-time (aref (timezone-parse-date date) 3)))) (unix (encode-time (nth 2 ttime) (nth 1 ttime) (nth 0 ttime) - (nth 2 tdate) (nth 1 tdate) (nth 0 tdate) (nth 4 tdate)))) + (nth 2 tdate) (nth 1 tdate) (nth 0 tdate) + (nth 4 tdate)))) (+ (* (car unix) 65536.0) - (car (cdr unix))))) + (cadr unix)))) (provide 'nnspool) diff --git a/lisp/nntp.el b/lisp/nntp.el index e5e1f2a36b3..8b34460b108 100644 --- a/lisp/nntp.el +++ b/lisp/nntp.el @@ -1,5 +1,4 @@ ;;; nntp.el --- nntp access for Gnus - ;; Copyright (C) 1987,88,89,90,92,93,94,95,96 Free Software Foundation, Inc. ;; Author: Masanobu UMEDA @@ -27,22 +26,25 @@ ;;; Code: -(require 'rnews) -(require 'sendmail) (require 'nnheader) +(require 'nnoo) +(eval-when-compile (require 'cl)) + +(nnoo-declare nntp) + +(eval-and-compile + (unless (fboundp 'open-network-stream) + (require 'tcp))) (eval-when-compile (require 'cl)) (eval-and-compile - (autoload 'news-setup "rnewspost") - (autoload 'news-reply-mode "rnewspost") - (autoload 'nnmail-request-post-buffer "nnmail") (autoload 'cancel-timer "timer") (autoload 'telnet "telnet" nil t) (autoload 'telnet-send-input "telnet" nil t) (autoload 'timezone-parse-date "timezone")) -(defvar nntp-server-hook nil +(defvoo nntp-server-hook nil "*Hooks for the NNTP server. If the kanji code of the NNTP server is different from the local kanji code, the correct kanji code of the buffer associated with the NNTP @@ -58,7 +60,7 @@ server must be specified as follows: If you'd like to change something depending on the server in this hook, use the variable `nntp-address'.") -(defvar nntp-server-opened-hook nil +(defvoo nntp-server-opened-hook '(nntp-send-mode-reader) "*Hook used for sending commands to the server at startup. The default value is `nntp-send-mode-reader', which makes an innd server spawn an nnrpd server. Another useful function to put in this @@ -67,7 +69,19 @@ to allow posting from the server. Note that this is only necessary to do on servers that use strict access control.") (add-hook 'nntp-server-opened-hook 'nntp-send-mode-reader) -(defvar nntp-open-server-function 'nntp-open-network-stream +(defvoo nntp-server-action-alist + '(("nntpd 1\\.5\\.11t" + (remove-hook 'nntp-server-opened-hook 'nntp-send-mode-reader))) + "Alist of regexps to match on server types and actions to be taken. +For instance, if you want Gnus to beep every time you connect +to innd, you could say something like: + +\(setq nntp-server-action-alist + '((\"innd\" (ding)))) + +You probably don't want to do that, though.") + +(defvoo nntp-open-server-function 'nntp-open-network-stream "*Function used for connecting to a remote system. It will be called with the address of the remote system. @@ -77,63 +91,75 @@ system (see nntp-port-number). The other is `nntp-open-rlogin', which does an rlogin on the remote system, and then does a telnet to the NNTP server available there (see nntp-rlogin-parameters).") -(defvar nntp-rlogin-parameters '("telnet" "${NNTPSERVER:=localhost}" "nntp") +(defvoo nntp-rlogin-parameters '("telnet" "${NNTPSERVER:=localhost}" "nntp") "*Parameters to `nntp-open-login'. That function may be used as `nntp-open-server-function'. In that case, this list will be used as the parameter list given to rsh.") -(defvar nntp-rlogin-user-name nil +(defvoo nntp-rlogin-user-name nil "*User name on remote system when using the rlogin connect method.") -(defvar nntp-address nil +(defvoo nntp-address nil "*The name of the NNTP server.") -(defvar nntp-port-number "nntp" +(defvoo nntp-port-number "nntp" "*Port number to connect to.") -(defvar nntp-large-newsgroup 50 +(defvoo nntp-end-of-line "\r\n" + "String to use on the end of lines when talking to the NNTP server. +This is \"\\r\\n\" by default, but should be \"\\n\" when +using rlogin to communicate with the server.") + +(defvoo nntp-large-newsgroup 50 "*The number of the articles which indicates a large newsgroup. If the number of the articles is greater than the value, verbose messages will be shown to indicate the current status.") -(defvar nntp-buggy-select (memq system-type '(fujitsu-uts)) +(defvoo nntp-buggy-select (memq system-type '(fujitsu-uts)) "*t if your select routine is buggy. If the select routine signals error or fall into infinite loop while waiting for the server response, the variable must be set to t. In case of Fujitsu UTS, it is set to T since `accept-process-output' doesn't work properly.") -(defvar nntp-maximum-request 400 +(defvoo nntp-maximum-request 400 "*The maximum number of the requests sent to the NNTP server at one time. If Emacs hangs up while retrieving headers, set the variable to a lower value.") -(defvar nntp-debug-read 10000 +(defvoo nntp-debug-read 10000 "*Display '...' every 10Kbytes of a message being received if it is non-nil. If it is a number, dots are displayed per the number.") -(defvar nntp-nov-is-evil nil +(defvoo nntp-nov-is-evil nil "*If non-nil, nntp will never attempt to use XOVER when talking to the server.") -(defvar nntp-xover-commands '("XOVER" "XOVERVIEW") +(defvoo nntp-xover-commands '("XOVER" "XOVERVIEW") "*List of strings that are used as commands to fetch NOV lines from a server. The strings are tried in turn until a positive response is gotten. If none of the commands are successful, nntp will just grab headers one by one.") -(defvar nntp-nov-gap 20 +(defvoo nntp-nov-gap 20 "*Maximum allowed gap between two articles. If the gap between two consecutive articles is bigger than this variable, split the XOVER request into two requests.") -(defvar nntp-connection-timeout nil +(defvoo nntp-connection-timeout nil "*Number of seconds to wait before an nntp connection times out. If this variable is nil, which is the default, no timers are set.") -(defvar nntp-news-default-headers nil +(defvoo nntp-command-timeout nil + "*Number of seconds to wait for a response when sending a command. +If this variable is nil, which is the default, no timers are set.") + +(defvoo nntp-retry-on-break nil + "*If non-nil, re-send the command when the user types `C-g'.") + +(defvoo nntp-news-default-headers nil "*If non-nil, override `mail-default-headers' when posting news.") -(defvar nntp-prepare-server-hook nil +(defvoo nntp-prepare-server-hook nil "*Hook run before a server is opened. If can be used to set up a server remotely, for instance. Say you have an account at the machine \"other.machine\". This machine has @@ -141,9 +167,11 @@ access to an NNTP server that you can't access locally. You could then use this hook to rsh to the remote machine and start a proxy NNTP server there that you can connect to.") -(defvar nntp-async-number 5 +(defvoo nntp-async-number 5 "*How many articles should be prefetched when in asynchronous mode.") +(defvoo nntp-warn-about-losing-connection t + "*If non-nil, beep when a server closes connection.") @@ -153,226 +181,181 @@ server there that you can connect to.") (defvar nntp-server-buffer nil "Buffer associated with the NNTP server process.") -(defvar nntp-server-process nil +(defvoo nntp-server-process nil "The NNTP server process. You'd better not use this variable in NNTP front-end program, but instead use `nntp-server-buffer'.") -(defvar nntp-status-string nil - "Save the server response message. -You'd better not use this variable in NNTP front-end program but -instead call function `nntp-status-message' to get status message.") +(defvoo nntp-status-string nil + "Save the server response message.") (defvar nntp-opened-connections nil "All (possibly) opened connections.") -(defvar nntp-server-xover 'try) -(defvar nntp-server-list-active-group 'try) -(defvar nntp-current-group "") -(defvar nntp-timeout-servers nil) - -(defvar nntp-async-process nil) -(defvar nntp-async-buffer nil) -(defvar nntp-async-articles nil) -(defvar nntp-async-fetched nil) -(defvar nntp-async-group-alist nil) +(defvoo nntp-server-xover 'try) +(defvoo nntp-server-list-active-group 'try) +(defvoo nntp-current-group "") +(defvoo nntp-server-type nil) - - -(defvar nntp-current-server nil) -(defvar nntp-server-alist nil) -(defvar nntp-server-variables - (list - (list 'nntp-server-hook nntp-server-hook) - (list 'nntp-server-opened-hook nntp-server-opened-hook) - (list 'nntp-port-number nntp-port-number) - (list 'nntp-address nntp-address) - (list 'nntp-large-newsgroup nntp-large-newsgroup) - (list 'nntp-buggy-select nntp-buggy-select) - (list 'nntp-maximum-request nntp-maximum-request) - (list 'nntp-debug-read nntp-debug-read) - (list 'nntp-nov-is-evil nntp-nov-is-evil) - (list 'nntp-xover-commands nntp-xover-commands) - (list 'nntp-connection-timeout nntp-connection-timeout) - (list 'nntp-news-default-headers nntp-news-default-headers) - (list 'nntp-prepare-server-hook nntp-prepare-server-hook) - (list 'nntp-async-number nntp-async-number) - '(nntp-async-process nil) - '(nntp-async-buffer nil) - '(nntp-async-articles nil) - '(nntp-async-fetched nil) - '(nntp-async-group-alist nil) - '(nntp-server-process nil) - '(nntp-status-string nil) - '(nntp-server-xover try) - '(nntp-server-list-active-group try) - '(nntp-current-group ""))) +(defvoo nntp-async-process nil) +(defvoo nntp-async-buffer nil) +(defvoo nntp-async-articles nil) +(defvoo nntp-async-fetched nil) +(defvoo nntp-async-group-alist nil) ;;; Interface functions. -(defun nntp-retrieve-headers (sequence &optional newsgroup server) - "Retrieve the headers to the articles in SEQUENCE." - (nntp-possibly-change-server newsgroup server) +(nnoo-define-basics nntp) + +(deffoo nntp-retrieve-headers (articles &optional group server fetch-old) + "Retrieve the headers of ARTICLES." + (nntp-possibly-change-server group server) (save-excursion (set-buffer nntp-server-buffer) (erase-buffer) (if (and (not gnus-nov-is-evil) (not nntp-nov-is-evil) - (nntp-retrieve-headers-with-xover sequence)) + (nntp-retrieve-headers-with-xover articles fetch-old)) + ;; We successfully retrieved the headers via XOVER. 'nov - (let ((number (length sequence)) + ;; XOVER didn't work, so we do it the hard, slow and inefficient + ;; way. + (let ((number (length articles)) (count 0) (received 0) + (message-log-max nil) (last-point (point-min))) ;; Send HEAD command. - (while sequence + (while articles (nntp-send-strings-to-server - "HEAD" (if (numberp (car sequence)) (int-to-string (car sequence)) - (car sequence))) - (setq sequence (cdr sequence) + "HEAD" (if (numberp (car articles)) + (int-to-string (car articles)) + ;; `articles' is either a list of article numbers + ;; or a list of article IDs. + (car articles))) + (setq articles (cdr articles) count (1+ count)) - ;; Every 400 header requests we have to read stream in order - ;; to avoid deadlock. - (if (or (null sequence) ;All requests have been sent. - (zerop (% count nntp-maximum-request))) - (progn - (nntp-accept-response) - (while (progn - (goto-char last-point) - ;; Count replies. - (while (re-search-forward "^[0-9]" nil t) - (setq received (1+ received))) - (setq last-point (point)) - (< received count)) - ;; If number of headers is greater than 100, give - ;; informative messages. - (and (numberp nntp-large-newsgroup) - (> number nntp-large-newsgroup) - (zerop (% received 20)) - (message "NNTP: Receiving headers... %d%%" - (/ (* received 100) number))) - (nntp-accept-response))))) + ;; Every 400 header requests we have to read the stream in + ;; order to avoid deadlocks. + (when (or (null articles) ;All requests have been sent. + (zerop (% count nntp-maximum-request))) + (nntp-accept-response) + (while (progn + (goto-char last-point) + ;; Count replies. + (while (re-search-forward "^[0-9]" nil t) + (setq received (1+ received))) + (setq last-point (point)) + (< received count)) + ;; If number of headers is greater than 100, give + ;; informative messages. + (and (numberp nntp-large-newsgroup) + (> number nntp-large-newsgroup) + (zerop (% received 20)) + (nnheader-message 7 "NNTP: Receiving headers... %d%%" + (/ (* received 100) number))) + (nntp-accept-response)))) ;; Wait for text of last command. (goto-char (point-max)) (re-search-backward "^[0-9]" nil t) - (if (looking-at "^[23]") - (while (progn - (goto-char (- (point-max) 3)) - (not (looking-at "^\\.\r?\n"))) - (nntp-accept-response))) + (when (looking-at "^[23]") + (while (progn + (goto-char (- (point-max) 3)) + (not (looking-at "^\\.\r?\n"))) + (nntp-accept-response))) (and (numberp nntp-large-newsgroup) (> number nntp-large-newsgroup) - (message "NNTP: Receiving headers...done")) + (nnheader-message 7 "NNTP: Receiving headers...done")) - ;; Now all of replies are received. - (setq received number) - ;; First, fold continuation lines. - (goto-char (point-min)) - (while (re-search-forward "\\(\r?\n[ \t]+\\)+" nil t) - (replace-match " ")) - ;; Remove all "\r"'s + ;; Now all of replies are received. Fold continuation lines. + (nnheader-fold-continuation-lines) + ;; Remove all "\r"'s. (goto-char (point-min)) (while (search-forward "\r" nil t) - (replace-match "")) + (replace-match "" t t)) 'headers)))) -(defun nntp-retrieve-groups (groups &optional server) +(deffoo nntp-retrieve-groups (groups &optional server) + "Retrieve group info on GROUPS." (nntp-possibly-change-server nil server) (save-excursion (set-buffer nntp-server-buffer) - (and (eq nntp-server-list-active-group 'try) - (nntp-try-list-active (car groups))) + ;; The first time this is run, this variable is `try'. So we + ;; try. + (when (eq nntp-server-list-active-group 'try) + (nntp-try-list-active (car groups))) (erase-buffer) (let ((count 0) (received 0) (last-point (point-min)) - (command (if nntp-server-list-active-group - "LIST ACTIVE" "GROUP"))) + (command (if nntp-server-list-active-group "LIST ACTIVE" "GROUP"))) (while groups + ;; Send the command to the server. (nntp-send-strings-to-server command (car groups)) (setq groups (cdr groups)) (setq count (1+ count)) ;; Every 400 requests we have to read the stream in ;; order to avoid deadlocks. - (if (or (null groups) ;All requests have been sent. - (zerop (% count nntp-maximum-request))) - (progn - (nntp-accept-response) - (while (progn - (goto-char last-point) - ;; Count replies. - (while (re-search-forward "^[0-9]" nil t) - (setq received (1+ received))) - (setq last-point (point)) - (< received count)) - (nntp-accept-response))))) + (when (or (null groups) ;All requests have been sent. + (zerop (% count nntp-maximum-request))) + (nntp-accept-response) + (while (progn + (goto-char last-point) + ;; Count replies. + (while (re-search-forward "^[0-9]" nil t) + (setq received (1+ received))) + (setq last-point (point)) + (< received count)) + (nntp-accept-response)))) ;; Wait for the reply from the final command. - (if nntp-server-list-active-group - (progn - (goto-char (point-max)) - (re-search-backward "^[0-9]" nil t) - (if (looking-at "^[23]") - (while (progn - (goto-char (- (point-max) 3)) - (not (looking-at "^\\.\r?\n"))) - (nntp-accept-response))))) + (when nntp-server-list-active-group + (goto-char (point-max)) + (re-search-backward "^[0-9]" nil t) + (when (looking-at "^[23]") + (while (progn + (goto-char (- (point-max) 3)) + (not (looking-at "^\\.\r?\n"))) + (nntp-accept-response)))) ;; Now all replies are received. We remove CRs. (goto-char (point-min)) (while (search-forward "\r" nil t) (replace-match "" t t)) - (if nntp-server-list-active-group - (progn - ;; We have read active entries, so we just delete the - ;; superfluous gunk. - (goto-char (point-min)) - (while (re-search-forward "^[.2-5]" nil t) - (delete-region (match-beginning 0) - (progn (forward-line 1) (point)))) - 'active) - 'group)))) + (if (not nntp-server-list-active-group) + 'group + ;; We have read active entries, so we just delete the + ;; superfluos gunk. + (goto-char (point-min)) + (while (re-search-forward "^[.2-5]" nil t) + (delete-region (match-beginning 0) + (progn (forward-line 1) (point)))) + 'active)))) -(defun nntp-open-server (server &optional defs connectionless) +(deffoo nntp-open-server (server &optional defs connectionless) "Open the virtual server SERVER. If CONNECTIONLESS is non-nil, don't attempt to connect to any physical servers." - (nnheader-init-server-buffer) + ;; Called with just a port number as the defs. + (when (or (stringp (car defs)) + (numberp (car defs))) + (setq defs `((nntp-port-number ,(car defs))))) + (unless (assq 'nntp-address defs) + (setq defs (append defs `((nntp-address ,server))))) + (nnoo-change-server 'nntp server defs) (if (nntp-server-opened server) t - (if (or (stringp (car defs)) - (numberp (car defs))) - (setq defs (cons (list 'nntp-port-number (car defs)) (cdr defs)))) - (or (assq 'nntp-address defs) - (setq defs (append defs (list (list 'nntp-address server))))) - (if (and nntp-current-server - (not (equal server nntp-current-server))) - (setq nntp-server-alist - (cons (list nntp-current-server - (nnheader-save-variables nntp-server-variables)) - nntp-server-alist))) - (let ((state (assoc server nntp-server-alist))) - (if state - (progn - (nnheader-restore-variables (nth 1 state)) - (setq nntp-server-alist (delq state nntp-server-alist))) - (nnheader-set-init-variables nntp-server-variables defs))) - (setq nntp-current-server server) - ;; We have now changed to the proper virtual server. We then - ;; check that the physical server is opened. - (if (or (nntp-server-opened server) - connectionless) - t - (if (member nntp-address nntp-timeout-servers) - nil - ;; We open a connection to the physical nntp server. - (run-hooks 'nntp-prepare-server-hook) - (nntp-open-server-semi-internal nntp-address nntp-port-number))))) - -(defun nntp-close-server (&optional server) + (or (nntp-server-opened server) + connectionless + (prog2 + (run-hooks 'nntp-prepare-server-hook) + (nntp-open-server-semi-internal nntp-address nntp-port-number) + (nnheader-insert ""))))) + +(deffoo nntp-close-server (&optional server) "Close connection to SERVER." (nntp-possibly-change-server nil server t) (unwind-protect @@ -383,41 +366,49 @@ servers." (process-sentinel nntp-server-process)) (set-process-sentinel nntp-server-process nil)) ;; We cannot send QUIT command unless the process is running. - (if (nntp-server-opened) - (nntp-send-command nil "QUIT"))) - (nntp-close-server-internal server) - (setq nntp-timeout-servers (delete server nntp-timeout-servers)))) - -(defalias 'nntp-request-quit (symbol-function 'nntp-close-server)) + (when (nntp-server-opened server) + (nntp-send-command nil "QUIT") + ;; Give the QUIT time to arrive. + (sleep-for 1))) + (nntp-close-server-internal server))) -(defun nntp-request-close () +(deffoo nntp-request-close () "Close all server connections." (let (proc) (while nntp-opened-connections - (setq proc (pop nntp-opened-connections)) - (and proc (delete-process proc))) + (when (setq proc (pop nntp-opened-connections)) + ;; Un-set default sentinel function before closing connection. + (when (eq 'nntp-default-sentinel (process-sentinel proc)) + (set-process-sentinel proc nil)) + (condition-case () + (process-send-string proc (concat "QUIT" nntp-end-of-line)) + (error nil)) + ;; Give the QUIT time to reach the server before we close + ;; down the process. + (sleep-for 1) + (delete-process proc))) (and nntp-async-buffer - (get-buffer nntp-async-buffer) + (buffer-name nntp-async-buffer) (kill-buffer nntp-async-buffer)) - (while nntp-server-alist - (and (setq proc (nth 1 (assq 'nntp-async-buffer - (car nntp-server-alist)))) - (buffer-name proc) - (kill-buffer proc)) - (setq nntp-server-alist (cdr nntp-server-alist))) - (setq nntp-current-server nil - nntp-timeout-servers nil - nntp-async-group-alist nil))) - -(defun nntp-server-opened (&optional server) + (let ((alist (cddr (assq 'nntp nnoo-state-alist))) + entry) + (while (setq entry (pop alist)) + (and (setq proc (cdr (assq 'nntp-async-buffer entry))) + (buffer-name proc) + (kill-buffer proc)))) + (nnoo-close-server 'nntp) + (setq nntp-async-group-alist nil + nntp-async-articles nil))) + +(deffoo nntp-server-opened (&optional server) "Say whether a connection to SERVER has been opened." - (and (equal server nntp-current-server) + (and (nnoo-current-server-p 'nntp server) nntp-server-buffer (buffer-name nntp-server-buffer) nntp-server-process (memq (process-status nntp-server-process) '(open run)))) -(defun nntp-status-message (&optional server) +(deffoo nntp-status-message (&optional server) "Return server status as a string." (if (and nntp-status-string ;; NNN MESSAGE @@ -427,22 +418,22 @@ servers." ;; Empty message if nothing. (or nntp-status-string ""))) -(defun nntp-request-article (id &optional newsgroup server buffer) - "Request article ID (message-id or number)." - (nntp-possibly-change-server newsgroup server) +(deffoo nntp-request-article (id &optional group server buffer) + "Request article ID (Message-ID or number)." + (nntp-possibly-change-server group server) (let (found) ;; First we see whether we can get the article from the async buffer. - (if (and (numberp id) - nntp-async-articles - (memq id nntp-async-fetched)) - (save-excursion - (set-buffer nntp-async-buffer) - (let ((opoint (point)) - (art (if (numberp id) (int-to-string id) id)) - beg end) - (if (and (or (re-search-forward (concat "^2.. +" art) nil t) + (when (and (numberp id) + nntp-async-articles + (memq id nntp-async-fetched)) + (save-excursion + (set-buffer nntp-async-buffer) + (let ((opoint (point)) + (art (if (numberp id) (int-to-string id) id)) + beg end) + (when (and (or (re-search-forward (concat "^2.. +" art) nil t) (progn (goto-char (point-min)) (re-search-forward (concat "^2.. +" art) opoint t))) @@ -450,115 +441,134 @@ servers." (beginning-of-line) (setq beg (point) end (re-search-forward "^\\.\r?\n" nil t)))) - (progn - (setq found t) - (save-excursion - (set-buffer (or buffer nntp-server-buffer)) - (erase-buffer) - (insert-buffer-substring nntp-async-buffer beg end) - (let ((nntp-server-buffer (current-buffer))) - (nntp-decode-text))) - (delete-region beg end) - (and nntp-async-articles - (nntp-async-fetch-articles id))))))) + (setq found t) + (save-excursion + (set-buffer (or buffer nntp-server-buffer)) + (erase-buffer) + (insert-buffer-substring nntp-async-buffer beg end) + (let ((nntp-server-buffer (current-buffer))) + (nntp-decode-text))) + (delete-region beg end) + (when nntp-async-articles + (nntp-async-fetch-articles id)))))) (if found - t + id ;; The article was not in the async buffer, so we fetch it now. (unwind-protect (progn (if buffer (set-process-buffer nntp-server-process buffer)) (let ((nntp-server-buffer (or buffer nntp-server-buffer)) (art (or (and (numberp id) (int-to-string id)) id))) - ;; If NEmacs, end of message may look like: "\256\215" (".^M") (prog1 - (nntp-send-command "^\\.\r?\n" "ARTICLE" art) + (and (nntp-send-command + ;; A bit odd regexp to ensure working over rlogin. + "^\\.\r?\n" "ARTICLE" art) + (if (numberp id) + (cons nntp-current-group id) + ;; We find out what the article number was. + (nntp-find-group-and-number))) (nntp-decode-text) (and nntp-async-articles (nntp-async-fetch-articles id))))) - (if buffer (set-process-buffer - nntp-server-process nntp-server-buffer)))))) + (when buffer + (set-process-buffer nntp-server-process nntp-server-buffer)))))) -(defun nntp-request-body (id &optional newsgroup server) - "Request body of article ID (message-id or number)." - (nntp-possibly-change-server newsgroup server) +(deffoo nntp-request-body (id &optional group server) + "Request body of article ID (Message-ID or number)." + (nntp-possibly-change-server group server) (prog1 ;; If NEmacs, end of message may look like: "\256\215" (".^M") (nntp-send-command "^\\.\r?\n" "BODY" (or (and (numberp id) (int-to-string id)) id)) (nntp-decode-text))) -(defun nntp-request-head (id &optional newsgroup server) - "Request head of article ID (message-id or number)." - (nntp-possibly-change-server newsgroup server) +(deffoo nntp-request-head (id &optional group server) + "Request head of article ID (Message-ID or number)." + (nntp-possibly-change-server group server) (prog1 - (nntp-send-command - "^\\.\r?\n" "HEAD" (or (and (numberp id) (int-to-string id)) id)) - (nntp-decode-text))) + (when (nntp-send-command + "^\\.\r?\n" "HEAD" (if (numberp id) (int-to-string id) id)) + (if (numberp id) id + ;; We find out what the article number was. + (nntp-find-group-and-number))) + (nntp-decode-text) + (save-excursion + (set-buffer nntp-server-buffer) + (nnheader-fold-continuation-lines)))) -(defun nntp-request-stat (id &optional newsgroup server) - "Request STAT of article ID (message-id or number)." - (nntp-possibly-change-server newsgroup server) +(deffoo nntp-request-stat (id &optional group server) + "Request STAT of article ID (Message-ID or number)." + (nntp-possibly-change-server group server) (nntp-send-command "^[23].*\r?\n" "STAT" (or (and (numberp id) (int-to-string id)) id))) -(defun nntp-request-group (group &optional server dont-check) +(deffoo nntp-request-type (group &optional article) + 'news) + +(deffoo nntp-request-group (group &optional server dont-check) "Select GROUP." - (nntp-send-command "^.*\r?\n" "GROUP" group) - (setq nntp-current-group group) - (save-excursion - (set-buffer nntp-server-buffer) - (goto-char (point-min)) - (looking-at "[23]"))) - -(defun nntp-request-asynchronous (group &optional server articles) - (and nntp-async-articles (nntp-async-request-group group)) - (and - nntp-async-number - (if (not (or (nntp-async-server-opened) - (nntp-async-open-server))) - (progn - (message "Can't open second connection to %s" nntp-address) - (ding) - (setq nntp-async-articles nil) - (sit-for 2)) - (setq nntp-async-articles articles) - (setq nntp-async-fetched nil) - (save-excursion - (set-buffer nntp-async-buffer) - (erase-buffer)) - (nntp-async-send-strings "GROUP" group) - t))) - -(defun nntp-list-active-group (group &optional server) + (nntp-possibly-change-server nil server) + (setq nntp-current-group + (when (nntp-send-command "^2.*\r?\n" "GROUP" group) + group))) + +(deffoo nntp-request-asynchronous (group &optional server articles) + "Enable pre-fetch in GROUP." + (when nntp-async-articles + (nntp-async-request-group group)) + (when nntp-async-number + (if (not (or (nntp-async-server-opened) + (nntp-async-open-server))) + ;; Couldn't open the second connection + (progn + (message "Can't open second connection to %s" nntp-address) + (ding) + (setq nntp-async-articles nil) + (sit-for 2)) + ;; We opened the second connection (or it was opened already). + (setq nntp-async-articles articles) + (setq nntp-async-fetched nil) + ;; Clear any old data. + (save-excursion + (set-buffer nntp-async-buffer) + (erase-buffer)) + ;; Select the correct current group on this server. + (nntp-async-send-strings "GROUP" group) + t))) + +(deffoo nntp-list-active-group (group &optional server) + "Return the active info on GROUP (which can be a regexp." + (nntp-possibly-change-server group server) (nntp-send-command "^.*\r?\n" "LIST ACTIVE" group)) -(defun nntp-request-group-description (group &optional server) - "Get description of GROUP." +(deffoo nntp-request-group-description (group &optional server) + "Get the description of GROUP." (nntp-possibly-change-server nil server) (prog1 (nntp-send-command "^.*\r?\n" "XGTITLE" group) (nntp-decode-text))) -(defun nntp-close-group (group &optional server) +(deffoo nntp-close-group (group &optional server) + "Close GROUP." (setq nntp-current-group nil) t) -(defun nntp-request-list (&optional server) - "List active groups." +(deffoo nntp-request-list (&optional server) + "List all active groups." (nntp-possibly-change-server nil server) (prog1 (nntp-send-command "^\\.\r?\n" "LIST") (nntp-decode-text))) -(defun nntp-request-list-newsgroups (&optional server) - "List groups." +(deffoo nntp-request-list-newsgroups (&optional server) + "Get descriptions on all groups on SERVER." (nntp-possibly-change-server nil server) (prog1 (nntp-send-command "^\\.\r?\n" "LIST NEWSGROUPS") (nntp-decode-text))) -(defun nntp-request-newgroups (date &optional server) - "List new groups." +(deffoo nntp-request-newgroups (date &optional server) + "List groups that have arrived since DATE." (nntp-possibly-change-server nil server) (let* ((date (timezone-parse-date date)) (time-string @@ -571,120 +581,33 @@ servers." (nntp-send-command "^\\.\r?\n" "NEWGROUPS" time-string) (nntp-decode-text)))) -(defun nntp-request-list-distributions (&optional server) +(deffoo nntp-request-list-distributions (&optional server) "List distributions." (nntp-possibly-change-server nil server) (prog1 (nntp-send-command "^\\.\r?\n" "LIST DISTRIBUTIONS") (nntp-decode-text))) -(defun nntp-request-last (&optional newsgroup server) +(deffoo nntp-request-last (&optional group server) "Decrease the current article pointer." - (nntp-possibly-change-server newsgroup server) + (nntp-possibly-change-server group server) (nntp-send-command "^[23].*\r?\n" "LAST")) -(defun nntp-request-next (&optional newsgroup server) +(deffoo nntp-request-next (&optional group server) "Advance the current article pointer." - (nntp-possibly-change-server newsgroup server) + (nntp-possibly-change-server group server) (nntp-send-command "^[23].*\r?\n" "NEXT")) -(defun nntp-request-post (&optional server) +(deffoo nntp-request-post (&optional server) "Post the current buffer." (nntp-possibly-change-server nil server) - (save-excursion - (set-buffer nntp-server-buffer) - (erase-buffer)) - (if (nntp-send-command "^[23].*\r?\n" "POST") - (progn - (save-excursion - (set-buffer nntp-server-buffer) - (erase-buffer)) - (nntp-encode-text) - (nntp-send-region-to-server (point-min) (point-max)) - ;; 1.2a NNTP's post command is buggy. "^M" (\r) is not - ;; appended to end of the status message. - (nntp-wait-for-response "^[23].*\n")))) - -(defun nntp-request-post-buffer - (post group subject header article-buffer info follow-to respect-poster) - "Request a buffer suitable for composing an article. -If POST, this is an original article; otherwise it's a followup. -GROUP is the group to be posted to, the article should have subject -SUBJECT. HEADER is a Gnus header vector. ARTICLE-BUFFER contains the -article being followed up. INFO is a Gnus info list. If FOLLOW-TO, -post to this group instead. If RESPECT-POSTER, heed the special -\"poster\" value of the Followup-to header." - (if (assq 'to-address (nth 5 info)) - (nnmail-request-post-buffer - post group subject header article-buffer info follow-to respect-poster) - (let ((mail-default-headers - (or nntp-news-default-headers mail-default-headers)) - from date to followup-to newsgroups message-of - references distribution message-id) - (save-excursion - (set-buffer (get-buffer-create "*post-news*")) - (news-reply-mode) - (if (and (buffer-modified-p) - (> (buffer-size) 0) - (not (y-or-n-p "Unsent article being composed; erase it? "))) - () - (erase-buffer) - (if post - (news-setup nil subject nil group nil) - (save-excursion - (set-buffer article-buffer) - (goto-char (point-min)) - (narrow-to-region (point-min) - (progn (search-forward "\n\n") (point))) - (setq from (mail-header-from header)) - (setq date (mail-header-date header)) - (and from - (let ((stop-pos - (string-match " *at \\| *@ \\| *(\\| *<" from))) - (setq - message-of - (concat (if stop-pos (substring from 0 stop-pos) from) - "'s message of " date)))) - (setq subject (or subject (mail-header-subject header))) - (or (string-match "^[Rr][Ee]:" subject) - (setq subject (concat "Re: " subject))) - (setq followup-to (mail-fetch-field "followup-to")) - (if (or (null respect-poster) ;Ignore followup-to: field. - (string-equal "" followup-to) ;Bogus header. - (string-equal "poster" followup-to);Poster - (and (eq respect-poster 'ask) - followup-to - (not (y-or-n-p (concat "Followup to " - followup-to "? "))))) - (setq followup-to nil)) - (setq newsgroups - (or follow-to followup-to (mail-fetch-field "newsgroups"))) - (setq references (mail-header-references header)) - (setq distribution (mail-fetch-field "distribution")) - ;; Remove bogus distribution. - (and (stringp distribution) - (string-match "world" distribution) - (setq distribution nil)) - (setq message-id (mail-header-id header)) - (widen)) - (setq news-reply-yank-from from) - (setq news-reply-yank-message-id message-id) - (news-setup to subject message-of - (if (stringp newsgroups) newsgroups "") - article-buffer) - (if (and newsgroups (listp newsgroups)) - (progn - (goto-char (point-min)) - (while newsgroups - (insert (car (car newsgroups)) ": " - (cdr (car newsgroups)) "\n") - (setq newsgroups (cdr newsgroups))))) - (nnheader-insert-references references message-id) - (if distribution - (progn - (mail-position-on-field "Distribution") - (insert distribution))))) - (current-buffer))))) + (when (nntp-send-command "^[23].*\r?\n" "POST") + (nnheader-insert "") + (nntp-encode-text) + (nntp-send-region-to-server (point-min) (point-max)) + ;; 1.2a NNTP's post command is buggy. "^M" (\r) is not + ;; appended to end of the status message. + (nntp-wait-for-response "^[23].*\n"))) ;;; Internal functions. @@ -695,6 +618,15 @@ It will make innd servers spawn an nnrpd process to allow actual article reading." (nntp-send-command "^.*\r?\n" "MODE READER")) +(defun nntp-send-nosy-authinfo () + "Send the AUTHINFO to the nntp server. +This function is supposed to be called from `nntp-server-opened-hook'. +It will prompt for a password." + (nntp-send-command "^.*\r?\n" "AUTHINFO USER" + (read-string "NNTP user name: ")) + (nntp-send-command "^.*\r?\n" "AUTHINFO PASS" + (read-string "NNTP password: "))) + (defun nntp-send-authinfo () "Send the AUTHINFO to the nntp server. This function is supposed to be called from `nntp-server-opened-hook'. @@ -707,20 +639,22 @@ It will prompt for a password." "Send the AUTHINFO to the nntp server. This function is supposed to be called from `nntp-server-opened-hook'. It will prompt for a password." - (and (file-exists-p "~/.nntp-authinfo") - (save-excursion - (set-buffer (get-buffer-create " *tull*")) - (insert-file-contents "~/.nntp-authinfo") - (goto-char (point-min)) - (nntp-send-command "^.*\r?\n" "AUTHINFO USER" (user-login-name)) - (nntp-send-command "^.*\r?\n" "AUTHINFO PASS" - (buffer-substring (point) - (progn (end-of-line) (point)))) - (kill-buffer (current-buffer))))) + (when (file-exists-p "~/.nntp-authinfo") + (save-excursion + (set-buffer (get-buffer-create " *authinfo*")) + (buffer-disable-undo (current-buffer)) + (erase-buffer) + (insert-file-contents "~/.nntp-authinfo") + (goto-char (point-min)) + (nntp-send-command "^.*\r?\n" "AUTHINFO USER" (user-login-name)) + (nntp-send-command + "^.*\r?\n" "AUTHINFO PASS" + (buffer-substring (point) (progn (end-of-line) (point)))) + (kill-buffer (current-buffer))))) (defun nntp-default-sentinel (proc status) "Default sentinel function for NNTP server process." - (let ((servers nntp-server-alist) + (let ((servers (cddr (assq 'nntp nnoo-state-alist))) server) ;; Go through the alist of server names and find the name of the ;; server that the process that sent the signal is connected to. @@ -728,23 +662,26 @@ It will prompt for a password." (if (equal proc nntp-server-process) (setq server nntp-address) (while (and servers - (not (equal proc (nth 1 (assq 'nntp-server-process - (car servers)))))) + (not (equal proc (cdr (assq 'nntp-server-process + (car servers)))))) (setq servers (cdr servers))) - (setq server (car (car servers)))) - (and server - (progn - (message "nntp: Connection closed to server %s" server) - (ding))))) + (setq server (caar servers))) + (when (and server + nntp-warn-about-losing-connection) + (nnheader-message 3 "nntp: Connection closed to server %s" server) + (setq nntp-current-group "") + (ding)))) (defun nntp-kill-connection (server) - (let ((proc (nth 1 (assq 'nntp-server-process - (assoc server nntp-server-alist))))) - (and proc (delete-process (process-name proc))) + "Choke the connection to SERVER." + (let ((proc (cdr (assq 'nntp-server-process + (assoc server (cddr + (assq 'nntp nnoo-state-alist))))))) + (when proc + (delete-process (process-name proc))) (nntp-close-server server) - (setq nntp-timeout-servers (cons server nntp-timeout-servers)) - (setq nntp-status-string - (message "Connection timed out to server %s." server)) + (nnheader-report + 'nntp (message "Connection timed out to server %s" server)) (ding) (sit-for 1))) @@ -762,19 +699,15 @@ It will prompt for a password." (goto-char (point-max)) (or (bolp) (insert "\n")) ;; Delete status line. - (goto-char (point-min)) - (delete-region (point) (progn (forward-line 1) (point))) - ;; Delete `^M' at the end of lines. - (while (not (eobp)) - (end-of-line) - (and (= (preceding-char) ?\r) - (delete-char -1)) - (forward-line 1)) + (delete-region (goto-char (point-min)) (progn (forward-line 1) (point))) + ;; Delete `^M's. + (while (search-forward "\r" nil t) + (replace-match "" t t)) ;; Delete `.' at end of the buffer (end of text mark). (goto-char (point-max)) (forward-line -1) - (if (looking-at "^\\.\n") - (delete-region (point) (progn (forward-line 1) (point)))) + (when (looking-at "^\\.\n") + (delete-region (point) (progn (forward-line 1) (point)))) ;; Replace `..' at beginning of line with `.'. (goto-char (point-min)) ;; (replace-regexp "^\\.\\." ".") @@ -786,24 +719,72 @@ It will prompt for a password." 1. Insert `.' at beginning of line. 2. Insert `.' at end of buffer (end of text mark)." (save-excursion - ;; Insert newline at end of buffer. - (goto-char (point-max)) - (or (bolp) (insert "\n")) ;; Replace `.' at beginning of line with `..'. (goto-char (point-min)) - ;; (replace-regexp "^\\." "..") (while (search-forward "\n." nil t) (insert ".")) - ;; Insert `.' at end of buffer (end of text mark). (goto-char (point-max)) - (insert ".\r\n"))) + ;; Insert newline at end of buffer. + (or (bolp) (insert "\n")) + ;; Insert `.' at end of buffer (end of text mark). + (insert "." nntp-end-of-line))) ;;; -;;; Synchronous Communication with NNTP Server. +;;; Synchronous Communication with NNTP servers. ;;; +(defvar nntp-retry-command) + (defun nntp-send-command (response cmd &rest args) + "Wait for server RESPONSE after sending CMD and optional ARGS to server." + (let ((timer + (and nntp-command-timeout + (nnheader-run-at-time + nntp-command-timeout nil 'nntp-kill-command + (nnoo-current-server 'nntp)))) + (nntp-retry-command t) + result) + (unwind-protect + (save-excursion + (while nntp-retry-command + (setq nntp-retry-command nil) + ;; Clear communication buffer. + (set-buffer nntp-server-buffer) + (widen) + (erase-buffer) + (if nntp-retry-on-break + (condition-case () + (progn + (apply 'nntp-send-strings-to-server cmd args) + (setq result + (if response + (nntp-wait-for-response response) + t))) + (quit (setq nntp-retry-command t))) + (apply 'nntp-send-strings-to-server cmd args) + (setq result + (if response + (nntp-wait-for-response response) + t)))) + result) + (when timer + (nnheader-cancel-timer timer))))) + +(defun nntp-kill-command (server) + "Kill and restart the connection to SERVER." + (let ((proc (cdr (assq + 'nntp-server-process + (assoc server (cddr (assq 'nntp nnoo-state-alist))))))) + (when proc + (delete-process (process-name proc))) + (nntp-close-server server) + (nntp-open-server server) + (when nntp-current-group + (nntp-request-group nntp-current-group)) + (setq nntp-retry-command t))) + +(defun nntp-send-command-old (response cmd &rest args) "Wait for server RESPONSE after sending CMD and optional ARGS to server." (save-excursion ;; Clear communication buffer. @@ -854,31 +835,28 @@ It will prompt for a password." ;; Save status message. (end-of-line) (setq nntp-status-string - (buffer-substring (point-min) (point))) - (if status - (progn - (setq wait t) - (while wait - (goto-char (point-max)) - (forward-line -1) ;(beginning-of-line) - ;;(message (buffer-substring - ;; (point) - ;; (save-excursion (end-of-line) (point)))) - (if (looking-at regexp) - (setq wait nil) - (if nntp-debug-read - (let ((newnum (/ (buffer-size) dotsize))) - (if (not (= dotnum newnum)) - (progn - (setq dotnum newnum) - (message "NNTP: Reading %s" - (make-string dotnum ?.)))))) - (nntp-accept-response))) - ;; Remove "...". - (if (and nntp-debug-read (> dotnum 0)) - (message "")) - ;; Successfully received server response. - t))))) + (nnheader-replace-chars-in-string + (buffer-substring (point-min) (point)) ?\r ? )) + (when status + (setq wait t) + (while wait + (goto-char (point-max)) + (if (bolp) (forward-line -1) (beginning-of-line)) + (if (looking-at regexp) + (setq wait nil) + (when nntp-debug-read + (let ((newnum (/ (buffer-size) dotsize)) + (message-log-max nil)) + (unless (= dotnum newnum) + (setq dotnum newnum) + (nnheader-message 7 "NNTP: Reading %s" + (make-string dotnum ?.))))) + (nntp-accept-response))) + ;; Remove "...". + (when (and nntp-debug-read (> dotnum 0)) + (message "")) + ;; Successfully received server response. + t)))) @@ -886,7 +864,46 @@ It will prompt for a password." ;;; Low-Level Interface to NNTP Server. ;;; -(defun nntp-retrieve-headers-with-xover (sequence) +(defun nntp-find-group-and-number () + (save-excursion + (save-restriction + (set-buffer nntp-server-buffer) + (narrow-to-region (goto-char (point-min)) + (or (search-forward "\n\n" nil t) (point-max))) + (goto-char (point-min)) + ;; We first find the number by looking at the status line. + (let ((number (and (looking-at "2[0-9][0-9] +\\([0-9]+\\) ") + (string-to-int + (buffer-substring (match-beginning 1) + (match-end 1))))) + group newsgroups xref) + (and number (zerop number) (setq number nil)) + ;; Then we find the group name. + (setq group + (cond + ;; If there is only one group in the Newsgroups header, + ;; then it seems quite likely that this article comes + ;; from that group, I'd say. + ((and (setq newsgroups (mail-fetch-field "newsgroups")) + (not (string-match "," newsgroups))) + newsgroups) + ;; If there is more than one group in the Newsgroups + ;; header, then the Xref header should be filled out. + ;; We hazard a guess that the group that has this + ;; article number in the Xref header is the one we are + ;; looking for. This might very well be wrong if this + ;; article happens to have the same number in several + ;; groups, but that's life. + ((and (setq xref (mail-fetch-field "xref")) + number + (string-match (format "\\([^ :]+\\):%d" number) xref)) + (substring xref (match-beginning 1) (match-end 1))) + (t ""))) + (when (string-match "\r" group) + (setq group (substring group 0 (match-beginning 0)))) + (cons group number))))) + +(defun nntp-retrieve-headers-with-xover (articles &optional fetch-old) (erase-buffer) (cond @@ -895,19 +912,25 @@ It will prompt for a password." nil) ;; We don't care about gaps. - ((not nntp-nov-gap) + ((or (not nntp-nov-gap) + fetch-old) (nntp-send-xover-command - (car sequence) (nntp-last-element sequence) 'wait) + (if fetch-old + (if (numberp fetch-old) + (max 1 (- (car articles) fetch-old)) + 1) + (car articles)) + (nntp-last-element articles) 'wait) (goto-char (point-min)) - (if (looking-at "[1-5][0-9][0-9] ") - (delete-region (point) (progn (forward-line 1) (point)))) + (when (looking-at "[1-5][0-9][0-9] ") + (delete-region (point) (progn (forward-line 1) (point)))) (while (search-forward "\r" nil t) (replace-match "" t t)) (goto-char (point-max)) (forward-line -1) - (if (looking-at "\\.") - (delete-region (point) (progn (forward-line 1) (point))))) + (when (looking-at "\\.") + (delete-region (point) (progn (forward-line 1) (point))))) ;; We do it the hard way. For each gap, an XOVER command is sent ;; to the server. We do not wait for a reply from the server, we @@ -923,51 +946,48 @@ It will prompt for a password." ;; We have to check `nntp-server-xover'. If it gets set to nil, ;; that means that the server does not understand XOVER, but we ;; won't know that until we try. - (while (and nntp-server-xover sequence) - (setq first (car sequence)) + (while (and nntp-server-xover articles) + (setq first (car articles)) ;; Search forward until we find a gap, or until we run out of ;; articles. - (while (and (cdr sequence) - (< (- (nth 1 sequence) (car sequence)) nntp-nov-gap)) - (setq sequence (cdr sequence))) + (while (and (cdr articles) + (< (- (nth 1 articles) (car articles)) nntp-nov-gap)) + (setq articles (cdr articles))) - (if (not (nntp-send-xover-command first (car sequence))) - () - (setq sequence (cdr sequence) + (when (nntp-send-xover-command first (car articles)) + (setq articles (cdr articles) count (1+ count)) ;; Every 400 requests we have to read the stream in ;; order to avoid deadlocks. - (if (or (null sequence) ;All requests have been sent. - (zerop (% count nntp-maximum-request))) - (progn - (accept-process-output) - ;; On some Emacs versions the preceding function has - ;; a tendency to change the buffer. Perhaps. It's - ;; quite difficult to reproduce, because it only - ;; seems to happen once in a blue moon. - (set-buffer buf) - (while (progn - (goto-char last-point) - ;; Count replies. - (while (re-search-forward "^[0-9][0-9][0-9] " nil t) - (setq received (1+ received))) - (setq last-point (point)) - (< received count)) - (accept-process-output) - (set-buffer buf)))))) - - (if (not nntp-server-xover) - () + (when (or (null articles) ;All requests have been sent. + (zerop (% count nntp-maximum-request))) + (accept-process-output) + ;; On some Emacs versions the preceding function has + ;; a tendency to change the buffer. Perhaps. It's + ;; quite difficult to reproduce, because it only + ;; seems to happen once in a blue moon. + (set-buffer buf) + (while (progn + (goto-char last-point) + ;; Count replies. + (while (re-search-forward "^[0-9][0-9][0-9] " nil t) + (setq received (1+ received))) + (setq last-point (point)) + (< received count)) + (accept-process-output) + (set-buffer buf))))) + + (when nntp-server-xover ;; Wait for the reply from the final command. (goto-char (point-max)) (re-search-backward "^[0-9][0-9][0-9] " nil t) - (if (looking-at "^[23]") - (while (progn - (goto-char (point-max)) - (forward-line -1) - (not (looking-at "^\\.\r?\n"))) - (nntp-accept-response))) + (when (looking-at "^[23]") + (while (progn + (goto-char (point-max)) + (forward-line -1) + (not (looking-at "^\\.\r?\n"))) + (nntp-accept-response))) ;; We remove any "." lines and status lines. (goto-char (point-min)) @@ -979,16 +999,15 @@ It will prompt for a password." nntp-server-xover) (defun nntp-send-xover-command (beg end &optional wait-for-reply) - (let ((range (format "%d-%d" beg end))) + "Send the XOVER command to the server." + (let ((range (format "%d-%d" (or beg 1) (or end beg 1)))) (if (stringp nntp-server-xover) ;; If `nntp-server-xover' is a string, then we just send this ;; command. (if wait-for-reply (nntp-send-command "^\\.\r?\n" nntp-server-xover range) ;; We do not wait for the reply. - (progn - (nntp-send-strings-to-server nntp-server-xover range) - t)) + (nntp-send-strings-to-server nntp-server-xover range)) (let ((commands nntp-xover-commands)) ;; `nntp-xover-commands' is a list of possible XOVER commands. ;; We try them all until we get at positive response. @@ -1007,31 +1026,30 @@ It will prompt for a password." (setq nntp-server-xover (car commands)))) (setq commands (cdr commands))) ;; If none of the commands worked, we disable XOVER. - (if (eq nntp-server-xover 'try) - (save-excursion - (set-buffer nntp-server-buffer) - (erase-buffer) - (setq nntp-server-xover nil))) + (when (eq nntp-server-xover 'try) + (save-excursion + (set-buffer nntp-server-buffer) + (erase-buffer) + (setq nntp-server-xover nil))) nntp-server-xover)))) (defun nntp-send-strings-to-server (&rest strings) - "Send list of STRINGS to news server as command and its arguments." - (let ((cmd (concat (mapconcat 'identity strings " ") "\r\n"))) + "Send STRINGS to the server." + (let ((cmd (concat (mapconcat 'identity strings " ") nntp-end-of-line))) ;; We open the nntp server if it is down. - (or (nntp-server-opened nntp-current-server) - (nntp-open-server nntp-current-server) - (error "%s" (nntp-status-message))) + (or (nntp-server-opened (nnoo-current-server 'nntp)) + (nntp-open-server (nnoo-current-server 'nntp)) + (error (nntp-status-message))) ;; Send the strings. - (process-send-string nntp-server-process cmd))) + (process-send-string nntp-server-process cmd) + t)) (defun nntp-send-region-to-server (begin end) "Send the current buffer region (from BEGIN to END) to the server." (save-excursion (let ((cur (current-buffer))) ;; Copy the buffer over to the send buffer. - (set-buffer (get-buffer-create " *nntp send*")) - (buffer-disable-undo (current-buffer)) - (erase-buffer) + (nnheader-set-temp-buffer " *nntp send*") (insert-buffer-substring cur begin end) (save-excursion (set-buffer cur) @@ -1040,7 +1058,8 @@ It will prompt for a password." ;; large, so we send it piecemeal. (let ((last (point-min)) (size 100)) ;Size of text sent at once. - (while (/= last (point-max)) + (while (and (/= last (point-max)) + (memq (process-status nntp-server-process) '(open run))) (process-send-region nntp-server-process last (setq last (min (+ last size) (point-max)))) @@ -1052,25 +1071,17 @@ It will prompt for a password." "Open SERVER. If SERVER is nil, use value of environment variable `NNTPSERVER'. If SERVICE, this this as the port number." + (nnheader-insert "") (let ((server (or server (getenv "NNTPSERVER"))) (status nil) (timer (and nntp-connection-timeout - (cond - ((fboundp 'run-at-time) - (run-at-time nntp-connection-timeout - nil 'nntp-kill-connection server)) - ((fboundp 'start-itimer) - ;; Not sure if this will work or not, only one way to - ;; find out - (eval '(start-itimer "nntp-timeout" - (lambda () - (nntp-kill-connection server)) - nntp-connection-timeout nil))))))) + (nnheader-run-at-time nntp-connection-timeout + nil 'nntp-kill-connection server)))) (save-excursion (set-buffer nntp-server-buffer) (setq nntp-status-string "") - (message "nntp: Connecting to server on %s..." server) + (nnheader-message 5 "nntp: Connecting to server on %s..." nntp-address) (cond ((and server (nntp-open-server-internal server service)) (setq nntp-address server) (setq status @@ -1078,60 +1089,102 @@ If SERVICE, this this as the port number." (nntp-wait-for-response "^[23].*\r?\n" 'slow) (error nil) (quit nil))) - (or status (nntp-close-server-internal server)) - (and nntp-server-process - (progn - (set-process-sentinel - nntp-server-process 'nntp-default-sentinel) - ;; You can send commands at startup like AUTHINFO here. - ;; Added by Hallvard B Furuseth - (run-hooks 'nntp-server-opened-hook)))) + (unless status + (nntp-close-server-internal server) + (nnheader-report + 'nntp "Couldn't open connection to %s" + (if (and nntp-address + (not (equal nntp-address ""))) + nntp-address server))) + (when nntp-server-process + (set-process-sentinel + nntp-server-process 'nntp-default-sentinel) + ;; You can send commands at startup like AUTHINFO here. + ;; Added by Hallvard B Furuseth + (run-hooks 'nntp-server-opened-hook))) ((null server) - (setq nntp-status-string "NNTP server is not specified.")) + (nnheader-report 'nntp "NNTP server is not specified.")) (t ; We couldn't open the server. - (setq nntp-status-string - (buffer-substring (point-min) (point-max))) - (setq nntp-timeout-servers (cons server nntp-timeout-servers)))) - (and timer (cancel-timer timer)) + (nnheader-report + 'nntp (buffer-substring (point-min) (point-max))))) + (when timer + (nnheader-cancel-timer timer)) (message "") - (or status - (setq nntp-current-server nil - nntp-async-number nil)) + (unless status + (nnoo-close-server 'nntp server) + (setq nntp-async-number nil)) status))) +(defvar nntp-default-directories '("~" "/tmp" "/") + "Directories to as current directory in the nntp server buffer.") + (defun nntp-open-server-internal (server &optional service) "Open connection to news server on SERVER by SERVICE (default is nntp)." (let (proc) (save-excursion - ;; Use TCP/IP stream emulation package if needed. - (or (fboundp 'open-network-stream) - (require 'tcp)) - ;; Initialize communication buffer. - (nnheader-init-server-buffer) (set-buffer nntp-server-buffer) - (if (setq proc - (condition-case nil - (funcall nntp-open-server-function server) - (error nil))) - (progn - (setq nntp-server-process proc) - ;; Suggested by Hallvard B Furuseth . - (process-kill-without-query proc) - (setq nntp-address server) - ;; It is possible to change kanji-fileio-code in this hook. - (run-hooks 'nntp-server-hook) - (push proc nntp-opened-connections) - nntp-server-process))))) + ;; Make sure we have a valid current directory for the + ;; nntp server buffer. + (unless (file-exists-p default-directory) + (let ((dirs nntp-default-directories)) + (while dirs + (when (file-exists-p (car dirs)) + (setq default-directory (car dirs) + dirs nil)) + (setq dirs (cdr dirs))))) + (cond + ((and (setq proc + (condition-case nil + (funcall nntp-open-server-function server) + (error nil))) + (memq (process-status proc) '(open run))) + (setq nntp-server-process proc) + (setq nntp-address server) + ;; Suggested by Hallvard B Furuseth . + (process-kill-without-query proc) + (run-hooks 'nntp-server-hook) + (push proc nntp-opened-connections) + (condition-case () + (nntp-read-server-type) + (error + (nnheader-report 'nntp "Couldn't open server %s" server) + (nntp-close-server))) + nntp-server-process) + (t + (nnheader-report 'nntp "Couldn't open server %s" server)))))) + +(defun nntp-read-server-type () + "Find out what the name of the server we have connected to is." + ;; Wait for the status string to arrive. + (nntp-wait-for-response "^.*\n" t) + (setq nntp-server-type (buffer-string)) + (let ((alist nntp-server-action-alist) + entry) + ;; Run server-specific commmands. + (while alist + (setq entry (pop alist)) + (when (string-match (car entry) nntp-server-type) + (if (and (listp (cadr entry)) + (not (eq 'lambda (caadr entry)))) + (eval (cadr entry)) + (funcall (cadr entry))))))) (defun nntp-open-network-stream (server) (open-network-stream "nntpd" nntp-server-buffer server nntp-port-number)) (defun nntp-open-rlogin (server) - (let ((proc (start-process "nntpd" nntp-server-buffer "rsh" server))) - (process-send-string proc (mapconcat 'identity nntp-rlogin-parameters - " ")) - (process-send-string proc "\n"))) + (let ((proc (if nntp-rlogin-user-name + (start-process + "nntpd" nntp-server-buffer "rsh" + "-l" nntp-rlogin-user-name server + (mapconcat 'identity + nntp-rlogin-parameters " ")) + (start-process + "nntpd" nntp-server-buffer "rsh" server + (mapconcat 'identity + nntp-rlogin-parameters " "))))) + proc)) (defun nntp-telnet-to-machine () (let (b) @@ -1177,9 +1230,9 @@ defining this function as macro." ;; We cannot use `accept-process-output'. ;; Fujitsu UTS requires messages during sleep-for. ;; I don't know why. - (message "NNTP: Reading...") + (nnheader-message 5 "NNTP: Reading...") (sleep-for 1) - (message "")) + (nnheader-message 5 "")) (condition-case errorcode (accept-process-output nntp-server-process 1) (error @@ -1199,15 +1252,15 @@ defining this function as macro." (defun nntp-possibly-change-server (newsgroup server &optional connectionless) "Check whether the virtual server needs changing." - (if (and server - (not (nntp-server-opened server))) - ;; This virtual server isn't open, so we (re)open it here. - (nntp-open-server server nil t)) - (if (and newsgroup - (not (equal newsgroup nntp-current-group))) - ;; Set the proper current group. - (nntp-request-group newsgroup server))) - + (when (and server + (not (nntp-server-opened server))) + ;; This virtual server isn't open, so we (re)open it here. + (nntp-open-server server nil t)) + (when (and newsgroup + (not (equal newsgroup nntp-current-group))) + ;; Set the proper current group. + (nntp-request-group newsgroup server))) + (defun nntp-try-list-active (group) (nntp-list-active-group group) (save-excursion @@ -1248,17 +1301,17 @@ defining this function as macro." nart) (while (and (>= (setq max (1- max)) 0) articles) - (or (memq (setq nart (car (car articles))) nntp-async-fetched) + (or (memq (setq nart (caar articles)) nntp-async-fetched) (progn (nntp-async-send-strings "ARTICLE " (int-to-string nart)) (setq nntp-async-fetched (cons nart nntp-async-fetched)))) (setq articles (cdr articles)))))) (defun nntp-async-send-strings (&rest strings) - (let ((cmd (concat (mapconcat 'identity strings " ") "\r\n"))) + (let ((cmd (concat (mapconcat 'identity strings " ") nntp-end-of-line))) (or (nntp-async-server-opened) (nntp-async-open-server) - (error "%s" (nntp-status-message))) + (error (nntp-status-message))) (process-send-string nntp-async-process cmd))) (defun nntp-async-request-group (group) diff --git a/lisp/nnvirtual.el b/lisp/nnvirtual.el index 76e6e563e9c..47269c0de69 100644 --- a/lisp/nnvirtual.el +++ b/lisp/nnvirtual.el @@ -1,6 +1,5 @@ ;;; nnvirtual.el --- virtual newsgroups access for Gnus - -;; Copyright (C) 1994,95 Free Software Foundation, Inc. +;; Copyright (C) 1994,95,96 Free Software Foundation, Inc. ;; Author: Lars Magne Ingebrigtsen ;; Masanobu UMEDA @@ -34,444 +33,376 @@ (require 'nntp) (require 'nnheader) (require 'gnus) +(require 'nnoo) +(eval-when-compile (require 'cl)) + +(nnoo-declare nnvirtual) + +(defvoo nnvirtual-always-rescan nil + "*If non-nil, always scan groups for unread articles when entering a group. +If this variable is nil (which is the default) and you read articles +in a component group after the virtual group has been activated, the +read articles from the component group will show up when you enter the +virtual group.") + +(defvoo nnvirtual-component-regexp nil + "*Regexp to match component groups.") -(defconst nnvirtual-version "nnvirtual 1.0" - "Version number of this version of nnvirtual.") +(defconst nnvirtual-version "nnvirtual 1.0") -(defvar nnvirtual-group-alist nil) -(defvar nnvirtual-current-group nil) -(defvar nnvirtual-current-groups nil) -(defvar nnvirtual-current-mapping nil) +(defvoo nnvirtual-current-group nil) +(defvoo nnvirtual-component-groups nil) +(defvoo nnvirtual-mapping nil) -(defvar nnvirtual-do-not-open nil) +(defvoo nnvirtual-status-string "") -(defvar nnvirtual-status-string "") +(eval-and-compile + (autoload 'gnus-cache-articles-in-group "gnus-cache")) ;;; Interface functions. -(defun nnvirtual-retrieve-headers (sequence &optional newsgroup server) - "Retrieve the headers for the articles in SEQUENCE." - (nnvirtual-possibly-change-newsgroups newsgroup server t) - (save-excursion - (set-buffer (get-buffer-create "*virtual headers*")) - (buffer-disable-undo (current-buffer)) - (erase-buffer) - (if (stringp (car sequence)) - 'headers - (let ((map nnvirtual-current-mapping) - (offset 0) - articles beg group active top article result prefix - fetched-articles group-method) - (while sequence - (while (< (car (car map)) (car sequence)) - (setq offset (car (car map))) - (setq map (cdr map))) - (setq top (car (car map))) - (setq group (nth 1 (car map))) - (setq prefix (gnus-group-real-prefix group)) - (setq active (nth 2 (car map))) - (setq articles nil) - (while (and sequence (<= (car sequence) top)) - (setq articles (cons (- (+ active (car sequence)) offset) - articles)) - (setq sequence (cdr sequence))) - (setq articles (nreverse articles)) - (if (and articles - (setq result - (progn - (setq group-method - (gnus-find-method-for-group group)) - (and (or (gnus-server-opened group-method) - (gnus-open-server group-method)) - (gnus-request-group group t) - (gnus-retrieve-headers articles group))))) +(nnoo-define-basics nnvirtual) + +(deffoo nnvirtual-retrieve-headers (articles &optional newsgroup + server fetch-old) + (when (nnvirtual-possibly-change-server server) + (save-excursion + (set-buffer nntp-server-buffer) + (erase-buffer) + (if (stringp (car articles)) + 'headers + (let ((vbuf (nnheader-set-temp-buffer + (get-buffer-create " *virtual headers*"))) + (unfetched (mapcar (lambda (g) (list g)) + nnvirtual-component-groups)) + (system-name (system-name)) + cgroup article result prefix) + (while articles + (setq article (assq (pop articles) nnvirtual-mapping)) + (when (and (setq cgroup (cadr article)) + (gnus-check-server + (gnus-find-method-for-group cgroup) t) + (gnus-request-group cgroup t)) + (setq prefix (gnus-group-real-prefix cgroup)) + (when (setq result (gnus-retrieve-headers + (list (caddr article)) cgroup nil)) + (set-buffer nntp-server-buffer) + (if (zerop (buffer-size)) + (nconc (assq cgroup unfetched) (list (caddr article))) + ;; If we got HEAD headers, we convert them into NOV + ;; headers. This is slow, inefficient and, come to think + ;; of it, downright evil. So sue me. I couldn't be + ;; bothered to write a header parse routine that could + ;; parse a mixed HEAD/NOV buffer. + (when (eq result 'headers) + (nnvirtual-convert-headers)) + (goto-char (point-min)) + (while (not (eobp)) + (delete-region + (point) (progn (read nntp-server-buffer) (point))) + (princ (car article) (current-buffer)) + (beginning-of-line) + (looking-at + "[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t") + (goto-char (match-end 0)) + (or (search-forward + "\t" (save-excursion (end-of-line) (point)) t) + (end-of-line)) + (while (= (char-after (1- (point))) ? ) + (forward-char -1) + (delete-char 1)) + (if (eolp) + (progn + (end-of-line) + (or (= (char-after (1- (point))) ?\t) + (insert ?\t)) + (insert "Xref: " system-name " " cgroup ":") + (princ (caddr article) (current-buffer)) + (insert "\t")) + (insert "Xref: " system-name " " cgroup ":") + (princ (caddr article) (current-buffer)) + (insert " ") + (if (not (string= "" prefix)) + (while (re-search-forward + "[^ ]+:[0-9]+" + (save-excursion (end-of-line) (point)) t) + (save-excursion + (goto-char (match-beginning 0)) + (insert prefix)))) + (end-of-line) + (or (= (char-after (1- (point))) ?\t) + (insert ?\t))) + (forward-line 1)) + (set-buffer vbuf) + (goto-char (point-max)) + (insert-buffer-substring nntp-server-buffer))))) + + ;; In case some of the articles have expired or been + ;; cancelled, we have to mark them as read in the + ;; component group. + (while unfetched + (when (cdar unfetched) + (gnus-group-make-articles-read + (caar unfetched) (sort (cdar unfetched) '<))) + (setq unfetched (cdr unfetched))) + + ;; The headers are ready for reading, so they are inserted into + ;; the nntp-server-buffer, which is where Gnus expects to find + ;; them. + (prog1 (save-excursion (set-buffer nntp-server-buffer) - ;; If we got HEAD headers, we convert them into NOV - ;; headers. This is slow, inefficient and, come to think - ;; of it, downright evil. So sue me. I couldn't be - ;; bothered to write a header parse routine that could - ;; parse a mixed HEAD/NOV buffer. - (and (eq result 'headers) (nnvirtual-convert-headers)) - (goto-char (point-min)) - (setq fetched-articles nil) - (while (not (eobp)) - (setq beg (point) - article (read nntp-server-buffer) - fetched-articles (cons article fetched-articles)) - (delete-region beg (point)) - (insert (int-to-string (+ (- article active) offset))) - (beginning-of-line) - (looking-at - "[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t") - (goto-char (match-end 0)) - (or (search-forward - "\t" (save-excursion (end-of-line) (point)) t) - (end-of-line)) - (while (= (char-after (1- (point))) ? ) - (forward-char -1) - (delete-char 1)) - (if (eolp) - (progn - (end-of-line) - (or (= (char-after (1- (point))) ?\t) - (insert ?\t)) - (insert (format "Xref: %s %s:%d\t" (system-name) - group article))) - (if (not (string= "" prefix)) - (while (re-search-forward - "[^ ]+:[0-9]+" - (save-excursion (end-of-line) (point)) t) - (save-excursion - (goto-char (match-beginning 0)) - (insert prefix)))) - (end-of-line) - (or (= (char-after (1- (point))) ?\t) - (insert ?\t))) - (forward-line 1)))) - (goto-char (point-max)) - (insert-buffer-substring nntp-server-buffer) - ;; We have now massaged and inserted the headers from one - ;; group. In case some of the articles have expired or been - ;; cancelled, we have to mark them as read in the component - ;; group. - (let ((unfetched (gnus-sorted-complement - articles (nreverse fetched-articles)))) - (and unfetched - (gnus-group-make-articles-read group unfetched nil)))) - ;; The headers are ready for reading, so they are inserted into - ;; the nntp-server-buffer, which is where Gnus expects to find - ;; them. - (prog1 + (erase-buffer) + (insert-buffer-substring vbuf) + 'nov) + (kill-buffer vbuf))))))) + +(deffoo nnvirtual-request-article (article &optional group server buffer) + (when (and (nnvirtual-possibly-change-server server) + (numberp article)) + (let* ((amap (assq article nnvirtual-mapping)) + (cgroup (cadr amap))) + (cond + ((not amap) + (nnheader-report 'nnvirtual "No such article: %s" article)) + ((not (gnus-check-group cgroup)) + (nnheader-report + 'nnvirtual "Can't open server where %s exists" cgroup)) + ((not (gnus-request-group cgroup t)) + (nnheader-report 'nnvirtual "Can't open component group %s" cgroup)) + (t + (if buffer (save-excursion - (set-buffer nntp-server-buffer) - (erase-buffer) - (insert-buffer-substring "*virtual headers*") - 'nov) - (kill-buffer (current-buffer))))))) - -(defun nnvirtual-open-server (newsgroups &optional something) - "Open a virtual newsgroup that contains NEWSGROUPS." - (nnheader-init-server-buffer)) - -(defun nnvirtual-close-server (&rest dum) - "Close news server." + (set-buffer buffer) + (gnus-request-article-this-buffer (caddr amap) cgroup)) + (gnus-request-article (caddr amap) cgroup))))))) + +(deffoo nnvirtual-open-server (server &optional defs) + (unless (assq 'nnvirtual-component-regexp defs) + (push `(nnvirtual-component-regexp ,server) + defs)) + (nnoo-change-server 'nnvirtual server defs) + (if nnvirtual-component-groups + t + (setq nnvirtual-mapping nil) + ;; Go through the newsrc alist and find all component groups. + (let ((newsrc (cdr gnus-newsrc-alist)) + group) + (while (setq group (car (pop newsrc))) + (when (string-match nnvirtual-component-regexp group) ; Match + ;; Add this group to the list of component groups. + (setq nnvirtual-component-groups + (cons group (delete group nnvirtual-component-groups)))))) + (if (not nnvirtual-component-groups) + (nnheader-report 'nnvirtual "No component groups: %s" server) + t))) + +(deffoo nnvirtual-request-group (group &optional server dont-check) + (nnvirtual-possibly-change-server server) + (setq nnvirtual-component-groups + (delete (nnvirtual-current-group) nnvirtual-component-groups)) + (cond + ((null nnvirtual-component-groups) + (setq nnvirtual-current-group nil) + (nnheader-report 'nnvirtual "No component groups in %s" group)) + (t + (unless dont-check + (nnvirtual-create-mapping)) + (setq nnvirtual-current-group group) + (let ((len (length nnvirtual-mapping))) + (nnheader-insert "211 %d 1 %d %s\n" len len group))))) + +(deffoo nnvirtual-request-type (group &optional article) + (if (not article) + 'unknown + (let ((mart (assq article nnvirtual-mapping))) + (when mart + (gnus-request-type (cadr mart) (car mart)))))) + +(deffoo nnvirtual-request-update-mark (group article mark) + (let* ((nart (assq article nnvirtual-mapping)) + (cgroup (cadr nart)) + ;; The component group might be a virtual group. + (nmark (gnus-request-update-mark cgroup (caddr nart) mark))) + (when (and nart + (= mark nmark) + (gnus-group-auto-expirable-p cgroup)) + (setq mark gnus-expirable-mark))) + mark) + +(deffoo nnvirtual-close-group (group &optional server) + (when (nnvirtual-possibly-change-server server) + ;; Copy (un)read articles. + (nnvirtual-update-reads) + ;; We copy the marks from this group to the component + ;; groups here. + (nnvirtual-update-marked)) t) + +(deffoo nnvirtual-request-list (&optional server) + (nnheader-report 'nnvirtual "LIST is not implemented.")) -(defun nnvirtual-request-close () - (setq nnvirtual-current-group nil - nnvirtual-current-groups nil - nnvirtual-current-mapping nil - nnvirtual-group-alist nil) - t) +(deffoo nnvirtual-request-newgroups (date &optional server) + (nnheader-report 'nnvirtual "NEWGROUPS is not supported.")) + +(deffoo nnvirtual-request-list-newsgroups (&optional server) + (nnheader-report 'nnvirtual "LIST NEWSGROUPS is not implemented.")) -(defun nnvirtual-server-opened (&optional server) - "Return server process status, T or NIL. -If the stream is opened, return T, otherwise return NIL." - (and nntp-server-buffer - (get-buffer nntp-server-buffer))) - -(defun nnvirtual-status-message (&optional server) - "Return server status response as string." - nnvirtual-status-string) - -(defun nnvirtual-request-article (article &optional newsgroup server buffer) - "Select article by message number." - (nnvirtual-possibly-change-newsgroups newsgroup server t) - (and (numberp article) - (let ((map nnvirtual-current-mapping) - (offset 0) - group-method) - (while (< (car (car map)) article) - (setq offset (car (car map))) - (setq map (cdr map))) - (setq group-method (gnus-find-method-for-group (nth 1 (car map)))) - (or (gnus-server-opened group-method) - (gnus-open-server group-method)) - (gnus-request-group (nth 1 (car map)) t) - (gnus-request-article (- (+ (nth 2 (car map)) article) offset) - (nth 1 (car map)) buffer)))) - -(defun nnvirtual-request-group (group &optional server dont-check) - "Make GROUP the current newsgroup." - (nnvirtual-possibly-change-newsgroups group server dont-check) - (let ((map nnvirtual-current-mapping)) +(deffoo nnvirtual-request-update-info (group info &optional server) + (when (nnvirtual-possibly-change-server server) + (let ((map nnvirtual-mapping) + (marks (mapcar (lambda (m) (list (cdr m))) gnus-article-mark-lists)) + reads mr m op) + ;; Go through the mapping. + (while map + (unless (nth 3 (setq m (pop map))) + ;; Read article. + (push (car m) reads)) + ;; Copy marks. + (when (setq mr (nth 4 m)) + (while mr + (setcdr (setq op (assq (pop mr) marks)) (cons (car m) (cdr op)))))) + ;; Compress the marks and the reads. + (setq mr marks) + (while mr + (setcdr (car mr) (gnus-compress-sequence (sort (cdr (pop mr)) '<)))) + (setcar (cddr info) (gnus-compress-sequence (nreverse reads))) + ;; Remove empty marks lists. + (while (and marks (not (cdar marks))) + (setq marks (cdr marks))) + (setq mr marks) + (while (cdr mr) + (if (cdadr mr) + (setq mr (cdr mr)) + (setcdr mr (cddr mr)))) + + ;; Enter these new marks into the info of the group. + (if (nthcdr 3 info) + (setcar (nthcdr 3 info) marks) + ;; Add the marks lists to the end of the info. + (when marks + (setcdr (nthcdr 2 info) (list marks)))) + t))) + +(deffoo nnvirtual-catchup-group (group &optional server all) + (nnvirtual-possibly-change-server server) + (let ((gnus-group-marked (copy-sequence nnvirtual-component-groups)) + (gnus-expert-user t)) + ;; Make sure all groups are activated. + (mapcar + (lambda (g) + (when (not (numberp (car (gnus-gethash g gnus-newsrc-hashtb)))) + (gnus-activate-group g))) + nnvirtual-component-groups) (save-excursion - (set-buffer nntp-server-buffer) - (erase-buffer) - (if map - (progn - (while (cdr map) - (setq map (cdr map))) - (insert (format "211 %d 1 %d %s\n" (car (car map)) - (car (car map)) group)) - t) - (setq nnvirtual-status-string "No component groups") - (setq nnvirtual-current-group nil) - nil)))) - -(defun nnvirtual-close-group (group &optional server) - (if (not nnvirtual-current-group) - () - (nnvirtual-possibly-change-newsgroups group server t) - (nnvirtual-update-marked) - (setq nnvirtual-current-group nil - nnvirtual-current-groups nil - nnvirtual-current-mapping nil) - (setq nnvirtual-group-alist - (delq (assoc group nnvirtual-group-alist) nnvirtual-group-alist)))) - -(defun nnvirtual-request-list (&optional server) - (setq nnvirtual-status-string "nnvirtual: LIST is not implemented.") - nil) - -(defun nnvirtual-request-newgroups (date &optional server) - "List new groups." - (setq nnvirtual-status-string "NEWGROUPS is not supported.") - nil) - -(defun nnvirtual-request-list-newsgroups (&optional server) - (setq nnvirtual-status-string - "nnvirtual: LIST NEWSGROUPS is not implemented.") - nil) - -(defalias 'nnvirtual-request-post 'nntp-request-post) - -(defun nnvirtual-request-post-buffer - (post group subject header article-buffer info follow-to respect-poster) - (nntp-request-post-buffer post "" subject header article-buffer - info follow-to respect-poster)) + (set-buffer gnus-group-buffer) + (gnus-group-catchup-current nil all)))) + +(deffoo nnvirtual-find-group-art (group article) + "Return the real group and article for virtual GROUP and ARTICLE." + (let ((mart (assq article nnvirtual-mapping))) + (when mart + (cons (cadr mart) (caddr mart))))) ;;; Internal functions. -;; Convert HEAD headers into NOV headers. (defun nnvirtual-convert-headers () + "Convert HEAD headers into NOV headers." (save-excursion (set-buffer nntp-server-buffer) - (let* ((gnus-newsgroup-dependencies (make-vector 100 0)) - (headers (gnus-get-newsgroup-headers)) + (let* ((dependencies (make-vector 100 0)) + (headers (gnus-get-newsgroup-headers dependencies)) header) (erase-buffer) - (while headers - (setq header (car headers) - headers (cdr headers)) - (insert (int-to-string (mail-header-number header)) "\t" - (or (mail-header-subject header) "") "\t" - (or (mail-header-from header) "") "\t" - (or (mail-header-date header) "") "\t" - (or (mail-header-id header) "") "\t" - (or (mail-header-references header) "") "\t" - (int-to-string (or (mail-header-chars header) 0)) "\t" - (int-to-string (or (mail-header-lines header) 0)) "\t" - (if (mail-header-xref header) - (concat "Xref: " (mail-header-xref header) "\t") - "") "\n"))))) - -(defun nnvirtual-possibly-change-newsgroups (group regexp &optional check) - (let ((inf t)) - (or (not group) - (and nnvirtual-current-group - (string= group nnvirtual-current-group)) - (and (setq inf (assoc group nnvirtual-group-alist)) - (string= (nth 3 inf) regexp) - (progn - (setq nnvirtual-current-group (car inf)) - (setq nnvirtual-current-groups (nth 1 inf)) - (setq nnvirtual-current-mapping (nth 2 inf))))) - (if (or (not check) (not inf)) - (progn - (and inf (setq nnvirtual-group-alist - (delq inf nnvirtual-group-alist))) - (setq nnvirtual-current-mapping nil) - (setq nnvirtual-current-group group) - (let ((newsrc gnus-newsrc-alist) - (virt-group (gnus-group-prefixed-name - nnvirtual-current-group '(nnvirtual "")))) - (setq nnvirtual-current-groups nil) - (while newsrc - (and (string-match regexp (car (car newsrc))) - (not (string= (car (car newsrc)) virt-group)) - (setq nnvirtual-current-groups - (cons (car (car newsrc)) nnvirtual-current-groups))) - (setq newsrc (cdr newsrc)))) - (if nnvirtual-current-groups - (progn - (nnvirtual-create-mapping group) - (setq nnvirtual-group-alist - (cons (list group nnvirtual-current-groups - nnvirtual-current-mapping regexp) - nnvirtual-group-alist))) - (setq nnvirtual-status-string - (format - "nnvirtual: No newsgroups for this virtual newsgroup")))))) - nnvirtual-current-groups) - -(defun nnvirtual-create-mapping (group) - (let* ((group (gnus-group-prefixed-name group (list 'nnvirtual ""))) - (info (nth 2 (gnus-gethash group gnus-newsrc-hashtb))) - (groups nnvirtual-current-groups) - (offset 0) - reads unread igroup itotal ireads) - ;; The virtual group doesn't exist. (?) - (or info (error "No such group: %s" group)) - (setq nnvirtual-current-mapping nil) - (while groups - ;; Added by Sudish Joseph . - (setq igroup (car groups)) - (let ((info (nth 2 (gnus-gethash igroup gnus-newsrc-hashtb))) - (active (gnus-gethash igroup gnus-active-hashtb))) - ;; See if the group has had its active list read this session - ;; if not, we do it now. - (if (null active) - (if (gnus-activate-group igroup) - (progn - (gnus-get-unread-articles-in-group - info (gnus-gethash igroup gnus-active-hashtb)) - (setq active (gnus-gethash igroup gnus-active-hashtb))) - (message "Couldn't open component group %s" igroup))) - (if (null active) - () - ;; And then we do the mapping for this component group. If - ;; you feel tempted to cast your eyes to the soup below - - ;; don't. It'll hurt your soul. Suffice to say that it - ;; assigns ranges of nnvirtual article numbers to the - ;; different component groups. To get the article number - ;; from the nnvirtual number, one does something like - ;; (+ (- number offset) (car active)), where `offset' is the - ;; slice the mess below assigns, and active is the lowest - ;; active article in the component group. - (setq itotal (1+ (- (cdr active) (car active)))) - (if (setq ireads (nth 2 info)) - (let ((itreads - (if (not (listp (cdr ireads))) - (setq ireads (list (cons (car ireads) (cdr ireads)))) - (setq ireads (copy-alist ireads))))) - (if (< (or (and (numberp (car ireads)) (car ireads)) - (cdr (car ireads))) (car active)) - (setq ireads (setq itreads (cdr ireads)))) - (if (and ireads (< (or (and (numberp (car ireads)) - (car ireads)) - (car (car ireads))) (car active))) - (setcar (or (and (numberp (car ireads)) ireads) - (car ireads)) (1+ (car active)))) - (while itreads - (setcar (or (and (numberp (car itreads)) itreads) - (car itreads)) - (+ (max - 1 (- (if (numberp (car itreads)) - (car itreads) - (car (car itreads))) - (car active))) - offset)) - (if (not (numberp (car itreads))) - (setcdr (car itreads) - (+ (- (cdr (car itreads)) (car active)) offset))) - (setq itreads (cdr itreads))) - (setq reads (nconc reads ireads)))) - (setq offset (+ offset (1- itotal))) - (setq nnvirtual-current-mapping - (cons (list offset igroup (car active)) - nnvirtual-current-mapping))) - (setq groups (cdr groups)))) - (setq nnvirtual-current-mapping - (nreverse nnvirtual-current-mapping)) - ;; Set Gnus active info. - (gnus-sethash group (cons 1 (1- offset)) gnus-active-hashtb) - ;; Set Gnus read info. - (setcar (nthcdr 2 info) reads) - - ;; Then we deal with the marks. - (let ((map nnvirtual-current-mapping) - (marks '(tick dormant reply expire score)) - (offset 0) - tick dormant reply expire score marked active) - (while map - (setq igroup (nth 1 (car map))) - (setq active (nth 2 (car map))) - (setq marked (nth 3 (nth 2 (gnus-gethash igroup gnus-newsrc-hashtb)))) - (let ((m marks)) - (while m - (and (assq (car m) marked) - (set (car m) - (nconc (mapcar - (lambda (art) - (if (numberp art) - (if (< art active) - 0 (+ (- art active) offset)) - (cons (+ (- (car art) active) offset) - (cdr art)))) - (cdr (assq (car m) marked))) - (symbol-value (car m))))) - (setq m (cdr m)))) - (setq offset (car (car map))) - (setq map (cdr map))) - ;; Put the list of marked articles in the info of the virtual group. - (let ((m marks) - marked) - (while m - (and (symbol-value (car m)) - (setq marked (cons (cons (car m) (symbol-value (car m))) - marked))) - (setq m (cdr m))) - (if (nthcdr 3 info) - (setcar (nthcdr 3 info) marked) - (setcdr (nthcdr 2 info) (list marked))))))) + (while (setq header (pop headers)) + (nnheader-insert-nov header))))) + +(defun nnvirtual-possibly-change-server (server) + (or (not server) + (nnoo-current-server-p 'nnvirtual server) + (nnvirtual-open-server server))) (defun nnvirtual-update-marked () - (let ((mark-lists '((gnus-newsgroup-marked . tick) - (gnus-newsgroup-dormant . dormant) - (gnus-newsgroup-expirable . expire) - (gnus-newsgroup-replied . reply))) - marks art-group group-alist g) - (while mark-lists - (setq marks (symbol-value (car (car mark-lists)))) - ;; Find out what groups the mark belong to. - (while marks - (setq art-group (nnvirtual-art-group (car marks))) - (if (setq g (assoc (car art-group) group-alist)) - (nconc g (list (cdr art-group))) - (setq group-alist (cons (list (car art-group) (cdr art-group)) - group-alist))) - (setq marks (cdr marks))) - ;; The groups that don't have marks must have no marks. (Yup.) - (let ((groups nnvirtual-current-groups)) - (while groups - (or (assoc (car groups) group-alist) - (setq group-alist (cons (list (car groups)) group-alist))) - (setq groups (cdr groups)))) - ;; The we update the list of marks. - (while group-alist + "Copy marks from the virtual group to the component groups." + (let ((mark-lists gnus-article-mark-lists) + (marks (gnus-info-marks (gnus-get-info (nnvirtual-current-group)))) + type list mart cgroups) + (while (setq type (cdr (pop mark-lists))) + (setq list (gnus-uncompress-range (cdr (assq type marks)))) + (setq cgroups + (mapcar (lambda (g) (list g)) nnvirtual-component-groups)) + (while list + (nconc (assoc (cadr (setq mart (assq (pop list) nnvirtual-mapping))) + cgroups) + (list (caddr mart)))) + (while cgroups (gnus-add-marked-articles - (car (car group-alist)) (cdr (car mark-lists)) - (cdr (car group-alist)) nil t) - (gnus-group-update-group (car (car group-alist)) t) - (setq group-alist (cdr group-alist))) - (setq mark-lists (cdr mark-lists))))) - -(defun nnvirtual-art-group (article) - (let ((map nnvirtual-current-mapping) - (offset 0)) - (while (< (car (car map)) (if (numberp article) article (car article))) - (setq offset (car (car map)) - map (cdr map))) - (cons (nth 1 (car map)) - (if (numberp article) - (- (+ article (nth 2 (car map))) offset) - (cons (- (+ (car article) (nth 2 (car map))) offset) - (cdr article)))))) - -(defun nnvirtual-catchup-group (group &optional server all) - (nnvirtual-possibly-change-newsgroups group server) - (let ((gnus-group-marked nnvirtual-current-groups) - (gnus-expert-user t)) - (save-excursion - (set-buffer gnus-group-buffer) - (gnus-group-catchup-current nil all)))) + (caar cgroups) type (cdar cgroups) nil t) + (gnus-group-update-group (car (pop cgroups)) t))))) + +(defun nnvirtual-update-reads () + "Copy (un)reads from the current group to the component groups." + (let ((groups (mapcar (lambda (g) (list g)) nnvirtual-component-groups)) + (articles (gnus-list-of-unread-articles + (nnvirtual-current-group))) + m) + (while articles + (setq m (assq (pop articles) nnvirtual-mapping)) + (nconc (assoc (nth 1 m) groups) (list (nth 2 m)))) + (while groups + (gnus-update-read-articles (caar groups) (cdr (pop groups)))))) + +(defun nnvirtual-current-group () + "Return the prefixed name of the current nnvirtual group." + (concat "nnvirtual:" nnvirtual-current-group)) + +(defsubst nnvirtual-marks (article marks) + "Return a list of mark types for ARTICLE." + (let (out) + (while marks + (when (memq article (cdar marks)) + (push (caar marks) out)) + (setq marks (cdr marks))) + out)) + +(defun nnvirtual-create-mapping () + "Create an article mapping for the current group." + (let* ((div nil) + m marks list article unreads marks active + (map (sort + (apply + 'nconc + (mapcar + (lambda (g) + (when (and (setq active (gnus-activate-group g)) + (> (cdr active) (car active))) + (setq unreads (gnus-list-of-unread-articles g) + marks (gnus-uncompress-marks + (gnus-info-marks (gnus-get-info g)))) + (when gnus-use-cache + (push (cons 'cache (gnus-cache-articles-in-group g)) + marks)) + (setq div (/ (float (car active)) + (if (zerop (cdr active)) + 1 (cdr active)))) + (mapcar (lambda (n) + (list (* div (- n (car active))) + g n (and (memq n unreads) t) + (inline (nnvirtual-marks n marks)))) + (gnus-uncompress-range active)))) + nnvirtual-component-groups)) + (lambda (m1 m2) + (< (car m1) (car m2))))) + (i 0)) + (setq nnvirtual-mapping map) + ;; Set the virtual article numbers. + (while (setq m (pop map)) + (setcar m (setq article (incf i)))))) (provide 'nnvirtual)