comparison lisp/gnus/nnmbox.el @ 108:360340f9fd5f r20-1b6

Import from CVS: tag r20-1b6
author cvs
date Mon, 13 Aug 2007 09:18:39 +0200
parents 4be1180a9e89
children 8619ce7e4c50
comparison
equal deleted inserted replaced
107:523141596bda 108:360340f9fd5f
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)
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 (when (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 (setq start
89 (save-excursion 89 (save-excursion
90 (re-search-backward 90 (re-search-backward
91 (concat "^" message-unix-mail-delimiter) nil t) 91 (concat "^" message-unix-mail-delimiter) nil t)
92 (point))) 92 (point)))
93 (search-forward "\n\n" nil t) 93 (search-forward "\n\n" nil t)
94 (setq stop (1- (point))) 94 (setq stop (1- (point)))
95 (set-buffer nntp-server-buffer) 95 (set-buffer nntp-server-buffer)
114 'headers))) 114 'headers)))
115 115
116 (deffoo nnmbox-open-server (server &optional defs) 116 (deffoo nnmbox-open-server (server &optional defs)
117 (nnoo-change-server 'nnmbox server defs) 117 (nnoo-change-server 'nnmbox server defs)
118 (nnmbox-create-mbox) 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)
150 (when (search-forward (nnmbox-article-string article) nil t) 150 (when (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)))
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) 189 (nnmbox-possibly-change-newsgroup group server)
190 (nnmbox-read-mbox) 190 (nnmbox-read-mbox)
191 (nnmail-get-new-mail 191 (nnmail-get-new-mail
192 'nnmbox 192 'nnmbox
193 (lambda () 193 (lambda ()
194 (save-excursion 194 (save-excursion
195 (set-buffer nnmbox-mbox-buffer) 195 (set-buffer nnmbox-mbox-buffer)
196 (save-buffer))) 196 (save-buffer)))
197 (file-name-directory nnmbox-mbox-file) 197 (file-name-directory nnmbox-mbox-file)
217 (nnmbox-request-list server)) 217 (nnmbox-request-list server))
218 218
219 (deffoo nnmbox-request-list-newsgroups (&optional server) 219 (deffoo nnmbox-request-list-newsgroups (&optional server)
220 (nnheader-report 'nnmbox "LIST NEWSGROUPS is not implemented.")) 220 (nnheader-report 'nnmbox "LIST NEWSGROUPS is not implemented."))
221 221
222 (deffoo nnmbox-request-expire-articles 222 (deffoo nnmbox-request-expire-articles
223 (articles newsgroup &optional server force) 223 (articles newsgroup &optional server force)
224 (nnmbox-possibly-change-newsgroup newsgroup server) 224 (nnmbox-possibly-change-newsgroup newsgroup server)
225 (let* ((is-old t) 225 (let* ((is-old t)
226 rest) 226 rest)
227 (nnmail-activate 'nnmbox) 227 (nnmail-activate 'nnmbox)
228 228
229 (save-excursion 229 (save-excursion
230 (set-buffer nnmbox-mbox-buffer) 230 (set-buffer nnmbox-mbox-buffer)
231 (while (and articles is-old) 231 (while (and articles is-old)
232 (goto-char (point-min)) 232 (goto-char (point-min))
233 (when (search-forward (nnmbox-article-string (car articles)) nil t) 233 (when (search-forward (nnmbox-article-string (car articles)) nil t)
234 (if (setq is-old 234 (if (setq is-old
235 (nnmail-expired-article-p 235 (nnmail-expired-article-p
236 newsgroup 236 newsgroup
237 (buffer-substring 237 (buffer-substring
238 (point) (progn (end-of-line) (point))) force)) 238 (point) (progn (end-of-line) (point))) force))
239 (progn 239 (progn
240 (nnheader-message 5 "Deleting article %d in %s..." 240 (nnheader-message 5 "Deleting article %d in %s..."
241 (car articles) newsgroup) 241 (car articles) newsgroup)
242 (nnmbox-delete-mail)) 242 (nnmbox-delete-mail))
256 256
257 (deffoo nnmbox-request-move-article 257 (deffoo nnmbox-request-move-article
258 (article group server accept-form &optional last) 258 (article group server accept-form &optional last)
259 (let ((buf (get-buffer-create " *nnmbox move*")) 259 (let ((buf (get-buffer-create " *nnmbox move*"))
260 result) 260 result)
261 (and 261 (and
262 (nnmbox-request-article article group server) 262 (nnmbox-request-article article group server)
263 (save-excursion 263 (save-excursion
264 (set-buffer buf) 264 (set-buffer buf)
265 (buffer-disable-undo (current-buffer)) 265 (buffer-disable-undo (current-buffer))
266 (erase-buffer) 266 (erase-buffer)
267 (insert-buffer-substring nntp-server-buffer) 267 (insert-buffer-substring nntp-server-buffer)
268 (goto-char (point-min)) 268 (goto-char (point-min))
269 (while (re-search-forward 269 (while (re-search-forward
270 "^X-Gnus-Newsgroup:" 270 "^X-Gnus-Newsgroup:"
271 (save-excursion (search-forward "\n\n" nil t) (point)) t) 271 (save-excursion (search-forward "\n\n" nil t) (point)) t)
272 (delete-region (progn (beginning-of-line) (point)) 272 (delete-region (progn (beginning-of-line) (point))
273 (progn (forward-line 1) (point)))) 273 (progn (forward-line 1) (point))))
274 (setq result (eval accept-form)) 274 (setq result (eval accept-form))
275 (kill-buffer buf) 275 (kill-buffer buf)
293 (when (looking-at (concat ">" message-unix-mail-delimiter)) 293 (when (looking-at (concat ">" message-unix-mail-delimiter))
294 (delete-char 1)) 294 (delete-char 1))
295 (if (looking-at "X-From-Line: ") 295 (if (looking-at "X-From-Line: ")
296 (replace-match "From ") 296 (replace-match "From ")
297 (insert "From nobody " (current-time-string) "\n")) 297 (insert "From nobody " (current-time-string) "\n"))
298 (and 298 (and
299 (nnmail-activate 'nnmbox) 299 (nnmail-activate 'nnmbox)
300 (progn 300 (progn
301 (set-buffer buf) 301 (set-buffer buf)
302 (goto-char (point-min)) 302 (goto-char (point-min))
303 (search-forward "\n\n" nil t) 303 (search-forward "\n\n" nil t)
304 (forward-line -1) 304 (forward-line -1)
305 (while (re-search-backward "^X-Gnus-Newsgroup: " nil t) 305 (while (re-search-backward "^X-Gnus-Newsgroup: " nil t)
306 (delete-region (point) (progn (forward-line 1) (point)))) 306 (delete-region (point) (progn (forward-line 1) (point))))
307 (nnmail-cache-insert (nnmail-fetch-field "message-id"))
307 (setq result (nnmbox-save-mail 308 (setq result (nnmbox-save-mail
308 (if (stringp group) 309 (if (stringp group)
309 (list (cons group (nnmbox-active-number group))) 310 (list (cons group (nnmbox-active-number group)))
310 (nnmail-article-group 'nnmbox-active-number))))) 311 (nnmail-article-group 'nnmbox-active-number)))))
311 (save-excursion 312 (save-excursion
312 (set-buffer nnmbox-mbox-buffer) 313 (set-buffer nnmbox-mbox-buffer)
313 (goto-char (point-max)) 314 (goto-char (point-max))
314 (insert-buffer-substring buf) 315 (insert-buffer-substring buf)
315 (and last (save-buffer)) 316 (when last
316 result) 317 (nnmail-cache-close)
317 (nnmail-save-active nnmbox-group-alist nnmbox-active-file)) 318 (nnmail-save-active nnmbox-group-alist nnmbox-active-file)
319 (save-buffer))))
318 (car result))) 320 (car result)))
319 321
320 (deffoo nnmbox-request-replace-article (article group buffer) 322 (deffoo nnmbox-request-replace-article (article group buffer)
321 (nnmbox-possibly-change-newsgroup group) 323 (nnmbox-possibly-change-newsgroup group)
322 (save-excursion 324 (save-excursion
344 (setq found t) 346 (setq found t)
345 (nnmbox-delete-mail)) 347 (nnmbox-delete-mail))
346 (when found 348 (when found
347 (save-buffer))))) 349 (save-buffer)))))
348 ;; Remove the group from all structures. 350 ;; Remove the group from all structures.
349 (setq nnmbox-group-alist 351 (setq nnmbox-group-alist
350 (delq (assoc group nnmbox-group-alist) nnmbox-group-alist) 352 (delq (assoc group nnmbox-group-alist) nnmbox-group-alist)
351 nnmbox-current-group nil) 353 nnmbox-current-group nil)
352 ;; Save the active file. 354 ;; Save the active file.
353 (nnmail-save-active nnmbox-group-alist nnmbox-active-file) 355 (nnmail-save-active nnmbox-group-alist nnmbox-active-file)
354 t) 356 t)
406 ;; Only delete the article if no other groups owns it as well. 408 ;; Only delete the article if no other groups owns it as well.
407 (when (or force (not (re-search-forward "^X-Gnus-Newsgroup: " nil t))) 409 (when (or force (not (re-search-forward "^X-Gnus-Newsgroup: " nil t)))
408 (delete-region (point-min) (point-max)))))) 410 (delete-region (point-min) (point-max))))))
409 411
410 (defun nnmbox-possibly-change-newsgroup (newsgroup &optional server) 412 (defun nnmbox-possibly-change-newsgroup (newsgroup &optional server)
411 (when (and server 413 (when (and server
412 (not (nnmbox-server-opened server))) 414 (not (nnmbox-server-opened server)))
413 (nnmbox-open-server server)) 415 (nnmbox-open-server server))
414 (when (or (not nnmbox-mbox-buffer) 416 (when (or (not nnmbox-mbox-buffer)
415 (not (buffer-name nnmbox-mbox-buffer))) 417 (not (buffer-name nnmbox-mbox-buffer)))
416 (save-excursion 418 (save-excursion
417 (set-buffer (setq nnmbox-mbox-buffer 419 (set-buffer (setq nnmbox-mbox-buffer
418 (nnheader-find-file-noselect 420 (nnheader-find-file-noselect
419 nnmbox-mbox-file nil 'raw))) 421 nnmbox-mbox-file nil 'raw)))
420 (buffer-disable-undo (current-buffer)))) 422 (buffer-disable-undo (current-buffer))))
421 (when (not nnmbox-group-alist) 423 (when (not nnmbox-group-alist)
422 (nnmail-activate 'nnmbox)) 424 (nnmail-activate 'nnmbox))
425 (setq nnmbox-current-group newsgroup)) 427 (setq nnmbox-current-group newsgroup))
426 t)) 428 t))
427 429
428 (defun nnmbox-article-string (article) 430 (defun nnmbox-article-string (article)
429 (if (numberp article) 431 (if (numberp article)
430 (concat "\nX-Gnus-Newsgroup: " nnmbox-current-group ":" 432 (concat "\nX-Gnus-Newsgroup: " nnmbox-current-group ":"
431 (int-to-string article) " ") 433 (int-to-string article) " ")
432 (concat "\nMessage-ID: " article))) 434 (concat "\nMessage-ID: " article)))
433 435
434 (defun nnmbox-article-group-number () 436 (defun nnmbox-article-group-number ()
435 (save-excursion 437 (save-excursion
464 (save-excursion 466 (save-excursion
465 (goto-char (point-min)) 467 (goto-char (point-min))
466 (when (search-forward "\n\n" nil t) 468 (when (search-forward "\n\n" nil t)
467 (forward-char -1) 469 (forward-char -1)
468 (while group-art 470 (while group-art
469 (insert (format "X-Gnus-Newsgroup: %s:%d %s\n" 471 (insert (format "X-Gnus-Newsgroup: %s:%d %s\n"
470 (caar group-art) (cdar group-art) 472 (caar group-art) (cdar group-art)
471 (current-time-string))) 473 (current-time-string)))
472 (setq group-art (cdr group-art)))) 474 (setq group-art (cdr group-art))))
473 t)) 475 t))
474 476
499 () 501 ()
500 (save-excursion 502 (save-excursion
501 (let ((delim (concat "^" message-unix-mail-delimiter)) 503 (let ((delim (concat "^" message-unix-mail-delimiter))
502 (alist nnmbox-group-alist) 504 (alist nnmbox-group-alist)
503 start end number) 505 start end number)
504 (set-buffer (setq nnmbox-mbox-buffer 506 (set-buffer (setq nnmbox-mbox-buffer
505 (nnheader-find-file-noselect 507 (nnheader-find-file-noselect
506 nnmbox-mbox-file nil 'raw))) 508 nnmbox-mbox-file nil 'raw)))
507 (buffer-disable-undo (current-buffer)) 509 (buffer-disable-undo (current-buffer))
508 510
509 ;; Go through the group alist and compare against 511 ;; Go through the group alist and compare against
512 (goto-char (point-max)) 514 (goto-char (point-max))
513 (when (and (re-search-backward 515 (when (and (re-search-backward
514 (format "^X-Gnus-Newsgroup: %s:\\([0-9]+\\) " 516 (format "^X-Gnus-Newsgroup: %s:\\([0-9]+\\) "
515 (caar alist)) nil t) 517 (caar alist)) nil t)
516 (>= (setq number 518 (>= (setq number
517 (string-to-number 519 (string-to-number
518 (buffer-substring 520 (buffer-substring
519 (match-beginning 1) (match-end 1)))) 521 (match-beginning 1) (match-end 1))))
520 (cdadar alist))) 522 (cdadar alist)))
521 (setcdr (cadar alist) (1+ number))) 523 (setcdr (cadar alist) (1+ number)))
522 (setq alist (cdr alist))) 524 (setq alist (cdr alist)))
523 525
524 (goto-char (point-min)) 526 (goto-char (point-min))
525 (while (re-search-forward delim nil t) 527 (while (re-search-forward delim nil t)
526 (setq start (match-beginning 0)) 528 (setq start (match-beginning 0))
527 (when (not (search-forward "\nX-Gnus-Newsgroup: " 529 (when (not (search-forward "\nX-Gnus-Newsgroup: "
528 (save-excursion 530 (save-excursion
529 (setq end 531 (setq end
530 (or 532 (or
531 (and 533 (and
532 (re-search-forward delim nil t) 534 (re-search-forward delim nil t)
533 (match-beginning 0)) 535 (match-beginning 0))
534 (point-max)))) 536 (point-max))))
535 t)) 537 t))
536 (save-excursion 538 (save-excursion
537 (save-restriction 539 (save-restriction
538 (narrow-to-region start end) 540 (narrow-to-region start end)
539 (nnmbox-save-mail 541 (nnmbox-save-mail
540 (nnmail-article-group 'nnmbox-active-number))))) 542 (nnmail-article-group 'nnmbox-active-number)))))
541 (goto-char end)))))) 543 (goto-char end))))))
542 544
543 (provide 'nnmbox) 545 (provide 'nnmbox)
544 546