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
96 "Sadness like snow" ; 1.17
98 (defconst pop3-fma-version (format "Multiple POP3 account utiliy for Gnus v%s - \"%s\""
99 pop3-fma-version-number
102 (defcustom pop3-fma-spool-file-alist nil
103 "*Spool file to get mail using pop3 protocol.
104 You should specify this variable like
106 (\"po:user1@mailhost1\" type)
107 (\"po:user2@mailhost2\" type)
109 Type must be pass or apop."
113 (defcustom pop3-fma-local-spool-file-alist nil
114 "*List of Local spool file to get mail."
118 (defcustom pop3-fma-movemail-type 'lisp
119 "*Type of movemail program.
120 Lisp means `nnmail-movemail-program' is lisp function.
121 Exe means `nnmail-movemail-program' is external program.
122 Please do not use exe if you do not use Meadow."
124 :type '(choice (const lisp)
127 (defcustom pop3-fma-movemail-arguments '("-pf")
128 "*Options for movemail."
130 :type '(repeat (string :tag "Argument")))
132 (defcustom pop3-fma-save-password-information nil
133 "*If non nil , save POP Server's password information.
134 ============== Important notice =====================
135 Please take care of your password information.
136 If set to t , your pop3 password is saved in pop3-fma-password in raw text.
137 So , Anybody can see this information by describe-variable.
138 If there is any problem , please set this variable to nil(default).
139 ============== Important notice ====================="
143 ;;; Internal variables.
144 (defvar pop3-fma-password nil
145 "*POP3 password , user , mailhost information for Gnus.")
147 (defvar pop3-fma-movemail-program
148 (if (eq system-type 'windows-nt)
151 "*External program name your movemail.")
154 ;; Temporary variable
159 (defvar movemail-output-buffer " *movemail-out*")
160 (defvar pop3-fma-commandline-arguments nil)
162 ;;; To silence byte compiler
164 (fboundp 'eval-when-compile)
168 (eval-region (point-min) (point)))
169 (let (case-fold-search)
173 (unless (boundp symbol)
174 (make-local-variable symbol)
175 (eval (list 'setq symbol nil)))))
181 (make-local-variable 'byte-compile-warnings)
182 (setq byte-compile-warnings nil))))
184 (defun pop3-fma-init-message-hook ()
185 (add-hook 'message-send-hook 'pop3-fma-message-add-header))
187 (eval-after-load "message"
188 '(pop3-fma-init-message-hook))
190 (add-hook 'gnus-after-exiting-gnus-hook
191 '(lambda () (setq pop3-fma-password nil)))
192 (add-hook 'gnus-before-startup-hook 'pop3-fma-set-pop3-password)
196 ;; Gnus POP3 additional utility...
198 (defun pop3-fma-movemail (inbox crashbox)
199 "Function to move mail from INBOX on a pop3 server to file CRASHBOX."
200 (if (string-match "^po:" inbox)
203 (substring inbox (match-end (string-match "^po:" inbox))
204 (- (match-end (string-match "^.*@" inbox)) 1)))
206 (substring inbox (match-end (string-match "^.*@" inbox))))
208 (if pop3-fma-save-password-information
209 (pop3-fma-read-passwd (substring inbox (match-end (string-match "^.*@" inbox))))
210 (pop3-fma-input-password
211 (substring inbox (match-end (string-match "^.*@" inbox)))
212 (substring inbox (match-end (string-match "^po:" inbox))
213 (- (match-end (string-match "^.*@" inbox)) 1)))))
214 (pop3-authentication-scheme
215 (nth 1 (assoc inbox pop3-fma-spool-file-alist))))
216 ;; (pop3-fma-movemail-type (pop3-fma-get-movemail-type inbox)))
217 (if (eq pop3-authentication-scheme 'pass)
218 (message "Checking new mail user %s at %s using USER/PASS ..." pop3-maildrop pop3-mailhost)
219 (message "Checking new mail user %s at %s using APOP ..." pop3-maildrop pop3-mailhost))
220 (if (and (eq system-type 'windows-nt)
221 (eq pop3-fma-movemail-type 'exe))
223 (setenv "MAILHOST" pop3-mailhost)
224 (if (and (not (memq pop3-password pop3-fma-commandline-arguments))
225 (not (memq (concat "po:" pop3-maildrop) pop3-fma-commandline-arguments)))
227 (if (eq pop3-authentication-scheme 'apop)
228 (setq pop3-fma-commandline-arguments
230 pop3-fma-movemail-arguments
233 (concat "po:" pop3-maildrop)
236 (setq pop3-fma-commandline-arguments
238 pop3-fma-movemail-arguments
240 (concat "po:" pop3-maildrop)
243 (if (not (get-buffer movemail-output-buffer))
244 (get-buffer-create movemail-output-buffer))
245 (set-buffer movemail-output-buffer)
247 (apply 'call-process (concat
249 pop3-fma-movemail-program)
250 nil movemail-output-buffer nil
251 pop3-fma-commandline-arguments)
252 (let ((string (buffer-string)))
253 (if (> (length string) 0)
256 (concat (substring string 0
257 (- (length string) 1))
261 (pop3-movemail crashbox))))
262 (message "Checking new mail at %s ... " inbox)
263 (call-process (concat exec-directory pop3-fma-movemail-program)
269 (message "Checking new mail at %s ... done." inbox)))
272 (defun pop3-fma-read-passwd (mailhost)
273 (setq passwd (nth 2 (assoc mailhost pop3-fma-password)))
276 (defun pop3-fma-input-password (mailhost maildrop)
277 (pop3-fma-read-noecho
278 (format "POP Password for %s at %s: " maildrop mailhost) t))
280 (setq pop3-read-passwd 'pop3-fma-read-passwd
281 nnmail-read-passwd 'pop3-fma-read-passwd)
283 ;; Set multiple pop3 server's password
284 (defun pop3-fma-store-password (passwd)
286 (list (pop3-fma-read-noecho
287 (format "POP Password for %s at %s: " pop3-maildrop pop3-mailhost) t)))
288 (if (not (assoc pop3-mailhost pop3-fma-password))
289 (setq pop3-fma-password
290 (append pop3-fma-password
296 (setcar (cdr (cdr (assoc pop3-mailhost pop3-fma-password)))
298 (message "POP password registered.")
302 (defun pop3-fma-set-pop3-password()
304 (if pop3-fma-save-password-information
309 (substring (car x) (match-end (string-match "^po:" (car x)))
310 (- (match-end (string-match "^.*@" (car x))) 1)))
312 (substring (car x) (match-end (string-match "^.*@" (car x))))))
313 (call-interactively 'pop3-fma-store-password)))
314 pop3-fma-spool-file-alist)))
315 (setq nnmail-movemail-program 'pop3-fma-movemail)
316 ;; (setq nnmail-spool-file pop3-fma-spool-file-alist))
317 (setq nnmail-spool-file (append
318 pop3-fma-local-spool-file-alist
322 pop3-fma-spool-file-alist))))
324 (defmacro pop3-fma-read-char-exclusive ()
325 (cond ((featurep 'xemacs)
326 '(let ((table (quote ((backspace . ?\C-h) (delete . ?\C-?)
331 (key-press-event-p (setq event (next-command-event)))
332 (setq key (or (event-to-character event)
333 (cdr (assq (event-key event) table)))))))
335 ((fboundp 'read-char-exclusive)
336 '(read-char-exclusive))
340 (defun pop3-fma-read-noecho (prompt &optional stars)
341 "Read a single line of text from user without echoing, and return it.
346 (cursor-in-echo-area t)
347 (log-message-max-size 0)
348 message-log-max done msg truncate)
350 (if (or (not stars) (string-equal "" ans))
352 (setq msg (concat prompt (make-string (length ans) ?*)))
354 (1+ (- (length msg) (window-width (minibuffer-window)))))
356 (setq msg (concat "$" (substring msg (1+ truncate))))))
358 (setq c (pop3-fma-read-char-exclusive))
362 ((memq c '(?\r ?\n ?\e))
366 ((and (/= ?\b c) (/= ?\177 c))
367 (setq ans (concat ans (char-to-string c))))
369 (setq ans (substring ans 0 -1)))))
379 (defun pop3-fma-message-add-header ()
381 (pop3-fma-add-custom-header "X-Ya-Pop3:" pop3-fma-version)))
384 ;; Add your custom header.
385 (defun pop3-fma-add-custom-header (header string)
387 (progn (goto-char (point-min))
389 (concat "^" (regexp-quote mail-header-separator) "\n"))
391 (goto-char (point-min))
392 (or (re-search-forward (concat "^" header) delimline t)
394 (goto-char delimline)
397 (setq hdr (concat header " "))
398 (setq str (concat hdr string))
399 (setq hdr (concat str "\n"))
400 (insert-string hdr)))))
403 (defun pop3-fma-get-movemail-type (inbox)
404 (if (eq (nth 1 (assoc inbox pop3-fma-spool-file-alist)) 'apop)
406 pop3-fma-movemail-type))
410 ;; pop3-fma.el ends here.