]> code.delx.au - gnu-emacs/blob - lisp/gnus/nnlistserv.el
Add 2012 to FSF copyright years for Emacs files (do not merge to trunk)
[gnu-emacs] / lisp / gnus / nnlistserv.el
1 ;;; nnlistserv.el --- retrieving articles via web mailing list archives
2
3 ;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
5
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: news, mail
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23
24 ;;; Commentary:
25
26 ;;; Code:
27
28 (eval-when-compile (require 'cl))
29
30 (require 'nnoo)
31 (require 'mm-url)
32 (require 'nnweb)
33
34 (nnoo-declare nnlistserv
35 nnweb)
36
37 (defvoo nnlistserv-directory (nnheader-concat gnus-directory "nnlistserv/")
38 "Where nnlistserv will save its files."
39 nnweb-directory)
40
41 (defvoo nnlistserv-name 'kk
42 "What search engine type is being used."
43 nnweb-type)
44
45 (defvoo nnlistserv-type-definition
46 '((kk
47 (article . nnlistserv-kk-wash-article)
48 (map . nnlistserv-kk-create-mapping)
49 (search . nnlistserv-kk-search)
50 (address . "http://www.itk.ntnu.no/ansatte/Andresen_Trond/kk-f/%s/")
51 (pages "fra160396" "fra160796" "fra061196" "fra160197"
52 "fra090997" "fra040797" "fra130397" "nye")
53 (index . "date.html")
54 (identifier . nnlistserv-kk-identity)))
55 "Type-definition alist."
56 nnweb-type-definition)
57
58 (defvoo nnlistserv-search nil
59 "Search string to feed to DejaNews."
60 nnweb-search)
61
62 (defvoo nnlistserv-ephemeral-p nil
63 "Whether this nnlistserv server is ephemeral."
64 nnweb-ephemeral-p)
65
66 ;;; Internal variables
67
68 ;;; Interface functions
69
70 (nnoo-define-basics nnlistserv)
71
72 (nnoo-import nnlistserv
73 (nnweb))
74
75 ;;; Internal functions
76
77 ;;;
78 ;;; KK functions.
79 ;;;
80
81 (defun nnlistserv-kk-create-mapping ()
82 "Perform the search and create a number-to-url alist."
83 (save-excursion
84 (set-buffer nnweb-buffer)
85 (let ((case-fold-search t)
86 (active (or (cadr (assoc nnweb-group nnweb-group-alist))
87 (cons 1 0)))
88 (pages (nnweb-definition 'pages))
89 map url page subject from )
90 (while (setq page (pop pages))
91 (erase-buffer)
92 (when (funcall (nnweb-definition 'search) page)
93 ;; Go through all the article hits on this page.
94 (goto-char (point-min))
95 (mm-url-decode-entities)
96 (goto-char (point-min))
97 (while (re-search-forward "^<li> *<a href=\"\\([^\"]+\\)\"><b>\\([^\\>]+\\)</b></a> *<[^>]+><i>\\([^>]+\\)<" nil t)
98 (setq url (match-string 1)
99 subject (match-string 2)
100 from (match-string 3))
101 (setq url (concat (format (nnweb-definition 'address) page) url))
102 (unless (nnweb-get-hashtb url)
103 (push
104 (list
105 (incf (cdr active))
106 (make-full-mail-header
107 (cdr active) subject from ""
108 (concat "<" (nnweb-identifier url) "@kk>")
109 nil 0 0 url))
110 map)
111 (nnweb-set-hashtb (cadar map) (car map))
112 (nnheader-message 5 "%s %s %s" (cdr active) (point) pages)))))
113 ;; Return the articles in the right order.
114 (setq nnweb-articles
115 (sort (nconc nnweb-articles map) 'car-less-than-car)))))
116
117 (defun nnlistserv-kk-wash-article ()
118 (let ((case-fold-search t)
119 (headers '(sent name email subject id))
120 sent name email subject id)
121 (mm-url-decode-entities)
122 (while headers
123 (goto-char (point-min))
124 (re-search-forward (format "<!-- %s=\"\\([^\"]+\\)" (car headers)) nil t)
125 (set (pop headers) (match-string 1)))
126 (goto-char (point-min))
127 (search-forward "<!-- body" nil t)
128 (delete-region (point-min) (progn (forward-line 1) (point)))
129 (goto-char (point-max))
130 (search-backward "<!-- body" nil t)
131 (delete-region (point-max) (progn (beginning-of-line) (point)))
132 (mm-url-remove-markup)
133 (goto-char (point-min))
134 (insert (format "From: %s <%s>\n" name email)
135 (format "Subject: %s\n" subject)
136 (format "Message-ID: %s\n" id)
137 (format "Date: %s\n\n" sent))))
138
139 (defun nnlistserv-kk-search (search)
140 (mm-url-insert
141 (concat (format (nnweb-definition 'address) search)
142 (nnweb-definition 'index)))
143 t)
144
145 (defun nnlistserv-kk-identity (url)
146 "Return an unique identifier based on URL."
147 url)
148
149 (provide 'nnlistserv)
150
151 ;; arch-tag: 7705176f-d332-4a5e-a520-d0d319445617
152 ;;; nnlistserv.el ends here