* nnmh.el (nnmh-retrieve-parsed-headers): Bind `in-reply-to' and `cur' as
[elisp/gnus.git-] / lisp / nnmh.el
1 ;;; nnmh.el --- mhspool access for Gnus
2 ;; Copyright (C) 1995,96,97,98,99 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
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 ;; Based on nnspool.el by Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>.
28 ;; For an overview of what the interface functions do, please see the
29 ;; Gnus sources.
30
31 ;;; Code:
32
33 (require 'nnheader)
34 (require 'nnmail)
35 (require 'gnus-start)
36 (require 'nnoo)
37 (eval-when-compile (require 'cl))
38
39 (nnoo-declare nnmh)
40
41 (defvoo nnmh-directory message-directory
42   "*Mail spool directory.")
43
44 (defvoo nnmh-get-new-mail t
45   "*If non-nil, nnmh will check the incoming mail file and split the mail.")
46
47 (defvoo nnmh-prepare-save-mail-hook nil
48   "*Hook run narrowed to an article before saving.")
49
50 (defvoo nnmh-be-safe nil
51   "*If non-nil, nnmh will check all articles to make sure whether they are new or not.")
52
53 \f
54
55 (defconst nnmh-version "nnmh 1.0"
56   "nnmh version.")
57
58 (defvoo nnmh-current-directory nil
59   "Current news group directory.")
60
61 (defvoo nnmh-status-string "")
62 (defvoo nnmh-group-alist nil)
63 (defvoo nnmh-allow-delete-final nil)
64
65 \f
66
67 ;;; Interface functions.
68
69 (nnoo-define-basics nnmh)
70
71 (deffoo nnmh-retrieve-headers (articles &optional newsgroup server fetch-old)
72   (save-excursion
73     (set-buffer nntp-server-buffer)
74     (erase-buffer)
75     (let* ((file nil)
76            (number (length articles))
77            (large (and (numberp nnmail-large-newsgroup)
78                        (> number nnmail-large-newsgroup)))
79            (count 0)
80            (pathname-coding-system 'binary)
81            beg article)
82       (nnmh-possibly-change-directory newsgroup server)
83       ;; We don't support fetching by Message-ID.
84       (if (stringp (car articles))
85           'headers
86         (while articles
87           (when (and (file-exists-p
88                       (setq file (concat (file-name-as-directory
89                                           nnmh-current-directory)
90                                          (int-to-string
91                                           (setq article (pop articles))))))
92                      (not (file-directory-p file)))
93             (insert (format "221 %d Article retrieved.\n" article))
94             (setq beg (point))
95             (nnheader-insert-head file)
96             (goto-char beg)
97             (if (search-forward "\n\n" nil t)
98                 (forward-char -1)
99               (goto-char (point-max))
100               (insert "\n\n"))
101             (insert ".\n")
102             (delete-region (point) (point-max)))
103           (setq count (1+ count))
104
105           (and large
106                (zerop (% count 20))
107                (nnheader-message 5 "nnmh: Receiving headers... %d%%"
108                         (/ (* count 100) number))))
109
110         (when large
111           (nnheader-message 5 "nnmh: Receiving headers...done"))
112
113         ;; (nnheader-fold-continuation-lines)
114         'headers))))
115
116 (deffoo nnmh-retrieve-parsed-headers (articles
117                                       dependencies
118                                       &optional newsgroup server fetch-old
119                                       force-new)
120   (save-excursion
121     (set-buffer nntp-server-buffer)
122     (let* ((file nil)
123            (number (length articles))
124            (large (and (numberp nnmail-large-newsgroup)
125                        (> number nnmail-large-newsgroup)))
126            (count 0)
127            (pathname-coding-system 'binary)
128            (case-fold-search t)
129            ;;beg
130            article
131            headers header id end ref lines chars ctype in-reply-to
132            (cur (current-buffer)))
133       (nnmh-possibly-change-directory newsgroup server)
134       ;; We don't support fetching by Message-ID.
135       (if (stringp (car articles))
136           'headers
137         (while articles
138           (when (and (file-exists-p
139                       (setq file (concat (file-name-as-directory
140                                           nnmh-current-directory)
141                                          (int-to-string
142                                           (setq article (pop articles))))))
143                      (not (file-directory-p file)))
144             ;;(insert (format "221 %d Article retrieved.\n" article))
145             ;;(setq beg (point))
146             (erase-buffer)
147             (nnheader-insert-head file)
148             (save-restriction
149               (std11-narrow-to-header)
150               (setq
151                header
152                (make-full-mail-header
153                 ;; Number.
154                 article
155                 ;; Subject.
156                 (or (std11-fetch-field "Subject")
157                     "(none)")
158                 ;; From.
159                 (or (std11-fetch-field "From")
160                     "(nobody)")
161                 ;; Date.
162                 (or (std11-fetch-field "Date")
163                     "")
164                 ;; Message-ID.
165                 (progn
166                   (goto-char (point-min))
167                   (setq id (if (re-search-forward
168                                 "^Message-ID: *\\(<[^\n\t> ]+>\\)" nil t)
169                                ;; We do it this way to make sure the Message-ID
170                                ;; is (somewhat) syntactically valid.
171                                (buffer-substring (match-beginning 1)
172                                                  (match-end 1))
173                              ;; If there was no message-id, we just fake one
174                              ;; to make subsequent routines simpler.
175                              (nnheader-generate-fake-message-id))))
176                 ;; References.
177                 (progn
178                   (goto-char (point-min))
179                   (if (search-forward "\nReferences: " nil t)
180                       (progn
181                         (setq end (point))
182                         (prog1
183                             (buffer-substring (match-end 0) (std11-field-end))
184                           (setq ref
185                                 (buffer-substring
186                                  (progn
187                                    ;; (end-of-line)
188                                    (search-backward ">" end t)
189                                    (1+ (point)))
190                                  (progn
191                                    (search-backward "<" end t)
192                                    (point))))))
193                     ;; Get the references from the in-reply-to header if there
194                     ;; were no references and the in-reply-to header looks
195                     ;; promising.
196                     (if (and (search-forward "\nIn-Reply-To: " nil t)
197                              (setq in-reply-to
198                                    (buffer-substring (match-end 0)
199                                                      (std11-field-end)))
200                              (string-match "<[^>]+>" in-reply-to))
201                         (let (ref2)
202                           (setq ref (substring in-reply-to (match-beginning 0)
203                                                (match-end 0)))
204                           (while (string-match "<[^>]+>"
205                                                in-reply-to (match-end 0))
206                             (setq ref2
207                                   (substring in-reply-to (match-beginning 0)
208                                              (match-end 0)))
209                             (when (> (length ref2) (length ref))
210                               (setq ref ref2)))
211                           ref)
212                       (setq ref nil))))
213                 ;; Chars.
214                 (progn
215                   (goto-char (point-min))
216                   (if (search-forward "\nChars: " nil t)
217                       (if (numberp (setq chars (ignore-errors (read cur))))
218                           chars 0)
219                     0))
220                 ;; Lines.
221                 (progn
222                   (goto-char (point-min))
223                   (if (search-forward "\nLines: " nil t)
224                       (if (numberp (setq lines (ignore-errors (read cur))))
225                           lines 0)
226                     0))
227                 ;; Xref.
228                 (std11-fetch-field "Xref")
229                 ))
230               (goto-char (point-min))
231               (if (setq ctype (std11-fetch-field "Content-Type"))
232                   (mime-entity-set-content-type-internal
233                    header (mime-parse-Content-Type ctype)))
234               )
235             (when (setq header
236                         (gnus-dependencies-add-header
237                          header dependencies force-new))
238               (push header headers))
239             )
240           (setq count (1+ count))
241
242           (and large
243                (zerop (% count 20))
244                (nnheader-message 5 "nnmh: Receiving headers... %d%%"
245                                  (/ (* count 100) number))))
246
247         (when large
248           (nnheader-message 5 "nnmh: Receiving headers...done"))
249
250         ;; (nnheader-fold-continuation-lines)
251         (cons 'header (nreverse headers))
252         ))))
253
254 (deffoo nnmh-open-server (server &optional defs)
255   (nnoo-change-server 'nnmh server defs)
256   (when (not (file-exists-p nnmh-directory))
257     (condition-case ()
258         (make-directory nnmh-directory t)
259       (error t)))
260   (cond
261    ((not (file-exists-p nnmh-directory))
262     (nnmh-close-server)
263     (nnheader-report 'nnmh "Couldn't create directory: %s" nnmh-directory))
264    ((not (file-directory-p (file-truename nnmh-directory)))
265     (nnmh-close-server)
266     (nnheader-report 'nnmh "Not a directory: %s" nnmh-directory))
267    (t
268     (nnheader-report 'nnmh "Opened server %s using directory %s"
269                      server nnmh-directory)
270     t)))
271
272 (deffoo nnmh-request-article (id &optional newsgroup server buffer)
273   (nnmh-possibly-change-directory newsgroup server)
274   (let ((file (if (stringp id)
275                   nil
276                 (concat nnmh-current-directory (int-to-string id))))
277         (pathname-coding-system 'binary)
278         (nntp-server-buffer (or buffer nntp-server-buffer)))
279     (and (stringp file)
280          (file-exists-p file)
281          (not (file-directory-p file))
282          (save-excursion (nnmail-find-file file))
283          (string-to-int (file-name-nondirectory file)))))
284
285 (deffoo nnmh-request-group (group &optional server dont-check)
286   (nnheader-init-server-buffer)
287   (nnmh-possibly-change-directory group server)
288   (let ((pathname (nnmail-group-pathname group nnmh-directory))
289         (pathname-coding-system 'binary)
290         dir)
291     (cond
292      ((not (file-directory-p pathname))
293       (nnheader-report
294        'nnmh "Can't select group (no such directory): %s" group))
295      (t
296       (setq nnmh-current-directory pathname)
297       (and nnmh-get-new-mail
298            nnmh-be-safe
299            (nnmh-update-gnus-unreads group))
300       (cond
301        (dont-check
302         (nnheader-report 'nnmh "Selected group %s" group)
303         t)
304        (t
305         ;; Re-scan the directory if it's on a foreign system.
306         (nnheader-re-read-dir pathname)
307         (setq dir
308               (sort
309                (mapcar (lambda (name) (string-to-int name))
310                        (directory-files pathname nil "^[0-9]+$" t))
311                '<))
312           (cond
313            (dir
314             (nnheader-report 'nnmh "Selected group %s" group)
315             (nnheader-insert
316              "211 %d %d %d %s\n" (length dir) (car dir)
317              (progn (while (cdr dir) (setq dir (cdr dir))) (car dir))
318              group))
319            (t
320             (nnheader-report 'nnmh "Empty group %s" group)
321             (nnheader-insert (format "211 0 1 0 %s\n" group))))))))))
322
323 (deffoo nnmh-request-scan (&optional group server)
324   (nnmail-get-new-mail 'nnmh nil nnmh-directory group))
325
326 (deffoo nnmh-request-list (&optional server dir)
327   (nnheader-insert "")
328   (nnmh-possibly-change-directory nil server)
329   (let ((pathname-coding-system 'binary)
330         (nnmh-toplev
331          (file-truename (or dir (file-name-as-directory nnmh-directory)))))
332     (nnmh-request-list-1 nnmh-toplev))
333   (setq nnmh-group-alist (nnmail-get-active))
334   t)
335
336 (defvar nnmh-toplev)
337 (defun nnmh-request-list-1 (dir)
338   (setq dir (expand-file-name dir))
339   ;; Recurse down all directories.
340   (let ((dirs (and (file-readable-p dir)
341                    (> (nth 1 (file-attributes (file-chase-links dir))) 2)
342                    (nnheader-directory-files dir t nil t)))
343         rdir)
344     ;; Recurse down directories.
345     (while (setq rdir (pop dirs))
346       (when (and (file-directory-p rdir)
347                  (file-readable-p rdir)
348                  (not (equal (file-truename rdir)
349                              (file-truename dir))))
350         (nnmh-request-list-1 rdir))))
351   ;; For each directory, generate an active file line.
352   (unless (string= (expand-file-name nnmh-toplev) dir)
353     (let ((files (mapcar
354                   (lambda (name) (string-to-int name))
355                   (directory-files dir nil "^[0-9]+$" t))))
356       (when files
357         (save-excursion
358           (set-buffer nntp-server-buffer)
359           (goto-char (point-max))
360           (insert
361            (format
362             "%s %d %d y\n"
363             (progn
364               (string-match
365                (regexp-quote
366                 (file-truename (file-name-as-directory
367                                 (expand-file-name nnmh-toplev))))
368                dir)
369               (nnheader-replace-chars-in-string
370                (decode-coding-string (substring dir (match-end 0))
371                                      nnmail-pathname-coding-system)
372                ?/ ?.))
373             (apply 'max files)
374             (apply 'min files)))))))
375   t)
376
377 (deffoo nnmh-request-newgroups (date &optional server)
378   (nnmh-request-list server))
379
380 (deffoo nnmh-request-expire-articles (articles newsgroup
381                                                &optional server force)
382   (nnmh-possibly-change-directory newsgroup server)
383   (let* ((is-old t)
384          article rest mod-time)
385     (nnheader-init-server-buffer)
386
387     (while (and articles is-old)
388       (setq article (concat nnmh-current-directory
389                             (int-to-string (car articles))))
390       (when (setq mod-time (nth 5 (file-attributes article)))
391         (if (and (nnmh-deletable-article-p newsgroup (car articles))
392                  (setq is-old
393                        (nnmail-expired-article-p newsgroup mod-time force)))
394             (progn
395               (nnheader-message 5 "Deleting article %s in %s..."
396                                 article newsgroup)
397               (condition-case ()
398                   (funcall nnmail-delete-file-function article)
399                 (file-error
400                  (nnheader-message 1 "Couldn't delete article %s in %s"
401                                    article newsgroup)
402                  (push (car articles) rest))))
403           (push (car articles) rest)))
404       (setq articles (cdr articles)))
405     (nnheader-message 5 "")
406     (nconc rest articles)))
407
408 (deffoo nnmh-close-group (group &optional server)
409   t)
410
411 (deffoo nnmh-request-move-article
412   (article group server accept-form &optional last)
413   (let ((buf (get-buffer-create " *nnmh move*"))
414         result)
415     (and
416      (nnmh-deletable-article-p group article)
417      (nnmh-request-article article group server)
418      (save-excursion
419        (set-buffer buf)
420        (erase-buffer)
421        (insert-buffer-substring nntp-server-buffer)
422        (setq result (eval accept-form))
423        (kill-buffer (current-buffer))
424        result)
425      (progn
426        (nnmh-possibly-change-directory group server)
427        (condition-case ()
428            (funcall nnmail-delete-file-function
429                     (concat nnmh-current-directory (int-to-string article)))
430          (file-error nil))))
431     result))
432
433 (deffoo nnmh-request-accept-article (group &optional server last noinsert)
434   (nnmh-possibly-change-directory group server)
435   (if (and (not (equal group "queue"))
436            (not (equal group "draft")))
437       (nnmail-check-syntax))
438   (when nnmail-cache-accepted-message-ids
439     (nnmail-cache-insert (nnmail-fetch-field "message-id")))
440   (nnheader-init-server-buffer)
441   (prog1
442       (if (stringp group)
443           (if noinsert
444               (nnmh-active-number group)
445             (car (nnmh-save-mail
446                   (list (cons group (nnmh-active-number group)))
447                   noinsert)))
448         (let ((res (nnmail-article-group 'nnmh-active-number)))
449           (if (and (null res)
450                    (yes-or-no-p "Moved to `junk' group; delete article? "))
451               'junk
452             (car (nnmh-save-mail res noinsert)))))
453     (when (and last nnmail-cache-accepted-message-ids)
454       (nnmail-cache-close))))
455
456 (deffoo nnmh-request-replace-article (article group buffer)
457   (nnmh-possibly-change-directory group)
458   (save-excursion
459     (set-buffer buffer)
460     (nnmh-possibly-create-directory group)
461     (ignore-errors
462       (nnmail-write-region
463        (point-min) (point-max)
464        (concat nnmh-current-directory (int-to-string article))
465        nil (if (nnheader-be-verbose 5) nil 'nomesg))
466       t)))
467
468 (deffoo nnmh-request-create-group (group &optional server args)
469   (nnheader-init-server-buffer)
470   (unless (assoc group nnmh-group-alist)
471     (let (active)
472       (push (list group (setq active (cons 1 0)))
473             nnmh-group-alist)
474       (nnmh-possibly-create-directory group)
475       (nnmh-possibly-change-directory group server)
476       (let ((articles (mapcar
477                        (lambda (file)
478                          (string-to-int file))
479                        (directory-files
480                         nnmh-current-directory nil "^[0-9]+$"))))
481         (when articles
482           (setcar active (apply 'min articles))
483           (setcdr active (apply 'max articles))))))
484   t)
485
486 (deffoo nnmh-request-delete-group (group &optional force server)
487   (nnmh-possibly-change-directory group server)
488   ;; Delete all articles in GROUP.
489   (if (not force)
490       ()                                ; Don't delete the articles.
491     (let ((articles (directory-files nnmh-current-directory t "^[0-9]+$")))
492       (while articles
493         (when (file-writable-p (car articles))
494           (nnheader-message 5 "Deleting article %s in %s..."
495                             (car articles) group)
496           (funcall nnmail-delete-file-function (car articles)))
497         (setq articles (cdr articles))))
498     ;; Try to delete the directory itself.
499     (ignore-errors
500       (delete-directory nnmh-current-directory)))
501   ;; Remove the group from all structures.
502   (setq nnmh-group-alist
503         (delq (assoc group nnmh-group-alist) nnmh-group-alist)
504         nnmh-current-directory nil)
505   t)
506
507 (deffoo nnmh-request-rename-group (group new-name &optional server)
508   (nnmh-possibly-change-directory group server)
509   (let ((new-dir (nnmail-group-pathname new-name nnmh-directory))
510         (old-dir (nnmail-group-pathname group nnmh-directory)))
511     (when (ignore-errors
512             (make-directory new-dir t)
513             t)
514       ;; We move the articles file by file instead of renaming
515       ;; the directory -- there may be subgroups in this group.
516       ;; One might be more clever, I guess.
517       (let ((files (nnheader-article-to-file-alist old-dir)))
518         (while files
519           (rename-file
520            (concat old-dir (cdar files))
521            (concat new-dir (cdar files)))
522           (pop files)))
523       (when (<= (length (directory-files old-dir)) 2)
524         (ignore-errors
525           (delete-directory old-dir)))
526       ;; That went ok, so we change the internal structures.
527       (let ((entry (assoc group nnmh-group-alist)))
528         (when entry
529           (setcar entry new-name))
530         (setq nnmh-current-directory nil)
531         t))))
532
533 (nnoo-define-skeleton nnmh)
534
535 \f
536 ;;; Internal functions.
537
538 (defun nnmh-possibly-change-directory (newsgroup &optional server)
539   (when (and server
540              (not (nnmh-server-opened server)))
541     (nnmh-open-server server))
542   (when newsgroup
543     (let ((pathname (nnmail-group-pathname newsgroup nnmh-directory))
544           (pathname-coding-system 'binary))
545       (if (file-directory-p pathname)
546           (setq nnmh-current-directory pathname)
547         (error "No such newsgroup: %s" newsgroup)))))
548
549 (defun nnmh-possibly-create-directory (group)
550   (let (dir dirs)
551     (setq dir (nnmail-group-pathname group nnmh-directory))
552     (while (not (file-directory-p dir))
553       (push dir dirs)
554       (setq dir (file-name-directory (directory-file-name dir))))
555     (while dirs
556       (when (make-directory (directory-file-name (car dirs)))
557         (error "Could not create directory %s" (car dirs)))
558       (nnheader-message 5 "Creating mail directory %s" (car dirs))
559       (setq dirs (cdr dirs)))))
560
561 (defun nnmh-save-mail (group-art &optional noinsert)
562   "Called narrowed to an article."
563   (unless noinsert
564     (nnmail-insert-lines)
565     (nnmail-insert-xref group-art))
566   (run-hooks 'nnmail-prepare-save-mail-hook)
567   (run-hooks 'nnmh-prepare-save-mail-hook)
568   (goto-char (point-min))
569   (while (looking-at "From ")
570     (replace-match "X-From-Line: ")
571     (forward-line 1))
572   ;; We save the article in all the newsgroups it belongs in.
573   (let ((ga group-art)
574         first)
575     (while ga
576       (nnmh-possibly-create-directory (caar ga))
577       (let ((file (concat (nnmail-group-pathname
578                            (caar ga) nnmh-directory)
579                           (int-to-string (cdar ga)))))
580         (if first
581             ;; It was already saved, so we just make a hard link.
582             (funcall nnmail-crosspost-link-function first file t)
583           ;; Save the article.
584           (nnmail-write-region (point-min) (point-max) file nil nil)
585           (setq first file)))
586       (setq ga (cdr ga))))
587   group-art)
588
589 (defun nnmh-active-number (group)
590   "Compute the next article number in GROUP."
591   (let ((active (cadr (assoc group nnmh-group-alist)))
592         (dir (nnmail-group-pathname group nnmh-directory))
593         (pathname-coding-system 'binary))
594     (unless active
595       ;; The group wasn't known to nnmh, so we just create an active
596       ;; entry for it.
597       (setq active (cons 1 0))
598       (push (list group active) nnmh-group-alist)
599       (unless (file-exists-p dir)
600         (gnus-make-directory dir))
601       ;; Find the highest number in the group.
602       (let ((files (sort
603                     (mapcar
604                      (lambda (f)
605                        (string-to-int f))
606                      (directory-files dir nil "^[0-9]+$"))
607                     '>)))
608         (when files
609           (setcdr active (car files)))))
610     (setcdr active (1+ (cdr active)))
611     (while (file-exists-p
612             (concat (nnmail-group-pathname group nnmh-directory)
613                     (int-to-string (cdr active))))
614       (setcdr active (1+ (cdr active))))
615     (cdr active)))
616
617 (defun nnmh-update-gnus-unreads (group)
618   ;; Go through the .nnmh-articles file and compare with the actual
619   ;; articles in this folder.  The articles that are "new" will be
620   ;; marked as unread by Gnus.
621   (let* ((dir nnmh-current-directory)
622          (files (sort (mapcar (function (lambda (name) (string-to-int name)))
623                               (directory-files nnmh-current-directory
624                                                nil "^[0-9]+$" t))
625                       '<))
626          (nnmh-file (concat dir ".nnmh-articles"))
627          new articles)
628     ;; Load the .nnmh-articles file.
629     (when (file-exists-p nnmh-file)
630       (setq articles
631             (let (nnmh-newsgroup-articles)
632               (ignore-errors (load nnmh-file nil t t))
633               nnmh-newsgroup-articles)))
634     ;; Add all new articles to the `new' list.
635     (let ((art files))
636       (while art
637         (unless (assq (car art) articles)
638           (push (car art) new))
639         (setq art (cdr art))))
640     ;; Remove all deleted articles.
641     (let ((art articles))
642       (while art
643         (unless (memq (caar art) files)
644           (setq articles (delq (car art) articles)))
645         (setq art (cdr art))))
646     ;; Check whether the articles really are the ones that Gnus thinks
647     ;; they are by looking at the time-stamps.
648     (let ((arts articles)
649           art)
650       (while (setq art (pop arts))
651         (when (not (equal
652                     (nth 5 (file-attributes
653                             (concat dir (int-to-string (car art)))))
654                     (cdr art)))
655           (setq articles (delq art articles))
656           (push (car art) new))))
657     ;; Go through all the new articles and add them, and their
658     ;; time-stamps, to the list.
659     (setq articles
660           (nconc articles
661                  (mapcar
662                   (lambda (art)
663                     (cons art
664                           (nth 5 (file-attributes
665                                   (concat dir (int-to-string art))))))
666                   new)))
667     ;; Make Gnus mark all new articles as unread.
668     (when new
669       (gnus-make-articles-unread
670        (gnus-group-prefixed-name group (list 'nnmh ""))
671        (setq new (sort new '<))))
672     ;; Sort the article list with highest numbers first.
673     (setq articles (sort articles (lambda (art1 art2)
674                                     (> (car art1) (car art2)))))
675     ;; Finally write this list back to the .nnmh-articles file.
676     (with-temp-file nnmh-file
677       (insert ";; Gnus article active file for " group "\n\n")
678       (insert "(setq nnmh-newsgroup-articles '")
679       (gnus-prin1 articles)
680       (insert ")\n"))))
681
682 (defun nnmh-deletable-article-p (group article)
683   "Say whether ARTICLE in GROUP can be deleted."
684   (let ((path (concat nnmh-current-directory (int-to-string article))))
685     ;; Writable.
686     (and (file-writable-p path)
687          (or
688           ;; We can never delete the last article in the group.
689           (not (eq (cdr (nth 1 (assoc group nnmh-group-alist)))
690                    article))
691           ;; Well, we can.
692           nnmh-allow-delete-final))))
693
694 (provide 'nnmh)
695
696 ;;; nnmh.el ends here