1 ;;; nnmh.el --- mhspool access for Gnus
3 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2003
4 ;; Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
8 ;; Keywords: news, mail
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
29 ;; Based on nnspool.el by Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>.
30 ;; For an overview of what the interface functions do, please see the
39 (eval-when-compile (require 'cl))
43 (defvoo nnmh-directory message-directory
44 "Mail spool directory.")
46 (defvoo nnmh-get-new-mail t
47 "If non-nil, nnmh will check the incoming mail file and split the mail.")
49 (defvoo nnmh-prepare-save-mail-hook nil
50 "Hook run narrowed to an article before saving.")
52 (defvoo nnmh-be-safe nil
53 "If non-nil, nnmh will check all articles to make sure whether they are new or not.
54 Go through the .nnmh-articles file and compare with the actual
55 articles in this folder. The articles that are \"new\" will be marked
60 (defconst nnmh-version "nnmh 1.0"
63 (defvoo nnmh-current-directory nil
64 "Current news group directory.")
66 (defvoo nnmh-status-string "")
67 (defvoo nnmh-group-alist nil)
68 ;; Don't even think about setting this variable. It does not exist.
69 ;; Forget about it. Uh-huh. Nope. Nobody here. It's only bound
70 ;; dynamically by certain functions in nndraft.
71 (defvar nnmh-allow-delete-final nil)
75 ;;; Interface functions.
77 (nnoo-define-basics nnmh)
79 (deffoo nnmh-retrieve-headers (articles &optional newsgroup server fetch-old)
81 (set-buffer nntp-server-buffer)
84 (number (length articles))
85 (large (and (numberp nnmail-large-newsgroup)
86 (> number nnmail-large-newsgroup)))
88 (file-name-coding-system nnmail-pathname-coding-system)
90 (nnmh-possibly-change-directory newsgroup server)
91 ;; We don't support fetching by Message-ID.
92 (if (stringp (car articles))
95 (when (and (file-exists-p
96 (setq file (concat (file-name-as-directory
97 nnmh-current-directory)
99 (setq article (pop articles))))))
100 (not (file-directory-p file)))
101 (insert (format "221 %d Article retrieved.\n" article))
103 (nnheader-insert-head file)
105 (if (search-forward "\n\n" nil t)
107 (goto-char (point-max))
110 (delete-region (point) (point-max)))
111 (setq count (1+ count))
115 (nnheader-message 5 "nnmh: Receiving headers... %d%%"
116 (/ (* count 100) number))))
119 (nnheader-message 5 "nnmh: Receiving headers...done"))
121 (nnheader-fold-continuation-lines)
124 (deffoo nnmh-open-server (server &optional defs)
125 (nnoo-change-server 'nnmh server defs)
126 (when (not (file-exists-p nnmh-directory))
128 (make-directory nnmh-directory t)
131 ((not (file-exists-p nnmh-directory))
133 (nnheader-report 'nnmh "Couldn't create directory: %s" nnmh-directory))
134 ((not (file-directory-p (file-truename nnmh-directory)))
136 (nnheader-report 'nnmh "Not a directory: %s" nnmh-directory))
138 (nnheader-report 'nnmh "Opened server %s using directory %s"
139 server nnmh-directory)
142 (deffoo nnmh-request-article (id &optional newsgroup server buffer)
143 (nnmh-possibly-change-directory newsgroup server)
144 (let ((file (if (stringp id)
146 (concat nnmh-current-directory (int-to-string id))))
147 (file-name-coding-system nnmail-pathname-coding-system)
148 (nntp-server-buffer (or buffer nntp-server-buffer)))
151 (not (file-directory-p file))
152 (save-excursion (nnmail-find-file file))
153 (string-to-int (file-name-nondirectory file)))))
155 (deffoo nnmh-request-group (group &optional server dont-check)
156 (nnheader-init-server-buffer)
157 (nnmh-possibly-change-directory group server)
158 (let ((pathname (nnmail-group-pathname group nnmh-directory))
159 (file-name-coding-system nnmail-pathname-coding-system)
162 ((not (file-directory-p pathname))
164 'nnmh "Can't select group (no such directory): %s" group))
166 (setq nnmh-current-directory pathname)
167 (and nnmh-get-new-mail
169 (nnmh-update-gnus-unreads group))
172 (nnheader-report 'nnmh "Selected group %s" group)
175 ;; Re-scan the directory if it's on a foreign system.
176 (nnheader-re-read-dir pathname)
179 (mapcar (lambda (name) (string-to-int name))
180 (directory-files pathname nil &