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