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.
|
120
|
194 (and vm-xemacs-mule-p
|
140
|
195 (set-buffer-file-coding-system 'binary t))
|
0
|
196 ;; clear the trace buffer of old output
|
|
197 (save-excursion
|
|
198 (set-buffer process-buffer)
|
189
|
199 (buffer-disable-undo)
|
0
|
200 (erase-buffer))
|
|
201 ;; open the connection to the server
|
|
202 (setq process (open-network-stream "POP" process-buffer host port))
|
|
203 (and (null process) (throw 'done nil))
|
100
|
204 (process-kill-without-query process)
|
0
|
205 (save-excursion
|
|
206 (set-buffer process-buffer)
|
|
207 (make-local-variable 'vm-pop-read-point)
|
100
|
208 (setq vm-pop-read-point (point-min))
|
|
209 (if (null (setq greeting (vm-pop-read-response process t)))
|
|
210 (progn (delete-process process)
|
|
211 (throw 'done nil)))
|
|
212 (setq process-to-shutdown process)
|
0
|
213 ;; authentication
|
|
214 (cond ((equal auth "pass")
|
|
215 (vm-pop-send-command process (format "USER %s" user))
|
|
216 (and (null (vm-pop-read-response process))
|
|
217 (throw 'done nil))
|
|
218 (vm-pop-send-command process (format "PASS %s" pass))
|
|
219 (if (null (vm-pop-read-response process))
|
|
220 (progn
|
|
221 (if saved-password
|
|
222 (setq vm-pop-passwords
|
|
223 (delete (list source pass)
|
|
224 vm-pop-passwords)))
|
|
225 (throw 'done nil))))
|
|
226 ((equal auth "rpop")
|
|
227 (vm-pop-send-command process (format "USER %s" user))
|
|
228 (and (null (vm-pop-read-response process))
|
|
229 (throw 'done nil))
|
|
230 (vm-pop-send-command process (format "RPOP %s" pass))
|
|
231 (and (null (vm-pop-read-response process))
|
|
232 (throw 'done nil)))
|
|
233 ((equal auth "apop")
|
|
234 (setq timestamp (vm-parse greeting "[^<]+\\(<[^>]+>\\)")
|
|
235 timestamp (car timestamp))
|
|
236 (if (null timestamp)
|
|
237 (progn
|
|
238 (goto-char (point-max))
|
100
|
239 (insert-before-markers "<<< ooops, no timestamp found in greeting! >>>\n")
|
0
|
240 (throw 'done nil)))
|
|
241 (vm-pop-send-command
|
|
242 process
|
|
243 (format "APOP %s %s"
|
|
244 user
|
|
245 (vm-pop-md5 (concat timestamp pass))))
|
|
246 (and (null (vm-pop-read-response process))
|
|
247 (throw 'done nil)))
|
108
|
248 (t (error "Don't know how to authenticate using %s" auth)))
|
100
|
249 (setq process-to-shutdown nil)
|
|
250 process ))
|
|
251 (if process-to-shutdown
|
|
252 (vm-pop-end-session process-to-shutdown)))))
|
0
|
253
|
100
|
254 (defun vm-pop-end-session (process)
|
0
|
255 (save-excursion
|
|
256 (set-buffer (process-buffer process))
|
100
|
257 (vm-pop-send-command process "QUIT")
|
|
258 (vm-pop-read-response process)
|
|
259 (if (fboundp 'add-async-timeout)
|
|
260 (add-async-timeout 2 'delete-process process)
|
|
261 (run-at-time 2 nil 'delete-process process))))
|
30
|
262
|
108
|
263 (defun vm-pop-stat-timer (o) (aref o 0))
|
|
264 (defun vm-pop-stat-x-box (o) (aref o 1))
|
|
265 (defun vm-pop-stat-x-currmsg (o) (aref o 2))
|
|
266 (defun vm-pop-stat-x-maxmsg (o) (aref o 3))
|
|
267 (defun vm-pop-stat-x-got (o) (aref o 4))
|
|
268 (defun vm-pop-stat-x-need (o) (aref o 5))
|
|
269 (defun vm-pop-stat-y-box (o) (aref o 6))
|
|
270 (defun vm-pop-stat-y-currmsg (o) (aref o 7))
|
|
271 (defun vm-pop-stat-y-maxmsg (o) (aref o 8))
|
|
272 (defun vm-pop-stat-y-got (o) (aref o 9))
|
|
273 (defun vm-pop-stat-y-need (o) (aref o 10))
|
|
274
|
|
275 (defun vm-set-pop-stat-timer (o val) (aset o 0 val))
|
|
276 (defun vm-set-pop-stat-x-box (o val) (aset o 1 val))
|
|
277 (defun vm-set-pop-stat-x-currmsg (o val) (aset o 2 val))
|
|
278 (defun vm-set-pop-stat-x-maxmsg (o val) (aset o 3 val))
|
|
279 (defun vm-set-pop-stat-x-got (o val) (aset o 4 val))
|
|
280 (defun vm-set-pop-stat-x-need (o val) (aset o 5 val))
|
|
281 (defun vm-set-pop-stat-y-box (o val) (aset o 6 val))
|
|
282 (defun vm-set-pop-stat-y-currmsg (o val) (aset o 7 val))
|
|
283 (defun vm-set-pop-stat-y-maxmsg (o val) (aset o 8 val))
|
|
284 (defun vm-set-pop-stat-y-got (o val) (aset o 9 val))
|
|
285 (defun vm-set-pop-stat-y-need (o val) (aset o 10 val))
|
|
286
|
|
287 (defun vm-pop-start-status-timer ()
|
|
288 (let ((blob (make-vector 11 nil))
|
|
289 timer)
|
|
290 (setq timer (add-timeout 5 'vm-pop-report-retrieval-status blob 5))
|
|
291 (vm-set-pop-stat-timer blob timer)
|
|
292 blob ))
|
|
293
|
|
294 (defun vm-pop-stop-status-timer (status-blob)
|
|
295 (if (fboundp 'disable-timeout)
|
|
296 (disable-timeout (vm-pop-stat-timer status-blob))
|
|
297 (cancel-timer (vm-pop-stat-timer status-blob))))
|
|
298
|
|
299 (defun vm-pop-report-retrieval-status (o)
|
|
300 (cond ((null (vm-pop-stat-x-got o)) t)
|
|
301 ;; should not be possible, but better safe...
|
|
302 ((not (eq (vm-pop-stat-x-box o) (vm-pop-stat-y-box o))) t)
|
|
303 ((not (eq (vm-pop-stat-x-currmsg o) (vm-pop-stat-y-currmsg o))) t)
|
|
304 (t (message "Retrieving message %d (of %d) from %s, %s..."
|
|
305 (vm-pop-stat-x-currmsg o)
|
|
306 (vm-pop-stat-x-maxmsg o)
|
|
307 (vm-pop-stat-x-box o)
|
|
308 (format "%d%s of %d%s"
|
|
309 (vm-pop-stat-x-got o)
|
|
310 (if (> (vm-pop-stat-x-got o)
|
|
311 (vm-pop-stat-x-need o))
|
|
312 "!"
|
|
313 "")
|
|
314 (vm-pop-stat-x-need o)
|
|
315 (if (eq (vm-pop-stat-x-got o)
|
|
316 (vm-pop-stat-y-got o))
|
|
317 " (stalled)"
|
|
318 "")))))
|
|
319 (vm-set-pop-stat-y-box o (vm-pop-stat-x-box o))
|
|
320 (vm-set-pop-stat-y-currmsg o (vm-pop-stat-x-currmsg o))
|
|
321 (vm-set-pop-stat-y-maxmsg o (vm-pop-stat-x-maxmsg o))
|
|
322 (vm-set-pop-stat-y-got o (vm-pop-stat-x-got o))
|
|
323 (vm-set-pop-stat-y-need o (vm-pop-stat-x-need o)))
|
|
324
|
0
|
325 (defun vm-pop-send-command (process command)
|
|
326 (goto-char (point-max))
|
|
327 (if (= (aref command 0) ?P)
|
100
|
328 (insert-before-markers "PASS <omitted>\r\n")
|
|
329 (insert-before-markers command "\r\n"))
|
0
|
330 (setq vm-pop-read-point (point))
|
|
331 (process-send-string process command)
|
|
332 (process-send-string process "\r\n"))
|
|
333
|
|
334 (defun vm-pop-read-response (process &optional return-response-string)
|
|
335 (let ((case-fold-search nil)
|
|
336 match-end)
|
|
337 (goto-char vm-pop-read-point)
|
|
338 (while (not (search-forward "\r\n" nil t))
|
|
339 (accept-process-output process)
|
|
340 (goto-char vm-pop-read-point))
|
|
341 (setq match-end (point))
|
|
342 (goto-char vm-pop-read-point)
|
|
343 (if (not (looking-at "+OK"))
|
|
344 (progn (setq vm-pop-read-point match-end) nil)
|
|
345 (setq vm-pop-read-point match-end)
|
|
346 (if return-response-string
|
|
347 (buffer-substring (point) match-end)
|
|
348 t ))))
|
|
349
|
100
|
350 (defun vm-pop-read-past-dot-sentinel-line (process)
|
|
351 (let ((case-fold-search nil))
|
|
352 (goto-char vm-pop-read-point)
|
108
|
353 (while (not (re-search-forward "^\\.\r\n" nil 0))
|
100
|
354 (beginning-of-line)
|
|
355 ;; save-excursion doesn't work right
|
|
356 (let ((opoint (point)))
|
|
357 (accept-process-output process)
|
|
358 (goto-char opoint)))
|
|
359 (setq vm-pop-read-point (point))))
|
|
360
|
0
|
361 (defun vm-pop-read-stat-response (process)
|
100
|
362 (let ((response (vm-pop-read-response process t))
|
|
363 list)
|
|
364 (setq list (vm-parse response "\\([^ ]+\\) *"))
|
|
365 (list (string-to-int (nth 1 list)) (string-to-int (nth 2 list)))))
|
|
366
|
|
367 (defun vm-pop-read-list-response (process)
|
0
|
368 (let ((response (vm-pop-read-response process t)))
|
100
|
369 (string-to-int (nth 2 (vm-parse response "\\([^ ]+\\) *")))))
|
|
370
|
|
371 (defun vm-pop-ask-about-large-message (process size n)
|
|
372 (let ((work-buffer nil)
|
|
373 (pop-buffer (current-buffer))
|
|
374 start end)
|
|
375 (unwind-protect
|
|
376 (save-excursion
|
|
377 (save-window-excursion
|
|
378 (vm-pop-send-command process (format "TOP %d %d" n 0))
|
|
379 (if (vm-pop-read-response process)
|
|
380 (progn
|
|
381 (setq start vm-pop-read-point)
|
|
382 (vm-pop-read-past-dot-sentinel-line process)
|
|
383 (setq end vm-pop-read-point)
|
|
384 (setq work-buffer (generate-new-buffer "*pop-glop*"))
|
|
385 (set-buffer work-buffer)
|
|
386 (insert-buffer-substring pop-buffer start end)
|
|
387 (forward-line -1)
|
|
388 (delete-region (point) (point-max))
|
|
389 (vm-pop-cleanup-region (point-min) (point-max))
|
|
390 (vm-display-buffer work-buffer)
|
|
391 (setq minibuffer-scroll-window (selected-window))
|
|
392 (goto-char (point-min))
|
|
393 (if (re-search-forward "^Received:" nil t)
|
|
394 (progn
|
|
395 (goto-char (match-beginning 0))
|
|
396 (vm-reorder-message-headers
|
|
397 nil vm-visible-headers
|
|
398 vm-invisible-header-regexp)))
|
|
399 (set-window-point (selected-window) (point))))
|
|
400 (if (y-or-n-p (format "Message %d, size = %d, retrieve? " n size))
|
|
401 'retrieve
|
|
402 (if (y-or-n-p (format "Delete message %d from popdrop? " n size))
|
|
403 'delete
|
|
404 'skip))))
|
|
405 (and work-buffer (kill-buffer work-buffer)))))
|
24
|
406
|
108
|
407 (defun vm-pop-retrieve-to-crashbox (process crash statblob)
|
0
|
408 (let ((start vm-pop-read-point) end)
|
|
409 (goto-char start)
|
108
|
410 (vm-set-pop-stat-x-got statblob 0)
|
100
|
411 (while (not (re-search-forward "^\\.\r\n" nil 0))
|
|
412 (beginning-of-line)
|
|
413 ;; save-excursion doesn't work right
|
108
|
414 (let* ((opoint (point))
|
|
415 (func
|
|
416 (function
|
|
417 (lambda (beg end len)
|
|
418 (if vm-pop-read-point
|
|
419 (progn
|
|
420 (vm-set-pop-stat-x-got statblob (- end start))
|
|
421 (if (zerop (% (random) 10))
|
|
422 (vm-pop-report-retrieval-status statblob)))))))
|
|
423 (after-change-functions (cons func after-change-functions)))
|
100
|
424 (accept-process-output process)
|
|
425 (goto-char opoint)))
|
108
|
426 (vm-set-pop-stat-x-got statblob nil)
|
0
|
427 (setq vm-pop-read-point (point-marker))
|
|
428 (goto-char (match-beginning 0))
|
|
429 (setq end (point-marker))
|
|
430 (vm-pop-cleanup-region start end)
|
|
431 ;; Some POP servers strip leading and trailing message
|
|
432 ;; separators, some don't. Figure out what kind we're
|
|
433 ;; talking to and do the right thing.
|
|
434 (if (eq (vm-get-folder-type nil start end) 'unknown)
|
|
435 (progn
|
|
436 (vm-munge-message-separators vm-folder-type start end)
|
|
437 (goto-char start)
|
|
438 ;; avoid the consing and stat() call for all but babyl
|
|
439 ;; files, since this will probably slow things down.
|
|
440 ;; only babyl files have the folder header, and we
|
|
441 ;; should only insert it if the crash box is empty.
|
|
442 (if (and (eq vm-folder-type 'babyl)
|
|
443 (let ((attrs (file-attributes crash)))
|
|
444 (or (null attrs) (equal 0 (nth 7 attrs)))))
|
|
445 (let ((opoint (point)))
|
|
446 (vm-convert-folder-header nil vm-folder-type)
|
|
447 ;; if start is a marker, then it was moved
|
|
448 ;; forward by the insertion. restore it.
|
|
449 (setq start opoint)
|
|
450 (goto-char start)
|
|
451 (vm-skip-past-folder-header)))
|
|
452 (insert (vm-leading-message-separator))
|
|
453 ;; this will not find the trailing message separator but
|
|
454 ;; for the Content-Length stuff counting from eob is
|
|
455 ;; the same thing in this case.
|
|
456 (vm-convert-folder-type-headers nil vm-folder-type)
|
|
457 (goto-char end)
|
|
458 (insert-before-markers (vm-trailing-message-separator))))
|
98
|
459 ;; Set file type to binary for DOS/Windows. I don't know if
|
|
460 ;; this is correct to do or not; it depends on whether the
|
|
461 ;; the CRLF or the LF newline convention is used on the inbox
|
|
462 ;; associated with this crashbox. This setting assumes the LF
|
|
463 ;; newline convention is used.
|
|
464 (let ((buffer-file-type t))
|
|
465 (write-region start end crash t 0))
|
0
|
466 (delete-region start end)
|
|
467 t ))
|
|
468
|
|
469 (defun vm-pop-cleanup-region (start end)
|
108
|
470 (if (> (- end start) 30000)
|
|
471 (message "CRLF conversion and char unstuffing..."))
|
0
|
472 (setq end (vm-marker end))
|
|
473 (save-excursion
|
|
474 (goto-char start)
|
|
475 ;; CRLF -> LF
|
|
476 (while (and (< (point) end) (search-forward "\r\n" end t))
|
|
477 (replace-match "\n" t t))
|
|
478 (goto-char start)
|
|
479 ;; chop leading dots
|
|
480 (while (and (< (point) end) (re-search-forward "^\\." end t))
|
|
481 (replace-match "" t t)
|
|
482 (forward-char)))
|
108
|
483 (if (> (- end start) 30000)
|
|
484 (message "CRLF conversion and dot unstuffing... done"))
|
0
|
485 (set-marker end nil))
|
|
486
|
|
487 (defun vm-pop-md5 (string)
|
|
488 (let ((buffer nil))
|
|
489 (unwind-protect
|
|
490 (save-excursion
|
|
491 (setq buffer (generate-new-buffer "*vm-work*"))
|
|
492 (set-buffer buffer)
|
|
493 (insert string)
|
|
494 (call-process-region (point-min) (point-max)
|
|
495 "/bin/sh" t buffer nil
|
98
|
496 shell-command-switch vm-pop-md5-program)
|
0
|
497 ;; MD5 digest is 32 chars long
|
|
498 ;; mddriver adds a newline to make neaten output for tty
|
|
499 ;; viewing, make sure we leave it behind.
|
|
500 (vm-buffer-substring-no-properties (point-min) (+ (point-min) 32)))
|
|
501 (and buffer (kill-buffer buffer)))))
|