1 ;;; elmo-nmz.el --- Namazu interface for ELMO.
3 ;; Copyright (C) 2000 Yuuichi Teranishi <teranisi@gohome.org>
5 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
6 ;; Keywords: mail, net news
8 ;; This file is part of ELMO (Elisp Library for Message Orchestration).
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
35 (defcustom elmo-nmz-default-index-path "~/Mail"
36 "*Default index path for namazu.
37 If the value is a list, all elements are used as index paths for namazu."
41 (defcustom elmo-nmz-prog "namazu"
42 "*Program name of namazu."
46 (defcustom elmo-nmz-charset 'iso-2022-jp
47 "*Charset for namazu argument."
51 (defcustom elmo-nmz-args '("--all" "--list" "--late")
52 "*Argument list for namazu to list matched files."
53 :type '(repeat string)
56 (defcustom elmo-nmz-index-alias-alist nil
57 "*Alist of ALIAS and INDEX-PATH."
58 :type '(repeat (cons (string :tag "Alias Name")
59 (choice (directory :tag "Index Path")
60 (repeat (directory :tag "Index Path")))))
63 (defvar elmo-nmz-use-drive-letter (if (memq system-type
64 '(OS/2 emx windows-nt)) t nil)
65 "*If non-nil, do a drive letter conversion (e.g. /a|/ => a:/).")
69 (luna-define-class elmo-nmz-folder
70 (elmo-map-folder) (pattern index-path))
71 (luna-define-internal-accessors 'elmo-nmz-folder))
73 (luna-define-method elmo-folder-initialize ((folder
76 (when (> (length name) 0)
79 (goto-char (point-min))
81 (elmo-nmz-folder-set-pattern-internal folder
85 (let ((index (buffer-substring (point) (point-max))))
86 (elmo-nmz-folder-set-index-path-internal
88 (cond ((cdr (assoc index elmo-nmz-index-alias-alist)))
89 ((eq (length index) 0)
90 elmo-nmz-default-index-path)
95 (luna-define-method elmo-folder-expand-msgdb-path ((folder
98 (elmo-replace-string-as-filename
99 (elmo-folder-name-internal folder))
100 (expand-file-name "nmz" elmo-msgdb-directory)))
102 (defun elmo-nmz-msgdb-create-entity (msgdb folder number)
103 "Create msgdb entity for the message in the FOLDER with NUMBER."
104 (let ((location (expand-file-name (elmo-map-message-location folder number)))
106 (setq entity (elmo-msgdb-create-message-entity-from-file
107 (elmo-msgdb-message-entity-handler msgdb) number location))
108 (unless (or (> (length (elmo-message-entity-field entity 'to)) 0)
109 (> (length (elmo-message-entity-field entity 'cc)) 0)
110 (not (string= (elmo-message-entity-field entity 'subject)
112 (elmo-message-entity-set-field entity 'subject location)
113 (setq uid (nth 2 (file-attributes location)))
114 (elmo-message-entity-set-field entity 'from
117 " <"(user-login-name uid) "@"
121 (luna-define-method elmo-folder-msgdb-create ((folder elmo-nmz-folder)
123 (let ((new-msgdb (elmo-make-msgdb))
124 entity mark i percent num)
125 (setq num (length numlist))
127 (message "Creating msgdb...")
130 (elmo-nmz-msgdb-create-entity
131 new-msgdb folder (car numlist)))
133 (elmo-msgdb-append-entity new-msgdb entity '(new unread)))
134 (when (> num elmo-display-progress-threshold)
136 (setq percent (/ (* i 100) num))
137 (elmo-display-progress
138 'elmo-folder-msgdb-create "Creating msgdb..."
140 (setq numlist (cdr numlist)))
141 (message "Creating msgdb...done")
144 (luna-define-method elmo-folder-message-file-p ((folder elmo-nmz-folder))
147 (luna-define-method elmo-message-file-name ((folder elmo-nmz-folder)
149 (elmo-map-message-location folder number))
151 (luna-define-method elmo-folder-message-make-temp-file-p
152 ((folder elmo-nmz-folder))
155 (luna-define-method elmo-folder-diff ((folder elmo-nmz-folder))
158 (luna-define-method elmo-folder-message-make-temp-files ((folder
163 (let ((temp-dir (elmo-folder-make-temporary-directory folder))
164 (cur-number (if start-number 0)))
165 (dolist (number numbers)
167 (elmo-message-file-name folder number)
169 (int-to-string (if start-number (incf cur-number) number))
173 (luna-define-method elmo-map-message-fetch ((folder elmo-nmz-folder)
175 &optional section unseen)
176 (when (file-exists-p location)
178 (insert-file-contents-as-binary (expand-file-name location))
179 (unless (or (std11-field-body "To")
180 (std11-field-body "Cc")
181 (std11-field-body "Subject"))
182 (let (charset guess uid)
184 (set-buffer-multibyte t)
185 (insert-file-contents (expand-file-name location))
186 (setq charset (detect-mime-charset-region (point-min)
188 (goto-char (point-min))
189 (setq guess (mime-find-file-type location))
190 (setq uid (nth 2 (file-attributes location)))
191 (insert "From: " (concat (user-full-name uid)
192 " <"(user-login-name uid) "@"
193 (system-name) ">") "\n")
194 (insert "Subject: " location "\n")
195 (insert "Content-Type: "
196 (concat (nth 0 guess) "/" (nth 1 guess))
197 "; charset=" (upcase (symbol-name charset))
198 "\nMIME-Version: 1.0\n\n")
199 (encode-mime-charset-region (point-min) (point-max) charset)
200 (set-buffer-multibyte nil))))))
202 (luna-define-method elmo-map-folder-list-message-locations
203 ((folder elmo-nmz-folder))
206 (apply 'call-process elmo-nmz-prog nil t t
207 (append elmo-nmz-args
209 (encode-mime-charset-string
210 (elmo-nmz-folder-pattern-internal folder)
212 (if (listp (elmo-nmz-folder-index-path-internal folder))
215 (elmo-nmz-folder-index-path-internal folder))
218 (elmo-nmz-folder-index-path-internal folder))))))
219 (goto-char (point-min))
222 ;; convert url to file path.
223 (when (looking-at "^file://")
225 (when (and elmo-nmz-use-drive-letter
226 (looking-at "^/\\([A-Za-z]\\)|/"))
227 (replace-match "\\1:/")
231 (setq locations (cons (buffer-substring bol (point)) locations))
233 (nreverse locations))))
235 (luna-define-method elmo-folder-exists-p ((folder elmo-nmz-folder))
236 (elmo-nmz-folder-pattern-internal folder))
238 (luna-define-method elmo-folder-have-subfolder-p ((folder elmo-nmz-folder))
239 (null (elmo-nmz-folder-pattern-internal folder)))
241 (luna-define-method elmo-folder-list-subfolders ((folder elmo-nmz-folder)
243 (mapcar (lambda (name) (elmo-recover-string-from-filename name))
244 (directory-files (expand-file-name "nmz" elmo-msgdb-directory)
249 (elmo-folder-prefix-internal folder))))))
252 (product-provide (provide 'elmo-nmz) (require 'elmo-version))
254 ;;; elmo-nmz.el ends here