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