Mercurial > emacs
annotate lisp/gnus/pop3.el @ 26473:762c51f4a100
(unexec): Handle .rel.dyn section.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Wed, 17 Nov 1999 20:58:06 +0000 |
parents | 08a36c7a0a52 |
children | 64597461b498 |
rev | line source |
---|---|
17493 | 1 ;;; pop3.el --- Post Office Protocol (RFC 1460) interface |
2 | |
26108
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
3 ;; Copyright (C) 1996-1999 Free Software Foundation, Inc. |
17493 | 4 |
5 ;; Author: Richard L. Pieri <ratinox@peorth.gweep.net> | |
26108
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
6 ;; Maintainer: FSF |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
7 ;; Keywords: mail |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
8 ;; Version: 1.3s |
17493 | 9 |
10 ;; This file is part of GNU Emacs. | |
11 | |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
13 ;; it under the terms of the GNU General Public License as published by | |
14 ;; the Free Software Foundation; either version 2, or (at your option) | |
15 ;; any later version. | |
16 | |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
25 ;; Boston, MA 02111-1307, USA. | |
26 | |
27 ;;; Commentary: | |
28 | |
29 ;; Most of the standard Post Office Protocol version 3 (RFC 1460) commands | |
30 ;; are implemented. The LIST command has not been implemented due to lack | |
31 ;; of actual usefulness. | |
32 ;; The optional POP3 command TOP has not been implemented. | |
33 | |
34 ;; This program was inspired by Kyle E. Jones's vm-pop program. | |
35 | |
36 ;;; Code: | |
37 | |
38 (require 'mail-utils) | |
39 | |
26108
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
40 (defconst pop3-version "1.3s") |
17493 | 41 |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
42 (defvar pop3-maildrop (or (user-login-name) (getenv "LOGNAME") (getenv "USER") nil) |
17493 | 43 "*POP3 maildrop.") |
44 (defvar pop3-mailhost (or (getenv "MAILHOST") nil) | |
45 "*POP3 mailhost.") | |
46 (defvar pop3-port 110 | |
47 "*POP3 port.") | |
48 | |
49 (defvar pop3-password-required t | |
50 "*Non-nil if a password is required when connecting to POP server.") | |
51 (defvar pop3-password nil | |
52 "*Password to use when connecting to POP server.") | |
53 | |
54 (defvar pop3-authentication-scheme 'pass | |
55 "*POP3 authentication scheme. | |
56 Defaults to 'pass, for the standard USER/PASS authentication. Other valid | |
57 values are 'apop.") | |
58 | |
59 (defvar pop3-timestamp nil | |
60 "Timestamp returned when initially connected to the POP server. | |
61 Used for APOP authentication.") | |
62 | |
19595
7184c8337963
(pop3-movemail-file-coding-system): Append it for
Kenichi Handa <handa@m17n.org>
parents:
17493
diff
changeset
|
63 (defvar pop3-movemail-file-coding-system nil |
26108
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
64 "Crashbox made by `pop3-movemail' with this coding system.") |
19595
7184c8337963
(pop3-movemail-file-coding-system): Append it for
Kenichi Handa <handa@m17n.org>
parents:
17493
diff
changeset
|
65 |
17493 | 66 (defvar pop3-read-point nil) |
67 (defvar pop3-debug nil) | |
68 | |
69 (defun pop3-movemail (&optional crashbox) | |
70 "Transfer contents of a maildrop to the specified CRASHBOX." | |
71 (or crashbox (setq crashbox (expand-file-name "~/.crashbox"))) | |
72 (let* ((process (pop3-open-server pop3-mailhost pop3-port)) | |
73 (crashbuf (get-buffer-create " *pop3-retr*")) | |
74 (n 1) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
75 message-count |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
76 (pop3-password pop3-password) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
77 ) |
17493 | 78 ;; for debugging only |
79 (if pop3-debug (switch-to-buffer (process-buffer process))) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
80 ;; query for password |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
81 (if (and pop3-password-required (not pop3-password)) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
82 (setq pop3-password |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
83 (pop3-read-passwd (format "Password for %s: " pop3-maildrop)))) |
17493 | 84 (cond ((equal 'apop pop3-authentication-scheme) |
85 (pop3-apop process pop3-maildrop)) | |
86 ((equal 'pass pop3-authentication-scheme) | |
87 (pop3-user process pop3-maildrop) | |
88 (pop3-pass process)) | |
26108
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
89 (t (error "Invalid POP3 authentication scheme"))) |
17493 | 90 (setq message-count (car (pop3-stat process))) |
26108
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
91 (unwind-protect |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
92 (while (<= n message-count) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
93 (message (format "Retrieving message %d of %d from %s..." |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
94 n message-count pop3-mailhost)) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
95 (pop3-retr process n crashbuf) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
96 (save-excursion |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
97 (set-buffer crashbuf) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
98 (write-region (point-min) (point-max) crashbox t 'nomesg) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
99 (set-buffer (process-buffer process)) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
100 (while (> (buffer-size) 5000) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
101 (goto-char (point-min)) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
102 (forward-line 50) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
103 (delete-region (point-min) (point)))) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
104 (pop3-dele process n) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
105 (setq n (+ 1 n)) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
106 (if pop3-debug (sit-for 1) (sit-for 0.1)) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
107 ) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
108 (pop3-quit process)) |
17493 | 109 (kill-buffer crashbuf) |
110 ) | |
26108
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
111 t) |
17493 | 112 |
113 (defun pop3-open-server (mailhost port) | |
26108
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
114 "Open TCP connection to MAILHOST on PORT. |
17493 | 115 Returns the process associated with the connection." |
116 (let ((process-buffer | |
117 (get-buffer-create (format "trace of POP session to %s" mailhost))) | |
23403
789be3d7ef2d
(pop3-open-server): Set process-coding-system-alist around open-network-stream.
Richard M. Stallman <rms@gnu.org>
parents:
19969
diff
changeset
|
118 (process) |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
119 (coding-system-for-read 'binary) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
120 (coding-system-for-write 'binary) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
121 ) |
17493 | 122 (save-excursion |
123 (set-buffer process-buffer) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
124 (erase-buffer) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
125 (setq pop3-read-point (point-min)) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
126 ) |
17493 | 127 (setq process |
128 (open-network-stream "POP" process-buffer mailhost port)) | |
129 (let ((response (pop3-read-response process t))) | |
130 (setq pop3-timestamp | |
131 (substring response (or (string-match "<" response) 0) | |
132 (+ 1 (or (string-match ">" response) -1))))) | |
133 process | |
134 )) | |
135 | |
136 ;; Support functions | |
137 | |
138 (defun pop3-process-filter (process output) | |
139 (save-excursion | |
140 (set-buffer (process-buffer process)) | |
141 (goto-char (point-max)) | |
142 (insert output))) | |
143 | |
144 (defun pop3-send-command (process command) | |
145 (set-buffer (process-buffer process)) | |
146 (goto-char (point-max)) | |
147 ;; (if (= (aref command 0) ?P) | |
148 ;; (insert "PASS <omitted>\r\n") | |
149 ;; (insert command "\r\n")) | |
150 (setq pop3-read-point (point)) | |
151 (goto-char (point-max)) | |
26108
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
152 (process-send-string process (concat command "\r\n")) |
17493 | 153 ) |
154 | |
155 (defun pop3-read-response (process &optional return) | |
156 "Read the response from the server. | |
157 Return the response string if optional second argument is non-nil." | |
158 (let ((case-fold-search nil) | |
159 match-end) | |
160 (save-excursion | |
161 (set-buffer (process-buffer process)) | |
162 (goto-char pop3-read-point) | |
163 (while (not (search-forward "\r\n" nil t)) | |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19633
diff
changeset
|
164 (accept-process-output process 3) |
17493 | 165 (goto-char pop3-read-point)) |
166 (setq match-end (point)) | |
167 (goto-char pop3-read-point) | |
168 (if (looking-at "-ERR") | |
169 (error (buffer-substring (point) (- match-end 2))) | |
170 (if (not (looking-at "+OK")) | |
171 (progn (setq pop3-read-point match-end) nil) | |
172 (setq pop3-read-point match-end) | |
173 (if return | |
174 (buffer-substring (point) match-end) | |
175 t) | |
176 ))))) | |
177 | |
178 (defun pop3-string-to-list (string &optional regexp) | |
179 "Chop up a string into a list." | |
180 (let ((list) | |
181 (regexp (or regexp " ")) | |
182 (string (if (string-match "\r" string) | |
183 (substring string 0 (match-beginning 0)) | |
184 string))) | |
185 (store-match-data nil) | |
186 (while string | |
187 (if (string-match regexp string) | |
188 (setq list (cons (substring string 0 (- (match-end 0) 1)) list) | |
189 string (substring string (match-end 0))) | |
190 (setq list (cons string list) | |
191 string nil))) | |
192 (nreverse list))) | |
193 | |
194 (defvar pop3-read-passwd nil) | |
195 (defun pop3-read-passwd (prompt) | |
196 (if (not pop3-read-passwd) | |
24599
04a29f9f6a22
(pop3-read-passwd): Use read-passwd if that is defined.
Richard M. Stallman <rms@gnu.org>
parents:
24357
diff
changeset
|
197 (if (fboundp 'read-passwd) |
17493 | 198 (setq pop3-read-passwd 'read-passwd) |
24599
04a29f9f6a22
(pop3-read-passwd): Use read-passwd if that is defined.
Richard M. Stallman <rms@gnu.org>
parents:
24357
diff
changeset
|
199 (if (load "passwd" t) |
04a29f9f6a22
(pop3-read-passwd): Use read-passwd if that is defined.
Richard M. Stallman <rms@gnu.org>
parents:
24357
diff
changeset
|
200 (setq pop3-read-passwd 'read-passwd) |
04a29f9f6a22
(pop3-read-passwd): Use read-passwd if that is defined.
Richard M. Stallman <rms@gnu.org>
parents:
24357
diff
changeset
|
201 (autoload 'ange-ftp-read-passwd "ange-ftp") |
04a29f9f6a22
(pop3-read-passwd): Use read-passwd if that is defined.
Richard M. Stallman <rms@gnu.org>
parents:
24357
diff
changeset
|
202 (setq pop3-read-passwd 'ange-ftp-read-passwd)))) |
17493 | 203 (funcall pop3-read-passwd prompt)) |
204 | |
205 (defun pop3-clean-region (start end) | |
206 (setq end (set-marker (make-marker) end)) | |
207 (save-excursion | |
208 (goto-char start) | |
209 (while (and (< (point) end) (search-forward "\r\n" end t)) | |
210 (replace-match "\n" t t)) | |
211 (goto-char start) | |
212 (while (and (< (point) end) (re-search-forward "^\\." end t)) | |
213 (replace-match "" t t) | |
214 (forward-char))) | |
215 (set-marker end nil)) | |
216 | |
217 (defun pop3-munge-message-separator (start end) | |
218 "Check to see if a message separator exists. If not, generate one." | |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19633
diff
changeset
|
219 (if (not (fboundp 'message-make-date)) (autoload 'message-make-date "message")) |
17493 | 220 (save-excursion |
221 (save-restriction | |
222 (narrow-to-region start end) | |
223 (goto-char (point-min)) | |
224 (if (not (or (looking-at "From .?") ; Unix mail | |
225 (looking-at "\001\001\001\001\n") ; MMDF | |
226 (looking-at "BABYL OPTIONS:") ; Babyl | |
227 )) | |
228 (let ((from (mail-strip-quoted-names (mail-fetch-field "From"))) | |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19633
diff
changeset
|
229 (date (pop3-string-to-list (or (mail-fetch-field "Date") |
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19633
diff
changeset
|
230 (message-make-date)))) |
17493 | 231 (From_)) |
232 ;; sample date formats I have seen | |
233 ;; Date: Tue, 9 Jul 1996 09:04:21 -0400 (EDT) | |
234 ;; Date: 08 Jul 1996 23:22:24 -0400 | |
235 ;; should be | |
236 ;; Tue Jul 9 09:04:21 1996 | |
237 (setq date | |
238 (cond ((string-match "[A-Z]" (nth 0 date)) | |
239 (format "%s %s %s %s %s" | |
240 (nth 0 date) (nth 2 date) (nth 1 date) | |
241 (nth 4 date) (nth 3 date))) | |
242 (t | |
243 ;; this really needs to be better but I don't feel | |
244 ;; like writing a date to day converter. | |
245 (format "Sun %s %s %s %s" | |
246 (nth 1 date) (nth 0 date) | |
247 (nth 3 date) (nth 2 date))) | |
248 )) | |
249 (setq From_ (format "\nFrom %s %s\n" from date)) | |
250 (while (string-match "," From_) | |
251 (setq From_ (concat (substring From_ 0 (match-beginning 0)) | |
252 (substring From_ (match-end 0))))) | |
253 (goto-char (point-min)) | |
26108
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
254 (insert From_) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
255 (re-search-forward "\n\n") |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
256 (narrow-to-region (point) (point-max)) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
257 (let ((size (- (point-max) (point-min)))) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
258 (goto-char (point-min)) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
259 (widen) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
260 (forward-line -1) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
261 (insert (format "Content-Length: %s\n" size))) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
262 ))))) |
17493 | 263 |
264 ;; The Command Set | |
265 | |
266 ;; AUTHORIZATION STATE | |
267 | |
268 (defun pop3-user (process user) | |
269 "Send USER information to POP3 server." | |
270 (pop3-send-command process (format "USER %s" user)) | |
271 (let ((response (pop3-read-response process t))) | |
272 (if (not (and response (string-match "+OK" response))) | |
273 (error (format "USER %s not valid." user))))) | |
274 | |
275 (defun pop3-pass (process) | |
276 "Send authentication information to the server." | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
277 (pop3-send-command process (format "PASS %s" pop3-password)) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
278 (let ((response (pop3-read-response process t))) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
279 (if (not (and response (string-match "+OK" response))) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
280 (pop3-quit process)))) |
19633
25317a11d7a1
(pop3-md5): New function.
Richard M. Stallman <rms@gnu.org>
parents:
19595
diff
changeset
|
281 |
17493 | 282 (defun pop3-apop (process user) |
283 "Send alternate authentication information to the server." | |
284 (let ((pass pop3-password)) | |
285 (if (and pop3-password-required (not pass)) | |
286 (setq pass | |
287 (pop3-read-passwd (format "Password for %s: " pop3-maildrop)))) | |
288 (if pass | |
19633
25317a11d7a1
(pop3-md5): New function.
Richard M. Stallman <rms@gnu.org>
parents:
19595
diff
changeset
|
289 (let ((hash (pop3-md5 (concat pop3-timestamp pass)))) |
17493 | 290 (pop3-send-command process (format "APOP %s %s" user hash)) |
291 (let ((response (pop3-read-response process t))) | |
292 (if (not (and response (string-match "+OK" response))) | |
293 (pop3-quit process))))) | |
294 )) | |
295 | |
296 ;; TRANSACTION STATE | |
297 | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
298 (defvar pop3-md5-program "md5" |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
299 "*Program to encode its input in MD5.") |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
300 |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
301 (defun pop3-md5 (string) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
302 (with-temp-buffer |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
303 (insert string) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
304 (call-process-region (point-min) (point-max) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
305 (or shell-file-name "/bin/sh") |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
306 t (current-buffer) nil |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
307 "-c" pop3-md5-program) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
308 ;; The meaningful output is the first 32 characters. |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
309 ;; Don't return the newline that follows them! |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
310 (buffer-substring (point-min) (+ (point-min) 32)))) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
311 |
17493 | 312 (defun pop3-stat (process) |
313 "Return the number of messages in the maildrop and the maildrop's size." | |
314 (pop3-send-command process "STAT") | |
315 (let ((response (pop3-read-response process t))) | |
316 (list (string-to-int (nth 1 (pop3-string-to-list response))) | |
317 (string-to-int (nth 2 (pop3-string-to-list response)))) | |
318 )) | |
319 | |
320 (defun pop3-list (process &optional msg) | |
321 "Scan listing of available messages. | |
322 This function currently does nothing.") | |
323 | |
324 (defun pop3-retr (process msg crashbuf) | |
325 "Retrieve message-id MSG to buffer CRASHBUF." | |
326 (pop3-send-command process (format "RETR %s" msg)) | |
327 (pop3-read-response process) | |
328 (let ((start pop3-read-point) end) | |
329 (save-excursion | |
330 (set-buffer (process-buffer process)) | |
331 (while (not (re-search-forward "^\\.\r\n" nil t)) | |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19633
diff
changeset
|
332 (accept-process-output process 3) |
17493 | 333 ;; bill@att.com ... to save wear and tear on the heap |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
334 ;; uncommented because the condensed version below is a problem for |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
335 ;; some. |
17493 | 336 (if (> (buffer-size) 20000) (sleep-for 1)) |
337 (if (> (buffer-size) 50000) (sleep-for 1)) | |
338 (if (> (buffer-size) 100000) (sleep-for 1)) | |
339 (if (> (buffer-size) 200000) (sleep-for 1)) | |
340 (if (> (buffer-size) 500000) (sleep-for 1)) | |
341 ;; bill@att.com | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
342 ;; condensed into: |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
343 ;; (sometimes causes problems for really large messages.) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
344 ; (if (> (buffer-size) 20000) (sleep-for (/ (buffer-size) 20000))) |
17493 | 345 (goto-char start)) |
346 (setq pop3-read-point (point-marker)) | |
347 ;; this code does not seem to work for some POP servers... | |
348 ;; and I cannot figure out why not. | |
349 ; (goto-char (match-beginning 0)) | |
350 ; (backward-char 2) | |
351 ; (if (not (looking-at "\r\n")) | |
352 ; (insert "\r\n")) | |
353 ; (re-search-forward "\\.\r\n") | |
354 (goto-char (match-beginning 0)) | |
355 (setq end (point-marker)) | |
356 (pop3-clean-region start end) | |
357 (pop3-munge-message-separator start end) | |
358 (save-excursion | |
359 (set-buffer crashbuf) | |
360 (erase-buffer)) | |
361 (copy-to-buffer crashbuf start end) | |
362 (delete-region start end) | |
363 ))) | |
364 | |
365 (defun pop3-dele (process msg) | |
366 "Mark message-id MSG as deleted." | |
367 (pop3-send-command process (format "DELE %s" msg)) | |
368 (pop3-read-response process)) | |
369 | |
370 (defun pop3-noop (process msg) | |
371 "No-operation." | |
372 (pop3-send-command process "NOOP") | |
373 (pop3-read-response process)) | |
374 | |
375 (defun pop3-last (process) | |
376 "Return highest accessed message-id number for the session." | |
377 (pop3-send-command process "LAST") | |
378 (let ((response (pop3-read-response process t))) | |
379 (string-to-int (nth 1 (pop3-string-to-list response))) | |
380 )) | |
381 | |
382 (defun pop3-rset (process) | |
383 "Remove all delete marks from current maildrop." | |
384 (pop3-send-command process "RSET") | |
385 (pop3-read-response process)) | |
386 | |
387 ;; UPDATE | |
388 | |
389 (defun pop3-quit (process) | |
390 "Close connection to POP3 server. | |
391 Tell server to remove all messages marked as deleted, unlock the maildrop, | |
392 and close the connection." | |
393 (pop3-send-command process "QUIT") | |
394 (pop3-read-response process t) | |
395 (if process | |
396 (save-excursion | |
397 (set-buffer (process-buffer process)) | |
398 (goto-char (point-max)) | |
399 (delete-process process)))) | |
400 | |
401 ;; Summary of POP3 (Post Office Protocol version 3) commands and responses | |
402 | |
403 ;;; AUTHORIZATION STATE | |
404 | |
405 ;; Initial TCP connection | |
406 ;; Arguments: none | |
407 ;; Restrictions: none | |
408 ;; Possible responses: | |
409 ;; +OK [POP3 server ready] | |
410 | |
411 ;; USER name | |
412 ;; Arguments: a server specific user-id (required) | |
413 ;; Restrictions: authorization state [after unsuccessful USER or PASS | |
414 ;; Possible responses: | |
415 ;; +OK [valid user-id] | |
416 ;; -ERR [invalid user-id] | |
417 | |
418 ;; PASS string | |
419 ;; Arguments: a server/user-id specific password (required) | |
420 ;; Restrictions: authorization state, after successful USER | |
421 ;; Possible responses: | |
422 ;; +OK [maildrop locked and ready] | |
423 ;; -ERR [invalid password] | |
424 ;; -ERR [unable to lock maildrop] | |
425 | |
426 ;;; TRANSACTION STATE | |
427 | |
428 ;; STAT | |
429 ;; Arguments: none | |
430 ;; Restrictions: transaction state | |
431 ;; Possible responses: | |
432 ;; +OK nn mm [# of messages, size of maildrop] | |
433 | |
434 ;; LIST [msg] | |
435 ;; Arguments: a message-id (optional) | |
436 ;; Restrictions: transaction state; msg must not be deleted | |
437 ;; Possible responses: | |
438 ;; +OK [scan listing follows] | |
439 ;; -ERR [no such message] | |
440 | |
441 ;; RETR msg | |
442 ;; Arguments: a message-id (required) | |
443 ;; Restrictions: transaction state; msg must not be deleted | |
444 ;; Possible responses: | |
445 ;; +OK [message contents follow] | |
446 ;; -ERR [no such message] | |
447 | |
448 ;; DELE msg | |
449 ;; Arguments: a message-id (required) | |
450 ;; Restrictions: transaction state; msg must not be deleted | |
451 ;; Possible responses: | |
452 ;; +OK [message deleted] | |
453 ;; -ERR [no such message] | |
454 | |
455 ;; NOOP | |
456 ;; Arguments: none | |
457 ;; Restrictions: transaction state | |
458 ;; Possible responses: | |
459 ;; +OK | |
460 | |
461 ;; LAST | |
462 ;; Arguments: none | |
463 ;; Restrictions: transaction state | |
464 ;; Possible responses: | |
465 ;; +OK nn [highest numbered message accessed] | |
466 | |
467 ;; RSET | |
468 ;; Arguments: none | |
469 ;; Restrictions: transaction state | |
470 ;; Possible responses: | |
471 ;; +OK [all delete marks removed] | |
472 | |
473 ;;; UPDATE STATE | |
474 | |
475 ;; QUIT | |
476 ;; Arguments: none | |
477 ;; Restrictions: none | |
478 ;; Possible responses: | |
479 ;; +OK [TCP connection closed] | |
26108
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
480 |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
481 (provide 'pop3) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
482 |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
483 ;;; pop3.el ends here |