annotate lisp/vm/vm-pop.el @ 194:2947057885e5

Added tag r20-3b23 for changeset f53b5ca2e663
author cvs
date Mon, 13 Aug 2007 09:58:32 +0200
parents 489f57a838ef
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
1 ;;; Simple POP (RFC 1939) client for VM
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
2 ;;; Copyright (C) 1993, 1994, 1997 Kyle E. Jones
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;;; This program is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;;; the Free Software Foundation; either version 1, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;;; This program is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;;; along with this program; if not, write to the Free Software
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 (provide 'vm-pop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; Nothing fancy here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; Our goal is to drag the mail from the POP maildrop to the crash box.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; just as if we were using movemail on a spool file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 (defun vm-pop-move-mail (source destination)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 (let ((process nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 (folder-type vm-folder-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 (saved-password t)
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
27 (m-per-session vm-pop-messages-per-session)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
28 (b-per-session vm-pop-bytes-per-session)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 (handler (and (fboundp 'find-file-name-handler)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 (find-file-name-handler source 'vm-pop-move-mail)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 (wrong-number-of-arguments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 (find-file-name-handler source)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (popdrop (vm-safe-popdrop-string source))
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
35 (statblob nil)
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
36 mailbox-count mailbox-size message-size response
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
37 n retrieved retrieved-bytes process-buffer)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (catch 'done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (if handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (throw 'done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (funcall handler 'vm-pop-move-mail source destination)))
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
43 (setq process (vm-pop-make-session source))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
44 (or process (throw 'done nil))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
45 (setq process-buffer (process-buffer process))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
46 (save-excursion
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
47 (set-buffer process-buffer)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
48 (setq vm-folder-type (or folder-type vm-default-folder-type))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
49 ;; find out how many messages are in the box.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
50 (vm-pop-send-command process "STAT")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
51 (setq response (vm-pop-read-stat-response process)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
52 mailbox-count (nth 0 response)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
53 mailbox-size (nth 1 response))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
54 ;; forget it if the command fails
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
55 ;; or if there are no messages present.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
56 (if (or (null mailbox-count)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
57 (< mailbox-count 1))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
58 (throw 'done nil))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
59 ;; loop through the maildrop retrieving and deleting
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
60 ;; messages as we go.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
61 (setq n 1 retrieved 0 retrieved-bytes 0)
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
62 (setq statblob (vm-pop-start-status-timer))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
63 (vm-set-pop-stat-x-box statblob popdrop)
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
64 (vm-set-pop-stat-x-maxmsg statblob mailbox-count)
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
65 (while (and (<= n mailbox-count)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
66 (or (not (natnump m-per-session))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
67 (< retrieved m-per-session))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
68 (or (not (natnump b-per-session))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
69 (< retrieved-bytes b-per-session)))
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
70 (vm-set-pop-stat-x-currmsg statblob n)
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
71 (vm-pop-send-command process (format "LIST %d" n))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
72 (setq message-size (vm-pop-read-list-response process))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
73 (vm-set-pop-stat-x-need statblob message-size)
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
74 (if (and (integerp vm-pop-max-message-size)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
75 (> message-size vm-pop-max-message-size)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
76 (progn
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
77 (setq response
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
78 (if vm-pop-ok-to-ask
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
79 (vm-pop-ask-about-large-message process
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
80 message-size
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
81 n)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
82 'skip))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
83 (not (eq response 'retrieve))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
84 (if (eq response 'delete)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
85 (progn
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
86 (message "Deleting message %d..." n)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
87 (vm-pop-send-command process (format "DELE %d" n))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
88 (and (null (vm-pop-read-response process))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
89 (throw 'done (not (equal retrieved 0)))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
90 (if vm-pop-ok-to-ask
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
91 (message "Skipping message %d..." n)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
92 (message "Skipping message %d in %s, too large (%d > %d)..."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
93 n popdrop message-size vm-pop-max-message-size)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
94 (message "Retrieving message %d (of %d) from %s..."
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
95 n mailbox-count popdrop)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
96 (vm-pop-send-command process (format "RETR %d" n))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
97 (and (null (vm-pop-read-response process))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
98 (throw 'done (not (equal retrieved 0))))
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
99 (and (null (vm-pop-retrieve-to-crashbox process destination
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
100 statblob))
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
101 (throw 'done (not (equal retrieved 0))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
102 (vm-increment retrieved)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
103 (and b-per-session
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
104 (setq retrieved-bytes (+ retrieved-bytes message-size)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
105 (vm-pop-send-command process (format "DELE %d" n))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
106 ;; DELE can't fail but Emacs or this code might
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
107 ;; blow a gasket and spew filth down the
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
108 ;; connection, so...
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
109 (and (null (vm-pop-read-response process))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
110 (throw 'done (not (equal retrieved 0)))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
111 (vm-increment n))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
112 (not (equal retrieved 0)) ))
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
113 (and statblob (vm-pop-stop-status-timer statblob))
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
114 (if process
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
115 (vm-pop-end-session process)))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
116
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
117 (defun vm-pop-check-mail (source)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
118 (let ((process nil)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
119 (handler (and (fboundp 'find-file-name-handler)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
120 (condition-case ()
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
121 (find-file-name-handler source 'vm-pop-check-mail)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
122 (wrong-number-of-arguments
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
123 (find-file-name-handler source)))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
124 response)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
125 (unwind-protect
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
126 (save-excursion
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
127 (catch 'done
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
128 (if handler
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
129 (throw 'done
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
130 (funcall handler 'vm-pop-check-mail source)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
131 (setq process (vm-pop-make-session source))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
132 (or process (throw 'done nil))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
133 (set-buffer (process-buffer process))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
134 (vm-pop-send-command process "STAT")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
135 (setq response (vm-pop-read-stat-response process))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
136 (if (null response)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
137 nil
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
138 (not (equal 0 (car response))))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
139 (and process (vm-pop-end-session process)))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
140
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
141 (defun vm-pop-make-session (source)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
142 (let ((process-to-shutdown nil)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
143 process
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
144 (saved-password t)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
145 (popdrop (vm-safe-popdrop-string source))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
146 greeting timestamp
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
147 host port auth user pass source-list process-buffer)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
148 (unwind-protect
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
149 (catch 'done
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 ;; parse the maildrop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (setq source-list (vm-parse source "\\([^:]+\\):?")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 host (nth 0 source-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 port (nth 1 source-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 auth (nth 2 source-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 user (nth 3 source-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 pass (nth 4 source-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 ;; carp if parts are missing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (if (null host)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (error "No host in POP maildrop specification, \"%s\""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 source))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (if (null port)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (error "No port in POP maildrop specification, \"%s\""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 source))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (if (string-match "^[0-9]+$" port)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (setq port (string-to-int port)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (if (null auth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 "No authentication method in POP maildrop specification, \"%s\""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 source))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (if (null user)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (error "No user in POP maildrop specification, \"%s\""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 source))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (if (null pass)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (error "No password in POP maildrop specification, \"%s\""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 source))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (if (equal pass "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (setq pass (car (cdr (assoc source vm-pop-passwords))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (if (null pass)
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
180 (if (null vm-pop-ok-to-ask)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
181 (progn (message "Need password for %s" popdrop)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
182 (throw 'done nil))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
183 (setq pass
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
184 (vm-read-password
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
185 (format "POP password for %s: "
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
186 popdrop))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
187 vm-pop-passwords (cons (list source pass)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
188 vm-pop-passwords)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
189 saved-password t)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 ;; get the trace buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (setq process-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (get-buffer-create (format "trace of POP session to %s" host)))
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
193 ;; Tell XEmacs/MULE not to mess with the text.
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
194 (and vm-xemacs-mule-p
140
585fb297b004 Import from CVS: tag r20-2b4
cvs
parents: 136
diff changeset
195 (set-buffer-file-coding-system 'binary t))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 ;; clear the trace buffer of old output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (set-buffer process-buffer)
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 140
diff changeset
199 (buffer-disable-undo)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (erase-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 ;; open the connection to the server
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (setq process (open-network-stream "POP" process-buffer host port))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (and (null process) (throw 'done nil))
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
204 (process-kill-without-query process)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (set-buffer process-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (make-local-variable 'vm-pop-read-point)
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
208 (setq vm-pop-read-point (point-min))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
209 (if (null (setq greeting (vm-pop-read-response process t)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
210 (progn (delete-process process)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
211 (throw 'done nil)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
212 (setq process-to-shutdown process)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 ;; authentication
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (cond ((equal auth "pass")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (vm-pop-send-command process (format "USER %s" user))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (and (null (vm-pop-read-response process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (throw 'done nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (vm-pop-send-command process (format "PASS %s" pass))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (if (null (vm-pop-read-response process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (if saved-password
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (setq vm-pop-passwords
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (delete (list source pass)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 vm-pop-passwords)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (throw 'done nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 ((equal auth "rpop")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (vm-pop-send-command process (format "USER %s" user))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (and (null (vm-pop-read-response process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (throw 'done nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (vm-pop-send-command process (format "RPOP %s" pass))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (and (null (vm-pop-read-response process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (throw 'done nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 ((equal auth "apop")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (setq timestamp (vm-parse greeting "[^<]+\\(<[^>]+>\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 timestamp (car timestamp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (if (null timestamp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (goto-char (point-max))
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
239 (insert-before-markers "<<< ooops, no timestamp found in greeting! >>>\n")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (throw 'done nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (vm-pop-send-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (format "APOP %s %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 user
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (vm-pop-md5 (concat timestamp pass))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (and (null (vm-pop-read-response process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (throw 'done nil)))
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
248 (t (error "Don't know how to authenticate using %s" auth)))
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
249 (setq process-to-shutdown nil)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
250 process ))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
251 (if process-to-shutdown
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
252 (vm-pop-end-session process-to-shutdown)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
254 (defun vm-pop-end-session (process)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (set-buffer (process-buffer process))
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
257 (vm-pop-send-command process "QUIT")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
258 (vm-pop-read-response process)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
259 (if (fboundp 'add-async-timeout)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
260 (add-async-timeout 2 'delete-process process)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
261 (run-at-time 2 nil 'delete-process process))))
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
262
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
263 (defun vm-pop-stat-timer (o) (aref o 0))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
264 (defun vm-pop-stat-x-box (o) (aref o 1))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
265 (defun vm-pop-stat-x-currmsg (o) (aref o 2))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
266 (defun vm-pop-stat-x-maxmsg (o) (aref o 3))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
267 (defun vm-pop-stat-x-got (o) (aref o 4))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
268 (defun vm-pop-stat-x-need (o) (aref o 5))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
269 (defun vm-pop-stat-y-box (o) (aref o 6))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
270 (defun vm-pop-stat-y-currmsg (o) (aref o 7))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
271 (defun vm-pop-stat-y-maxmsg (o) (aref o 8))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
272 (defun vm-pop-stat-y-got (o) (aref o 9))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
273 (defun vm-pop-stat-y-need (o) (aref o 10))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
274
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
275 (defun vm-set-pop-stat-timer (o val) (aset o 0 val))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
276 (defun vm-set-pop-stat-x-box (o val) (aset o 1 val))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
277 (defun vm-set-pop-stat-x-currmsg (o val) (aset o 2 val))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
278 (defun vm-set-pop-stat-x-maxmsg (o val) (aset o 3 val))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
279 (defun vm-set-pop-stat-x-got (o val) (aset o 4 val))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
280 (defun vm-set-pop-stat-x-need (o val) (aset o 5 val))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
281 (defun vm-set-pop-stat-y-box (o val) (aset o 6 val))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
282 (defun vm-set-pop-stat-y-currmsg (o val) (aset o 7 val))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
283 (defun vm-set-pop-stat-y-maxmsg (o val) (aset o 8 val))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
284 (defun vm-set-pop-stat-y-got (o val) (aset o 9 val))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
285 (defun vm-set-pop-stat-y-need (o val) (aset o 10 val))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
286
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
287 (defun vm-pop-start-status-timer ()
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
288 (let ((blob (make-vector 11 nil))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
289 timer)
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
290 (setq timer (add-timeout 5 'vm-pop-report-retrieval-status blob 5))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
291 (vm-set-pop-stat-timer blob timer)
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
292 blob ))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
293
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
294 (defun vm-pop-stop-status-timer (status-blob)
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
295 (if (fboundp 'disable-timeout)
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
296 (disable-timeout (vm-pop-stat-timer status-blob))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
297 (cancel-timer (vm-pop-stat-timer status-blob))))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
298
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
299 (defun vm-pop-report-retrieval-status (o)
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
300 (cond ((null (vm-pop-stat-x-got o)) t)
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
301 ;; should not be possible, but better safe...
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
302 ((not (eq (vm-pop-stat-x-box o) (vm-pop-stat-y-box o))) t)
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
303 ((not (eq (vm-pop-stat-x-currmsg o) (vm-pop-stat-y-currmsg o))) t)
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
304 (t (message "Retrieving message %d (of %d) from %s, %s..."
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
305 (vm-pop-stat-x-currmsg o)
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
306 (vm-pop-stat-x-maxmsg o)
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
307 (vm-pop-stat-x-box o)
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
308 (format "%d%s of %d%s"
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
309 (vm-pop-stat-x-got o)
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
310 (if (> (vm-pop-stat-x-got o)
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
311 (vm-pop-stat-x-need o))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
312 "!"
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
313 "")
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
314 (vm-pop-stat-x-need o)
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
315 (if (eq (vm-pop-stat-x-got o)
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
316 (vm-pop-stat-y-got o))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
317 " (stalled)"
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
318 "")))))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
319 (vm-set-pop-stat-y-box o (vm-pop-stat-x-box o))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
320 (vm-set-pop-stat-y-currmsg o (vm-pop-stat-x-currmsg o))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
321 (vm-set-pop-stat-y-maxmsg o (vm-pop-stat-x-maxmsg o))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
322 (vm-set-pop-stat-y-got o (vm-pop-stat-x-got o))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
323 (vm-set-pop-stat-y-need o (vm-pop-stat-x-need o)))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
324
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (defun vm-pop-send-command (process command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (if (= (aref command 0) ?P)
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
328 (insert-before-markers "PASS <omitted>\r\n")
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
329 (insert-before-markers command "\r\n"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (setq vm-pop-read-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (process-send-string process command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (process-send-string process "\r\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (defun vm-pop-read-response (process &optional return-response-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (let ((case-fold-search nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 match-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (goto-char vm-pop-read-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (while (not (search-forward "\r\n" nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (accept-process-output process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (goto-char vm-pop-read-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (setq match-end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (goto-char vm-pop-read-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (if (not (looking-at "+OK"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (progn (setq vm-pop-read-point match-end) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (setq vm-pop-read-point match-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (if return-response-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (buffer-substring (point) match-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 t ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
350 (defun vm-pop-read-past-dot-sentinel-line (process)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
351 (let ((case-fold-search nil))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
352 (goto-char vm-pop-read-point)
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
353 (while (not (re-search-forward "^\\.\r\n" nil 0))
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
354 (beginning-of-line)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
355 ;; save-excursion doesn't work right
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
356 (let ((opoint (point)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
357 (accept-process-output process)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
358 (goto-char opoint)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
359 (setq vm-pop-read-point (point))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
360
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (defun vm-pop-read-stat-response (process)
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
362 (let ((response (vm-pop-read-response process t))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
363 list)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
364 (setq list (vm-parse response "\\([^ ]+\\) *"))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
365 (list (string-to-int (nth 1 list)) (string-to-int (nth 2 list)))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
366
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
367 (defun vm-pop-read-list-response (process)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (let ((response (vm-pop-read-response process t)))
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
369 (string-to-int (nth 2 (vm-parse response "\\([^ ]+\\) *")))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
370
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
371 (defun vm-pop-ask-about-large-message (process size n)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
372 (let ((work-buffer nil)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
373 (pop-buffer (current-buffer))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
374 start end)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
375 (unwind-protect
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
376 (save-excursion
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
377 (save-window-excursion
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
378 (vm-pop-send-command process (format "TOP %d %d" n 0))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
379 (if (vm-pop-read-response process)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
380 (progn
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
381 (setq start vm-pop-read-point)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
382 (vm-pop-read-past-dot-sentinel-line process)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
383 (setq end vm-pop-read-point)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
384 (setq work-buffer (generate-new-buffer "*pop-glop*"))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
385 (set-buffer work-buffer)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
386 (insert-buffer-substring pop-buffer start end)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
387 (forward-line -1)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
388 (delete-region (point) (point-max))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
389 (vm-pop-cleanup-region (point-min) (point-max))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
390 (vm-display-buffer work-buffer)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
391 (setq minibuffer-scroll-window (selected-window))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
392 (goto-char (point-min))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
393 (if (re-search-forward "^Received:" nil t)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
394 (progn
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
395 (goto-char (match-beginning 0))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
396 (vm-reorder-message-headers
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
397 nil vm-visible-headers
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
398 vm-invisible-header-regexp)))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
399 (set-window-point (selected-window) (point))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
400 (if (y-or-n-p (format "Message %d, size = %d, retrieve? " n size))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
401 'retrieve
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
402 (if (y-or-n-p (format "Delete message %d from popdrop? " n size))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
403 'delete
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
404 'skip))))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
405 (and work-buffer (kill-buffer work-buffer)))))
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 20
diff changeset
406
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
407 (defun vm-pop-retrieve-to-crashbox (process crash statblob)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (let ((start vm-pop-read-point) end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (goto-char start)
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
410 (vm-set-pop-stat-x-got statblob 0)
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
411 (while (not (re-search-forward "^\\.\r\n" nil 0))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
412 (beginning-of-line)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
413 ;; save-excursion doesn't work right
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
414 (let* ((opoint (point))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
415 (func
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
416 (function
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
417 (lambda (beg end len)
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
418 (if vm-pop-read-point
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
419 (progn
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
420 (vm-set-pop-stat-x-got statblob (- end start))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
421 (if (zerop (% (random) 10))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
422 (vm-pop-report-retrieval-status statblob)))))))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
423 (after-change-functions (cons func after-change-functions)))
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
424 (accept-process-output process)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
425 (goto-char opoint)))
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
426 (vm-set-pop-stat-x-got statblob nil)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (setq vm-pop-read-point (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (setq end (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (vm-pop-cleanup-region start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 ;; Some POP servers strip leading and trailing message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 ;; separators, some don't. Figure out what kind we're
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 ;; talking to and do the right thing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (if (eq (vm-get-folder-type nil start end) 'unknown)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (vm-munge-message-separators vm-folder-type start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 ;; avoid the consing and stat() call for all but babyl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 ;; files, since this will probably slow things down.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 ;; only babyl files have the folder header, and we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 ;; should only insert it if the crash box is empty.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (if (and (eq vm-folder-type 'babyl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (let ((attrs (file-attributes crash)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (or (null attrs) (equal 0 (nth 7 attrs)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (let ((opoint (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (vm-convert-folder-header nil vm-folder-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 ;; if start is a marker, then it was moved
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 ;; forward by the insertion. restore it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (setq start opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (vm-skip-past-folder-header)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (insert (vm-leading-message-separator))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 ;; this will not find the trailing message separator but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 ;; for the Content-Length stuff counting from eob is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 ;; the same thing in this case.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (vm-convert-folder-type-headers nil vm-folder-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (insert-before-markers (vm-trailing-message-separator))))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
459 ;; Set file type to binary for DOS/Windows. I don't know if
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
460 ;; this is correct to do or not; it depends on whether the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
461 ;; the CRLF or the LF newline convention is used on the inbox
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
462 ;; associated with this crashbox. This setting assumes the LF
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
463 ;; newline convention is used.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
464 (let ((buffer-file-type t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
465 (write-region start end crash t 0))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (delete-region start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 t ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (defun vm-pop-cleanup-region (start end)
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
470 (if (> (- end start) 30000)
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
471 (message "CRLF conversion and char unstuffing..."))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (setq end (vm-marker end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 ;; CRLF -> LF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (while (and (< (point) end) (search-forward "\r\n" end t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (replace-match "\n" t t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 ;; chop leading dots
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (while (and (< (point) end) (re-search-forward "^\\." end t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (replace-match "" t t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (forward-char)))
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
483 (if (> (- end start) 30000)
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 102
diff changeset
484 (message "CRLF conversion and dot unstuffing... done"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (set-marker end nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (defun vm-pop-md5 (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (let ((buffer nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (setq buffer (generate-new-buffer "*vm-work*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (insert string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (call-process-region (point-min) (point-max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 "/bin/sh" t buffer nil
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
496 shell-command-switch vm-pop-md5-program)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 ;; MD5 digest is 32 chars long
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 ;; mddriver adds a newline to make neaten output for tty
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 ;; viewing, make sure we leave it behind.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (vm-buffer-substring-no-properties (point-min) (+ (point-min) 32)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (and buffer (kill-buffer buffer)))))