1 ;; pop3-fma.el.el --- POP3 for Multiple Account for Gnus.
2 ;; Copyright (C) 1996,97,98 Free Software Foundation, Inc. , Tatsuya Ichikawa
3 ;; Author: Tatsuya Ichikawa <t-ichi@po.shiojiri.ne.jp>
5 ;; Keywords: mail , gnus , pop3
8 ;; Keiichi Suzuki <kei-suzu@mail.wbs.or.jp>
9 ;; Katsumi Yamaoka <yamaoka@jpl.org>
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
33 ;; add your .emacs following codes.
35 ;; (autoload 'pop3-fma-set-pop3-password "pop3-fma")
36 ;; (setq pop3-fma-spool-file-alist
38 ;; "po:username0@mailhost0.your.domain0"
39 ;; "po:username1@mailhost1.your.domain1"
46 ;; pop3-fma-spool-file-alist ... Spool file alist of POP3 protocol
47 ;; pop3-fma-movemail-type ... Type of movemail program.
51 ;; pop3-fma-movemail-arguments ... List of options of movemail program.
58 (unless (and (condition-case ()
64 (defmacro defgroup (&rest args))
65 (defmacro defcustom (symbol value &optional doc &rest args)
66 (` (defvar (, symbol) (, value) (, doc))))
69 (defgroup pop3-fma nil
70 "Multile POP3 account utility for Gnus."
75 (defconst pop3-fma-version-number "0.13")
76 (defconst pop3-fma-codename
77 ;; "Feel the wind" ; 0.10
78 ;; "My home town" ; 0.11
79 ;; "On the road" ; 0.12
80 "Rock'n Roll city" ; 0.13
82 ;; "Midnight blue train" ; 0.xx
85 ;; "Blood line" ; 0.xx
87 ;; "Goodbye Game" ; 0.xx
89 (defconst pop3-fma-version (format "Multiple POP3 account utiliy for Gnus v%s - \"%s\""
90 pop3-fma-version-number
93 (defcustom pop3-fma-spool-file-alist nil
94 "*Spoolfile to get mail using pop3 protocol.
95 You should specify this variable like
97 \"po:user1@mailhost1\"
98 \"po:user2@mailhost2\"
103 (defcustom pop3-fma-movemail-type 'lisp
104 "*Type of movemail program.
105 Lisp means `nnmail-movemail-program' is lisp function.
106 Exe means `nnmail-movemail-program' is external program.
107 Please do not use exe if you do not use Meadow."
109 :type '(choice (const lisp)
112 (defcustom pop3-fma-movemail-arguments '("-pf")
113 "*Options for movemail."
115 :type '(repeat (string :tag "Argument")))
117 ;;; Internal variables.
118 (defvar pop3-fma-password nil
119 "*POP3 password , user , mailhost information for Gnus.")
121 (defvar pop3-fma-movemail-program "movemail.exe"
122 "*External program name your movemail.
123 Please do not set this valiable non-nil if you do not use Meadow.")
125 ;; Temporary variable
129 (defvar pop3-fma-movemail-options pop3-fma-movemail-arguments)
130 (defvar pop3-fma-cypher-key (1+ (random 92)))
132 (defun pop3-fma-init-hooks ()
133 (add-hook 'message-send-hook 'pop3-fma-message-add-header))
135 (eval-after-load "message"
136 '(pop3-fma-init-hooks))
138 (add-hook 'gnus-after-exiting-gnus-hook
139 '(lambda () (setq pop3-fma-password nil)))
140 (add-hook 'gnus-before-startup-hook 'pop3-fma-set-pop3-password)
143 ;; Gnus POP3 additional utility...
145 (defun pop3-fma-movemail (inbox crashbox)
146 "Function to move mail from INBOX on a pop3 server to file CRASHBOX."
148 (substring inbox (match-end (string-match "^po:" inbox))
149 (- (match-end (string-match "^.*@" inbox)) 1)))
151 (substring inbox (match-end (string-match "^.*@" inbox)))))
153 (pop3-fma-read-passwd pop3-mailhost)))
154 (message "Checking new mail user %s at %s..." pop3-maildrop pop3-mailhost)
155 (if (and (eq system-type 'windows-nt)
156 (eq pop3-fma-movemail-type 'exe))
158 (setenv "MAILHOST" pop3-mailhost)
159 (if (and (not (memq pop3-password pop3-fma-movemail-arguments))
160 (not (memq (concat "po:" pop3-maildrop) pop3-fma-movemail-arguments)))
162 (setq pop3-fma-movemail-arguments nil)
163 (setq pop3-fma-movemail-arguments
164 (append pop3-fma-movemail-options
166 (concat "po:" pop3-maildrop)
169 (apply 'call-process (concat
171 pop3-fma-movemail-program)
173 pop3-fma-movemail-arguments))
174 (pop3-movemail crashbox)))))
177 (defun pop3-fma-read-passwd (mailhost)
178 (setq passwd (nth 2 (assoc mailhost pop3-fma-password)))
179 (pop3-fma-cypher-string passwd nil t))
181 (setq pop3-read-passwd 'pop3-fma-read-passwd)
183 ;; Set multiple pop3 server's password
184 (defun pop3-fma-store-password (passwd)
186 (list (pop3-fma-read-noecho
187 (format "POP Password for %s at %s: " pop3-maildrop pop3-mailhost) t)))
188 (if (not (assoc pop3-mailhost pop3-fma-password))
189 (setq pop3-fma-password
190 (append pop3-fma-password
195 (pop3-fma-cypher-string passwd)))))
196 (setcar (cdr (cdr (assoc pop3-mailhost pop3-fma-password)))
198 (message "POP password registered.")
202 (defun pop3-fma-set-pop3-password()
207 (substring x (match-end (string-match "^po:" x))
208 (- (match-end (string-match "^.*@" x)) 1)))
210 (substring x (match-end (string-match "^.*@" x)))))
211 (call-interactively 'pop3-fma-store-password)))
212 pop3-fma-spool-file-alist)
213 (setq nnmail-movemail-program 'pop3-fma-movemail)
214 (setq nnmail-spool-file pop3-fma-spool-file-alist))
216 (defun pop3-fma-read-noecho (prompt &optional stars)
217 "Read a single line of text from user without echoing, and return it.
222 (cursor-in-echo-area t)
223 (log-message-max-size 0)
224 message-log-max done msg truncate)
226 (if (or (not stars) (string-equal "" ans))
228 (setq msg (concat prompt (make-string (length ans) ?*)))
230 (1+ (- (length msg) (window-width (minibuffer-window)))))
232 (setq msg (concat "$" (substring msg (1+ truncate))))))
234 (setq c (read-char-exclusive))
238 ((or (= c ?\r) (= c ?\n) (= c ?\e))
242 ((and (/= c ?\b) (/= c ?\177))
243 (setq ans (concat ans (char-to-string c))))
245 (setq ans (substring ans 0 -1)))))
255 (defun pop3-fma-message-add-header ()
257 (pop3-fma-add-custom-header "X-Ya-Pop3:" pop3-fma-version)))
260 ;; Add your custom header.
262 (defun pop3-fma-add-custom-header (header string)
264 (progn (goto-char (point-min))
266 (concat "^" (regexp-quote mail-header-separator) "\n"))
268 (goto-char (point-min))
269 (or (re-search-forward (concat "^" header) delimline t)
271 (goto-char delimline)
274 (setq hdr (concat header " "))
275 (setq str (concat hdr string))
276 (setq hdr (concat str "\n"))
277 (insert-string hdr)))))
279 ;; Crypt password string
281 (defun pop3-fma-cypher-string (string &optional key flag)
284 (rot (if flag (- 94 (or key pop3-fma-cypher-key 13))
285 (or key pop3-fma-cypher-key 13))))
290 ((and (<= 32 x) (<= x 126))
297 (t (char-to-string x)))))
299 (string-to-char-list string))
304 ;; pop3-fma.el ends here.