-(defun nnbabyl-get-new-mail (&optional group)
- "Read new incoming mail."
- (let* ((spools (nnmail-get-spool-files group))
- (group-in group)
- incoming incomings)
- (nnbabyl-read-mbox)
- (if (or (not nnbabyl-get-new-mail) (not nnmail-spool-file))
- ()
- ;; We go through all the existing spool files and split the
- ;; mail from each.
- (while spools
- (and
- (file-exists-p (car spools))
- (> (nth 7 (file-attributes (car spools))) 0)
- (progn
- (and gnus-verbose-backends
- (message "nnbabyl: Reading incoming mail..."))
- (setq incoming
- (nnmail-move-inbox
- (car spools) (concat nnbabyl-mbox-file "-Incoming")))
- (setq incomings (cons incoming incomings))
- (save-excursion
- (setq group (nnmail-get-split-group (car spools) group-in))
- (let* ((nnmail-prepare-incoming-hook
- (cons 'nnbabyl-remove-incoming-delims
- nnmail-prepare-incoming-hook))
- in-buf)
- (setq in-buf (nnmail-split-incoming
- incoming 'nnbabyl-save-mail t group))
- (set-buffer in-buf)
- (goto-char (point-min))
- (while (search-forward "\n\^_\n" nil t)
- (delete-char -1))
- (set-buffer nnbabyl-mbox-buffer)
- (goto-char (point-max))
- (search-backward "\n\^_" nil t)
- (goto-char (match-end 0))
- (insert-buffer-substring in-buf)
- (kill-buffer in-buf)))))
- (setq spools (cdr spools)))
- ;; If we did indeed read any incoming spools, we save all info.
- (and (buffer-modified-p nnbabyl-mbox-buffer)
- (save-excursion
- (nnmail-save-active nnbabyl-group-alist nnbabyl-active-file)
- (set-buffer nnbabyl-mbox-buffer)
- (save-buffer)))
- (if incomings (run-hooks 'nnmail-read-incoming-hook))
- (while incomings
- (and nnmail-delete-incoming
- (file-writable-p incoming)
- (delete-file incoming))
- (setq incomings (cdr incomings))))))
+(defun nnbabyl-check-mbox ()
+ "Go through the nnbabyl mbox and make sure that no article numbers are reused."
+ (interactive)
+ (let ((idents (make-vector 1000 0))
+ id)
+ (save-excursion
+ (when (or (not nnbabyl-mbox-buffer)
+ (not (buffer-name nnbabyl-mbox-buffer)))
+ (nnbabyl-read-mbox))
+ (set-buffer nnbabyl-mbox-buffer)
+ (goto-char (point-min))
+ (while (re-search-forward "^X-Gnus-Newsgroup: \\([^ ]+\\) " nil t)
+ (if (intern-soft (setq id (match-string 1)) idents)
+ (progn
+ (delete-region (progn (beginning-of-line) (point))
+ (progn (forward-line 1) (point)))
+ (nnheader-message 7 "Moving %s..." id)
+ (nnbabyl-save-mail
+ (nnmail-article-group 'nnbabyl-active-number)))
+ (intern id idents)))
+ (when (buffer-modified-p (current-buffer))
+ (save-buffer))
+ (nnmail-save-active nnbabyl-group-alist nnbabyl-active-file)
+ (nnheader-message 5 ""))))