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
78 (goto-char (point-min))
80 (elmo-nmz-folder-set-pattern-internal folder
84 (let ((index (buffer-substring (point) (point-max))))
85 (elmo-nmz-folder-set-index-path-internal
87 (cond ((cdr (assoc index elmo-nmz-index-alias-alist)))
88 ((eq (length index) 0)
89 elmo-nmz-default-index-path)
94 (luna-define-method elmo-folder-expand-msgdb-path ((folder
97 (elmo-replace-string-as-filename
98 (elmo-folder-name-internal folder))
99 (expand-file-name "nmz" elmo-msgdb-directory)))
101 (defun elmo-nmz-msgdb-create-entity (folder number)
102 "Create msgdb entity for the message in the FOLDER with NUMBER."
103 (let ((location (expand-file-name (elmo-map-message-location folder number)))
105 (setq entity (elmo-msgdb-create-overview-entity-from-file number location))
106 (unless (or (> (length (elmo-msgdb-overview-entity-get-to entity)) 0)
107 (> (length (elmo-msgdb-overview-entity-get-cc entity)) 0)
108 (not (string= (elmo-msgdb-overview-entity-get-subject entity)
110 (elmo-msgdb-overview-entity-set-subject entity location)
111 (setq uid (nth 2 (file-attributes location)))
112 (elmo-msgdb-overview-entity-set-from entity
115 " <"(user-login-name uid) "@"
119 (luna-define-method elmo-folder-msgdb-create ((folder elmo-nmz-folder)
121 (let* (overview number-alist mark-alist entity
123 (setq num (length numlist))
125 (message "Creating msgdb...")
128 (elmo-nmz-msgdb-create-entity
129 folder (car numlist)))
132 (elmo-msgdb-append-element
135 (elmo-msgdb-number-add number-alist
136 (elmo-msgdb-overview-entity-get-number
138 (elmo-msgdb-overview-entity-get-id
141 (elmo-msgdb-mark-append
143 (elmo-msgdb-overview-entity-get-number
145 (or (elmo-msgdb-global-mark-get
146 (elmo-msgdb-overview-entity-get-id
148 elmo-msgdb-new-mark))))
149 (when (> num elmo-display-progress-threshold)
151 (setq percent (/ (* i 100) num))
152 (elmo-display-progress
153 'elmo-folder-msgdb-create "Creating msgdb..."
155 (setq numlist (cdr numlist)))
156 (message "Creating msgdb...done.")
157 (list overview number-alist mark-alist)))
159 (luna-define-method elmo-folder-message-file-p ((folder elmo-nmz-folder))
162 (luna-define-method elmo-message-file-name ((folder elmo-nmz-folder)
164 (elmo-map-message-location folder number))
166 (luna-define-method elmo-folder-message-make-temp-file-p
167 ((folder elmo-nmz-folder))
170 (luna-define-method elmo-folder-diff ((folder elmo-nmz-folder)
174 (luna-define-method elmo-folder-message-make-temp-files ((folder
179 (let ((temp-dir (elmo-folder-make-temporary-directory folder))
180 (cur-number (if start-number 0)))
181 (dolist (number numbers)
183 (elmo-message-file-name folder number)
185 (int-to-string (if start-number (incf cur-number) number))
189 (luna-define-method elmo-map-message-fetch ((folder elmo-nmz-folder)
191 &optional section unseen)
192 (when (file-exists-p location)
194 (insert-file-contents-as-binary (expand-file-name location))
195 (unless (or (std11-field-body "To")
196 (std11-field-body "Cc")
197 (std11-field-body "Subject"))
198 (let (charset guess uid)
200 (set-buffer-multibyte t)
201 (insert-file-contents (expand-file-name location))
202 (setq charset (detect-mime-charset-region (point-min)
204 (goto-char (point-min))
205 (setq guess (mime-find-file-type location))
206 (setq uid (nth 2 (file-attributes location)))
207 (insert "From: " (concat (user-full-name uid)
208 " <"(user-login-name uid) "@"
209 (system-name) ">") "\n")
210 (insert "Subject: " location "\n")
211 (insert "Content-Type: "
212 (concat (nth 0 guess) "/" (nth 1 guess))
213 "; charset=" (upcase (symbol-name charset))
214 "\nMIME-Version: 1.0\n\n")
215 (encode-mime-charset-region (point-min) (point-max) charset)
216 (set-buffer-multibyte nil))))))
218 (luna-define-method elmo-map-folder-list-message-locations
219 ((folder elmo-nmz-folder))
222 (apply 'call-process elmo-nmz-prog nil t t
223 (append elmo-nmz-args
225 (encode-mime-charset-string
226 (elmo-nmz-folder-pattern-internal folder)
228 (if (listp (elmo-nmz-folder-index-path-internal folder))
231 (elmo-nmz-folder-index-path-internal folder))
234 (elmo-nmz-folder-index-path-internal folder))))))
235 (goto-char (point-min))
238 ;; convert url to file path.
239 (when (looking-at "^file://")
241 (when (and elmo-nmz-use-drive-letter
242 (looking-at "^/\\([A-Za-z]\\)|/"))
243 (replace-match "\\1:/")
247 (setq locations (cons (buffer-substring bol (point)) locations))
249 (nreverse locations))))
251 (luna-define-method elmo-folder-exists-p ((folder elmo-nmz-folder))
255 (product-provide (provide 'elmo-nmz) (require 'elmo-version))
257 ;;; elmo-nmz.el ends here