comparison lisp/gnus/nneething.el @ 89971:cce1c0ee76ee

Revision: miles@gnu.org--gnu-2004/emacs--unicode--0--patch-36 Merge from emacs--cvs-trunk--0, emacs--gnus--5.10, gnus--rel--5.10 Patches applied: * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523 Merge from emacs--gnus--5.10, gnus--rel--5.10 * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-524 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-534 Update from CVS * miles@gnu.org--gnu-2004/emacs--gnus--5.10--base-0 tag of miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-464 * miles@gnu.org--gnu-2004/emacs--gnus--5.10--patch-1 Import from CVS branch gnus-5_10-branch * miles@gnu.org--gnu-2004/emacs--gnus--5.10--patch-2 Merge from lorentey@elte.hu--2004/emacs--multi-tty--0, emacs--cvs-trunk--0 * miles@gnu.org--gnu-2004/emacs--gnus--5.10--patch-3 Merge from gnus--rel--5.10 * miles@gnu.org--gnu-2004/emacs--gnus--5.10--patch-4 Merge from gnus--rel--5.10 * miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-18 Update from CVS * miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-19 Remove autoconf-generated files from archive * miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-20 Update from CVS
author Miles Bader <miles@gnu.org>
date Thu, 09 Sep 2004 09:36:36 +0000
parents 561b856c5b1f 55fd4f77387a
children 30ad2795fdab
comparison
equal deleted inserted replaced
89970:a849e5779b8c 89971:cce1c0ee76ee
1 ;;; nneething.el --- arbitrary file access for Gnus 1 ;;; nneething.el --- arbitrary file access for Gnus
2 2
3 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000 3 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
4 ;; Free Software Foundation, Inc. 4 ;; Free Software Foundation, Inc.
5 5
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> 6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Masanobu UMEDA <umerin@flab.flab.fujitsu.junet> 7 ;; Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
8 ;; Keywords: news, mail 8 ;; Keywords: news, mail
9 9
10 ;; This file is part of GNU Emacs. 10 ;; This file is part of GNU Emacs.
11 11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify 12 ;; GNU Emacs is free software; you can redistribute it and/or modify
62 (defvoo nneething-current-directory nil 62 (defvoo nneething-current-directory nil
63 "Current news group directory.") 63 "Current news group directory.")
64 64
65 (defvoo nneething-status-string "") 65 (defvoo nneething-status-string "")
66 66
67 (defvoo nneething-message-id-number 0)
68 (defvoo nneething-work-buffer " *nneething work*") 67 (defvoo nneething-work-buffer " *nneething work*")
69 68
70 (defvoo nneething-group nil) 69 (defvoo nneething-group nil)
71 (defvoo nneething-map nil) 70 (defvoo nneething-map nil)
72 (defvoo nneething-read-only nil) 71 (defvoo nneething-read-only nil)
120 (deffoo nneething-request-article (id &optional group server buffer) 119 (deffoo nneething-request-article (id &optional group server buffer)
121 (nneething-possibly-change-directory group) 120 (nneething-possibly-change-directory group)
122 (let ((file (unless (stringp id) 121 (let ((file (unless (stringp id)
123 (nneething-file-name id))) 122 (nneething-file-name id)))
124 (nntp-server-buffer (or buffer nntp-server-buffer))) 123 (nntp-server-buffer (or buffer nntp-server-buffer)))
125 (and (stringp file) ; We did not request by Message-ID. 124 (and (stringp file) ; We did not request by Message-ID.
126 (file-exists-p file) ; The file exists. 125 (file-exists-p file) ; The file exists.
127 (not (file-directory-p file)) ; It's not a dir. 126 (not (file-directory-p file)) ; It's not a dir.
128 (save-excursion 127 (save-excursion
129 (nnmail-find-file file) ; Insert the file in the nntp buf. 128 (let ((nnmail-file-coding-system 'binary))
129 (nnmail-find-file file)) ; Insert the file in the nntp buf.
130 (unless (nnheader-article-p) ; Either it's a real article... 130 (unless (nnheader-article-p) ; Either it's a real article...
131 (goto-char (point-min)) 131 (let ((type
132 (nneething-make-head 132 (unless (file-directory-p file)
133 file (current-buffer)) ; ... or we fake some headers. 133 (or (cdr (assoc (concat "." (file-name-extension file))
134 mailcap-mime-extensions))
135 "text/plain")))
136 (charset
137 (mm-detect-mime-charset-region (point-min) (point-max)))
138 (encoding))
139 (unless (string-match "\\`text/" type)
140 (base64-encode-region (point-min) (point-max))
141 (setq encoding "base64"))
142 (goto-char (point-min))
143 (nneething-make-head file (current-buffer)
144 nil type charset encoding))
134 (insert "\n")) 145 (insert "\n"))
135 t)))) 146 t))))
136 147
137 (deffoo nneething-request-group (group &optional server dont-check) 148 (deffoo nneething-request-group (group &optional server dont-check)
138 (nneething-possibly-change-directory group server) 149 (nneething-possibly-change-directory group server)
232 ;; Remove deleted files from the map. 243 ;; Remove deleted files from the map.
233 (let ((map nneething-map) 244 (let ((map nneething-map)
234 prev) 245 prev)
235 (while map 246 (while map
236 (if (and (member (cadr (car map)) files) 247 (if (and (member (cadr (car map)) files)
237 ;; We also remove files that have changed mod times. 248 ;; We also remove files that have changed mod times.
238 (equal (nth 5 (file-attributes 249 (equal (nth 5 (file-attributes
239 (nneething-file-name (cadr (car map))))) 250 (nneething-file-name (cadr (car map)))))
240 (cadr (cdar map)))) 251 (cadr (cdar map))))
241 (progn 252 (progn
242 (push (cadr (car map)) map-files) 253 (push (cadr (car map)) map-files)
270 "Insert the head of FILE." 281 "Insert the head of FILE."
271 (when (nneething-get-head file) 282 (when (nneething-get-head file)
272 (insert-buffer-substring nneething-work-buffer) 283 (insert-buffer-substring nneething-work-buffer)
273 (goto-char (point-max)))) 284 (goto-char (point-max))))
274 285
275 (defun nneething-make-head (file &optional buffer) 286 (defun nneething-encode-file-name (file &optional coding-system)
287 "Encode the name of the FILE in CODING-SYSTEM."
288 (let ((pos 0) buf)
289 (setq file (mm-encode-coding-string
290 file (or coding-system nnmail-pathname-coding-system)))
291 (while (string-match "[^-0-9a-zA-Z_:/.]" file pos)
292 (setq buf (cons (format "%%%02x" (aref file (match-beginning 0)))
293 (cons (substring file pos (match-beginning 0)) buf))
294 pos (match-end 0)))
295 (apply (function concat)
296 (nreverse (cons (substring file pos) buf)))))
297
298 (defun nneething-decode-file-name (file &optional coding-system)
299 "Decode the name of the FILE is encoded in CODING-SYSTEM."
300 (let ((pos 0) buf)
301 (while (string-match "%\\([0-9a-fA-F][0-9a-fA-F]\\)" file pos)
302 (setq buf (cons (string (string-to-number (match-string 1 file) 16))
303 (cons (substring file pos (match-beginning 0)) buf))
304 pos (match-end 0)))
305 (decode-coding-string
306 (apply (function concat)
307 (nreverse (cons (substring file pos) buf)))
308 (or coding-system nnmail-pathname-coding-system))))
309
310 (defun nneething-get-file-name (id)
311 "Extract the file name from the message ID string."
312 (when (string-match "\\`<nneething-\\([^@]+\\)@.*>\\'" id)
313 (nneething-decode-file-name (match-string 1 id))))
314
315 (defun nneething-make-head (file &optional buffer extra-msg
316 mime-type mime-charset mime-encoding)
276 "Create a head by looking at the file attributes of FILE." 317 "Create a head by looking at the file attributes of FILE."
277 (let ((atts (file-attributes file))) 318 (let ((atts (file-attributes file)))
278 (insert 319 (insert
279 "Subject: " (file-name-nondirectory file) "\n" 320 "Subject: " (file-name-nondirectory file) (or extra-msg "") "\n"
280 "Message-ID: <nneething-" 321 "Message-ID: <nneething-" (nneething-encode-file-name file)
281 (int-to-string (incf nneething-message-id-number))
282 "@" (system-name) ">\n" 322 "@" (system-name) ">\n"
283 (if (equal '(0 0) (nth 5 atts)) "" 323 (if (equal '(0 0) (nth 5 atts)) ""
284 (concat "Date: " (current-time-string (nth 5 atts)) "\n")) 324 (concat "Date: " (current-time-string (nth 5 atts)) "\n"))
285 (or (when buffer 325 (or (when buffer
286 (save-excursion 326 (save-excursion
295 (save-excursion 335 (save-excursion
296 (set-buffer buffer) 336 (set-buffer buffer)
297 (concat "Lines: " (int-to-string 337 (concat "Lines: " (int-to-string
298 (count-lines (point-min) (point-max))) 338 (count-lines (point-min) (point-max)))
299 "\n")) 339 "\n"))
340 "")
341 (if mime-type
342 (concat "Content-Type: " mime-type
343 (if mime-charset
344 (concat "; charset="
345 (if (stringp mime-charset)
346 mime-charset
347 (symbol-name mime-charset)))
348 "")
349 (if mime-encoding
350 (concat "\nContent-Transfer-Encoding: " mime-encoding)
351 "")
352 "\nMIME-Version: 1.0\n")
300 "")))) 353 ""))))
301 354
302 (defun nneething-from-line (uid &optional file) 355 (defun nneething-from-line (uid &optional file)
303 "Return a From header based of UID." 356 "Return a From header based of UID."
304 (let* ((login (condition-case nil 357 (let* ((login (condition-case nil
342 (file-symlink-p file)) 395 (file-symlink-p file))
343 ;; It's a dir, so we fudge a head. 396 ;; It's a dir, so we fudge a head.
344 (nneething-make-head file) t) 397 (nneething-make-head file) t)
345 (t 398 (t
346 ;; We examine the file. 399 ;; We examine the file.
347 (nnheader-insert-head file) 400 (condition-case ()
348 (if (nnheader-article-p) 401 (progn
349 (delete-region 402 (nnheader-insert-head file)
350 (progn 403 (if (nnheader-article-p)
351 (goto-char (point-min)) 404 (delete-region
352 (or (and (search-forward "\n\n" nil t) 405 (progn
353 (1- (point))) 406 (goto-char (point-min))
354 (point-max))) 407 (or (and (search-forward "\n\n" nil t)
355 (point-max)) 408 (1- (point)))
356 (goto-char (point-min)) 409 (point-max)))
357 (nneething-make-head file (current-buffer)) 410 (point-max))
358 (delete-region (point) (point-max))) 411 (goto-char (point-min))
412 (nneething-make-head file (current-buffer))
413 (delete-region (point) (point-max))))
414 (file-error
415 (nneething-make-head file (current-buffer) " (unreadable)")))
359 t)))) 416 t))))
360 417
361 (defun nneething-file-name (article) 418 (defun nneething-file-name (article)
362 "Return the file name of ARTICLE." 419 "Return the file name of ARTICLE."
363 (let ((dir (file-name-as-directory nneething-address)) 420 (let ((dir (file-name-as-directory nneething-address))
364 fname) 421 fname)
365 (if (numberp article) 422 (if (numberp article)
366 (if (setq fname (cadr (assq article nneething-map))) 423 (if (setq fname (cadr (assq article nneething-map)))
367 (expand-file-name fname dir) 424 (expand-file-name fname dir)
368 (mm-make-temp-file (expand-file-name "nneething" dir))) 425 (mm-make-temp-file (expand-file-name "nneething" dir)))
369 (expand-file-name article dir)))) 426 (expand-file-name article dir))))