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"
45 ;; "po:username1@mailhost1.your.domain1"
52 ;; pop3-fma-spool-file-alist ... Spool file alist of POP3 protocol
53 ;; pop3-fma-movemail-type ... Type of movemail program.
57 ;; pop3-fma-movemail-arguments ... List of options of movemail program.
64 (unless (and (condition-case ()
70 (defmacro defgroup (&rest args))
71 (defmacro defcustom (symbol value &optional doc &rest args)
72 (` (defvar (, symbol) (, value) (, doc))))
75 (unless (and (fboundp 'pop3-fma-encode-string)
76 (fboundp 'pop3-fma-decode-string))
78 (fset 'pop3-fma-encode-string 'base64-encode-string)
79 (fset 'pop3-fma-decode-string 'base64-decode-string))
81 (defgroup pop3-fma nil
82 "Multile POP3 account utility for Gnus."
87 (defconst pop3-fma-version-number "0.21")
88 (defconst pop3-fma-codename
89 ;; "Feel the wind" ; 0.10
90 ;; "My home town" ; 0.11
91 ;; "On the road" ; 0.12
92 ;; "Rock'n Roll city" ; 0.13
96 ;; "Blood line" ; 0.xx
98 ;; "Goodbye Game" ; 0.xx
100 (defconst pop3-fma-version (format "Multiple POP3 account utiliy for Gnus v%s - \"%s\""
101 pop3-fma-version-number
104 (defcustom pop3-fma-spool-file-alist nil
105 "*Spool file to get mail using pop3 protocol.
106 You should specify this variable like
108 \"po:user1@mailhost1\"
109 \"po:user2@mailhost2\"
114 (defcustom pop3-fma-local-spool-file-alist nil
115 "*List of Local spool file to get mail."
119 (defcustom pop3-fma-movemail-type 'lisp
120 "*Type of movemail program.
121 Lisp means `nnmail-movemail-program' is lisp function.
122 Exe means `nnmail-movemail-program' is external program.
123 Please do not use exe if you do not use Meadow."
125 :type '(choice (const lisp)
128 (defcustom pop3-fma-movemail-arguments '("-pf")
129 "*Options for movemail."
131 :type '(repeat (string :tag "Argument")))
133 ;;; Internal variables.
134 (defvar pop3-fma-password nil
135 "*POP3 password , user , mailhost information for Gnus.")
137 (defvar pop3-fma-movemail-program "movemail.exe"
138 "*External program name your movemail.
139 Please do not set this valiable non-nil if you do not use Meadow.")
141 ;; Temporary variable
145 (defvar pop3-fma-movemail-options pop3-fma-movemail-arguments)
148 (defun pop3-fma-init-message-hook ()
149 (add-hook 'message-send-hook 'pop3-fma-message-add-header))
151 (eval-after-load "message"
152 '(pop3-fma-init-message-hook))
154 (add-hook 'gnus-after-exiting-gnus-hook
155 '(lambda () (setq pop3-fma-password nil)))
156 (add-hook 'gnus-before-startup-hook 'pop3-fma-set-pop3-password)
160 ;; Gnus POP3 additional utility...
162 (defun pop3-fma-movemail (inbox crashbox)
163 "Function to move mail from INBOX on a pop3 server to file CRASHBOX."
164 (if (string-match "^po:" inbox)
167 (substring inbox (match-end (string-match "^po:" inbox))
168 (- (match-end (string-match "^.*@" inbox)) 1)))
170 (substring inbox (match-end (string-match "^.*@" inbox)))))
172 (pop3-fma-read-passwd pop3-mailhost)))
173 (message "Checking new mail user %s at %s..." pop3-maildrop pop3-mailhost)
174 (if (and (eq system-type 'windows-nt)
175 (eq pop3-fma-movemail-type 'exe))
177 (setenv "MAILHOST" pop3-mailhost)
178 (if (and (not (memq pop3-password pop3-fma-movemail-arguments))
179 (not (memq (concat "po:" pop3-maildrop) pop3-fma-movemail-arguments)))
181 (setq pop3-fma-movemail-arguments nil)
182 (setq pop3-fma-movemail-arguments
183 (append pop3-fma-movemail-options
185 (concat "po:" pop3-maildrop)
188 (apply 'call-process (concat
190 pop3-fma-movemail-program)
192 pop3-fma-movemail-arguments))
193 (pop3-movemail crashbox)))))
194 (message "Checking new mail at %s ... " inbox)
195 (call-process (concat exec-directory pop3-fma-movemail-program)
201 (message "Checking new mail at %s ... done." inbox)))
204 (defun pop3-fma-read-passwd (mailhost)
205 (setq passwd (nth 2 (assoc mailhost pop3-fma-password)))
206 (pop3-fma-decode-string passwd))
208 (setq pop3-read-passwd 'pop3-fma-read-passwd)
210 ;; Set multiple pop3 server's password
211 (defun pop3-fma-store-password (passwd)
213 (list (pop3-fma-read-noecho
214 (format "POP Password for %s at %s: " pop3-maildrop pop3-mailhost) t)))
215 (if (not (assoc pop3-mailhost pop3-fma-password))
216 (setq pop3-fma-password
217 (append pop3-fma-password
222 (pop3-fma-encode-string passwd)))))
223 (setcar (cdr (cdr (assoc pop3-mailhost pop3-fma-password)))
224 (pop3-fma-encode-string passwd)))
225 (message "POP password registered.")
226 (pop3-fma-encode-string passwd))
229 (defun pop3-fma-set-pop3-password()
234 (substring x (match-end (string-match "^po:" x))
235 (- (match-end (string-match "^.*@" x)) 1)))
237 (substring x (match-end (string-match "^.*@" x)))))
238 (call-interactively 'pop3-fma-store-password)))
239 pop3-fma-spool-file-alist)
240 (setq nnmail-movemail-program 'pop3-fma-movemail)
241 ;; (setq nnmail-spool-file pop3-fma-spool-file-alist))
242 (setq nnmail-spool-file (append
243 pop3-fma-local-spool-file-alist
244 pop3-fma-spool-file-alist)))
246 (defun pop3-fma-read-noecho (prompt &optional stars)
247 "Read a single line of text from user without echoing, and return it.
252 (cursor-in-echo-area t)
253 (log-message-max-size 0)
254 message-log-max done msg truncate)
256 (if (or (not stars) (string-equal "" ans))
258 (setq msg (concat prompt (make-string (length ans) ?*)))
260 (1+ (- (length msg) (window-width (minibuffer-window)))))
262 (setq msg (concat "$" (substring msg (1+ truncate))))))
264 (setq c (read-char-exclusive))
268 ((or (= c ?\r) (= c ?\n) (= c ?\e))
272 ((and (/= c ?\b) (/= c ?\177))
273 (setq ans (concat ans (char-to-string c))))
275 (setq ans (substring ans 0 -1)))))
285 (defun pop3-fma-message-add-header ()
287 (pop3-fma-add-custom-header "X-Ya-Pop3:" pop3-fma-version)))
290 ;; Add your custom header.
292 (defun pop3-fma-add-custom-header (header string)
294 (progn (goto-char (point-min))
296 (concat "^" (regexp-quote mail-header-separator) "\n"))
298 (goto-char (point-min))
299 (or (re-search-forward (concat "^" header) delimline t)
301 (goto-char delimline)
304 (setq hdr (concat header " "))
305 (setq str (concat hdr string))
306 (setq hdr (concat str "\n"))
307 (insert-string hdr)))))
311 ;; pop3-fma.el ends here.