Mercurial > emacs
annotate lisp/gnus/nneething.el @ 111731:8071f778f77e
nnimap.el (nnimap-request-set-mark): Remove left over.
nnimap.el (nnimap-get-groups): Allow non-quoted strings as mailbox names.
author | Katsumi Yamaoka <yamaoka@jpl.org> |
---|---|
date | Fri, 26 Nov 2010 11:03:16 +0000 |
parents | 93e093c035a0 |
children | 417b1e4d63cd |
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, |
106815 | 4 ;; 2004, 2005, 2006, 2007, 2008, 2009, 2010 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 | |
94662
f42ef85caf91
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
12 ;; GNU Emacs is free software: you can redistribute it and/or modify |
17493 | 13 ;; it under the terms of the GNU General Public License as published by |
94662
f42ef85caf91
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
14 ;; the Free Software Foundation, either version 3 of the License, or |
f42ef85caf91
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
15 ;; (at your option) any later version. |
17493 | 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 | |
94662
f42ef85caf91
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
17493 | 24 |
25 ;;; Commentary: | |
26 | |
27 ;;; Code: | |
28 | |
19522
681265352f07
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
29 (eval-when-compile (require 'cl)) |
681265352f07
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
30 |
107427
ecbe0edc4f69
Stop message.el from loading about 40 libraries it doesn't always need.
Glenn Morris <rgm@gnu.org>
parents:
106815
diff
changeset
|
31 (require 'mailcap) |
17493 | 32 (require 'nnheader) |
33 (require 'nnmail) | |
34 (require 'nnoo) | |
35 (require 'gnus-util) | |
36 | |
37 (nnoo-declare nneething) | |
38 | |
60696
7503b2a24a3c
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-187
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
39 (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
|
40 (nnheader-concat gnus-directory ".nneething/") |
17493 | 41 "Where nneething stores the map files.") |
42 | |
43 (defvoo nneething-map-file ".nneething" | |
44 "Name of the map files.") | |
45 | |
46 (defvoo nneething-exclude-files nil | |
47 "Regexp saying what files to exclude from the group. | |
48 If this variable is nil, no files will be excluded.") | |
49 | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
50 (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
|
51 "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
|
52 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
|
53 included.") |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
54 |
17493 | 55 |
56 | |
57 ;;; Internal variables. | |
58 | |
59 (defconst nneething-version "nneething 1.0" | |
60 "nneething version.") | |
61 | |
62 (defvoo nneething-current-directory nil | |
63 "Current news group directory.") | |
64 | |
65 (defvoo nneething-status-string "") | |
66 | |
67 (defvoo nneething-work-buffer " *nneething work*") | |
68 | |
69 (defvoo nneething-group nil) | |
70 (defvoo nneething-map nil) | |
71 (defvoo nneething-read-only nil) | |
72 (defvoo nneething-active nil) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19522
diff
changeset
|
73 (defvoo nneething-address nil) |
17493 | 74 |
75 | |
76 | |
77 ;;; Interface functions. | |
78 | |
79 (nnoo-define-basics nneething) | |
80 | |
81 (deffoo nneething-retrieve-headers (articles &optional group server fetch-old) | |
82 (nneething-possibly-change-directory group) | |
83 | |
110410
f2e111723c3a
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110102
diff
changeset
|
84 (with-current-buffer nntp-server-buffer |
17493 | 85 (erase-buffer) |
86 (let* ((number (length articles)) | |
87 (count 0) | |
88 (large (and (numberp nnmail-large-newsgroup) | |
89 (> number nnmail-large-newsgroup))) | |
90 article file) | |
91 | |
92 (if (stringp (car articles)) | |
93 'headers | |
94 | |
95 (while (setq article (pop articles)) | |
96 (setq file (nneething-file-name article)) | |
97 | |
98 (when (and (file-exists-p file) | |
99 (or (file-directory-p file) | |
100 (not (zerop (nnheader-file-size file))))) | |
101 (insert (format "221 %d Article retrieved.\n" article)) | |
102 (nneething-insert-head file) | |
103 (insert ".\n")) | |
104 | |
105 (incf count) | |
106 | |
107 (and large | |
108 (zerop (% count 20)) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19522
diff
changeset
|
109 (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
|
110 (/ (* count 100) number)))) |
17493 | 111 |
112 (when large | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19522
diff
changeset
|
113 (nnheader-message 5 "nneething: Receiving headers...done")) |
17493 | 114 |
115 (nnheader-fold-continuation-lines) | |
116 'headers)))) | |
117 | |
118 (deffoo nneething-request-article (id &optional group server buffer) | |
119 (nneething-possibly-change-directory group) | |
120 (let ((file (unless (stringp id) | |
121 (nneething-file-name id))) | |
122 (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
|
123 (and (stringp file) ; We did not request by Message-ID. |
17493 | 124 (file-exists-p file) ; The file exists. |
125 (not (file-directory-p file)) ; It's not a dir. | |
126 (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
|
127 (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
|
128 (nnmail-find-file file)) ; Insert the file in the nntp buf. |
17493 | 129 (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
|
130 (let ((type |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
131 (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
|
132 (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
|
133 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
|
134 "text/plain"))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
135 (charset |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
136 (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
|
137 (encoding)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
138 (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
|
139 (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
|
140 (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
|
141 (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
|
142 (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
|
143 nil type charset encoding)) |
17493 | 144 (insert "\n")) |
145 t)))) | |
146 | |
110422
93e093c035a0
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110410
diff
changeset
|
147 (deffoo nneething-request-group (group &optional server dont-check info) |
17493 | 148 (nneething-possibly-change-directory group server) |
149 (unless dont-check | |
150 (nneething-create-mapping) | |
151 (if (> (car nneething-active) (cdr nneething-active)) | |
152 (nnheader-insert "211 0 1 0 %s\n" group) | |
153 (nnheader-insert | |
154 "211 %d %d %d %s\n" | |
155 (- (1+ (cdr nneething-active)) (car nneething-active)) | |
156 (car nneething-active) (cdr nneething-active) | |
157 group))) | |
158 t) | |
159 | |
160 (deffoo nneething-request-list (&optional server dir) | |
161 (nnheader-report 'nneething "LIST is not implemented.")) | |
162 | |
163 (deffoo nneething-request-newgroups (date &optional server) | |
164 (nnheader-report 'nneething "NEWSGROUPS is not implemented.")) | |
165 | |
166 (deffoo nneething-request-type (group &optional article) | |
167 'unknown) | |
168 | |
169 (deffoo nneething-close-group (group &optional server) | |
170 (setq nneething-current-directory nil) | |
171 t) | |
172 | |
173 (deffoo nneething-open-server (server &optional defs) | |
174 (nnheader-init-server-buffer) | |
175 (if (nneething-server-opened server) | |
176 t | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19522
diff
changeset
|
177 (unless (assq 'nneething-address defs) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19522
diff
changeset
|
178 (setq defs (append defs (list (list 'nneething-address server))))) |
17493 | 179 (nnoo-change-server 'nneething server defs))) |
180 | |
181 | |
182 ;;; Internal functions. | |
183 | |
184 (defun nneething-possibly-change-directory (group &optional server) | |
185 (when (and server | |
186 (not (nneething-server-opened server))) | |
187 (nneething-open-server server)) | |
188 (when (and group | |
189 (not (equal nneething-group group))) | |
190 (setq nneething-group group) | |
191 (setq nneething-map nil) | |
192 (setq nneething-active (cons 1 0)) | |
193 (nneething-create-mapping))) | |
194 | |
195 (defun nneething-map-file () | |
196 ;; We make sure that the .nneething directory exists. | |
197 (gnus-make-directory nneething-map-file-directory) | |
198 ;; We store it in a special directory under the user's home dir. | |
199 (concat (file-name-as-directory nneething-map-file-directory) | |
200 nneething-group nneething-map-file)) | |
201 | |
202 (defun nneething-create-mapping () | |
203 ;; 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
|
204 (when (file-exists-p nneething-address) |
17493 | 205 (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
|
206 (files (directory-files nneething-address)) |
17493 | 207 touched map-files) |
208 (when (file-exists-p map-file) | |
209 (ignore-errors | |
210 (load map-file nil t t))) | |
211 (unless nneething-active | |
212 (setq nneething-active (cons 1 0))) | |
213 ;; Old nneething had a different map format. | |
214 (when (and (cdar nneething-map) | |
215 (atom (cdar nneething-map))) | |
216 (setq nneething-map | |
217 (mapcar (lambda (n) | |
218 (list (cdr n) (car n) | |
219 (nth 5 (file-attributes | |
220 (nneething-file-name (car n)))))) | |
221 nneething-map))) | |
222 ;; Remove files matching the exclusion regexp. | |
223 (when nneething-exclude-files | |
224 (let ((f files) | |
225 prev) | |
226 (while f | |
227 (if (string-match nneething-exclude-files (car f)) | |
228 (if prev (setcdr prev (cdr f)) | |
229 (setq files (cdr files))) | |
230 (setq prev f)) | |
231 (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
|
232 ;; 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
|
233 (when nneething-include-files |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
234 (let ((f files) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
235 prev) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
236 (while f |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
237 (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
|
238 (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
|
239 (setq files (cdr files))) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
240 (setq prev f)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
241 (setq f (cdr f))))) |
17493 | 242 ;; Remove deleted files from the map. |
243 (let ((map nneething-map) | |
244 prev) | |
245 (while map | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
246 (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
|
247 ;; We also remove files that have changed mod times. |
17493 | 248 (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
|
249 (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
|
250 (cadr (cdar map)))) |
17493 | 251 (progn |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
252 (push (cadr (car map)) map-files) |
17493 | 253 (setq prev map)) |
254 (setq touched t) | |
255 (if prev | |
256 (setcdr prev (cdr map)) | |
257 (setq nneething-map (cdr nneething-map)))) | |
258 (setq map (cdr map)))) | |
259 ;; Find all new files and enter them into the map. | |
260 (while files | |
261 (unless (member (car files) map-files) | |
262 ;; This file is not in the map, so we enter it. | |
263 (setq touched t) | |
264 (setcdr nneething-active (1+ (cdr nneething-active))) | |
265 (push (list (cdr nneething-active) (car files) | |
266 (nth 5 (file-attributes | |
267 (nneething-file-name (car files))))) | |
268 nneething-map)) | |
269 (setq files (cdr files))) | |
270 (when (and touched | |
271 (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
|
272 (with-temp-file map-file |
17493 | 273 (insert "(setq nneething-map '") |
274 (gnus-prin1 nneething-map) | |
275 (insert ")\n(setq nneething-active '") | |
276 (gnus-prin1 nneething-active) | |
277 (insert ")\n")))))) | |
278 | |
279 (defun nneething-insert-head (file) | |
280 "Insert the head of FILE." | |
281 (when (nneething-get-head file) | |
282 (insert-buffer-substring nneething-work-buffer) | |
283 (goto-char (point-max)))) | |
284 | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
285 (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
|
286 "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
|
287 (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
|
288 (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
|
289 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
|
290 (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
|
291 (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
|
292 (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
|
293 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
|
294 (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
|
295 (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
|
296 |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
297 (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
|
298 "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
|
299 (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
|
300 (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
|
301 (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
|
302 (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
|
303 pos (match-end 0))) |
74347 | 304 (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
|
305 (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
|
306 (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
|
307 (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
|
308 |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
309 (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
|
310 "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
|
311 (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
|
312 (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
|
313 |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
314 (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
|
315 mime-type mime-charset mime-encoding) |
17493 | 316 "Create a head by looking at the file attributes of FILE." |
317 (let ((atts (file-attributes file))) | |
318 (insert | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
319 "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
|
320 "Message-ID: <nneething-" (nneething-encode-file-name file) |
17493 | 321 "@" (system-name) ">\n" |
322 (if (equal '(0 0) (nth 5 atts)) "" | |
323 (concat "Date: " (current-time-string (nth 5 atts)) "\n")) | |
324 (or (when buffer | |
110410
f2e111723c3a
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110102
diff
changeset
|
325 (with-current-buffer buffer |
17493 | 326 (when (re-search-forward "<[a-zA-Z0-9_]@[-a-zA-Z0-9_]>" 1000 t) |
327 (concat "From: " (match-string 0) "\n")))) | |
328 (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
|
329 (if (> (string-to-number (int-to-string (nth 7 atts))) 0) |
17493 | 330 (concat "Chars: " (int-to-string (nth 7 atts)) "\n") |
331 "") | |
332 (if buffer | |
110410
f2e111723c3a
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110102
diff
changeset
|
333 (with-current-buffer buffer |
17493 | 334 (concat "Lines: " (int-to-string |
335 (count-lines (point-min) (point-max))) | |
336 "\n")) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
337 "") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
338 (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
|
339 (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
|
340 (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
|
341 (concat "; charset=" |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
342 (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
|
343 mime-charset |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
344 (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
|
345 "") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
346 (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
|
347 (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
|
348 "") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
349 "\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
|
350 "")))) |
17493 | 351 |
352 (defun nneething-from-line (uid &optional file) | |
353 "Return a From header based of UID." | |
354 (let* ((login (condition-case nil | |
355 (user-login-name uid) | |
356 (error | |
357 (cond ((= uid (user-uid)) (user-login-name)) | |
358 ((zerop uid) "root") | |
359 (t (int-to-string uid)))))) | |
360 (name (condition-case nil | |
361 (user-full-name uid) | |
362 (error | |
363 (cond ((= uid (user-uid)) (user-full-name)) | |
364 ((zerop uid) "Ms. Root"))))) | |
365 (host (if (string-match "\\`/[^/@]*@\\([^:/]+\\):" file) | |
366 (prog1 | |
367 (substring file | |
368 (match-beginning 1) | |
369 (match-end 1)) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
370 (when (string-match |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
371 "/\\(users\\|home\\)/\\([^/]+\\)/" file) |
17493 | 372 (setq login (substring file |
373 (match-beginning 2) | |
374 (match-end 2)) | |
375 name nil))) | |
376 (system-name)))) | |
377 (concat "From: " login "@" host | |
378 (if name (concat " (" name ")") "") "\n"))) | |
379 | |
380 (defun nneething-get-head (file) | |
381 "Either find the head in FILE or make a head for FILE." | |
110410
f2e111723c3a
Merge changes made in Gnus trunk.
Katsumi Yamaoka <yamaoka@jpl.org>
parents:
110102
diff
changeset
|
382 (with-current-buffer (get-buffer-create nneething-work-buffer) |
17493 | 383 (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
|
384 (buffer-disable-undo) |
17493 | 385 (erase-buffer) |
386 (cond | |
387 ((not (file-exists-p file)) | |
388 ;; The file do not exist. | |
389 nil) | |
390 ((or (file-directory-p file) | |
391 (file-symlink-p file)) | |
392 ;; It's a dir, so we fudge a head. | |
393 (nneething-make-head file) t) | |
394 (t | |
395 ;; 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
|
396 (condition-case () |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
397 (progn |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
398 (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
|
399 (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
|
400 (delete-region |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
401 (progn |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
402 (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
|
403 (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
|
404 (1- (point))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
405 (point-max))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
406 (point-max)) |
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 (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
|
409 (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
|
410 (file-error |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
411 (nneething-make-head file (current-buffer) " (unreadable)"))) |
17493 | 412 t)))) |
413 | |
414 (defun nneething-file-name (article) | |
415 "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
|
416 (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
|
417 fname) |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
418 (if (numberp article) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
419 (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
|
420 (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
|
421 (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
|
422 (expand-file-name article dir)))) |
17493 | 423 |
424 (provide 'nneething) | |
425 | |
426 ;;; nneething.el ends here |