Debian Codegraph @

mew-nntp.el

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 ;;; mew-nntp.el for reading
2
3 ;; Author: Kazu Yamamoto <[email protected]>
4 ;; Created: Feb 1, 1999
5
6 ;;; Code:
7
8 (require 'mew)
9
10 (defvar mew-nntp-msgid-file ".mew-msgid")
11 (defvar mew-nntp-folder-alist-file ".mew-folder-alist")
12 (defvar mew-nntp-folder-alist nil)
13 ;; without mew-folder-nntp
14 (defvar mew-nntp-folder-alist2-file ".mew-folder-alist2")
15 (defvar mew-nntp-folder-alist2 nil)
16
17 (defvar mew-nntp-skip-uidl t)
18
19 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
20 ;;;
21 ;;; NNTP info
22 ;;;
23
24 (defvar mew-nntp-info-list
25 '("server" "port" "process" "ssh-process" "ssl-process" "status"
26 "directive" "bnm" "mdb"
27 "rtrs" "refs" "range"
28 "rttl" "rcnt" "hlds"
29 "user" "account"
30 "size" "get-body" "no-msg" "case" "msgdb" "done" "dispatched" "error"
31 "max"
32 "newsgroup" "msgid" "truncated"
33 "virtual-info" "disp-info" "status-buf"))
34
35 (mew-info-defun "mew-nntp-" mew-nntp-info-list)
36
37 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
38 ;;;
39 ;;; FSM
40 ;;;
41
42 (defvar mew-nntp-fsm
43 '(("greeting" nil ("20[01]" . "mode-reader"))
44 ("mode-reader" nil (t . "authinfo"))
45 ("authinfo" nil ("381" . "authpass"))
46 ("authpass" nil ("281" . "group") (t . "wpwd"))
47 ("group" nil ("211" . "xover"))
48 ("xover" t ("224" . "pre-article"))
49 ("article" t ("22[01]" . "post-article") (t . "next-article"))
50 ("list" t ("215" . "post-list"))
51 ("pre-quit" nil (t . "quit2"))
52 ("quit" nil ("205" . "noop"))))
53
54 (defun mew-nntp-fsm-by-status (status)
55 (assoc status mew-nntp-fsm))
56
57 (defun mew-nntp-fsm-next (status code)
58 (cdr (mew-assoc-match2 code (nthcdr 2 (mew-nntp-fsm-by-status status)) 0)))
59
60 (defun mew-nntp-fsm-reply (status)
61 (nth 1 (mew-nntp-fsm-by-status status)))
62
63 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
64 ;;;
65 ;;; Filters
66 ;;;
67
68 (defun mew-nntp-secure-p (pnm)
69 (or (mew-nntp-get-ssh-process pnm) (mew-nntp-get-ssl-process pnm)))
70
71 (defun mew-nntp-command-mode-reader (pro pnm)
72 (mew-net-status (mew-nntp-get-status-buf pnm)
73 "Connecting"
74 nil
75 (mew-nntp-secure-p pnm))
76 (mew-nntp-process-send-string pro "MODE READER"))
77
78 (defun mew-nntp-command-authinfo (pro pnm)
79 (let ((user (mew-nntp-get-user pnm)))
80 (if user
81 (mew-nntp-process-send-string pro "AUTHINFO USER %s" user)
82 (mew-nntp-set-status pnm "group")
83 (mew-nntp-command-group pro pnm))))
84
85 (defun mew-nntp-command-authpass (pro pnm)
86 (let* ((prompt (format "NNTP password (%s): " (mew-nntp-get-account pnm)))
87 (pass (mew-nntp-input-passwd prompt pnm)))
88 (mew-nntp-process-send-string pro "AUTHINFO PASS %s" pass)))
89
90 (defun mew-nntp-command-wpwd (_pro pnm)
91 (mew-nntp-message pnm "NNTP password is wrong!")
92 (mew-passwd-set-passwd (mew-nntp-passtag pnm) nil)
93 (mew-nntp-set-status pnm "pre-quit"))
94
95 (defun mew-nntp-command-group (pro pnm)
96 (let ((directive (mew-nntp-get-directive pnm))
97 (newsgroup (mew-nntp-get-newsgroup pnm)))
98 (cond
99 ((eq directive 'list)
100 (mew-nntp-set-status pnm "list")
101 (mew-nntp-command-list pro pnm))
102 (t
103 (mew-nntp-process-send-string pro "GROUP %s" newsgroup)))))
104
105 (defun mew-nntp-command-xover (pro pnm)
106 (let ((directive (mew-nntp-get-directive pnm))
107 (refs (mew-nntp-get-refs pnm)) ;; (uid siz del (+fld msg))
108 (bnm (mew-nntp-get-bnm pnm))
109 (range (mew-nntp-get-range pnm))
110 max first last)
111 (if (and mew-nntp-skip-uidl (eq directive 'get))
112 (mew-nntp-command-dispatch pro pnm directive refs nil)
113 (mew-net-status (mew-nntp-get-status-buf pnm)
114 "Checking" nil (mew-nntp-secure-p pnm))
115 (cond
116 ((eq directive 'scan)
117 (if (eq range nil) ;; update
118 (setq max (mew-lisp-load
119 (mew-expand-file bnm mew-nntp-msgid-file))))))
120 ;; 221 total first last newsgroup (xxx)
121 (if (re-search-forward "^[0-9]+ +[0-9]+ +\\([0-9]+\\) +\\([0-9]+\\) +[-.a-zA-Z0-9]+" nil t)
122 (progn
123 (setq first (string-to-number (mew-match-string 1)))
124 (setq last (string-to-number (mew-match-string 2)))
125 (cond
126 ((stringp max)
127 (setq max (string-to-number max)))
128 (max ;; backward compatibility
129 ;; reversed
130 (setq max (car max))
131 (setq max (string-to-number max)))
132 ((and (eq directive 'scan) (integerp range))
133 (setq max (- last range))
134 (if (< max first) (setq max (1- first))))
135 (t
136 (setq max (1- first))))
137 (mew-nntp-set-max pnm max)
138 (mew-nntp-process-send-string pro "XOVER %d-" (1+ max)))
139 (mew-nntp-set-status pnm "quit")
140 (mew-nntp-command-quit pro pnm)))))
141
142 (defun mew-nntp-command-pre-article (pro pnm)
143 (let* ((directive (mew-nntp-get-directive pnm))
144 (max (mew-nntp-get-max pnm))
145 (refs (mew-nntp-get-refs pnm))
146 ;; (uid siz del (+fld msg))
147 (range (mew-nntp-get-range pnm))
148 uid siz rtr rtrs hlds)
149 (goto-char (point-min))
150 ;; num subj from date msg-id ref siz lines
151 (while (re-search-forward "^\\([0-9]+\\)\t[^\t\n]*\t[^\t\n]*\t[^\t\n]*\t<[^>\t\n]+>\t[^\t\n]*\t\\([0-9]*\\)" nil t)
152 (setq uid (mew-match-string 1))
153 (setq siz (mew-match-string 2))
154 (if (string= uid "") (setq uid nil))
155 (cond
156 ((eq directive 'get)
157 (setq rtr (assoc uid refs))
158 (if rtr (setq rtrs (cons rtr rtrs))))
159 ((eq directive 'scan)
160 (if (and uid (or range ;; all, last:n
161 (> (string-to-number uid) max))) ;; update
162 (setq rtrs (cons (mew-make-refileinfo :uid uid :size siz) rtrs))))
163 ((eq directive 'sync)
164 (if uid (setq hlds (cons uid hlds))))))
165 (mew-nntp-set-msgid pnm (mew-refileinfo-get-uid (car rtrs))) ;; 'scan
166 ;; last:n xxx
167 ;; (when (and (eq directive 'scan) (integerp range))
168 ;; (mew-ntake range rtrs))
169 (setq rtrs (nreverse rtrs))
170 (setq hlds (nreverse hlds))
171 (mew-nntp-command-dispatch pro pnm directive rtrs hlds)))
172
173 (defun mew-nntp-command-dispatch (pro pnm directive rtrs hlds)
174 (let ((rttl (length rtrs)))
175 (mew-nntp-set-rtrs pnm rtrs)
176 (mew-nntp-set-rttl pnm rttl)
177 (mew-nntp-set-hlds pnm hlds)
178 (mew-nntp-set-dispatched pnm t)
179 (cond
180 ((eq directive 'sync)
181 (mew-nntp-set-status pnm "quit")
182 (mew-nntp-command-quit pro pnm))
183 ((= rttl 0)
184 (mew-nntp-message pnm "No new messages")
185 (mew-nntp-set-status pnm "quit")
186 (mew-nntp-command-quit pro pnm))
187 ((= rttl 1)
188 (mew-nntp-message pnm "Retrieving 1 message in background...")
189 (mew-nntp-set-status pnm "article")
190 (mew-nntp-command-article pro pnm))
191 (t
192 (mew-nntp-message pnm "Retrieving %d messages in background..." rttl)
193 (mew-nntp-set-status pnm "article")
194 (mew-nntp-command-article pro pnm)))))
195
196 (defun mew-nntp-command-article (pro pnm)
197 (mew-net-status2 (mew-nntp-get-status-buf pnm)
198 (mew-nntp-get-rttl pnm)
199 (mew-nntp-get-rcnt pnm)
200 (mew-refileinfo-get-size (car (mew-nntp-get-rtrs pnm)))
201 'zero
202 (mew-nntp-secure-p pnm))
203 (let* ((directive (mew-nntp-get-directive pnm))
204 (rtrs (mew-nntp-get-rtrs pnm))
205 (rtr (car rtrs))
206 (uid (mew-refileinfo-get-uid rtr))
207 (siz (mew-refileinfo-get-size rtr))
208 (lim (mew-nntp-get-size pnm))
209 (get-body (mew-nntp-get-get-body pnm)))
210 (cond
211 ((or (null rtr) (eq directive 'biff))
212 (mew-nntp-set-truncated pnm nil)
213 (mew-nntp-set-status pnm "quit")
214 (mew-nntp-command-quit pro pnm))
215 ((eq directive 'get)
216 (mew-nntp-set-truncated pnm nil)
217 (mew-nntp-process-send-string pro "ARTICLE %s" uid))
218 ((and (eq directive 'scan) (not get-body))
219 (mew-nntp-set-truncated pnm t)
220 (mew-nntp-process-send-string pro "HEAD %s" uid))
221 ((or (= lim 0) (<= (string-to-number siz) lim))
222 (mew-nntp-set-truncated pnm nil)
223 (mew-nntp-process-send-string pro "ARTICLE %s" uid))
224 (t
225 (mew-nntp-set-truncated pnm t)
226 (mew-nntp-process-send-string pro "HEAD %s" uid)))))
227
228 (defun mew-nntp-command-post-article (pro pnm)
229 (let* ((directive (mew-nntp-get-directive pnm))
230 (width (1- (mew-scan-width)))
231 (rtrs (mew-nntp-get-rtrs pnm))
232 (rtr (car rtrs))
233 (uid (mew-refileinfo-get-uid rtr))
234 (siz (mew-refileinfo-get-size rtr))
235 (fld-msg (mew-refileinfo-get-folders rtr))
236 (truncated (mew-nntp-get-truncated pnm))
237 fld msg vec file msg-file lmsg)
238 (cond
239 ((null fld-msg)
240 (setq fld (mew-nntp-get-bnm pnm)))
241 ((stringp fld-msg)
242 (setq fld fld-msg))
243 ((listp fld-msg)
244 (mew-set '(fld msg) fld-msg)
245 (setq lmsg msg)))
246 (goto-char (point-min))
247 (forward-line)
248 (delete-region (point-min) (point))
249 ;; line delimiters
250 (mew-eol-fix-for-read)
251 (mew-dot-delete)
252 (cond
253 ((eq directive 'scan)
254 (setq msg uid)
255 (setq file (mew-expand-new-msg fld msg)))
256 (t
257 (setq msg-file (mew-net-get-new-message
258 pnm fld msg 'mew-nntp-get-msgdb 'mew-nntp-set-msgdb))
259 (setq msg (car msg-file) file (cdr msg-file))))
260 (goto-char (point-min))
261 (if truncated
262 (mew-header-insert-xmu uid siz t)
263 (mew-header-insert-xmu uid siz nil))
264 (catch 'write-error
265 (condition-case nil
266 (let ((write-region-inhibit-fsync mew-use-async-write))
267 (mew-frwlet mew-cs-dummy mew-cs-text-for-write
268 (write-region (point-min) (point-max) file nil 'no-msg)))
269 (error
270 (mew-nntp-set-status pnm "quit")
271 (mew-nntp-command-quit pro pnm)
272 (throw 'write-error nil)))
273 (when (file-exists-p file)
274 (mew-set-file-modes file)
275 (mew-set-file-type file)
276 (mew-set-buffer-multibyte t)
277 (setq vec (mew-scan-header))
278 (mew-scan-set-folder vec fld)
279 (mew-scan-set-message vec msg)
280 (mew-scan-body vec)
281 (mew-set-buffer-multibyte nil)
282 (mew-scan-insert-line fld vec width lmsg))
283 (mew-nntp-command-next-article pro pnm))))
284
285 (defun mew-nntp-command-next-article (pro pnm)
286 (let* ((rtrs (mew-nntp-get-rtrs pnm)))
287 (mew-nntp-set-rcnt pnm (1+ (mew-nntp-get-rcnt pnm)))
288 (mew-nntp-set-rtrs pnm (cdr rtrs))
289 (mew-nntp-set-status pnm "article")
290 (mew-nntp-command-article pro pnm)))
291
292 (defun mew-nntp-command-list (pro pnm)
293 (mew-net-status (mew-nntp-get-status-buf pnm)
294 "Listing"
295 nil
296 (mew-nntp-secure-p pnm))
297 (mew-nntp-message pnm "Collecting newsgroup list...")
298 (mew-nntp-process-send-string pro "LIST"))
299
300 (defun mew-nntp-command-post-list (pro pnm)
301 (let ((case (mew-nntp-get-case pnm))
302 group group2 groups groups2)
303 (goto-char (point-min))
304 (forward-line)
305 (delete-region (point-min) (point))
306 ;; line delimiters
307 (mew-eol-fix-for-read)
308 (mew-dot-delete)
309 (while (not (eobp))
310 (when (looking-at "\\([a-z][^ \t\n]+\\)")
311 (setq group2 (mew-match-string 1))
312 (setq group (concat mew-folder-nntp group2))
313 (setq groups (cons (mew-folder-func group) groups))
314 (setq groups2 (cons (mew-folder-func group2) groups2)))
315 (forward-line))
316 (if (null case) (setq case mew-case-default))
317 (setq groups (nreverse groups))
318 (mew-nntp-folder-save case groups groups2)
319 (mew-nntp-folder-alist-set case groups)
320 (mew-nntp-folder-alist2-set case groups2)
321 (mew-nntp-set-status pnm "quit")
322 (mew-nntp-command-quit pro pnm)))
323
324 (defun mew-nntp-command-quit (pro pnm)
325 (mew-nntp-set-done pnm t)
326 (mew-nntp-process-send-string pro "QUIT"))
327
328 (defun mew-nntp-command-quit2 (pro pnm)
329 (mew-nntp-set-done pnm t)
330 (mew-nntp-set-error pnm t)
331 (mew-nntp-set-status pnm "quit")
332 (mew-nntp-process-send-string pro "QUIT"))
333
334 (defun mew-nntp-command-noop (_pro _pnm)
335 ())
336
337 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
338 ;;;
339 ;;; Sub functions
340 ;;;
341
342 (defconst mew-nntp-info-prefix "mew-nntp-info-")
343
344 (defun mew-nntp-info-name (case newsgroup)
345 (let ((server (mew-nntp-server case))
346 (port (mew-*-to-string (mew-nntp-port case)))
347 (sshsrv (mew-nntp-ssh-server case))
348 (name mew-nntp-info-prefix))
349 (setq name (concat name server "/" newsgroup))
350 (unless (mew-port-equal port mew-nntp-port)
351 (setq name (concat name ":" port)))
352 (if sshsrv
353 (concat name "%" sshsrv)
354 name)))
355
356 (defun mew-nntp-buffer-name (pnm)
357 (concat mew-buffer-prefix pnm))
358
359 (defun mew-nntp-process-send-string (pro &rest args)
360 (let ((str (apply 'format args)))
361 (mew-nntp-debug "=SEND=" str)
362 (if (and (processp pro) (eq (process-status pro) 'open))
363 (process-send-string pro (concat str mew-cs-eol))
364 (message "NNTP time out"))))
365
366 (defun mew-nntp-passtag (pnm)
367 (let ((server (mew-nntp-get-server pnm))
368 (port (mew-nntp-get-port pnm))
369 (user (mew-nntp-get-user pnm)))
370 (concat user "@" server ":" port)))
371
372 (defun mew-nntp-message (pnm &rest args)
373 (or (mew-nntp-get-no-msg pnm) (apply 'message args)))
374
375 (defun mew-bnm-to-newsgroup (bnm)
376 (mew-folder-string (mew-case:folder-folder bnm)))
377
378 (defun mew-nntp-input-passwd (prompt pnm)
379 (let* ((tag (mew-nntp-passtag pnm))
380 (pro (mew-nntp-get-process pnm))
381 (pass (mew-input-passwd prompt tag)))
382 (unless (and (processp pro) (eq (process-status pro) 'open))
383 (mew-passwd-set-passwd tag nil))
384 pass))
385
386 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
387 ;;;
388 ;;; Opening NNTP
389 ;;;
390
391 (defun mew-nntp-open (pnm server port no-msg)
392 (let ((sprt (mew-*-to-port port))
393 pro tm)
394 (condition-case emsg
395 (progn
396 (setq tm (run-at-time mew-nntp-timeout-time nil 'mew-nntp-timeout))
397 (or no-msg (message "Connecting to the NNTP server..."))
398 (setq pro (open-network-stream pnm nil server sprt))
399 (mew-process-silent-exit pro)
400 (mew-set-process-cs pro mew-cs-text-for-net mew-cs-text-for-net)
401 (or no-msg (message "Connecting to the NNTP server...done")))
402 (quit
403 (or no-msg (message "Cannot connect to the NNTP server"))
404 (setq pro nil))
405 (error
406 (or no-msg (message "%s, %s" (nth 1 emsg) (nth 2 emsg)))
407 (setq pro nil)))
408 (if tm (cancel-timer tm))
409 pro))
410
411 (defun mew-nntp-timeout ()
412 (signal 'quit nil))
413
414 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
415 ;;;
416 ;;; Launcher
417 ;;;
418
419 (defun mew-nntp-retrieve (case directive bnm &rest args)
420 (let* ((server (mew-nntp-server case))
421 (user (mew-nntp-user case))
422 (port (mew-*-to-string (mew-nntp-port case)))
423 (sshsrv (mew-nntp-ssh-server case))
424 (sslp (mew-nntp-ssl case))
425 (sslport (mew-nntp-ssl-port case))
426 (newsgroup (mew-bnm-to-newsgroup bnm))
427 (pnm (mew-nntp-info-name case newsgroup))
428 (buf (get-buffer-create (mew-nntp-buffer-name pnm)))
429 (no-msg (eq directive 'biff))
430 process sshname sshpro sslname sslpro lport tls
431 virtual-info disp-info virtual)
432 (if (mew-nntp-get-process pnm)
433 (message "Another NNTP process is running. Try later")
434 (cond
435 (sshsrv
436 (setq sshpro (mew-open-ssh-stream case server port sshsrv))
437 (when sshpro
438 (setq sshname (process-name sshpro))
439 (setq lport (mew-ssh-pnm-to-lport sshname))
440 (when lport
441 (setq process (mew-nntp-open pnm "localhost" lport no-msg)))))
442 (sslp
443 (if (mew-port-equal port sslport) (setq tls mew-tls-nntp))
444 (setq sslpro (mew-open-ssl-stream case server sslport tls))
445 (when sslpro
446 (setq sslname (process-name sslpro))
447 (setq lport (mew-ssl-pnm-to-lport sslname))
448 (when lport
449 (setq process (mew-nntp-open pnm mew-ssl-localhost lport no-msg)))))
450 (t
451 (setq process (mew-nntp-open pnm server port no-msg))))
452 (when process
453 (mew-summary-lock process "NNTPing" (or sshpro sslpro))
454 (mew-sinfo-set-summary-form (mew-get-summary-form bnm))
455 (mew-sinfo-set-summary-column (mew-get-summary-column bnm))
456 (mew-sinfo-set-unread-mark nil)
457 (mew-sinfo-set-scan-id nil)
458 (mew-sinfo-set-scan-md5 nil)
459 (mew-info-clean-up pnm)
460 (mew-nntp-set-no-msg pnm no-msg) ;; must come here
461 (mew-nntp-message pnm "Communicating with the NNTP server...")
462 (mew-nntp-set-process pnm process)
463 (mew-nntp-set-ssh-process pnm sshpro)
464 (mew-nntp-set-ssl-process pnm sslpro)
465 (mew-nntp-set-server pnm server)
466 (mew-nntp-set-port pnm port)
467 (mew-nntp-set-user pnm user)
468 (mew-nntp-set-account pnm (format "%s@%s" user server))
469 (mew-nntp-set-status pnm "greeting")
470 (mew-nntp-set-directive pnm directive)
471 (mew-nntp-set-bnm pnm bnm)
472 (mew-nntp-set-status-buf pnm bnm)
473 (mew-nntp-set-rcnt pnm 1)
474 (mew-nntp-set-rttl pnm 0)
475 (mew-nntp-set-size pnm (mew-nntp-size case))
476 (mew-nntp-set-newsgroup pnm newsgroup)
477 (mew-nntp-set-case pnm case)
478 ;;
479 (cond
480 ((eq directive 'get)
481 (mew-sinfo-set-unread-mark (mew-get-unread-mark bnm))
482 (mew-nntp-set-refs pnm (nth 0 args))
483 (setq virtual-info (nth 1 args))
484 (mew-nntp-set-virtual-info pnm virtual-info)
485 (setq disp-info (nth 1 args))
486 (mew-nntp-set-disp-info pnm disp-info)
487 (setq virtual (mew-net-virtual-info-get-virtual virtual-info))
488 (when virtual
489 (mew-nntp-set-status-buf pnm virtual)
490 (with-current-buffer virtual
491 (mew-summary-lock process "NNTPing" (or sshpro sslpro)))))
492 ((eq directive 'scan)
493 (mew-nntp-set-range pnm (nth 0 args))
494 (mew-nntp-set-get-body pnm (nth 1 args))
495 (if (mew-nntp-get-range pnm)
496 (progn
497 (mew-nntp-set-mdb pnm (mew-summary-mark-collect4))
498 (mew-net-folder-clean))
499 (mew-sinfo-set-unread-mark (mew-get-unread-mark bnm))))
500 ((eq directive 'sync)
501 ))
502 (mew-sinfo-set-start-point (point)) ;; after erase-buffer
503 (set-process-sentinel process 'mew-nntp-sentinel)
504 (set-process-filter process 'mew-nntp-filter)
505 (set-process-buffer process buf)))))
506
507 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
508 ;;;
509 ;;; Filter and sentinel
510 ;;;
511
512 (defun mew-nntp-debug (label string)
513 (when (mew-debug 'net)
514 (with-current-buffer (get-buffer-create mew-buffer-debug)
515 (goto-char (point-max))
516 (insert (format "\n<%s>\n%s\n" label string)))))
517
518 (defun mew-nntp-filter (process string)
519 (let* ((pnm (process-name process))
520 (status (mew-nntp-get-status pnm))
521 (mulrep (mew-nntp-fsm-reply status))
522 stay next func code)
523 (mew-nntp-debug (upcase status) string)
524 (mew-filter
525 ;; Process's buffer
526 (goto-char (point-max))
527 (mew-set-buffer-multibyte nil)
528 (insert string)
529 (when (string= status "article")
530 (mew-net-status2 (mew-nntp-get-status-buf pnm)
531 (mew-nntp-get-rttl pnm)
532 (mew-nntp-get-rcnt pnm)
533 (mew-refileinfo-get-size (car (mew-nntp-get-rtrs pnm)))
534 nil
535 (mew-nntp-secure-p pnm)))
536 (cond
537 ((and (and (goto-char (1- (point-max))) (looking-at "\n$"))
538 (and (goto-char (point-min)) (looking-at "^\\([45][0-9][0-9]\\)")))
539 ;; this is an error code. this cannot be a multiple-line reply.
540 (setq code (mew-match-string 1))
541 (setq next (mew-nntp-fsm-next status code)))
542 ((and (or (and mulrep
543 (goto-char (point-max))
544 (= (forward-line -1) 0)
545 (looking-at "^\\.\r?$"))
546 (and (not mulrep)
547 (goto-char (1- (point-max)))
548 (looking-at "\n$")))
549 (and (goto-char (point-min)) (looking-at "^\\([0-9][0-9][0-9]\\)")))
550 (setq code (mew-match-string 1))
551 (setq next (mew-nntp-fsm-next status code)))
552 (t
553 (setq stay t)))
554 (unless stay
555 (unless next (setq next "quit"))
556 (mew-nntp-set-status pnm next)
557 (setq func (intern-soft (concat "mew-nntp-command-" next)))
558 (goto-char (point-min))
559 (if (fboundp func)
560 (funcall func process pnm)
561 (error "No function called %s" (symbol-name func)))
562 (if (and process (equal (process-buffer process) (current-buffer)))
563 (mew-erase-buffer))))))
564
565 (defun mew-nntp-sentinel (process event)
566 (let* ((pnm (process-name process))
567 (directive (mew-nntp-get-directive pnm))
568 (mdb (mew-nntp-get-mdb pnm))
569 (sshpro (mew-nntp-get-ssh-process pnm))
570 (sslpro (mew-nntp-get-ssl-process pnm))
571 (rttl (mew-nntp-get-rttl pnm))
572 (bnm (or (mew-nntp-get-bnm pnm) (current-buffer)))
573 (hlds (mew-nntp-get-hlds pnm))
574 (msgid (mew-nntp-get-msgid pnm))
575 (done (mew-nntp-get-done pnm))
576 (error (mew-nntp-get-error pnm))
577 (file (mew-expand-file bnm mew-nntp-msgid-file))
578 (buf (process-buffer process))
579 (virtual-info (mew-nntp-get-virtual-info pnm))
580 (disp-info (mew-nntp-get-disp-info pnm)))
581 (save-excursion
582 (mew-nntp-debug "NNTP SENTINEL" event)
583 (set-process-buffer process nil)
584 (set-buffer bnm)
585 (mew-summary-mark-recover mdb)
586 (mew-remove-buffer buf)
587 (if (not done)
588 (let* ((rtrs (mew-nntp-get-rtrs pnm))
589 (lefts (length rtrs))
590 (msgid (mew-refileinfo-get-uid (car rtrs)))
591 recovered)
592 (mew-nntp-message pnm "NNTP connection is lost")
593 (when (mew-nntp-get-dispatched pnm)
594 (cond
595 ((eq directive 'scan)
596 (setq msgid (number-to-string (1- (string-to-number msgid))))
597 (mew-lisp-save file msgid nil 'unlimit)
598 (setq recovered t)))
599 (when recovered
600 (mew-nntp-message
601 pnm
602 "%d message retrieved. %d messages are left due to an error"
603 (- rttl lefts) lefts)
604 (mew-summary-folder-cache-save))))
605 (if virtual-info (mew-summary-retrieve-message-for-virtual virtual-info))
606 (cond
607 (error
608 ;; retain the error message
609 )
610 ((eq directive 'list)
611 (mew-nntp-message pnm "Collecting newsgroup list...done"))
612 ((eq directive 'sync)
613 (mew-nntp-message pnm "Synchronizing messages...")
614 (mew-net-folder-sync bnm hlds)
615 (mew-nntp-message pnm "Synchronizing messages...done")
616 (mew-summary-folder-cache-save))
617 ((eq directive 'get)
618 (cond
619 ((= rttl 0)
620 (mew-nntp-message pnm "No new messages"))
621 ((= rttl 1)
622 (mew-nntp-message pnm "1 message retrieved")
623 (mew-summary-folder-cache-save))
624 (t
625 (mew-nntp-message pnm "%d messages retrieved" rttl)
626 (mew-summary-folder-cache-save))))
627 ((eq directive 'scan)
628 (cond
629 ((or (= rttl 0) (null msgid))
630 (mew-nntp-message pnm "No messages scanned"))
631 ((= rttl 1)
632 (mew-nntp-message pnm "1 message scanned")
633 (mew-lisp-save file msgid nil 'unlimit)
634 (mew-summary-folder-cache-save))
635 (t
636 (mew-nntp-message pnm "%d messages scanned" rttl)
637 (mew-lisp-save file msgid nil 'unlimit)
638 (mew-summary-folder-cache-save))))))
639 ;;
640 (and mew-use-async-write (mew-unix-sync))
641 (mew-net-status-clear (mew-nntp-get-status-buf pnm))
642 (mew-info-clean-up pnm)
643 (set-buffer-modified-p nil)
644 (mew-summary-unlock)
645 (if (and (processp sshpro) (not mew-ssh-keep-connection))
646 (process-send-string sshpro "exit\n"))
647 (if (and (processp sslpro) (not mew-ssl-keep-connection))
648 (delete-process sslpro))
649 (mew-net-disp-info-display disp-info)
650 (run-hooks 'mew-nntp-sentinel-hook))))
651
652 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
653 ;;;
654 ;;; Newsgroup alist
655 ;;;
656
657 (defun mew-nntp-folder-clean-up ()
658 (setq mew-nntp-folder-alist nil)
659 (setq mew-nntp-folder-alist2 nil))
660
661 (defun mew-nntp-folder-alist (&optional case)
662 (let ((ent (assoc (or case mew-case-default) mew-nntp-folder-alist))
663 alist)
664 (if (and ent (cdr ent))
665 (cdr ent)
666 (setq alist (mew-nntp-folder-load case))
667 (if alist
668 alist
669 (list (mew-folder-func (mew-nntp-newsgroup case)))))))
670
671 (defun mew-nntp-folder-alist2 (&optional case)
672 (let ((ent (assoc (or case mew-case-default) mew-nntp-folder-alist2)))
673 (if ent
674 (cdr ent)
675 (mew-nntp-folder-load case 'two))))
676
677 (defun mew-nntp-folder-load (case &optional two)
678 (let* ((fld (mew-nntp-folder case))
679 (file (mew-expand-file fld mew-nntp-folder-alist-file))
680 (groups (mew-lisp-load file))
681 (file2 (mew-expand-file fld mew-nntp-folder-alist2-file))
682 (groups2 (mew-lisp-load file2)))
683 (mew-nntp-folder-alist-set case groups)
684 (mew-nntp-folder-alist2-set case groups2)
685 (if two groups2 groups)))
686
687 (defun mew-nntp-folder-save (case groups groups2)
688 (let* ((fld (mew-nntp-folder case))
689 (dir (mew-expand-folder fld))
690 (file (expand-file-name mew-nntp-folder-alist-file dir))
691 (file2 (expand-file-name mew-nntp-folder-alist2-file dir)))
692 (mew-check-directory dir)
693 (mew-lisp-save file groups 'nobackup 'unlimit)
694 (mew-lisp-save file2 groups2 'nobackup 'unlimit)))
695
696 (defun mew-nntp-folder-alist-set (case groups)
697 (setq mew-nntp-folder-alist
698 (cons (cons (or case mew-case-default) groups)
699 (delete (assoc (or case mew-case-default) mew-nntp-folder-alist)
700 mew-nntp-folder-alist))))
701
702 (defun mew-nntp-folder-alist2-set (case groups)
703 (setq mew-nntp-folder-alist2
704 (cons (cons (or case mew-case-default) groups)
705 (delete (assoc (or case mew-case-default) mew-nntp-folder-alist2)
706 mew-nntp-folder-alist2))))
707
708 (defun mew-nntp-update (case)
709 (let ((bnm (mew-summary-folder-name 'ext)))
710 (mew-nntp-retrieve case 'list bnm)))
711
712 (provide 'mew-nntp)
713
714 ;;; Copyright Notice:
715
716 ;; Copyright (C) 1999-2015 Mew developing team.
717 ;; All rights reserved.
718
719 ;; Redistribution and use in source and binary forms, with or without
720 ;; modification, are permitted provided that the following conditions
721 ;; are met:
722 ;;
723 ;; 1. Redistributions of source code must retain the above copyright
724 ;; notice, this list of conditions and the following disclaimer.
725 ;; 2. Redistributions in binary form must reproduce the above copyright
726 ;; notice, this list of conditions and the following disclaimer in the
727 ;; documentation and/or other materials provided with the distribution.
728 ;; 3. Neither the name of the team nor the names of its contributors
729 ;; may be used to endorse or promote products derived from this software
730 ;; without specific prior written permission.
731 ;;
732 ;; THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS'' AND
733 ;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
734 ;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
735 ;; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TEAM OR CONTRIBUTORS BE
736 ;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
737 ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
738 ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
739 ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
740 ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
741 ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
742 ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
743
744 ;;; mew-nntp.el ends here