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.10")
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
103 ;; "Star ring" ; 0.xx
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)
155 (defun pop3-fma-init-message-hook ()
156 (add-hook 'message-send-hook 'pop3-fma-message-add-header))
158 (eval-after-load "message"
159 '(pop3-fma-init-message-hook))
161 (add-hook 'gnus-after-exiting-gnus-hook
162 '(lambda () (setq pop3-fma-password nil)))
163 (add-hook 'gnus-before-startup-hook 'pop3-fma-set-pop3-password)
167 ;; Gnus POP3 additional utility...
169 (defun pop3-fma-movemail (inbox crashbox)
170 "Function to move mail from INBOX on a pop3 server to file CRASHBOX."
171 (if (string-match "^po:" inbox)
174 (substring inbox (match-end (string-match "^po:" inbox))
175 (- (match-end (string-match "^.*@" inbox)) 1)))
177 (substring inbox (match-end (string-match "^.*@" inbox)))))
179 (pop3-fma-read-passwd pop3-mailhost)))
180 (let ((pop3-authentication-scheme
181 (nth 1 (assoc inbox pop3-fma-spool-file-alist))))
182 (if (eq pop3-authentication-scheme 'pass)
183 (message "Checking new mail user %s at %s using USER/PASS ..." pop3-maildrop pop3-mailhost)
184 (message "Checking new mail user %s at %s using APOP ..." pop3-maildrop pop3-mailhost)
185 (setq pop3-fma-movemail-type 'lisp))
186 (if (and (eq system-type 'windows-nt)
187 (eq pop3-fma-movemail-type 'exe))
189 (setenv "MAILHOST" pop3-mailhost)
190 (if (and (not (memq pop3-password pop3-fma-movemail-arguments))
191 (not (memq (concat "po:" pop3-maildrop) pop3-fma-movemail-arguments)))
193 (setq pop3-fma-movemail-arguments nil)
194 (setq pop3-fma-movemail-arguments
195 (append pop3-fma-movemail-options
197 (concat "po:" pop3-maildrop)
200 (apply 'call-process (concat
202 pop3-fma-movemail-program)
204 pop3-fma-movemail-arguments))
205 (pop3-movemail crashbox))))))
206 (message "Checking new mail at %s ... " inbox)
207 (call-process (concat exec-directory pop3-fma-movemail-program)
213 (message "Checking new mail at %s ... done." inbox)))
216 (defun pop3-fma-read-passwd (mailhost)
217 (setq passwd (nth 2 (assoc mailhost pop3-fma-password)))
218 (pop3-fma-decode-string passwd))
220 (setq pop3-read-passwd 'pop3-fma-read-passwd)
222 ;; Set multiple pop3 server's password
223 (defun pop3-fma-store-password (passwd)
225 (list (pop3-fma-read-noecho
226 (format "POP Password for %s at %s: " pop3-maildrop pop3-mailhost) t)))
227 (if (not (assoc pop3-mailhost pop3-fma-password))
228 (setq pop3-fma-password
229 (append pop3-fma-password
234 (pop3-fma-encode-string passwd)))))
235 (setcar (cdr (cdr (assoc pop3-mailhost pop3-fma-password)))
236 (pop3-fma-encode-string passwd)))
237 (message "POP password registered.")
238 (pop3-fma-encode-string passwd))
241 (defun pop3-fma-set-pop3-password()
246 (substring (car x) (match-end (string-match "^po:" (car x)))
247 (- (match-end (string-match "^.*@" (car x))) 1)))
249 (substring (car x) (match-end (string-match "^.*@" (car x))))))
250 (call-interactively 'pop3-fma-store-password)))
251 pop3-fma-spool-file-alist)
252 (setq nnmail-movemail-program 'pop3-fma-movemail)
253 ;; (setq nnmail-spool-file pop3-fma-spool-file-alist))
254 (setq nnmail-spool-file (append
255 pop3-fma-local-spool-file-alist
259 pop3-fma-spool-file-alist))))
261 (defun pop3-fma-read-noecho (prompt &optional stars)
262 "Read a single line of text from user without echoing, and return it.
267 (cursor-in-echo-area t)
268 (log-message-max-size 0)
269 message-log-max done msg truncate)
271 (if (or (not stars) (string-equal "" ans))
273 (setq msg (concat prompt (make-string (length ans) ?*)))
275 (1+ (- (length msg) (window-width (minibuffer-window)))))
277 (setq msg (concat "$" (substring msg (1+ truncate))))))
279 (setq c (read-char-exclusive))
283 ((or (= c ?\r) (= c ?\n) (= c ?\e))
287 ((and (/= c ?\b) (/= c ?\177))
288 (setq ans (concat ans (char-to-string c))))
290 (setq ans (substring ans 0 -1)))))
300 (defun pop3-fma-message-add-header ()
302 (pop3-fma-add-custom-header "X-Ya-Pop3:" pop3-fma-version)))
305 ;; Add your custom header.
307 (defun pop3-fma-add-custom-header (header string)
309 (progn (goto-char (point-min))
311 (concat "^" (regexp-quote mail-header-separator) "\n"))
313 (goto-char (point-min))
314 (or (re-search-forward (concat "^" header) delimline t)
316 (goto-char delimline)
319 (setq hdr (concat header " "))
320 (setq str (concat hdr string))
321 (setq hdr (concat str "\n"))
322 (insert-string hdr)))))
326 ;; pop3-fma.el ends here.