annotate lisp/gnus/nneething.el @ 110:fe104dbd9147 r20-1b7

Import from CVS: tag r20-1b7
author cvs
date Mon, 13 Aug 2007 09:19:45 +0200
parents 360340f9fd5f
children 48d667d6f17f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; nneething.el --- random file access for Gnus
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
2 ;; Copyright (C) 1995,96,97 Free Software Foundation, Inc.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Keywords: news, mail
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 38
diff changeset
27 ;; Based on nnspool.el by Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 38
diff changeset
28 ;; For an overview of what the interface functions do, please see the
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 98
diff changeset
29 ;; Gnus sources.
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 38
diff changeset
30
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 (require 'nnheader)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (require 'nnmail)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (require 'nnoo)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
36 (require 'gnus-util)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
37 (require 'cl)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (nnoo-declare nneething)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (defvoo nneething-map-file-directory "~/.nneething/"
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 38
diff changeset
42 "*Where nneething stores the map files.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (defvoo nneething-map-file ".nneething"
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 38
diff changeset
45 "*Name of the map files.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (defvoo nneething-exclude-files nil
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 38
diff changeset
48 "*Regexp saying what files to exclude from the group.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 If this variable is nil, no files will be excluded.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 98
diff changeset
53 ;;; Internal variables.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (defconst nneething-version "nneething 1.0"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 "nneething version.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (defvoo nneething-current-directory nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 "Current news group directory.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (defvoo nneething-status-string "")
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 38
diff changeset
62 (defvoo nneething-group-alist nil)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (defvoo nneething-message-id-number 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (defvoo nneething-work-buffer " *nneething work*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 38
diff changeset
67 (defvoo nneething-directory nil)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (defvoo nneething-group nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (defvoo nneething-map nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (defvoo nneething-read-only nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (defvoo nneething-active nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;;; Interface functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (nnoo-define-basics nneething)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (deffoo nneething-retrieve-headers (articles &optional group server fetch-old)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (nneething-possibly-change-directory group)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (set-buffer nntp-server-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (let* ((number (length articles))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (large (and (numberp nnmail-large-newsgroup)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (> number nnmail-large-newsgroup)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 article file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (if (stringp (car articles))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 'headers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (while (setq article (pop articles))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (setq file (nneething-file-name article))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (when (and (file-exists-p file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (or (file-directory-p file)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
99 (not (zerop (nnheader-file-size file)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (insert (format "221 %d Article retrieved.\n" article))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (nneething-insert-head file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (insert ".\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (incf count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (and large
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (zerop (% count 20))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (message "nneething: Receiving headers... %d%%"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (/ (* count 100) number))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (when large
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (message "nneething: Receiving headers...done"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (nnheader-fold-continuation-lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 'headers))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (deffoo nneething-request-article (id &optional group server buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (nneething-possibly-change-directory group)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
119 (let ((file (unless (stringp id)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
120 (nneething-file-name id)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (nntp-server-buffer (or buffer nntp-server-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (and (stringp file) ; We did not request by Message-ID.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (file-exists-p file) ; The file exists.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (not (file-directory-p file)) ; It's not a dir.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (nnmail-find-file file) ; Insert the file in the nntp buf.
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
127 (unless (nnheader-article-p) ; Either it's a real article...
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
128 (goto-char (point-min))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
129 (nneething-make-head file (current-buffer)) ; ... or we fake some headers.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
130 (insert "\n"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 38
diff changeset
133 (deffoo nneething-request-group (group &optional dir dont-check)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 38
diff changeset
134 (nneething-possibly-change-directory group dir)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (unless dont-check
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (nneething-create-mapping)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (if (> (car nneething-active) (cdr nneething-active))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (nnheader-insert "211 0 1 0 %s\n" group)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (nnheader-insert
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 98
diff changeset
140 "211 %d %d %d %s\n"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (- (1+ (cdr nneething-active)) (car nneething-active))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (car nneething-active) (cdr nneething-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 group)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (deffoo nneething-request-list (&optional server dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (nnheader-report 'nneething "LIST is not implemented."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (deffoo nneething-request-newgroups (date &optional server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (nnheader-report 'nneething "NEWSGROUPS is not implemented."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (deffoo nneething-request-type (group &optional article)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 'unknown)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (deffoo nneething-close-group (group &optional server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (setq nneething-current-directory nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 ;;; Internal functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 38
diff changeset
162 (defun nneething-possibly-change-directory (group &optional dir)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 38
diff changeset
163 (when group
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 38
diff changeset
164 (if (and nneething-group
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 38
diff changeset
165 (string= group nneething-group))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 38
diff changeset
166 t
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 38
diff changeset
167 (let (entry)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 38
diff changeset
168 (if (setq entry (assoc group nneething-group-alist))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 38
diff changeset
169 (progn
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 38
diff changeset
170 (setq nneething-group group)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 38
diff changeset
171 (setq nneething-directory (nth 1 entry))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 38
diff changeset
172 (setq nneething-map (nth 2 entry))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 38
diff changeset
173 (setq nneething-active (nth 3 entry)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 38
diff changeset
174 (setq nneething-group group)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 38
diff changeset
175 (setq nneething-directory dir)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 38
diff changeset
176 (setq nneething-map nil)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 38
diff changeset
177 (setq nneething-active (cons 1 0))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 38
diff changeset
178 (nneething-create-mapping)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 38
diff changeset
179 (push (list group dir nneething-map nneething-active)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 38
diff changeset
180 nneething-group-alist))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (defun nneething-map-file ()
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 98
diff changeset
183 ;; We make sure that the .nneething directory exists.
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
184 (gnus-make-directory nneething-map-file-directory)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 ;; We store it in a special directory under the user's home dir.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (concat (file-name-as-directory nneething-map-file-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 nneething-group nneething-map-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (defun nneething-create-mapping ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 ;; Read nneething-active and nneething-map.
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
191 (when (file-exists-p nneething-directory)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
192 (let ((map-file (nneething-map-file))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
193 (files (directory-files nneething-directory))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
194 touched map-files)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
195 (when (file-exists-p map-file)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
196 (ignore-errors
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
197 (load map-file nil t t)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
198 (unless nneething-active
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
199 (setq nneething-active (cons 1 0)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
200 ;; Old nneething had a different map format.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
201 (when (and (cdar nneething-map)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
202 (atom (cdar nneething-map)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
203 (setq nneething-map
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
204 (mapcar (lambda (n)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
205 (list (cdr n) (car n)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
206 (nth 5 (file-attributes
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
207 (nneething-file-name (car n))))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
208 nneething-map)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
209 ;; Remove files matching the exclusion regexp.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
210 (when nneething-exclude-files
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
211 (let ((f files)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
212 prev)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
213 (while f
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
214 (if (string-match nneething-exclude-files (car f))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
215 (if prev (setcdr prev (cdr f))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
216 (setq files (cdr files)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
217 (setq prev f))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
218 (setq f (cdr f)))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
219 ;; Remove deleted files from the map.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
220 (let ((map nneething-map)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 prev)
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
222 (while map
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
223 (if (and (member (cadar map) files)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
224 ;; We also remove files that have changed mod times.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
225 (equal (nth 5 (file-attributes
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
226 (nneething-file-name (cadar map))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
227 (caddar map)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
228 (progn
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
229 (push (cadar map) map-files)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
230 (setq prev map))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
231 (setq touched t)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
232 (if prev
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
233 (setcdr prev (cdr map))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
234 (setq nneething-map (cdr nneething-map))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
235 (setq map (cdr map))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
236 ;; Find all new files and enter them into the map.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
237 (while files
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
238 (unless (member (car files) map-files)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
239 ;; This file is not in the map, so we enter it.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (setq touched t)
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
241 (setcdr nneething-active (1+ (cdr nneething-active)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
242 (push (list (cdr nneething-active) (car files)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
243 (nth 5 (file-attributes
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
244 (nneething-file-name (car files)))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
245 nneething-map))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
246 (setq files (cdr files)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
247 (when (and touched
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
248 (not nneething-read-only))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
249 (nnheader-temp-write map-file
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
250 (insert "(setq nneething-map '")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
251 (gnus-prin1 nneething-map)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
252 (insert ")\n(setq nneething-active '")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
253 (gnus-prin1 nneething-active)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
254 (insert ")\n"))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (defun nneething-insert-head (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 "Insert the head of FILE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (when (nneething-get-head file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (insert-buffer-substring nneething-work-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (goto-char (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (defun nneething-make-head (file &optional buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 "Create a head by looking at the file attributes of FILE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (let ((atts (file-attributes file)))
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 98
diff changeset
265 (insert
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 "Subject: " (file-name-nondirectory file) "\n"
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 98
diff changeset
267 "Message-ID: <nneething-"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (int-to-string (incf nneething-message-id-number))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 "@" (system-name) ">\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (if (equal '(0 0) (nth 5 atts)) ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (concat "Date: " (current-time-string (nth 5 atts)) "\n"))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
272 (or (when buffer
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 98
diff changeset
273 (save-excursion
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
274 (set-buffer buffer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
275 (when (re-search-forward "<[a-zA-Z0-9_]@[-a-zA-Z0-9_]>" 1000 t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
276 (concat "From: " (match-string 0) "\n"))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (nneething-from-line (nth 2 atts) file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (if (> (string-to-int (int-to-string (nth 7 atts))) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (concat "Chars: " (int-to-string (nth 7 atts)) "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 "")
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 98
diff changeset
281 (if buffer
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (set-buffer buffer)
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 98
diff changeset
284 (concat "Lines: " (int-to-string
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
285 (count-lines (point-min) (point-max)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
286 "\n"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (defun nneething-from-line (uid &optional file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 "Return a From header based of UID."
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 98
diff changeset
292 (let* ((login (condition-case nil
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (user-login-name uid)
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 98
diff changeset
294 (error
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (cond ((= uid (user-uid)) (user-login-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 ((zerop uid) "root")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (t (int-to-string uid))))))
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 98
diff changeset
298 (name (condition-case nil
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (user-full-name uid)
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 98
diff changeset
300 (error
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (cond ((= uid (user-uid)) (user-full-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 ((zerop uid) "Ms. Root")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (host (if (string-match "\\`/[^/@]*@\\([^:/]+\\):" file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (prog1
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 98
diff changeset
305 (substring file
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
306 (match-beginning 1)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (match-end 1))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
308 (when (string-match "/\\(users\\|home\\)/\\([^/]+\\)/" file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
309 (setq login (substring file
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
310 (match-beginning 2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
311 (match-end 2))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
312 name nil)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (system-name))))
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 98
diff changeset
314 (concat "From: " login "@" host
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (if name (concat " (" name ")") "") "\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (defun nneething-get-head (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 "Either find the head in FILE or make a head for FILE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (set-buffer (get-buffer-create nneething-work-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (setq case-fold-search nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (buffer-disable-undo (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (erase-buffer)
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 98
diff changeset
324 (cond
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 ((not (file-exists-p file))
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 98
diff changeset
326 ;; The file do not exist.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 ((or (file-directory-p file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (file-symlink-p file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 ;; It's a dir, so we fudge a head.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (nneething-make-head file) t)
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 98
diff changeset
332 (t
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 ;; We examine the file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (nnheader-insert-head file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (if (nnheader-article-p)
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 98
diff changeset
336 (delete-region
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (or (and (search-forward "\n\n" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (1- (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (nneething-make-head file (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (delete-region (point) (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (defun nneething-file-name (article)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 "Return the file name of ARTICLE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (concat (file-name-as-directory nneething-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (if (numberp article)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (cadr (assq article nneething-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 article)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (provide 'nneething)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 ;;; nneething.el ends here