(pop3-streaming-movemail): Respect pop3-leave-mail-on-server.
[gnus] / lisp / pop3.el
1 ;;; pop3.el --- Post Office Protocol (RFC 1460) interface
2
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 ;;   2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5
6 ;; Author: Richard L. Pieri <ratinox@peorth.gweep.net>
7 ;; Maintainer: FSF
8 ;; Keywords: mail
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
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)
37 (defvar parse-time-months)
38
39 (defgroup pop3 nil
40   "Post Office Protocol."
41   :group 'mail
42   :group 'mail-source)
43
44 (defcustom pop3-maildrop (or (user-login-name)
45                              (getenv "LOGNAME")
46                              (getenv "USER"))
47   "*POP3 maildrop."
48   :version "22.1" ;; Oort Gnus
49   :type 'string
50   :group 'pop3)
51
52 (defcustom pop3-mailhost (or (getenv "MAILHOST") ;; nil -> mismatch
53                              "pop3")
54   "*POP3 mailhost."
55   :version "22.1" ;; Oort Gnus
56   :type 'string
57   :group 'pop3)
58
59 (defcustom pop3-port 110
60   "*POP3 port."
61   :version "22.1" ;; Oort Gnus
62   :type 'number
63   :group 'pop3)
64
65 (defcustom pop3-password-required t
66   "*Non-nil if a password is required when connecting to POP server."
67   :version "22.1" ;; Oort Gnus
68   :type 'boolean
69   :group 'pop3)
70
71 ;; Should this be customizable?
72 (defvar pop3-password nil
73   "*Password to use when connecting to POP server.")
74
75 (defcustom pop3-authentication-scheme 'pass
76   "*POP3 authentication scheme.
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))
81   :version "22.1" ;; Oort Gnus
82   :group 'pop3)
83
84 (defcustom pop3-leave-mail-on-server nil
85   "*Non-nil if the mail is to be left on the POP server after fetching.
86
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."
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?
97   :version "22.1" ;; Oort Gnus
98   :type 'boolean
99   :group 'pop3)
100
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
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\\|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.
122 Shorter values mean quicker response, but are more CPU intensive.")
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))))))
130
131 (defun pop3-streaming-movemail (file)
132   "Transfer contents of a maildrop to the specified FILE.
133 Use streaming commands."
134   (let* ((process (pop3-open-server pop3-mailhost pop3-port))
135          message-count message-total-size)
136     (pop3-logon)
137     (with-current-buffer (process-buffer process)
138       (let ((size (pop3-stat process)))
139         (setq message-count (car size)
140               message-total-size (cadr size)))
141       (when (plusp message-count)
142         (pop3-send-streaming-command
143          process "RETR" message-count message-total-size)
144         (pop3-write-to-file file)
145         (unless pop3-leave-mail-on-server
146           (pop3-send-streaming-command
147            process "DELE" message-count nil))
148         (pop3-quit process)))))
149
150 (defun pop3-send-streaming-command (process command count total-size)
151   (erase-buffer)
152   (let ((i 1))
153     (while (>= (1+ count) i)
154       (process-send-string process (format "%s %d\r\n" command i))
155       ;; Only do 100 messages at a time to avoid pipe stalls.
156       (when (zerop (% i 100))
157         (pop3-wait-for-messages process i total-size))
158       (incf i)))
159   (pop3-wait-for-messages process count total-size))
160
161 (defun pop3-wait-for-messages (process count total-size)
162   (while (< (pop3-number-of-responses total-size) count)
163     (when total-size
164       (message "pop3 retrieved %dKB (%d%%)"
165                (truncate (/ (buffer-size) 1000))
166                (truncate (* (/ (* (buffer-size) 1.0)
167                                total-size) 100))))
168     (nnheader-accept-process-output process)))
169
170 (defun pop3-write-to-file (file)
171   (let ((pop-buffer (current-buffer))
172         (start (point-min))
173         beg end
174         temp-buffer)
175     (with-temp-buffer
176       (setq temp-buffer (current-buffer))
177       (with-current-buffer pop-buffer
178         (goto-char (point-min))
179         (while (re-search-forward "^\\+OK" nil t)
180           (forward-line 1)
181           (setq beg (point))
182           (when (re-search-forward "^\\.\r?\n" nil t)
183             (setq start (point))
184             (forward-line -1)
185             (setq end (point)))
186           (with-current-buffer temp-buffer
187             (goto-char (point-max))
188             (let ((hstart (point)))
189               (insert-buffer-substring pop-buffer beg end)
190               (pop3-clean-region hstart (point))
191               (goto-char (point-max))
192               (pop3-munge-message-separator hstart (point))
193               (goto-char (point-max))))))
194       (let ((coding-system-for-write 'binary))
195         (goto-char (point-min))
196         ;; Check whether something inserted a newline at the start and
197         ;; delete it.
198         (when (eolp)
199           (delete-char 1))
200         (write-region (point-min) (point-max) file)))))
201
202 (defun pop3-number-of-responses (endp)
203   (let ((responses 0))
204     (save-excursion
205       (goto-char (point-min))
206       (while (or (and (re-search-forward "^\\+OK " nil t)
207                       (or (not endp)
208                           (re-search-forward "^\\.\r?\n" nil t)))
209                  (re-search-forward "^-ERR " nil t))
210         (incf responses)))
211     responses))
212
213 (defun pop3-logon ()
214   (let ((pop3-password pop3-password))
215     ;; for debugging only
216     (if pop3-debug (switch-to-buffer (process-buffer process)))
217     ;; query for password
218     (if (and pop3-password-required (not pop3-password))
219         (setq pop3-password
220               (read-passwd (format "Password for %s: " pop3-maildrop))))
221     (cond ((equal 'apop pop3-authentication-scheme)
222            (pop3-apop process pop3-maildrop))
223           ((equal 'pass pop3-authentication-scheme)
224            (pop3-user process pop3-maildrop)
225            (pop3-pass process))
226           (t (error "Invalid POP3 authentication scheme")))))
227
228 (defun pop3-movemail (&optional crashbox)
229   "Transfer contents of a maildrop to the specified CRASHBOX."
230   (or crashbox (setq crashbox (expand-file-name "~/.crashbox")))
231   (let* ((process (pop3-open-server pop3-mailhost pop3-port))
232          (crashbuf (get-buffer-create " *pop3-retr*"))
233          (n 1)
234          message-count
235          message-sizes)
236     (pop3-logon)
237     (setq message-count (car (pop3-stat process)))
238     (when (and pop3-display-message-size-flag
239                (> message-count 0))
240       (setq message-sizes (pop3-list process)))
241     (unwind-protect
242         (while (<= n message-count)
243           (message "Retrieving message %d of %d from %s... (%.1fk)"
244                    n message-count pop3-mailhost
245                    (/ (cdr (assoc n message-sizes))
246                       1024.0))
247           (pop3-retr process n crashbuf)
248           (save-excursion
249             (set-buffer crashbuf)
250             (let ((coding-system-for-write 'binary))
251               (write-region (point-min) (point-max) crashbox t 'nomesg))
252             (set-buffer (process-buffer process))
253             (erase-buffer))
254           (unless pop3-leave-mail-on-server
255             (pop3-dele process n))
256           (setq n (+ 1 n))
257           (pop3-accept-process-output process))
258       (when (and pop3-leave-mail-on-server
259                  (> n 1))
260         (message "pop3.el doesn't support UIDL.  Setting `pop3-leave-mail-on-server'
261 to %s might not give the result you'd expect." pop3-leave-mail-on-server)
262         (sit-for 1))
263       (pop3-quit process))
264     (kill-buffer crashbuf))
265   t)
266
267 (defun pop3-get-message-count ()
268   "Return the number of messages in the maildrop."
269   (let* ((process (pop3-open-server pop3-mailhost pop3-port))
270          message-count
271          (pop3-password pop3-password))
272     ;; for debugging only
273     (if pop3-debug (switch-to-buffer (process-buffer process)))
274     ;; query for password
275     (if (and pop3-password-required (not pop3-password))
276         (setq pop3-password
277               (read-passwd (format "Password for %s: " pop3-maildrop))))
278     (cond ((equal 'apop pop3-authentication-scheme)
279            (pop3-apop process pop3-maildrop))
280           ((equal 'pass pop3-authentication-scheme)
281            (pop3-user process pop3-maildrop)
282            (pop3-pass process))
283           (t (error "Invalid POP3 authentication scheme")))
284     (setq message-count (car (pop3-stat process)))
285     (pop3-quit process)
286     message-count))
287
288 (autoload 'open-tls-stream "tls")
289 (autoload 'starttls-open-stream "starttls")
290 (autoload 'starttls-negotiate "starttls") ; avoid warning
291
292 (defcustom pop3-stream-type nil
293   "*Transport security type for POP3 connexions.
294 This may be either nil (plain connexion), `ssl' (use an
295 SSL/TSL-secured stream) or `starttls' (use the starttls mechanism
296 to turn on TLS security after opening the stream).  However, if
297 this is nil, `ssl' is assumed for connexions to port
298 995 (pop3s)."
299   :version "23.1" ;; No Gnus
300   :group 'pop3
301   :type '(choice (const :tag "Plain" nil)
302                  (const :tag "SSL/TLS" ssl)
303                  (const starttls)))
304
305 (defun pop3-open-server (mailhost port)
306   "Open TCP connection to MAILHOST on PORT.
307 Returns the process associated with the connection."
308   (let ((coding-system-for-read 'binary)
309         (coding-system-for-write 'binary)
310         process)
311     (save-excursion
312       (set-buffer (get-buffer-create (concat " trace of POP session to "
313                                              mailhost)))
314       (erase-buffer)
315       (setq pop3-read-point (point-min))
316       (setq process
317             (cond
318              ((or (eq pop3-stream-type 'ssl)
319                   (and (not pop3-stream-type) (member port '(995 "pop3s"))))
320               ;; gnutls-cli, openssl don't accept service names
321               (if (or (equal port "pop3s")
322                       (null port))
323                   (setq port 995))
324               (let ((process (open-tls-stream "POP" (current-buffer)
325                                               mailhost port)))
326                 (when process
327                   ;; There's a load of info printed that needs deleting.
328                   (let ((again 't))
329                     ;; repeat until
330                     ;; - either we received the +OK line
331                     ;; - or accept-process-output timed out without getting
332                     ;;   anything
333                     (while (and again
334                                 (setq again (memq (process-status process)
335                                                   '(open run))))
336                       (setq again (pop3-accept-process-output process))
337                       (goto-char (point-max))
338                       (forward-line -1)
339                       (cond ((looking-at "\\+OK")
340                              (setq again nil)
341                              (delete-region (point-min) (point)))
342                             ((not again)
343                              (pop3-quit process)
344                              (error "POP SSL connexion failed")))))
345                   process)))
346              ((eq pop3-stream-type 'starttls)
347               ;; gnutls-cli, openssl don't accept service names
348               (if (equal port "pop3")
349                   (setq port 110))
350               (let ((process (starttls-open-stream "POP" (current-buffer)
351                                                    mailhost (or port 110))))
352                 (pop3-send-command process "STLS")
353                 (let ((response (pop3-read-response process t)))
354                   (if (and response (string-match "+OK" response))
355                       (starttls-negotiate process)
356                     (pop3-quit process)
357                     (error "POP server doesn't support starttls")))
358                 process))
359              (t
360               (open-network-stream "POP" (current-buffer) mailhost port))))
361       (let ((response (pop3-read-response process t)))
362         (setq pop3-timestamp
363               (substring response (or (string-match "<" response) 0)
364                          (+ 1 (or (string-match ">" response) -1)))))
365       (set-process-query-on-exit-flag process nil)
366       process)))
367
368 ;; Support functions
369
370 (defun pop3-send-command (process command)
371   (set-buffer (process-buffer process))
372   (goto-char (point-max))
373   ;; (if (= (aref command 0) ?P)
374   ;;     (insert "PASS <omitted>\r\n")
375   ;;   (insert command "\r\n"))
376   (setq pop3-read-point (point))
377   (goto-char (point-max))
378   (process-send-string process (concat command "\r\n")))
379
380 (defun pop3-read-response (process &optional return)
381   "Read the response from the server.
382 Return the response string if optional second argument is non-nil."
383   (let ((case-fold-search nil)
384         match-end)
385     (save-excursion
386       (set-buffer (process-buffer process))
387       (goto-char pop3-read-point)
388       (while (and (memq (process-status process) '(open run))
389                   (not (search-forward "\r\n" nil t)))
390         (pop3-accept-process-output process)
391         (goto-char pop3-read-point))
392       (setq match-end (point))
393       (goto-char pop3-read-point)
394       (if (looking-at "-ERR")
395           (error "%s" (buffer-substring (point) (- match-end 2)))
396         (if (not (looking-at "+OK"))
397             (progn (setq pop3-read-point match-end) nil)
398           (setq pop3-read-point match-end)
399           (if return
400               (buffer-substring (point) match-end)
401             t)
402           )))))
403
404 (defun pop3-clean-region (start end)
405   (setq end (set-marker (make-marker) end))
406   (save-excursion
407     (goto-char start)
408     (while (and (< (point) end) (search-forward "\r\n" end t))
409       (replace-match "\n" t t))
410     (goto-char start)
411     (while (and (< (point) end) (re-search-forward "^\\." end t))
412       (replace-match "" t t)
413       (forward-char)))
414   (set-marker end nil))
415
416 ;; Copied from message-make-date.
417 (defun pop3-make-date (&optional now)
418   "Make a valid date header.
419 If NOW, use that time instead."
420   (require 'parse-time)
421   (let* ((now (or now (current-time)))
422          (zone (nth 8 (decode-time now)))
423          (sign "+"))
424     (when (< zone 0)
425       (setq sign "-")
426       (setq zone (- zone)))
427     (concat
428      (format-time-string "%d" now)
429      ;; The month name of the %b spec is locale-specific.  Pfff.
430      (format " %s "
431              (capitalize (car (rassoc (nth 4 (decode-time now))
432                                       parse-time-months))))
433      (format-time-string "%Y %H:%M:%S " now)
434      ;; We do all of this because XEmacs doesn't have the %z spec.
435      (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60)))))
436
437 (defun pop3-munge-message-separator (start end)
438   "Check to see if a message separator exists.  If not, generate one."
439   (save-excursion
440     (save-restriction
441       (narrow-to-region start end)
442       (goto-char (point-min))
443       (if (not (or (looking-at "From .?") ; Unix mail
444                    (looking-at "\001\001\001\001\n") ; MMDF
445                    (looking-at "BABYL OPTIONS:") ; Babyl
446                    ))
447           (let* ((from (mail-strip-quoted-names (mail-fetch-field "From")))
448                  (tdate (mail-fetch-field "Date"))
449                  (date (split-string (or (and tdate
450                                               (not (string= "" tdate))
451                                               tdate)
452                                          (pop3-make-date))
453                                      " "))
454                  (From_))
455             ;; sample date formats I have seen
456             ;; Date: Tue, 9 Jul 1996 09:04:21 -0400 (EDT)
457             ;; Date: 08 Jul 1996 23:22:24 -0400
458             ;; should be
459             ;; Tue Jul 9 09:04:21 1996
460
461             ;; Fixme: This should use timezone on the date field contents.
462             (setq date
463                   (cond ((not date)
464                          "Tue Jan 1 00:00:0 1900")
465                         ((string-match "[A-Z]" (nth 0 date))
466                          (format "%s %s %s %s %s"
467                                  (nth 0 date) (nth 2 date) (nth 1 date)
468                                  (nth 4 date) (nth 3 date)))
469                         (t
470                          ;; this really needs to be better but I don't feel
471                          ;; like writing a date to day converter.
472                          (format "Sun %s %s %s %s"
473                                  (nth 1 date) (nth 0 date)
474                                  (nth 3 date) (nth 2 date)))
475                         ))
476             (setq From_ (format "\nFrom %s  %s\n" from date))
477             (while (string-match "," From_)
478               (setq From_ (concat (substring From_ 0 (match-beginning 0))
479                                   (substring From_ (match-end 0)))))
480             (goto-char (point-min))
481             (insert From_)
482             (if (search-forward "\n\n" nil t)
483                 nil
484               (goto-char (point-max))
485               (insert "\n"))
486             (let ((size (- (point-max) (point))))
487               (forward-line -1)
488               (insert (format "Content-Length: %s\n" size)))
489             )))))
490
491 ;; The Command Set
492
493 ;; AUTHORIZATION STATE
494
495 (defun pop3-user (process user)
496   "Send USER information to POP3 server."
497   (pop3-send-command process (format "USER %s" user))
498   (let ((response (pop3-read-response process t)))
499     (if (not (and response (string-match "+OK" response)))
500         (error "USER %s not valid" user))))
501
502 (defun pop3-pass (process)
503   "Send authentication information to the server."
504   (pop3-send-command process (format "PASS %s" pop3-password))
505   (let ((response (pop3-read-response process t)))
506     (if (not (and response (string-match "+OK" response)))
507         (pop3-quit process))))
508
509 (defun pop3-apop (process user)
510   "Send alternate authentication information to the server."
511   (let ((pass pop3-password))
512     (if (and pop3-password-required (not pass))
513         (setq pass
514               (read-passwd (format "Password for %s: " pop3-maildrop))))
515     (if pass
516         (let ((hash (md5 (concat pop3-timestamp pass) nil nil 'binary)))
517           (pop3-send-command process (format "APOP %s %s" user hash))
518           (let ((response (pop3-read-response process t)))
519             (if (not (and response (string-match "+OK" response)))
520                 (pop3-quit process)))))
521     ))
522
523 ;; TRANSACTION STATE
524
525 (defun pop3-stat (process)
526   "Return the number of messages in the maildrop and the maildrop's size."
527   (pop3-send-command process "STAT")
528   (let ((response (pop3-read-response process t)))
529     (list (string-to-number (nth 1 (split-string response " ")))
530           (string-to-number (nth 2 (split-string response " "))))
531     ))
532
533 (defun pop3-list (process &optional msg)
534   "If MSG is nil, return an alist of (MESSAGE-ID . SIZE) pairs.
535 Otherwise, return the size of the message-id MSG"
536   (pop3-send-command process (if msg
537                                  (format "LIST %d" msg)
538                                "LIST"))
539   (let ((response (pop3-read-response process t)))
540     (if msg
541         (string-to-number (nth 2 (split-string response " ")))
542       (let ((start pop3-read-point) end)
543         (save-excursion
544           (set-buffer (process-buffer process))
545           (while (not (re-search-forward "^\\.\r\n" nil t))
546             (pop3-accept-process-output process)
547             (goto-char start))
548           (setq pop3-read-point (point-marker))
549           (goto-char (match-beginning 0))
550           (setq end (point-marker))
551           (mapcar #'(lambda (s) (let ((split (split-string s " ")))
552                                   (cons (string-to-number (nth 0 split))
553                                         (string-to-number (nth 1 split)))))
554                   (delete "" (split-string (buffer-substring start end)
555                                            "\r\n"))))))))
556
557 (defun pop3-retr (process msg crashbuf)
558   "Retrieve message-id MSG to buffer CRASHBUF."
559   (pop3-send-command process (format "RETR %s" msg))
560   (pop3-read-response process)
561   (let ((start pop3-read-point) end)
562     (save-excursion
563       (set-buffer (process-buffer process))
564       (while (not (re-search-forward "^\\.\r\n" nil t))
565         (pop3-accept-process-output process)
566         (goto-char start))
567       (setq pop3-read-point (point-marker))
568       ;; this code does not seem to work for some POP servers...
569       ;; and I cannot figure out why not.
570       ;;      (goto-char (match-beginning 0))
571       ;;      (backward-char 2)
572       ;;      (if (not (looking-at "\r\n"))
573       ;;          (insert "\r\n"))
574       ;;      (re-search-forward "\\.\r\n")
575       (goto-char (match-beginning 0))
576       (setq end (point-marker))
577       (pop3-clean-region start end)
578       (pop3-munge-message-separator start end)
579       (save-excursion
580         (set-buffer crashbuf)
581         (erase-buffer))
582       (copy-to-buffer crashbuf start end)
583       (delete-region start end)
584       )))
585
586 (defun pop3-dele (process msg)
587   "Mark message-id MSG as deleted."
588   (pop3-send-command process (format "DELE %s" msg))
589   (pop3-read-response process))
590
591 (defun pop3-noop (process msg)
592   "No-operation."
593   (pop3-send-command process "NOOP")
594   (pop3-read-response process))
595
596 (defun pop3-last (process)
597   "Return highest accessed message-id number for the session."
598   (pop3-send-command process "LAST")
599   (let ((response (pop3-read-response process t)))
600     (string-to-number (nth 1 (split-string response " ")))
601     ))
602
603 (defun pop3-rset (process)
604   "Remove all delete marks from current maildrop."
605   (pop3-send-command process "RSET")
606   (pop3-read-response process))
607
608 ;; UPDATE
609
610 (defun pop3-quit (process)
611   "Close connection to POP3 server.
612 Tell server to remove all messages marked as deleted, unlock the maildrop,
613 and close the connection."
614   (pop3-send-command process "QUIT")
615   (pop3-read-response process t)
616   (if process
617       (save-excursion
618         (set-buffer (process-buffer process))
619         (goto-char (point-max))
620         (delete-process process))))
621 \f
622 ;; Summary of POP3 (Post Office Protocol version 3) commands and responses
623
624 ;;; AUTHORIZATION STATE
625
626 ;; Initial TCP connection
627 ;; Arguments: none
628 ;; Restrictions: none
629 ;; Possible responses:
630 ;;  +OK [POP3 server ready]
631
632 ;; USER name
633 ;; Arguments: a server specific user-id (required)
634 ;; Restrictions: authorization state [after unsuccessful USER or PASS
635 ;; Possible responses:
636 ;;  +OK [valid user-id]
637 ;;  -ERR [invalid user-id]
638
639 ;; PASS string
640 ;; Arguments: a server/user-id specific password (required)
641 ;; Restrictions: authorization state, after successful USER
642 ;; Possible responses:
643 ;;  +OK [maildrop locked and ready]
644 ;;  -ERR [invalid password]
645 ;;  -ERR [unable to lock maildrop]
646
647 ;; STLS      (RFC 2595)
648 ;; Arguments: none
649 ;; Restrictions: Only permitted in AUTHORIZATION state.
650 ;; Possible responses:
651 ;;  +OK
652 ;;  -ERR
653
654 ;;; TRANSACTION STATE
655
656 ;; STAT
657 ;; Arguments: none
658 ;; Restrictions: transaction state
659 ;; Possible responses:
660 ;;  +OK nn mm [# of messages, size of maildrop]
661
662 ;; LIST [msg]
663 ;; Arguments: a message-id (optional)
664 ;; Restrictions: transaction state; msg must not be deleted
665 ;; Possible responses:
666 ;;  +OK [scan listing follows]
667 ;;  -ERR [no such message]
668
669 ;; RETR msg
670 ;; Arguments: a message-id (required)
671 ;; Restrictions: transaction state; msg must not be deleted
672 ;; Possible responses:
673 ;;  +OK [message contents follow]
674 ;;  -ERR [no such message]
675
676 ;; DELE msg
677 ;; Arguments: a message-id (required)
678 ;; Restrictions: transaction state; msg must not be deleted
679 ;; Possible responses:
680 ;;  +OK [message deleted]
681 ;;  -ERR [no such message]
682
683 ;; NOOP
684 ;; Arguments: none
685 ;; Restrictions: transaction state
686 ;; Possible responses:
687 ;;  +OK
688
689 ;; LAST
690 ;; Arguments: none
691 ;; Restrictions: transaction state
692 ;; Possible responses:
693 ;;  +OK nn [highest numbered message accessed]
694
695 ;; RSET
696 ;; Arguments: none
697 ;; Restrictions: transaction state
698 ;; Possible responses:
699 ;;  +OK [all delete marks removed]
700
701 ;;; UPDATE STATE
702
703 ;; QUIT
704 ;; Arguments: none
705 ;; Restrictions: none
706 ;; Possible responses:
707 ;;  +OK [TCP connection closed]
708
709 (provide 'pop3)
710
711 ;;; pop3.el ends here