1 ;;; elmo-file.el --- File 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.
36 (luna-define-class elmo-file-folder (elmo-map-folder) (file-path))
37 (luna-define-internal-accessors 'elmo-file-folder))
39 (luna-define-method elmo-folder-initialize ((folder
42 (elmo-file-folder-set-file-path-internal folder name)
45 (luna-define-method elmo-folder-expand-msgdb-path ((folder
48 (elmo-replace-string-as-filename (elmo-folder-name-internal folder))
49 (expand-file-name "file" elmo-msgdb-directory)))
51 (defun elmo-file-make-date-string (attrs)
52 (let ((s (current-time-string (nth 5 attrs))))
53 (string-match "\\`\\([A-Z][a-z][a-z]\\) +[A-Z][a-z][a-z] +[0-9][0-9]? *[0-9][0-9]?:[0-9][0-9]:[0-9][0-9] *[0-9]?[0-9]?[0-9][0-9]"
55 (concat (elmo-match-string 1 s) ", "
56 (timezone-make-date-arpa-standard s (current-time-zone)))))
58 (defun elmo-file-msgdb-create-entity (msgdb folder number)
59 "Create msgdb entity for the message in the FOLDER with NUMBER."
60 (let* ((file (elmo-message-file-name folder number))
61 (attrs (file-attributes file)))
62 (and (not (file-directory-p file))
64 (elmo-msgdb-make-message-entity
65 (elmo-msgdb-message-entity-handler msgdb)
66 :message-id (concat "<" (elmo-replace-in-string
71 :date (elmo-file-make-date-string attrs)
72 :subject (file-name-nondirectory file)
73 :from (concat (user-full-name (nth 2 attrs))
74 " <" (user-login-name (nth 2 attrs)) "@"
75 (system-name) ">")))))
77 (luna-define-method elmo-folder-msgdb-create ((folder elmo-file-folder)
79 (let ((new-msgdb (elmo-make-msgdb))
80 entity mark i percent num)
81 (setq num (length numlist))
83 (message "Creating msgdb...")
86 (elmo-file-msgdb-create-entity new-msgdb folder (car numlist)))
88 (elmo-msgdb-append-entity new-msgdb entity '(new unread)))
89 (when (> num elmo-display-progress-threshold)
91 (setq percent (/ (* i 100) num))
92 (elmo-display-progress
93 'elmo-folder-msgdb-create "Creating msgdb..."
95 (setq numlist (cdr numlist)))
96 (message "Creating msgdb...done")
99 (luna-define-method elmo-folder-message-file-p ((folder elmo-file-folder))
102 (luna-define-method elmo-message-file-name ((folder elmo-file-folder)
104 (expand-file-name (car (split-string
105 (elmo-map-message-location folder number)
107 (elmo-file-folder-file-path-internal folder)))
109 (luna-define-method elmo-folder-message-make-temp-file-p
110 ((folder elmo-file-folder))
113 (luna-define-method elmo-folder-diff ((folder elmo-file-folder))
116 (luna-define-method elmo-folder-message-make-temp-files ((folder
121 (let ((temp-dir (elmo-folder-make-temporary-directory folder))
122 (cur-number (if start-number 0)))
123 (dolist (number numbers)
125 (elmo-message-file-name folder number)
127 (int-to-string (if start-number (incf cur-number) number))
131 (luna-define-method elmo-map-message-fetch ((folder elmo-file-folder)
133 &optional section unseen)
134 (let ((file (expand-file-name (car (split-string location "/"))
135 (elmo-file-folder-file-path-internal folder)))
137 (when (file-exists-p file)
139 (insert-file-contents-as-binary file)
140 (unless (or (std11-field-body "To")
141 (std11-field-body "Cc")
142 (std11-field-body "Subject"))
144 (set-buffer-multibyte t)
145 (insert-file-contents file)
146 (setq charset (detect-mime-charset-region (point-min)
148 (goto-char (point-min))
149 (setq guess (mime-find-file-type file))
150 (setq uid (nth 2 (file-attributes file)))
151 (insert "From: " (concat (user-full-name uid)
152 " <"(user-login-name uid) "@"
153 (system-name) ">") "\n")
154 (insert "Subject: " (file-name-nondirectory file) "\n")
156 (elmo-file-make-date-string (file-attributes file))
158 (insert "Message-ID: "
159 (concat "<" (elmo-replace-in-string file "/" ":")
160 "@" (system-name) ">\n"))
161 (insert "Content-Type: "
162 (concat (nth 0 guess) "/" (nth 1 guess))
163 (or (and (string= (nth 0 guess) "text")
165 "; charset=" (upcase (symbol-name charset))))
167 "\nMIME-Version: 1.0\n\n")
168 (when (string= (nth 0 guess) "text")
169 (encode-mime-charset-region (point-min) (point-max) charset))
170 (set-buffer-multibyte nil))))))
172 (luna-define-method elmo-map-folder-list-message-locations
173 ((folder elmo-file-folder))
180 (nth 5 (file-attributes (expand-file-name
182 (elmo-file-folder-file-path-internal
185 (directory-files (elmo-file-folder-file-path-internal folder))))
187 (luna-define-method elmo-folder-exists-p ((folder elmo-file-folder))
188 (file-directory-p (elmo-file-folder-file-path-internal folder)))
190 (luna-define-method elmo-folder-list-subfolders ((folder elmo-file-folder)
192 (when (file-directory-p (elmo-file-folder-file-path-internal folder))
194 (list (elmo-folder-name-internal folder))
198 (when (and (file-directory-p
201 (elmo-file-folder-file-path-internal folder)))
202 (not (string= file "."))
203 (not (string= file "..")))
204 (concat (elmo-folder-name-internal folder) "/" file)))
205 (directory-files (elmo-file-folder-file-path-internal
209 (product-provide (provide 'elmo-file) (require 'elmo-version))
211 ;;; elmo-file.el ends here