Mercurial > hg > xemacs-beta
comparison lisp/gnus/nndoc.el @ 30:ec9a17fef872 r19-15b98
Import from CVS: tag r19-15b98
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:52:29 +0200 |
parents | 1917ad0d78d7 |
children | d620409f5eb8 |
comparison
equal
deleted
inserted
replaced
29:7976500f47f9 | 30:ec9a17fef872 |
---|---|
41 `clari-briefs' or `guess'.") | 41 `clari-briefs' or `guess'.") |
42 | 42 |
43 (defvoo nndoc-post-type 'mail | 43 (defvoo nndoc-post-type 'mail |
44 "*Whether the nndoc group is `mail' or `post'.") | 44 "*Whether the nndoc group is `mail' or `post'.") |
45 | 45 |
46 (defvar nndoc-type-alist | 46 (defvar nndoc-type-alist |
47 `((mmdf | 47 `((mmdf |
48 (article-begin . "^\^A\^A\^A\^A\n") | 48 (article-begin . "^\^A\^A\^A\^A\n") |
49 (body-end . "^\^A\^A\^A\^A\n")) | 49 (body-end . "^\^A\^A\^A\^A\n")) |
50 (news | 50 (news |
51 (article-begin . "^Path:")) | 51 (article-begin . "^Path:")) |
52 (rnews | 52 (rnews |
53 (article-begin . "^#! *rnews +\\([0-9]+\\) *\n") | 53 (article-begin . "^#! *rnews +\\([0-9]+\\) *\n") |
54 (body-end-function . nndoc-rnews-body-end)) | 54 (body-end-function . nndoc-rnews-body-end)) |
55 (mbox | 55 (mbox |
56 (article-begin-function . nndoc-mbox-article-begin) | 56 (article-begin-function . nndoc-mbox-article-begin) |
57 (body-end-function . nndoc-mbox-body-end)) | 57 (body-end-function . nndoc-mbox-body-end)) |
58 (babyl | 58 (babyl |
59 (article-begin . "\^_\^L *\n") | 59 (article-begin . "\^_\^L *\n") |
60 (body-end . "\^_") | 60 (body-end . "\^_") |
61 (body-begin-function . nndoc-babyl-body-begin) | 61 (body-begin-function . nndoc-babyl-body-begin) |
62 (head-begin-function . nndoc-babyl-head-begin)) | 62 (head-begin-function . nndoc-babyl-head-begin)) |
63 (forward | 63 (forward |
106 (body-end . "-------------------------------------------------") | 106 (body-end . "-------------------------------------------------") |
107 (file-end . "^Title: Recent Seminal") | 107 (file-end . "^Title: Recent Seminal") |
108 (generate-head-function . nndoc-generate-lanl-gov-head) | 108 (generate-head-function . nndoc-generate-lanl-gov-head) |
109 (article-transform-function . nndoc-transform-lanl-gov-announce) | 109 (article-transform-function . nndoc-transform-lanl-gov-announce) |
110 (subtype preprints guess)) | 110 (subtype preprints guess)) |
111 (guess | 111 (guess |
112 (guess . t) | 112 (guess . t) |
113 (subtype nil)) | 113 (subtype nil)) |
114 (digest | 114 (digest |
115 (guess . t) | 115 (guess . t) |
116 (subtype nil)) | 116 (subtype nil)) |
188 (set-buffer buffer) | 188 (set-buffer buffer) |
189 (erase-buffer) | 189 (erase-buffer) |
190 (when entry | 190 (when entry |
191 (if (stringp article) | 191 (if (stringp article) |
192 nil | 192 nil |
193 (insert-buffer-substring | 193 (insert-buffer-substring |
194 nndoc-current-buffer (car entry) (nth 1 entry)) | 194 nndoc-current-buffer (car entry) (nth 1 entry)) |
195 (insert "\n") | 195 (insert "\n") |
196 (setq beg (point)) | 196 (setq beg (point)) |
197 (insert-buffer-substring | 197 (insert-buffer-substring |
198 nndoc-current-buffer (nth 2 entry) (nth 3 entry)) | 198 nndoc-current-buffer (nth 2 entry) (nth 3 entry)) |
199 (goto-char beg) | 199 (goto-char beg) |
200 (when nndoc-prepare-body-function | 200 (when nndoc-prepare-body-function |
201 (funcall nndoc-prepare-body-function)) | 201 (funcall nndoc-prepare-body-function)) |
202 (when nndoc-article-transform-function | 202 (when nndoc-article-transform-function |
204 t))))) | 204 t))))) |
205 | 205 |
206 (deffoo nndoc-request-group (group &optional server dont-check) | 206 (deffoo nndoc-request-group (group &optional server dont-check) |
207 "Select news GROUP." | 207 "Select news GROUP." |
208 (let (number) | 208 (let (number) |
209 (cond | 209 (cond |
210 ((not (nndoc-possibly-change-buffer group server)) | 210 ((not (nndoc-possibly-change-buffer group server)) |
211 (nnheader-report 'nndoc "No such file or buffer: %s" | 211 (nnheader-report 'nndoc "No such file or buffer: %s" |
212 nndoc-address)) | 212 nndoc-address)) |
213 (dont-check | 213 (dont-check |
214 (nnheader-report 'nndoc "Selected group %s" group) | 214 (nnheader-report 'nndoc "Selected group %s" group) |
248 | 248 |
249 ;;; Internal functions. | 249 ;;; Internal functions. |
250 | 250 |
251 (defun nndoc-possibly-change-buffer (group source) | 251 (defun nndoc-possibly-change-buffer (group source) |
252 (let (buf) | 252 (let (buf) |
253 (cond | 253 (cond |
254 ;; The current buffer is this group's buffer. | 254 ;; The current buffer is this group's buffer. |
255 ((and nndoc-current-buffer | 255 ((and nndoc-current-buffer |
256 (buffer-name nndoc-current-buffer) | 256 (buffer-name nndoc-current-buffer) |
257 (eq nndoc-current-buffer | 257 (eq nndoc-current-buffer |
258 (setq buf (cdr (assoc group nndoc-group-alist)))))) | 258 (setq buf (cdr (assoc group nndoc-group-alist)))))) |
259 ;; We change buffers by taking an old from the group alist. | 259 ;; We change buffers by taking an old from the group alist. |
260 ;; `source' is either a string (a file name) or a buffer object. | 260 ;; `source' is either a string (a file name) or a buffer object. |
261 (buf | 261 (buf |
262 (setq nndoc-current-buffer buf)) | 262 (setq nndoc-current-buffer buf)) |
263 ;; It's a totally new group. | 263 ;; It's a totally new group. |
264 ((or (and (bufferp nndoc-address) | 264 ((or (and (bufferp nndoc-address) |
265 (buffer-name nndoc-address)) | 265 (buffer-name nndoc-address)) |
266 (and (stringp nndoc-address) | 266 (and (stringp nndoc-address) |
267 (file-exists-p nndoc-address) | 267 (file-exists-p nndoc-address) |
268 (not (file-directory-p nndoc-address)))) | 268 (not (file-directory-p nndoc-address)))) |
269 (push (cons group (setq nndoc-current-buffer | 269 (push (cons group (setq nndoc-current-buffer |
270 (get-buffer-create | 270 (get-buffer-create |
271 (concat " *nndoc " group "*")))) | 271 (concat " *nndoc " group "*")))) |
272 nndoc-group-alist) | 272 nndoc-group-alist) |
273 (setq nndoc-dissection-alist nil) | 273 (setq nndoc-dissection-alist nil) |
274 (save-excursion | 274 (save-excursion |
275 (set-buffer nndoc-current-buffer) | 275 (set-buffer nndoc-current-buffer) |
294 ;;; Deciding what document type we have | 294 ;;; Deciding what document type we have |
295 ;;; | 295 ;;; |
296 | 296 |
297 (defun nndoc-set-delims () | 297 (defun nndoc-set-delims () |
298 "Set the nndoc delimiter variables according to the type of the document." | 298 "Set the nndoc delimiter variables according to the type of the document." |
299 (let ((vars '(nndoc-file-begin | 299 (let ((vars '(nndoc-file-begin |
300 nndoc-first-article | 300 nndoc-first-article |
301 nndoc-article-end nndoc-head-begin nndoc-head-end | 301 nndoc-article-end nndoc-head-begin nndoc-head-end |
302 nndoc-file-end nndoc-article-begin | 302 nndoc-file-end nndoc-article-begin |
303 nndoc-body-begin nndoc-body-end-function nndoc-body-end | 303 nndoc-body-begin nndoc-body-end-function nndoc-body-end |
304 nndoc-prepare-body-function nndoc-article-transform-function | 304 nndoc-prepare-body-function nndoc-article-transform-function |
305 nndoc-generate-head-function nndoc-body-begin-function | 305 nndoc-generate-head-function nndoc-body-begin-function |
306 nndoc-head-begin-function))) | 306 nndoc-head-begin-function))) |
307 (while vars | 307 (while vars |
308 (set (pop vars) nil))) | 308 (set (pop vars) nil))) |
309 (let (defs) | 309 (let (defs) |
310 ;; Guess away until we find the real file type. | 310 ;; Guess away until we find the real file type. |
311 (while (assq 'guess (setq defs (cdr (assq nndoc-article-type | 311 (while (assq 'guess (setq defs (cdr (assq nndoc-article-type |
312 nndoc-type-alist)))) | 312 nndoc-type-alist)))) |
313 (setq nndoc-article-type (nndoc-guess-type nndoc-article-type))) | 313 (setq nndoc-article-type (nndoc-guess-type nndoc-article-type))) |
314 ;; Set the nndoc variables. | 314 ;; Set the nndoc variables. |
315 (while defs | 315 (while defs |
316 (set (intern (format "nndoc-%s" (caar defs))) | 316 (set (intern (format "nndoc-%s" (caar defs))) |
322 (while (and (not result) | 322 (while (and (not result) |
323 (setq entry (pop alist))) | 323 (setq entry (pop alist))) |
324 (when (memq subtype (or (cdr (assq 'subtype entry)) '(guess))) | 324 (when (memq subtype (or (cdr (assq 'subtype entry)) '(guess))) |
325 (goto-char (point-min)) | 325 (goto-char (point-min)) |
326 (when (numberp (setq result (funcall (intern | 326 (when (numberp (setq result (funcall (intern |
327 (format "nndoc-%s-type-p" | 327 (format "nndoc-%s-type-p" |
328 (car entry)))))) | 328 (car entry)))))) |
329 (push (cons result entry) results) | 329 (push (cons result entry) results) |
330 (setq result nil)))) | 330 (setq result nil)))) |
331 (unless (or result results) | 331 (unless (or result results) |
332 (error "Document is not of any recognized type")) | 332 (error "Document is not of any recognized type")) |
333 (if result | 333 (if result |
334 (car entry) | 334 (car entry) |
335 (cadar (sort results (lambda (r1 r2) (< (car r1) (car r2)))))))) | 335 (cadar (sort results (lambda (r1 r2) (< (car r1) (car r2)))))))) |
336 | 336 |
337 ;;; | 337 ;;; |
338 ;;; Built-in type predicates and functions | 338 ;;; Built-in type predicates and functions |
339 ;;; | 339 ;;; |
340 | 340 |
341 (defun nndoc-mbox-type-p () | 341 (defun nndoc-mbox-type-p () |
342 (when (looking-at message-unix-mail-delimiter) | 342 (when (looking-at message-unix-mail-delimiter) |
349 (defun nndoc-mbox-body-end () | 349 (defun nndoc-mbox-body-end () |
350 (let ((beg (point)) | 350 (let ((beg (point)) |
351 len end) | 351 len end) |
352 (when | 352 (when |
353 (save-excursion | 353 (save-excursion |
354 (and (re-search-backward | 354 (and (re-search-backward |
355 (concat "^" message-unix-mail-delimiter) nil t) | 355 (concat "^" message-unix-mail-delimiter) nil t) |
356 (setq end (point)) | 356 (setq end (point)) |
357 (search-forward "\n\n" beg t) | 357 (search-forward "\n\n" beg t) |
358 (re-search-backward | 358 (re-search-backward |
359 "^Content-Length:[ \t]*\\([0-9]+\\) *$" end t) | 359 "^Content-Length:[ \t]*\\([0-9]+\\) *$" end t) |
470 (cons 'file-end (concat "\n--" boundary-id "--[ \t]*$")))) | 470 (cons 'file-end (concat "\n--" boundary-id "--[ \t]*$")))) |
471 t))) | 471 t))) |
472 | 472 |
473 (defun nndoc-standard-digest-type-p () | 473 (defun nndoc-standard-digest-type-p () |
474 (when (and (re-search-forward (concat "^" (make-string 70 ?-) "\n\n") nil t) | 474 (when (and (re-search-forward (concat "^" (make-string 70 ?-) "\n\n") nil t) |
475 (re-search-forward | 475 (re-search-forward |
476 (concat "\n\n" (make-string 30 ?-) "\n\n") nil t)) | 476 (concat "\n\n" (make-string 30 ?-) "\n\n") nil t)) |
477 t)) | 477 t)) |
478 | 478 |
479 (defun nndoc-digest-body-end () | 479 (defun nndoc-digest-body-end () |
480 (and (re-search-forward nndoc-article-begin nil t) | 480 (and (re-search-forward nndoc-article-begin nil t) |
493 (when (re-search-backward "^\\\\\\\\ +(\\([^ ]*\\) , *\\([^ ]*\\))" nil t) | 493 (when (re-search-backward "^\\\\\\\\ +(\\([^ ]*\\) , *\\([^ ]*\\))" nil t) |
494 (replace-match "\n\nGet it at \\1 (\\2)" t nil)) | 494 (replace-match "\n\nGet it at \\1 (\\2)" t nil)) |
495 ;; (when (re-search-backward "^\\\\\\\\$" nil t) | 495 ;; (when (re-search-backward "^\\\\\\\\$" nil t) |
496 ;; (replace-match "" t t)) | 496 ;; (replace-match "" t t)) |
497 ) | 497 ) |
498 | 498 |
499 (defun nndoc-generate-lanl-gov-head (article) | 499 (defun nndoc-generate-lanl-gov-head (article) |
500 (let ((entry (cdr (assq article nndoc-dissection-alist))) | 500 (let ((entry (cdr (assq article nndoc-dissection-alist))) |
501 (e-mail "no address given") | 501 (e-mail "no address given") |
502 subject from) | 502 subject from) |
503 (save-excursion | 503 (save-excursion |
516 )) | 516 )) |
517 (while (and from (string-match "(\[^)\]*)" from)) | 517 (while (and from (string-match "(\[^)\]*)" from)) |
518 (setq from (replace-match "" t t from))) | 518 (setq from (replace-match "" t t from))) |
519 (insert "From: " (or from "unknown") | 519 (insert "From: " (or from "unknown") |
520 "\nSubject: " (or subject "(no subject)") "\n"))) | 520 "\nSubject: " (or subject "(no subject)") "\n"))) |
521 | 521 |
522 | 522 |
523 | 523 |
524 ;;; | 524 ;;; |
525 ;;; Functions for dissecting the documents | 525 ;;; Functions for dissecting the documents |
526 ;;; | 526 ;;; |
547 (nndoc-search nndoc-first-article) | 547 (nndoc-search nndoc-first-article) |
548 (nndoc-article-begin)) | 548 (nndoc-article-begin)) |
549 (setq first nil) | 549 (setq first nil) |
550 (cond (nndoc-head-begin-function | 550 (cond (nndoc-head-begin-function |
551 (funcall nndoc-head-begin-function)) | 551 (funcall nndoc-head-begin-function)) |
552 (nndoc-head-begin | 552 (nndoc-head-begin |
553 (nndoc-search nndoc-head-begin))) | 553 (nndoc-search nndoc-head-begin))) |
554 (if (or (>= (point) (point-max)) | 554 (if (or (>= (point) (point-max)) |
555 (and nndoc-file-end | 555 (and nndoc-file-end |
556 (looking-at nndoc-file-end))) | 556 (looking-at nndoc-file-end))) |
557 (goto-char (point-max)) | 557 (goto-char (point-max)) |