1 ;; pop3-fma.el.el --- POP3 for Multiple Account for Gnus.
2 ;; Copyright (C) 1996,97,98 Free Software Foundation, Inc. , Tatsuya Ichikawa
4 ;; Author: Tatsuya Ichikawa <t-ichi@po.shiojiri.ne.jp>
5 ;; Yasuo OKABE <okabe@kuis.kyoto-u.ac.jp>
7 ;; Keywords: mail , gnus , pop3
10 ;; Keiichi Suzuki <kei-suzu@mail.wbs.or.jp>
11 ;; Katsumi Yamaoka <yamaoka@jpl.org>
13 ;; This file is not part of GNU Emacs.
15 ;; GNU Emacs is free software; you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation; either version 2, or (at your option)
20 ;; GNU Emacs is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;; GNU General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28 ;; Boston, MA 02111-1307, USA.
34 ;; This file store pop3 password in variable "pop3-fma-password".
35 ;; Please take care by yourself to treat pop3 password.
39 ;; add your .emacs following codes.
41 ;; (require 'pop3-fma)
42 ;; (setq pop3-fma-spool-file-alist
44 ;; ("po:username0@mailhost0.your.domain0" pass)
45 ;; ("po:username1@mailhost1.your.domain1" apop)
50 ;; pass means normal authentication USER/PASS.
51 ;; apop means authentication using APOP.
53 ;; When using apop , Please set pop3-fma-movemail-type 'lisp.
54 ;; movemail.exe does not work on APOP protocol.
58 ;; pop3-fma-spool-file-alist ... Spool file alist of POP3 protocol
59 ;; pop3-fma-movemail-type ... Type of movemail program.
63 ;; pop3-fma-movemail-arguments ... List of options of movemail program.
70 (unless (and (condition-case ()
76 (defmacro defgroup (&rest args))
77 (defmacro defcustom (symbol value &optional doc &rest args)
78 (` (defvar (, symbol) (, value) (, doc))))
81 (defgroup pop3-fma nil
82 "Multile POP3 account utility for Gnus."
87 (defconst pop3-fma-version-number "1.16")
88 (defconst pop3-fma-codename
90 ;; "Blood line" ; 1.10
92 ;; "Goodbye Game" ; 1.12
93 ;; "Love is Gamble" ; 1.13
95 "Feel the wind" ; 1.16
97 (defconst pop3-fma-version (format "Multiple POP3 account utiliy for Gnus v%s - \"%s\""
98 pop3-fma-version-number
101 (defcustom pop3-fma-spool-file-alist nil
102 "*Spool file to get mail using pop3 protocol.
103 You should specify this variable like
105 (\"po:user1@mailhost1\" type)
106 (\"po:user2@mailhost2\" type)
108 Type must be pass or apop."
112 (defcustom pop3-fma-local-spool-file-alist nil
113 "*List of Local spool file to get mail."
117 (defcustom pop3-fma-movemail-type 'lisp
118 "*Type of movemail program.
119 Lisp means `nnmail-movemail-program' is lisp function.
120 Exe means `nnmail-movemail-program' is external program.
121 Please do not use exe if you do not use Meadow."
123 :type '(choice (const lisp)
126 (defcustom pop3-fma-movemail-arguments '("-pf")
127 "*Options for movemail."
129 :type '(repeat (string :tag "Argument")))
131 (defcustom pop3-fma-save-password-information nil
132 "*If non nil , save POP Server's password information.
133 ============== Important notice =====================
134 Please take care of your password information.
135 If set to t , your pop3 password is saved in pop3-fma-password in raw text.
136 So , Anybody can see this information by describe-variable.
137 If there is any problem , please set this variable to nil(default).
138 ============== Important notice ====================="
142 ;;; Internal variables.
143 (defvar pop3-fma-password nil
144 "*POP3 password , user , mailhost information for Gnus.")
146 (defvar pop3-fma-movemail-program
147 (if (eq system-type 'windows-nt)
150 "*External program name your movemail.")
153 ;; Temporary variable
158 (defvar movemail-output-buffer " *movemail-out*")
159 (defvar pop3-fma-commandline-arguments nil)
161 ;;; To silence byte compiler
163 (fboundp 'eval-when-compile)
167 (eval-region (point-min) (point)))
168 (let (case-fold-search)
172 (unless (boundp symbol)
173 (make-local-variable symbol)
174 (eval (list 'setq symbol nil)))))
180 (make-local-variable 'byte-compile-warnings)
181 (setq byte-compile-warnings nil))))
183 (defun pop3-fma-init-message-hook ()
184 (add-hook 'message-send-hook 'pop3-fma-message-add-header))
186 (eval-after-load "message"
187 '(pop3-fma-init-message-hook))
189 (add-hook 'gnus-after-exiting-gnus-hook
190 '(lambda () (setq pop3-fma-password nil)))
191 (add-hook 'gnus-before-startup-hook 'pop3-fma-set-pop3-password)
195 ;; Gnus POP3 additional utility...
197 (defun pop3-fma-movemail (inbox crashbox)
198 "Function to move mail from INBOX on a pop3 server to file CRASHBOX."
199 (if (string-match "^po:" inbox)
202 (substring inbox (match-end (string-match "^po:" inbox))
203 (- (match-end (string-match "^.*@" inbox)) 1)))
205 (substring inbox (match-end (string-match "^.*@" inbox))))
207 (if pop3-fma-save-password-information
208 (pop3-fma-read-passwd (substring inbox (match-end (string-match "^.*@" inbox))))
209 (pop3-fma-input-password
210 (substring inbox (match-end (string-match "^.*@" inbox)))
211 (substring inbox (match-end (string-match "^po:" inbox))
212 (- (match-end (string-match "^.*@" inbox)) 1)))))
213 (pop3-authentication-scheme
214 (nth 1 (assoc inbox pop3-fma-spool-file-alist)))
215 (pop3-fma-movemail-type (pop3-fma-get-movemail-type inbox)))
216 (if (eq pop3-authentication-scheme 'pass)
217 (message "Checking new mail user %s at %s using USER/PASS ..." pop3-maildrop pop3-mailhost)
218 (message "Checking new mail user %s at %s using APOP ..." pop3-maildrop pop3-mailhost))
219 (if (and (eq system-type 'windows-nt)
220 (eq pop3-fma-movemail-type 'exe))
222 (setenv "MAILHOST" pop3-mailhost)
223 (if (and (not (memq pop3-password pop3-fma-commandline-arguments))
224 (not (memq (concat "po:" pop3-maildrop) pop3-fma-commandline-arguments)))
226 (setq pop3-fma-commandline-arguments
228 pop3-fma-movemail-arguments
230 (concat "po:" pop3-maildrop)
233 (if (not (get-buffer movemail-output-buffer))
234 (get-buffer-create movemail-output-buffer))
235 (set-buffer movemail-output-buffer)
237 (apply 'call-process (concat
239 pop3-fma-movemail-program)
240 nil movemail-output-buffer nil
241 pop3-fma-commandline-arguments)
242 (let ((string (buffer-string)))
243 (if (> (length string) 0)
246 (concat (substring string 0
247 (- (length string) 1))
251 (pop3-movemail crashbox))))
252 (message "Checking new mail at %s ... " inbox)
253 (call-process (concat exec-directory pop3-fma-movemail-program)
259 (message "Checking new mail at %s ... done." inbox)))
262 (defun pop3-fma-read-passwd (mailhost)
263 (setq passwd (nth 2 (assoc mailhost pop3-fma-password)))
266 (defun pop3-fma-input-password (mailhost maildrop)
267 (pop3-fma-read-noecho
268 (format "POP Password for %s at %s: " maildrop mailhost) t))
270 (setq pop3-read-passwd 'pop3-fma-read-passwd
271 nnmail-read-passwd 'pop3-fma-read-passwd)
273 ;; Set multiple pop3 server's password
274 (defun pop3-fma-store-password (passwd)
276 (list (pop3-fma-read-noecho
277 (format "POP Password for %s at %s: " pop3-maildrop pop3-mailhost) t)))
278 (if (not (assoc pop3-mailhost pop3-fma-password))
279 (setq pop3-fma-password
280 (append pop3-fma-password
286 (setcar (cdr (cdr (assoc pop3-mailhost pop3-fma-password)))
288 (message "POP password registered.")
292 (defun pop3-fma-set-pop3-password()
294 (if pop3-fma-save-password-information
299 (substring (car x) (match-end (string-match "^po:" (car x)))
300 (- (match-end (string-match "^.*@" (car x))) 1)))
302 (substring (car x) (match-end (string-match "^.*@" (car x))))))
303 (call-interactively 'pop3-fma-store-password)))
304 pop3-fma-spool-file-alist)))
305 (setq nnmail-movemail-program 'pop3-fma-movemail)
306 ;; (setq nnmail-spool-file pop3-fma-spool-file-alist))
307 (setq nnmail-spool-file (append
308 pop3-fma-local-spool-file-alist
312 pop3-fma-spool-file-alist))))
314 (defmacro pop3-fma-read-char-exclusive ()
315 (cond ((featurep 'xemacs)
316 '(let ((table (quote ((backspace . ?\C-h) (delete . ?\C-?)
321 (key-press-event-p (setq event (next-command-event)))
322 (setq key (or (event-to-character event)
323 (cdr (assq (event-key event) table)))))))
325 ((fboundp 'read-char-exclusive)
326 '(read-char-exclusive))
330 (defun pop3-fma-read-noecho (prompt &optional stars)
331 "Read a single line of text from user without echoing, and return it.
336 (cursor-in-echo-area t)
337 (log-message-max-size 0)
338 message-log-max done msg truncate)
340 (if (or (not stars) (string-equal "" ans))
342 (setq msg (concat prompt (make-string (length ans) ?*)))
344 (1+ (- (length msg) (window-width (minibuffer-window)))))
346 (setq msg (concat "$" (substring msg (1+ truncate))))))
348 (setq c (pop3-fma-read-char-exclusive))
352 ((memq c '(?\r ?\n ?\e))
356 ((and (/= ?\b c) (/= ?\177 c))
357 (setq ans (concat ans (char-to-string c))))
359 (setq ans (substring ans 0 -1)))))
369 (defun pop3-fma-message-add-header ()
371 (pop3-fma-add-custom-header "X-Ya-Pop3:" pop3-fma-version)))
374 ;; Add your custom header.
375 (defun pop3-fma-add-custom-header (header string)
377 (progn (goto-char (point-min))
379 (concat "^" (regexp-quote mail-header-separator) "\n"))
381 (goto-char (point-min))
382 (or (re-search-forward (concat "^" header) delimline t)
384 (goto-char delimline)
387 (setq hdr (concat header " "))
388 (setq str (concat hdr string))
389 (setq hdr (concat str "\n"))
390 (insert-string hdr)))))
393 (defun pop3-fma-get-movemail-type (inbox)
394 (if (eq (nth 1 (assoc inbox pop3-fma-spool-file-alist)) 'apop)
396 pop3-fma-movemail-type))
400 ;; pop3-fma.el ends here.