annotate lisp/gnus/nnmh.el @ 26:441bb1e64a06 r19-15b96

Import from CVS: tag r19-15b96
author cvs
date Mon, 13 Aug 2007 08:51:32 +0200
parents 4103f0995bd7
children ec9a17fef872
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; nnmh.el --- mhspool access for Gnus
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
2 ;; Copyright (C) 1995,96,97 Free Software Foundation, Inc.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Keywords: news, mail
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;; Based on nnspool.el by Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; For an overview of what the interface functions do, please see the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; Gnus sources.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 (require 'nnheader)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (require 'nnmail)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
35 (require 'gnus-start)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (require 'nnoo)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
37 (require 'cl)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (nnoo-declare nnmh)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (defvoo nnmh-directory message-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 "*Mail spool directory.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (defvoo nnmh-get-new-mail t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 "*If non-nil, nnmh will check the incoming mail file and split the mail.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (defvoo nnmh-prepare-save-mail-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 "*Hook run narrowed to an article before saving.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (defvoo nnmh-be-safe nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 "*If non-nil, nnmh will check all articles to make sure whether they are new or not.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (defconst nnmh-version "nnmh 1.0"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 "nnmh version.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (defvoo nnmh-current-directory nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 "Current news group directory.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (defvoo nnmh-status-string "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (defvoo nnmh-group-alist nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;;; Interface functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (nnoo-define-basics nnmh)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (deffoo nnmh-retrieve-headers (articles &optional newsgroup server fetch-old)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (set-buffer nntp-server-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (let* ((file nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (number (length articles))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (large (and (numberp nnmail-large-newsgroup)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (> number nnmail-large-newsgroup)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 beg article)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (nnmh-possibly-change-directory newsgroup server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;; We don't support fetching by Message-ID.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (if (stringp (car articles))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 'headers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (while articles
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (when (and (file-exists-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (setq file (concat (file-name-as-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 nnmh-current-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (int-to-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (setq article (pop articles))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (not (file-directory-p file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (insert (format "221 %d Article retrieved.\n" article))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (setq beg (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (nnheader-insert-head file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (goto-char beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (if (search-forward "\n\n" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (insert "\n\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (insert ".\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (delete-region (point) (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (setq count (1+ count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (and large
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (zerop (% count 20))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (message "nnmh: Receiving headers... %d%%"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (/ (* count 100) number))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
108 (when large
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
109 (message "nnmh: Receiving headers...done"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (nnheader-fold-continuation-lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 'headers))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (deffoo nnmh-open-server (server &optional defs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (nnoo-change-server 'nnmh server defs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (when (not (file-exists-p nnmh-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (make-directory nnmh-directory t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (error t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 ((not (file-exists-p nnmh-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (nnmh-close-server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (nnheader-report 'nnmh "Couldn't create directory: %s" nnmh-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 ((not (file-directory-p (file-truename nnmh-directory)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (nnmh-close-server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (nnheader-report 'nnmh "Not a directory: %s" nnmh-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (nnheader-report 'nnmh "Opened server %s using directory %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 server nnmh-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (deffoo nnmh-request-article (id &optional newsgroup server buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (nnmh-possibly-change-directory newsgroup server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (let ((file (if (stringp id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (concat nnmh-current-directory (int-to-string id))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (nntp-server-buffer (or buffer nntp-server-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (and (stringp file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (file-exists-p file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (not (file-directory-p file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (save-excursion (nnmail-find-file file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (string-to-int (file-name-nondirectory file)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (deffoo nnmh-request-group (group &optional server dont-check)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (let ((pathname (nnmail-group-pathname group nnmh-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 ((not (file-directory-p pathname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (nnheader-report
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 'nnmh "Can't select group (no such directory): %s" group))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (setq nnmh-current-directory pathname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (and nnmh-get-new-mail
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 nnmh-be-safe
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (nnmh-update-gnus-unreads group))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (dont-check
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (nnheader-report 'nnmh "Selected group %s" group)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (t
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
161 ;; Re-scan the directory if it's on a foreign system.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
162 (nnheader-re-read-dir pathname)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (setq dir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (sort
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (mapcar (lambda (name) (string-to-int name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (directory-files pathname nil "^[0-9]+$" t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 '<))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (dir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (nnheader-report 'nnmh "Selected group %s" group)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (nnheader-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 "211 %d %d %d %s\n" (length dir) (car dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (progn (while (cdr dir) (setq dir (cdr dir))) (car dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 group))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (nnheader-report 'nnmh "Empty group %s" group)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (nnheader-insert (format "211 0 1 0 %s\n" group))))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (deffoo nnmh-request-scan (&optional group server)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
180 (nnmail-get-new-mail 'nnmh nil nnmh-directory group))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (deffoo nnmh-request-list (&optional server dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (nnheader-insert "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (let ((nnmh-toplev
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (or dir (file-truename (file-name-as-directory nnmh-directory)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (nnmh-request-list-1 nnmh-toplev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (setq nnmh-group-alist (nnmail-get-active))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (defvar nnmh-toplev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (defun nnmh-request-list-1 (dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (setq dir (expand-file-name dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 ;; Recurse down all directories.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (let ((dirs (and (file-readable-p dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (> (nth 1 (file-attributes (file-chase-links dir))) 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (directory-files dir t nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 ;; Recurse down directories.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (while (setq dir (pop dirs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (when (and (not (member (file-name-nondirectory dir) '("." "..")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (file-directory-p dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (file-readable-p dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (nnmh-request-list-1 dir))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 ;; For each directory, generate an active file line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (unless (string= (expand-file-name nnmh-toplev) dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (let ((files (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (lambda (name) (string-to-int name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (directory-files dir nil "^[0-9]+$" t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (when files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (set-buffer nntp-server-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 "%s %d %d y\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (regexp-quote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (file-truename (file-name-as-directory
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
220 (expand-file-name nnmh-toplev))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
221 dir)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (nnheader-replace-chars-in-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (substring dir (match-end 0)) ?/ ?.))
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
224 (apply 'max files)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (apply 'min files)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (deffoo nnmh-request-newgroups (date &optional server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (nnmh-request-list server))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 16
diff changeset
231 (deffoo nnmh-request-expire-articles (articles newsgroup
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 16
diff changeset
232 &optional server force)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (nnmh-possibly-change-directory newsgroup server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (let* ((active-articles
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (lambda (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (string-to-int name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (directory-files nnmh-current-directory nil "^[0-9]+$" t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (is-old t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 article rest mod-time)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (nnmail-activate 'nnmh)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (while (and articles is-old)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (setq article (concat nnmh-current-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (int-to-string (car articles))))
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
247 (when (setq mod-time (nth 5 (file-attributes article)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
248 (if (and (nnmh-deletable-article-p newsgroup (car articles))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
249 (setq is-old
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
250 (nnmail-expired-article-p newsgroup mod-time force)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
251 (progn
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
252 (nnheader-message 5 "Deleting article %s in %s..."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
253 article newsgroup)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
254 (condition-case ()
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
255 (funcall nnmail-delete-file-function article)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
256 (file-error
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
257 (nnheader-message 1 "Couldn't delete article %s in %s"
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
258 article newsgroup)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
259 (push (car articles) rest))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
260 (push (car articles) rest)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (setq articles (cdr articles)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (message "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (nconc rest articles)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (deffoo nnmh-close-group (group &optional server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (deffoo nnmh-request-move-article
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (article group server accept-form &optional last)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (let ((buf (get-buffer-create " *nnmh move*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (nnmh-deletable-article-p group article)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (nnmh-request-article article group server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (set-buffer buf)
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
277 (erase-buffer)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (insert-buffer-substring nntp-server-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (setq result (eval accept-form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (kill-buffer (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (nnmh-possibly-change-directory group server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (funcall nnmail-delete-file-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (concat nnmh-current-directory (int-to-string article)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (file-error nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (deffoo nnmh-request-accept-article (group &optional server last noinsert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (nnmh-possibly-change-directory group server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (nnmail-check-syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (if (stringp group)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (nnmail-activate 'nnmh)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
296 (car (nnmh-save-mail
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
297 (list (cons group (nnmh-active-number group)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
298 noinsert)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (nnmail-activate 'nnmh)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
301 (car (nnmh-save-mail (nnmail-article-group 'nnmh-active-number)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
302 noinsert)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (deffoo nnmh-request-replace-article (article group buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (nnmh-possibly-change-directory group)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (nnmh-possibly-create-directory group)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
309 (ignore-errors
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
310 (nnmail-write-region
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
311 (point-min) (point-max)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
312 (concat nnmh-current-directory (int-to-string article))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
313 nil (if (nnheader-be-verbose 5) nil 'nomesg))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
314 t)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
316 (deffoo nnmh-request-create-group (group &optional server args)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (nnmail-activate 'nnmh)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
318 (unless (assoc group nnmh-group-alist)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
319 (let (active)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
320 (push (list group (setq active (cons 1 0)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
321 nnmh-group-alist)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
322 (nnmh-possibly-create-directory group)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
323 (nnmh-possibly-change-directory group server)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
324 (let ((articles (mapcar
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
325 (lambda (file)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
326 (string-to-int file))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
327 (directory-files
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
328 nnmh-current-directory nil "^[0-9]+$"))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
329 (when articles
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
330 (setcar active (apply 'min articles))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
331 (setcdr active (apply 'max articles))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (deffoo nnmh-request-delete-group (group &optional force server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (nnmh-possibly-change-directory group server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 ;; Delete all articles in GROUP.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (if (not force)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 () ; Don't delete the articles.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (let ((articles (directory-files nnmh-current-directory t "^[0-9]+$")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (while articles
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
341 (when (file-writable-p (car articles))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
342 (nnheader-message 5 "Deleting article %s in %s..."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
343 (car articles) group)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
344 (funcall nnmail-delete-file-function (car articles)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (setq articles (cdr articles))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 ;; Try to delete the directory itself.
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
347 (ignore-errors
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
348 (delete-directory nnmh-current-directory)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 ;; Remove the group from all structures.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (setq nnmh-group-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (delq (assoc group nnmh-group-alist) nnmh-group-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 nnmh-current-directory nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (deffoo nnmh-request-rename-group (group new-name &optional server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (nnmh-possibly-change-directory group server)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
357 (let ((new-dir (nnmail-group-pathname new-name nnmh-directory))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
358 (old-dir (nnmail-group-pathname group nnmh-directory)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
359 (when (ignore-errors
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
360 (make-directory new-dir t)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
361 t)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
362 ;; We move the articles file by file instead of renaming
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
363 ;; the directory -- there may be subgroups in this group.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
364 ;; One might be more clever, I guess.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
365 (let ((files (nnheader-article-to-file-alist old-dir)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
366 (while files
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
367 (rename-file
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
368 (concat old-dir (cdar files))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
369 (concat new-dir (cdar files)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
370 (pop files)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
371 (when (<= (length (directory-files old-dir)) 2)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
372 (ignore-errors
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
373 (delete-directory old-dir)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
374 ;; That went ok, so we change the internal structures.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
375 (let ((entry (assoc group nnmh-group-alist)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
376 (when entry
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
377 (setcar entry new-name))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
378 (setq nnmh-current-directory nil)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
379 t))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
380
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
381 (nnoo-define-skeleton nnmh)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 ;;; Internal functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (defun nnmh-possibly-change-directory (newsgroup &optional server)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (when (and server
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (not (nnmh-server-opened server)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (nnmh-open-server server))
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
390 (when newsgroup
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
391 (let ((pathname (nnmail-group-pathname newsgroup nnmh-directory)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
392 (if (file-directory-p pathname)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
393 (setq nnmh-current-directory pathname)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
394 (error "No such newsgroup: %s" newsgroup)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (defun nnmh-possibly-create-directory (group)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (let (dir dirs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (setq dir (nnmail-group-pathname group nnmh-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 (while (not (file-directory-p dir))
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
400 (push dir dirs)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (setq dir (file-name-directory (directory-file-name dir))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (while dirs
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
403 (when (make-directory (directory-file-name (car dirs)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
404 (error "Could not create directory %s" (car dirs)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (nnheader-message 5 "Creating mail directory %s" (car dirs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (setq dirs (cdr dirs)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
408 (defun nnmh-save-mail (group-art &optional noinsert)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 "Called narrowed to an article."
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
410 (unless noinsert
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
411 (nnmail-insert-lines)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
412 (nnmail-insert-xref group-art))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
413 (run-hooks 'nnmail-prepare-save-mail-hook)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
414 (run-hooks 'nnmh-prepare-save-mail-hook)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
415 (goto-char (point-min))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
416 (while (looking-at "From ")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
417 (replace-match "X-From-Line: ")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
418 (forward-line 1))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
419 ;; We save the article in all the newsgroups it belongs in.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
420 (let ((ga group-art)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
421 first)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
422 (while ga
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
423 (nnmh-possibly-create-directory (caar ga))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
424 (let ((file (concat (nnmail-group-pathname
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
425 (caar ga) nnmh-directory)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
426 (int-to-string (cdar ga)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
427 (if first
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
428 ;; It was already saved, so we just make a hard link.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
429 (funcall nnmail-crosspost-link-function first file t)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
430 ;; Save the article.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
431 (nnmail-write-region (point-min) (point-max) file nil nil)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
432 (setq first file)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
433 (setq ga (cdr ga))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
434 group-art)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (defun nnmh-active-number (group)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 "Compute the next article number in GROUP."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (let ((active (cadr (assoc group nnmh-group-alist))))
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
439 (unless active
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
440 ;; The group wasn't known to nnmh, so we just create an active
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
441 ;; entry for it.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
442 (setq active (cons 1 0))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
443 (push (list group active) nnmh-group-alist)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
444 ;; Find the highest number in the group.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
445 (let ((files (sort
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
446 (mapcar
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
447 (lambda (f)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
448 (string-to-int f))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
449 (directory-files
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
450 (nnmail-group-pathname group nnmh-directory)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
451 nil "^[0-9]+$"))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
452 '>)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
453 (when files
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
454 (setcdr active (car files)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (setcdr active (1+ (cdr active)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (while (file-exists-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (concat (nnmail-group-pathname group nnmh-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (int-to-string (cdr active))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (setcdr active (1+ (cdr active))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (cdr active)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (defun nnmh-update-gnus-unreads (group)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 ;; Go through the .nnmh-articles file and compare with the actual
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
464 ;; articles in this folder. The articles that are "new" will be
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 ;; marked as unread by Gnus.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (let* ((dir nnmh-current-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (files (sort (mapcar (function (lambda (name) (string-to-int name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (directory-files nnmh-current-directory
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
469 nil "^[0-9]+$" t))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
470 '<))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (nnmh-file (concat dir ".nnmh-articles"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 new articles)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 ;; Load the .nnmh-articles file.
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
474 (when (file-exists-p nnmh-file)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
475 (setq articles
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
476 (let (nnmh-newsgroup-articles)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
477 (ignore-errors (load nnmh-file nil t t))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
478 nnmh-newsgroup-articles)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 ;; Add all new articles to the `new' list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (let ((art files))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (while art
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
482 (unless (assq (car art) articles)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
483 (push (car art) new))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (setq art (cdr art))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 ;; Remove all deleted articles.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (let ((art articles))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (while art
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
488 (unless (memq (caar art) files)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
489 (setq articles (delq (car art) articles)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (setq art (cdr art))))
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
491 ;; Check whether the articles really are the ones that Gnus thinks
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
492 ;; they are by looking at the time-stamps.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
493 (let ((arts articles)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
494 art)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
495 (while (setq art (pop arts))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
496 (when (not (equal
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
497 (nth 5 (file-attributes
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
498 (concat dir (int-to-string (car art)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
499 (cdr art)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
500 (setq articles (delq art articles))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
501 (push (car art) new))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 ;; Go through all the new articles and add them, and their
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
503 ;; time-stamps, to the list.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
504 (setq articles
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
505 (nconc articles
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
506 (mapcar
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
507 (lambda (art)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
508 (cons art
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
509 (nth 5 (file-attributes
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
510 (concat dir (int-to-string art))))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
511 new)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 ;; Make Gnus mark all new articles as unread.
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
513 (when new
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
514 (gnus-make-articles-unread
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
515 (gnus-group-prefixed-name group (list 'nnmh ""))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
516 (setq new (sort new '<))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 ;; Sort the article list with highest numbers first.
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
518 (setq articles (sort articles (lambda (art1 art2)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (> (car art1) (car art2)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 ;; Finally write this list back to the .nnmh-articles file.
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
521 (nnheader-temp-write nnmh-file
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (insert ";; Gnus article active file for " group "\n\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (insert "(setq nnmh-newsgroup-articles '")
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
524 (gnus-prin1 articles)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
525 (insert ")\n"))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (defun nnmh-deletable-article-p (group article)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 "Say whether ARTICLE in GROUP can be deleted."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (let ((path (concat nnmh-current-directory (int-to-string article))))
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
530 ;; Writable.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
531 (and (file-writable-p path)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
532 ;; We can never delete the last article in the group.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
533 (not (eq (cdr (nth 1 (assoc group nnmh-group-alist)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
534 article)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 (provide 'nnmh)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 ;;; nnmh.el ends here