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