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