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