Mercurial > emacs
annotate lisp/gnus/pop3.el @ 45920:e475ce899bf1
Comment corrected.
author | Francesco Potortì <pot@gnu.org> |
---|---|
date | Thu, 20 Jun 2002 10:05:11 +0000 |
parents | a5381c78296d |
children | a5038d551293 d7ddb3e565de |
rev | line source |
---|---|
17493 | 1 ;;; pop3.el --- Post Office Protocol (RFC 1460) interface |
2 | |
44541
1910e7c74f9f
* pop3.el (pop3-munge-message-separator): Work if no date.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
44452
diff
changeset
|
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002 |
31716
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 |
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 | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
40 (defvar pop3-maildrop (or (user-login-name) (getenv "LOGNAME") (getenv "USER") nil) |
17493 | 41 "*POP3 maildrop.") |
42 (defvar pop3-mailhost (or (getenv "MAILHOST") nil) | |
43 "*POP3 mailhost.") | |
44 (defvar pop3-port 110 | |
45 "*POP3 port.") | |
46 | |
47 (defvar pop3-password-required t | |
48 "*Non-nil if a password is required when connecting to POP server.") | |
49 (defvar pop3-password nil | |
50 "*Password to use when connecting to POP server.") | |
51 | |
52 (defvar pop3-authentication-scheme 'pass | |
53 "*POP3 authentication scheme. | |
54 Defaults to 'pass, for the standard USER/PASS authentication. Other valid | |
55 values are 'apop.") | |
56 | |
57 (defvar pop3-timestamp nil | |
58 "Timestamp returned when initially connected to the POP server. | |
59 Used for APOP authentication.") | |
60 | |
61 (defvar pop3-read-point nil) | |
62 (defvar pop3-debug nil) | |
63 | |
64 (defun pop3-movemail (&optional crashbox) | |
65 "Transfer contents of a maildrop to the specified CRASHBOX." | |
66 (or crashbox (setq crashbox (expand-file-name "~/.crashbox"))) | |
67 (let* ((process (pop3-open-server pop3-mailhost pop3-port)) | |
68 (crashbuf (get-buffer-create " *pop3-retr*")) | |
69 (n 1) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
70 message-count |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
71 (pop3-password pop3-password) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
72 ) |
17493 | 73 ;; for debugging only |
74 (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
|
75 ;; query for password |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
76 (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
|
77 (setq pop3-password |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
78 (pop3-read-passwd (format "Password for %s: " pop3-maildrop)))) |
17493 | 79 (cond ((equal 'apop pop3-authentication-scheme) |
80 (pop3-apop process pop3-maildrop)) | |
81 ((equal 'pass pop3-authentication-scheme) | |
82 (pop3-user process pop3-maildrop) | |
83 (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
|
84 (t (error "Invalid POP3 authentication scheme"))) |
17493 | 85 (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
|
86 (unwind-protect |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
87 (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
|
88 (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
|
89 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
|
90 (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
|
91 (save-excursion |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
92 (set-buffer crashbuf) |
34618
81ecf6fce11a
2000-12-15 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
33369
diff
changeset
|
93 (let ((coding-system-for-write 'binary)) |
26944
64597461b498
(pop3-movemail-file-coding-system): Doc fix.
Dave Love <fx@gnu.org>
parents:
26108
diff
changeset
|
94 (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
|
95 (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
|
96 (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
|
97 (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
|
98 (forward-line 50) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
99 (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
|
100 (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
|
101 (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
|
102 (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
|
103 ) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
104 (pop3-quit process)) |
17493 | 105 (kill-buffer crashbuf) |
106 ) | |
26108
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
107 t) |
17493 | 108 |
35453
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34618
diff
changeset
|
109 (defun pop3-get-message-count () |
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34618
diff
changeset
|
110 "Return the number of messages in the maildrop." |
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34618
diff
changeset
|
111 (let* ((process (pop3-open-server pop3-mailhost pop3-port)) |
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34618
diff
changeset
|
112 message-count |
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34618
diff
changeset
|
113 (pop3-password pop3-password) |
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34618
diff
changeset
|
114 ) |
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34618
diff
changeset
|
115 ;; for debugging only |
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34618
diff
changeset
|
116 (if pop3-debug (switch-to-buffer (process-buffer process))) |
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34618
diff
changeset
|
117 ;; query for password |
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34618
diff
changeset
|
118 (if (and pop3-password-required (not pop3-password)) |
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34618
diff
changeset
|
119 (setq pop3-password |
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34618
diff
changeset
|
120 (pop3-read-passwd (format "Password for %s: " pop3-maildrop)))) |
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34618
diff
changeset
|
121 (cond ((equal 'apop pop3-authentication-scheme) |
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34618
diff
changeset
|
122 (pop3-apop process pop3-maildrop)) |
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34618
diff
changeset
|
123 ((equal 'pass pop3-authentication-scheme) |
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34618
diff
changeset
|
124 (pop3-user process pop3-maildrop) |
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34618
diff
changeset
|
125 (pop3-pass process)) |
38412
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
35453
diff
changeset
|
126 (t (error "Invalid POP3 authentication scheme"))) |
35453
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34618
diff
changeset
|
127 (setq message-count (car (pop3-stat process))) |
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34618
diff
changeset
|
128 (pop3-quit process) |
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34618
diff
changeset
|
129 message-count)) |
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34618
diff
changeset
|
130 |
17493 | 131 (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
|
132 "Open TCP connection to MAILHOST on PORT. |
17493 | 133 Returns the process associated with the connection." |
28835 | 134 (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
|
135 (coding-system-for-write 'binary) |
28835 | 136 process) |
17493 | 137 (save-excursion |
28835 | 138 (set-buffer (get-buffer-create (concat " trace of POP session to " |
139 mailhost))) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
140 (erase-buffer) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
141 (setq pop3-read-point (point-min)) |
44544
a5381c78296d
(pop3-open-server): Fix typo.
Juanma Barranquero <lekktu@gmail.com>
parents:
44541
diff
changeset
|
142 (setq process (open-network-stream "POP" (current-buffer) mailhost port)) |
28835 | 143 (let ((response (pop3-read-response process t))) |
144 (setq pop3-timestamp | |
145 (substring response (or (string-match "<" response) 0) | |
146 (+ 1 (or (string-match ">" response) -1))))) | |
147 process))) | |
17493 | 148 |
149 ;; Support functions | |
150 | |
151 (defun pop3-process-filter (process output) | |
152 (save-excursion | |
153 (set-buffer (process-buffer process)) | |
154 (goto-char (point-max)) | |
155 (insert output))) | |
156 | |
157 (defun pop3-send-command (process command) | |
158 (set-buffer (process-buffer process)) | |
159 (goto-char (point-max)) | |
160 ;; (if (= (aref command 0) ?P) | |
161 ;; (insert "PASS <omitted>\r\n") | |
162 ;; (insert command "\r\n")) | |
163 (setq pop3-read-point (point)) | |
164 (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
|
165 (process-send-string process (concat command "\r\n")) |
17493 | 166 ) |
167 | |
168 (defun pop3-read-response (process &optional return) | |
169 "Read the response from the server. | |
170 Return the response string if optional second argument is non-nil." | |
171 (let ((case-fold-search nil) | |
172 match-end) | |
173 (save-excursion | |
174 (set-buffer (process-buffer process)) | |
175 (goto-char pop3-read-point) | |
176 (while (not (search-forward "\r\n" nil t)) | |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19633
diff
changeset
|
177 (accept-process-output process 3) |
17493 | 178 (goto-char pop3-read-point)) |
179 (setq match-end (point)) | |
180 (goto-char pop3-read-point) | |
181 (if (looking-at "-ERR") | |
182 (error (buffer-substring (point) (- match-end 2))) | |
183 (if (not (looking-at "+OK")) | |
184 (progn (setq pop3-read-point match-end) nil) | |
185 (setq pop3-read-point match-end) | |
186 (if return | |
187 (buffer-substring (point) match-end) | |
188 t) | |
189 ))))) | |
190 | |
191 (defvar pop3-read-passwd nil) | |
192 (defun pop3-read-passwd (prompt) | |
193 (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
|
194 (if (fboundp 'read-passwd) |
17493 | 195 (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
|
196 (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
|
197 (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
|
198 (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
|
199 (setq pop3-read-passwd 'ange-ftp-read-passwd)))) |
17493 | 200 (funcall pop3-read-passwd prompt)) |
201 | |
202 (defun pop3-clean-region (start end) | |
203 (setq end (set-marker (make-marker) end)) | |
204 (save-excursion | |
205 (goto-char start) | |
206 (while (and (< (point) end) (search-forward "\r\n" end t)) | |
207 (replace-match "\n" t t)) | |
208 (goto-char start) | |
209 (while (and (< (point) end) (re-search-forward "^\\." end t)) | |
210 (replace-match "" t t) | |
211 (forward-char))) | |
212 (set-marker end nil)) | |
213 | |
33369 | 214 (eval-when-compile (defvar parse-time-months)) |
215 | |
216 ;; Copied from message-make-date. | |
217 (defun pop3-make-date (&optional now) | |
218 "Make a valid date header. | |
219 If NOW, use that time instead." | |
220 (require 'parse-time) | |
221 (let* ((now (or now (current-time))) | |
222 (zone (nth 8 (decode-time now))) | |
223 (sign "+")) | |
224 (when (< zone 0) | |
225 (setq sign "-") | |
226 (setq zone (- zone))) | |
227 (concat | |
228 (format-time-string "%d" now) | |
229 ;; The month name of the %b spec is locale-specific. Pfff. | |
230 (format " %s " | |
231 (capitalize (car (rassoc (nth 4 (decode-time now)) | |
232 parse-time-months)))) | |
233 (format-time-string "%Y %H:%M:%S " now) | |
234 ;; We do all of this because XEmacs doesn't have the %z spec. | |
235 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60))))) | |
236 | |
17493 | 237 (defun pop3-munge-message-separator (start end) |
238 "Check to see if a message separator exists. If not, generate one." | |
239 (save-excursion | |
240 (save-restriction | |
241 (narrow-to-region start end) | |
242 (goto-char (point-min)) | |
243 (if (not (or (looking-at "From .?") ; Unix mail | |
244 (looking-at "\001\001\001\001\n") ; MMDF | |
245 (looking-at "BABYL OPTIONS:") ; Babyl | |
246 )) | |
44541
1910e7c74f9f
* pop3.el (pop3-munge-message-separator): Work if no date.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
44452
diff
changeset
|
247 (let* ((from (mail-strip-quoted-names (mail-fetch-field "From"))) |
1910e7c74f9f
* pop3.el (pop3-munge-message-separator): Work if no date.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
44452
diff
changeset
|
248 (tdate (mail-fetch-field "Date")) |
1910e7c74f9f
* pop3.el (pop3-munge-message-separator): Work if no date.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
44452
diff
changeset
|
249 (date (split-string (or (and tdate |
1910e7c74f9f
* pop3.el (pop3-munge-message-separator): Work if no date.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
44452
diff
changeset
|
250 (not (string= "" tdate)) |
1910e7c74f9f
* pop3.el (pop3-munge-message-separator): Work if no date.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
44452
diff
changeset
|
251 tdate) |
1910e7c74f9f
* pop3.el (pop3-munge-message-separator): Work if no date.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
44452
diff
changeset
|
252 (pop3-make-date)) |
1910e7c74f9f
* pop3.el (pop3-munge-message-separator): Work if no date.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
44452
diff
changeset
|
253 " ")) |
1910e7c74f9f
* pop3.el (pop3-munge-message-separator): Work if no date.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
44452
diff
changeset
|
254 (From_)) |
17493 | 255 ;; sample date formats I have seen |
256 ;; Date: Tue, 9 Jul 1996 09:04:21 -0400 (EDT) | |
257 ;; Date: 08 Jul 1996 23:22:24 -0400 | |
258 ;; should be | |
259 ;; Tue Jul 9 09:04:21 1996 | |
260 (setq date | |
44541
1910e7c74f9f
* pop3.el (pop3-munge-message-separator): Work if no date.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
44452
diff
changeset
|
261 (cond ((not date) |
1910e7c74f9f
* pop3.el (pop3-munge-message-separator): Work if no date.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
44452
diff
changeset
|
262 "Tue Jan 1 00:00:0 1900") |
1910e7c74f9f
* pop3.el (pop3-munge-message-separator): Work if no date.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
44452
diff
changeset
|
263 ((string-match "[A-Z]" (nth 0 date)) |
17493 | 264 (format "%s %s %s %s %s" |
265 (nth 0 date) (nth 2 date) (nth 1 date) | |
266 (nth 4 date) (nth 3 date))) | |
267 (t | |
268 ;; this really needs to be better but I don't feel | |
269 ;; like writing a date to day converter. | |
270 (format "Sun %s %s %s %s" | |
271 (nth 1 date) (nth 0 date) | |
272 (nth 3 date) (nth 2 date))) | |
273 )) | |
274 (setq From_ (format "\nFrom %s %s\n" from date)) | |
275 (while (string-match "," From_) | |
276 (setq From_ (concat (substring From_ 0 (match-beginning 0)) | |
277 (substring From_ (match-end 0))))) | |
278 (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
|
279 (insert From_) |
33369 | 280 (if (search-forward "\n\n" nil t) |
281 nil | |
282 (goto-char (point-max)) | |
283 (insert "\n")) | |
26108
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
284 (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
|
285 (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
|
286 (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
|
287 (widen) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
288 (forward-line -1) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
289 (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
|
290 ))))) |
17493 | 291 |
292 ;; The Command Set | |
293 | |
294 ;; AUTHORIZATION STATE | |
295 | |
296 (defun pop3-user (process user) | |
297 "Send USER information to POP3 server." | |
298 (pop3-send-command process (format "USER %s" user)) | |
299 (let ((response (pop3-read-response process t))) | |
300 (if (not (and response (string-match "+OK" response))) | |
38412
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
35453
diff
changeset
|
301 (error (format "USER %s not valid" user))))) |
17493 | 302 |
303 (defun pop3-pass (process) | |
304 "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
|
305 (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
|
306 (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
|
307 (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
|
308 (pop3-quit process)))) |
19633
25317a11d7a1
(pop3-md5): New function.
Richard M. Stallman <rms@gnu.org>
parents:
19595
diff
changeset
|
309 |
17493 | 310 (defun pop3-apop (process user) |
311 "Send alternate authentication information to the server." | |
312 (let ((pass pop3-password)) | |
313 (if (and pop3-password-required (not pass)) | |
314 (setq pass | |
315 (pop3-read-passwd (format "Password for %s: " pop3-maildrop)))) | |
316 (if pass | |
19633
25317a11d7a1
(pop3-md5): New function.
Richard M. Stallman <rms@gnu.org>
parents:
19595
diff
changeset
|
317 (let ((hash (pop3-md5 (concat pop3-timestamp pass)))) |
17493 | 318 (pop3-send-command process (format "APOP %s %s" user hash)) |
319 (let ((response (pop3-read-response process t))) | |
320 (if (not (and response (string-match "+OK" response))) | |
321 (pop3-quit process))))) | |
322 )) | |
323 | |
324 ;; TRANSACTION STATE | |
325 | |
33369 | 326 (eval-and-compile |
327 (if (fboundp 'md5) | |
328 (defalias 'pop3-md5 'md5) | |
329 (defvar pop3-md5-program "md5" | |
330 "*Program to encode its input in MD5.") | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
331 |
33369 | 332 (defun pop3-md5 (string) |
333 (with-temp-buffer | |
334 (insert string) | |
335 (call-process-region (point-min) (point-max) | |
336 pop3-md5-program | |
337 t (current-buffer) nil) | |
338 ;; The meaningful output is the first 32 characters. | |
339 ;; Don't return the newline that follows them! | |
44452
a7836a045796
(pop3-md5): Don't hardcode point-min == 1.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
340 (buffer-substring (point-min) (+ 32 (point-min))))))) |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
341 |
17493 | 342 (defun pop3-stat (process) |
343 "Return the number of messages in the maildrop and the maildrop's size." | |
344 (pop3-send-command process "STAT") | |
345 (let ((response (pop3-read-response process t))) | |
28835 | 346 (list (string-to-int (nth 1 (split-string response " "))) |
347 (string-to-int (nth 2 (split-string response " ")))) | |
17493 | 348 )) |
349 | |
350 (defun pop3-list (process &optional msg) | |
351 "Scan listing of available messages. | |
352 This function currently does nothing.") | |
353 | |
354 (defun pop3-retr (process msg crashbuf) | |
355 "Retrieve message-id MSG to buffer CRASHBUF." | |
356 (pop3-send-command process (format "RETR %s" msg)) | |
357 (pop3-read-response process) | |
358 (let ((start pop3-read-point) end) | |
359 (save-excursion | |
360 (set-buffer (process-buffer process)) | |
361 (while (not (re-search-forward "^\\.\r\n" nil t)) | |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19633
diff
changeset
|
362 (accept-process-output process 3) |
17493 | 363 ;; 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
|
364 ;; 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
|
365 ;; some. |
17493 | 366 (if (> (buffer-size) 20000) (sleep-for 1)) |
367 (if (> (buffer-size) 50000) (sleep-for 1)) | |
368 (if (> (buffer-size) 100000) (sleep-for 1)) | |
369 (if (> (buffer-size) 200000) (sleep-for 1)) | |
370 (if (> (buffer-size) 500000) (sleep-for 1)) | |
371 ;; bill@att.com | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
372 ;; condensed into: |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
373 ;; (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
|
374 ; (if (> (buffer-size) 20000) (sleep-for (/ (buffer-size) 20000))) |
17493 | 375 (goto-char start)) |
376 (setq pop3-read-point (point-marker)) | |
377 ;; this code does not seem to work for some POP servers... | |
378 ;; and I cannot figure out why not. | |
379 ; (goto-char (match-beginning 0)) | |
380 ; (backward-char 2) | |
381 ; (if (not (looking-at "\r\n")) | |
382 ; (insert "\r\n")) | |
383 ; (re-search-forward "\\.\r\n") | |
384 (goto-char (match-beginning 0)) | |
385 (setq end (point-marker)) | |
386 (pop3-clean-region start end) | |
387 (pop3-munge-message-separator start end) | |
388 (save-excursion | |
389 (set-buffer crashbuf) | |
390 (erase-buffer)) | |
391 (copy-to-buffer crashbuf start end) | |
392 (delete-region start end) | |
393 ))) | |
394 | |
395 (defun pop3-dele (process msg) | |
396 "Mark message-id MSG as deleted." | |
397 (pop3-send-command process (format "DELE %s" msg)) | |
398 (pop3-read-response process)) | |
399 | |
400 (defun pop3-noop (process msg) | |
401 "No-operation." | |
402 (pop3-send-command process "NOOP") | |
403 (pop3-read-response process)) | |
404 | |
405 (defun pop3-last (process) | |
406 "Return highest accessed message-id number for the session." | |
407 (pop3-send-command process "LAST") | |
408 (let ((response (pop3-read-response process t))) | |
28835 | 409 (string-to-int (nth 1 (split-string response " "))) |
17493 | 410 )) |
411 | |
412 (defun pop3-rset (process) | |
413 "Remove all delete marks from current maildrop." | |
414 (pop3-send-command process "RSET") | |
415 (pop3-read-response process)) | |
416 | |
417 ;; UPDATE | |
418 | |
419 (defun pop3-quit (process) | |
420 "Close connection to POP3 server. | |
421 Tell server to remove all messages marked as deleted, unlock the maildrop, | |
422 and close the connection." | |
423 (pop3-send-command process "QUIT") | |
424 (pop3-read-response process t) | |
425 (if process | |
426 (save-excursion | |
427 (set-buffer (process-buffer process)) | |
428 (goto-char (point-max)) | |
429 (delete-process process)))) | |
430 | |
431 ;; Summary of POP3 (Post Office Protocol version 3) commands and responses | |
432 | |
433 ;;; AUTHORIZATION STATE | |
434 | |
435 ;; Initial TCP connection | |
436 ;; Arguments: none | |
437 ;; Restrictions: none | |
438 ;; Possible responses: | |
439 ;; +OK [POP3 server ready] | |
440 | |
441 ;; USER name | |
442 ;; Arguments: a server specific user-id (required) | |
443 ;; Restrictions: authorization state [after unsuccessful USER or PASS | |
444 ;; Possible responses: | |
445 ;; +OK [valid user-id] | |
446 ;; -ERR [invalid user-id] | |
447 | |
448 ;; PASS string | |
449 ;; Arguments: a server/user-id specific password (required) | |
450 ;; Restrictions: authorization state, after successful USER | |
451 ;; Possible responses: | |
452 ;; +OK [maildrop locked and ready] | |
453 ;; -ERR [invalid password] | |
454 ;; -ERR [unable to lock maildrop] | |
455 | |
456 ;;; TRANSACTION STATE | |
457 | |
458 ;; STAT | |
459 ;; Arguments: none | |
460 ;; Restrictions: transaction state | |
461 ;; Possible responses: | |
462 ;; +OK nn mm [# of messages, size of maildrop] | |
463 | |
464 ;; LIST [msg] | |
465 ;; Arguments: a message-id (optional) | |
466 ;; Restrictions: transaction state; msg must not be deleted | |
467 ;; Possible responses: | |
468 ;; +OK [scan listing follows] | |
469 ;; -ERR [no such message] | |
470 | |
471 ;; RETR msg | |
472 ;; Arguments: a message-id (required) | |
473 ;; Restrictions: transaction state; msg must not be deleted | |
474 ;; Possible responses: | |
475 ;; +OK [message contents follow] | |
476 ;; -ERR [no such message] | |
477 | |
478 ;; DELE msg | |
479 ;; Arguments: a message-id (required) | |
480 ;; Restrictions: transaction state; msg must not be deleted | |
481 ;; Possible responses: | |
482 ;; +OK [message deleted] | |
483 ;; -ERR [no such message] | |
484 | |
485 ;; NOOP | |
486 ;; Arguments: none | |
487 ;; Restrictions: transaction state | |
488 ;; Possible responses: | |
489 ;; +OK | |
490 | |
491 ;; LAST | |
492 ;; Arguments: none | |
493 ;; Restrictions: transaction state | |
494 ;; Possible responses: | |
495 ;; +OK nn [highest numbered message accessed] | |
496 | |
497 ;; RSET | |
498 ;; Arguments: none | |
499 ;; Restrictions: transaction state | |
500 ;; Possible responses: | |
501 ;; +OK [all delete marks removed] | |
502 | |
503 ;;; UPDATE STATE | |
504 | |
505 ;; QUIT | |
506 ;; Arguments: none | |
507 ;; Restrictions: none | |
508 ;; Possible responses: | |
509 ;; +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
|
510 |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
511 (provide 'pop3) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
512 |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
513 ;;; pop3.el ends here |