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.20")
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
94 ;; "Midnight blue train" ; 0.xx
97 ;; "Blood line" ; 0.xx
99 ;; "Goodbye Game" ; 0.xx
101 (defconst pop3-fma-version (format "Multiple POP3 account utiliy for Gnus v%s - \"%s\""
102 pop3-fma-version-number
105 (defcustom pop3-fma-spool-file-alist nil
106 "*Spoolfile to get mail using pop3 protocol.
107 You should specify this variable like
109 \"po:user1@mailhost1\"
110 \"po:user2@mailhost2\"
115 (defcustom pop3-fma-movemail-type 'lisp
116 "*Type of movemail program.
117 Lisp means `nnmail-movemail-program' is lisp function.
118 Exe means `nnmail-movemail-program' is external program.
119 Please do not use exe if you do not use Meadow."
121 :type '(choice (const lisp)
124 (defcustom pop3-fma-movemail-arguments '("-pf")
125 "*Options for movemail."
127 :type '(repeat (string :tag "Argument")))
129 ;;; Internal variables.
130 (defvar pop3-fma-password nil
131 "*POP3 password , user , mailhost information for Gnus.")
133 (defvar pop3-fma-movemail-program "movemail.exe"
134 "*External program name your movemail.
135 Please do not set this valiable non-nil if you do not use Meadow.")
137 ;; Temporary variable
141 (defvar pop3-fma-movemail-options pop3-fma-movemail-arguments)
143 (defun pop3-fma-init-message-hook ()
144 (add-hook 'message-send-hook 'pop3-fma-message-add-header))
146 (eval-after-load "message"
147 '(pop3-fma-init-message-hook))
149 (add-hook 'gnus-after-exiting-gnus-hook
150 '(lambda () (setq pop3-fma-password nil)))
151 (add-hook 'gnus-before-startup-hook 'pop3-fma-set-pop3-password)
155 ;; Gnus POP3 additional utility...
157 (defun pop3-fma-movemail (inbox crashbox)
158 "Function to move mail from INBOX on a pop3 server to file CRASHBOX."
160 (substring inbox (match-end (string-match "^po:" inbox))
161 (- (match-end (string-match "^.*@" inbox)) 1)))
163 (substring inbox (match-end (string-match "^.*@" inbox)))))
165 (pop3-fma-read-passwd pop3-mailhost)))
166 (message "Checking new mail user %s at %s..." pop3-maildrop pop3-mailhost)
167 (if (and (eq system-type 'windows-nt)
168 (eq pop3-fma-movemail-type 'exe))
170 (setenv "MAILHOST" pop3-mailhost)
171 (if (and (not (memq pop3-password pop3-fma-movemail-arguments))
172 (not (memq (concat "po:" pop3-maildrop) pop3-fma-movemail-arguments)))
174 (setq pop3-fma-movemail-arguments nil)
175 (setq pop3-fma-movemail-arguments
176 (append pop3-fma-movemail-options
178 (concat "po:" pop3-maildrop)
181 (apply 'call-process (concat
183 pop3-fma-movemail-program)
185 pop3-fma-movemail-arguments))
186 (pop3-movemail crashbox)))))
189 (defun pop3-fma-read-passwd (mailhost)
190 (setq passwd (nth 2 (assoc mailhost pop3-fma-password)))
191 (pop3-fma-decode-string passwd))
193 (setq pop3-read-passwd 'pop3-fma-read-passwd)
195 ;; Set multiple pop3 server's password
196 (defun pop3-fma-store-password (passwd)
198 (list (pop3-fma-read-noecho
199 (format "POP Password for %s at %s: " pop3-maildrop pop3-mailhost) t)))
200 (if (not (assoc pop3-mailhost pop3-fma-password))
201 (setq pop3-fma-password
202 (append pop3-fma-password
207 (pop3-fma-encode-string passwd)))))
208 (setcar (cdr (cdr (assoc pop3-mailhost pop3-fma-password)))
209 (pop3-fma-encode-string passwd)))
210 (message "POP password registered.")
211 (pop3-fma-encode-string passwd))
214 (defun pop3-fma-set-pop3-password()
219 (substring x (match-end (string-match "^po:" x))
220 (- (match-end (string-match "^.*@" x)) 1)))
222 (substring x (match-end (string-match "^.*@" x)))))
223 (call-interactively 'pop3-fma-store-password)))
224 pop3-fma-spool-file-alist)
225 (setq nnmail-movemail-program 'pop3-fma-movemail)
226 (setq nnmail-spool-file pop3-fma-spool-file-alist))
228 (defun pop3-fma-read-noecho (prompt &optional stars)
229 "Read a single line of text from user without echoing, and return it.
234 (cursor-in-echo-area t)
235 (log-message-max-size 0)
236 message-log-max done msg truncate)
238 (if (or (not stars) (string-equal "" ans))
240 (setq msg (concat prompt (make-string (length ans) ?*)))
242 (1+ (- (length msg) (window-width (minibuffer-window)))))
244 (setq msg (concat "$" (substring msg (1+ truncate))))))
246 (setq c (read-char-exclusive))
250 ((or (= c ?\r) (= c ?\n) (= c ?\e))
254 ((and (/= c ?\b) (/= c ?\177))
255 (setq ans (concat ans (char-to-string c))))
257 (setq ans (substring ans 0 -1)))))
267 (defun pop3-fma-message-add-header ()
269 (pop3-fma-add-custom-header "X-Ya-Pop3:" pop3-fma-version)))
272 ;; Add your custom header.
274 (defun pop3-fma-add-custom-header (header string)
276 (progn (goto-char (point-min))
278 (concat "^" (regexp-quote mail-header-separator) "\n"))
280 (goto-char (point-min))
281 (or (re-search-forward (concat "^" header) delimline t)
283 (goto-char delimline)
286 (setq hdr (concat header " "))
287 (setq str (concat hdr string))
288 (setq hdr (concat str "\n"))
289 (insert-string hdr)))))
293 ;; pop3-fma.el ends here.