Mercurial > emacs
annotate lisp/gnus/pop3.el @ 94946:6009a07ef854
(fonts_changed_p): Comment improved.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Wed, 14 May 2008 01:47:59 +0000 |
parents | f42ef85caf91 |
children | d90ff358ee27 |
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, |
79708 | 4 ;; 2004, 2005, 2006, 2007, 2008 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 |
17493 | 101 (defvar pop3-timestamp nil |
102 "Timestamp returned when initially connected to the POP server. | |
103 Used for APOP authentication.") | |
104 | |
105 (defvar pop3-read-point nil) | |
106 (defvar pop3-debug nil) | |
107 | |
57561
505c55fe8dc9
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
108 ;; Borrowed from nnheader-accept-process-output in nnheader.el. |
505c55fe8dc9
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
109 (defvar pop3-read-timeout |
505c55fe8dc9
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
110 (if (string-match "windows-nt\\|os/2\\|emx\\|cygwin" |
505c55fe8dc9
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
111 (symbol-name system-type)) |
505c55fe8dc9
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
112 ;; http://thread.gmane.org/v9655t3pjo.fsf@marauder.physik.uni-ulm.de |
505c55fe8dc9
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
113 ;; |
505c55fe8dc9
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
114 ;; IIRC, values lower than 1.0 didn't/don't work on Windows/DOS. |
505c55fe8dc9
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
115 ;; |
505c55fe8dc9
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
116 ;; There should probably be a runtime test to determine the timing |
505c55fe8dc9
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
117 ;; resolution, or a primitive to report it. I don't know off-hand |
505c55fe8dc9
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
118 ;; what's possible. Perhaps better, maybe the Windows/DOS primitive |
505c55fe8dc9
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
119 ;; could round up non-zero timeouts to a minimum of 1.0? |
505c55fe8dc9
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
120 1.0 |
505c55fe8dc9
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
121 0.1) |
505c55fe8dc9
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
122 "How long pop3 should wait between checking for the end of output. |
505c55fe8dc9
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
123 Shorter values mean quicker response, but are more CPU intensive.") |
505c55fe8dc9
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
124 |
505c55fe8dc9
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
125 ;; Borrowed from nnheader-accept-process-output in nnheader.el. |
505c55fe8dc9
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
126 (defun pop3-accept-process-output (process) |
505c55fe8dc9
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
127 (accept-process-output |
505c55fe8dc9
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
128 process |
505c55fe8dc9
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
129 (truncate pop3-read-timeout) |
505c55fe8dc9
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
130 (truncate (* (- pop3-read-timeout |
505c55fe8dc9
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
131 (truncate pop3-read-timeout)) |
505c55fe8dc9
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
132 1000)))) |
505c55fe8dc9
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-621
Miles Bader <miles@gnu.org>
parents:
57442
diff
changeset
|
133 |
17493 | 134 (defun pop3-movemail (&optional crashbox) |
135 "Transfer contents of a maildrop to the specified CRASHBOX." | |
136 (or crashbox (setq crashbox (expand-file-name "~/.crashbox"))) | |
137 (let* ((process (pop3-open-server pop3-mailhost pop3-port)) | |
138 (crashbuf (get-buffer-create " *pop3-retr*")) | |
139 (n 1) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
140 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
|
141 (pop3-password pop3-password)) |
17493 | 142 ;; for debugging only |
143 (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
|
144 ;; query for password |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
145 (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
|
146 (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
|
147 (read-passwd (format "Password for %s: " pop3-maildrop)))) |
17493 | 148 (cond ((equal 'apop pop3-authentication-scheme) |
149 (pop3-apop process pop3-maildrop)) | |
150 ((equal 'pass pop3-authentication-scheme) | |
151 (pop3-user process pop3-maildrop) | |
152 (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
|
153 (t (error "Invalid POP3 authentication scheme"))) |
17493 | 154 (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
|
155 (unwind-protect |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
156 (while (<= n message-count) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
157 (message "Retrieving message %d of %d from %s..." |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
158 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
|
159 (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
|
160 (save-excursion |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
161 (set-buffer crashbuf) |
34618
81ecf6fce11a
2000-12-15 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
33369
diff
changeset
|
162 (let ((coding-system-for-write 'binary)) |
26944
64597461b498
(pop3-movemail-file-coding-system): Doc fix.
Dave Love <fx@gnu.org>
parents:
26108
diff
changeset
|
163 (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
|
164 (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
|
165 (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
|
166 (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
|
167 (forward-line 50) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
168 (delete-region (point-min) (point)))) |
51546
a5038d551293
(pop3-leave-mail-on-server): New user variable.
Sam Steingold <sds@gnu.org>
parents:
44544
diff
changeset
|
169 (unless pop3-leave-mail-on-server |
a5038d551293
(pop3-leave-mail-on-server): New user variable.
Sam Steingold <sds@gnu.org>
parents:
44544
diff
changeset
|
170 (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
|
171 (setq n (+ 1 n)) |
73269 | 172 (if pop3-debug (sit-for 1) (sit-for 0.1))) ; why? |
173 (when (and pop3-leave-mail-on-server | |
174 (> n 1)) | |
175 (message "pop3.el doesn't support UIDL. Setting `pop3-leave-mail-on-server' | |
176 to %s might not give the result you'd expect." pop3-leave-mail-on-server) | |
177 (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
|
178 (pop3-quit process)) |
73269 | 179 (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
|
180 t) |
17493 | 181 |
35453
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34618
diff
changeset
|
182 (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
|
183 "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
|
184 (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
|
185 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
|
186 (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
|
187 ;; for debugging only |
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34618
diff
changeset
|
188 (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
|
189 ;; query for password |
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34618
diff
changeset
|
190 (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
|
191 (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
|
192 (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
|
193 (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
|
194 (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
|
195 ((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
|
196 (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
|
197 (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
|
198 (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
|
199 (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
|
200 (pop3-quit process) |
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34618
diff
changeset
|
201 message-count)) |
26726eff41ca
2001-01-21 ShengHuo ZHU <zsh@cs.rochester.edu>
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
34618
diff
changeset
|
202 |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
203 (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
|
204 (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
|
205 (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
|
206 |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
207 (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
|
208 "*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
|
209 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
|
210 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
|
211 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
|
212 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
|
213 995 (pop3s)." |
92336
5f827896103e
Change defcustom :version from 23.0 to 23.1.
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
214 :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
|
215 :group 'pop3 |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
216 :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
|
217 (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
|
218 (const starttls))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
219 |
17493 | 220 (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
|
221 "Open TCP connection to MAILHOST on PORT. |
17493 | 222 Returns the process associated with the connection." |
28835 | 223 (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
|
224 (coding-system-for-write 'binary) |
28835 | 225 process) |
17493 | 226 (save-excursion |
28835 | 227 (set-buffer (get-buffer-create (concat " trace of POP session to " |
228 mailhost))) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
229 (erase-buffer) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
23435
diff
changeset
|
230 (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
|
231 (setq process |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
232 (cond |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
233 ((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
|
234 (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
|
235 ;; 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
|
236 (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
|
237 (null port)) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
238 (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
|
239 (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
|
240 mailhost port))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
241 (when process |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
242 ;; There's a load of info printed that needs deleting. |
86225 | 243 (let ((again 't)) |
244 ;; repeat until | |
245 ;; - either we received the +OK line | |
246 ;; - or accept-process-output timed out without getting | |
247 ;; anything | |
248 (while (and again | |
249 (setq again (memq (process-status process) | |
250 '(open run)))) | |
251 (setq again (pop3-accept-process-output process)) | |
252 (goto-char (point-max)) | |
253 (forward-line -1) | |
254 (cond ((looking-at "\\+OK") | |
255 (setq again nil) | |
256 (delete-region (point-min) (point))) | |
257 ((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
|
258 (pop3-quit process) |
86225 | 259 (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
|
260 process))) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
261 ((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
|
262 ;; 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
|
263 (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
|
264 (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
|
265 (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
|
266 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
|
267 (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
|
268 (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
|
269 (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
|
270 (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
|
271 (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
|
272 (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
|
273 process)) |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
274 (t |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
275 (open-network-stream "POP" (current-buffer) mailhost port)))) |
28835 | 276 (let ((response (pop3-read-response process t))) |
277 (setq pop3-timestamp | |
278 (substring response (or (string-match "<" response) 0) | |
279 (+ 1 (or (string-match ">" response) -1))))) | |
280 process))) | |
17493 | 281 |
282 ;; Support functions | |
283 | |
284 (defun pop3-process-filter (process output) | |
285 (save-excursion | |
286 (set-buffer (process-buffer process)) | |
287 (goto-char (point-max)) | |
288 (insert output))) | |
289 | |
290 (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
|
291 (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
|
292 (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
|
293 ;; (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
|
294 ;; (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
|
295 ;; (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
|
296 (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
|
297 (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
|
298 (process-send-string process (concat command "\r\n"))) |
17493 | 299 |
300 (defun pop3-read-response (process &optional return) | |
301 "Read the response from the server. | |
302 Return the response string if optional second argument is non-nil." | |
303 (let ((case-fold-search nil) | |
304 match-end) | |
305 (save-excursion | |
306 (set-buffer (process-buffer process)) | |
307 (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
|
308 (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
|
309 (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
|
310 (pop3-accept-process-output process) |
17493 | 311 (goto-char pop3-read-point)) |
312 (setq match-end (point)) | |
313 (goto-char pop3-read-point) | |
314 (if (looking-at "-ERR") | |
87140
9c91533a901a
Fix buggy calls to `error'.
Deepak Goel <deego@gnufans.org>
parents:
86225
diff
changeset
|
315 (error "%s" (buffer-substring (point) (- match-end 2))) |
17493 | 316 (if (not (looking-at "+OK")) |
317 (progn (setq pop3-read-point match-end) nil) | |
318 (setq pop3-read-point match-end) | |
319 (if return | |
320 (buffer-substring (point) match-end) | |
321 t) | |
322 ))))) | |
323 | |
324 (defun pop3-clean-region (start end) | |
325 (setq end (set-marker (make-marker) end)) | |
326 (save-excursion | |
327 (goto-char start) | |
328 (while (and (< (point) end) (search-forward "\r\n" end t)) | |
329 (replace-match "\n" t t)) | |
330 (goto-char start) | |
331 (while (and (< (point) end) (re-search-forward "^\\." end t)) | |
332 (replace-match "" t t) | |
333 (forward-char))) | |
334 (set-marker end nil)) | |
335 | |
33369 | 336 ;; Copied from message-make-date. |
337 (defun pop3-make-date (&optional now) | |
338 "Make a valid date header. | |
339 If NOW, use that time instead." | |
340 (require 'parse-time) | |
341 (let* ((now (or now (current-time))) | |
342 (zone (nth 8 (decode-time now))) | |
343 (sign "+")) | |
344 (when (< zone 0) | |
345 (setq sign "-") | |
346 (setq zone (- zone))) | |
347 (concat | |
348 (format-time-string "%d" now) | |
349 ;; The month name of the %b spec is locale-specific. Pfff. | |
350 (format " %s " | |
351 (capitalize (car (rassoc (nth 4 (decode-time now)) | |
352 parse-time-months)))) | |
353 (format-time-string "%Y %H:%M:%S " now) | |
354 ;; We do all of this because XEmacs doesn't have the %z spec. | |
355 (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60))))) | |
356 | |
17493 | 357 (defun pop3-munge-message-separator (start end) |
358 "Check to see if a message separator exists. If not, generate one." | |
359 (save-excursion | |
360 (save-restriction | |
361 (narrow-to-region start end) | |
362 (goto-char (point-min)) | |
363 (if (not (or (looking-at "From .?") ; Unix mail | |
364 (looking-at "\001\001\001\001\n") ; MMDF | |
365 (looking-at "BABYL OPTIONS:") ; Babyl | |
366 )) | |
44541
1910e7c74f9f
* pop3.el (pop3-munge-message-separator): Work if no date.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
44452
diff
changeset
|
367 (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
|
368 (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
|
369 (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
|
370 (not (string= "" tdate)) |
1910e7c74f9f
* pop3.el (pop3-munge-message-separator): Work if no date.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
44452
diff
changeset
|
371 tdate) |
1910e7c74f9f
* pop3.el (pop3-munge-message-separator): Work if no date.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
44452
diff
changeset
|
372 (pop3-make-date)) |
1910e7c74f9f
* pop3.el (pop3-munge-message-separator): Work if no date.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
44452
diff
changeset
|
373 " ")) |
1910e7c74f9f
* pop3.el (pop3-munge-message-separator): Work if no date.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
44452
diff
changeset
|
374 (From_)) |
17493 | 375 ;; sample date formats I have seen |
376 ;; Date: Tue, 9 Jul 1996 09:04:21 -0400 (EDT) | |
377 ;; Date: 08 Jul 1996 23:22:24 -0400 | |
378 ;; should be | |
379 ;; Tue Jul 9 09:04:21 1996 | |
73269 | 380 |
381 ;; Fixme: This should use timezone on the date field contents. | |
17493 | 382 (setq date |
44541
1910e7c74f9f
* pop3.el (pop3-munge-message-separator): Work if no date.
ShengHuo ZHU <zsh@cs.rochester.edu>
parents:
44452
diff
changeset
|
383 (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
|
384 "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
|
385 ((string-match "[A-Z]" (nth 0 date)) |
17493 | 386 (format "%s %s %s %s %s" |
387 (nth 0 date) (nth 2 date) (nth 1 date) | |
388 (nth 4 date) (nth 3 date))) | |
389 (t | |
390 ;; this really needs to be better but I don't feel | |
391 ;; like writing a date to day converter. | |
392 (format "Sun %s %s %s %s" | |
393 (nth 1 date) (nth 0 date) | |
394 (nth 3 date) (nth 2 date))) | |
395 )) | |
396 (setq From_ (format "\nFrom %s %s\n" from date)) | |
397 (while (string-match "," From_) | |
398 (setq From_ (concat (substring From_ 0 (match-beginning 0)) | |
399 (substring From_ (match-end 0))))) | |
400 (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
|
401 (insert From_) |
33369 | 402 (if (search-forward "\n\n" nil t) |
403 nil | |
404 (goto-char (point-max)) | |
405 (insert "\n")) | |
26108
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
406 (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
|
407 (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
|
408 (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
|
409 (widen) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
410 (forward-line -1) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
411 (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
|
412 ))))) |
17493 | 413 |
414 ;; The Command Set | |
415 | |
416 ;; AUTHORIZATION STATE | |
417 | |
418 (defun pop3-user (process user) | |
419 "Send USER information to POP3 server." | |
420 (pop3-send-command process (format "USER %s" user)) | |
421 (let ((response (pop3-read-response process t))) | |
422 (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
|
423 (error "USER %s not valid" user)))) |
17493 | 424 |
425 (defun pop3-pass (process) | |
426 "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
|
427 (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
|
428 (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
|
429 (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
|
430 (pop3-quit process)))) |
19633
25317a11d7a1
(pop3-md5): New function.
Richard M. Stallman <rms@gnu.org>
parents:
19595
diff
changeset
|
431 |
17493 | 432 (defun pop3-apop (process user) |
433 "Send alternate authentication information to the server." | |
434 (let ((pass pop3-password)) | |
435 (if (and pop3-password-required (not pass)) | |
436 (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
|
437 (read-passwd (format "Password for %s: " pop3-maildrop)))) |
17493 | 438 (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
|
439 (let ((hash (md5 (concat pop3-timestamp pass) nil nil 'binary))) |
17493 | 440 (pop3-send-command process (format "APOP %s %s" user hash)) |
441 (let ((response (pop3-read-response process t))) | |
442 (if (not (and response (string-match "+OK" response))) | |
443 (pop3-quit process))))) | |
444 )) | |
445 | |
446 ;; TRANSACTION STATE | |
447 | |
448 (defun pop3-stat (process) | |
449 "Return the number of messages in the maildrop and the maildrop's size." | |
450 (pop3-send-command process "STAT") | |
451 (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
|
452 (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
|
453 (string-to-number (nth 2 (split-string response " ")))) |
17493 | 454 )) |
455 | |
456 (defun pop3-list (process &optional msg) | |
457 "Scan listing of available messages. | |
458 This function currently does nothing.") | |
459 | |
460 (defun pop3-retr (process msg crashbuf) | |
461 "Retrieve message-id MSG to buffer CRASHBUF." | |
462 (pop3-send-command process (format "RETR %s" msg)) | |
463 (pop3-read-response process) | |
464 (let ((start pop3-read-point) end) | |
465 (save-excursion | |
466 (set-buffer (process-buffer process)) | |
467 (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
|
468 (pop3-accept-process-output process) |
17493 | 469 (goto-char start)) |
470 (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
|
471 ;; 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
|
472 ;; 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
|
473 ;; (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
|
474 ;; (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
|
475 ;; (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
|
476 ;; (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
|
477 ;; (re-search-forward "\\.\r\n") |
17493 | 478 (goto-char (match-beginning 0)) |
479 (setq end (point-marker)) | |
480 (pop3-clean-region start end) | |
481 (pop3-munge-message-separator start end) | |
482 (save-excursion | |
483 (set-buffer crashbuf) | |
484 (erase-buffer)) | |
485 (copy-to-buffer crashbuf start end) | |
486 (delete-region start end) | |
487 ))) | |
488 | |
489 (defun pop3-dele (process msg) | |
490 "Mark message-id MSG as deleted." | |
491 (pop3-send-command process (format "DELE %s" msg)) | |
492 (pop3-read-response process)) | |
493 | |
494 (defun pop3-noop (process msg) | |
495 "No-operation." | |
496 (pop3-send-command process "NOOP") | |
497 (pop3-read-response process)) | |
498 | |
499 (defun pop3-last (process) | |
500 "Return highest accessed message-id number for the session." | |
501 (pop3-send-command process "LAST") | |
502 (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
|
503 (string-to-number (nth 1 (split-string response " "))) |
17493 | 504 )) |
505 | |
506 (defun pop3-rset (process) | |
507 "Remove all delete marks from current maildrop." | |
508 (pop3-send-command process "RSET") | |
509 (pop3-read-response process)) | |
510 | |
511 ;; UPDATE | |
512 | |
513 (defun pop3-quit (process) | |
514 "Close connection to POP3 server. | |
515 Tell server to remove all messages marked as deleted, unlock the maildrop, | |
516 and close the connection." | |
517 (pop3-send-command process "QUIT") | |
518 (pop3-read-response process t) | |
519 (if process | |
520 (save-excursion | |
521 (set-buffer (process-buffer process)) | |
522 (goto-char (point-max)) | |
523 (delete-process process)))) | |
524 | |
525 ;; Summary of POP3 (Post Office Protocol version 3) commands and responses | |
526 | |
527 ;;; AUTHORIZATION STATE | |
528 | |
529 ;; Initial TCP connection | |
530 ;; Arguments: none | |
531 ;; Restrictions: none | |
532 ;; Possible responses: | |
533 ;; +OK [POP3 server ready] | |
534 | |
535 ;; USER name | |
536 ;; Arguments: a server specific user-id (required) | |
537 ;; Restrictions: authorization state [after unsuccessful USER or PASS | |
538 ;; Possible responses: | |
539 ;; +OK [valid user-id] | |
540 ;; -ERR [invalid user-id] | |
541 | |
542 ;; PASS string | |
543 ;; Arguments: a server/user-id specific password (required) | |
544 ;; Restrictions: authorization state, after successful USER | |
545 ;; Possible responses: | |
546 ;; +OK [maildrop locked and ready] | |
547 ;; -ERR [invalid password] | |
548 ;; -ERR [unable to lock maildrop] | |
549 | |
85712
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
550 ;; 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
|
551 ;; Arguments: none |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
552 ;; 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
|
553 ;; Possible responses: |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
554 ;; +OK |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
555 ;; -ERR |
a3c27999decb
Update Gnus to No Gnus 0.7 from the Gnus CVS trunk
Miles Bader <miles@gnu.org>
parents:
78224
diff
changeset
|
556 |
17493 | 557 ;;; TRANSACTION STATE |
558 | |
559 ;; STAT | |
560 ;; Arguments: none | |
561 ;; Restrictions: transaction state | |
562 ;; Possible responses: | |
563 ;; +OK nn mm [# of messages, size of maildrop] | |
564 | |
565 ;; LIST [msg] | |
566 ;; Arguments: a message-id (optional) | |
567 ;; Restrictions: transaction state; msg must not be deleted | |
568 ;; Possible responses: | |
569 ;; +OK [scan listing follows] | |
570 ;; -ERR [no such message] | |
571 | |
572 ;; RETR msg | |
573 ;; Arguments: a message-id (required) | |
574 ;; Restrictions: transaction state; msg must not be deleted | |
575 ;; Possible responses: | |
576 ;; +OK [message contents follow] | |
577 ;; -ERR [no such message] | |
578 | |
579 ;; DELE msg | |
580 ;; Arguments: a message-id (required) | |
581 ;; Restrictions: transaction state; msg must not be deleted | |
582 ;; Possible responses: | |
583 ;; +OK [message deleted] | |
584 ;; -ERR [no such message] | |
585 | |
586 ;; NOOP | |
587 ;; Arguments: none | |
588 ;; Restrictions: transaction state | |
589 ;; Possible responses: | |
590 ;; +OK | |
591 | |
592 ;; LAST | |
593 ;; Arguments: none | |
594 ;; Restrictions: transaction state | |
595 ;; Possible responses: | |
596 ;; +OK nn [highest numbered message accessed] | |
597 | |
598 ;; RSET | |
599 ;; Arguments: none | |
600 ;; Restrictions: transaction state | |
601 ;; Possible responses: | |
602 ;; +OK [all delete marks removed] | |
603 | |
604 ;;; UPDATE STATE | |
605 | |
606 ;; QUIT | |
607 ;; Arguments: none | |
608 ;; Restrictions: none | |
609 ;; Possible responses: | |
610 ;; +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
|
611 |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
612 (provide 'pop3) |
08a36c7a0a52
Merge changes from version `1.3s' which we weren't sent.
Dave Love <fx@gnu.org>
parents:
24599
diff
changeset
|
613 |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92336
diff
changeset
|
614 ;; 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
|
615 ;;; pop3.el ends here |