Mercurial > emacs
annotate lisp/gnus/nnmh.el @ 92955:35b7a4096c03
*** empty log message ***
author | Jason Rumney <jasonr@gnu.org> |
---|---|
date | Fri, 14 Mar 2008 23:43:02 +0000 |
parents | a3d61f1532f1 |
children | a789a1138b08 |
rev | line source |
---|---|
17493 | 1 ;;; nnmh.el --- mhspool access for Gnus |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
2 |
64754
fafd692d1e40
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64085
diff
changeset
|
3 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, |
79708 | 4 ;; 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
17493 | 5 |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
7 ;; Masanobu UMEDA <umerin@flab.flab.fujitsu.junet> |
17493 | 8 ;; Keywords: news, mail |
9 | |
10 ;; This file is part of GNU Emacs. | |
11 | |
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 | |
78224
24202b793a08
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
75347
diff
changeset
|
14 ;; the Free Software Foundation; either version 3, or (at your option) |
17493 | 15 ;; any later version. |
16 | |
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. | |
21 | |
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 | |
64085 | 24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
25 ;; Boston, MA 02110-1301, USA. | |
17493 | 26 |
27 ;;; Commentary: | |
28 | |
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 | |
31 ;; Gnus sources. | |
32 | |
33 ;;; Code: | |
34 | |
35 (require 'nnheader) | |
36 (require 'nnmail) | |
37 (require 'gnus-start) | |
38 (require 'nnoo) | |
19494
4280cff25537
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
39 (eval-when-compile (require 'cl)) |
17493 | 40 |
41 (nnoo-declare nnmh) | |
42 | |
43 (defvoo nnmh-directory message-directory | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
44 "Mail spool directory.") |
17493 | 45 |
46 (defvoo nnmh-get-new-mail t | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
47 "If non-nil, nnmh will check the incoming mail file and split the mail.") |
17493 | 48 |
49 (defvoo nnmh-prepare-save-mail-hook nil | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
50 "Hook run narrowed to an article before saving.") |
17493 | 51 |
52 (defvoo nnmh-be-safe nil | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
53 "If non-nil, nnmh will check all articles to make sure whether they are new or not. |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
54 Go through the .nnmh-articles file and compare with the actual |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
55 articles in this folder. The articles that are \"new\" will be marked |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
56 as unread by Gnus.") |
17493 | 57 |
58 | |
59 | |
60 (defconst nnmh-version "nnmh 1.0" | |
61 "nnmh version.") | |
62 | |
63 (defvoo nnmh-current-directory nil | |
64 "Current news group directory.") | |
65 | |
66 (defvoo nnmh-status-string "") | |
67 (defvoo nnmh-group-alist nil) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
68 ;; Don't even think about setting this variable. It does not exist. |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
69 ;; Forget about it. Uh-huh. Nope. Nobody here. It's only bound |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
70 ;; dynamically by certain functions in nndraft. |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
71 (defvar nnmh-allow-delete-final nil) |
17493 | 72 |
73 | |
74 | |
75 ;;; Interface functions. | |
76 | |
77 (nnoo-define-basics nnmh) | |
78 | |
79 (deffoo nnmh-retrieve-headers (articles &optional newsgroup server fetch-old) | |
92771
a3d61f1532f1
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
80 (with-current-buffer nntp-server-buffer |
17493 | 81 (erase-buffer) |
82 (let* ((file nil) | |
83 (number (length articles)) | |
84 (large (and (numberp nnmail-large-newsgroup) | |
85 (> number nnmail-large-newsgroup))) | |
86 (count 0) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
87 (file-name-coding-system nnmail-pathname-coding-system) |
17493 | 88 beg article) |
89 (nnmh-possibly-change-directory newsgroup server) | |
90 ;; We don't support fetching by Message-ID. | |
91 (if (stringp (car articles)) | |
92 'headers | |
93 (while articles | |
94 (when (and (file-exists-p | |
95 (setq file (concat (file-name-as-directory | |
96 nnmh-current-directory) | |
97 (int-to-string | |
98 (setq article (pop articles)))))) | |
99 (not (file-directory-p file))) | |
100 (insert (format "221 %d Article retrieved.\n" article)) | |
101 (setq beg (point)) | |
102 (nnheader-insert-head file) | |
103 (goto-char beg) | |
104 (if (search-forward "\n\n" nil t) | |
105 (forward-char -1) | |
106 (goto-char (point-max)) | |
107 (insert "\n\n")) | |
108 (insert ".\n") | |
109 (delete-region (point) (point-max))) | |
110 (setq count (1+ count)) | |
111 | |
112 (and large | |
113 (zerop (% count 20)) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
114 (nnheader-message 5 "nnmh: Receiving headers... %d%%" |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
115 (/ (* count 100) number)))) |
17493 | 116 |
117 (when large | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
118 (nnheader-message 5 "nnmh: Receiving headers...done")) |
17493 | 119 |
120 (nnheader-fold-continuation-lines) | |
121 'headers)))) | |
122 | |
123 (deffoo nnmh-open-server (server &optional defs) | |
124 (nnoo-change-server 'nnmh server defs) | |
125 (when (not (file-exists-p nnmh-directory)) | |
126 (condition-case () | |
127 (make-directory nnmh-directory t) | |
128 (error t))) | |
129 (cond | |
130 ((not (file-exists-p nnmh-directory)) | |
131 (nnmh-close-server) | |
132 (nnheader-report 'nnmh "Couldn't create directory: %s" nnmh-directory)) | |
133 ((not (file-directory-p (file-truename nnmh-directory))) | |
134 (nnmh-close-server) | |
135 (nnheader-report 'nnmh "Not a directory: %s" nnmh-directory)) | |
136 (t | |
137 (nnheader-report 'nnmh "Opened server %s using directory %s" | |
138 server nnmh-directory) | |
139 t))) | |
140 | |
141 (deffoo nnmh-request-article (id &optional newsgroup server buffer) | |
142 (nnmh-possibly-change-directory newsgroup server) | |
143 (let ((file (if (stringp id) | |
144 nil | |
145 (concat nnmh-current-directory (int-to-string id)))) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
146 (file-name-coding-system nnmail-pathname-coding-system) |
17493 | 147 (nntp-server-buffer (or buffer nntp-server-buffer))) |
148 (and (stringp file) | |
149 (file-exists-p file) | |
150 (not (file-directory-p file)) | |
151 (save-excursion (nnmail-find-file file)) | |
62907
88db2adda4b7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-339
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
152 (string-to-number (file-name-nondirectory file))))) |
17493 | 153 |
154 (deffoo nnmh-request-group (group &optional server dont-check) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
155 (nnheader-init-server-buffer) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
156 (nnmh-possibly-change-directory group server) |
17493 | 157 (let ((pathname (nnmail-group-pathname group nnmh-directory)) |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
158 (file-name-coding-system nnmail-pathname-coding-system) |
17493 | 159 dir) |
160 (cond | |
161 ((not (file-directory-p pathname)) | |
162 (nnheader-report | |
163 'nnmh "Can't select group (no such directory): %s" group)) | |
164 (t | |
165 (setq nnmh-current-directory pathname) | |
166 (and nnmh-get-new-mail | |
167 nnmh-be-safe | |
168 (nnmh-update-gnus-unreads group)) | |
169 (cond | |
170 (dont-check | |
171 (nnheader-report 'nnmh "Selected group %s" group) | |
172 t) | |
173 (t | |
174 ;; Re-scan the directory if it's on a foreign system. | |
175 (nnheader-re-read-dir pathname) | |
176 (setq dir | |
177 (sort | |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
178 (mapcar 'string-to-number |
17493 | 179 (directory-files pathname nil "^[0-9]+$" t)) |
180 '<)) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
181 (cond |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
182 (dir |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
183 (setq nnmh-group-alist |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
184 (delq (assoc group nnmh-group-alist) nnmh-group-alist)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
185 (push (list group (cons (car dir) (car (last dir)))) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
186 nnmh-group-alist) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
187 (nnheader-report 'nnmh "Selected group %s" group) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
188 (nnheader-insert |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
189 "211 %d %d %d %s\n" (length dir) (car dir) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
190 (car (last dir)) group)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
191 (t |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
192 (nnheader-report 'nnmh "Empty group %s" group) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
193 (nnheader-insert (format "211 0 1 0 %s\n" group)))))))))) |
17493 | 194 |
195 (deffoo nnmh-request-scan (&optional group server) | |
196 (nnmail-get-new-mail 'nnmh nil nnmh-directory group)) | |
197 | |
198 (deffoo nnmh-request-list (&optional server dir) | |
199 (nnheader-insert "") | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
200 (nnmh-possibly-change-directory nil server) |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
201 (let ((file-name-coding-system nnmail-pathname-coding-system) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
202 (nnmh-toplev |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
203 (file-truename (or dir (file-name-as-directory nnmh-directory))))) |
17493 | 204 (nnmh-request-list-1 nnmh-toplev)) |
205 (setq nnmh-group-alist (nnmail-get-active)) | |
206 t) | |
207 | |
208 (defvar nnmh-toplev) | |
209 (defun nnmh-request-list-1 (dir) | |
210 (setq dir (expand-file-name dir)) | |
211 ;; Recurse down all directories. | |
212 (let ((dirs (and (file-readable-p dir) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
213 (nnheader-directory-files dir t nil t))) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
214 rdir) |
17493 | 215 ;; Recurse down directories. |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
216 (while (setq rdir (pop dirs)) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
217 (when (and (file-directory-p rdir) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
218 (file-readable-p rdir) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
219 (not (equal (file-truename rdir) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
220 (file-truename dir)))) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
221 (nnmh-request-list-1 rdir)))) |
17493 | 222 ;; For each directory, generate an active file line. |
223 (unless (string= (expand-file-name nnmh-toplev) dir) | |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
224 (let ((files (mapcar 'string-to-number |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
225 (directory-files dir nil "^[0-9]+$" t)))) |
17493 | 226 (when files |
92771
a3d61f1532f1
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
227 (with-current-buffer nntp-server-buffer |
17493 | 228 (goto-char (point-max)) |
229 (insert | |
230 (format | |
46966
47d8bf1dec03
* nnmh.el (nnmh-request-list-1): Use %.0f instead of %d to
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
31716
diff
changeset
|
231 "%s %.0f %.0f y\n" |
17493 | 232 (progn |
233 (string-match | |
234 (regexp-quote | |
235 (file-truename (file-name-as-directory | |
236 (expand-file-name nnmh-toplev)))) | |
237 dir) | |
92771
a3d61f1532f1
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
238 (mm-string-to-multibyte ;Why? Isn't it multibyte already? |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
239 (mm-encode-coding-string |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
240 (nnheader-replace-chars-in-string |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
241 (substring dir (match-end 0)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
242 ?/ ?.) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
243 nnmail-pathname-coding-system))) |
17493 | 244 (apply 'max files) |
245 (apply 'min files))))))) | |
246 t) | |
247 | |
248 (deffoo nnmh-request-newgroups (date &optional server) | |
249 (nnmh-request-list server)) | |
250 | |
251 (deffoo nnmh-request-expire-articles (articles newsgroup | |
252 &optional server force) | |
253 (nnmh-possibly-change-directory newsgroup server) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
254 (let* ((is-old t) |
17493 | 255 article rest mod-time) |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
256 (nnheader-init-server-buffer) |
17493 | 257 |
258 (while (and articles is-old) | |
259 (setq article (concat nnmh-current-directory | |
260 (int-to-string (car articles)))) | |
261 (when (setq mod-time (nth 5 (file-attributes article))) | |
262 (if (and (nnmh-deletable-article-p newsgroup (car articles)) | |
263 (setq is-old | |
264 (nnmail-expired-article-p newsgroup mod-time force))) | |
265 (progn | |
47002
b87254142b98
* nnfolder.el (nnfolder-request-expire-articles): expiry-target.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
46966
diff
changeset
|
266 ;; Allow a special target group. -- jcn |
b87254142b98
* nnfolder.el (nnfolder-request-expire-articles): expiry-target.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
46966
diff
changeset
|
267 (unless (eq nnmail-expiry-target 'delete) |
b87254142b98
* nnfolder.el (nnfolder-request-expire-articles): expiry-target.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
46966
diff
changeset
|
268 (with-temp-buffer |
b87254142b98
* nnfolder.el (nnfolder-request-expire-articles): expiry-target.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
46966
diff
changeset
|
269 (nnmh-request-article (car articles) |
b87254142b98
* nnfolder.el (nnfolder-request-expire-articles): expiry-target.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
46966
diff
changeset
|
270 newsgroup server (current-buffer)) |
b87254142b98
* nnfolder.el (nnfolder-request-expire-articles): expiry-target.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
46966
diff
changeset
|
271 (nnmail-expiry-target-group |
b87254142b98
* nnfolder.el (nnfolder-request-expire-articles): expiry-target.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
46966
diff
changeset
|
272 nnmail-expiry-target newsgroup))) |
17493 | 273 (nnheader-message 5 "Deleting article %s in %s..." |
274 article newsgroup) | |
275 (condition-case () | |
276 (funcall nnmail-delete-file-function article) | |
277 (file-error | |
278 (nnheader-message 1 "Couldn't delete article %s in %s" | |
279 article newsgroup) | |
280 (push (car articles) rest)))) | |
281 (push (car articles) rest))) | |
282 (setq articles (cdr articles))) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
283 (nnheader-message 5 "") |
17493 | 284 (nconc rest articles))) |
285 | |
286 (deffoo nnmh-close-group (group &optional server) | |
287 t) | |
288 | |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
289 (deffoo nnmh-request-move-article (article group server accept-form |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
290 &optional last move-is-internal) |
17493 | 291 (let ((buf (get-buffer-create " *nnmh move*")) |
292 result) | |
293 (and | |
294 (nnmh-deletable-article-p group article) | |
295 (nnmh-request-article article group server) | |
92771
a3d61f1532f1
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
296 (with-current-buffer buf |
17493 | 297 (erase-buffer) |
298 (insert-buffer-substring nntp-server-buffer) | |
299 (setq result (eval accept-form)) | |
300 (kill-buffer (current-buffer)) | |
301 result) | |
302 (progn | |
303 (nnmh-possibly-change-directory group server) | |
304 (condition-case () | |
305 (funcall nnmail-delete-file-function | |
306 (concat nnmh-current-directory (int-to-string article))) | |
307 (file-error nil)))) | |
308 result)) | |
309 | |
310 (deffoo nnmh-request-accept-article (group &optional server last noinsert) | |
311 (nnmh-possibly-change-directory group server) | |
312 (nnmail-check-syntax) | |
313 (when nnmail-cache-accepted-message-ids | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
314 (nnmail-cache-insert (nnmail-fetch-field "message-id") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
315 group |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
316 (nnmail-fetch-field "subject") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
317 (nnmail-fetch-field "from"))) |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
318 (nnheader-init-server-buffer) |
17493 | 319 (prog1 |
320 (if (stringp group) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
321 (if noinsert |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
322 (nnmh-active-number group) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
323 (car (nnmh-save-mail |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
324 (list (cons group (nnmh-active-number group))) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
325 noinsert))) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
326 (let ((res (nnmail-article-group 'nnmh-active-number))) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
327 (if (and (null res) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
328 (yes-or-no-p "Moved to `junk' group; delete article? ")) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
329 'junk |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
330 (car (nnmh-save-mail res noinsert))))) |
17493 | 331 (when (and last nnmail-cache-accepted-message-ids) |
332 (nnmail-cache-close)))) | |
333 | |
334 (deffoo nnmh-request-replace-article (article group buffer) | |
335 (nnmh-possibly-change-directory group) | |
92771
a3d61f1532f1
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
336 (with-current-buffer buffer |
17493 | 337 (nnmh-possibly-create-directory group) |
338 (ignore-errors | |
339 (nnmail-write-region | |
340 (point-min) (point-max) | |
341 (concat nnmh-current-directory (int-to-string article)) | |
342 nil (if (nnheader-be-verbose 5) nil 'nomesg)) | |
343 t))) | |
344 | |
345 (deffoo nnmh-request-create-group (group &optional server args) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
346 (nnheader-init-server-buffer) |
17493 | 347 (unless (assoc group nnmh-group-alist) |
348 (let (active) | |
349 (push (list group (setq active (cons 1 0))) | |
350 nnmh-group-alist) | |
351 (nnmh-possibly-create-directory group) | |
352 (nnmh-possibly-change-directory group server) | |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
353 (let ((articles (mapcar 'string-to-number |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
354 (directory-files |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
355 nnmh-current-directory nil "^[0-9]+$")))) |
17493 | 356 (when articles |
357 (setcar active (apply 'min articles)) | |
358 (setcdr active (apply 'max articles)))))) | |
359 t) | |
360 | |
361 (deffoo nnmh-request-delete-group (group &optional force server) | |
362 (nnmh-possibly-change-directory group server) | |
363 ;; Delete all articles in GROUP. | |
364 (if (not force) | |
365 () ; Don't delete the articles. | |
366 (let ((articles (directory-files nnmh-current-directory t "^[0-9]+$"))) | |
367 (while articles | |
368 (when (file-writable-p (car articles)) | |
369 (nnheader-message 5 "Deleting article %s in %s..." | |
370 (car articles) group) | |
371 (funcall nnmail-delete-file-function (car articles))) | |
372 (setq articles (cdr articles)))) | |
373 ;; Try to delete the directory itself. | |
374 (ignore-errors | |
375 (delete-directory nnmh-current-directory))) | |
376 ;; Remove the group from all structures. | |
377 (setq nnmh-group-alist | |
378 (delq (assoc group nnmh-group-alist) nnmh-group-alist) | |
379 nnmh-current-directory nil) | |
380 t) | |
381 | |
382 (deffoo nnmh-request-rename-group (group new-name &optional server) | |
383 (nnmh-possibly-change-directory group server) | |
384 (let ((new-dir (nnmail-group-pathname new-name nnmh-directory)) | |
385 (old-dir (nnmail-group-pathname group nnmh-directory))) | |
386 (when (ignore-errors | |
387 (make-directory new-dir t) | |
388 t) | |
389 ;; We move the articles file by file instead of renaming | |
390 ;; the directory -- there may be subgroups in this group. | |
391 ;; One might be more clever, I guess. | |
392 (let ((files (nnheader-article-to-file-alist old-dir))) | |
393 (while files | |
394 (rename-file | |
395 (concat old-dir (cdar files)) | |
396 (concat new-dir (cdar files))) | |
397 (pop files))) | |
398 (when (<= (length (directory-files old-dir)) 2) | |
399 (ignore-errors | |
400 (delete-directory old-dir))) | |
401 ;; That went ok, so we change the internal structures. | |
402 (let ((entry (assoc group nnmh-group-alist))) | |
403 (when entry | |
404 (setcar entry new-name)) | |
405 (setq nnmh-current-directory nil) | |
406 t)))) | |
407 | |
408 (nnoo-define-skeleton nnmh) | |
409 | |
410 | |
411 ;;; Internal functions. | |
412 | |
413 (defun nnmh-possibly-change-directory (newsgroup &optional server) | |
414 (when (and server | |
415 (not (nnmh-server-opened server))) | |
416 (nnmh-open-server server)) | |
417 (when newsgroup | |
19602
549f21ee4bf0
(nnmh-request-list, nnmh-active-number): Protect from
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
418 (let ((pathname (nnmail-group-pathname newsgroup nnmh-directory)) |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
419 (file-name-coding-system nnmail-pathname-coding-system)) |
17493 | 420 (if (file-directory-p pathname) |
421 (setq nnmh-current-directory pathname) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
422 (nnheader-report 'nnmh "Not a directory: %s" nnmh-directory))))) |
17493 | 423 |
424 (defun nnmh-possibly-create-directory (group) | |
425 (let (dir dirs) | |
426 (setq dir (nnmail-group-pathname group nnmh-directory)) | |
427 (while (not (file-directory-p dir)) | |
428 (push dir dirs) | |
429 (setq dir (file-name-directory (directory-file-name dir)))) | |
430 (while dirs | |
431 (when (make-directory (directory-file-name (car dirs))) | |
432 (error "Could not create directory %s" (car dirs))) | |
433 (nnheader-message 5 "Creating mail directory %s" (car dirs)) | |
434 (setq dirs (cdr dirs))))) | |
435 | |
436 (defun nnmh-save-mail (group-art &optional noinsert) | |
437 "Called narrowed to an article." | |
438 (unless noinsert | |
439 (nnmail-insert-lines) | |
440 (nnmail-insert-xref group-art)) | |
441 (run-hooks 'nnmail-prepare-save-mail-hook) | |
442 (run-hooks 'nnmh-prepare-save-mail-hook) | |
443 (goto-char (point-min)) | |
444 (while (looking-at "From ") | |
445 (replace-match "X-From-Line: ") | |
446 (forward-line 1)) | |
447 ;; We save the article in all the newsgroups it belongs in. | |
448 (let ((ga group-art) | |
449 first) | |
450 (while ga | |
451 (nnmh-possibly-create-directory (caar ga)) | |
452 (let ((file (concat (nnmail-group-pathname | |
453 (caar ga) nnmh-directory) | |
454 (int-to-string (cdar ga))))) | |
455 (if first | |
456 ;; It was already saved, so we just make a hard link. | |
457 (funcall nnmail-crosspost-link-function first file t) | |
458 ;; Save the article. | |
459 (nnmail-write-region (point-min) (point-max) file nil nil) | |
460 (setq first file))) | |
461 (setq ga (cdr ga)))) | |
462 group-art) | |
463 | |
464 (defun nnmh-active-number (group) | |
465 "Compute the next article number in GROUP." | |
466 (let ((active (cadr (assoc group nnmh-group-alist))) | |
19602
549f21ee4bf0
(nnmh-request-list, nnmh-active-number): Protect from
Kenichi Handa <handa@m17n.org>
parents:
19494
diff
changeset
|
467 (dir (nnmail-group-pathname group nnmh-directory)) |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
468 (file-name-coding-system nnmail-pathname-coding-system) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
469 file) |
17493 | 470 (unless active |
471 ;; The group wasn't known to nnmh, so we just create an active | |
472 ;; entry for it. | |
473 (setq active (cons 1 0)) | |
474 (push (list group active) nnmh-group-alist) | |
475 (unless (file-exists-p dir) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
476 (gnus-make-directory dir)) |
17493 | 477 ;; Find the highest number in the group. |
478 (let ((files (sort | |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
479 (mapcar 'string-to-number |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
480 (directory-files dir nil "^[0-9]+$")) |
17493 | 481 '>))) |
482 (when files | |
483 (setcdr active (car files))))) | |
484 (setcdr active (1+ (cdr active))) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
485 (while (or |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
486 ;; See whether the file exists... |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
487 (file-exists-p |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
488 (setq file (concat (nnmail-group-pathname group nnmh-directory) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
489 (int-to-string (cdr active))))) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
490 ;; ... or there is a buffer that will make that file exist |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
491 ;; in the future. |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
492 (get-file-buffer file)) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
493 ;; Skip past that file. |
17493 | 494 (setcdr active (1+ (cdr active)))) |
495 (cdr active))) | |
496 | |
497 (defun nnmh-update-gnus-unreads (group) | |
498 ;; Go through the .nnmh-articles file and compare with the actual | |
499 ;; articles in this folder. The articles that are "new" will be | |
500 ;; marked as unread by Gnus. | |
501 (let* ((dir nnmh-current-directory) | |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
502 (files (sort (mapcar 'string-to-number |
17493 | 503 (directory-files nnmh-current-directory |
504 nil "^[0-9]+$" t)) | |
505 '<)) | |
506 (nnmh-file (concat dir ".nnmh-articles")) | |
507 new articles) | |
508 ;; Load the .nnmh-articles file. | |
509 (when (file-exists-p nnmh-file) | |
510 (setq articles | |
511 (let (nnmh-newsgroup-articles) | |
512 (ignore-errors (load nnmh-file nil t t)) | |
513 nnmh-newsgroup-articles))) | |
514 ;; Add all new articles to the `new' list. | |
515 (let ((art files)) | |
516 (while art | |
517 (unless (assq (car art) articles) | |
518 (push (car art) new)) | |
519 (setq art (cdr art)))) | |
520 ;; Remove all deleted articles. | |
521 (let ((art articles)) | |
522 (while art | |
523 (unless (memq (caar art) files) | |
524 (setq articles (delq (car art) articles))) | |
525 (setq art (cdr art)))) | |
526 ;; Check whether the articles really are the ones that Gnus thinks | |
527 ;; they are by looking at the time-stamps. | |
528 (let ((arts articles) | |
529 art) | |
530 (while (setq art (pop arts)) | |
531 (when (not (equal | |
532 (nth 5 (file-attributes | |
533 (concat dir (int-to-string (car art))))) | |
534 (cdr art))) | |
535 (setq articles (delq art articles)) | |
536 (push (car art) new)))) | |
537 ;; Go through all the new articles and add them, and their | |
538 ;; time-stamps, to the list. | |
539 (setq articles | |
540 (nconc articles | |
541 (mapcar | |
542 (lambda (art) | |
543 (cons art | |
544 (nth 5 (file-attributes | |
545 (concat dir (int-to-string art)))))) | |
546 new))) | |
547 ;; Make Gnus mark all new articles as unread. | |
548 (when new | |
549 (gnus-make-articles-unread | |
550 (gnus-group-prefixed-name group (list 'nnmh "")) | |
551 (setq new (sort new '<)))) | |
552 ;; Sort the article list with highest numbers first. | |
553 (setq articles (sort articles (lambda (art1 art2) | |
554 (> (car art1) (car art2))))) | |
555 ;; Finally write this list back to the .nnmh-articles file. | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
556 (with-temp-file nnmh-file |
17493 | 557 (insert ";; Gnus article active file for " group "\n\n") |
558 (insert "(setq nnmh-newsgroup-articles '") | |
559 (gnus-prin1 articles) | |
560 (insert ")\n")))) | |
561 | |
562 (defun nnmh-deletable-article-p (group article) | |
563 "Say whether ARTICLE in GROUP can be deleted." | |
564 (let ((path (concat nnmh-current-directory (int-to-string article)))) | |
565 ;; Writable. | |
566 (and (file-writable-p path) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
567 (or |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
568 ;; We can never delete the last article in the group. |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
569 (not (eq (cdr (nth 1 (assoc group nnmh-group-alist))) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
570 article)) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
571 ;; Well, we can. |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19995
diff
changeset
|
572 nnmh-allow-delete-final)))) |
17493 | 573 |
574 (provide 'nnmh) | |
575 | |
92771
a3d61f1532f1
Use with-current-buffer.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
576 ;; arch-tag: 36c12a98-3bad-44b3-9953-628078ef0e04 |
17493 | 577 ;;; nnmh.el ends here |