Mercurial > hg > xemacs-beta
comparison lisp/gnus/nnmbox.el @ 70:131b0175ea99 r20-0b30
Import from CVS: tag r20-0b30
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:02:59 +0200 |
parents | 8b8b7f3559a2 |
children | 0d2f883870bc |
comparison
equal
deleted
inserted
replaced
69:804d1389bcd6 | 70:131b0175ea99 |
---|---|
1 ;;; nnmbox.el --- mail mbox access for Gnus | 1 ;;; nnmbox.el --- mail mbox access for Gnus |
2 ;; Copyright (C) 1995,96,97 Free Software Foundation, Inc. | 2 ;; Copyright (C) 1995,96 Free Software Foundation, Inc. |
3 | 3 |
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no> | 4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no> |
5 ;; Masanobu UMEDA <umerin@flab.flab.fujitsu.junet> | 5 ;; Masanobu UMEDA <umerin@flab.flab.fujitsu.junet> |
6 ;; Keywords: news, mail | 6 ;; Keywords: news, mail |
7 | 7 |
23 ;; Boston, MA 02111-1307, USA. | 23 ;; Boston, MA 02111-1307, USA. |
24 | 24 |
25 ;;; Commentary: | 25 ;;; Commentary: |
26 | 26 |
27 ;; For an overview of what the interface functions do, please see the | 27 ;; For an overview of what the interface functions do, please see the |
28 ;; Gnus sources. | 28 ;; Gnus sources. |
29 | 29 |
30 ;;; Code: | 30 ;;; Code: |
31 | 31 |
32 (require 'nnheader) | 32 (require 'nnheader) |
33 (require 'message) | 33 (require 'message) |
80 (nnmbox-possibly-change-newsgroup newsgroup server) | 80 (nnmbox-possibly-change-newsgroup newsgroup server) |
81 (while sequence | 81 (while sequence |
82 (setq article (car sequence)) | 82 (setq article (car sequence)) |
83 (setq art-string (nnmbox-article-string article)) | 83 (setq art-string (nnmbox-article-string article)) |
84 (set-buffer nnmbox-mbox-buffer) | 84 (set-buffer nnmbox-mbox-buffer) |
85 (when (or (search-forward art-string nil t) | 85 (if (or (search-forward art-string nil t) |
86 (progn (goto-char (point-min)) | 86 (progn (goto-char (point-min)) |
87 (search-forward art-string nil t))) | 87 (search-forward art-string nil t))) |
88 (setq start | 88 (progn |
89 (save-excursion | 89 (setq start |
90 (re-search-backward | 90 (save-excursion |
91 (concat "^" message-unix-mail-delimiter) nil t) | 91 (re-search-backward |
92 (point))) | 92 (concat "^" message-unix-mail-delimiter) nil t) |
93 (search-forward "\n\n" nil t) | 93 (point))) |
94 (setq stop (1- (point))) | 94 (search-forward "\n\n" nil t) |
95 (set-buffer nntp-server-buffer) | 95 (setq stop (1- (point))) |
96 (insert (format "221 %d Article retrieved.\n" article)) | 96 (set-buffer nntp-server-buffer) |
97 (insert-buffer-substring nnmbox-mbox-buffer start stop) | 97 (insert (format "221 %d Article retrieved.\n" article)) |
98 (goto-char (point-max)) | 98 (insert-buffer-substring nnmbox-mbox-buffer start stop) |
99 (insert ".\n")) | 99 (goto-char (point-max)) |
100 (insert ".\n"))) | |
100 (setq sequence (cdr sequence)) | 101 (setq sequence (cdr sequence)) |
101 (setq count (1+ count)) | 102 (setq count (1+ count)) |
102 (and (numberp nnmail-large-newsgroup) | 103 (and (numberp nnmail-large-newsgroup) |
103 (> number nnmail-large-newsgroup) | 104 (> number nnmail-large-newsgroup) |
104 (zerop (% count 20)) | 105 (zerop (% count 20)) |
113 (nnheader-fold-continuation-lines) | 114 (nnheader-fold-continuation-lines) |
114 'headers))) | 115 'headers))) |
115 | 116 |
116 (deffoo nnmbox-open-server (server &optional defs) | 117 (deffoo nnmbox-open-server (server &optional defs) |
117 (nnoo-change-server 'nnmbox server defs) | 118 (nnoo-change-server 'nnmbox server defs) |
118 (nnmbox-create-mbox) | 119 (cond |
119 (cond | |
120 ((not (file-exists-p nnmbox-mbox-file)) | 120 ((not (file-exists-p nnmbox-mbox-file)) |
121 (nnmbox-close-server) | 121 (nnmbox-close-server) |
122 (nnheader-report 'nnmbox "No such file: %s" nnmbox-mbox-file)) | 122 (nnheader-report 'nnmbox "No such file: %s" nnmbox-mbox-file)) |
123 ((file-directory-p nnmbox-mbox-file) | 123 ((file-directory-p nnmbox-mbox-file) |
124 (nnmbox-close-server) | 124 (nnmbox-close-server) |
145 (deffoo nnmbox-request-article (article &optional newsgroup server buffer) | 145 (deffoo nnmbox-request-article (article &optional newsgroup server buffer) |
146 (nnmbox-possibly-change-newsgroup newsgroup server) | 146 (nnmbox-possibly-change-newsgroup newsgroup server) |
147 (save-excursion | 147 (save-excursion |
148 (set-buffer nnmbox-mbox-buffer) | 148 (set-buffer nnmbox-mbox-buffer) |
149 (goto-char (point-min)) | 149 (goto-char (point-min)) |
150 (when (search-forward (nnmbox-article-string article) nil t) | 150 (if (search-forward (nnmbox-article-string article) nil t) |
151 (let (start stop) | 151 (let (start stop) |
152 (re-search-backward (concat "^" message-unix-mail-delimiter) nil t) | 152 (re-search-backward (concat "^" message-unix-mail-delimiter) nil t) |
153 (setq start (point)) | 153 (setq start (point)) |
154 (forward-line 1) | 154 (forward-line 1) |
155 (or (and (re-search-forward | 155 (or (and (re-search-forward |
156 (concat "^" message-unix-mail-delimiter) nil t) | 156 (concat "^" message-unix-mail-delimiter) nil t) |
157 (forward-line -1)) | 157 (forward-line -1)) |
158 (goto-char (point-max))) | 158 (goto-char (point-max))) |
159 (setq stop (point)) | 159 (setq stop (point)) |
160 (let ((nntp-server-buffer (or buffer nntp-server-buffer))) | 160 (let ((nntp-server-buffer (or buffer nntp-server-buffer))) |
161 (set-buffer nntp-server-buffer) | 161 (set-buffer nntp-server-buffer) |
162 (erase-buffer) | 162 (erase-buffer) |
163 (insert-buffer-substring nnmbox-mbox-buffer start stop) | 163 (insert-buffer-substring nnmbox-mbox-buffer start stop) |
164 (goto-char (point-min)) | 164 (goto-char (point-min)) |
165 (while (looking-at "From ") | 165 (while (looking-at "From ") |
166 (delete-char 5) | 166 (delete-char 5) |
167 (insert "X-From-Line: ") | 167 (insert "X-From-Line: ") |
168 (forward-line 1)) | 168 (forward-line 1)) |
169 (if (numberp article) | 169 (if (numberp article) |
170 (cons nnmbox-current-group article) | 170 (cons nnmbox-current-group article) |
171 (nnmbox-article-group-number))))))) | 171 (nnmbox-article-group-number))))))) |
172 | 172 |
173 (deffoo nnmbox-request-group (group &optional server dont-check) | 173 (deffoo nnmbox-request-group (group &optional server dont-check) |
174 (let ((active (cadr (assoc group nnmbox-group-alist)))) | 174 (let ((active (cadr (assoc group nnmbox-group-alist)))) |
175 (cond | 175 (cond |
176 ((or (null active) | 176 ((or (null active) |
177 (null (nnmbox-possibly-change-newsgroup group server))) | 177 (null (nnmbox-possibly-change-newsgroup group server))) |
178 (nnheader-report 'nnmbox "No such group: %s" group)) | 178 (nnheader-report 'nnmbox "No such group: %s" group)) |
179 (dont-check | 179 (dont-check |
180 (nnheader-report 'nnmbox "Selected group %s" group) | 180 (nnheader-report 'nnmbox "Selected group %s" group) |
181 (nnheader-insert "")) | 181 (nnheader-insert "")) |
182 (t | 182 (t |
183 (nnheader-report 'nnmbox "Selected group %s" group) | 183 (nnheader-report 'nnmbox "Selected group %s" group) |
184 (nnheader-insert "211 %d %d %d %s\n" | 184 (nnheader-insert "211 %d %d %d %s\n" |
185 (1+ (- (cdr active) (car active))) | 185 (1+ (- (cdr active) (car active))) |
186 (car active) (cdr active) group))))) | 186 (car active) (cdr active) group))))) |
187 | 187 |
188 (deffoo nnmbox-request-scan (&optional group server) | 188 (deffoo nnmbox-request-scan (&optional group server) |
189 (nnmbox-possibly-change-newsgroup group server) | |
190 (nnmbox-read-mbox) | 189 (nnmbox-read-mbox) |
191 (nnmail-get-new-mail | 190 (nnmail-get-new-mail |
192 'nnmbox | 191 'nnmbox |
193 (lambda () | 192 (lambda () |
194 (save-excursion | 193 (save-excursion |
195 (set-buffer nnmbox-mbox-buffer) | 194 (set-buffer nnmbox-mbox-buffer) |
196 (save-buffer))) | 195 (save-buffer))) |
197 (file-name-directory nnmbox-mbox-file) | 196 nnmbox-mbox-file group |
198 group | |
199 (lambda () | 197 (lambda () |
200 (save-excursion | 198 (save-excursion |
201 (let ((in-buf (current-buffer))) | 199 (let ((in-buf (current-buffer))) |
202 (set-buffer nnmbox-mbox-buffer) | 200 (set-buffer nnmbox-mbox-buffer) |
203 (goto-char (point-max)) | 201 (goto-char (point-max)) |
208 t) | 206 t) |
209 | 207 |
210 (deffoo nnmbox-request-list (&optional server) | 208 (deffoo nnmbox-request-list (&optional server) |
211 (save-excursion | 209 (save-excursion |
212 (nnmail-find-file nnmbox-active-file) | 210 (nnmail-find-file nnmbox-active-file) |
213 (setq nnmbox-group-alist (nnmail-get-active)) | 211 (setq nnmbox-group-alist (nnmail-get-active)))) |
214 t)) | |
215 | 212 |
216 (deffoo nnmbox-request-newgroups (date &optional server) | 213 (deffoo nnmbox-request-newgroups (date &optional server) |
217 (nnmbox-request-list server)) | 214 (nnmbox-request-list server)) |
218 | 215 |
219 (deffoo nnmbox-request-list-newsgroups (&optional server) | 216 (deffoo nnmbox-request-list-newsgroups (&optional server) |
220 (nnheader-report 'nnmbox "LIST NEWSGROUPS is not implemented.")) | 217 (nnheader-report 'nnmbox "LIST NEWSGROUPS is not implemented.")) |
221 | 218 |
222 (deffoo nnmbox-request-expire-articles | 219 (deffoo nnmbox-request-expire-articles |
223 (articles newsgroup &optional server force) | 220 (articles newsgroup &optional server force) |
224 (nnmbox-possibly-change-newsgroup newsgroup server) | 221 (nnmbox-possibly-change-newsgroup newsgroup server) |
225 (let* ((is-old t) | 222 (let* ((is-old t) |
226 rest) | 223 rest) |
227 (nnmail-activate 'nnmbox) | 224 (nnmail-activate 'nnmbox) |
228 | 225 |
229 (save-excursion | 226 (save-excursion |
230 (set-buffer nnmbox-mbox-buffer) | 227 (set-buffer nnmbox-mbox-buffer) |
231 (while (and articles is-old) | 228 (while (and articles is-old) |
232 (goto-char (point-min)) | 229 (goto-char (point-min)) |
233 (when (search-forward (nnmbox-article-string (car articles)) nil t) | 230 (if (search-forward (nnmbox-article-string (car articles)) nil t) |
234 (if (setq is-old | 231 (if (setq is-old |
235 (nnmail-expired-article-p | 232 (nnmail-expired-article-p |
236 newsgroup | 233 newsgroup |
237 (buffer-substring | 234 (buffer-substring |
238 (point) (progn (end-of-line) (point))) force)) | 235 (point) (progn (end-of-line) (point))) force)) |
239 (progn | 236 (progn |
240 (nnheader-message 5 "Deleting article %d in %s..." | 237 (nnheader-message 5 "Deleting article %d in %s..." |
241 (car articles) newsgroup) | 238 (car articles) newsgroup) |
242 (nnmbox-delete-mail)) | 239 (nnmbox-delete-mail)) |
243 (push (car articles) rest))) | 240 (setq rest (cons (car articles) rest)))) |
244 (setq articles (cdr articles))) | 241 (setq articles (cdr articles))) |
245 (save-buffer) | 242 (save-buffer) |
246 ;; Find the lowest active article in this group. | 243 ;; Find the lowest active article in this group. |
247 (let ((active (nth 1 (assoc newsgroup nnmbox-group-alist)))) | 244 (let ((active (nth 1 (assoc newsgroup nnmbox-group-alist)))) |
248 (goto-char (point-min)) | 245 (goto-char (point-min)) |
254 (nnmail-save-active nnmbox-group-alist nnmbox-active-file) | 251 (nnmail-save-active nnmbox-group-alist nnmbox-active-file) |
255 (nconc rest articles)))) | 252 (nconc rest articles)))) |
256 | 253 |
257 (deffoo nnmbox-request-move-article | 254 (deffoo nnmbox-request-move-article |
258 (article group server accept-form &optional last) | 255 (article group server accept-form &optional last) |
256 (nnmbox-possibly-change-newsgroup group server) | |
259 (let ((buf (get-buffer-create " *nnmbox move*")) | 257 (let ((buf (get-buffer-create " *nnmbox move*")) |
260 result) | 258 result) |
261 (and | 259 (and |
262 (nnmbox-request-article article group server) | 260 (nnmbox-request-article article group server) |
263 (save-excursion | 261 (save-excursion |
264 (set-buffer buf) | 262 (set-buffer buf) |
265 (buffer-disable-undo (current-buffer)) | 263 (buffer-disable-undo (current-buffer)) |
266 (erase-buffer) | 264 (erase-buffer) |
267 (insert-buffer-substring nntp-server-buffer) | 265 (insert-buffer-substring nntp-server-buffer) |
268 (goto-char (point-min)) | 266 (goto-char (point-min)) |
269 (while (re-search-forward | 267 (while (re-search-forward |
270 "^X-Gnus-Newsgroup:" | 268 "^X-Gnus-Newsgroup:" |
271 (save-excursion (search-forward "\n\n" nil t) (point)) t) | 269 (save-excursion (search-forward "\n\n" nil t) (point)) t) |
272 (delete-region (progn (beginning-of-line) (point)) | 270 (delete-region (progn (beginning-of-line) (point)) |
273 (progn (forward-line 1) (point)))) | 271 (progn (forward-line 1) (point)))) |
274 (setq result (eval accept-form)) | 272 (setq result (eval accept-form)) |
275 (kill-buffer buf) | 273 (kill-buffer buf) |
276 result) | 274 result) |
277 (save-excursion | 275 (save-excursion |
278 (nnmbox-possibly-change-newsgroup group server) | |
279 (set-buffer nnmbox-mbox-buffer) | 276 (set-buffer nnmbox-mbox-buffer) |
280 (goto-char (point-min)) | 277 (goto-char (point-min)) |
281 (when (search-forward (nnmbox-article-string article) nil t) | 278 (if (search-forward (nnmbox-article-string article) nil t) |
282 (nnmbox-delete-mail)) | 279 (nnmbox-delete-mail)) |
283 (and last (save-buffer)))) | 280 (and last (save-buffer)))) |
284 result)) | 281 result)) |
285 | 282 |
286 (deffoo nnmbox-request-accept-article (group &optional server last) | 283 (deffoo nnmbox-request-accept-article (group &optional server last) |
287 (nnmbox-possibly-change-newsgroup group server) | 284 (nnmbox-possibly-change-newsgroup group server) |
293 (when (looking-at (concat ">" message-unix-mail-delimiter)) | 290 (when (looking-at (concat ">" message-unix-mail-delimiter)) |
294 (delete-char 1)) | 291 (delete-char 1)) |
295 (if (looking-at "X-From-Line: ") | 292 (if (looking-at "X-From-Line: ") |
296 (replace-match "From ") | 293 (replace-match "From ") |
297 (insert "From nobody " (current-time-string) "\n")) | 294 (insert "From nobody " (current-time-string) "\n")) |
298 (and | 295 (and |
299 (nnmail-activate 'nnmbox) | 296 (nnmail-activate 'nnmbox) |
300 (progn | 297 (progn |
301 (set-buffer buf) | 298 (set-buffer buf) |
302 (goto-char (point-min)) | 299 (goto-char (point-min)) |
303 (search-forward "\n\n" nil t) | 300 (search-forward "\n\n" nil t) |
304 (forward-line -1) | 301 (forward-line -1) |
305 (while (re-search-backward "^X-Gnus-Newsgroup: " nil t) | 302 (while (re-search-backward "^X-Gnus-Newsgroup: " nil t) |
306 (delete-region (point) (progn (forward-line 1) (point)))) | 303 (delete-region (point) (progn (forward-line 1) (point)))) |
307 (when nnmail-cache-accepted-message-ids | 304 (setq result (nnmbox-save-mail (and (stringp group) group)))) |
308 (nnmail-cache-insert (nnmail-fetch-field "message-id"))) | |
309 (setq result (if (stringp group) | |
310 (list (cons group (nnmbox-active-number group))) | |
311 (nnmail-article-group 'nnmbox-active-number))) | |
312 (if (null result) | |
313 (setq result 'junk) | |
314 (setq result (car (nnmbox-save-mail result))))) | |
315 (save-excursion | 305 (save-excursion |
316 (set-buffer nnmbox-mbox-buffer) | 306 (set-buffer nnmbox-mbox-buffer) |
317 (goto-char (point-max)) | 307 (goto-char (point-max)) |
318 (insert-buffer-substring buf) | 308 (insert-buffer-substring buf) |
319 (when last | 309 (and last (save-buffer)) |
320 (when nnmail-cache-accepted-message-ids | 310 result) |
321 (nnmail-cache-close)) | 311 (nnmail-save-active nnmbox-group-alist nnmbox-active-file)) |
322 (nnmail-save-active nnmbox-group-alist nnmbox-active-file) | 312 (car result))) |
323 (save-buffer)))) | |
324 result)) | |
325 | 313 |
326 (deffoo nnmbox-request-replace-article (article group buffer) | 314 (deffoo nnmbox-request-replace-article (article group buffer) |
327 (nnmbox-possibly-change-newsgroup group) | 315 (nnmbox-possibly-change-newsgroup group) |
328 (save-excursion | 316 (save-excursion |
329 (set-buffer nnmbox-mbox-buffer) | 317 (set-buffer nnmbox-mbox-buffer) |
347 (let ((ident (concat "\nX-Gnus-Newsgroup: " nnmbox-current-group ":")) | 335 (let ((ident (concat "\nX-Gnus-Newsgroup: " nnmbox-current-group ":")) |
348 found) | 336 found) |
349 (while (search-forward ident nil t) | 337 (while (search-forward ident nil t) |
350 (setq found t) | 338 (setq found t) |
351 (nnmbox-delete-mail)) | 339 (nnmbox-delete-mail)) |
352 (when found | 340 (and found (save-buffer))))) |
353 (save-buffer))))) | |
354 ;; Remove the group from all structures. | 341 ;; Remove the group from all structures. |
355 (setq nnmbox-group-alist | 342 (setq nnmbox-group-alist |
356 (delq (assoc group nnmbox-group-alist) nnmbox-group-alist) | 343 (delq (assoc group nnmbox-group-alist) nnmbox-group-alist) |
357 nnmbox-current-group nil) | 344 nnmbox-current-group nil) |
358 ;; Save the active file. | 345 ;; Save the active file. |
359 (nnmail-save-active nnmbox-group-alist nnmbox-active-file) | 346 (nnmail-save-active nnmbox-group-alist nnmbox-active-file) |
360 t) | 347 t) |
368 (new-ident (concat "\nX-Gnus-Newsgroup: " new-name ":")) | 355 (new-ident (concat "\nX-Gnus-Newsgroup: " new-name ":")) |
369 found) | 356 found) |
370 (while (search-forward ident nil t) | 357 (while (search-forward ident nil t) |
371 (replace-match new-ident t t) | 358 (replace-match new-ident t t) |
372 (setq found t)) | 359 (setq found t)) |
373 (when found | 360 (and found (save-buffer)))) |
374 (save-buffer)))) | |
375 (let ((entry (assoc group nnmbox-group-alist))) | 361 (let ((entry (assoc group nnmbox-group-alist))) |
376 (when entry | 362 (and entry (setcar entry new-name)) |
377 (setcar entry new-name)) | |
378 (setq nnmbox-current-group nil) | 363 (setq nnmbox-current-group nil) |
379 ;; Save the new group alist. | 364 ;; Save the new group alist. |
380 (nnmail-save-active nnmbox-group-alist nnmbox-active-file) | 365 (nnmail-save-active nnmbox-group-alist nnmbox-active-file) |
381 t)) | 366 t)) |
382 | 367 |
383 | 368 |
384 ;;; Internal functions. | 369 ;;; Internal functions. |
385 | 370 |
386 ;; If FORCE, delete article no matter how many X-Gnus-Newsgroup | 371 ;; If FORCE, delete article no matter how many X-Gnus-Newsgroup |
387 ;; headers there are. If LEAVE-DELIM, don't delete the Unix mbox | 372 ;; headers there are. If LEAVE-DELIM, don't delete the Unix mbox |
388 ;; delimiter line. | 373 ;; delimiter line. |
389 (defun nnmbox-delete-mail (&optional force leave-delim) | 374 (defun nnmbox-delete-mail (&optional force leave-delim) |
390 ;; Delete the current X-Gnus-Newsgroup line. | 375 ;; Delete the current X-Gnus-Newsgroup line. |
391 (or force | 376 (or force |
392 (delete-region | 377 (delete-region |
400 (re-search-backward (concat "^" message-unix-mail-delimiter) nil t) | 385 (re-search-backward (concat "^" message-unix-mail-delimiter) nil t) |
401 (if leave-delim (progn (forward-line 1) (point)) | 386 (if leave-delim (progn (forward-line 1) (point)) |
402 (match-beginning 0))) | 387 (match-beginning 0))) |
403 (progn | 388 (progn |
404 (forward-line 1) | 389 (forward-line 1) |
405 (or (and (re-search-forward (concat "^" message-unix-mail-delimiter) | 390 (or (and (re-search-forward (concat "^" message-unix-mail-delimiter) |
406 nil t) | 391 nil t) |
407 (if (and (not (bobp)) leave-delim) | 392 (if (and (not (bobp)) leave-delim) |
408 (progn (forward-line -2) (point)) | 393 (progn (forward-line -2) (point)) |
409 (match-beginning 0))) | 394 (match-beginning 0))) |
410 (point-max)))) | 395 (point-max)))) |
411 (goto-char (point-min)) | 396 (goto-char (point-min)) |
412 ;; Only delete the article if no other groups owns it as well. | 397 ;; Only delete the article if no other groups owns it as well. |
413 (when (or force (not (re-search-forward "^X-Gnus-Newsgroup: " nil t))) | 398 (if (or force (not (re-search-forward "^X-Gnus-Newsgroup: " nil t))) |
414 (delete-region (point-min) (point-max)))))) | 399 (delete-region (point-min) (point-max)))))) |
415 | 400 |
416 (defun nnmbox-possibly-change-newsgroup (newsgroup &optional server) | 401 (defun nnmbox-possibly-change-newsgroup (newsgroup &optional server) |
417 (when (and server | 402 (when (and server |
418 (not (nnmbox-server-opened server))) | 403 (not (nnmbox-server-opened server))) |
419 (nnmbox-open-server server)) | 404 (nnmbox-open-server server)) |
420 (when (or (not nnmbox-mbox-buffer) | 405 (if (or (not nnmbox-mbox-buffer) |
421 (not (buffer-name nnmbox-mbox-buffer))) | 406 (not (buffer-name nnmbox-mbox-buffer))) |
422 (save-excursion | 407 (save-excursion |
423 (set-buffer (setq nnmbox-mbox-buffer | 408 (set-buffer (setq nnmbox-mbox-buffer |
424 (nnheader-find-file-noselect | 409 (nnheader-find-file-noselect |
425 nnmbox-mbox-file nil 'raw))) | 410 nnmbox-mbox-file nil 'raw))) |
426 (buffer-disable-undo (current-buffer)))) | 411 (buffer-disable-undo (current-buffer)))) |
427 (when (not nnmbox-group-alist) | 412 (if (not nnmbox-group-alist) |
428 (nnmail-activate 'nnmbox)) | 413 (nnmail-activate 'nnmbox)) |
429 (if newsgroup | 414 (if newsgroup |
430 (when (assoc newsgroup nnmbox-group-alist) | 415 (if (assoc newsgroup nnmbox-group-alist) |
431 (setq nnmbox-current-group newsgroup)) | 416 (setq nnmbox-current-group newsgroup)) |
432 t)) | 417 t)) |
433 | 418 |
434 (defun nnmbox-article-string (article) | 419 (defun nnmbox-article-string (article) |
435 (if (numberp article) | 420 (if (numberp article) |
436 (concat "\nX-Gnus-Newsgroup: " nnmbox-current-group ":" | 421 (concat "\nX-Gnus-Newsgroup: " nnmbox-current-group ":" |
437 (int-to-string article) " ") | 422 (int-to-string article) " ") |
438 (concat "\nMessage-ID: " article))) | 423 (concat "\nMessage-ID: " article))) |
439 | 424 |
440 (defun nnmbox-article-group-number () | 425 (defun nnmbox-article-group-number () |
441 (save-excursion | 426 (save-excursion |
442 (goto-char (point-min)) | 427 (goto-char (point-min)) |
443 (when (re-search-forward "^X-Gnus-Newsgroup: +\\([^:]+\\):\\([0-9]+\\) " | 428 (and (re-search-forward "^X-Gnus-Newsgroup: +\\([^:]+\\):\\([0-9]+\\) " |
444 nil t) | 429 nil t) |
445 (cons (buffer-substring (match-beginning 1) (match-end 1)) | 430 (cons (buffer-substring (match-beginning 1) (match-end 1)) |
446 (string-to-int | 431 (string-to-int |
447 (buffer-substring (match-beginning 2) (match-end 2))))))) | 432 (buffer-substring (match-beginning 2) (match-end 2))))))) |
448 | 433 |
449 (defun nnmbox-save-mail (group-art) | 434 (defun nnmbox-save-mail (&optional group) |
450 "Called narrowed to an article." | 435 "Called narrowed to an article." |
451 (let ((delim (concat "^" message-unix-mail-delimiter))) | 436 (let* ((nnmail-split-methods |
437 (if group (list (list group "")) nnmail-split-methods)) | |
438 (group-art (nreverse (nnmail-article-group 'nnmbox-active-number))) | |
439 (delim (concat "^" message-unix-mail-delimiter))) | |
452 (goto-char (point-min)) | 440 (goto-char (point-min)) |
453 ;; This might come from somewhere else. | 441 ;; This might come from somewhere else. |
454 (unless (looking-at delim) | 442 (unless (looking-at delim) |
455 (insert "From nobody " (current-time-string) "\n") | 443 (insert "From nobody " (current-time-string) "\n") |
456 (goto-char (point-min))) | 444 (goto-char (point-min))) |
467 group-art)) | 455 group-art)) |
468 | 456 |
469 (defun nnmbox-insert-newsgroup-line (group-art) | 457 (defun nnmbox-insert-newsgroup-line (group-art) |
470 (save-excursion | 458 (save-excursion |
471 (goto-char (point-min)) | 459 (goto-char (point-min)) |
472 (when (search-forward "\n\n" nil t) | 460 (if (search-forward "\n\n" nil t) |
473 (forward-char -1) | 461 (progn |
474 (while group-art | 462 (forward-char -1) |
475 (insert (format "X-Gnus-Newsgroup: %s:%d %s\n" | 463 (while group-art |
476 (caar group-art) (cdar group-art) | 464 (insert (format "X-Gnus-Newsgroup: %s:%d %s\n" |
477 (current-time-string))) | 465 (caar group-art) (cdar group-art) |
478 (setq group-art (cdr group-art)))) | 466 (current-time-string))) |
467 (setq group-art (cdr group-art))))) | |
479 t)) | 468 t)) |
480 | 469 |
481 (defun nnmbox-active-number (group) | 470 (defun nnmbox-active-number (group) |
482 ;; Find the next article number in GROUP. | 471 ;; Find the next article number in GROUP. |
483 (let ((active (cadr (assoc group nnmbox-group-alist)))) | 472 (let ((active (cadr (assoc group nnmbox-group-alist)))) |
484 (if active | 473 (if active |
485 (setcdr active (1+ (cdr active))) | 474 (setcdr active (1+ (cdr active))) |
486 ;; This group is new, so we create a new entry for it. | 475 ;; This group is new, so we create a new entry for it. |
487 ;; This might be a bit naughty... creating groups on the drop of | 476 ;; This might be a bit naughty... creating groups on the drop of |
488 ;; a hat, but I don't know... | 477 ;; a hat, but I don't know... |
489 (push (list group (setq active (cons 1 1))) | 478 (setq nnmbox-group-alist (cons (list group (setq active (cons 1 1))) |
490 nnmbox-group-alist)) | 479 nnmbox-group-alist))) |
491 (cdr active))) | 480 (cdr active))) |
492 | |
493 (defun nnmbox-create-mbox () | |
494 (when (not (file-exists-p nnmbox-mbox-file)) | |
495 (nnmail-write-region 1 1 nnmbox-mbox-file t 'nomesg))) | |
496 | 481 |
497 (defun nnmbox-read-mbox () | 482 (defun nnmbox-read-mbox () |
498 (nnmail-activate 'nnmbox) | 483 (nnmail-activate 'nnmbox) |
499 (nnmbox-create-mbox) | 484 (if (not (file-exists-p nnmbox-mbox-file)) |
485 (write-region 1 1 nnmbox-mbox-file t 'nomesg)) | |
500 (if (and nnmbox-mbox-buffer | 486 (if (and nnmbox-mbox-buffer |
501 (buffer-name nnmbox-mbox-buffer) | 487 (buffer-name nnmbox-mbox-buffer) |
502 (save-excursion | 488 (save-excursion |
503 (set-buffer nnmbox-mbox-buffer) | 489 (set-buffer nnmbox-mbox-buffer) |
504 (= (buffer-size) (nnheader-file-size nnmbox-mbox-file)))) | 490 (= (buffer-size) (nnheader-file-size nnmbox-mbox-file)))) |
505 () | 491 () |
506 (save-excursion | 492 (save-excursion |
507 (let ((delim (concat "^" message-unix-mail-delimiter)) | 493 (let ((delim (concat "^" message-unix-mail-delimiter)) |
508 (alist nnmbox-group-alist) | 494 (alist nnmbox-group-alist) |
509 start end number) | 495 start end number) |
510 (set-buffer (setq nnmbox-mbox-buffer | 496 (set-buffer (setq nnmbox-mbox-buffer |
511 (nnheader-find-file-noselect | 497 (nnheader-find-file-noselect |
512 nnmbox-mbox-file nil 'raw))) | 498 nnmbox-mbox-file nil 'raw))) |
513 (buffer-disable-undo (current-buffer)) | 499 (buffer-disable-undo (current-buffer)) |
514 | 500 |
515 ;; Go through the group alist and compare against | 501 ;; Go through the group alist and compare against |
518 (goto-char (point-max)) | 504 (goto-char (point-max)) |
519 (when (and (re-search-backward | 505 (when (and (re-search-backward |
520 (format "^X-Gnus-Newsgroup: %s:\\([0-9]+\\) " | 506 (format "^X-Gnus-Newsgroup: %s:\\([0-9]+\\) " |
521 (caar alist)) nil t) | 507 (caar alist)) nil t) |
522 (>= (setq number | 508 (>= (setq number |
523 (string-to-number | 509 (string-to-number |
524 (buffer-substring | 510 (buffer-substring |
525 (match-beginning 1) (match-end 1)))) | 511 (match-beginning 1) (match-end 1)))) |
526 (cdadar alist))) | 512 (cdadar alist))) |
527 (setcdr (cadar alist) (1+ number))) | 513 (setcdr (cadar alist) (1+ number))) |
528 (setq alist (cdr alist))) | 514 (setq alist (cdr alist))) |
529 | 515 |
530 (goto-char (point-min)) | 516 (goto-char (point-min)) |
531 (while (re-search-forward delim nil t) | 517 (while (re-search-forward delim nil t) |
532 (setq start (match-beginning 0)) | 518 (setq start (match-beginning 0)) |
533 (when (not (search-forward "\nX-Gnus-Newsgroup: " | 519 (if (not (search-forward "\nX-Gnus-Newsgroup: " |
534 (save-excursion | 520 (save-excursion |
535 (setq end | 521 (setq end |
536 (or | 522 (or |
537 (and | 523 (and |
538 (re-search-forward delim nil t) | 524 (re-search-forward delim nil t) |
539 (match-beginning 0)) | 525 (match-beginning 0)) |
540 (point-max)))) | 526 (point-max)))) |
541 t)) | 527 t)) |
542 (save-excursion | 528 (save-excursion |
543 (save-restriction | 529 (save-restriction |
544 (narrow-to-region start end) | 530 (narrow-to-region start end) |
545 (nnmbox-save-mail | 531 (nnmbox-save-mail)))) |
546 (nnmail-article-group 'nnmbox-active-number))))) | |
547 (goto-char end)))))) | 532 (goto-char end)))))) |
548 | 533 |
549 (provide 'nnmbox) | 534 (provide 'nnmbox) |
550 | 535 |
551 ;;; nnmbox.el ends here | 536 ;;; nnmbox.el ends here |