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 (unless (and (fboundp 'pop3-fma-encode-string)
82 (fboundp 'pop3-fma-decode-string))
84 (fset 'pop3-fma-encode-string 'base64-encode-string)
85 (fset 'pop3-fma-decode-string 'base64-decode-string))
87 (defgroup pop3-fma nil
88 "Multile POP3 account utility for Gnus."
93 (defconst pop3-fma-version-number "1.11")
94 (defconst pop3-fma-codename
95 ;; "Feel the wind" ; 0.10
96 ;; "My home town" ; 0.11
97 ;; "On the road" ; 0.12
98 ;; "Rock'n Roll city" ; 0.13
102 ;; "Blood line" ; 1.10
104 ;; "Goodbye Game" ; 0.xx
106 (defconst pop3-fma-version (format "Multiple POP3 account utiliy for Gnus v%s - \"%s\""
107 pop3-fma-version-number
110 (defcustom pop3-fma-spool-file-alist nil
111 "*Spool file to get mail using pop3 protocol.
112 You should specify this variable like
114 (\"po:user1@mailhost1\" type)
115 (\"po:user2@mailhost2\" type)
117 Type must be pass or apop."
121 (defcustom pop3-fma-local-spool-file-alist nil
122 "*List of Local spool file to get mail."
126 (defcustom pop3-fma-movemail-type 'lisp
127 "*Type of movemail program.
128 Lisp means `nnmail-movemail-program' is lisp function.
129 Exe means `nnmail-movemail-program' is external program.
130 Please do not use exe if you do not use Meadow."
132 :type '(choice (const lisp)
135 (defcustom pop3-fma-movemail-arguments '("-pf")
136 "*Options for movemail."
138 :type '(repeat (string :tag "Argument")))
140 ;;; Internal variables.
141 (defvar pop3-fma-password nil
142 "*POP3 password , user , mailhost information for Gnus.")
144 (defvar pop3-fma-movemail-program "movemail.exe"
145 "*External program name your movemail.
146 Please do not set this valiable non-nil if you do not use Meadow.")
148 ;; Temporary variable
152 (defvar pop3-fma-movemail-options pop3-fma-movemail-arguments)
154 (defvar movemail-output-buffer " *movemail-out*")
156 (defun pop3-fma-init-message-hook ()
157 (add-hook 'message-send-hook 'pop3-fma-message-add-header))
159 (eval-after-load "message"
160 '(pop3-fma-init-message-hook))
162 (add-hook 'gnus-after-exiting-gnus-hook
163 '(lambda () (setq pop3-fma-password nil)))
164 (add-hook 'gnus-before-startup-hook 'pop3-fma-set-pop3-password)
168 ;; Gnus POP3 additional utility...
170 (defun pop3-fma-movemail (inbox crashbox)
171 "Function to move mail from INBOX on a pop3 server to file CRASHBOX."
172 (if (string-match "^po:" inbox)
175 (substring inbox (match-end (string-match "^po:" inbox))
176 (- (match-end (string-match "^.*@" inbox)) 1)))
178 (substring inbox (match-end (string-match "^.*@" inbox))))
180 (pop3-fma-read-passwd (substring inbox (match-end (string-match "^.*@" inbox)))))
181 (pop3-authentication-scheme
182 (nth 1 (assoc inbox pop3-fma-spool-file-alist)))
183 (pop3-fma-movemail-type (pop3-fma-get-movemail-type inbox)))
184 (if (eq pop3-authentication-scheme 'pass)
185 (message "Checking new mail user %s at %s using USER/PASS ..." pop3-maildrop pop3-mailhost)
186 (message "Checking new mail user %s at %s using APOP ..." pop3-maildrop pop3-mailhost))
187 (if (and (eq system-type 'windows-nt)
188 (eq pop3-fma-movemail-type 'exe))
190 (setenv "MAILHOST" pop3-mailhost)
191 (if (and (not (memq pop3-password pop3-fma-movemail-arguments))
192 (not (memq (concat "po:" pop3-maildrop) pop3-fma-movemail-arguments)))
194 (setq pop3-fma-movemail-arguments nil)
195 (setq pop3-fma-movemail-arguments
196 (append pop3-fma-movemail-options
198 (concat "po:" pop3-maildrop)
201 (if (not (get-buffer movemail-output-buffer))
202 (get-buffer-create movemail-output-buffer))
203 (set-buffer movemail-output-buffer)
205 (apply 'call-process (concat
207 pop3-fma-movemail-program)
208 nil movemail-output-buffer nil
209 pop3-fma-movemail-arguments)
210 (let ((string (buffer-string)))
211 (if (> (length string) 0)
214 (concat (substring string 0
215 (- (length string) 1))
219 (pop3-movemail crashbox))))
220 (message "Checking new mail at %s ... " inbox)
221 (call-process (concat exec-directory pop3-fma-movemail-program)
227 (message "Checking new mail at %s ... done." inbox)))
230 (defun pop3-fma-read-passwd (mailhost)
231 (setq passwd (nth 2 (assoc mailhost pop3-fma-password)))
232 (pop3-fma-decode-string passwd))
234 (setq pop3-read-passwd 'pop3-fma-read-passwd)
236 ;; Set multiple pop3 server's password
237 (defun pop3-fma-store-password (passwd)
239 (list (pop3-fma-read-noecho
240 (format "POP Password for %s at %s: " pop3-maildrop pop3-mailhost) t)))
241 (if (not (assoc pop3-mailhost pop3-fma-password))
242 (setq pop3-fma-password
243 (append pop3-fma-password
248 (pop3-fma-encode-string passwd)))))
249 (setcar (cdr (cdr (assoc pop3-mailhost pop3-fma-password)))
250 (pop3-fma-encode-string passwd)))
251 (message "POP password registered.")
252 (pop3-fma-encode-string passwd))
255 (defun pop3-fma-set-pop3-password()
260 (substring (car x) (match-end (string-match "^po:" (car x)))
261 (- (match-end (string-match "^.*@" (car x))) 1)))
263 (substring (car x) (match-end (string-match "^.*@" (car x))))))
264 (call-interactively 'pop3-fma-store-password)))
265 pop3-fma-spool-file-alist)
266 (setq nnmail-movemail-program 'pop3-fma-movemail)
267 ;; (setq nnmail-spool-file pop3-fma-spool-file-alist))
268 (setq nnmail-spool-file (append
269 pop3-fma-local-spool-file-alist
273 pop3-fma-spool-file-alist))))
275 (defun pop3-fma-read-noecho (prompt &optional stars)
276 "Read a single line of text from user without echoing, and return it.
281 (cursor-in-echo-area t)
282 (log-message-max-size 0)
283 message-log-max done msg truncate)
285 (if (or (not stars) (string-equal "" ans))
287 (setq msg (concat prompt (make-string (length ans) ?*)))
289 (1+ (- (length msg) (window-width (minibuffer-window)))))
291 (setq msg (concat "$" (substring msg (1+ truncate))))))
293 (setq c (read-char-exclusive))
297 ((or (= c ?\r) (= c ?\n) (= c ?\e))
301 ((and (/= c ?\b) (/= c ?\177))
302 (setq ans (concat ans (char-to-string c))))
304 (setq ans (substring ans 0 -1)))))
314 (defun pop3-fma-message-add-header ()
316 (pop3-fma-add-custom-header "X-Ya-Pop3:" pop3-fma-version)))
319 ;; Add your custom header.
320 (defun pop3-fma-add-custom-header (header string)
322 (progn (goto-char (point-min))
324 (concat "^" (regexp-quote mail-header-separator) "\n"))
326 (goto-char (point-min))
327 (or (re-search-forward (concat "^" header) delimline t)
329 (goto-char delimline)
332 (setq hdr (concat header " "))
333 (setq str (concat hdr string))
334 (setq hdr (concat str "\n"))
335 (insert-string hdr)))))
338 (defun pop3-fma-get-movemail-type (inbox)
339 (if (eq (nth 1 (assoc inbox pop3-fma-spool-file-alist)) 'apop)
341 pop3-fma-movemail-type))
345 ;; pop3-fma.el ends here.