Mercurial > emacs
comparison lisp/gnus/nnwarchive.el @ 88155:d7ddb3e565de
sync with trunk
author | Henrik Enberg <henrik.enberg@telia.com> |
---|---|
date | Mon, 16 Jan 2006 00:03:54 +0000 |
parents | 0d8b17d428b5 |
children |
comparison
equal
deleted
inserted
replaced
88154:8ce476d3ba36 | 88155:d7ddb3e565de |
---|---|
1 ;;; nnwarchive.el --- interfacing with web archives | 1 ;;; nnwarchive.el --- interfacing with web archives |
2 ;; Copyright (C) 1999, 2000 Free Software Foundation, Inc. | 2 |
3 ;; Copyright (C) 1999, 2000, 2002, 2003, 2004, | |
4 ;; 2005 Free Software Foundation, Inc. | |
3 | 5 |
4 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu> | 6 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu> |
5 ;; Keywords: news egroups mail-archive | 7 ;; Keywords: news egroups mail-archive |
6 | 8 |
7 ;; This file is part of GNU Emacs. | 9 ;; This file is part of GNU Emacs. |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 ;; General Public License for more details. | 19 ;; General Public License for more details. |
18 | 20 |
19 ;; You should have received a copy of the GNU General Public License | 21 ;; You should have received a copy of the GNU General Public License |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the | 22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
22 ;; Boston, MA 02111-1307, USA. | 24 ;; Boston, MA 02110-1301, USA. |
23 | 25 |
24 ;;; Commentary: | 26 ;;; Commentary: |
25 | 27 |
26 ;; Note: You need to have `url' (w3 0.46) or greater version | 28 ;; Note: You need to have `url' (w3 0.46) or greater version |
27 ;; installed for this backend to work. | 29 ;; installed for some functions of this backend to work. |
28 | 30 |
29 ;; Todo: | 31 ;; Todo: |
30 ;; 1. To support more web archives. | 32 ;; 1. To support more web archives. |
31 ;; 2. Generalize webmail to other MHonArc archive. | 33 ;; 2. Generalize webmail to other MHonArc archive. |
32 | 34 |
39 (require 'gnus-util) | 41 (require 'gnus-util) |
40 (require 'gnus) | 42 (require 'gnus) |
41 (require 'gnus-bcklg) | 43 (require 'gnus-bcklg) |
42 (require 'nnmail) | 44 (require 'nnmail) |
43 (require 'mm-util) | 45 (require 'mm-util) |
44 (require 'mail-source) | 46 (require 'mm-url) |
45 (eval-when-compile | |
46 (ignore-errors | |
47 (require 'w3) | |
48 (require 'url) | |
49 (require 'w3-forms) | |
50 (require 'nnweb))) | |
51 ;; Report failure to find w3 at load time if appropriate. | |
52 (eval '(progn | |
53 (require 'w3) | |
54 (require 'url) | |
55 (require 'w3-forms) | |
56 (require 'nnweb))) | |
57 | 47 |
58 (nnoo-declare nnwarchive) | 48 (nnoo-declare nnwarchive) |
59 | 49 |
60 (defvar nnwarchive-type-definition | 50 (defvar nnwarchive-type-definition |
61 '((egroups | 51 '((egroups |
295 (read-string | 285 (read-string |
296 (format "Login at %s: " server) | 286 (format "Login at %s: " server) |
297 user-mail-address))) | 287 user-mail-address))) |
298 (setq nnwarchive-passwd | 288 (setq nnwarchive-passwd |
299 (or nnwarchive-passwd | 289 (or nnwarchive-passwd |
300 (mail-source-read-passwd | 290 (read-passwd |
301 (format "Password for %s at %s: " | 291 (format "Password for %s at %s: " |
302 nnwarchive-login server))))) | 292 nnwarchive-login server))))) |
303 (unless nnwarchive-groups | 293 (unless nnwarchive-groups |
304 (nnwarchive-read-groups)) | 294 (nnwarchive-read-groups)) |
305 (save-excursion | 295 (save-excursion |
358 (save-excursion | 348 (save-excursion |
359 (nnheader-set-temp-buffer | 349 (nnheader-set-temp-buffer |
360 (format " *nnwarchive %s %s*" nnwarchive-type server))))) | 350 (format " *nnwarchive %s %s*" nnwarchive-type server))))) |
361 (nnwarchive-set-default nnwarchive-type)) | 351 (nnwarchive-set-default nnwarchive-type)) |
362 | 352 |
363 (defun nnwarchive-encode-www-form-urlencoded (pairs) | |
364 "Return PAIRS encoded for forms." | |
365 (mapconcat | |
366 (function | |
367 (lambda (data) | |
368 (concat (w3-form-encode-xwfu (car data)) "=" | |
369 (w3-form-encode-xwfu (cdr data))))) | |
370 pairs "&")) | |
371 | |
372 (defun nnwarchive-fetch-form (url pairs) | |
373 (let ((url-request-data (nnwarchive-encode-www-form-urlencoded pairs)) | |
374 (url-request-method "POST") | |
375 (url-request-extra-headers | |
376 '(("Content-type" . "application/x-www-form-urlencoded")))) | |
377 (nnweb-insert url)) | |
378 t) | |
379 | |
380 (defun nnwarchive-eval (expr) | 353 (defun nnwarchive-eval (expr) |
381 (cond | 354 (cond |
382 ((consp expr) | 355 ((consp expr) |
383 (cons (nnwarchive-eval (car expr)) (nnwarchive-eval (cdr expr)))) | 356 (cons (nnwarchive-eval (car expr)) (nnwarchive-eval (cdr expr)))) |
384 ((symbolp expr) | 357 ((symbolp expr) |
386 (t | 359 (t |
387 expr))) | 360 expr))) |
388 | 361 |
389 (defun nnwarchive-url (xurl) | 362 (defun nnwarchive-url (xurl) |
390 (mm-with-unibyte-current-buffer | 363 (mm-with-unibyte-current-buffer |
391 (let ((url-confirmation-func 'identity) | 364 (let ((url-confirmation-func 'identity) ;; Some hacks. |
392 (url-cookie-multiple-line nil)) | 365 (url-cookie-multiple-line nil)) |
393 (cond | 366 (cond |
394 ((eq (car xurl) 'post) | 367 ((eq (car xurl) 'post) |
395 (pop xurl) | 368 (pop xurl) |
396 (nnwarchive-fetch-form (car xurl) (nnwarchive-eval (cdr xurl)))) | 369 (mm-url-fetch-form (car xurl) (nnwarchive-eval (cdr xurl)))) |
397 (t | 370 (t |
398 (nnweb-insert (apply 'format (nnwarchive-eval xurl)))))))) | 371 (mm-url-insert (apply 'format (nnwarchive-eval xurl)))))))) |
399 | 372 |
400 (defun nnwarchive-generate-active () | 373 (defun nnwarchive-generate-active () |
401 (save-excursion | 374 (save-excursion |
402 (set-buffer nntp-server-buffer) | 375 (set-buffer nntp-server-buffer) |
403 (erase-buffer) | 376 (erase-buffer) |
468 (setq date (identity (match-string 1)))) | 441 (setq date (identity (match-string 1)))) |
469 (push (cons | 442 (push (cons |
470 article | 443 article |
471 (make-full-mail-header | 444 (make-full-mail-header |
472 article | 445 article |
473 (nnweb-decode-entities-string subject) | 446 (mm-url-decode-entities-string subject) |
474 (nnweb-decode-entities-string from) | 447 (mm-url-decode-entities-string from) |
475 date | 448 date |
476 (concat "<" group "%" | 449 (concat "<" group "%" |
477 (number-to-string article) | 450 (number-to-string article) |
478 "@egroup.com>") | 451 "@egroup.com>") |
479 "" | 452 "" |
488 (if (search-backward "</pre>" nil t) | 461 (if (search-backward "</pre>" nil t) |
489 (delete-region (point) (point-max))) | 462 (delete-region (point) (point-max))) |
490 (goto-char (point-min)) | 463 (goto-char (point-min)) |
491 (while (re-search-forward "<a[^>]+>\\([^<]+\\)</a>" nil t) | 464 (while (re-search-forward "<a[^>]+>\\([^<]+\\)</a>" nil t) |
492 (replace-match "\\1")) | 465 (replace-match "\\1")) |
493 (nnweb-decode-entities) | 466 (mm-url-decode-entities) |
494 (buffer-string)) | 467 (buffer-string)) |
495 | 468 |
496 (defun nnwarchive-egroups-xover-files (group articles) | 469 (defun nnwarchive-egroups-xover-files (group articles) |
497 (let (aux auxs) | 470 (let (aux auxs) |
498 (setq auxs (nnwarchive-paged (sort articles '<))) | 471 (setq auxs (nnwarchive-paged (sort articles '<))) |
548 nil t) | 521 nil t) |
549 (setq article (1+ (string-to-number (match-string 1))) | 522 (setq article (1+ (string-to-number (match-string 1))) |
550 subject (match-string 2)) | 523 subject (match-string 2)) |
551 (forward-line 1) | 524 (forward-line 1) |
552 (unless (assq article nnwarchive-headers) | 525 (unless (assq article nnwarchive-headers) |
553 (if (looking-at "<UL><LI><EM>From</EM>:\\([^&]+\\)<\\([^&]+\\)>") | 526 (if (looking-at "<UL><LI><EM>From</EM>: *\\([^<]*[^< ]\\) *<\\([^&]+\\)>") |
554 (progn | 527 (progn |
555 (setq from (match-string 1) | 528 (setq from (match-string 1) |
556 date (identity (match-string 2)))) | 529 date (identity (match-string 2)))) |
557 (setq from "" date "")) | 530 (setq from "" date "")) |
558 (push (cons | 531 (push (cons |
559 article | 532 article |
560 (make-full-mail-header | 533 (make-full-mail-header |
561 article | 534 article |
562 (nnweb-decode-entities-string subject) | 535 (mm-url-decode-entities-string subject) |
563 (nnweb-decode-entities-string from) | 536 (mm-url-decode-entities-string from) |
564 date | 537 date |
565 (format "<%05d%%%s>\n" (1- article) group) | 538 (format "<%05d%%%s>\n" (1- article) group) |
566 "" | 539 "" |
567 0 0 "")) nnwarchive-headers)))) | 540 0 0 "")) nnwarchive-headers)))) |
568 nnwarchive-headers) | 541 nnwarchive-headers) |
621 (save-restriction | 594 (save-restriction |
622 (goto-char (point-min)) | 595 (goto-char (point-min)) |
623 (when (search-forward "X-Head-End" nil t) | 596 (when (search-forward "X-Head-End" nil t) |
624 (beginning-of-line) | 597 (beginning-of-line) |
625 (narrow-to-region (point-min) (point)) | 598 (narrow-to-region (point-min) (point)) |
626 (nnweb-decode-entities) | 599 (mm-url-decode-entities) |
627 (goto-char (point-min)) | 600 (goto-char (point-min)) |
628 (while (search-forward "<!--X-" nil t) | 601 (while (search-forward "<!--X-" nil t) |
629 (replace-match "")) | 602 (replace-match "")) |
630 (goto-char (point-min)) | 603 (goto-char (point-min)) |
631 (while (search-forward " -->" nil t) | 604 (while (search-forward " -->" nil t) |
643 (forward-line) | 616 (forward-line) |
644 (delete-region (point-min) (point)) | 617 (delete-region (point-min) (point)) |
645 (search-forward "</ul>" nil t) | 618 (search-forward "</ul>" nil t) |
646 (end-of-line) | 619 (end-of-line) |
647 (narrow-to-region (point-min) (point)) | 620 (narrow-to-region (point-min) (point)) |
648 (nnweb-remove-markup) | 621 (mm-url-remove-markup) |
649 (nnweb-decode-entities) | 622 (mm-url-decode-entities) |
650 (goto-char (point-min)) | 623 (goto-char (point-min)) |
651 (delete-blank-lines) | 624 (delete-blank-lines) |
652 (when from | 625 (when from |
653 (message-remove-header "from") | 626 (message-remove-header "from") |
654 (goto-char (point-max)) | 627 (goto-char (point-max)) |
685 (setq p (point)) | 658 (setq p (point)) |
686 (when (search-forward "</PRE>" nil t) | 659 (when (search-forward "</PRE>" nil t) |
687 (delete-region (match-beginning 0) (match-end 0)) | 660 (delete-region (match-beginning 0) (match-end 0)) |
688 (save-restriction | 661 (save-restriction |
689 (narrow-to-region p (point)) | 662 (narrow-to-region p (point)) |
690 (nnweb-remove-markup) | 663 (mm-url-remove-markup) |
691 (nnweb-decode-entities) | 664 (mm-url-decode-entities) |
692 (goto-char (point-max))))) | 665 (goto-char (point-max))))) |
693 ((looking-at "<P><A HREF=\"\\([^\"]+\\)") | 666 ((looking-at "<P><A HREF=\"\\([^\"]+\\)") |
694 (setq url (match-string 1)) | 667 (setq url (match-string 1)) |
695 (delete-region (match-beginning 0) | 668 (delete-region (match-beginning 0) |
696 (progn (forward-line) (point))) | 669 (progn (forward-line) (point))) |
697 ;; I hate to download the url encode it, then immediately | 670 ;; I hate to download the url encode it, then immediately |
698 ;; decode it. | 671 ;; decode it. |
699 ;; FixMe: Find a better solution to attach the URL. | 672 (insert "<#external" |
700 ;; Maybe do some hack in external part of mml-generate-mim-1. | 673 " type=" |
701 (insert "<#part>" | 674 (or (and url |
702 "\n--\nExternal: \n" | 675 (string-match "\\.[^\\.]+$" url) |
703 (format "<URL:http://www.mail-archive.com/%s/%s>" | 676 (mailcap-extension-to-mime |
677 (match-string 0 url))) | |
678 "application/octet-stream") | |
679 (format " url=\"http://www.mail-archive.com/%s/%s\"" | |
704 group url) | 680 group url) |
705 "\n--\n" | 681 ">\n" |
706 "<#/part>") | 682 "<#/external>") |
707 (setq mime t)) | 683 (setq mime t)) |
708 (t | 684 (t |
709 (setq p (point)) | 685 (setq p (point)) |
710 (insert "<#part type=\"text/html\" disposition=inline>") | 686 (insert "<#part type=\"text/html\" disposition=inline>") |
711 (goto-char | 687 (goto-char |
747 (widen))) | 723 (widen))) |
748 (buffer-string))) | 724 (buffer-string))) |
749 | 725 |
750 (provide 'nnwarchive) | 726 (provide 'nnwarchive) |
751 | 727 |
728 ;;; arch-tag: 1ab7a15c-777a-40e0-95c0-0c41b3963578 | |
752 ;;; nnwarchive.el ends here | 729 ;;; nnwarchive.el ends here |