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