(pop3-except-header-regexp): New variable.
[elisp/gnus.git-] / lisp / pop3.el
1 ;;; pop3.el --- Post Office Protocol (RFC 1460) interface
2
3 ;; Copyright (C) 1996-1999 Free Software Foundation, Inc.
4
5 ;; Author: Richard L. Pieri <ratinox@peorth.gweep.net>
6 ;;      Daiki Ueno  <ueno@ueda.info.waseda.ac.jp>
7 ;; Keywords: mail, pop3
8 ;; Version: 1.3s
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 2, or (at your option)
15 ;; 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; see the file COPYING.  If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Commentary:
28
29 ;; Most of the standard Post Office Protocol version 3 (RFC 1460) commands
30 ;; are implemented.  The LIST command has not been implemented due to lack
31 ;; of actual usefulness.
32 ;; The optional POP3 command TOP has not been implemented.
33
34 ;; This program was inspired by Kyle E. Jones's vm-pop program.
35
36 ;;; Code:
37
38 (require 'mail-utils)
39 (provide 'pop3)
40
41 (defconst pop3-version "1.3s")
42
43 (defvar pop3-maildrop (or (user-login-name) (getenv "LOGNAME") (getenv "USER") nil)
44   "*POP3 maildrop.")
45 (defvar pop3-mailhost (or (getenv "MAILHOST") nil)
46   "*POP3 mailhost.")
47 (defvar pop3-port 110
48   "*POP3 port.")
49 (defvar pop3-connection-type nil
50   "*POP3 connection type.")
51
52 (defvar pop3-password-required t
53   "*Non-nil if a password is required when connecting to POP server.")
54 (defvar pop3-password nil
55   "*Password to use when connecting to POP server.")
56
57 (defvar pop3-authentication-scheme 'pass
58   "*POP3 authentication scheme.
59 Defaults to 'pass, for the standard USER/PASS authentication.  Other valid
60 values are 'apop.")
61
62 (defvar pop3-timestamp nil
63   "Timestamp returned when initially connected to the POP server.
64 Used for APOP authentication.")
65
66 (defvar pop3-leave-mail-on-server nil
67   "Non-nil if mail is to be left on the server and UIDL used for 
68 message retrieval.")
69
70 (defvar pop3-maximum-message-size nil
71   "If non-nil only download messages smaller than this.")
72
73 (defvar pop3-except-header-regexp nil
74   "If non-nil we do not retrieve messages whose headers are matching this regexp.")
75
76 (defvar pop3-uidl-file-name "~/.uidls"
77   "File in which to store the UIDL of processed messages.")
78
79 (defvar pop3-uidl-support 'dont-know
80   "Whether the server supports UIDL.
81 Nil means no, t means yes, not-nil-or-t means yet to be determined.")
82
83 (defvar pop3-uidl-obarray (make-vector 31 0)
84   "Uidl hash table.")
85
86 (defvar pop3-read-point nil)
87 (defvar pop3-debug nil)
88
89 (eval-and-compile
90   (autoload 'open-ssl-stream "ssl"))
91
92 (defvar pop3-ssl-program-arguments
93   '("-quiet")
94   "Arguments to be passed to the program `pop3-ssl-program-name'.")
95
96 (defun pop3-movemail (&optional crashbox)
97   "Transfer contents of a maildrop to the specified CRASHBOX."
98   (or crashbox (setq crashbox (expand-file-name "~/.crashbox")))
99   (let* ((process (pop3-open-server pop3-mailhost pop3-port))
100          (crashbuf (get-buffer-create " *pop3-retr*"))
101          (n 1)
102          (msgid 1)
103          (msglen 0)
104          message-count
105          (pop3-password pop3-password)
106          (pop3-uidl-file-name 
107           (concat pop3-uidl-file-name "-" pop3-mailhost))
108          (retrieved-messages nil)
109          messages)
110     ;; for debugging only
111     (if pop3-debug (switch-to-buffer (process-buffer process)))
112     ;; query for password
113     (if (and pop3-password-required (not pop3-password))
114         (setq pop3-password
115               (pop3-read-passwd (format "Password for %s: " pop3-maildrop))))
116     (cond ((equal 'apop pop3-authentication-scheme)
117            (pop3-apop process pop3-maildrop))
118           ((equal 'pass pop3-authentication-scheme)
119            (pop3-user process pop3-maildrop)
120            (pop3-pass process))
121           (t (error "Invalid POP3 authentication scheme.")))
122     ;; get messages that are suitable for download
123     (message "Retrieving message list...")
124     (setq messages (pop3-get-message-numbers process)
125           message-count (length messages))
126     (message (format "Retrieving message list...%d unread" message-count))
127     (unwind-protect
128         (progn
129           (while (<= n message-count)
130             (setq msgid (caar messages)
131                   msglen (cdar messages)
132                   messages (cdr messages))
133             ;; only retrieve messages matching our regexp or in the uidl list
134             (unless (or (not msgid)
135                         ;; don't download messages that are too large
136                         (and pop3-maximum-message-size 
137                              (> msglen pop3-maximum-message-size))
138                         (and pop3-except-header-regexp
139                              (string-match pop3-except-header-regexp
140                                            (pop3-top process msgid 0))))
141               (message (format "Retrieving message %d of %d from %s..."
142                                n message-count pop3-mailhost))
143               (pop3-retr process msgid crashbuf)
144               (setq retrieved-messages (cons msgid retrieved-messages)))
145             (setq n (1+ n)))
146           (with-current-buffer crashbuf
147             (write-region-as-binary (point-min) (point-max)
148                                     crashbox 'append 'nomesg)
149             )
150           ;; mark messages as read
151           (when pop3-leave-mail-on-server
152             (pop3-save-uidls))
153           ;; now delete the messages we have retrieved
154           (unless pop3-leave-mail-on-server
155             (dolist (n retrieved-messages)
156               (message (format "Deleting message %d of %d from %s..."
157                                n message-count pop3-mailhost))
158               (pop3-dele process n)))
159           )
160       (pop3-quit process))
161     (kill-buffer crashbuf)
162     t))
163
164 (defun pop3-open-server (mailhost port)
165   "Open TCP connection to MAILHOST.
166 Returns the process associated with the connection."
167   (let ((process-buffer
168          (get-buffer-create (format "trace of POP session to %s" mailhost)))
169         (process))
170     (save-excursion
171       (set-buffer process-buffer)
172       (erase-buffer))
173     (setq
174      process
175      (cond
176       ((eq pop3-connection-type 'ssl)
177        (pop3-open-ssl-stream "POP" process-buffer mailhost port))
178       (t
179        (open-network-stream-as-binary "POP" process-buffer mailhost port))))
180     (setq pop3-read-point (point-min))
181     (let ((response (pop3-read-response process t)))
182       (setq pop3-timestamp
183             (substring response (or (string-match "<" response) 0)
184                        (+ 1 (or (string-match ">" response) -1)))))
185     process))
186
187 (defun pop3-open-ssl-stream-1 (name buffer host service extra-arg)
188   (let* ((ssl-program-arguments 
189           `(,@pop3-ssl-program-arguments ,extra-arg
190             "-connect" ,(format "%s:%d" host service)))
191          (process (open-ssl-stream name buffer host service)))
192     (when process
193       (with-current-buffer buffer
194         (goto-char (point-min))
195         (while (and (memq (process-status process) '(open run))
196                     (goto-char (point-max))
197                     (forward-line -1)
198                     (not (looking-at "+OK")))
199           (accept-process-output process 1)
200           (sit-for 1))
201         (delete-region (point-min) (point)))
202       (and process (memq (process-status process) '(open run))
203            process))))
204
205 (defun pop3-open-ssl-stream (name buffer host service)
206   "Open a SSL connection for a service to a host."
207   (as-binary-process
208    (or (pop3-open-ssl-stream-1 name buffer host service "-ssl3")
209        (pop3-open-ssl-stream-1 name buffer host service "-ssl2"))))
210
211 ;; Support functions
212
213 (defun pop3-process-filter (process output)
214   (save-excursion
215     (set-buffer (process-buffer process))
216     (goto-char (point-max))
217     (insert output)))
218
219 (defun pop3-send-command (process command)
220     (set-buffer (process-buffer process))
221     (goto-char (point-max))
222 ;;    (if (= (aref command 0) ?P)
223 ;;      (insert "PASS <omitted>\r\n")
224 ;;      (insert command "\r\n"))
225     (setq pop3-read-point (point))
226     (goto-char (point-max))
227     (process-send-string process (concat command "\r\n"))
228     )
229
230 (defun pop3-read-response (process &optional return)
231   "Read the response from the server.
232 Return the response string if optional second argument is non-nil."
233   (let ((case-fold-search nil)
234         match-end)
235     (save-excursion
236       (set-buffer (process-buffer process))
237       (goto-char pop3-read-point)
238       (while (not (search-forward "\r\n" nil t))
239         (accept-process-output process 3)
240         (goto-char pop3-read-point))
241       (setq match-end (point))
242       (goto-char pop3-read-point)
243       (if (looking-at "-ERR")
244           (signal 'error (list (buffer-substring (point) (- match-end 2))))
245         (if (not (looking-at "+OK"))
246             (progn (setq pop3-read-point match-end) nil)
247           (setq pop3-read-point match-end)
248           (if return
249               (buffer-substring (point) match-end)
250             t)
251           )))))
252
253 (defvar pop3-read-passwd nil)
254 (defun pop3-read-passwd (prompt)
255   (if (not pop3-read-passwd)
256       (if (functionp 'read-passwd)
257           (setq pop3-read-passwd 'read-passwd)
258         (if (load "passwd" t)
259             (setq pop3-read-passwd 'read-passwd)
260           (autoload 'ange-ftp-read-passwd "ange-ftp")
261           (setq pop3-read-passwd 'ange-ftp-read-passwd))))
262   (funcall pop3-read-passwd prompt))
263
264 (defun pop3-clean-region (start end)
265   (setq end (set-marker (make-marker) end))
266   (save-excursion
267     (goto-char start)
268     (while (and (< (point) end) (search-forward "\r\n" end t))
269       (replace-match "\n" t t))
270     (goto-char start)
271     (while (re-search-forward "\n\n\\(From \\)" end t)
272       (replace-match "\n\n>\\1" t nil))
273     (goto-char start)
274     (while (and (< (point) end) (re-search-forward "^\\." end t))
275       (replace-match "" t t)
276       (forward-char)))
277   (set-marker end nil))
278
279 (defun pop3-munge-message-separator (start end)
280   "Check to see if a message separator exists.  If not, generate one."
281   (if (not (fboundp 'parse-time-string))
282       (autoload 'parse-time-string "parse-time"))
283   (save-excursion
284     (save-restriction
285       (narrow-to-region start end)
286       (goto-char (point-min))
287       (if (not (or (looking-at "From .?") ; Unix mail
288                    (looking-at "\001\001\001\001\n") ; MMDF
289                    (looking-at "BABYL OPTIONS:") ; Babyl
290                    ))
291           (let ((from (mail-strip-quoted-names (mail-fetch-field "From")))
292                 (date (mail-fetch-field "Date"))
293                 (From_))
294             ;; sample date formats I have seen
295             ;; Date: Tue, 9 Jul 1996 09:04:21 -0400 (EDT)
296             ;; Date: 08 Jul 1996 23:22:24 -0400
297             ;; should be
298             ;; Tue Jul 9 09:04:21 1996
299             (setq date (format-time-string
300                         "%a %b %e %T %Y"
301                         (if date
302                             (condition-case nil
303                                 (apply 'encode-time (parse-time-string date))
304                               (error (current-time)))
305                           (current-time))))
306             (setq From_ (format "\nFrom %s  %s\n" from date))
307             (while (string-match "," From_)
308               (setq From_ (concat (substring From_ 0 (match-beginning 0))
309                                   (substring From_ (match-end 0)))))
310             (goto-char (point-min))
311             (insert From_))))))
312
313 ;; UIDL support
314
315 (defun pop3-get-message-numbers (process)
316   "Get the list of message numbers and lengths to retrieve via PROCESS."
317   ;; we use the LIST comand first anyway to get the message lengths.
318   ;; then if we're leaving mail on the server, see if the UIDL command
319   ;; is implemented. if so, we use it to get the message number list.
320   (let ((messages (pop3-list process))
321         (uidl (if pop3-leave-mail-on-server
322                   (pop3-get-uidl process))))
323     (when messages
324       (pop messages)
325       (cond
326        ((eq pop3-uidl-support t)
327         ;; remove elements not in the uidl, this assumes the uidl is short
328         (remove-if-not
329          (lambda (message) (memq (car message) uidl))
330          (reverse messages)))
331        (t messages)))))
332
333 (defun pop3-get-uidl (process)
334   "Use PROCESS to get a list of unread message numbers."
335   (let ((messages (pop3-uidl process)) uidl)
336     (if (or (null messages) (null pop3-uidl-support))
337         (setq pop3-uidl-support nil)
338       (setq pop3-uidl-support t)
339       (save-excursion
340         (with-temp-buffer
341           (when (file-readable-p pop3-uidl-file-name)
342             (insert-file-contents pop3-uidl-file-name))
343           (goto-char (point-min))
344           (while (looking-at "\\([^ \n\t]+\\)")
345             (set (intern (match-string 1) pop3-uidl-obarray)
346                  (cons nil t))
347             (forward-line 1))
348           ))
349       (dolist (message (cdr messages))
350         (if (setq uidl (intern-soft (cdr message) pop3-uidl-obarray))
351             (setcar (symbol-value uidl) (car message))
352           (set (intern (cdr message) pop3-uidl-obarray)
353                (cons (car message) nil))))
354       (pop3-get-unread-message-numbers))
355     ))
356
357 (defun pop3-get-unread-message-numbers ()
358   "Return a sorted list of unread msg numbers to retrieve."
359   (let (nums)
360     (mapatoms (lambda (atom)
361                 (if (not (cdr (symbol-value atom)))
362                     (push (car (symbol-value atom)) nums)))
363               pop3-uidl-obarray)
364     (sort nums '<)))
365
366 (defun pop3-save-uidls ()
367   "Save the updated UIDLs to disk for use next time."
368   (when (and pop3-leave-mail-on-server 
369              pop3-uidl-obarray
370              (catch 'found
371                (dotimes (i (length pop3-uidl-obarray))
372                  (if (symbolp (aref pop3-uidl-obarray i))
373                      (throw 'found t)))))
374     (save-excursion
375       (with-temp-buffer
376         (when (file-readable-p pop3-uidl-file-name)
377           (copy-file pop3-uidl-file-name
378                      (concat pop3-uidl-file-name ".old")
379                      'overwrite 'keeptime))
380         (mapatoms 
381          (lambda (atom)
382            (when (car (symbol-value atom))
383              (insert (format "%s\n" atom))))
384          pop3-uidl-obarray)
385         (write-file pop3-uidl-file-name)))))
386
387 ;; The Command Set
388
389 ;; AUTHORIZATION STATE
390
391 (defun pop3-user (process user)
392   "Send USER information to POP3 server."
393   (pop3-send-command process (format "USER %s" user))
394   (let ((response (pop3-read-response process t)))
395     (if (not (and response (string-match "+OK" response)))
396         (error (format "USER %s not valid." user)))))
397
398 (defun pop3-pass (process)
399   "Send authentication information to the server."
400   (pop3-send-command process (format "PASS %s" pop3-password))
401   (let ((response (pop3-read-response process t)))
402     (if (not (and response (string-match "+OK" response)))
403         (pop3-quit process))))
404
405 (defun pop3-apop (process user)
406   "Send alternate authentication information to the server."
407   (if (not (fboundp 'md5)) (autoload 'md5 "md5"))
408   (let ((hash (md5 (concat pop3-timestamp pop3-password))))
409     (pop3-send-command process (format "APOP %s %s" user hash))
410     (let ((response (pop3-read-response process t)))
411       (if (not (and response (string-match "+OK" response)))
412           (pop3-quit process)))))
413
414 ;; TRANSACTION STATE
415
416 (defun pop3-stat (process)
417   "Return the number of messages in the maildrop and the maildrop's size."
418   (pop3-send-command process "STAT")
419   (let ((response (pop3-read-response process t)))
420     (list (string-to-int (nth 1 (split-string response)))
421           (string-to-int (nth 2 (split-string response))))
422     ))
423
424 (defun pop3-retr (process msg crashbuf)
425   "Retrieve message-id MSG to buffer CRASHBUF."
426   (pop3-send-command process (format "RETR %s" msg))
427   (pop3-read-response process)
428   (save-excursion
429     (let ((region (pop3-get-extended-response process)))
430       (pop3-munge-message-separator (car region) (cadr region))
431       (append-to-buffer crashbuf (car region) (cadr region))
432       (delete-region (car region) (cadr region))
433       )))
434
435 (defun pop3-dele (process msg)
436   "Mark message-id MSG as deleted."
437   (pop3-send-command process (format "DELE %s" msg))
438   (pop3-read-response process))
439
440 (defun pop3-noop (process msg)
441   "No-operation."
442   (pop3-send-command process "NOOP")
443   (pop3-read-response process))
444
445 (defun pop3-last (process)
446   "Return highest accessed message-id number for the session."
447   (pop3-send-command process "LAST")
448   (let ((response (pop3-read-response process t)))
449     (string-to-int (nth 1 (split-string response)))
450     ))
451
452 (defun pop3-rset (process)
453   "Remove all delete marks from current maildrop."
454   (pop3-send-command process "RSET")
455   (pop3-read-response process))
456
457 ;; UPDATE
458
459 (defun pop3-quit (process)
460   "Close connection to POP3 server.
461 Tell server to remove all messages marked as deleted, unlock the maildrop,
462 and close the connection."
463   (pop3-send-command process "QUIT")
464   (pop3-read-response process t)
465   (when process
466     (save-excursion
467       (set-buffer (process-buffer process))
468       (goto-char (point-max))
469       (delete-process process)
470       )))
471
472 (defun pop3-uidl (process &optional msgno)
473   "Return the results of a UIDL command in PROCESS for optional MSGNO.
474 If UIDL is unsupported on this mail server or if msgno is invalid, return nil.
475 Otherwise, return a list in the form
476
477    (N (1 UIDL-1) (2 UIDL-2) ... (N UIDL-N))
478
479 where
480
481    N is an integer for the number of UIDLs returned (could be 0)
482    UIDL-n is a string."
483
484   (if msgno
485       (pop3-send-command process (format "UIDL %d" msgno))
486     (pop3-send-command process "UIDL"))
487   
488   (if (null (pop3-read-response process t))
489       nil ;; UIDL is not supported on this server
490     (let (pairs uidl)
491       (save-excursion
492         (save-restriction
493           (apply 'narrow-to-region (pop3-get-extended-response process))
494           (goto-char (point-min))
495           (while (looking-at "\\([^ \n\t]*\\) \\([^ \n\t]*\\)")
496             (setq msgno (string-to-int (match-string 1))
497                   uidl (match-string 2))
498             (push (cons msgno uidl) pairs)
499             (beginning-of-line 2))
500           (cons (length pairs) (nreverse pairs))
501           )))))
502
503 (defun pop3-list (process &optional msgno)
504   "Return the results of a LIST command for PROCESS and optional MSGNO.
505 If (optional) msgno is invalid, return nil.  Otherwise, return a list
506 in the form
507
508    (N (1 LEN-1) (2 LEN-2) ... (N LEN-N))
509
510 where
511
512    N is an integer for the number of msg/len pairs (could be 0)
513    LEN-n is an integer."
514   (if msgno
515       (pop3-send-command process (format "LIST %d" msgno))
516     (pop3-send-command process "LIST"))
517
518   (if (null (pop3-read-response process t))
519       nil ;; MSGNO is not valid number
520     (let (pairs len)
521       (save-excursion
522         (save-restriction
523           (apply 'narrow-to-region (pop3-get-extended-response process))
524           (goto-char (point-min))
525           (while (looking-at "\\([^ \n\t]*\\) \\([^ \n\t]*\\)")
526             (setq msgno (string-to-int (match-string 1))
527                   len (string-to-int (match-string 2)))
528             (push (cons msgno len) pairs)
529             (beginning-of-line 2))
530           (cons (length pairs) (nreverse pairs))
531           )))))
532
533 (defun pop3-top (process msgno &optional lines)
534   "Return the top LINES of messages for PROCESS and MSGNO.
535 If msgno is invalid, return nil.  Otherwise, return a string."
536   (pop3-send-command process (format "TOP %d %d" msgno (or lines 1)))
537   (if (pop3-read-response process t)
538       nil ;; MSGNO is not valid number
539     (save-excursion
540       (apply 'buffer-substring (pop3-get-extended-response process)))
541     ))
542
543 ;;; Utility code
544
545 (defun pop3-get-extended-response (process)
546   "Get the extended pop3 response in the PROCESS buffer."
547   (let ((start pop3-read-point) end)
548     (set-buffer (process-buffer process))
549     (goto-char start)
550     (while (not (re-search-forward "^\\.\r\n" nil t))
551       (accept-process-output process 3)
552       (goto-char start))
553     (setq pop3-read-point (point-marker))
554     (goto-char (match-beginning 0))
555     (setq end (point-marker))
556     (pop3-clean-region start end)
557     (list start end)))
558
559 \f
560 ;; Summary of POP3 (Post Office Protocol version 3) commands and responses
561
562 ;;; AUTHORIZATION STATE
563
564 ;; Initial TCP connection
565 ;; Arguments: none
566 ;; Restrictions: none
567 ;; Possible responses:
568 ;;  +OK [POP3 server ready]
569
570 ;; USER name
571 ;; Arguments: a server specific user-id (required)
572 ;; Restrictions: authorization state [after unsuccessful USER or PASS
573 ;; Possible responses:
574 ;;  +OK [valid user-id]
575 ;;  -ERR [invalid user-id]
576
577 ;; PASS string
578 ;; Arguments: a server/user-id specific password (required)
579 ;; Restrictions: authorization state, after successful USER
580 ;; Possible responses:
581 ;;  +OK [maildrop locked and ready]
582 ;;  -ERR [invalid password]
583 ;;  -ERR [unable to lock maildrop]
584
585 ;;; TRANSACTION STATE
586
587 ;; STAT
588 ;; Arguments: none
589 ;; Restrictions: transaction state
590 ;; Possible responses:
591 ;;  +OK nn mm [# of messages, size of maildrop]
592
593 ;; LIST [msg]
594 ;; Arguments: a message-id (optional)
595 ;; Restrictions: transaction state; msg must not be deleted
596 ;; Possible responses:
597 ;;  +OK [scan listing follows]
598 ;;  -ERR [no such message]
599
600 ;; TOP msg [lines]
601 ;; Arguments: a message-id (required), number of lines (optional)
602 ;; Restrictions: transaction state; msg must not be deleted
603 ;; Possible responses:
604 ;;  +OK [partial message listing follows]
605 ;;  -ERR [no such message]
606
607 ;; UIDL [msg]
608 ;; Arguments: a message-id (optional)
609 ;; Restrictions: transaction state; msg must not be deleted
610 ;; Possible responses:
611 ;;  +OK [uidl listing follows]
612 ;;  -ERR [no such message]
613
614 ;; RETR msg
615 ;; Arguments: a message-id (required)
616 ;; Restrictions: transaction state; msg must not be deleted
617 ;; Possible responses:
618 ;;  +OK [message contents follow]
619 ;;  -ERR [no such message]
620
621 ;; DELE msg
622 ;; Arguments: a message-id (required)
623 ;; Restrictions: transaction state; msg must not be deleted
624 ;; Possible responses:
625 ;;  +OK [message deleted]
626 ;;  -ERR [no such message]
627
628 ;; NOOP
629 ;; Arguments: none
630 ;; Restrictions: transaction state
631 ;; Possible responses:
632 ;;  +OK
633
634 ;; LAST
635 ;; Arguments: none
636 ;; Restrictions: transaction state
637 ;; Possible responses:
638 ;;  +OK nn [highest numbered message accessed]
639
640 ;; RSET
641 ;; Arguments: none
642 ;; Restrictions: transaction state
643 ;; Possible responses:
644 ;;  +OK [all delete marks removed]
645
646 ;;; UPDATE STATE
647
648 ;; QUIT
649 ;; Arguments: none
650 ;; Restrictions: none
651 ;; Possible responses:
652 ;;  +OK [TCP connection closed]