annotate lisp/gnus/nneething.el @ 112:48d667d6f17f r20-1b8

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