pop3.el 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. ;;; pop3.el --- Post Office Protocol (RFC 1460) interface
  2. ;; Copyright (C) 1996-2012 Free Software Foundation, Inc.
  3. ;; Author: Richard L. Pieri <ratinox@peorth.gweep.net>
  4. ;; Maintainer: FSF
  5. ;; Keywords: mail
  6. ;; This file is part of GNU Emacs.
  7. ;; GNU Emacs is free software: you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;; Most of the standard Post Office Protocol version 3 (RFC 1460) commands
  19. ;; are implemented. The LIST command has not been implemented due to lack
  20. ;; of actual usefulness.
  21. ;; The optional POP3 command TOP has not been implemented.
  22. ;; This program was inspired by Kyle E. Jones's vm-pop program.
  23. ;;; Code:
  24. (eval-when-compile (require 'cl))
  25. (eval-and-compile
  26. ;; In Emacs 24, `open-protocol-stream' is an autoloaded alias for
  27. ;; `make-network-stream'.
  28. (unless (fboundp 'open-protocol-stream)
  29. (require 'proto-stream)))
  30. (require 'mail-utils)
  31. (defvar parse-time-months)
  32. (defgroup pop3 nil
  33. "Post Office Protocol."
  34. :group 'mail
  35. :group 'mail-source)
  36. (defcustom pop3-maildrop (or (user-login-name)
  37. (getenv "LOGNAME")
  38. (getenv "USER"))
  39. "*POP3 maildrop."
  40. :version "22.1" ;; Oort Gnus
  41. :type 'string
  42. :group 'pop3)
  43. (defcustom pop3-mailhost (or (getenv "MAILHOST") ;; nil -> mismatch
  44. "pop3")
  45. "*POP3 mailhost."
  46. :version "22.1" ;; Oort Gnus
  47. :type 'string
  48. :group 'pop3)
  49. (defcustom pop3-port 110
  50. "*POP3 port."
  51. :version "22.1" ;; Oort Gnus
  52. :type 'number
  53. :group 'pop3)
  54. (defcustom pop3-password-required t
  55. "*Non-nil if a password is required when connecting to POP server."
  56. :version "22.1" ;; Oort Gnus
  57. :type 'boolean
  58. :group 'pop3)
  59. ;; Should this be customizable?
  60. (defvar pop3-password nil
  61. "*Password to use when connecting to POP server.")
  62. (defcustom pop3-authentication-scheme 'pass
  63. "*POP3 authentication scheme.
  64. Defaults to `pass', for the standard USER/PASS authentication. The other
  65. valid value is 'apop'."
  66. :type '(choice (const :tag "Normal user/password" pass)
  67. (const :tag "APOP" apop))
  68. :version "22.1" ;; Oort Gnus
  69. :group 'pop3)
  70. (defcustom pop3-stream-length 100
  71. "How many messages should be requested at one time.
  72. The lower the number, the more latency-sensitive the fetching
  73. will be. If your pop3 server doesn't support streaming at all,
  74. set this to 1."
  75. :type 'number
  76. :version "24.1"
  77. :group 'pop3)
  78. (defcustom pop3-leave-mail-on-server nil
  79. "*Non-nil if the mail is to be left on the POP server after fetching.
  80. If `pop3-leave-mail-on-server' is non-nil the mail is to be left
  81. on the POP server after fetching. Note that POP servers maintain
  82. no state information between sessions, so what the client
  83. believes is there and what is actually there may not match up.
  84. If they do not, then you may get duplicate mails or the whole
  85. thing can fall apart and leave you with a corrupt mailbox."
  86. ;; We can't use the UILD support from XEmacs mail-lib or cvs.m17n.org:
  87. ;; http://thread.gmane.org/v9lld8fml4.fsf@marauder.physik.uni-ulm.de
  88. ;; http://thread.gmane.org/b9yy8hzy9ej.fsf@jpl.org
  89. ;; Any volunteer to re-implement this?
  90. :version "22.1" ;; Oort Gnus
  91. :type 'boolean
  92. :group 'pop3)
  93. (defvar pop3-timestamp nil
  94. "Timestamp returned when initially connected to the POP server.
  95. Used for APOP authentication.")
  96. (defvar pop3-read-point nil)
  97. (defvar pop3-debug nil)
  98. ;; Borrowed from nnheader-accept-process-output in nnheader.el. See the
  99. ;; comments there for explanations about the values.
  100. (eval-and-compile
  101. (if (and (fboundp 'nnheader-accept-process-output)
  102. (boundp 'nnheader-read-timeout))
  103. (defalias 'pop3-accept-process-output 'nnheader-accept-process-output)
  104. ;; Borrowed from `nnheader.el':
  105. (defvar pop3-read-timeout
  106. (if (string-match "windows-nt\\|os/2\\|cygwin"
  107. (symbol-name system-type))
  108. 1.0
  109. 0.01)
  110. "How long pop3 should wait between checking for the end of output.
  111. Shorter values mean quicker response, but are more CPU intensive.")
  112. (defun pop3-accept-process-output (process)
  113. (accept-process-output
  114. process
  115. (truncate pop3-read-timeout)
  116. (truncate (* (- pop3-read-timeout
  117. (truncate pop3-read-timeout))
  118. 1000))))))
  119. ;;;###autoload
  120. (defun pop3-movemail (file)
  121. "Transfer contents of a maildrop to the specified FILE.
  122. Use streaming commands."
  123. (let* ((process (pop3-open-server pop3-mailhost pop3-port))
  124. message-count message-total-size)
  125. (pop3-logon process)
  126. (with-current-buffer (process-buffer process)
  127. (let ((size (pop3-stat process)))
  128. (setq message-count (car size)
  129. message-total-size (cadr size)))
  130. (when (> message-count 0)
  131. (pop3-send-streaming-command
  132. process "RETR" message-count message-total-size)
  133. (pop3-write-to-file file)
  134. (unless pop3-leave-mail-on-server
  135. (pop3-send-streaming-command
  136. process "DELE" message-count nil))))
  137. (pop3-quit process)
  138. t))
  139. (defun pop3-send-streaming-command (process command count total-size)
  140. (erase-buffer)
  141. (let ((i 1)
  142. (start-point (point-min))
  143. (waited-for 0))
  144. (while (>= count i)
  145. (process-send-string process (format "%s %d\r\n" command i))
  146. ;; Only do 100 messages at a time to avoid pipe stalls.
  147. (when (zerop (% i pop3-stream-length))
  148. (setq start-point
  149. (pop3-wait-for-messages process pop3-stream-length
  150. total-size start-point))
  151. (incf waited-for pop3-stream-length))
  152. (incf i))
  153. (pop3-wait-for-messages process (- count waited-for)
  154. total-size start-point)))
  155. (defun pop3-wait-for-messages (process count total-size start-point)
  156. (while (> count 0)
  157. (goto-char start-point)
  158. (while (or (and (re-search-forward "^\\+OK" nil t)
  159. (or (not total-size)
  160. (re-search-forward "^\\.\r?\n" nil t)))
  161. (re-search-forward "^-ERR " nil t))
  162. (decf count)
  163. (setq start-point (point)))
  164. (unless (memq (process-status process) '(open run))
  165. (error "pop3 process died"))
  166. (when total-size
  167. (message "pop3 retrieved %dKB (%d%%)"
  168. (truncate (/ (buffer-size) 1000))
  169. (truncate (* (/ (* (buffer-size) 1.0)
  170. total-size) 100))))
  171. (pop3-accept-process-output process))
  172. start-point)
  173. (defun pop3-write-to-file (file)
  174. (let ((pop-buffer (current-buffer))
  175. (start (point-min))
  176. beg end
  177. temp-buffer)
  178. (with-temp-buffer
  179. (setq temp-buffer (current-buffer))
  180. (with-current-buffer pop-buffer
  181. (goto-char (point-min))
  182. (while (re-search-forward "^\\+OK" nil t)
  183. (forward-line 1)
  184. (setq beg (point))
  185. (when (re-search-forward "^\\.\r?\n" nil t)
  186. (setq start (point))
  187. (forward-line -1)
  188. (setq end (point)))
  189. (with-current-buffer temp-buffer
  190. (goto-char (point-max))
  191. (let ((hstart (point)))
  192. (insert-buffer-substring pop-buffer beg end)
  193. (pop3-clean-region hstart (point))
  194. (goto-char (point-max))
  195. (pop3-munge-message-separator hstart (point))
  196. (goto-char (point-max))))))
  197. (let ((coding-system-for-write 'binary))
  198. (goto-char (point-min))
  199. ;; Check whether something inserted a newline at the start and
  200. ;; delete it.
  201. (when (eolp)
  202. (delete-char 1))
  203. (write-region (point-min) (point-max) file nil 'nomesg)))))
  204. (defun pop3-logon (process)
  205. (let ((pop3-password pop3-password))
  206. ;; for debugging only
  207. (if pop3-debug (switch-to-buffer (process-buffer process)))
  208. ;; query for password
  209. (if (and pop3-password-required (not pop3-password))
  210. (setq pop3-password
  211. (read-passwd (format "Password for %s: " pop3-maildrop))))
  212. (cond ((equal 'apop pop3-authentication-scheme)
  213. (pop3-apop process pop3-maildrop))
  214. ((equal 'pass pop3-authentication-scheme)
  215. (pop3-user process pop3-maildrop)
  216. (pop3-pass process))
  217. (t (error "Invalid POP3 authentication scheme")))))
  218. (defun pop3-get-message-count ()
  219. "Return the number of messages in the maildrop."
  220. (let* ((process (pop3-open-server pop3-mailhost pop3-port))
  221. message-count
  222. (pop3-password pop3-password))
  223. ;; for debugging only
  224. (if pop3-debug (switch-to-buffer (process-buffer process)))
  225. ;; query for password
  226. (if (and pop3-password-required (not pop3-password))
  227. (setq pop3-password
  228. (read-passwd (format "Password for %s: " pop3-maildrop))))
  229. (cond ((equal 'apop pop3-authentication-scheme)
  230. (pop3-apop process pop3-maildrop))
  231. ((equal 'pass pop3-authentication-scheme)
  232. (pop3-user process pop3-maildrop)
  233. (pop3-pass process))
  234. (t (error "Invalid POP3 authentication scheme")))
  235. (setq message-count (car (pop3-stat process)))
  236. (pop3-quit process)
  237. message-count))
  238. (defcustom pop3-stream-type nil
  239. "*Transport security type for POP3 connections.
  240. This may be either nil (plain connection), `ssl' (use an
  241. SSL/TSL-secured stream) or `starttls' (use the starttls mechanism
  242. to turn on TLS security after opening the stream). However, if
  243. this is nil, `ssl' is assumed for connections to port
  244. 995 (pop3s)."
  245. :version "23.1" ;; No Gnus
  246. :group 'pop3
  247. :type '(choice (const :tag "Plain" nil)
  248. (const :tag "SSL/TLS" ssl)
  249. (const starttls)))
  250. (eval-and-compile
  251. (if (fboundp 'set-process-query-on-exit-flag)
  252. (defalias 'pop3-set-process-query-on-exit-flag
  253. 'set-process-query-on-exit-flag)
  254. (defalias 'pop3-set-process-query-on-exit-flag
  255. 'process-kill-without-query)))
  256. (defun pop3-open-server (mailhost port)
  257. "Open TCP connection to MAILHOST on PORT.
  258. Returns the process associated with the connection."
  259. (let ((coding-system-for-read 'binary)
  260. (coding-system-for-write 'binary)
  261. result)
  262. (with-current-buffer
  263. (get-buffer-create (concat " trace of POP session to "
  264. mailhost))
  265. (erase-buffer)
  266. (setq pop3-read-point (point-min))
  267. (setq result
  268. (open-protocol-stream
  269. "POP" (current-buffer) mailhost port
  270. :type (cond
  271. ((or (eq pop3-stream-type 'ssl)
  272. (and (not pop3-stream-type)
  273. (member port '(995 "pop3s"))))
  274. 'tls)
  275. (t
  276. (or pop3-stream-type 'network)))
  277. :capability-command "CAPA\r\n"
  278. :end-of-command "^\\(-ERR\\|+OK\\).*\n"
  279. :end-of-capability "^\\.\r?\n\\|^-ERR"
  280. :success "^\\+OK.*\n"
  281. :return-list t
  282. :starttls-function
  283. (lambda (capabilities)
  284. (and (string-match "\\bSTLS\\b" capabilities)
  285. "STLS\r\n"))))
  286. (when result
  287. (let ((response (plist-get (cdr result) :greeting)))
  288. (setq pop3-timestamp
  289. (substring response (or (string-match "<" response) 0)
  290. (+ 1 (or (string-match ">" response) -1)))))
  291. (pop3-set-process-query-on-exit-flag (car result) nil)
  292. (erase-buffer)
  293. (car result)))))
  294. ;; Support functions
  295. (defun pop3-send-command (process command)
  296. (set-buffer (process-buffer process))
  297. (goto-char (point-max))
  298. ;; (if (= (aref command 0) ?P)
  299. ;; (insert "PASS <omitted>\r\n")
  300. ;; (insert command "\r\n"))
  301. (setq pop3-read-point (point))
  302. (goto-char (point-max))
  303. (process-send-string process (concat command "\r\n")))
  304. (defun pop3-read-response (process &optional return)
  305. "Read the response from the server.
  306. Return the response string if optional second argument is non-nil."
  307. (let ((case-fold-search nil)
  308. match-end)
  309. (with-current-buffer (process-buffer process)
  310. (goto-char pop3-read-point)
  311. (while (and (memq (process-status process) '(open run))
  312. (not (search-forward "\r\n" nil t)))
  313. (pop3-accept-process-output process)
  314. (goto-char pop3-read-point))
  315. (setq match-end (point))
  316. (goto-char pop3-read-point)
  317. (if (looking-at "-ERR")
  318. (error "%s" (buffer-substring (point) (- match-end 2)))
  319. (if (not (looking-at "+OK"))
  320. (progn (setq pop3-read-point match-end) nil)
  321. (setq pop3-read-point match-end)
  322. (if return
  323. (buffer-substring (point) match-end)
  324. t)
  325. )))))
  326. (defun pop3-clean-region (start end)
  327. (setq end (set-marker (make-marker) end))
  328. (save-excursion
  329. (goto-char start)
  330. (while (and (< (point) end) (search-forward "\r\n" end t))
  331. (replace-match "\n" t t))
  332. (goto-char start)
  333. (while (and (< (point) end) (re-search-forward "^\\." end t))
  334. (replace-match "" t t)
  335. (forward-char)))
  336. (set-marker end nil))
  337. ;; Copied from message-make-date.
  338. (defun pop3-make-date (&optional now)
  339. "Make a valid date header.
  340. If NOW, use that time instead."
  341. (require 'parse-time)
  342. (let* ((now (or now (current-time)))
  343. (zone (nth 8 (decode-time now)))
  344. (sign "+"))
  345. (when (< zone 0)
  346. (setq sign "-")
  347. (setq zone (- zone)))
  348. (concat
  349. (format-time-string "%d" now)
  350. ;; The month name of the %b spec is locale-specific. Pfff.
  351. (format " %s "
  352. (capitalize (car (rassoc (nth 4 (decode-time now))
  353. parse-time-months))))
  354. (format-time-string "%Y %H:%M:%S " now)
  355. ;; We do all of this because XEmacs doesn't have the %z spec.
  356. (format "%s%02d%02d" sign (/ zone 3600) (/ (% zone 3600) 60)))))
  357. (defun pop3-munge-message-separator (start end)
  358. "Check to see if a message separator exists. If not, generate one."
  359. (save-excursion
  360. (save-restriction
  361. (narrow-to-region start end)
  362. (goto-char (point-min))
  363. (if (not (or (looking-at "From .?") ; Unix mail
  364. (looking-at "\001\001\001\001\n") ; MMDF
  365. (looking-at "BABYL OPTIONS:") ; Babyl
  366. ))
  367. (let* ((from (mail-strip-quoted-names (mail-fetch-field "From")))
  368. (tdate (mail-fetch-field "Date"))
  369. (date (split-string (or (and tdate
  370. (not (string= "" tdate))
  371. tdate)
  372. (pop3-make-date))
  373. " "))
  374. (From_))
  375. ;; sample date formats I have seen
  376. ;; Date: Tue, 9 Jul 1996 09:04:21 -0400 (EDT)
  377. ;; Date: 08 Jul 1996 23:22:24 -0400
  378. ;; should be
  379. ;; Tue Jul 9 09:04:21 1996
  380. ;; Fixme: This should use timezone on the date field contents.
  381. (setq date
  382. (cond ((not date)
  383. "Tue Jan 1 00:00:0 1900")
  384. ((string-match "[A-Z]" (nth 0 date))
  385. (format "%s %s %s %s %s"
  386. (nth 0 date) (nth 2 date) (nth 1 date)
  387. (nth 4 date) (nth 3 date)))
  388. (t
  389. ;; this really needs to be better but I don't feel
  390. ;; like writing a date to day converter.
  391. (format "Sun %s %s %s %s"
  392. (nth 1 date) (nth 0 date)
  393. (nth 3 date) (nth 2 date)))
  394. ))
  395. (setq From_ (format "\nFrom %s %s\n" from date))
  396. (while (string-match "," From_)
  397. (setq From_ (concat (substring From_ 0 (match-beginning 0))
  398. (substring From_ (match-end 0)))))
  399. (goto-char (point-min))
  400. (insert From_)
  401. (if (search-forward "\n\n" nil t)
  402. nil
  403. (goto-char (point-max))
  404. (insert "\n"))
  405. (let ((size (- (point-max) (point))))
  406. (forward-line -1)
  407. (insert (format "Content-Length: %s\n" size)))
  408. )))))
  409. ;; The Command Set
  410. ;; AUTHORIZATION STATE
  411. (defun pop3-user (process user)
  412. "Send USER information to POP3 server."
  413. (pop3-send-command process (format "USER %s" user))
  414. (let ((response (pop3-read-response process t)))
  415. (if (not (and response (string-match "+OK" response)))
  416. (error "USER %s not valid" user))))
  417. (defun pop3-pass (process)
  418. "Send authentication information to the server."
  419. (pop3-send-command process (format "PASS %s" pop3-password))
  420. (let ((response (pop3-read-response process t)))
  421. (if (not (and response (string-match "+OK" response)))
  422. (pop3-quit process))))
  423. (defun pop3-apop (process user)
  424. "Send alternate authentication information to the server."
  425. (let ((pass pop3-password))
  426. (if (and pop3-password-required (not pass))
  427. (setq pass
  428. (read-passwd (format "Password for %s: " pop3-maildrop))))
  429. (if pass
  430. (let ((hash (md5 (concat pop3-timestamp pass) nil nil 'binary)))
  431. (pop3-send-command process (format "APOP %s %s" user hash))
  432. (let ((response (pop3-read-response process t)))
  433. (if (not (and response (string-match "+OK" response)))
  434. (pop3-quit process)))))
  435. ))
  436. ;; TRANSACTION STATE
  437. (defun pop3-stat (process)
  438. "Return the number of messages in the maildrop and the maildrop's size."
  439. (pop3-send-command process "STAT")
  440. (let ((response (pop3-read-response process t)))
  441. (list (string-to-number (nth 1 (split-string response " ")))
  442. (string-to-number (nth 2 (split-string response " "))))
  443. ))
  444. (defun pop3-list (process &optional msg)
  445. "If MSG is nil, return an alist of (MESSAGE-ID . SIZE) pairs.
  446. Otherwise, return the size of the message-id MSG"
  447. (pop3-send-command process (if msg
  448. (format "LIST %d" msg)
  449. "LIST"))
  450. (let ((response (pop3-read-response process t)))
  451. (if msg
  452. (string-to-number (nth 2 (split-string response " ")))
  453. (let ((start pop3-read-point) end)
  454. (with-current-buffer (process-buffer process)
  455. (while (not (re-search-forward "^\\.\r\n" nil t))
  456. (pop3-accept-process-output process)
  457. (goto-char start))
  458. (setq pop3-read-point (point-marker))
  459. (goto-char (match-beginning 0))
  460. (setq end (point-marker))
  461. (mapcar #'(lambda (s) (let ((split (split-string s " ")))
  462. (cons (string-to-number (nth 0 split))
  463. (string-to-number (nth 1 split)))))
  464. (split-string (buffer-substring start end) "\r\n" t)))))))
  465. (defun pop3-retr (process msg crashbuf)
  466. "Retrieve message-id MSG to buffer CRASHBUF."
  467. (pop3-send-command process (format "RETR %s" msg))
  468. (pop3-read-response process)
  469. (let ((start pop3-read-point) end)
  470. (with-current-buffer (process-buffer process)
  471. (while (not (re-search-forward "^\\.\r\n" nil t))
  472. (unless (memq (process-status process) '(open run))
  473. (error "pop3 server closed the connection"))
  474. (pop3-accept-process-output process)
  475. (goto-char start))
  476. (setq pop3-read-point (point-marker))
  477. ;; this code does not seem to work for some POP servers...
  478. ;; and I cannot figure out why not.
  479. ;; (goto-char (match-beginning 0))
  480. ;; (backward-char 2)
  481. ;; (if (not (looking-at "\r\n"))
  482. ;; (insert "\r\n"))
  483. ;; (re-search-forward "\\.\r\n")
  484. (goto-char (match-beginning 0))
  485. (setq end (point-marker))
  486. (pop3-clean-region start end)
  487. (pop3-munge-message-separator start end)
  488. (with-current-buffer crashbuf
  489. (erase-buffer))
  490. (copy-to-buffer crashbuf start end)
  491. (delete-region start end)
  492. )))
  493. (defun pop3-dele (process msg)
  494. "Mark message-id MSG as deleted."
  495. (pop3-send-command process (format "DELE %s" msg))
  496. (pop3-read-response process))
  497. (defun pop3-noop (process msg)
  498. "No-operation."
  499. (pop3-send-command process "NOOP")
  500. (pop3-read-response process))
  501. (defun pop3-last (process)
  502. "Return highest accessed message-id number for the session."
  503. (pop3-send-command process "LAST")
  504. (let ((response (pop3-read-response process t)))
  505. (string-to-number (nth 1 (split-string response " ")))
  506. ))
  507. (defun pop3-rset (process)
  508. "Remove all delete marks from current maildrop."
  509. (pop3-send-command process "RSET")
  510. (pop3-read-response process))
  511. ;; UPDATE
  512. (defun pop3-quit (process)
  513. "Close connection to POP3 server.
  514. Tell server to remove all messages marked as deleted, unlock the maildrop,
  515. and close the connection."
  516. (pop3-send-command process "QUIT")
  517. (pop3-read-response process t)
  518. (if process
  519. (with-current-buffer (process-buffer process)
  520. (goto-char (point-max))
  521. (delete-process process))))
  522. ;; Summary of POP3 (Post Office Protocol version 3) commands and responses
  523. ;;; AUTHORIZATION STATE
  524. ;; Initial TCP connection
  525. ;; Arguments: none
  526. ;; Restrictions: none
  527. ;; Possible responses:
  528. ;; +OK [POP3 server ready]
  529. ;; USER name
  530. ;; Arguments: a server specific user-id (required)
  531. ;; Restrictions: authorization state [after unsuccessful USER or PASS
  532. ;; Possible responses:
  533. ;; +OK [valid user-id]
  534. ;; -ERR [invalid user-id]
  535. ;; PASS string
  536. ;; Arguments: a server/user-id specific password (required)
  537. ;; Restrictions: authorization state, after successful USER
  538. ;; Possible responses:
  539. ;; +OK [maildrop locked and ready]
  540. ;; -ERR [invalid password]
  541. ;; -ERR [unable to lock maildrop]
  542. ;; STLS (RFC 2595)
  543. ;; Arguments: none
  544. ;; Restrictions: Only permitted in AUTHORIZATION state.
  545. ;; Possible responses:
  546. ;; +OK
  547. ;; -ERR
  548. ;;; TRANSACTION STATE
  549. ;; STAT
  550. ;; Arguments: none
  551. ;; Restrictions: transaction state
  552. ;; Possible responses:
  553. ;; +OK nn mm [# of messages, size of maildrop]
  554. ;; LIST [msg]
  555. ;; Arguments: a message-id (optional)
  556. ;; Restrictions: transaction state; msg must not be deleted
  557. ;; Possible responses:
  558. ;; +OK [scan listing follows]
  559. ;; -ERR [no such message]
  560. ;; RETR msg
  561. ;; Arguments: a message-id (required)
  562. ;; Restrictions: transaction state; msg must not be deleted
  563. ;; Possible responses:
  564. ;; +OK [message contents follow]
  565. ;; -ERR [no such message]
  566. ;; DELE msg
  567. ;; Arguments: a message-id (required)
  568. ;; Restrictions: transaction state; msg must not be deleted
  569. ;; Possible responses:
  570. ;; +OK [message deleted]
  571. ;; -ERR [no such message]
  572. ;; NOOP
  573. ;; Arguments: none
  574. ;; Restrictions: transaction state
  575. ;; Possible responses:
  576. ;; +OK
  577. ;; LAST
  578. ;; Arguments: none
  579. ;; Restrictions: transaction state
  580. ;; Possible responses:
  581. ;; +OK nn [highest numbered message accessed]
  582. ;; RSET
  583. ;; Arguments: none
  584. ;; Restrictions: transaction state
  585. ;; Possible responses:
  586. ;; +OK [all delete marks removed]
  587. ;;; UPDATE STATE
  588. ;; QUIT
  589. ;; Arguments: none
  590. ;; Restrictions: none
  591. ;; Possible responses:
  592. ;; +OK [TCP connection closed]
  593. (provide 'pop3)
  594. ;;; pop3.el ends here