Mercurial > emacs
annotate lisp/gnus/nnbabyl.el @ 31546:09bc2badb9e6
(quail-translation-docstring): New variable.
(quail-show-keyboard-layout): Docstring modified.
(quail-select-current): Likewise.
(quail-build-decode-map): Change arg MAP to MAP-LIST to avoid
infinite recursive call.
(quail-help): Check quail-translation-docstring. Format of the
output changed.
(quail-help-insert-keymap-description): Adjusted for the above
change.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Mon, 11 Sep 2000 23:38:47 +0000 |
parents | 15fc6acbae7a |
children | 9968f55ad26e |
rev | line source |
---|---|
17493 | 1 ;;; nnbabyl.el --- rmail mbox access for Gnus |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
17493
diff
changeset
|
2 ;; Copyright (C) 1995,96,97,98 Free Software Foundation, Inc. |
17493 | 3 |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
17493
diff
changeset
|
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> |
17493 | 5 ;; Masanobu UMEDA <umerin@flab.flab.fujitsu.junet> |
6 ;; Keywords: news, mail | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
24 | |
25 ;;; Commentary: | |
26 | |
27 ;; For an overview of what the interface functions do, please see the | |
28 ;; Gnus sources. | |
29 | |
30 ;;; Code: | |
31 | |
32 (require 'nnheader) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
17493
diff
changeset
|
33 (condition-case nil |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
17493
diff
changeset
|
34 (require 'rmail) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
17493
diff
changeset
|
35 (t (nnheader-message 5 "Ignore rmail errors from this file, you don't have rmail"))) |
17493 | 36 (require 'nnmail) |
37 (require 'nnoo) | |
38 (eval-when-compile (require 'cl)) | |
39 | |
40 (nnoo-declare nnbabyl) | |
41 | |
42 (defvoo nnbabyl-mbox-file (expand-file-name "~/RMAIL") | |
43 "The name of the rmail box file in the users home directory.") | |
44 | |
45 (defvoo nnbabyl-active-file (expand-file-name "~/.rmail-active") | |
46 "The name of the active file for the rmail box.") | |
47 | |
48 (defvoo nnbabyl-get-new-mail t | |
49 "If non-nil, nnbabyl will check the incoming mail file and split the mail.") | |
50 | |
51 (defvoo nnbabyl-prepare-save-mail-hook nil | |
52 "Hook run narrowed to an article before saving.") | |
53 | |
54 | |
55 | |
56 (defvar nnbabyl-mail-delimiter "\^_") | |
57 | |
58 (defconst nnbabyl-version "nnbabyl 1.0" | |
59 "nnbabyl version.") | |
60 | |
61 (defvoo nnbabyl-mbox-buffer nil) | |
62 (defvoo nnbabyl-current-group nil) | |
63 (defvoo nnbabyl-status-string "") | |
64 (defvoo nnbabyl-group-alist nil) | |
65 (defvoo nnbabyl-active-timestamp nil) | |
66 | |
67 (defvoo nnbabyl-previous-buffer-mode nil) | |
68 | |
69 (eval-and-compile | |
70 (autoload 'gnus-set-text-properties "gnus-ems")) | |
71 | |
72 | |
73 | |
74 ;;; Interface functions | |
75 | |
76 (nnoo-define-basics nnbabyl) | |
77 | |
78 (deffoo nnbabyl-retrieve-headers (articles &optional group server fetch-old) | |
79 (save-excursion | |
80 (set-buffer nntp-server-buffer) | |
81 (erase-buffer) | |
82 (let ((number (length articles)) | |
83 (count 0) | |
84 (delim (concat "^" nnbabyl-mail-delimiter)) | |
85 article art-string start stop) | |
86 (nnbabyl-possibly-change-newsgroup group server) | |
87 (while (setq article (pop articles)) | |
88 (setq art-string (nnbabyl-article-string article)) | |
89 (set-buffer nnbabyl-mbox-buffer) | |
90 (end-of-line) | |
91 (when (or (search-forward art-string nil t) | |
92 (search-backward art-string nil t)) | |
93 (unless (re-search-backward delim nil t) | |
94 (goto-char (point-min))) | |
95 (while (and (not (looking-at ".+:")) | |
96 (zerop (forward-line 1)))) | |
97 (setq start (point)) | |
98 (search-forward "\n\n" nil t) | |
99 (setq stop (1- (point))) | |
100 (set-buffer nntp-server-buffer) | |
101 (insert "221 ") | |
102 (princ article (current-buffer)) | |
103 (insert " Article retrieved.\n") | |
104 (insert-buffer-substring nnbabyl-mbox-buffer start stop) | |
105 (goto-char (point-max)) | |
106 (insert ".\n")) | |
107 (and (numberp nnmail-large-newsgroup) | |
108 (> number nnmail-large-newsgroup) | |
109 (zerop (% (incf count) 20)) | |
110 (nnheader-message 5 "nnbabyl: Receiving headers... %d%%" | |
111 (/ (* count 100) number)))) | |
112 | |
113 (and (numberp nnmail-large-newsgroup) | |
114 (> number nnmail-large-newsgroup) | |
115 (nnheader-message 5 "nnbabyl: Receiving headers...done")) | |
116 | |
117 (set-buffer nntp-server-buffer) | |
118 (nnheader-fold-continuation-lines) | |
119 'headers))) | |
120 | |
121 (deffoo nnbabyl-open-server (server &optional defs) | |
122 (nnoo-change-server 'nnbabyl server defs) | |
123 (nnbabyl-create-mbox) | |
124 (cond | |
125 ((not (file-exists-p nnbabyl-mbox-file)) | |
126 (nnbabyl-close-server) | |
127 (nnheader-report 'nnbabyl "No such file: %s" nnbabyl-mbox-file)) | |
128 ((file-directory-p nnbabyl-mbox-file) | |
129 (nnbabyl-close-server) | |
130 (nnheader-report 'nnbabyl "Not a regular file: %s" nnbabyl-mbox-file)) | |
131 (t | |
132 (nnheader-report 'nnbabyl "Opened server %s using mbox %s" server | |
133 nnbabyl-mbox-file) | |
134 t))) | |
135 | |
136 (deffoo nnbabyl-close-server (&optional server) | |
137 ;; Restore buffer mode. | |
138 (when (and (nnbabyl-server-opened) | |
139 nnbabyl-previous-buffer-mode) | |
140 (save-excursion | |
141 (set-buffer nnbabyl-mbox-buffer) | |
142 (narrow-to-region | |
143 (caar nnbabyl-previous-buffer-mode) | |
144 (cdar nnbabyl-previous-buffer-mode)) | |
145 (funcall (cdr nnbabyl-previous-buffer-mode)))) | |
146 (nnoo-close-server 'nnbabyl server) | |
147 (setq nnbabyl-mbox-buffer nil) | |
148 t) | |
149 | |
150 (deffoo nnbabyl-server-opened (&optional server) | |
151 (and (nnoo-current-server-p 'nnbabyl server) | |
152 nnbabyl-mbox-buffer | |
153 (buffer-name nnbabyl-mbox-buffer) | |
154 nntp-server-buffer | |
155 (buffer-name nntp-server-buffer))) | |
156 | |
157 (deffoo nnbabyl-request-article (article &optional newsgroup server buffer) | |
158 (nnbabyl-possibly-change-newsgroup newsgroup server) | |
159 (save-excursion | |
160 (set-buffer nnbabyl-mbox-buffer) | |
161 (goto-char (point-min)) | |
162 (when (search-forward (nnbabyl-article-string article) nil t) | |
163 (let (start stop summary-line) | |
164 (unless (re-search-backward (concat "^" nnbabyl-mail-delimiter) nil t) | |
165 (goto-char (point-min)) | |
166 (end-of-line)) | |
167 (while (and (not (looking-at ".+:")) | |
168 (zerop (forward-line 1)))) | |
169 (setq start (point)) | |
170 (or (when (re-search-forward | |
171 (concat "^" nnbabyl-mail-delimiter) nil t) | |
172 (beginning-of-line) | |
173 t) | |
174 (goto-char (point-max))) | |
175 (setq stop (point)) | |
176 (let ((nntp-server-buffer (or buffer nntp-server-buffer))) | |
177 (set-buffer nntp-server-buffer) | |
178 (erase-buffer) | |
179 (insert-buffer-substring nnbabyl-mbox-buffer start stop) | |
180 (goto-char (point-min)) | |
181 ;; If there is an EOOH header, then we have to remove some | |
182 ;; duplicated headers. | |
183 (setq summary-line (looking-at "Summary-line:")) | |
184 (when (search-forward "\n*** EOOH ***" nil t) | |
185 (if summary-line | |
186 ;; The headers to be deleted are located before the | |
187 ;; EOOH line... | |
188 (delete-region (point-min) (progn (forward-line 1) | |
189 (point))) | |
190 ;; ...or after. | |
191 (delete-region (progn (beginning-of-line) (point)) | |
192 (or (search-forward "\n\n" nil t) | |
193 (point))))) | |
194 (if (numberp article) | |
195 (cons nnbabyl-current-group article) | |
196 (nnbabyl-article-group-number))))))) | |
197 | |
198 (deffoo nnbabyl-request-group (group &optional server dont-check) | |
199 (let ((active (cadr (assoc group nnbabyl-group-alist)))) | |
200 (save-excursion | |
201 (cond | |
202 ((or (null active) | |
203 (null (nnbabyl-possibly-change-newsgroup group server))) | |
204 (nnheader-report 'nnbabyl "No such group: %s" group)) | |
205 (dont-check | |
206 (nnheader-report 'nnbabyl "Selected group %s" group) | |
207 (nnheader-insert "")) | |
208 (t | |
209 (nnheader-report 'nnbabyl "Selected group %s" group) | |
210 (nnheader-insert "211 %d %d %d %s\n" | |
211 (1+ (- (cdr active) (car active))) | |
212 (car active) (cdr active) group)))))) | |
213 | |
214 (deffoo nnbabyl-request-scan (&optional group server) | |
215 (nnbabyl-possibly-change-newsgroup group server) | |
216 (nnbabyl-read-mbox) | |
217 (nnmail-get-new-mail | |
218 'nnbabyl | |
219 (lambda () | |
220 (save-excursion | |
221 (set-buffer nnbabyl-mbox-buffer) | |
222 (save-buffer))) | |
223 (file-name-directory nnbabyl-mbox-file) | |
224 group | |
225 (lambda () | |
226 (save-excursion | |
227 (let ((in-buf (current-buffer))) | |
228 (goto-char (point-min)) | |
229 (while (search-forward "\n\^_\n" nil t) | |
230 (delete-char -1)) | |
231 (set-buffer nnbabyl-mbox-buffer) | |
232 (goto-char (point-max)) | |
233 (search-backward "\n\^_" nil t) | |
234 (goto-char (match-end 0)) | |
235 (insert-buffer-substring in-buf))) | |
236 (nnmail-save-active nnbabyl-group-alist nnbabyl-active-file)))) | |
237 | |
238 (deffoo nnbabyl-close-group (group &optional server) | |
239 t) | |
240 | |
241 (deffoo nnbabyl-request-create-group (group &optional server args) | |
242 (nnmail-activate 'nnbabyl) | |
243 (unless (assoc group nnbabyl-group-alist) | |
244 (push (list group (cons 1 0)) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
17493
diff
changeset
|
245 nnbabyl-group-alist) |
17493 | 246 (nnmail-save-active nnbabyl-group-alist nnbabyl-active-file)) |
247 t) | |
248 | |
249 (deffoo nnbabyl-request-list (&optional server) | |
250 (save-excursion | |
251 (nnmail-find-file nnbabyl-active-file) | |
252 (setq nnbabyl-group-alist (nnmail-get-active)) | |
253 t)) | |
254 | |
255 (deffoo nnbabyl-request-newgroups (date &optional server) | |
256 (nnbabyl-request-list server)) | |
257 | |
258 (deffoo nnbabyl-request-list-newsgroups (&optional server) | |
259 (nnheader-report 'nnbabyl "nnbabyl: LIST NEWSGROUPS is not implemented.")) | |
260 | |
261 (deffoo nnbabyl-request-expire-articles | |
262 (articles newsgroup &optional server force) | |
263 (nnbabyl-possibly-change-newsgroup newsgroup server) | |
264 (let* ((is-old t) | |
265 rest) | |
266 (nnmail-activate 'nnbabyl) | |
267 | |
268 (save-excursion | |
269 (set-buffer nnbabyl-mbox-buffer) | |
270 (gnus-set-text-properties (point-min) (point-max) nil) | |
271 (while (and articles is-old) | |
272 (goto-char (point-min)) | |
273 (when (search-forward (nnbabyl-article-string (car articles)) nil t) | |
274 (if (setq is-old | |
275 (nnmail-expired-article-p | |
276 newsgroup | |
277 (buffer-substring | |
278 (point) (progn (end-of-line) (point))) force)) | |
279 (progn | |
280 (nnheader-message 5 "Deleting article %d in %s..." | |
281 (car articles) newsgroup) | |
282 (nnbabyl-delete-mail)) | |
283 (push (car articles) rest))) | |
284 (setq articles (cdr articles))) | |
285 (save-buffer) | |
286 ;; Find the lowest active article in this group. | |
287 (let ((active (nth 1 (assoc newsgroup nnbabyl-group-alist)))) | |
288 (goto-char (point-min)) | |
289 (while (and (not (search-forward | |
290 (nnbabyl-article-string (car active)) nil t)) | |
291 (<= (car active) (cdr active))) | |
292 (setcar active (1+ (car active))) | |
293 (goto-char (point-min)))) | |
294 (nnmail-save-active nnbabyl-group-alist nnbabyl-active-file) | |
295 (nconc rest articles)))) | |
296 | |
297 (deffoo nnbabyl-request-move-article | |
298 (article group server accept-form &optional last) | |
299 (let ((buf (get-buffer-create " *nnbabyl move*")) | |
300 result) | |
301 (and | |
302 (nnbabyl-request-article article group server) | |
303 (save-excursion | |
304 (set-buffer buf) | |
305 (insert-buffer-substring nntp-server-buffer) | |
306 (goto-char (point-min)) | |
307 (while (re-search-forward | |
308 "^X-Gnus-Newsgroup:" | |
309 (save-excursion (search-forward "\n\n" nil t) (point)) t) | |
310 (delete-region (progn (beginning-of-line) (point)) | |
311 (progn (forward-line 1) (point)))) | |
312 (setq result (eval accept-form)) | |
313 (kill-buffer (current-buffer)) | |
314 result) | |
315 (save-excursion | |
316 (nnbabyl-possibly-change-newsgroup group server) | |
317 (set-buffer nnbabyl-mbox-buffer) | |
318 (goto-char (point-min)) | |
319 (if (search-forward (nnbabyl-article-string article) nil t) | |
320 (nnbabyl-delete-mail)) | |
321 (and last (save-buffer)))) | |
322 result)) | |
323 | |
324 (deffoo nnbabyl-request-accept-article (group &optional server last) | |
325 (nnbabyl-possibly-change-newsgroup group server) | |
326 (nnmail-check-syntax) | |
327 (let ((buf (current-buffer)) | |
328 result beg) | |
329 (and | |
330 (nnmail-activate 'nnbabyl) | |
331 (save-excursion | |
332 (goto-char (point-min)) | |
333 (search-forward "\n\n" nil t) | |
334 (forward-line -1) | |
335 (save-excursion | |
336 (while (re-search-backward "^X-Gnus-Newsgroup: " beg t) | |
337 (delete-region (point) (progn (forward-line 1) (point))))) | |
338 (when nnmail-cache-accepted-message-ids | |
339 (nnmail-cache-insert (nnmail-fetch-field "message-id"))) | |
340 (setq result | |
341 (if (stringp group) | |
342 (list (cons group (nnbabyl-active-number group))) | |
343 (nnmail-article-group 'nnbabyl-active-number))) | |
344 (if (and (null result) | |
345 (yes-or-no-p "Moved to `junk' group; delete article? ")) | |
346 (setq result 'junk) | |
347 (setq result (car (nnbabyl-save-mail result)))) | |
348 (set-buffer nnbabyl-mbox-buffer) | |
349 (goto-char (point-max)) | |
350 (search-backward "\n\^_") | |
351 (goto-char (match-end 0)) | |
352 (insert-buffer-substring buf) | |
353 (when last | |
354 (when nnmail-cache-accepted-message-ids | |
355 (nnmail-cache-insert (nnmail-fetch-field "message-id"))) | |
356 (save-buffer) | |
357 (nnmail-save-active nnbabyl-group-alist nnbabyl-active-file)) | |
358 result)))) | |
359 | |
360 (deffoo nnbabyl-request-replace-article (article group buffer) | |
361 (nnbabyl-possibly-change-newsgroup group) | |
362 (save-excursion | |
363 (set-buffer nnbabyl-mbox-buffer) | |
364 (goto-char (point-min)) | |
365 (if (not (search-forward (nnbabyl-article-string article) nil t)) | |
366 nil | |
367 (nnbabyl-delete-mail t t) | |
368 (insert-buffer-substring buffer) | |
369 (save-buffer) | |
370 t))) | |
371 | |
372 (deffoo nnbabyl-request-delete-group (group &optional force server) | |
373 (nnbabyl-possibly-change-newsgroup group server) | |
374 ;; Delete all articles in GROUP. | |
375 (if (not force) | |
376 () ; Don't delete the articles. | |
377 (save-excursion | |
378 (set-buffer nnbabyl-mbox-buffer) | |
379 (goto-char (point-min)) | |
380 ;; Delete all articles in this group. | |
381 (let ((ident (concat "\nX-Gnus-Newsgroup: " nnbabyl-current-group ":")) | |
382 found) | |
383 (while (search-forward ident nil t) | |
384 (setq found t) | |
385 (nnbabyl-delete-mail)) | |
386 (when found | |
387 (save-buffer))))) | |
388 ;; Remove the group from all structures. | |
389 (setq nnbabyl-group-alist | |
390 (delq (assoc group nnbabyl-group-alist) nnbabyl-group-alist) | |
391 nnbabyl-current-group nil) | |
392 ;; Save the active file. | |
393 (nnmail-save-active nnbabyl-group-alist nnbabyl-active-file) | |
394 t) | |
395 | |
396 (deffoo nnbabyl-request-rename-group (group new-name &optional server) | |
397 (nnbabyl-possibly-change-newsgroup group server) | |
398 (save-excursion | |
399 (set-buffer nnbabyl-mbox-buffer) | |
400 (goto-char (point-min)) | |
401 (let ((ident (concat "\nX-Gnus-Newsgroup: " nnbabyl-current-group ":")) | |
402 (new-ident (concat "\nX-Gnus-Newsgroup: " new-name ":")) | |
403 found) | |
404 (while (search-forward ident nil t) | |
405 (replace-match new-ident t t) | |
406 (setq found t)) | |
407 (when found | |
408 (save-buffer)))) | |
409 (let ((entry (assoc group nnbabyl-group-alist))) | |
410 (and entry (setcar entry new-name)) | |
411 (setq nnbabyl-current-group nil) | |
412 ;; Save the new group alist. | |
413 (nnmail-save-active nnbabyl-group-alist nnbabyl-active-file) | |
414 t)) | |
415 | |
416 | |
417 ;;; Internal functions. | |
418 | |
419 ;; If FORCE, delete article no matter how many X-Gnus-Newsgroup | |
420 ;; headers there are. If LEAVE-DELIM, don't delete the Unix mbox | |
421 ;; delimiter line. | |
422 (defun nnbabyl-delete-mail (&optional force leave-delim) | |
423 ;; Delete the current X-Gnus-Newsgroup line. | |
424 (unless force | |
425 (delete-region | |
426 (progn (beginning-of-line) (point)) | |
427 (progn (forward-line 1) (point)))) | |
428 ;; Beginning of the article. | |
429 (save-excursion | |
430 (save-restriction | |
431 (widen) | |
432 (narrow-to-region | |
433 (save-excursion | |
434 (unless (re-search-backward (concat "^" nnbabyl-mail-delimiter) nil t) | |
435 (goto-char (point-min)) | |
436 (end-of-line)) | |
437 (if leave-delim (progn (forward-line 1) (point)) | |
438 (match-beginning 0))) | |
439 (progn | |
440 (forward-line 1) | |
441 (or (and (re-search-forward (concat "^" nnbabyl-mail-delimiter) | |
442 nil t) | |
443 (match-beginning 0)) | |
444 (point-max)))) | |
445 (goto-char (point-min)) | |
446 ;; Only delete the article if no other groups owns it as well. | |
447 (when (or force (not (re-search-forward "^X-Gnus-Newsgroup: " nil t))) | |
448 (delete-region (point-min) (point-max)))))) | |
449 | |
450 (defun nnbabyl-possibly-change-newsgroup (newsgroup &optional server) | |
451 (when (and server | |
452 (not (nnbabyl-server-opened server))) | |
453 (nnbabyl-open-server server)) | |
454 (when (or (not nnbabyl-mbox-buffer) | |
455 (not (buffer-name nnbabyl-mbox-buffer))) | |
456 (save-excursion (nnbabyl-read-mbox))) | |
457 (unless nnbabyl-group-alist | |
458 (nnmail-activate 'nnbabyl)) | |
459 (if newsgroup | |
460 (if (assoc newsgroup nnbabyl-group-alist) | |
461 (setq nnbabyl-current-group newsgroup) | |
462 (nnheader-report 'nnbabyl "No such group in file")) | |
463 t)) | |
464 | |
465 (defun nnbabyl-article-string (article) | |
466 (if (numberp article) | |
467 (concat "\nX-Gnus-Newsgroup: " nnbabyl-current-group ":" | |
468 (int-to-string article) " ") | |
469 (concat "\nMessage-ID: " article))) | |
470 | |
471 (defun nnbabyl-article-group-number () | |
472 (save-excursion | |
473 (goto-char (point-min)) | |
474 (when (re-search-forward "^X-Gnus-Newsgroup: +\\([^:]+\\):\\([0-9]+\\) " | |
475 nil t) | |
476 (cons (buffer-substring (match-beginning 1) (match-end 1)) | |
477 (string-to-int | |
478 (buffer-substring (match-beginning 2) (match-end 2))))))) | |
479 | |
480 (defun nnbabyl-insert-lines () | |
481 "Insert how many lines and chars there are in the body of the mail." | |
482 (let (lines chars) | |
483 (save-excursion | |
484 (goto-char (point-min)) | |
485 (when (search-forward "\n\n" nil t) | |
486 ;; There may be an EOOH line here... | |
487 (when (looking-at "\\*\\*\\* EOOH \\*\\*\\*") | |
488 (search-forward "\n\n" nil t)) | |
489 (setq chars (- (point-max) (point)) | |
490 lines (max (- (count-lines (point) (point-max)) 1) 0)) | |
491 ;; Move back to the end of the headers. | |
492 (goto-char (point-min)) | |
493 (search-forward "\n\n" nil t) | |
494 (forward-char -1) | |
495 (save-excursion | |
496 (when (re-search-backward "^Lines: " nil t) | |
497 (delete-region (point) (progn (forward-line 1) (point))))) | |
498 (insert (format "Lines: %d\n" lines)) | |
499 chars)))) | |
500 | |
501 (defun nnbabyl-save-mail (group-art) | |
502 ;; Called narrowed to an article. | |
503 (nnbabyl-insert-lines) | |
504 (nnmail-insert-xref group-art) | |
505 (nnbabyl-insert-newsgroup-line group-art) | |
506 (run-hooks 'nnbabyl-prepare-save-mail-hook) | |
507 group-art) | |
508 | |
509 (defun nnbabyl-insert-newsgroup-line (group-art) | |
510 (save-excursion | |
511 (goto-char (point-min)) | |
512 (while (looking-at "From ") | |
513 (replace-match "Mail-from: From " t t) | |
514 (forward-line 1)) | |
515 ;; If there is a C-l at the beginning of the narrowed region, this | |
516 ;; isn't really a "save", but rather a "scan". | |
517 (goto-char (point-min)) | |
518 (unless (looking-at "\^L") | |
519 (save-excursion | |
520 (insert "\^L\n0, unseen,,\n*** EOOH ***\n") | |
521 (goto-char (point-max)) | |
522 (insert "\^_\n"))) | |
523 (when (search-forward "\n\n" nil t) | |
524 (forward-char -1) | |
525 (while group-art | |
526 (insert (format "X-Gnus-Newsgroup: %s:%d %s\n" | |
527 (caar group-art) (cdar group-art) | |
528 (current-time-string))) | |
529 (setq group-art (cdr group-art)))) | |
530 t)) | |
531 | |
532 (defun nnbabyl-active-number (group) | |
533 ;; Find the next article number in GROUP. | |
534 (let ((active (cadr (assoc group nnbabyl-group-alist)))) | |
535 (if active | |
536 (setcdr active (1+ (cdr active))) | |
537 ;; This group is new, so we create a new entry for it. | |
538 ;; This might be a bit naughty... creating groups on the drop of | |
539 ;; a hat, but I don't know... | |
540 (push (list group (setq active (cons 1 1))) | |
541 nnbabyl-group-alist)) | |
542 (cdr active))) | |
543 | |
544 (defun nnbabyl-create-mbox () | |
545 (unless (file-exists-p nnbabyl-mbox-file) | |
546 ;; Create a new, empty RMAIL mbox file. | |
547 (save-excursion | |
548 (set-buffer (setq nnbabyl-mbox-buffer | |
549 (create-file-buffer nnbabyl-mbox-file))) | |
550 (setq buffer-file-name nnbabyl-mbox-file) | |
551 (insert "BABYL OPTIONS:\n\n\^_") | |
552 (nnmail-write-region | |
553 (point-min) (point-max) nnbabyl-mbox-file t 'nomesg)))) | |
554 | |
555 (defun nnbabyl-read-mbox () | |
556 (nnmail-activate 'nnbabyl) | |
557 (nnbabyl-create-mbox) | |
558 | |
559 (unless (and nnbabyl-mbox-buffer | |
560 (buffer-name nnbabyl-mbox-buffer) | |
561 (save-excursion | |
562 (set-buffer nnbabyl-mbox-buffer) | |
563 (= (buffer-size) (nnheader-file-size nnbabyl-mbox-file)))) | |
564 ;; This buffer has changed since we read it last. Possibly. | |
565 (save-excursion | |
566 (let ((delim (concat "^" nnbabyl-mail-delimiter)) | |
567 (alist nnbabyl-group-alist) | |
568 start end number) | |
569 (set-buffer (setq nnbabyl-mbox-buffer | |
570 (nnheader-find-file-noselect | |
571 nnbabyl-mbox-file nil 'raw))) | |
572 ;; Save previous buffer mode. | |
573 (setq nnbabyl-previous-buffer-mode | |
574 (cons (cons (point-min) (point-max)) | |
575 major-mode)) | |
576 | |
577 (buffer-disable-undo (current-buffer)) | |
578 (widen) | |
579 (setq buffer-read-only nil) | |
580 (fundamental-mode) | |
581 | |
582 ;; Go through the group alist and compare against | |
583 ;; the rmail file. | |
584 (while alist | |
585 (goto-char (point-max)) | |
586 (when (and (re-search-backward | |
587 (format "^X-Gnus-Newsgroup: %s:\\([0-9]+\\) " | |
588 (caar alist)) | |
589 nil t) | |
590 (> (setq number | |
591 (string-to-number | |
592 (buffer-substring | |
593 (match-beginning 1) (match-end 1)))) | |
594 (cdadar alist))) | |
595 (setcdr (cadar alist) number)) | |
596 (setq alist (cdr alist))) | |
597 | |
598 ;; We go through the mbox and make sure that each and | |
599 ;; every mail belongs to some group or other. | |
600 (goto-char (point-min)) | |
601 (if (looking-at "\^L") | |
602 (setq start (point)) | |
603 (re-search-forward delim nil t) | |
604 (setq start (match-end 0))) | |
605 (while (re-search-forward delim nil t) | |
606 (setq end (match-end 0)) | |
607 (unless (search-backward "\nX-Gnus-Newsgroup: " start t) | |
608 (goto-char end) | |
609 (save-excursion | |
610 (save-restriction | |
611 (narrow-to-region (goto-char start) end) | |
612 (nnbabyl-save-mail | |
613 (nnmail-article-group 'nnbabyl-active-number)) | |
614 (setq end (point-max))))) | |
615 (goto-char (setq start end))) | |
616 (when (buffer-modified-p (current-buffer)) | |
617 (save-buffer)) | |
618 (nnmail-save-active nnbabyl-group-alist nnbabyl-active-file))))) | |
619 | |
620 (defun nnbabyl-remove-incoming-delims () | |
621 (goto-char (point-min)) | |
622 (while (search-forward "\^_" nil t) | |
623 (replace-match "?" t t))) | |
624 | |
625 (defun nnbabyl-check-mbox () | |
626 "Go through the nnbabyl mbox and make sure that no article numbers are reused." | |
627 (interactive) | |
628 (let ((idents (make-vector 1000 0)) | |
629 id) | |
630 (save-excursion | |
631 (when (or (not nnbabyl-mbox-buffer) | |
632 (not (buffer-name nnbabyl-mbox-buffer))) | |
633 (nnbabyl-read-mbox)) | |
634 (set-buffer nnbabyl-mbox-buffer) | |
635 (goto-char (point-min)) | |
636 (while (re-search-forward "^X-Gnus-Newsgroup: \\([^ ]+\\) " nil t) | |
637 (if (intern-soft (setq id (match-string 1)) idents) | |
638 (progn | |
639 (delete-region (progn (beginning-of-line) (point)) | |
640 (progn (forward-line 1) (point))) | |
641 (nnheader-message 7 "Moving %s..." id) | |
642 (nnbabyl-save-mail | |
643 (nnmail-article-group 'nnbabyl-active-number))) | |
644 (intern id idents))) | |
645 (when (buffer-modified-p (current-buffer)) | |
646 (save-buffer)) | |
647 (nnmail-save-active nnbabyl-group-alist nnbabyl-active-file) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
17493
diff
changeset
|
648 (nnheader-message 5 "")))) |
17493 | 649 |
650 (provide 'nnbabyl) | |
651 | |
652 ;;; nnbabyl.el ends here |