Mercurial > emacs
annotate lisp/gnus/nneething.el @ 87858:f176bf2c0e6d
*** empty log message ***
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Sun, 20 Jan 2008 04:02:15 +0000 |
parents | 107ccd98fa12 |
children | 606f2d163a64 1e3a407766b9 |
rev | line source |
---|---|
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19522
diff
changeset
|
1 ;;; nneething.el --- arbitrary file access for Gnus |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
2 |
64754
fafd692d1e40
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64085
diff
changeset
|
3 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, |
79708 | 4 ;; 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
17493 | 5 |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19522
diff
changeset
|
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
7 ;; Masanobu UMEDA <umerin@flab.flab.fujitsu.junet> |
17493 | 8 ;; Keywords: news, mail |
9 | |
10 ;; This file is part of GNU Emacs. | |
11 | |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
13 ;; it under the terms of the GNU General Public License as published by | |
78224
24202b793a08
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
75347
diff
changeset
|
14 ;; the Free Software Foundation; either version 3, or (at your option) |
17493 | 15 ;; any later version. |
16 | |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
64085 | 24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
25 ;; Boston, MA 02110-1301, USA. | |
17493 | 26 |
27 ;;; Commentary: | |
28 | |
29 ;;; Code: | |
30 | |
19522
681265352f07
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
31 (eval-when-compile (require 'cl)) |
681265352f07
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
32 |
17493 | 33 (require 'nnheader) |
34 (require 'nnmail) | |
35 (require 'nnoo) | |
36 (require 'gnus-util) | |
37 | |
38 (nnoo-declare nneething) | |
39 | |
60696
7503b2a24a3c
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-187
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
40 (defvoo nneething-map-file-directory |
7503b2a24a3c
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-187
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
41 (nnheader-concat gnus-directory ".nneething/") |
17493 | 42 "Where nneething stores the map files.") |
43 | |
44 (defvoo nneething-map-file ".nneething" | |
45 "Name of the map files.") | |
46 | |
47 (defvoo nneething-exclude-files nil | |
48 "Regexp saying what files to exclude from the group. | |
49 If this variable is nil, no files will be excluded.") | |
50 | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
51 (defvoo nneething-include-files nil |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
52 "Regexp saying what files to include in the group. |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
53 If this variable is non-nil, only files matching this regexp will be |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
54 included.") |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
55 |
17493 | 56 |
57 | |
58 ;;; Internal variables. | |
59 | |
60 (defconst nneething-version "nneething 1.0" | |
61 "nneething version.") | |
62 | |
63 (defvoo nneething-current-directory nil | |
64 "Current news group directory.") | |
65 | |
66 (defvoo nneething-status-string "") | |
67 | |
68 (defvoo nneething-work-buffer " *nneething work*") | |
69 | |
70 (defvoo nneething-group nil) | |
71 (defvoo nneething-map nil) | |
72 (defvoo nneething-read-only nil) | |
73 (defvoo nneething-active nil) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19522
diff
changeset
|
74 (defvoo nneething-address nil) |
17493 | 75 |
76 | |
77 | |
78 ;;; Interface functions. | |
79 | |
80 (nnoo-define-basics nneething) | |
81 | |
82 (deffoo nneething-retrieve-headers (articles &optional group server fetch-old) | |
83 (nneething-possibly-change-directory group) | |
84 | |
85 (save-excursion | |
86 (set-buffer nntp-server-buffer) | |
87 (erase-buffer) | |
88 (let* ((number (length articles)) | |
89 (count 0) | |
90 (large (and (numberp nnmail-large-newsgroup) | |
91 (> number nnmail-large-newsgroup))) | |
92 article file) | |
93 | |
94 (if (stringp (car articles)) | |
95 'headers | |
96 | |
97 (while (setq article (pop articles)) | |
98 (setq file (nneething-file-name article)) | |
99 | |
100 (when (and (file-exists-p file) | |
101 (or (file-directory-p file) | |
102 (not (zerop (nnheader-file-size file))))) | |
103 (insert (format "221 %d Article retrieved.\n" article)) | |
104 (nneething-insert-head file) | |
105 (insert ".\n")) | |
106 | |
107 (incf count) | |
108 | |
109 (and large | |
110 (zerop (% count 20)) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19522
diff
changeset
|
111 (nnheader-message 5 "nneething: Receiving headers... %d%%" |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
112 (/ (* count 100) number)))) |
17493 | 113 |
114 (when large | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19522
diff
changeset
|
115 (nnheader-message 5 "nneething: Receiving headers...done")) |
17493 | 116 |
117 (nnheader-fold-continuation-lines) | |
118 'headers)))) | |
119 | |
120 (deffoo nneething-request-article (id &optional group server buffer) | |
121 (nneething-possibly-change-directory group) | |
122 (let ((file (unless (stringp id) | |
123 (nneething-file-name id))) | |
124 (nntp-server-buffer (or buffer nntp-server-buffer))) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
125 (and (stringp file) ; We did not request by Message-ID. |
17493 | 126 (file-exists-p file) ; The file exists. |
127 (not (file-directory-p file)) ; It's not a dir. | |
128 (save-excursion | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
129 (let ((nnmail-file-coding-system 'binary)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
130 (nnmail-find-file file)) ; Insert the file in the nntp buf. |
17493 | 131 (unless (nnheader-article-p) ; Either it's a real article... |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
132 (let ((type |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
133 (unless (file-directory-p file) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
134 (or (cdr (assoc (concat "." (file-name-extension file)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
135 mailcap-mime-extensions)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
136 "text/plain"))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
137 (charset |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
138 (mm-detect-mime-charset-region (point-min) (point-max))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
139 (encoding)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
140 (unless (string-match "\\`text/" type) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
141 (base64-encode-region (point-min) (point-max)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
142 (setq encoding "base64")) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
143 (goto-char (point-min)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
144 (nneething-make-head file (current-buffer) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
145 nil type charset encoding)) |
17493 | 146 (insert "\n")) |
147 t)))) | |
148 | |
149 (deffoo nneething-request-group (group &optional server dont-check) | |
150 (nneething-possibly-change-directory group server) | |
151 (unless dont-check | |
152 (nneething-create-mapping) | |
153 (if (> (car nneething-active) (cdr nneething-active)) | |
154 (nnheader-insert "211 0 1 0 %s\n" group) | |
155 (nnheader-insert | |
156 "211 %d %d %d %s\n" | |
157 (- (1+ (cdr nneething-active)) (car nneething-active)) | |
158 (car nneething-active) (cdr nneething-active) | |
159 group))) | |
160 t) | |
161 | |
162 (deffoo nneething-request-list (&optional server dir) | |
163 (nnheader-report 'nneething "LIST is not implemented.")) | |
164 | |
165 (deffoo nneething-request-newgroups (date &optional server) | |
166 (nnheader-report 'nneething "NEWSGROUPS is not implemented.")) | |
167 | |
168 (deffoo nneething-request-type (group &optional article) | |
169 'unknown) | |
170 | |
171 (deffoo nneething-close-group (group &optional server) | |
172 (setq nneething-current-directory nil) | |
173 t) | |
174 | |
175 (deffoo nneething-open-server (server &optional defs) | |
176 (nnheader-init-server-buffer) | |
177 (if (nneething-server-opened server) | |
178 t | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19522
diff
changeset
|
179 (unless (assq 'nneething-address defs) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19522
diff
changeset
|
180 (setq defs (append defs (list (list 'nneething-address server))))) |
17493 | 181 (nnoo-change-server 'nneething server defs))) |
182 | |
183 | |
184 ;;; Internal functions. | |
185 | |
186 (defun nneething-possibly-change-directory (group &optional server) | |
187 (when (and server | |
188 (not (nneething-server-opened server))) | |
189 (nneething-open-server server)) | |
190 (when (and group | |
191 (not (equal nneething-group group))) | |
192 (setq nneething-group group) | |
193 (setq nneething-map nil) | |
194 (setq nneething-active (cons 1 0)) | |
195 (nneething-create-mapping))) | |
196 | |
197 (defun nneething-map-file () | |
198 ;; We make sure that the .nneething directory exists. | |
199 (gnus-make-directory nneething-map-file-directory) | |
200 ;; We store it in a special directory under the user's home dir. | |
201 (concat (file-name-as-directory nneething-map-file-directory) | |
202 nneething-group nneething-map-file)) | |
203 | |
204 (defun nneething-create-mapping () | |
205 ;; Read nneething-active and nneething-map. | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19522
diff
changeset
|
206 (when (file-exists-p nneething-address) |
17493 | 207 (let ((map-file (nneething-map-file)) |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19522
diff
changeset
|
208 (files (directory-files nneething-address)) |
17493 | 209 touched map-files) |
210 (when (file-exists-p map-file) | |
211 (ignore-errors | |
212 (load map-file nil t t))) | |
213 (unless nneething-active | |
214 (setq nneething-active (cons 1 0))) | |
215 ;; Old nneething had a different map format. | |
216 (when (and (cdar nneething-map) | |
217 (atom (cdar nneething-map))) | |
218 (setq nneething-map | |
219 (mapcar (lambda (n) | |
220 (list (cdr n) (car n) | |
221 (nth 5 (file-attributes | |
222 (nneething-file-name (car n)))))) | |
223 nneething-map))) | |
224 ;; Remove files matching the exclusion regexp. | |
225 (when nneething-exclude-files | |
226 (let ((f files) | |
227 prev) | |
228 (while f | |
229 (if (string-match nneething-exclude-files (car f)) | |
230 (if prev (setcdr prev (cdr f)) | |
231 (setq files (cdr files))) | |
232 (setq prev f)) | |
233 (setq f (cdr f))))) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
234 ;; Remove files not matching the inclusion regexp. |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
235 (when nneething-include-files |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
236 (let ((f files) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
237 prev) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
238 (while f |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
239 (if (not (string-match nneething-include-files (car f))) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
240 (if prev (setcdr prev (cdr f)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
241 (setq files (cdr files))) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
242 (setq prev f)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
243 (setq f (cdr f))))) |
17493 | 244 ;; Remove deleted files from the map. |
245 (let ((map nneething-map) | |
246 prev) | |
247 (while map | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
248 (if (and (member (cadr (car map)) files) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
249 ;; We also remove files that have changed mod times. |
17493 | 250 (equal (nth 5 (file-attributes |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
251 (nneething-file-name (cadr (car map))))) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
252 (cadr (cdar map)))) |
17493 | 253 (progn |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
254 (push (cadr (car map)) map-files) |
17493 | 255 (setq prev map)) |
256 (setq touched t) | |
257 (if prev | |
258 (setcdr prev (cdr map)) | |
259 (setq nneething-map (cdr nneething-map)))) | |
260 (setq map (cdr map)))) | |
261 ;; Find all new files and enter them into the map. | |
262 (while files | |
263 (unless (member (car files) map-files) | |
264 ;; This file is not in the map, so we enter it. | |
265 (setq touched t) | |
266 (setcdr nneething-active (1+ (cdr nneething-active))) | |
267 (push (list (cdr nneething-active) (car files) | |
268 (nth 5 (file-attributes | |
269 (nneething-file-name (car files))))) | |
270 nneething-map)) | |
271 (setq files (cdr files))) | |
272 (when (and touched | |
273 (not nneething-read-only)) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
274 (with-temp-file map-file |
17493 | 275 (insert "(setq nneething-map '") |
276 (gnus-prin1 nneething-map) | |
277 (insert ")\n(setq nneething-active '") | |
278 (gnus-prin1 nneething-active) | |
279 (insert ")\n")))))) | |
280 | |
281 (defun nneething-insert-head (file) | |
282 "Insert the head of FILE." | |
283 (when (nneething-get-head file) | |
284 (insert-buffer-substring nneething-work-buffer) | |
285 (goto-char (point-max)))) | |
286 | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
287 (defun nneething-encode-file-name (file &optional coding-system) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
288 "Encode the name of the FILE in CODING-SYSTEM." |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
289 (let ((pos 0) buf) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
290 (setq file (mm-encode-coding-string |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
291 file (or coding-system nnmail-pathname-coding-system))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
292 (while (string-match "[^-0-9a-zA-Z_:/.]" file pos) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
293 (setq buf (cons (format "%%%02x" (aref file (match-beginning 0))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
294 (cons (substring file pos (match-beginning 0)) buf)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
295 pos (match-end 0))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
296 (apply (function concat) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
297 (nreverse (cons (substring file pos) buf))))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
298 |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
299 (defun nneething-decode-file-name (file &optional coding-system) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
300 "Decode the name of the FILE is encoded in CODING-SYSTEM." |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
301 (let ((pos 0) buf) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
302 (while (string-match "%\\([0-9a-fA-F][0-9a-fA-F]\\)" file pos) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
303 (setq buf (cons (string (string-to-number (match-string 1 file) 16)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
304 (cons (substring file pos (match-beginning 0)) buf)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
305 pos (match-end 0))) |
74347 | 306 (mm-decode-coding-string |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
307 (apply (function concat) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
308 (nreverse (cons (substring file pos) buf))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
309 (or coding-system nnmail-pathname-coding-system)))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
310 |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
311 (defun nneething-get-file-name (id) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
312 "Extract the file name from the message ID string." |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
313 (when (string-match "\\`<nneething-\\([^@]+\\)@.*>\\'" id) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
314 (nneething-decode-file-name (match-string 1 id)))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
315 |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
316 (defun nneething-make-head (file &optional buffer extra-msg |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
317 mime-type mime-charset mime-encoding) |
17493 | 318 "Create a head by looking at the file attributes of FILE." |
319 (let ((atts (file-attributes file))) | |
320 (insert | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
321 "Subject: " (file-name-nondirectory file) (or extra-msg "") "\n" |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
322 "Message-ID: <nneething-" (nneething-encode-file-name file) |
17493 | 323 "@" (system-name) ">\n" |
324 (if (equal '(0 0) (nth 5 atts)) "" | |
325 (concat "Date: " (current-time-string (nth 5 atts)) "\n")) | |
326 (or (when buffer | |
327 (save-excursion | |
328 (set-buffer buffer) | |
329 (when (re-search-forward "<[a-zA-Z0-9_]@[-a-zA-Z0-9_]>" 1000 t) | |
330 (concat "From: " (match-string 0) "\n")))) | |
331 (nneething-from-line (nth 2 atts) file)) | |
62907
88db2adda4b7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-339
Miles Bader <miles@gnu.org>
parents:
60696
diff
changeset
|
332 (if (> (string-to-number (int-to-string (nth 7 atts))) 0) |
17493 | 333 (concat "Chars: " (int-to-string (nth 7 atts)) "\n") |
334 "") | |
335 (if buffer | |
336 (save-excursion | |
337 (set-buffer buffer) | |
338 (concat "Lines: " (int-to-string | |
339 (count-lines (point-min) (point-max))) | |
340 "\n")) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
341 "") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
342 (if mime-type |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
343 (concat "Content-Type: " mime-type |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
344 (if mime-charset |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
345 (concat "; charset=" |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
346 (if (stringp mime-charset) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
347 mime-charset |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
348 (symbol-name mime-charset))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
349 "") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
350 (if mime-encoding |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
351 (concat "\nContent-Transfer-Encoding: " mime-encoding) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
352 "") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
353 "\nMIME-Version: 1.0\n") |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
354 "")))) |
17493 | 355 |
356 (defun nneething-from-line (uid &optional file) | |
357 "Return a From header based of UID." | |
358 (let* ((login (condition-case nil | |
359 (user-login-name uid) | |
360 (error | |
361 (cond ((= uid (user-uid)) (user-login-name)) | |
362 ((zerop uid) "root") | |
363 (t (int-to-string uid)))))) | |
364 (name (condition-case nil | |
365 (user-full-name uid) | |
366 (error | |
367 (cond ((= uid (user-uid)) (user-full-name)) | |
368 ((zerop uid) "Ms. Root"))))) | |
369 (host (if (string-match "\\`/[^/@]*@\\([^:/]+\\):" file) | |
370 (prog1 | |
371 (substring file | |
372 (match-beginning 1) | |
373 (match-end 1)) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
374 (when (string-match |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
375 "/\\(users\\|home\\)/\\([^/]+\\)/" file) |
17493 | 376 (setq login (substring file |
377 (match-beginning 2) | |
378 (match-end 2)) | |
379 name nil))) | |
380 (system-name)))) | |
381 (concat "From: " login "@" host | |
382 (if name (concat " (" name ")") "") "\n"))) | |
383 | |
384 (defun nneething-get-head (file) | |
385 "Either find the head in FILE or make a head for FILE." | |
386 (save-excursion | |
387 (set-buffer (get-buffer-create nneething-work-buffer)) | |
388 (setq case-fold-search nil) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
389 (buffer-disable-undo) |
17493 | 390 (erase-buffer) |
391 (cond | |
392 ((not (file-exists-p file)) | |
393 ;; The file do not exist. | |
394 nil) | |
395 ((or (file-directory-p file) | |
396 (file-symlink-p file)) | |
397 ;; It's a dir, so we fudge a head. | |
398 (nneething-make-head file) t) | |
399 (t | |
400 ;; We examine the file. | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
401 (condition-case () |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
402 (progn |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
403 (nnheader-insert-head file) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
404 (if (nnheader-article-p) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
405 (delete-region |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
406 (progn |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
407 (goto-char (point-min)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
408 (or (and (search-forward "\n\n" nil t) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
409 (1- (point))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
410 (point-max))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
411 (point-max)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
412 (goto-char (point-min)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
413 (nneething-make-head file (current-buffer)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
414 (delete-region (point) (point-max)))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
415 (file-error |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
416 (nneething-make-head file (current-buffer) " (unreadable)"))) |
17493 | 417 t)))) |
418 | |
419 (defun nneething-file-name (article) | |
420 "Return the file name of ARTICLE." | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
421 (let ((dir (file-name-as-directory nneething-address)) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
422 fname) |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
423 (if (numberp article) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
424 (if (setq fname (cadr (assq article nneething-map))) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
425 (expand-file-name fname dir) |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
426 (make-temp-name (expand-file-name "nneething" dir))) |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
427 (expand-file-name article dir)))) |
17493 | 428 |
429 (provide 'nneething) | |
430 | |
52401 | 431 ;;; arch-tag: 1277f386-88f2-4459-bb24-f3f45962a6c5 |
17493 | 432 ;;; nneething.el ends here |