Mercurial > emacs
annotate lisp/gnus/pop3.el @ 30618:9dd1a6504bdd
Use `nth' instead of `first', `second', and `third'.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Sun, 06 Aug 2000 09:18:02 +0000 |
parents | f451114521a7 |
children | 9968f55ad26e |
rev | line source |
---|---|
17493 | 1 ;;; pop3.el --- Post Office Protocol (RFC 1460) interface |
2 | |
27546 | 3 ;; Copyright (C) 1996, 96, 97, 98, 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 |
26944
64597461b498
(pop3-movemail-file-coding-system): Doc fix.
Dave Love <fx@gnu.org>
parents:
26108
diff
changeset
|
64 "Coding system for the crashbox made by `pop3-movemail'.") |
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) |
26944
64597461b498
(pop3-movemail-file-coding-system): Doc fix.
Dave Love <fx@gnu.org>
parents:
26108
diff
changeset
|
98 (let ((coding-system-for-write pop3-movemail-file-coding-system)) |
64597461b498
(pop3-movemail-file-coding-system): Doc fix.
Dave Love <fx@gnu.org>
parents:
26108
diff
changeset
|
99 (write-region (point-min) (point-max) crashbox t 'nomesg)) |
26108
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
100 (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
|
101 (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
|
102 (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
|
103 (forward-line 50) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
104 (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
|
105 (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
|
106 (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
|
107 (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
|
108 ) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
109 (pop3-quit process)) |
17493 | 110 (kill-buffer crashbuf) |
111 ) | |
26108
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
112 t) |
17493 | 113 |
114 (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
|
115 "Open TCP connection to MAILHOST on PORT. |
17493 | 116 Returns the process associated with the connection." |
28835 | 117 (let ((coding-system-for-read 'binary) |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
118 (coding-system-for-write 'binary) |
28835 | 119 process) |
17493 | 120 (save-excursion |
28835 | 121 (set-buffer (get-buffer-create (concat " trace of POP session to " |
122 mailhost))) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
123 (erase-buffer) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
124 (setq pop3-read-point (point-min)) |
28835 | 125 (setq process (open-network-stream "POP"(current-buffer) mailhost port)) |
126 (let ((response (pop3-read-response process t))) | |
127 (setq pop3-timestamp | |
128 (substring response (or (string-match "<" response) 0) | |
129 (+ 1 (or (string-match ">" response) -1))))) | |
130 process))) | |
17493 | 131 |
132 ;; Support functions | |
133 | |
134 (defun pop3-process-filter (process output) | |
135 (save-excursion | |
136 (set-buffer (process-buffer process)) | |
137 (goto-char (point-max)) | |
138 (insert output))) | |
139 | |
140 (defun pop3-send-command (process command) | |
141 (set-buffer (process-buffer process)) | |
142 (goto-char (point-max)) | |
143 ;; (if (= (aref command 0) ?P) | |
144 ;; (insert "PASS <omitted>\r\n") | |
145 ;; (insert command "\r\n")) | |
146 (setq pop3-read-point (point)) | |
147 (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
|
148 (process-send-string process (concat command "\r\n")) |
17493 | 149 ) |
150 | |
151 (defun pop3-read-response (process &optional return) | |
152 "Read the response from the server. | |
153 Return the response string if optional second argument is non-nil." | |
154 (let ((case-fold-search nil) | |
155 match-end) | |
156 (save-excursion | |
157 (set-buffer (process-buffer process)) | |
158 (goto-char pop3-read-point) | |
159 (while (not (search-forward "\r\n" nil t)) | |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19633
diff
changeset
|
160 (accept-process-output process 3) |
17493 | 161 (goto-char pop3-read-point)) |
162 (setq match-end (point)) | |
163 (goto-char pop3-read-point) | |
164 (if (looking-at "-ERR") | |
165 (error (buffer-substring (point) (- match-end 2))) | |
166 (if (not (looking-at "+OK")) | |
167 (progn (setq pop3-read-point match-end) nil) | |
168 (setq pop3-read-point match-end) | |
169 (if return | |
170 (buffer-substring (point) match-end) | |
171 t) | |
172 ))))) | |
173 | |
174 (defvar pop3-read-passwd nil) | |
175 (defun pop3-read-passwd (prompt) | |
176 (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
|
177 (if (fboundp 'read-passwd) |
17493 | 178 (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
|
179 (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
|
180 (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
|
181 (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
|
182 (setq pop3-read-passwd 'ange-ftp-read-passwd)))) |
17493 | 183 (funcall pop3-read-passwd prompt)) |
184 | |
185 (defun pop3-clean-region (start end) | |
186 (setq end (set-marker (make-marker) end)) | |
187 (save-excursion | |
188 (goto-char start) | |
189 (while (and (< (point) end) (search-forward "\r\n" end t)) | |
190 (replace-match "\n" t t)) | |
191 (goto-char start) | |
192 (while (and (< (point) end) (re-search-forward "^\\." end t)) | |
193 (replace-match "" t t) | |
194 (forward-char))) | |
195 (set-marker end nil)) | |
196 | |
197 (defun pop3-munge-message-separator (start end) | |
198 "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
|
199 (if (not (fboundp 'message-make-date)) (autoload 'message-make-date "message")) |
17493 | 200 (save-excursion |
201 (save-restriction | |
202 (narrow-to-region start end) | |
203 (goto-char (point-min)) | |
204 (if (not (or (looking-at "From .?") ; Unix mail | |
205 (looking-at "\001\001\001\001\n") ; MMDF | |
206 (looking-at "BABYL OPTIONS:") ; Babyl | |
207 )) | |
208 (let ((from (mail-strip-quoted-names (mail-fetch-field "From"))) | |
28835 | 209 (date (split-string (or (mail-fetch-field "Date") |
210 (message-make-date)) | |
211 " ")) | |
17493 | 212 (From_)) |
213 ;; sample date formats I have seen | |
214 ;; Date: Tue, 9 Jul 1996 09:04:21 -0400 (EDT) | |
215 ;; Date: 08 Jul 1996 23:22:24 -0400 | |
216 ;; should be | |
217 ;; Tue Jul 9 09:04:21 1996 | |
218 (setq date | |
219 (cond ((string-match "[A-Z]" (nth 0 date)) | |
220 (format "%s %s %s %s %s" | |
221 (nth 0 date) (nth 2 date) (nth 1 date) | |
222 (nth 4 date) (nth 3 date))) | |
223 (t | |
224 ;; this really needs to be better but I don't feel | |
225 ;; like writing a date to day converter. | |
226 (format "Sun %s %s %s %s" | |
227 (nth 1 date) (nth 0 date) | |
228 (nth 3 date) (nth 2 date))) | |
229 )) | |
230 (setq From_ (format "\nFrom %s %s\n" from date)) | |
231 (while (string-match "," From_) | |
232 (setq From_ (concat (substring From_ 0 (match-beginning 0)) | |
233 (substring From_ (match-end 0))))) | |
234 (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
|
235 (insert From_) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
236 (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
|
237 (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
|
238 (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
|
239 (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
|
240 (widen) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
241 (forward-line -1) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
242 (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
|
243 ))))) |
17493 | 244 |
245 ;; The Command Set | |
246 | |
247 ;; AUTHORIZATION STATE | |
248 | |
249 (defun pop3-user (process user) | |
250 "Send USER information to POP3 server." | |
251 (pop3-send-command process (format "USER %s" user)) | |
252 (let ((response (pop3-read-response process t))) | |
253 (if (not (and response (string-match "+OK" response))) | |
254 (error (format "USER %s not valid." user))))) | |
255 | |
256 (defun pop3-pass (process) | |
257 "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
|
258 (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
|
259 (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
|
260 (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
|
261 (pop3-quit process)))) |
19633
25317a11d7a1
(pop3-md5): New function.
Richard M. Stallman <rms@gnu.org>
parents:
19595
diff
changeset
|
262 |
17493 | 263 (defun pop3-apop (process user) |
264 "Send alternate authentication information to the server." | |
265 (let ((pass pop3-password)) | |
266 (if (and pop3-password-required (not pass)) | |
267 (setq pass | |
268 (pop3-read-passwd (format "Password for %s: " pop3-maildrop)))) | |
269 (if pass | |
19633
25317a11d7a1
(pop3-md5): New function.
Richard M. Stallman <rms@gnu.org>
parents:
19595
diff
changeset
|
270 (let ((hash (pop3-md5 (concat pop3-timestamp pass)))) |
17493 | 271 (pop3-send-command process (format "APOP %s %s" user hash)) |
272 (let ((response (pop3-read-response process t))) | |
273 (if (not (and response (string-match "+OK" response))) | |
274 (pop3-quit process))))) | |
275 )) | |
276 | |
277 ;; TRANSACTION STATE | |
278 | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
279 (defvar pop3-md5-program "md5" |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
280 "*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
|
281 |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
282 (defun pop3-md5 (string) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
283 (with-temp-buffer |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
284 (insert string) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
285 (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
|
286 (or shell-file-name "/bin/sh") |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
287 t (current-buffer) nil |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
288 "-c" pop3-md5-program) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
289 ;; 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
|
290 ;; 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
|
291 (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
|
292 |
17493 | 293 (defun pop3-stat (process) |
294 "Return the number of messages in the maildrop and the maildrop's size." | |
295 (pop3-send-command process "STAT") | |
296 (let ((response (pop3-read-response process t))) | |
28835 | 297 (list (string-to-int (nth 1 (split-string response " "))) |
298 (string-to-int (nth 2 (split-string response " ")))) | |
17493 | 299 )) |
300 | |
301 (defun pop3-list (process &optional msg) | |
302 "Scan listing of available messages. | |
303 This function currently does nothing.") | |
304 | |
305 (defun pop3-retr (process msg crashbuf) | |
306 "Retrieve message-id MSG to buffer CRASHBUF." | |
307 (pop3-send-command process (format "RETR %s" msg)) | |
308 (pop3-read-response process) | |
309 (let ((start pop3-read-point) end) | |
310 (save-excursion | |
311 (set-buffer (process-buffer process)) | |
312 (while (not (re-search-forward "^\\.\r\n" nil t)) | |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19633
diff
changeset
|
313 (accept-process-output process 3) |
17493 | 314 ;; 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
|
315 ;; 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
|
316 ;; some. |
17493 | 317 (if (> (buffer-size) 20000) (sleep-for 1)) |
318 (if (> (buffer-size) 50000) (sleep-for 1)) | |
319 (if (> (buffer-size) 100000) (sleep-for 1)) | |
320 (if (> (buffer-size) 200000) (sleep-for 1)) | |
321 (if (> (buffer-size) 500000) (sleep-for 1)) | |
322 ;; bill@att.com | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
323 ;; condensed into: |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
324 ;; (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
|
325 ; (if (> (buffer-size) 20000) (sleep-for (/ (buffer-size) 20000))) |
17493 | 326 (goto-char start)) |
327 (setq pop3-read-point (point-marker)) | |
328 ;; this code does not seem to work for some POP servers... | |
329 ;; and I cannot figure out why not. | |
330 ; (goto-char (match-beginning 0)) | |
331 ; (backward-char 2) | |
332 ; (if (not (looking-at "\r\n")) | |
333 ; (insert "\r\n")) | |
334 ; (re-search-forward "\\.\r\n") | |
335 (goto-char (match-beginning 0)) | |
336 (setq end (point-marker)) | |
337 (pop3-clean-region start end) | |
338 (pop3-munge-message-separator start end) | |
339 (save-excursion | |
340 (set-buffer crashbuf) | |
341 (erase-buffer)) | |
342 (copy-to-buffer crashbuf start end) | |
343 (delete-region start end) | |
344 ))) | |
345 | |
346 (defun pop3-dele (process msg) | |
347 "Mark message-id MSG as deleted." | |
348 (pop3-send-command process (format "DELE %s" msg)) | |
349 (pop3-read-response process)) | |
350 | |
351 (defun pop3-noop (process msg) | |
352 "No-operation." | |
353 (pop3-send-command process "NOOP") | |
354 (pop3-read-response process)) | |
355 | |
356 (defun pop3-last (process) | |
357 "Return highest accessed message-id number for the session." | |
358 (pop3-send-command process "LAST") | |
359 (let ((response (pop3-read-response process t))) | |
28835 | 360 (string-to-int (nth 1 (split-string response " "))) |
17493 | 361 )) |
362 | |
363 (defun pop3-rset (process) | |
364 "Remove all delete marks from current maildrop." | |
365 (pop3-send-command process "RSET") | |
366 (pop3-read-response process)) | |
367 | |
368 ;; UPDATE | |
369 | |
370 (defun pop3-quit (process) | |
371 "Close connection to POP3 server. | |
372 Tell server to remove all messages marked as deleted, unlock the maildrop, | |
373 and close the connection." | |
374 (pop3-send-command process "QUIT") | |
375 (pop3-read-response process t) | |
376 (if process | |
377 (save-excursion | |
378 (set-buffer (process-buffer process)) | |
379 (goto-char (point-max)) | |
380 (delete-process process)))) | |
381 | |
382 ;; Summary of POP3 (Post Office Protocol version 3) commands and responses | |
383 | |
384 ;;; AUTHORIZATION STATE | |
385 | |
386 ;; Initial TCP connection | |
387 ;; Arguments: none | |
388 ;; Restrictions: none | |
389 ;; Possible responses: | |
390 ;; +OK [POP3 server ready] | |
391 | |
392 ;; USER name | |
393 ;; Arguments: a server specific user-id (required) | |
394 ;; Restrictions: authorization state [after unsuccessful USER or PASS | |
395 ;; Possible responses: | |
396 ;; +OK [valid user-id] | |
397 ;; -ERR [invalid user-id] | |
398 | |
399 ;; PASS string | |
400 ;; Arguments: a server/user-id specific password (required) | |
401 ;; Restrictions: authorization state, after successful USER | |
402 ;; Possible responses: | |
403 ;; +OK [maildrop locked and ready] | |
404 ;; -ERR [invalid password] | |
405 ;; -ERR [unable to lock maildrop] | |
406 | |
407 ;;; TRANSACTION STATE | |
408 | |
409 ;; STAT | |
410 ;; Arguments: none | |
411 ;; Restrictions: transaction state | |
412 ;; Possible responses: | |
413 ;; +OK nn mm [# of messages, size of maildrop] | |
414 | |
415 ;; LIST [msg] | |
416 ;; Arguments: a message-id (optional) | |
417 ;; Restrictions: transaction state; msg must not be deleted | |
418 ;; Possible responses: | |
419 ;; +OK [scan listing follows] | |
420 ;; -ERR [no such message] | |
421 | |
422 ;; RETR msg | |
423 ;; Arguments: a message-id (required) | |
424 ;; Restrictions: transaction state; msg must not be deleted | |
425 ;; Possible responses: | |
426 ;; +OK [message contents follow] | |
427 ;; -ERR [no such message] | |
428 | |
429 ;; DELE msg | |
430 ;; Arguments: a message-id (required) | |
431 ;; Restrictions: transaction state; msg must not be deleted | |
432 ;; Possible responses: | |
433 ;; +OK [message deleted] | |
434 ;; -ERR [no such message] | |
435 | |
436 ;; NOOP | |
437 ;; Arguments: none | |
438 ;; Restrictions: transaction state | |
439 ;; Possible responses: | |
440 ;; +OK | |
441 | |
442 ;; LAST | |
443 ;; Arguments: none | |
444 ;; Restrictions: transaction state | |
445 ;; Possible responses: | |
446 ;; +OK nn [highest numbered message accessed] | |
447 | |
448 ;; RSET | |
449 ;; Arguments: none | |
450 ;; Restrictions: transaction state | |
451 ;; Possible responses: | |
452 ;; +OK [all delete marks removed] | |
453 | |
454 ;;; UPDATE STATE | |
455 | |
456 ;; QUIT | |
457 ;; Arguments: none | |
458 ;; Restrictions: none | |
459 ;; Possible responses: | |
460 ;; +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
|
461 |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
462 (provide 'pop3) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
463 |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
464 ;;; pop3.el ends here |