annotate lisp/vm/vm-pop.el @ 98:0d2f883870bc r20-1b1

Import from CVS: tag r20-1b1
author cvs
date Mon, 13 Aug 2007 09:13:56 +0200
parents 131b0175ea99
children 4be1180a9e89
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
1 ;;; Simple POP (RFC 1460) client for VM
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
2 ;;; Copyright (C) 1993, 1994 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)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 (handler (and (fboundp 'find-file-name-handler)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 (find-file-name-handler source 'vm-pop-move-mail)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 (wrong-number-of-arguments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 (find-file-name-handler source)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 (popdrop (vm-safe-popdrop-string source))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
33 greeting timestamp n message-count
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
34 host port auth user pass source-list process-buffer)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (catch 'done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (if handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (throw 'done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (funcall handler 'vm-pop-move-mail source destination)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;; parse the maildrop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (setq source-list (vm-parse source "\\([^:]+\\):?")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 host (nth 0 source-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 port (nth 1 source-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 auth (nth 2 source-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 user (nth 3 source-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 pass (nth 4 source-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;; carp if parts are missing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (if (null host)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (error "No host in POP maildrop specification, \"%s\""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 source))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (if (null port)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (error "No port in POP maildrop specification, \"%s\""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 source))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (if (string-match "^[0-9]+$" port)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (setq port (string-to-int port)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (if (null auth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 "No authentication method in POP maildrop specification, \"%s\""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 source))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (if (null user)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (error "No user in POP maildrop specification, \"%s\""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 source))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (if (null pass)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (error "No password in POP maildrop specification, \"%s\""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 source))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (if (equal pass "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (setq pass (car (cdr (assoc source vm-pop-passwords))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (if (null pass)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
70 (setq pass
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
71 (vm-read-password
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
72 (format "POP password for %s: "
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
73 popdrop))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
74 vm-pop-passwords (cons (list source pass)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
75 vm-pop-passwords)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
76 saved-password t))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 ;; get the trace buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (setq process-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (get-buffer-create (format "trace of POP session to %s" host)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ;; clear the trace buffer of old output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (set-buffer process-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (erase-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;; open the connection to the server
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (setq process (open-network-stream "POP" process-buffer host port))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (and (null process) (throw 'done nil))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
87 (set-process-filter process 'vm-pop-process-filter)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (set-buffer process-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (make-local-variable 'vm-pop-read-point)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
91 (setq vm-pop-read-point (point-min)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
92 vm-folder-type (or folder-type vm-default-folder-type))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
93 (and (null (setq greeting (vm-pop-read-response process t)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
94 (throw 'done nil))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 ;; authentication
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (cond ((equal auth "pass")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (vm-pop-send-command process (format "USER %s" user))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (and (null (vm-pop-read-response process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (throw 'done nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (vm-pop-send-command process (format "PASS %s" pass))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (if (null (vm-pop-read-response process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (if saved-password
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (setq vm-pop-passwords
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (delete (list source pass)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 vm-pop-passwords)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (throw 'done nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ((equal auth "rpop")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (vm-pop-send-command process (format "USER %s" user))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (and (null (vm-pop-read-response process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (throw 'done nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (vm-pop-send-command process (format "RPOP %s" pass))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (and (null (vm-pop-read-response process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (throw 'done nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ((equal auth "apop")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (setq timestamp (vm-parse greeting "[^<]+\\(<[^>]+>\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 timestamp (car timestamp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (if (null timestamp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (goto-char (point-max))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
121 (insert "<<< ooops, no timestamp found in greeting! >>>\n")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (throw 'done nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (vm-pop-send-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (format "APOP %s %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 user
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (vm-pop-md5 (concat timestamp pass))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (and (null (vm-pop-read-response process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (throw 'done nil)))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
130 (t (error "Don't know how to authenticate with %s" auth)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
131 ;; find out how many messages are in the box.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
132 (vm-pop-send-command process "STAT")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
133 (setq message-count (vm-pop-read-stat-response process))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
134 ;; forget it if the command fails
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
135 ;; or if there are no messages present.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
136 (if (or (null message-count)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
137 (< message-count 1))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
138 (throw 'done nil))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
139 ;; loop through the maildrop retrieving and deleting
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
140 ;; messages as we go.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
141 (setq n 1)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
142 (while (<= n message-count)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
143 (vm-unsaved-message "Retrieving message %d (of %d) from %s..."
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
144 n message-count popdrop)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
145 (vm-pop-send-command process (format "RETR %d" n))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
146 (and (null (vm-pop-read-response process))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
147 (throw 'done (not (equal n 1))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
148 (and (null (vm-pop-retrieve-to-crashbox process destination))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
149 (throw 'done (not (equal n 1))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
150 (vm-pop-send-command process (format "DELE %d" n))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
151 ;; DELE can't fail but Emacs or this code might
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
152 ;; blow a gasket and spew filth down the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
153 ;; connection, so...
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
154 (and (null (vm-pop-read-response process))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
155 (throw 'done (not (equal n 1))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
156 (vm-increment n))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
157 t ))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
158 (if process
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
159 (save-excursion
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
160 (set-buffer (process-buffer process))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
161 (vm-pop-send-command process "QUIT")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
162 (vm-pop-read-response process)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
163 (delete-process process))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
165 (defun vm-pop-process-filter (process output)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (set-buffer (process-buffer process))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
168 (goto-char (point-max))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
169 (insert output)))
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
170
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (defun vm-pop-send-command (process command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (if (= (aref command 0) ?P)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
174 (insert "PASS <omitted>\r\n")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
175 (insert command "\r\n"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (setq vm-pop-read-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (process-send-string process command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (process-send-string process "\r\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (defun vm-pop-read-response (process &optional return-response-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (let ((case-fold-search nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 match-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (goto-char vm-pop-read-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (while (not (search-forward "\r\n" nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (accept-process-output process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (goto-char vm-pop-read-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (setq match-end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (goto-char vm-pop-read-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (if (not (looking-at "+OK"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (progn (setq vm-pop-read-point match-end) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (setq vm-pop-read-point match-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (if return-response-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (buffer-substring (point) match-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 t ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (defun vm-pop-read-stat-response (process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (let ((response (vm-pop-read-response process t)))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
198 (string-to-int (nth 1 (vm-parse response "\\([^ ]+\\) *")))))
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 20
diff changeset
199
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
200 (defun vm-pop-retrieve-to-crashbox (process crash)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (let ((start vm-pop-read-point) end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (goto-char start)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
203 (while (not (re-search-forward "^\\.\r\n" nil t))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
204 (accept-process-output process)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 54
diff changeset
205 (goto-char start))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (setq vm-pop-read-point (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (setq end (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (vm-pop-cleanup-region start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 ;; Some POP servers strip leading and trailing message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 ;; separators, some don't. Figure out what kind we're
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 ;; talking to and do the right thing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (if (eq (vm-get-folder-type nil start end) 'unknown)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (vm-munge-message-separators vm-folder-type start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 ;; avoid the consing and stat() call for all but babyl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 ;; files, since this will probably slow things down.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 ;; only babyl files have the folder header, and we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 ;; should only insert it if the crash box is empty.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (if (and (eq vm-folder-type 'babyl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (let ((attrs (file-attributes crash)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (or (null attrs) (equal 0 (nth 7 attrs)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (let ((opoint (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (vm-convert-folder-header nil vm-folder-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 ;; if start is a marker, then it was moved
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 ;; forward by the insertion. restore it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (setq start opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (vm-skip-past-folder-header)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (insert (vm-leading-message-separator))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 ;; this will not find the trailing message separator but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 ;; for the Content-Length stuff counting from eob is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 ;; the same thing in this case.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (vm-convert-folder-type-headers nil vm-folder-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (insert-before-markers (vm-trailing-message-separator))))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
238 ;; 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
239 ;; this is correct to do or not; it depends on whether the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
240 ;; the CRLF or the LF newline convention is used on the inbox
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
241 ;; associated with this crashbox. This setting assumes the LF
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
242 ;; newline convention is used.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
243 (let ((buffer-file-type t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
244 (write-region start end crash t 0))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (delete-region start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 t ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (defun vm-pop-cleanup-region (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (setq end (vm-marker end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 ;; CRLF -> LF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (while (and (< (point) end) (search-forward "\r\n" end t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (replace-match "\n" t t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 ;; chop leading dots
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (while (and (< (point) end) (re-search-forward "^\\." end t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (replace-match "" t t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (forward-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (set-marker end nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (defun vm-pop-md5 (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (let ((buffer nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (setq buffer (generate-new-buffer "*vm-work*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (insert string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (call-process-region (point-min) (point-max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 "/bin/sh" t buffer nil
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
271 shell-command-switch vm-pop-md5-program)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 ;; MD5 digest is 32 chars long
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 ;; mddriver adds a newline to make neaten output for tty
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 ;; viewing, make sure we leave it behind.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (vm-buffer-substring-no-properties (point-min) (+ (point-min) 32)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (and buffer (kill-buffer buffer)))))