comparison lisp/gnus/nnbabyl.el @ 30:ec9a17fef872 r19-15b98

Import from CVS: tag r19-15b98
author cvs
date Mon, 13 Aug 2007 08:52:29 +0200
parents 4103f0995bd7
children c53a95d3c46d
comparison
equal deleted inserted replaced
29:7976500f47f9 30:ec9a17fef872
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 'rmail) 33 (require 'rmail)
117 'headers))) 117 'headers)))
118 118
119 (deffoo nnbabyl-open-server (server &optional defs) 119 (deffoo nnbabyl-open-server (server &optional defs)
120 (nnoo-change-server 'nnbabyl server defs) 120 (nnoo-change-server 'nnbabyl server defs)
121 (nnbabyl-create-mbox) 121 (nnbabyl-create-mbox)
122 (cond 122 (cond
123 ((not (file-exists-p nnbabyl-mbox-file)) 123 ((not (file-exists-p nnbabyl-mbox-file))
124 (nnbabyl-close-server) 124 (nnbabyl-close-server)
125 (nnheader-report 'nnbabyl "No such file: %s" nnbabyl-mbox-file)) 125 (nnheader-report 'nnbabyl "No such file: %s" nnbabyl-mbox-file))
126 ((file-directory-p nnbabyl-mbox-file) 126 ((file-directory-p nnbabyl-mbox-file)
127 (nnbabyl-close-server) 127 (nnbabyl-close-server)
163 (goto-char (point-min)) 163 (goto-char (point-min))
164 (end-of-line)) 164 (end-of-line))
165 (while (and (not (looking-at ".+:")) 165 (while (and (not (looking-at ".+:"))
166 (zerop (forward-line 1)))) 166 (zerop (forward-line 1))))
167 (setq start (point)) 167 (setq start (point))
168 (or (when (re-search-forward 168 (or (when (re-search-forward
169 (concat "^" nnbabyl-mail-delimiter) nil t) 169 (concat "^" nnbabyl-mail-delimiter) nil t)
170 (beginning-of-line) 170 (beginning-of-line)
171 t) 171 t)
172 (goto-char (point-max))) 172 (goto-char (point-max)))
173 (setq stop (point)) 173 (setq stop (point))
175 (set-buffer nntp-server-buffer) 175 (set-buffer nntp-server-buffer)
176 (erase-buffer) 176 (erase-buffer)
177 (insert-buffer-substring nnbabyl-mbox-buffer start stop) 177 (insert-buffer-substring nnbabyl-mbox-buffer start stop)
178 (goto-char (point-min)) 178 (goto-char (point-min))
179 ;; If there is an EOOH header, then we have to remove some 179 ;; If there is an EOOH header, then we have to remove some
180 ;; duplicated headers. 180 ;; duplicated headers.
181 (setq summary-line (looking-at "Summary-line:")) 181 (setq summary-line (looking-at "Summary-line:"))
182 (when (search-forward "\n*** EOOH ***" nil t) 182 (when (search-forward "\n*** EOOH ***" nil t)
183 (if summary-line 183 (if summary-line
184 ;; The headers to be deleted are located before the 184 ;; The headers to be deleted are located before the
185 ;; EOOH line... 185 ;; EOOH line...
194 (nnbabyl-article-group-number))))))) 194 (nnbabyl-article-group-number)))))))
195 195
196 (deffoo nnbabyl-request-group (group &optional server dont-check) 196 (deffoo nnbabyl-request-group (group &optional server dont-check)
197 (let ((active (cadr (assoc group nnbabyl-group-alist)))) 197 (let ((active (cadr (assoc group nnbabyl-group-alist))))
198 (save-excursion 198 (save-excursion
199 (cond 199 (cond
200 ((or (null active) 200 ((or (null active)
201 (null (nnbabyl-possibly-change-newsgroup group server))) 201 (null (nnbabyl-possibly-change-newsgroup group server)))
202 (nnheader-report 'nnbabyl "No such group: %s" group)) 202 (nnheader-report 'nnbabyl "No such group: %s" group))
203 (dont-check 203 (dont-check
204 (nnheader-report 'nnbabyl "Selected group %s" group) 204 (nnheader-report 'nnbabyl "Selected group %s" group)
205 (nnheader-insert "")) 205 (nnheader-insert ""))
206 (t 206 (t
207 (nnheader-report 'nnbabyl "Selected group %s" group) 207 (nnheader-report 'nnbabyl "Selected group %s" group)
208 (nnheader-insert "211 %d %d %d %s\n" 208 (nnheader-insert "211 %d %d %d %s\n"
209 (1+ (- (cdr active) (car active))) 209 (1+ (- (cdr active) (car active)))
210 (car active) (cdr active) group)))))) 210 (car active) (cdr active) group))))))
211 211
212 (deffoo nnbabyl-request-scan (&optional group server) 212 (deffoo nnbabyl-request-scan (&optional group server)
213 (nnbabyl-possibly-change-newsgroup group server) 213 (nnbabyl-possibly-change-newsgroup group server)
214 (nnbabyl-read-mbox) 214 (nnbabyl-read-mbox)
215 (nnmail-get-new-mail 215 (nnmail-get-new-mail
216 'nnbabyl 216 'nnbabyl
217 (lambda () 217 (lambda ()
218 (save-excursion 218 (save-excursion
219 (set-buffer nnbabyl-mbox-buffer) 219 (set-buffer nnbabyl-mbox-buffer)
220 (save-buffer))) 220 (save-buffer)))
221 (file-name-directory nnbabyl-mbox-file) 221 (file-name-directory nnbabyl-mbox-file)
261 (nnbabyl-possibly-change-newsgroup newsgroup server) 261 (nnbabyl-possibly-change-newsgroup newsgroup server)
262 (let* ((is-old t) 262 (let* ((is-old t)
263 rest) 263 rest)
264 (nnmail-activate 'nnbabyl) 264 (nnmail-activate 'nnbabyl)
265 265
266 (save-excursion 266 (save-excursion
267 (set-buffer nnbabyl-mbox-buffer) 267 (set-buffer nnbabyl-mbox-buffer)
268 (gnus-set-text-properties (point-min) (point-max) nil) 268 (gnus-set-text-properties (point-min) (point-max) nil)
269 (while (and articles is-old) 269 (while (and articles is-old)
270 (goto-char (point-min)) 270 (goto-char (point-min))
271 (when (search-forward (nnbabyl-article-string (car articles)) nil t) 271 (when (search-forward (nnbabyl-article-string (car articles)) nil t)
272 (if (setq is-old 272 (if (setq is-old
273 (nnmail-expired-article-p 273 (nnmail-expired-article-p
274 newsgroup 274 newsgroup
275 (buffer-substring 275 (buffer-substring
276 (point) (progn (end-of-line) (point))) force)) 276 (point) (progn (end-of-line) (point))) force))
277 (progn 277 (progn
278 (nnheader-message 5 "Deleting article %d in %s..." 278 (nnheader-message 5 "Deleting article %d in %s..."
279 (car articles) newsgroup) 279 (car articles) newsgroup)
280 (nnbabyl-delete-mail)) 280 (nnbabyl-delete-mail))
281 (push (car articles) rest))) 281 (push (car articles) rest)))
282 (setq articles (cdr articles))) 282 (setq articles (cdr articles)))
283 (save-buffer) 283 (save-buffer)
290 (setcar active (1+ (car active))) 290 (setcar active (1+ (car active)))
291 (goto-char (point-min)))) 291 (goto-char (point-min))))
292 (nnmail-save-active nnbabyl-group-alist nnbabyl-active-file) 292 (nnmail-save-active nnbabyl-group-alist nnbabyl-active-file)
293 (nconc rest articles)))) 293 (nconc rest articles))))
294 294
295 (deffoo nnbabyl-request-move-article 295 (deffoo nnbabyl-request-move-article
296 (article group server accept-form &optional last) 296 (article group server accept-form &optional last)
297 (let ((buf (get-buffer-create " *nnbabyl move*")) 297 (let ((buf (get-buffer-create " *nnbabyl move*"))
298 result) 298 result)
299 (and 299 (and
300 (nnbabyl-request-article article group server) 300 (nnbabyl-request-article article group server)
301 (save-excursion 301 (save-excursion
302 (set-buffer buf) 302 (set-buffer buf)
303 (insert-buffer-substring nntp-server-buffer) 303 (insert-buffer-substring nntp-server-buffer)
304 (goto-char (point-min)) 304 (goto-char (point-min))
305 (while (re-search-forward 305 (while (re-search-forward
306 "^X-Gnus-Newsgroup:" 306 "^X-Gnus-Newsgroup:"
307 (save-excursion (search-forward "\n\n" nil t) (point)) t) 307 (save-excursion (search-forward "\n\n" nil t) (point)) t)
308 (delete-region (progn (beginning-of-line) (point)) 308 (delete-region (progn (beginning-of-line) (point))
309 (progn (forward-line 1) (point)))) 309 (progn (forward-line 1) (point))))
310 (setq result (eval accept-form)) 310 (setq result (eval accept-form))
311 (kill-buffer (current-buffer)) 311 (kill-buffer (current-buffer))
322 (deffoo nnbabyl-request-accept-article (group &optional server last) 322 (deffoo nnbabyl-request-accept-article (group &optional server last)
323 (nnbabyl-possibly-change-newsgroup group server) 323 (nnbabyl-possibly-change-newsgroup group server)
324 (nnmail-check-syntax) 324 (nnmail-check-syntax)
325 (let ((buf (current-buffer)) 325 (let ((buf (current-buffer))
326 result beg) 326 result beg)
327 (and 327 (and
328 (nnmail-activate 'nnbabyl) 328 (nnmail-activate 'nnbabyl)
329 (save-excursion 329 (save-excursion
330 (goto-char (point-min)) 330 (goto-char (point-min))
331 (search-forward "\n\n" nil t) 331 (search-forward "\n\n" nil t)
332 (forward-line -1) 332 (forward-line -1)
333 (save-excursion 333 (save-excursion
334 (while (re-search-backward "^X-Gnus-Newsgroup: " beg t) 334 (while (re-search-backward "^X-Gnus-Newsgroup: " beg t)
335 (delete-region (point) (progn (forward-line 1) (point))))) 335 (delete-region (point) (progn (forward-line 1) (point)))))
336 (nnmail-cache-insert (nnmail-fetch-field "message-id"))
336 (setq result (car (nnbabyl-save-mail 337 (setq result (car (nnbabyl-save-mail
337 (if (stringp group) 338 (if (stringp group)
338 (list (cons group (nnbabyl-active-number group))) 339 (list (cons group (nnbabyl-active-number group)))
339 (nnmail-article-group 'nnbabyl-active-number))))) 340 (nnmail-article-group 'nnbabyl-active-number)))))
340 (set-buffer nnbabyl-mbox-buffer) 341 (set-buffer nnbabyl-mbox-buffer)
341 (goto-char (point-max)) 342 (goto-char (point-max))
342 (search-backward "\n\^_") 343 (search-backward "\n\^_")
343 (goto-char (match-end 0)) 344 (goto-char (match-end 0))
344 (insert-buffer-substring buf) 345 (insert-buffer-substring buf)
345 (when last 346 (when last
347 (nnmail-cache-insert (nnmail-fetch-field "message-id"))
346 (save-buffer) 348 (save-buffer)
347 (nnmail-save-active nnbabyl-group-alist nnbabyl-active-file)) 349 (nnmail-save-active nnbabyl-group-alist nnbabyl-active-file))
348 result)))) 350 result))))
349 351
350 (deffoo nnbabyl-request-replace-article (article group buffer) 352 (deffoo nnbabyl-request-replace-article (article group buffer)
374 (setq found t) 376 (setq found t)
375 (nnbabyl-delete-mail)) 377 (nnbabyl-delete-mail))
376 (when found 378 (when found
377 (save-buffer))))) 379 (save-buffer)))))
378 ;; Remove the group from all structures. 380 ;; Remove the group from all structures.
379 (setq nnbabyl-group-alist 381 (setq nnbabyl-group-alist
380 (delq (assoc group nnbabyl-group-alist) nnbabyl-group-alist) 382 (delq (assoc group nnbabyl-group-alist) nnbabyl-group-alist)
381 nnbabyl-current-group nil) 383 nnbabyl-current-group nil)
382 ;; Save the active file. 384 ;; Save the active file.
383 (nnmail-save-active nnbabyl-group-alist nnbabyl-active-file) 385 (nnmail-save-active nnbabyl-group-alist nnbabyl-active-file)
384 t) 386 t)
436 ;; Only delete the article if no other groups owns it as well. 438 ;; Only delete the article if no other groups owns it as well.
437 (when (or force (not (re-search-forward "^X-Gnus-Newsgroup: " nil t))) 439 (when (or force (not (re-search-forward "^X-Gnus-Newsgroup: " nil t)))
438 (delete-region (point-min) (point-max)))))) 440 (delete-region (point-min) (point-max))))))
439 441
440 (defun nnbabyl-possibly-change-newsgroup (newsgroup &optional server) 442 (defun nnbabyl-possibly-change-newsgroup (newsgroup &optional server)
441 (when (and server 443 (when (and server
442 (not (nnbabyl-server-opened server))) 444 (not (nnbabyl-server-opened server)))
443 (nnbabyl-open-server server)) 445 (nnbabyl-open-server server))
444 (when (or (not nnbabyl-mbox-buffer) 446 (when (or (not nnbabyl-mbox-buffer)
445 (not (buffer-name nnbabyl-mbox-buffer))) 447 (not (buffer-name nnbabyl-mbox-buffer)))
446 (save-excursion (nnbabyl-read-mbox))) 448 (save-excursion (nnbabyl-read-mbox)))
452 (nnheader-report 'nnbabyl "No such group in file")) 454 (nnheader-report 'nnbabyl "No such group in file"))
453 t)) 455 t))
454 456
455 (defun nnbabyl-article-string (article) 457 (defun nnbabyl-article-string (article)
456 (if (numberp article) 458 (if (numberp article)
457 (concat "\nX-Gnus-Newsgroup: " nnbabyl-current-group ":" 459 (concat "\nX-Gnus-Newsgroup: " nnbabyl-current-group ":"
458 (int-to-string article) " ") 460 (int-to-string article) " ")
459 (concat "\nMessage-ID: " article))) 461 (concat "\nMessage-ID: " article)))
460 462
461 (defun nnbabyl-article-group-number () 463 (defun nnbabyl-article-group-number ()
462 (save-excursion 464 (save-excursion
476 ;; There may be an EOOH line here... 478 ;; There may be an EOOH line here...
477 (when (looking-at "\\*\\*\\* EOOH \\*\\*\\*") 479 (when (looking-at "\\*\\*\\* EOOH \\*\\*\\*")
478 (search-forward "\n\n" nil t)) 480 (search-forward "\n\n" nil t))
479 (setq chars (- (point-max) (point)) 481 (setq chars (- (point-max) (point))
480 lines (max (- (count-lines (point) (point-max)) 1) 0)) 482 lines (max (- (count-lines (point) (point-max)) 1) 0))
481 ;; Move back to the end of the headers. 483 ;; Move back to the end of the headers.
482 (goto-char (point-min)) 484 (goto-char (point-min))
483 (search-forward "\n\n" nil t) 485 (search-forward "\n\n" nil t)
484 (forward-char -1) 486 (forward-char -1)
485 (save-excursion 487 (save-excursion
486 (when (re-search-backward "^Lines: " nil t) 488 (when (re-search-backward "^Lines: " nil t)
511 (goto-char (point-max)) 513 (goto-char (point-max))
512 (insert "\^_\n"))) 514 (insert "\^_\n")))
513 (when (search-forward "\n\n" nil t) 515 (when (search-forward "\n\n" nil t)
514 (forward-char -1) 516 (forward-char -1)
515 (while group-art 517 (while group-art
516 (insert (format "X-Gnus-Newsgroup: %s:%d %s\n" 518 (insert (format "X-Gnus-Newsgroup: %s:%d %s\n"
517 (caar group-art) (cdar group-art) 519 (caar group-art) (cdar group-art)
518 (current-time-string))) 520 (current-time-string)))
519 (setq group-art (cdr group-art)))) 521 (setq group-art (cdr group-art))))
520 t)) 522 t))
521 523
554 ;; This buffer has changed since we read it last. Possibly. 556 ;; This buffer has changed since we read it last. Possibly.
555 (save-excursion 557 (save-excursion
556 (let ((delim (concat "^" nnbabyl-mail-delimiter)) 558 (let ((delim (concat "^" nnbabyl-mail-delimiter))
557 (alist nnbabyl-group-alist) 559 (alist nnbabyl-group-alist)
558 start end number) 560 start end number)
559 (set-buffer (setq nnbabyl-mbox-buffer 561 (set-buffer (setq nnbabyl-mbox-buffer
560 (nnheader-find-file-noselect 562 (nnheader-find-file-noselect
561 nnbabyl-mbox-file nil 'raw))) 563 nnbabyl-mbox-file nil 'raw)))
562 ;; Save previous buffer mode. 564 ;; Save previous buffer mode.
563 (setq nnbabyl-previous-buffer-mode 565 (setq nnbabyl-previous-buffer-mode
564 (cons (cons (point-min) (point-max)) 566 (cons (cons (point-min) (point-max))
565 major-mode)) 567 major-mode))
566 568
567 (buffer-disable-undo (current-buffer)) 569 (buffer-disable-undo (current-buffer))
568 (widen) 570 (widen)
576 (when (and (re-search-backward 578 (when (and (re-search-backward
577 (format "^X-Gnus-Newsgroup: %s:\\([0-9]+\\) " 579 (format "^X-Gnus-Newsgroup: %s:\\([0-9]+\\) "
578 (caar alist)) 580 (caar alist))
579 nil t) 581 nil t)
580 (> (setq number 582 (> (setq number
581 (string-to-number 583 (string-to-number
582 (buffer-substring 584 (buffer-substring
583 (match-beginning 1) (match-end 1)))) 585 (match-beginning 1) (match-end 1))))
584 (cdadar alist))) 586 (cdadar alist)))
585 (setcdr (cadar alist) number)) 587 (setcdr (cadar alist) number))
586 (setq alist (cdr alist))) 588 (setq alist (cdr alist)))
587 589
588 ;; We go through the mbox and make sure that each and 590 ;; We go through the mbox and make sure that each and
589 ;; every mail belongs to some group or other. 591 ;; every mail belongs to some group or other.
590 (goto-char (point-min)) 592 (goto-char (point-min))
591 (if (looking-at "\^L") 593 (if (looking-at "\^L")
592 (setq start (point)) 594 (setq start (point))
593 (re-search-forward delim nil t) 595 (re-search-forward delim nil t)
597 (unless (search-backward "\nX-Gnus-Newsgroup: " start t) 599 (unless (search-backward "\nX-Gnus-Newsgroup: " start t)
598 (goto-char end) 600 (goto-char end)
599 (save-excursion 601 (save-excursion
600 (save-restriction 602 (save-restriction
601 (narrow-to-region (goto-char start) end) 603 (narrow-to-region (goto-char start) end)
602 (nnbabyl-save-mail 604 (nnbabyl-save-mail
603 (nnmail-article-group 'nnbabyl-active-number)) 605 (nnmail-article-group 'nnbabyl-active-number))
604 (setq end (point-max))))) 606 (setq end (point-max)))))
605 (goto-char (setq start end))) 607 (goto-char (setq start end)))
606 (when (buffer-modified-p (current-buffer)) 608 (when (buffer-modified-p (current-buffer))
607 (save-buffer)) 609 (save-buffer))