Debian Codegraph @

mew-nntp.el

raw ◀ ▶
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 case server port no-msg starttlsp)
392 (let ((sprt (mew-*-to-port port))
•393 (sslnp (mew-ssl-native-p (mew-nntp-ssl case)))
394 pro tm)
395 (condition-case emsg
396 (progn
397 (setq tm (run-at-time mew-nntp-timeout-time nil 'mew-nntp-timeout))
398 (or no-msg (message "Connecting to the NNTP server..."))
•399 (setq pro (mew-open-network-stream pnm nil server sprt
400 'nntp sslnp starttlsp case))
401 (setq pro (car pro))
402 (when (not (processp pro)) (signal 'quit nil))
403 (mew-process-silent-exit pro)
404 (mew-set-process-cs pro mew-cs-text-for-net mew-cs-text-for-net)
405 (or no-msg (message "Connecting to the NNTP server...done")))
406 (quit
407 (or no-msg (message "Cannot connect to the NNTP server"))
408 (setq pro nil))
409 (error
410 (or no-msg (message "%s, %s" (nth 1 emsg) (nth 2 emsg)))
411 (setq pro nil)))
412 (if tm (cancel-timer tm))
413 pro))
414
415 (defun mew-nntp-timeout ()
•416 ;; Do not timeout if the NSM query pane is active.
417 (unless (get-buffer "*Network Security Manager*")
418 (message "NNTP connection timed out (%d seconds)"
419 mew-nntp-timeout-time)
420 (signal 'quit nil)))
421
422 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
423 ;;;
424 ;;; Launcher
425 ;;;
426
427 (defun mew-nntp-retrieve (case directive bnm &rest args)
428 (let* ((server (mew-nntp-server case))
429 (user (mew-nntp-user case))
430 (port (mew-*-to-string (mew-nntp-port case)))
431 (sshsrv (mew-nntp-ssh-server case))
432 (sslp (mew-nntp-ssl case))
433 (sslport (mew-nntp-ssl-port case))
•434 (sslnp (mew-ssl-native-p (mew-nntp-ssl case)))
435 (starttlsp
436 (mew-ssl-starttls-p (mew-nntp-ssl case)
437 (mew-*-to-string (mew-nntp-port case))
438 (mew-nntp-ssl-port case)))
439 (newsgroup (mew-bnm-to-newsgroup bnm))
440 (pnm (mew-nntp-info-name case newsgroup))
441 (buf (get-buffer-create (mew-nntp-buffer-name pnm)))
442 (no-msg (eq directive 'biff))
443 process sshname sshpro sslname sslpro lport tls
444 virtual-info disp-info virtual)
445 (if (mew-nntp-get-process pnm)
446 (message "Another NNTP process is running. Try later")
447 (cond
•448 (sslnp
449 (let ((serv (if starttlsp port sslport)))
450 (setq process (mew-nntp-open pnm case server serv no-msg starttlsp))))
451 (sshsrv
452 (setq sshpro (mew-open-ssh-stream case server port sshsrv))
453 (when sshpro
454 (setq sshname (process-name sshpro))
455 (setq lport (mew-ssh-pnm-to-lport sshname))
456 (when lport
•457 (setq process (mew-nntp-open pnm case "localhost" lport no-msg nil)))))
458 (sslp
•459 (when starttlsp (setq tls mew-tls-nntp))
460 (setq sslpro (mew-open-ssl-stream case server sslport tls))
461 (when sslpro
462 (setq sslname (process-name sslpro))
463 (setq lport (mew-ssl-pnm-to-lport sslname))
464 (when lport
•465 (setq process (mew-nntp-open pnm case mew-ssl-localhost lport no-msg nil)))))
466 (t
•467 (setq process (mew-nntp-open pnm case server port no-msg nil))))
468 (when process
469 (mew-summary-lock process "NNTPing" (or sshpro sslpro))
470 (mew-sinfo-set-summary-form (mew-get-summary-form bnm))
471 (mew-sinfo-set-summary-column (mew-get-summary-column bnm))
472 (mew-sinfo-set-unread-mark nil)
473 (mew-sinfo-set-scan-id nil)
474 (mew-sinfo-set-scan-md5 nil)
475 (mew-info-clean-up pnm)
476 (mew-nntp-set-no-msg pnm no-msg) ;; must come here
477 (mew-nntp-message pnm "Communicating with the NNTP server...")
478 (mew-nntp-set-process pnm process)
479 (mew-nntp-set-ssh-process pnm sshpro)
480 (mew-nntp-set-ssl-process pnm sslpro)
481 (mew-nntp-set-server pnm server)
482 (mew-nntp-set-port pnm port)
483 (mew-nntp-set-user pnm user)
484 (mew-nntp-set-account pnm (format "%s@%s" user server))
485 (mew-nntp-set-status pnm "greeting")
486 (mew-nntp-set-directive pnm directive)
487 (mew-nntp-set-bnm pnm bnm)
488 (mew-nntp-set-status-buf pnm bnm)
489 (mew-nntp-set-rcnt pnm 1)
490 (mew-nntp-set-rttl pnm 0)
491 (mew-nntp-set-size pnm (mew-nntp-size case))
492 (mew-nntp-set-newsgroup pnm newsgroup)
493 (mew-nntp-set-case pnm case)
494 ;;
495 (cond
496 ((eq directive 'get)
497 (mew-sinfo-set-unread-mark (mew-get-unread-mark bnm))
498 (mew-nntp-set-refs pnm (nth 0 args))
499 (setq virtual-info (nth 1 args))
500 (mew-nntp-set-virtual-info pnm virtual-info)
501 (setq disp-info (nth 1 args))
502 (mew-nntp-set-disp-info pnm disp-info)
503 (setq virtual (mew-net-virtual-info-get-virtual virtual-info))
504 (when virtual
505 (mew-nntp-set-status-buf pnm virtual)
506 (with-current-buffer virtual
507 (mew-summary-lock process "NNTPing" (or sshpro sslpro)))))
508 ((eq directive 'scan)
509 (mew-nntp-set-range pnm (nth 0 args))
510 (mew-nntp-set-get-body pnm (nth 1 args))
511 (if (mew-nntp-get-range pnm)
512 (progn
513 (mew-nntp-set-mdb pnm (mew-summary-mark-collect4))
514 (mew-net-folder-clean))
515 (mew-sinfo-set-unread-mark (mew-get-unread-mark bnm))))
516 ((eq directive 'sync)
517 ))
518 (mew-sinfo-set-start-point (point)) ;; after erase-buffer
519 (set-process-sentinel process 'mew-nntp-sentinel)
520 (set-process-filter process 'mew-nntp-filter)
•521 (set-process-buffer process buf)
522 (when sslnp
523 ;; GnuTLS requires a client-initiated command after the
524 ;; session is established or upgraded to use TLS because
525 ;; no additional greeting from the server.
526 (mew-nntp-command-mode-reader process pnm))
527 ))))
528
529 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
530 ;;;
531 ;;; Filter and sentinel
532 ;;;
533
534 (defun mew-nntp-debug (label string)
535 (when (mew-debug 'net)
536 (with-current-buffer (get-buffer-create mew-buffer-debug)
537 (goto-char (point-max))
538 (insert (format "\n<%s>\n%s\n" label string)))))
539
540 (defun mew-nntp-filter (process string)
541 (let* ((pnm (process-name process))
542 (status (mew-nntp-get-status pnm))
543 (mulrep (mew-nntp-fsm-reply status))
544 stay next func code)
545 (mew-nntp-debug (upcase status) string)
546 (mew-filter
547 ;; Process's buffer
548 (goto-char (point-max))
549 (mew-set-buffer-multibyte nil)
550 (insert string)
551 (when (string= status "article")
552 (mew-net-status2 (mew-nntp-get-status-buf pnm)
553 (mew-nntp-get-rttl pnm)
554 (mew-nntp-get-rcnt pnm)
555 (mew-refileinfo-get-size (car (mew-nntp-get-rtrs pnm)))
556 nil
557 (mew-nntp-secure-p pnm)))
558 (cond
559 ((and (and (goto-char (1- (point-max))) (looking-at "\n$"))
560 (and (goto-char (point-min)) (looking-at "^\\([45][0-9][0-9]\\)")))
561 ;; this is an error code. this cannot be a multiple-line reply.
562 (setq code (mew-match-string 1))
563 (setq next (mew-nntp-fsm-next status code)))
564 ((and (or (and mulrep
565 (goto-char (point-max))
566 (= (forward-line -1) 0)
567 (looking-at "^\\.\r?$"))
568 (and (not mulrep)
569 (goto-char (1- (point-max)))
570 (looking-at "\n$")))
571 (and (goto-char (point-min)) (looking-at "^\\([0-9][0-9][0-9]\\)")))
572 (setq code (mew-match-string 1))
573 (setq next (mew-nntp-fsm-next status code)))
574 (t
575 (setq stay t)))
576 (unless stay
577 (unless next (setq next "quit"))
578 (mew-nntp-set-status pnm next)
579 (setq func (intern-soft (concat "mew-nntp-command-" next)))
580 (goto-char (point-min))
581 (if (fboundp func)
582 (funcall func process pnm)
583 (error "No function called %s" (symbol-name func)))
584 (if (and process (equal (process-buffer process) (current-buffer)))
585 (mew-erase-buffer))))))
586
587 (defun mew-nntp-sentinel (process event)
588 (let* ((pnm (process-name process))
589 (directive (mew-nntp-get-directive pnm))
590 (mdb (mew-nntp-get-mdb pnm))
591 (sshpro (mew-nntp-get-ssh-process pnm))
592 (sslpro (mew-nntp-get-ssl-process pnm))
593 (rttl (mew-nntp-get-rttl pnm))
594 (bnm (or (mew-nntp-get-bnm pnm) (current-buffer)))
595 (hlds (mew-nntp-get-hlds pnm))
596 (msgid (mew-nntp-get-msgid pnm))
597 (done (mew-nntp-get-done pnm))
598 (error (mew-nntp-get-error pnm))
599 (file (mew-expand-file bnm mew-nntp-msgid-file))
600 (buf (process-buffer process))
601 (virtual-info (mew-nntp-get-virtual-info pnm))
602 (disp-info (mew-nntp-get-disp-info pnm)))
603 (save-excursion
604 (mew-nntp-debug "NNTP SENTINEL" event)
605 (set-process-buffer process nil)
606 (set-buffer bnm)
607 (mew-summary-mark-recover mdb)
608 (mew-remove-buffer buf)
609 (if (not done)
610 (let* ((rtrs (mew-nntp-get-rtrs pnm))
611 (lefts (length rtrs))
612 (msgid (mew-refileinfo-get-uid (car rtrs)))
613 recovered)
614 (mew-nntp-message pnm "NNTP connection is lost")
615 (when (mew-nntp-get-dispatched pnm)
616 (cond
617 ((eq directive 'scan)
618 (setq msgid (number-to-string (1- (string-to-number msgid))))
619 (mew-lisp-save file msgid nil 'unlimit)
620 (setq recovered t)))
621 (when recovered
622 (mew-nntp-message
623 pnm
624 "%d message retrieved. %d messages are left due to an error"
625 (- rttl lefts) lefts)
626 (mew-summary-folder-cache-save))))
627 (if virtual-info (mew-summary-retrieve-message-for-virtual virtual-info))
628 (cond
629 (error
630 ;; retain the error message
631 )
632 ((eq directive 'list)
633 (mew-nntp-message pnm "Collecting newsgroup list...done"))
634 ((eq directive 'sync)
635 (mew-nntp-message pnm "Synchronizing messages...")
636 (mew-net-folder-sync bnm hlds)
637 (mew-nntp-message pnm "Synchronizing messages...done")
638 (mew-summary-folder-cache-save))
639 ((eq directive 'get)
640 (cond
641 ((= rttl 0)
642 (mew-nntp-message pnm "No new messages"))
643 ((= rttl 1)
644 (mew-nntp-message pnm "1 message retrieved")
645 (mew-summary-folder-cache-save))
646 (t
647 (mew-nntp-message pnm "%d messages retrieved" rttl)
648 (mew-summary-folder-cache-save))))
649 ((eq directive 'scan)
650 (cond
651 ((or (= rttl 0) (null msgid))
652 (mew-nntp-message pnm "No messages scanned"))
653 ((= rttl 1)
654 (mew-nntp-message pnm "1 message scanned")
655 (mew-lisp-save file msgid nil 'unlimit)
656 (mew-summary-folder-cache-save))
657 (t
658 (mew-nntp-message pnm "%d messages scanned" rttl)
659 (mew-lisp-save file msgid nil 'unlimit)
660 (mew-summary-folder-cache-save))))))
661 ;;
662 (and mew-use-async-write (mew-unix-sync))
663 (mew-net-status-clear (mew-nntp-get-status-buf pnm))
664 (mew-info-clean-up pnm)
665 (set-buffer-modified-p nil)
666 (mew-summary-unlock)
667 (if (and (processp sshpro) (not mew-ssh-keep-connection))
668 (process-send-string sshpro "exit\n"))
669 (if (and (processp sslpro) (not mew-ssl-keep-connection))
670 (delete-process sslpro))
671 (mew-net-disp-info-display disp-info)
672 (run-hooks 'mew-nntp-sentinel-hook))))
673
674 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
675 ;;;
676 ;;; Newsgroup alist
677 ;;;
678
679 (defun mew-nntp-folder-clean-up ()
680 (setq mew-nntp-folder-alist nil)
681 (setq mew-nntp-folder-alist2 nil))
682
683 (defun mew-nntp-folder-alist (&optional case)
684 (let ((ent (assoc (or case mew-case-default) mew-nntp-folder-alist))
685 alist)
686 (if (and ent (cdr ent))
687 (cdr ent)
688 (setq alist (mew-nntp-folder-load case))
689 (if alist
690 alist
691 (list (mew-folder-func (mew-nntp-newsgroup case)))))))
692
693 (defun mew-nntp-folder-alist2 (&optional case)
694 (let ((ent (assoc (or case mew-case-default) mew-nntp-folder-alist2)))
695 (if ent
696 (cdr ent)
697 (mew-nntp-folder-load case 'two))))
698
699 (defun mew-nntp-folder-load (case &optional two)
700 (let* ((fld (mew-nntp-folder case))
701 (file (mew-expand-file fld mew-nntp-folder-alist-file))
702 (groups (mew-lisp-load file))
703 (file2 (mew-expand-file fld mew-nntp-folder-alist2-file))
704 (groups2 (mew-lisp-load file2)))
705 (mew-nntp-folder-alist-set case groups)
706 (mew-nntp-folder-alist2-set case groups2)
707 (if two groups2 groups)))
708
709 (defun mew-nntp-folder-save (case groups groups2)
710 (let* ((fld (mew-nntp-folder case))
711 (dir (mew-expand-folder fld))
712 (file (expand-file-name mew-nntp-folder-alist-file dir))
713 (file2 (expand-file-name mew-nntp-folder-alist2-file dir)))
714 (mew-check-directory dir)
715 (mew-lisp-save file groups 'nobackup 'unlimit)
716 (mew-lisp-save file2 groups2 'nobackup 'unlimit)))
717
718 (defun mew-nntp-folder-alist-set (case groups)
719 (setq mew-nntp-folder-alist
720 (cons (cons (or case mew-case-default) groups)
721 (delete (assoc (or case mew-case-default) mew-nntp-folder-alist)
722 mew-nntp-folder-alist))))
723
724 (defun mew-nntp-folder-alist2-set (case groups)
725 (setq mew-nntp-folder-alist2
726 (cons (cons (or case mew-case-default) groups)
727 (delete (assoc (or case mew-case-default) mew-nntp-folder-alist2)
728 mew-nntp-folder-alist2))))
729
730 (defun mew-nntp-update (case)
731 (let ((bnm (mew-summary-folder-name 'ext)))
732 (mew-nntp-retrieve case 'list bnm)))
733
734 (provide 'mew-nntp)
735
736 ;;; Copyright Notice:
737
•738 ;; Copyright (C) 1999-2020 Mew developing team.
739 ;; All rights reserved.
740
741 ;; Redistribution and use in source and binary forms, with or without
742 ;; modification, are permitted provided that the following conditions
743 ;; are met:
744 ;;
745 ;; 1. Redistributions of source code must retain the above copyright
746 ;; notice, this list of conditions and the following disclaimer.
747 ;; 2. Redistributions in binary form must reproduce the above copyright
748 ;; notice, this list of conditions and the following disclaimer in the
749 ;; documentation and/or other materials provided with the distribution.
750 ;; 3. Neither the name of the team nor the names of its contributors
751 ;; may be used to endorse or promote products derived from this software
752 ;; without specific prior written permission.
753 ;;
754 ;; THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS'' AND
755 ;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
756 ;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
757 ;; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TEAM OR CONTRIBUTORS BE
758 ;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
759 ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
760 ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
761 ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
762 ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
763 ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
764 ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
765
766 ;;; mew-nntp.el ends here