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