Mercurial > emacs
comparison lisp/gnus/pop3.el @ 24357:15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
author | Lars Magne Ingebrigtsen <larsi@gnus.org> |
---|---|
date | Sat, 20 Feb 1999 14:05:57 +0000 |
parents | dd68893482a9 |
children | 04a29f9f6a22 |
comparison
equal
deleted
inserted
replaced
24356:a5a611ef40f6 | 24357:15fc6acbae7a |
---|---|
1 ;;; pop3.el --- Post Office Protocol (RFC 1460) interface | 1 ;;; pop3.el --- Post Office Protocol (RFC 1460) interface |
2 | 2 |
3 ;; Copyright (C) 1996,1997 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1996,1997,1998 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Author: Richard L. Pieri <ratinox@peorth.gweep.net> | 5 ;; Author: Richard L. Pieri <ratinox@peorth.gweep.net> |
6 ;; Keywords: mail, pop3 | 6 ;; Keywords: mail, pop3 |
7 ;; Version: 1.3g | 7 ;; Version: 1.3m |
8 | 8 |
9 ;; This file is part of GNU Emacs. | 9 ;; This file is part of GNU Emacs. |
10 | 10 |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | 11 ;; GNU Emacs is free software; you can redistribute it and/or modify |
12 ;; it under the terms of the GNU General Public License as published by | 12 ;; it under the terms of the GNU General Public License as published by |
35 ;;; Code: | 35 ;;; Code: |
36 | 36 |
37 (require 'mail-utils) | 37 (require 'mail-utils) |
38 (provide 'pop3) | 38 (provide 'pop3) |
39 | 39 |
40 (defconst pop3-version "1.3g") | 40 (defconst pop3-version "1.3m") |
41 | 41 |
42 (defvar pop3-maildrop (or user-login-name (getenv "LOGNAME") (getenv "USER") nil) | 42 (defvar pop3-maildrop (or (user-login-name) (getenv "LOGNAME") (getenv "USER") nil) |
43 "*POP3 maildrop.") | 43 "*POP3 maildrop.") |
44 (defvar pop3-mailhost (or (getenv "MAILHOST") nil) | 44 (defvar pop3-mailhost (or (getenv "MAILHOST") nil) |
45 "*POP3 mailhost.") | 45 "*POP3 mailhost.") |
46 (defvar pop3-port 110 | 46 (defvar pop3-port 110 |
47 "*POP3 port.") | 47 "*POP3 port.") |
70 "Transfer contents of a maildrop to the specified CRASHBOX." | 70 "Transfer contents of a maildrop to the specified CRASHBOX." |
71 (or crashbox (setq crashbox (expand-file-name "~/.crashbox"))) | 71 (or crashbox (setq crashbox (expand-file-name "~/.crashbox"))) |
72 (let* ((process (pop3-open-server pop3-mailhost pop3-port)) | 72 (let* ((process (pop3-open-server pop3-mailhost pop3-port)) |
73 (crashbuf (get-buffer-create " *pop3-retr*")) | 73 (crashbuf (get-buffer-create " *pop3-retr*")) |
74 (n 1) | 74 (n 1) |
75 message-count) | 75 message-count |
76 (pop3-password pop3-password) | |
77 ) | |
76 ;; for debugging only | 78 ;; for debugging only |
77 (if pop3-debug (switch-to-buffer (process-buffer process))) | 79 (if pop3-debug (switch-to-buffer (process-buffer process))) |
80 ;; query for password | |
81 (if (and pop3-password-required (not pop3-password)) | |
82 (setq pop3-password | |
83 (pop3-read-passwd (format "Password for %s: " pop3-maildrop)))) | |
78 (cond ((equal 'apop pop3-authentication-scheme) | 84 (cond ((equal 'apop pop3-authentication-scheme) |
79 (pop3-apop process pop3-maildrop)) | 85 (pop3-apop process pop3-maildrop)) |
80 ((equal 'pass pop3-authentication-scheme) | 86 ((equal 'pass pop3-authentication-scheme) |
81 (pop3-user process pop3-maildrop) | 87 (pop3-user process pop3-maildrop) |
82 (pop3-pass process)) | 88 (pop3-pass process)) |
108 "Open TCP connection to MAILHOST. | 114 "Open TCP connection to MAILHOST. |
109 Returns the process associated with the connection." | 115 Returns the process associated with the connection." |
110 (let ((process-buffer | 116 (let ((process-buffer |
111 (get-buffer-create (format "trace of POP session to %s" mailhost))) | 117 (get-buffer-create (format "trace of POP session to %s" mailhost))) |
112 (process) | 118 (process) |
113 (coding-system-for-read 'no-conversion) | 119 (coding-system-for-read 'binary) |
114 (coding-system-for-write 'no-conversion)) | 120 (coding-system-for-write 'binary) |
121 ) | |
115 (save-excursion | 122 (save-excursion |
116 (set-buffer process-buffer) | 123 (set-buffer process-buffer) |
117 (erase-buffer)) | 124 (erase-buffer) |
125 (setq pop3-read-point (point-min)) | |
126 ) | |
118 (setq process | 127 (setq process |
119 (open-network-stream "POP" process-buffer mailhost port)) | 128 (open-network-stream "POP" process-buffer mailhost port)) |
120 (setq pop3-read-point (point-min)) | |
121 (let ((response (pop3-read-response process t))) | 129 (let ((response (pop3-read-response process t))) |
122 (setq pop3-timestamp | 130 (setq pop3-timestamp |
123 (substring response (or (string-match "<" response) 0) | 131 (substring response (or (string-match "<" response) 0) |
124 (+ 1 (or (string-match ">" response) -1))))) | 132 (+ 1 (or (string-match ">" response) -1))))) |
125 process | 133 process |
255 (if (not (and response (string-match "+OK" response))) | 263 (if (not (and response (string-match "+OK" response))) |
256 (error (format "USER %s not valid." user))))) | 264 (error (format "USER %s not valid." user))))) |
257 | 265 |
258 (defun pop3-pass (process) | 266 (defun pop3-pass (process) |
259 "Send authentication information to the server." | 267 "Send authentication information to the server." |
260 (let ((pass pop3-password)) | 268 (pop3-send-command process (format "PASS %s" pop3-password)) |
261 (if (and pop3-password-required (not pass)) | 269 (let ((response (pop3-read-response process t))) |
262 (setq pass | 270 (if (not (and response (string-match "+OK" response))) |
263 (pop3-read-passwd (format "Password for %s: " pop3-maildrop)))) | 271 (pop3-quit process)))) |
264 (if pass | |
265 (progn | |
266 (pop3-send-command process (format "PASS %s" pass)) | |
267 (let ((response (pop3-read-response process t))) | |
268 (if (not (and response (string-match "+OK" response))) | |
269 (pop3-quit process))))) | |
270 )) | |
271 | |
272 (defvar pop3-md5-program "md5" | |
273 "*Program to encode its input in MD5.") | |
274 | |
275 (defun pop3-md5 (string) | |
276 (with-temp-buffer | |
277 (insert string) | |
278 (call-process-region (point-min) (point-max) | |
279 (or shell-file-name "/bin/sh") | |
280 t (current-buffer) nil | |
281 "-c" pop3-md5-program) | |
282 ;; The meaningful output is the first 32 characters. | |
283 ;; Don't return the newline that follows them! | |
284 (buffer-substring (point-min) (+ (point-min) 32)))) | |
285 | 272 |
286 (defun pop3-apop (process user) | 273 (defun pop3-apop (process user) |
287 "Send alternate authentication information to the server." | 274 "Send alternate authentication information to the server." |
288 (let ((pass pop3-password)) | 275 (let ((pass pop3-password)) |
289 (if (and pop3-password-required (not pass)) | 276 (if (and pop3-password-required (not pass)) |
297 (pop3-quit process))))) | 284 (pop3-quit process))))) |
298 )) | 285 )) |
299 | 286 |
300 ;; TRANSACTION STATE | 287 ;; TRANSACTION STATE |
301 | 288 |
289 (defvar pop3-md5-program "md5" | |
290 "*Program to encode its input in MD5.") | |
291 | |
292 (defun pop3-md5 (string) | |
293 (with-temp-buffer | |
294 (insert string) | |
295 (call-process-region (point-min) (point-max) | |
296 (or shell-file-name "/bin/sh") | |
297 t (current-buffer) nil | |
298 "-c" pop3-md5-program) | |
299 ;; The meaningful output is the first 32 characters. | |
300 ;; Don't return the newline that follows them! | |
301 (buffer-substring (point-min) (+ (point-min) 32)))) | |
302 | |
302 (defun pop3-stat (process) | 303 (defun pop3-stat (process) |
303 "Return the number of messages in the maildrop and the maildrop's size." | 304 "Return the number of messages in the maildrop and the maildrop's size." |
304 (pop3-send-command process "STAT") | 305 (pop3-send-command process "STAT") |
305 (let ((response (pop3-read-response process t))) | 306 (let ((response (pop3-read-response process t))) |
306 (list (string-to-int (nth 1 (pop3-string-to-list response))) | 307 (list (string-to-int (nth 1 (pop3-string-to-list response))) |
319 (save-excursion | 320 (save-excursion |
320 (set-buffer (process-buffer process)) | 321 (set-buffer (process-buffer process)) |
321 (while (not (re-search-forward "^\\.\r\n" nil t)) | 322 (while (not (re-search-forward "^\\.\r\n" nil t)) |
322 (accept-process-output process 3) | 323 (accept-process-output process 3) |
323 ;; bill@att.com ... to save wear and tear on the heap | 324 ;; bill@att.com ... to save wear and tear on the heap |
325 ;; uncommented because the condensed version below is a problem for | |
326 ;; some. | |
324 (if (> (buffer-size) 20000) (sleep-for 1)) | 327 (if (> (buffer-size) 20000) (sleep-for 1)) |
325 (if (> (buffer-size) 50000) (sleep-for 1)) | 328 (if (> (buffer-size) 50000) (sleep-for 1)) |
326 (if (> (buffer-size) 100000) (sleep-for 1)) | 329 (if (> (buffer-size) 100000) (sleep-for 1)) |
327 (if (> (buffer-size) 200000) (sleep-for 1)) | 330 (if (> (buffer-size) 200000) (sleep-for 1)) |
328 (if (> (buffer-size) 500000) (sleep-for 1)) | 331 (if (> (buffer-size) 500000) (sleep-for 1)) |
329 ;; bill@att.com | 332 ;; bill@att.com |
333 ;; condensed into: | |
334 ;; (sometimes causes problems for really large messages.) | |
335 ; (if (> (buffer-size) 20000) (sleep-for (/ (buffer-size) 20000))) | |
330 (goto-char start)) | 336 (goto-char start)) |
331 (setq pop3-read-point (point-marker)) | 337 (setq pop3-read-point (point-marker)) |
332 ;; this code does not seem to work for some POP servers... | 338 ;; this code does not seem to work for some POP servers... |
333 ;; and I cannot figure out why not. | 339 ;; and I cannot figure out why not. |
334 ; (goto-char (match-beginning 0)) | 340 ; (goto-char (match-beginning 0)) |