Mercurial > emacs
annotate lisp/gnus/pop3.el @ 109088:05a72c8a402b
Fix whitespace in ChangeLogs.
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Thu, 01 Jul 2010 02:08:29 +0200 |
parents | 0fe940324254 |
children | 459fd421257a |
rev | line source |
---|---|
17493 | 1 ;;; pop3.el --- Post Office Protocol (RFC 1460) interface |
2 | |
64754
fafd692d1e40
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64085
diff
changeset
|
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, |
106815 | 4 ;; 2004, 2005, 2006, 2007, 2008, 2009, 2010 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 | |
94662
f42ef85caf91
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
12 ;; GNU Emacs is free software: you can redistribute it and/or modify |
17493 | 13 ;; it under the terms of the GNU General Public License as published by |
94662
f42ef85caf91
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
14 ;; the Free Software Foundation, either version 3 of the License, or |
f42ef85caf91
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
15 ;; (at your option) any later version. |
17493 | 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 | |
94662
f42ef85caf91
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
17493 | 24 |
25 ;;; Commentary: | |
26 | |
27 ;; Most of the standard Post Office Protocol version 3 (RFC 1460) commands | |
28 ;; are implemented. The LIST command has not been implemented due to lack | |
29 ;; of actual usefulness. | |
30 ;; The optional POP3 command TOP has not been implemented. | |
31 | |
32 ;; This program was inspired by Kyle E. Jones's vm-pop program. | |
33 | |
34 ;;; Code: | |
35 | |
36 (require 'mail-utils) | |
86154 | 37 (defvar parse-time-months) |
17493 | 38 |
57442
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
39 (defgroup pop3 nil |
63983
23c6b2acce05
(pop3): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents:
63495
diff
changeset
|
40 "Post Office Protocol." |
57442
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
41 :group 'mail |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
42 :group 'mail-source) |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
43 |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
44 (defcustom pop3-maildrop (or (user-login-name) |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
45 (getenv "LOGNAME") |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
46 (getenv "USER")) |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
47 "*POP3 maildrop." |
59996
aac0a33f5772
Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents:
58835
diff
changeset
|
48 :version "22.1" ;; Oort Gnus |
57442
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
49 :type 'string |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
50 :group 'pop3) |
17493 | 51 |
57442
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
52 (defcustom pop3-mailhost (or (getenv "MAILHOST") ;; nil -> mismatch |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
53 "pop3") |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
54 "*POP3 mailhost." |
59996
aac0a33f5772
Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents:
58835
diff
changeset
|
55 :version "22.1" ;; Oort Gnus |
57442
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
56 :type 'string |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
57 :group 'pop3) |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
58 |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
59 (defcustom pop3-port 110 |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
60 "*POP3 port." |
59996
aac0a33f5772
Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents:
58835
diff
changeset
|
61 :version "22.1" ;; Oort Gnus |
57442
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
62 :type 'number |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
63 :group 'pop3) |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
64 |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
65 (defcustom pop3-password-required t |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
66 "*Non-nil if a password is required when connecting to POP server." |
59996
aac0a33f5772
Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents:
58835
diff
changeset
|
67 :version "22.1" ;; Oort Gnus |
57442
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
68 :type 'boolean |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
69 :group 'pop3) |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
70 |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
71 ;; Should this be customizable? |
17493 | 72 (defvar pop3-password nil |
73 "*Password to use when connecting to POP server.") | |
74 | |
57442
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
75 (defcustom pop3-authentication-scheme 'pass |
17493 | 76 "*POP3 authentication scheme. |
73269 | 77 Defaults to `pass', for the standard USER/PASS authentication. The other |
78 valid value is 'apop'." | |
79 :type '(choice (const :tag "Normal user/password" pass) | |
80 (const :tag "APOP" apop)) | |
59996
aac0a33f5772
Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents:
58835
diff
changeset
|
81 :version "22.1" ;; Oort Gnus |
57442
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
82 :group 'pop3) |
17493 | 83 |
57442
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
84 (defcustom pop3-leave-mail-on-server nil |
57561
505c55fe8dc9
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
85 "*Non-nil if the mail is to be left on the POP server after fetching. |
505c55fe8dc9
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
86 |
73269 | 87 If `pop3-leave-mail-on-server' is non-nil the mail is to be left |
88 on the POP server after fetching. Note that POP servers maintain | |
89 no state information between sessions, so what the client | |
90 believes is there and what is actually there may not match up. | |
91 If they do not, then you may get duplicate mails or the whole | |
92 thing can fall apart and leave you with a corrupt mailbox." | |
72810 | 93 ;; We can't use the UILD support from XEmacs mail-lib or cvs.m17n.org: |
94 ;; http://thread.gmane.org/v9lld8fml4.fsf@marauder.physik.uni-ulm.de | |
95 ;; http://thread.gmane.org/b9yy8hzy9ej.fsf@jpl.org | |
96 ;; Any volunteer to re-implement this? | |
59996
aac0a33f5772
Change release version from 21.4 to 22.1 throughout.
Kim F. Storm <storm@cua.dk>
parents:
58835
diff
changeset
|
97 :version "22.1" ;; Oort Gnus |
57442
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
98 :type 'boolean |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
99 :group 'pop3) |
51546
a5038d551293
(pop3-leave-mail-on-server): New user variable.
Sam Steingold <sds@gnu.org>
parents:
44544
diff
changeset
|
100 |
107473 | 101 (defcustom pop3-display-message-size-flag t |
102 "*If non-nil, display the size of the message that is being fetched." | |
103 :version "22.1" ;; Oort Gnus | |
104 :type 'boolean | |
105 :group 'pop3) | |
106 | |
17493 | 107 (defvar pop3-timestamp nil |
108 "Timestamp returned when initially connected to the POP server. | |
109 Used for APOP authentication.") | |
110 | |
111 (defvar pop3-read-point nil) | |
112 (defvar pop3-debug nil) | |
113 | |
100993 | 114 ;; Borrowed from nnheader-accept-process-output in nnheader.el. See the |
115 ;; comments there for explanations about the values. | |
116 | |
117 (eval-and-compile | |
118 (if (and (fboundp 'nnheader-accept-process-output) | |
119 (boundp 'nnheader-read-timeout)) | |
120 (defalias 'pop3-accept-process-output 'nnheader-accept-process-output) | |
121 ;; Borrowed from `nnheader.el': | |
122 (defvar pop3-read-timeout | |
123 (if (string-match "windows-nt\\|os/2\\|emx\\|cygwin" | |
124 (symbol-name system-type)) | |
125 1.0 | |
126 0.01) | |
127 "How long pop3 should wait between checking for the end of output. | |
57561
505c55fe8dc9
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
128 Shorter values mean quicker response, but are more CPU intensive.") |
100993 | 129 (defun pop3-accept-process-output (process) |
130 (accept-process-output | |
131 process | |
132 (truncate pop3-read-timeout) | |
133 (truncate (* (- pop3-read-timeout | |
134 (truncate pop3-read-timeout)) | |
135 1000)))))) | |
95491
32ac518a1ca9
(nnheader-accept-process-output): Autoload it.
Glenn Morris <rgm@gnu.org>
parents:
95193
diff
changeset
|
136 |
17493 | 137 (defun pop3-movemail (&optional crashbox) |
138 "Transfer contents of a maildrop to the specified CRASHBOX." | |
139 (or crashbox (setq crashbox (expand-file-name "~/.crashbox"))) | |
140 (let* ((process (pop3-open-server pop3-mailhost pop3-port)) | |
141 (crashbuf (get-buffer-create " *pop3-retr*")) | |
142 (n 1) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
143 message-count |
107473 | 144 message-sizes |
57442
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
145 (pop3-password pop3-password)) |
17493 | 146 ;; for debugging only |
147 (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
|
148 ;; query for password |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
149 (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
|
150 (setq pop3-password |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
151 (read-passwd (format "Password for %s: " pop3-maildrop)))) |
17493 | 152 (cond ((equal 'apop pop3-authentication-scheme) |
153 (pop3-apop process pop3-maildrop)) | |
154 ((equal 'pass pop3-authentication-scheme) | |
155 (pop3-user process pop3-maildrop) | |
156 (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
|
157 (t (error "Invalid POP3 authentication scheme"))) |
17493 | 158 (setq message-count (car (pop3-stat process))) |
107473 | 159 (when (and pop3-display-message-size-flag |
160 (> message-count 0)) | |
161 (setq message-sizes (pop3-list process))) | |
26108
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
162 (unwind-protect |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
163 (while (<= n message-count) |
107473 | 164 (if pop3-display-message-size-flag |
165 (message "Retrieving message %d of %d from %s... (%.1fk)" | |
166 n message-count pop3-mailhost | |
167 (/ (cdr (assoc n message-sizes)) | |
168 1024.0)) | |
169 (message "Retrieving message %d of %d from %s..." | |
170 n message-count pop3-mailhost)) | |
26108
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
171 (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
|
172 (save-excursion |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
173 (set-buffer crashbuf) |
34618
81ecf6fce11a
2000-12-15 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
33369
diff
changeset
|
174 (let ((coding-system-for-write 'binary)) |
26944
64597461b498
(pop3-movemail-file-coding-system): Doc fix.
Dave Love <fx@gnu.org>
parents:
26108
diff
changeset
|
175 (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
|
176 (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
|
177 (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
|
178 (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
|
179 (forward-line 50) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
180 (delete-region (point-min) (point)))) |
51546
a5038d551293
(pop3-leave-mail-on-server): New user variable.
Sam Steingold <sds@gnu.org>
parents:
44544
diff
changeset
|
181 (unless pop3-leave-mail-on-server |
a5038d551293
(pop3-leave-mail-on-server): New user variable.
Sam Steingold <sds@gnu.org>
parents:
44544
diff
changeset
|
182 (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
|
183 (setq n (+ 1 n)) |
100993 | 184 (pop3-accept-process-output process)) |
73269 | 185 (when (and pop3-leave-mail-on-server |
186 (> n 1)) | |
187 (message "pop3.el doesn't support UIDL. Setting `pop3-leave-mail-on-server' | |
188 to %s might not give the result you'd expect." pop3-leave-mail-on-server) | |
189 (sit-for 1)) | |
26108
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
190 (pop3-quit process)) |
73269 | 191 (kill-buffer crashbuf)) |
26108
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
192 t) |
17493 | 193 |
35453
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34618
diff
changeset
|
194 (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
|
195 "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
|
196 (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
|
197 message-count |
57442
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
198 (pop3-password pop3-password)) |
35453
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34618
diff
changeset
|
199 ;; for debugging only |
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34618
diff
changeset
|
200 (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
|
201 ;; query for password |
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34618
diff
changeset
|
202 (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
|
203 (setq pop3-password |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
204 (read-passwd (format "Password for %s: " pop3-maildrop)))) |
35453
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34618
diff
changeset
|
205 (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
|
206 (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
|
207 ((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
|
208 (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
|
209 (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
|
210 (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
|
211 (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
|
212 (pop3-quit process) |
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34618
diff
changeset
|
213 message-count)) |
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34618
diff
changeset
|
214 |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
215 (autoload 'open-tls-stream "tls") |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
216 (autoload 'starttls-open-stream "starttls") |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
217 (autoload 'starttls-negotiate "starttls") ; avoid warning |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
218 |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
219 (defcustom pop3-stream-type nil |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
220 "*Transport security type for POP3 connexions. |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
221 This may be either nil (plain connexion), `ssl' (use an |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
222 SSL/TSL-secured stream) or `starttls' (use the starttls mechanism |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
223 to turn on TLS security after opening the stream). However, if |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
224 this is nil, `ssl' is assumed for connexions to port |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
225 995 (pop3s)." |
92336
5f827896103e
Change defcustom :version from 23.0 to 23.1.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
226 :version "23.1" ;; No Gnus |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
227 :group 'pop3 |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
228 :type '(choice (const :tag "Plain" nil) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
229 (const :tag "SSL/TLS" ssl) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
230 (const starttls))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
231 |
17493 | 232 (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
|
233 "Open TCP connection to MAILHOST on PORT. |
17493 | 234 Returns the process associated with the connection." |
28835 | 235 (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
|
236 (coding-system-for-write 'binary) |
28835 | 237 process) |
17493 | 238 (save-excursion |
28835 | 239 (set-buffer (get-buffer-create (concat " trace of POP session to " |
240 mailhost))) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
241 (erase-buffer) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
242 (setq pop3-read-point (point-min)) |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
243 (setq process |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
244 (cond |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
245 ((or (eq pop3-stream-type 'ssl) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
246 (and (not pop3-stream-type) (member port '(995 "pop3s")))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
247 ;; gnutls-cli, openssl don't accept service names |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
248 (if (or (equal port "pop3s") |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
249 (null port)) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
250 (setq port 995)) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
251 (let ((process (open-tls-stream "POP" (current-buffer) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
252 mailhost port))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
253 (when process |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
254 ;; There's a load of info printed that needs deleting. |
86225 | 255 (let ((again 't)) |
256 ;; repeat until | |
257 ;; - either we received the +OK line | |
258 ;; - or accept-process-output timed out without getting | |
259 ;; anything | |
260 (while (and again | |
261 (setq again (memq (process-status process) | |
262 '(open run)))) | |
263 (setq again (pop3-accept-process-output process)) | |
264 (goto-char (point-max)) | |
265 (forward-line -1) | |
266 (cond ((looking-at "\\+OK") | |
267 (setq again nil) | |
268 (delete-region (point-min) (point))) | |
269 ((not again) | |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
270 (pop3-quit process) |
86225 | 271 (error "POP SSL connexion failed"))))) |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
272 process))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
273 ((eq pop3-stream-type 'starttls) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
274 ;; gnutls-cli, openssl don't accept service names |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
275 (if (equal port "pop3") |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
276 (setq port 110)) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
277 (let ((process (starttls-open-stream "POP" (current-buffer) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
278 mailhost (or port 110)))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
279 (pop3-send-command process "STLS") |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
280 (let ((response (pop3-read-response process t))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
281 (if (and response (string-match "+OK" response)) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
282 (starttls-negotiate process) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
283 (pop3-quit process) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
284 (error "POP server doesn't support starttls"))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
285 process)) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
286 (t |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
287 (open-network-stream "POP" (current-buffer) mailhost port)))) |
28835 | 288 (let ((response (pop3-read-response process t))) |
289 (setq pop3-timestamp | |
290 (substring response (or (string-match "<" response) 0) | |
291 (+ 1 (or (string-match ">" response) -1))))) | |
292 process))) | |
17493 | 293 |
294 ;; Support functions | |
295 | |
296 (defun pop3-process-filter (process output) | |
297 (save-excursion | |
298 (set-buffer (process-buffer process)) | |
299 (goto-char (point-max)) | |
300 (insert output))) | |
301 | |
302 (defun pop3-send-command (process command) | |
57442
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
303 (set-buffer (process-buffer process)) |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
304 (goto-char (point-max)) |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
305 ;; (if (= (aref command 0) ?P) |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
306 ;; (insert "PASS <omitted>\r\n") |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
307 ;; (insert command "\r\n")) |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
308 (setq pop3-read-point (point)) |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
309 (goto-char (point-max)) |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
310 (process-send-string process (concat command "\r\n"))) |
17493 | 311 |
312 (defun pop3-read-response (process &optional return) | |
313 "Read the response from the server. | |
314 Return the response string if optional second argument is non-nil." | |
315 (let ((case-fold-search nil) | |
316 match-end) | |
317 (save-excursion | |
318 (set-buffer (process-buffer process)) | |
319 (goto-char pop3-read-point) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
320 (while (and (memq (process-status process) '(open run)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
321 (not (search-forward "\r\n" nil t))) |
57561
505c55fe8dc9
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
322 (pop3-accept-process-output process) |
17493 | 323 (goto-char pop3-read-point)) |
324 (setq match-end (point)) | |
325 (goto-char pop3-read-point) | |
326 (if (looking-at "-ERR") | |
87140
9c91533a901a
Fix buggy calls to `error'.
Deepak Goel <deego@gnufans.org>
parents:
86225
diff
changeset
|
327 (error "%s" (buffer-substring (point) (- match-end 2))) |
17493 | 328 (if (not (looking-at "+OK")) |
329 (progn (setq pop3-read-point match-end) nil) | |
330 (setq pop3-read-point match-end) | |
331 (if return | |
332 (buffer-substring (point) match-end) | |
333 t) | |
334 ))))) | |
335 | |
336 (defun pop3-clean-region (start end) | |
337 (setq end (set-marker (make-marker) end)) | |
338 (save-excursion | |
339 (goto-char start) | |
340 (while (and (< (point) end) (search-forward "\r\n" end t)) | |
341 (replace-match "\n" t t)) | |
342 (goto-char start) | |
343 (while (and (< (point) end) (re-search-forward "^\\." end t)) | |
344 (replace-match "" t t) | |
345 (forward-char))) | |
346 (set-marker end nil)) | |
347 | |
33369 | 348 ;; Copied from message-make-date. |
349 (defun pop3-make-date (&optional now) | |
350 "Make a valid date header. | |
351 If NOW, use that time instead." | |
352 (require 'parse-time) | |
353 (let* ((now (or now (current-time))) | |
354 (zone (nth 8 (decode-time now))) | |
355 (sign "+")) | |
356 (when (< zone 0) | |
357 (setq sign "-") | |
358 (setq zone (- zone))) | |
359 (concat | |
360 (format-time-string "%d" now) | |
361 ;; The month name of the %b spec is locale-specific. Pfff. | |
362 (format " %s " | |
363 (capitalize (car (rassoc (nth 4 (decode-time now)) | |
364 parse-time-months)))) | |
365 (format-time-string "%Y %H:%M:%S " now) | |
366 ;; We do all of this because XEmacs doesn't have the %z spec. | |
367 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60))))) | |
368 | |
17493 | 369 (defun pop3-munge-message-separator (start end) |
370 "Check to see if a message separator exists. If not, generate one." | |
371 (save-excursion | |
372 (save-restriction | |
373 (narrow-to-region start end) | |
374 (goto-char (point-min)) | |
375 (if (not (or (looking-at "From .?") ; Unix mail | |
376 (looking-at "\001\001\001\001\n") ; MMDF | |
377 (looking-at "BABYL OPTIONS:") ; Babyl | |
378 )) | |
44541
1910e7c74f9f
* pop3.el (pop3-munge-message-separator): Work if no date.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
44452
diff
changeset
|
379 (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
|
380 (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
|
381 (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
|
382 (not (string= "" tdate)) |
1910e7c74f9f
* pop3.el (pop3-munge-message-separator): Work if no date.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
44452
diff
changeset
|
383 tdate) |
1910e7c74f9f
* pop3.el (pop3-munge-message-separator): Work if no date.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
44452
diff
changeset
|
384 (pop3-make-date)) |
1910e7c74f9f
* pop3.el (pop3-munge-message-separator): Work if no date.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
44452
diff
changeset
|
385 " ")) |
1910e7c74f9f
* pop3.el (pop3-munge-message-separator): Work if no date.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
44452
diff
changeset
|
386 (From_)) |
17493 | 387 ;; sample date formats I have seen |
388 ;; Date: Tue, 9 Jul 1996 09:04:21 -0400 (EDT) | |
389 ;; Date: 08 Jul 1996 23:22:24 -0400 | |
390 ;; should be | |
391 ;; Tue Jul 9 09:04:21 1996 | |
73269 | 392 |
393 ;; Fixme: This should use timezone on the date field contents. | |
17493 | 394 (setq date |
44541
1910e7c74f9f
* pop3.el (pop3-munge-message-separator): Work if no date.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
44452
diff
changeset
|
395 (cond ((not date) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
396 "Tue Jan 1 00:00:0 1900") |
44541
1910e7c74f9f
* pop3.el (pop3-munge-message-separator): Work if no date.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
44452
diff
changeset
|
397 ((string-match "[A-Z]" (nth 0 date)) |
17493 | 398 (format "%s %s %s %s %s" |
399 (nth 0 date) (nth 2 date) (nth 1 date) | |
400 (nth 4 date) (nth 3 date))) | |
401 (t | |
402 ;; this really needs to be better but I don't feel | |
403 ;; like writing a date to day converter. | |
404 (format "Sun %s %s %s %s" | |
405 (nth 1 date) (nth 0 date) | |
406 (nth 3 date) (nth 2 date))) | |
407 )) | |
408 (setq From_ (format "\nFrom %s %s\n" from date)) | |
409 (while (string-match "," From_) | |
410 (setq From_ (concat (substring From_ 0 (match-beginning 0)) | |
411 (substring From_ (match-end 0))))) | |
412 (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
|
413 (insert From_) |
33369 | 414 (if (search-forward "\n\n" nil t) |
415 nil | |
416 (goto-char (point-max)) | |
417 (insert "\n")) | |
26108
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
418 (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
|
419 (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
|
420 (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
|
421 (widen) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
422 (forward-line -1) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
423 (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
|
424 ))))) |
17493 | 425 |
426 ;; The Command Set | |
427 | |
428 ;; AUTHORIZATION STATE | |
429 | |
430 (defun pop3-user (process user) | |
431 "Send USER information to POP3 server." | |
432 (pop3-send-command process (format "USER %s" user)) | |
433 (let ((response (pop3-read-response process t))) | |
434 (if (not (and response (string-match "+OK" response))) | |
63495
91a6c1b5b3c4
(pop3-user): Don't use `format' on `error' arguments.
Juanma Barranquero <lekktu@gmail.com>
parents:
62960
diff
changeset
|
435 (error "USER %s not valid" user)))) |
17493 | 436 |
437 (defun pop3-pass (process) | |
438 "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
|
439 (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
|
440 (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
|
441 (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
|
442 (pop3-quit process)))) |
19633
25317a11d7a1
(pop3-md5): New function.
Richard M. Stallman <rms@gnu.org>
parents:
19595
diff
changeset
|
443 |
17493 | 444 (defun pop3-apop (process user) |
445 "Send alternate authentication information to the server." | |
446 (let ((pass pop3-password)) | |
447 (if (and pop3-password-required (not pass)) | |
448 (setq pass | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
449 (read-passwd (format "Password for %s: " pop3-maildrop)))) |
17493 | 450 (if pass |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
451 (let ((hash (md5 (concat pop3-timestamp pass) nil nil 'binary))) |
17493 | 452 (pop3-send-command process (format "APOP %s %s" user hash)) |
453 (let ((response (pop3-read-response process t))) | |
454 (if (not (and response (string-match "+OK" response))) | |
455 (pop3-quit process))))) | |
456 )) | |
457 | |
458 ;; TRANSACTION STATE | |
459 | |
460 (defun pop3-stat (process) | |
461 "Return the number of messages in the maildrop and the maildrop's size." | |
462 (pop3-send-command process "STAT") | |
463 (let ((response (pop3-read-response process t))) | |
62907
88db2adda4b7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-339
Miles Bader <miles@gnu.org>
parents:
59996
diff
changeset
|
464 (list (string-to-number (nth 1 (split-string response " "))) |
88db2adda4b7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-339
Miles Bader <miles@gnu.org>
parents:
59996
diff
changeset
|
465 (string-to-number (nth 2 (split-string response " ")))) |
17493 | 466 )) |
467 | |
468 (defun pop3-list (process &optional msg) | |
107473 | 469 "If MSG is nil, return an alist of (MESSAGE-ID . SIZE) pairs. |
470 Otherwise, return the size of the message-id MSG" | |
471 (pop3-send-command process (if msg | |
472 (format "LIST %d" msg) | |
473 "LIST")) | |
474 (let ((response (pop3-read-response process t))) | |
475 (if msg | |
476 (string-to-number (nth 2 (split-string response " "))) | |
477 (let ((start pop3-read-point) end) | |
478 (save-excursion | |
479 (set-buffer (process-buffer process)) | |
480 (while (not (re-search-forward "^\\.\r\n" nil t)) | |
481 (pop3-accept-process-output process) | |
482 (goto-char start)) | |
483 (setq pop3-read-point (point-marker)) | |
484 (goto-char (match-beginning 0)) | |
485 (setq end (point-marker)) | |
486 (mapcar #'(lambda (s) (let ((split (split-string s " "))) | |
487 (cons (string-to-number (nth 0 split)) | |
488 (string-to-number (nth 1 split))))) | |
489 (delete "" (split-string (buffer-substring start end) | |
490 "\r\n")))))))) | |
17493 | 491 |
492 (defun pop3-retr (process msg crashbuf) | |
493 "Retrieve message-id MSG to buffer CRASHBUF." | |
494 (pop3-send-command process (format "RETR %s" msg)) | |
495 (pop3-read-response process) | |
496 (let ((start pop3-read-point) end) | |
497 (save-excursion | |
498 (set-buffer (process-buffer process)) | |
499 (while (not (re-search-forward "^\\.\r\n" nil t)) | |
57561
505c55fe8dc9
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
500 (pop3-accept-process-output process) |
17493 | 501 (goto-char start)) |
502 (setq pop3-read-point (point-marker)) | |
57442
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
503 ;; this code does not seem to work for some POP servers... |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
504 ;; and I cannot figure out why not. |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
505 ;; (goto-char (match-beginning 0)) |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
506 ;; (backward-char 2) |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
507 ;; (if (not (looking-at "\r\n")) |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
508 ;; (insert "\r\n")) |
2d9a1d1ac73d
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-610
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
509 ;; (re-search-forward "\\.\r\n") |
17493 | 510 (goto-char (match-beginning 0)) |
511 (setq end (point-marker)) | |
512 (pop3-clean-region start end) | |
513 (pop3-munge-message-separator start end) | |
514 (save-excursion | |
515 (set-buffer crashbuf) | |
516 (erase-buffer)) | |
517 (copy-to-buffer crashbuf start end) | |
518 (delete-region start end) | |
519 ))) | |
520 | |
521 (defun pop3-dele (process msg) | |
522 "Mark message-id MSG as deleted." | |
523 (pop3-send-command process (format "DELE %s" msg)) | |
524 (pop3-read-response process)) | |
525 | |
526 (defun pop3-noop (process msg) | |
527 "No-operation." | |
528 (pop3-send-command process "NOOP") | |
529 (pop3-read-response process)) | |
530 | |
531 (defun pop3-last (process) | |
532 "Return highest accessed message-id number for the session." | |
533 (pop3-send-command process "LAST") | |
534 (let ((response (pop3-read-response process t))) | |
62907
88db2adda4b7
Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-339
Miles Bader <miles@gnu.org>
parents:
59996
diff
changeset
|
535 (string-to-number (nth 1 (split-string response " "))) |
17493 | 536 )) |
537 | |
538 (defun pop3-rset (process) | |
539 "Remove all delete marks from current maildrop." | |
540 (pop3-send-command process "RSET") | |
541 (pop3-read-response process)) | |
542 | |
543 ;; UPDATE | |
544 | |
545 (defun pop3-quit (process) | |
546 "Close connection to POP3 server. | |
547 Tell server to remove all messages marked as deleted, unlock the maildrop, | |
548 and close the connection." | |
549 (pop3-send-command process "QUIT") | |
550 (pop3-read-response process t) | |
551 (if process | |
552 (save-excursion | |
553 (set-buffer (process-buffer process)) | |
554 (goto-char (point-max)) | |
555 (delete-process process)))) | |
556 | |
557 ;; Summary of POP3 (Post Office Protocol version 3) commands and responses | |
558 | |
559 ;;; AUTHORIZATION STATE | |
560 | |
561 ;; Initial TCP connection | |
562 ;; Arguments: none | |
563 ;; Restrictions: none | |
564 ;; Possible responses: | |
565 ;; +OK [POP3 server ready] | |
566 | |
567 ;; USER name | |
568 ;; Arguments: a server specific user-id (required) | |
569 ;; Restrictions: authorization state [after unsuccessful USER or PASS | |
570 ;; Possible responses: | |
571 ;; +OK [valid user-id] | |
572 ;; -ERR [invalid user-id] | |
573 | |
574 ;; PASS string | |
575 ;; Arguments: a server/user-id specific password (required) | |
576 ;; Restrictions: authorization state, after successful USER | |
577 ;; Possible responses: | |
578 ;; +OK [maildrop locked and ready] | |
579 ;; -ERR [invalid password] | |
580 ;; -ERR [unable to lock maildrop] | |
581 | |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
582 ;; STLS (RFC 2595) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
583 ;; Arguments: none |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
584 ;; Restrictions: Only permitted in AUTHORIZATION state. |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
585 ;; Possible responses: |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
586 ;; +OK |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
587 ;; -ERR |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
588 |
17493 | 589 ;;; TRANSACTION STATE |
590 | |
591 ;; STAT | |
592 ;; Arguments: none | |
593 ;; Restrictions: transaction state | |
594 ;; Possible responses: | |
595 ;; +OK nn mm [# of messages, size of maildrop] | |
596 | |
597 ;; LIST [msg] | |
598 ;; Arguments: a message-id (optional) | |
599 ;; Restrictions: transaction state; msg must not be deleted | |
600 ;; Possible responses: | |
601 ;; +OK [scan listing follows] | |
602 ;; -ERR [no such message] | |
603 | |
604 ;; RETR msg | |
605 ;; Arguments: a message-id (required) | |
606 ;; Restrictions: transaction state; msg must not be deleted | |
607 ;; Possible responses: | |
608 ;; +OK [message contents follow] | |
609 ;; -ERR [no such message] | |
610 | |
611 ;; DELE msg | |
612 ;; Arguments: a message-id (required) | |
613 ;; Restrictions: transaction state; msg must not be deleted | |
614 ;; Possible responses: | |
615 ;; +OK [message deleted] | |
616 ;; -ERR [no such message] | |
617 | |
618 ;; NOOP | |
619 ;; Arguments: none | |
620 ;; Restrictions: transaction state | |
621 ;; Possible responses: | |
622 ;; +OK | |
623 | |
624 ;; LAST | |
625 ;; Arguments: none | |
626 ;; Restrictions: transaction state | |
627 ;; Possible responses: | |
628 ;; +OK nn [highest numbered message accessed] | |
629 | |
630 ;; RSET | |
631 ;; Arguments: none | |
632 ;; Restrictions: transaction state | |
633 ;; Possible responses: | |
634 ;; +OK [all delete marks removed] | |
635 | |
636 ;;; UPDATE STATE | |
637 | |
638 ;; QUIT | |
639 ;; Arguments: none | |
640 ;; Restrictions: none | |
641 ;; Possible responses: | |
642 ;; +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
|
643 |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
644 (provide 'pop3) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
645 |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92336
diff
changeset
|
646 ;; 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
|
647 ;;; pop3.el ends here |