1 ;;; elmo.el --- Elisp Library for Message Orchestration.
3 ;; Copyright (C) 1998,1999,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.
34 (require 'elmo-version) ; reduce recursive-load-depth
39 (eval-when-compile (require 'cl))
41 (if (or (featurep 'dbm)
44 (featurep 'berkeley-db))
45 (require 'elmo-database))
47 (defcustom elmo-message-fetch-threshold 30000
52 (defcustom elmo-message-fetch-confirm t
53 "If non-nil, confirm fetching if message size is larger than
54 `elmo-message-fetch-threshold'.
55 Otherwise, entire fetching of the message is aborted without confirmation."
59 (defcustom elmo-folder-update-threshold 500
64 (defcustom elmo-folder-update-confirm t
65 "Confirm if update number exceeds `elmo-folder-update-threshold'."
69 (defvar elmo-message-displaying nil
70 "A global switch to indicate message is displaying or not.")
73 (defvar elmo-folder-type-alist nil)
75 (defvar elmo-newsgroups-hashtb nil)
77 (elmo-define-error 'elmo-error "Error" 'error)
78 (elmo-define-error 'elmo-open-error "Cannot open" 'elmo-error)
79 (elmo-define-error 'elmo-authenticate-error "Login failed" 'elmo-open-error)
80 (elmo-define-error 'elmo-imap4-bye-error "IMAP4 session was terminated" 'elmo-open-error)
82 (defun elmo-define-folder (prefix backend)
84 If a folder name begins with PREFIX, use BACKEND."
85 (let ((pair (assq prefix elmo-folder-type-alist)))
89 (setcdr pair backend))
90 (setq elmo-folder-type-alist (cons (cons prefix backend)
91 elmo-folder-type-alist)))))
93 (defmacro elmo-folder-type (name)
94 "Get folder type from NAME string."
95 (` (and (stringp (, name))
96 (cdr (assoc (string-to-char (, name)) elmo-folder-type-alist)))))
99 ;; A elmo folder provides uniformed (orchestrated) access
100 ;; to the internet messages.
102 (luna-define-class elmo-folder () (type ; folder type symbol.
103 name ; orignal folder name string.
104 prefix ; prefix for folder name
105 path ; directory path for msgdb.
106 msgdb ; msgdb (may be nil).
107 killed-list ; killed list.
108 persistent ; non-nil if persistent.
109 message-modified ; message is modified.
110 mark-modified ; mark is modified.
111 process-duplicates ; read or hide
112 biff ; folder for biff
114 (luna-define-internal-accessors 'elmo-folder))
116 (luna-define-generic elmo-folder-initialize (folder name)
117 ;; Initialize a FOLDER structure with NAME."
120 (defmacro elmo-folder-send (folder message &rest args)
121 "Let FOLDER receive the MESSAGE with ARGS."
122 (` (luna-send (, folder) (, message) (, folder) (,@ args))))
125 (defun elmo-make-folder (name &optional non-persistent)
126 "Make an ELMO folder structure specified by NAME.
127 If optional argument NON-PERSISTENT is non-nil, folder is treated as
129 (let ((type (elmo-folder-type name))
130 prefix split class folder original)
131 (setq original (elmo-string name))
134 (setq prefix (substring name 0 1))
135 (setq name (substring name 1)))
136 (setq type (intern (car (setq split (split-string name ":")))))
137 (if (> (length split) 2)
138 (setq name (substring name (+ 1 (length (car split)))))
139 (error "Error in folder name `%s'" original))
140 (setq prefix (concat (car split) ":")))
141 (setq class (format "elmo-%s" (symbol-name type)))
142 (require (intern class))
143 (setq folder (luna-make-entity (intern (concat class "-folder"))
147 :persistent (not non-persistent)))
149 (elmo-folder-send folder 'elmo-folder-initialize name))))
151 (defmacro elmo-folder-msgdb (folder)
152 "Return the msgdb of FOLDER (on-demand loading)."
153 (` (or (elmo-folder-msgdb-internal (, folder))
154 (elmo-folder-set-msgdb-internal (, folder)
155 (elmo-msgdb-load (, folder))))))
157 (luna-define-generic elmo-folder-open (folder &optional load-msgdb)
158 "Open and setup (load saved status) FOLDER.
159 If optional LOAD-MSGDB is non-nil, msgdb is loaded.
160 (otherwise, msgdb is loaded on-demand)")
162 (luna-define-generic elmo-folder-open-internal (folder)
163 "Open FOLDER (without loading saved folder status).")
165 (luna-define-generic elmo-folder-check (folder)
166 "Check the FOLDER to obtain newest information at the next list operation.")
168 (luna-define-generic elmo-folder-clear (folder &optional keep-killed)
169 "Clear FOLDER to the initial state.
170 If optional KEEP-KILLED is non-nil, killed-list is not cleared.")
172 (luna-define-generic elmo-folder-commit (folder)
173 "Save current status of FOLDER.")
175 (luna-define-generic elmo-folder-close (folder)
176 "Close, save and clearnup FOLDER.")
178 (luna-define-generic elmo-folder-close-internal (folder)
179 "Close FOLDER (without saving folder status).")
181 (luna-define-generic elmo-folder-plugged-p (folder)
182 "Returns t if FOLDER is plugged.")
184 (luna-define-generic elmo-folder-set-plugged (folder plugged &optional add)
185 "Set FOLDER as plugged.")
187 (luna-define-generic elmo-net-port-info (folder)
188 "Get port information of FOLDER.")
190 (luna-define-generic elmo-folder-use-flag-p (folder)
191 "Returns t if FOLDER treats unread/important flag itself.")
193 (luna-define-generic elmo-folder-diff (folder &optional numbers)
195 If optional NUMBERS is set, it is used as current NUMBERS.
196 Otherwise, saved status for folder is used for comparison.
197 Return value is cons cell or list:
198 - a cons cell (NEWS . MESSAGES)
199 - a list (RECENT UNSEEN MESSAGES) ; RECENT means NEWS, UNSEEN means UNREAD.")
201 (luna-define-generic elmo-folder-status (folder)
202 "Returns a cons cell of (MAX-NUMBER . MESSAGES) in the FOLDER.")
204 (luna-define-generic elmo-folder-reserve-status-p (folder)
205 "If non-nil, the folder should not close folder after `elmo-folder-status'.")
207 (defun elmo-folder-list-messages (folder &optional visible-only)
208 "Return a list of message numbers contained in FOLDER.
209 If optional VISIBLE-ONLY is non-nil, killed messages are not listed."
210 (let ((list (elmo-folder-list-messages-internal folder visible-only))
211 (killed (elmo-folder-killed-list-internal folder))
216 ;; Not available, use current list.
219 (elmo-msgdb-get-number-alist (elmo-folder-msgdb folder)))))
220 (elmo-living-messages numbers killed)))
222 (defun elmo-folder-list-unreads (folder unread-marks)
223 "Return a list of unread message numbers contained in FOLDER.
224 UNREAD-MARKS is the unread marks."
225 (let ((list (elmo-folder-list-unreads-internal folder
229 ;; Not available, use current mark.
234 (if (member (cadr x) unread-marks)
236 (elmo-msgdb-get-mark-alist (elmo-folder-msgdb folder)))))))
238 (defun elmo-folder-list-importants (folder important-mark)
239 "Returns a list of important message numbers contained in FOLDER.
240 IMPORTANT-MARK is the important mark."
241 (let ((importants (elmo-folder-list-importants-internal folder important-mark))
242 (number-alist (elmo-msgdb-get-number-alist
243 (elmo-folder-msgdb folder)))
245 (dolist (mark-pair (or elmo-msgdb-global-mark-alist
246 (setq elmo-msgdb-global-mark-alist
249 elmo-msgdb-global-mark-filename
250 elmo-msgdb-directory)))))
251 (if (and (string= important-mark (cdr mark-pair))
252 (setq num-pair (rassoc (car mark-pair) number-alist)))
253 (setq result (cons (car num-pair) result))))
254 (if (listp importants)
255 (elmo-uniq-list (nconc result importants))
258 (luna-define-generic elmo-folder-list-messages-internal (folder &optional
260 ;; Return a list of message numbers contained in FOLDER.
261 ;; Return t if the message list is not available.
264 (luna-define-generic elmo-folder-list-unreads-internal (folder
266 &optional mark-alist)
267 ;; Return a list of unread message numbers contained in FOLDER.
268 ;; If optional MARK-ALIST is set, it is used as mark-alist.
269 ;; Return t if this feature is not available.
272 (luna-define-generic elmo-folder-list-importants-internal (folder
274 ;; Return a list of important message numbers contained in FOLDER.
275 ;; Return t if this feature is not available.
278 (luna-define-generic elmo-folder-list-subfolders (folder &optional one-level)
279 "Returns a list of subfolders contained in FOLDER.
280 If optional argument ONE-LEVEL is non-nil, only children of FOLDER is returned.
281 (a folder which have children is returned as a list)
282 Otherwise, all descendent folders are returned.")
284 (luna-define-generic elmo-folder-have-subfolder-p (folder)
285 "Return non-nil when FOLDER has subfolders.")
287 (luna-define-generic elmo-folder-exists-p (folder)
288 "Returns non-nil when FOLDER exists.")
290 (luna-define-generic elmo-folder-creatable-p (folder)
291 "Returns non-nil when FOLDER is creatable.")
293 (luna-define-generic elmo-folder-writable-p (folder)
294 "Returns non-nil when FOLDER is writable.")
296 (luna-define-generic elmo-folder-persistent-p (folder)
297 "Return non-nil when FOLDER is persistent.")
299 (luna-define-generic elmo-folder-create (folder)
302 (luna-define-generic elmo-message-deletable-p (folder number)
303 "Returns non-nil when the message in the FOLDER with NUMBER is deletable.")
305 (luna-define-generic elmo-folder-delete (folder)
306 "Delete FOLDER completely.")
308 (luna-define-generic elmo-folder-rename (folder new-name)
309 "Rename FOLDER to NEW-NAME (string).")
311 (luna-define-generic elmo-folder-delete-messages (folder numbers)
313 FOLDER is the ELMO folder structure.
314 NUMBERS is a list of message numbers to be deleted.")
316 (luna-define-generic elmo-folder-search (folder condition &optional numbers)
317 "Search and return list of message numbers.
318 FOLDER is the ELMO folder structure.
319 CONDITION is a condition structure for searching.
320 If optional argument NUMBERS is specified and is a list of message numbers,
321 messages are searched from the list.")
323 (luna-define-generic elmo-message-match-condition (folder number
326 "Return non-nil when the message in the FOLDER with NUMBER is matched.
327 CONDITION is a condition structure for testing.
328 NUMBERS is a list of message numbers,
329 use to be test for \"last\" and \"first\" predicates.")
331 (luna-define-generic elmo-folder-msgdb-create
332 (folder numbers new-mark already-mark seen-mark important-mark seen-list)
333 "Create a message database (implemented in each backends).
334 FOLDER is the ELMO folder structure.
335 NUMBERS is a list of message numbers to create msgdb.
336 NEW-MARK, ALREADY-MARK, SEEN-MARK, and IMPORTANT-MARK are mark string for
337 new message, unread but cached message, read message and important message.
338 SEEN-LIST is a list of message-id string which should be treated as read.")
340 (luna-define-generic elmo-folder-unmark-important (folder numbers)
341 "Un-mark messages as important.
342 FOLDER is the ELMO folder structure.
343 NUMBERS is a list of message numbers to be processed.")
345 (luna-define-generic elmo-folder-mark-as-important (folder numbers)
346 "Mark messages as important.
347 FOLDER is the ELMO folder structure.
348 NUMBERS is a list of message numbers to be processed.")
350 (luna-define-generic elmo-folder-unmark-read (folder numbers)
351 "Un-mark messages as read.
352 FOLDER is the ELMO folder structure.
353 NUMBERS is a list of message numbers to be processed.")
355 (luna-define-generic elmo-folder-mark-as-read (folder numbers)
356 "Mark messages as read.
357 FOLDER is the ELMO folder structure.
358 NUMBERS is a list of message numbers to be processed.")
360 (luna-define-generic elmo-folder-append-buffer (folder unread &optional number)
361 "Append current buffer as a new message.
362 FOLDER is the destination folder(ELMO folder structure).
363 If UNREAD is non-nil, message is appended as unread.
364 If optional argument NUMBER is specified, the new message number is set
367 (luna-define-generic elmo-folder-append-messages (folder
373 "Append messages from folder.
374 FOLDER is the ELMO folder structure.
375 Caller should make sure FOLDER is `writable'.
376 (Can be checked with `elmo-folder-writable-p').
377 SRC-FOLDER is the source ELMO folder structure.
378 NUMBERS is the message numbers to be appended in the SRC-FOLDER.
379 UNREAD-MARKS is a list of unread mark string.
380 If second optional argument SAME-NUMBER is specified,
381 message number is preserved (if possible).")
383 (luna-define-generic elmo-folder-pack-numbers (folder)
384 "Pack message numbers of FOLDER.")
386 (luna-define-generic elmo-folder-update-number (folder)
387 "Update number of FOLDER.")
389 (luna-define-generic elmo-folder-diff-async (folder)
390 "Get diff of FOLDER asynchronously.")
392 (luna-define-generic elmo-folder-expand-msgdb-path (folder)
393 "Expand path for FOLDER.")
395 (luna-define-generic elmo-folder-get-primitive-list (folder)
396 "Get primitive folder structure list contained in FOLDER.")
398 (luna-define-generic elmo-folder-contains-type (folder type)
399 "Returns t if FOLDER contains TYPE.")
401 (luna-define-generic elmo-folder-local-p (folder)
402 "Returns t if FOLDER is local.")
404 (luna-define-generic elmo-folder-message-file-p (folder)
405 "Returns t if all messages in the FOLDER are files.")
408 (luna-define-generic elmo-message-use-cache-p (folder number)
409 "Returns t if the message in the FOLDER with NUMBER uses cache.")
411 (luna-define-generic elmo-message-file-name (folder number)
412 "Return the file name of a message specified by FOLDER and NUMBER.")
416 ;;; Use original file
417 (luna-define-generic elmo-folder-message-file-number-p (folder)
418 "Return t if the file name in the FOLDER is the message number.")
420 (luna-define-generic elmo-folder-message-file-directory (folder)
421 "Return the directory of the message files of FOLDER.")
423 ;;; Use temporary file
424 (luna-define-generic elmo-folder-message-make-temp-file-p (folder)
425 "Return t if the messages in the FOLDER makes local temporary file.")
427 (luna-define-generic elmo-folder-message-make-temp-files (folder
431 "Make a new temporary files from the messages in the FOLDER with NUMBERS.
432 If START-NUMBER is specified, temporary files begin from the number.
433 Otherwise, same number is used for temporary files.
434 Return newly created temporary directory name which contains temporary files.")
436 (luna-define-generic elmo-message-file-p (folder number)
437 "Return t if message in the FOLDER with NUMBER is a file.")
439 (luna-define-generic elmo-find-fetch-strategy
440 (folder entity &optional ignore-cache)
441 ;; Returns the message fetching strategy suitable for the message.
442 ;; FOLDER is the ELMO folder structure.
443 ;; ENTITY is the overview entity of the message in the folder.
444 ;; If optional argument IGNORE-CACHE is non-nil, cache is ignored.
445 ;; Returned value is a elmo-fetch-strategy object.
446 ;; If return value is nil, message should not be nil.
449 (defmacro elmo-make-fetch-strategy (entireness
454 ;; Make elmo-message-fetching strategy.
455 ;; ENTIRENESS is 'entire or 'section.
456 ;; 'entire means fetch message entirely at once.
457 ;; 'section means fetch message section by section.
458 ;; If optional USE-CACHE is non-nil, existing cache is used and otherwise,
459 ;; existing cache is thrown away.
460 ;; If SAVE-CACHE is non-nil, fetched message is saved.
461 ;; CACHE-PATH is the cache path to be used as a message cache file.
462 (` (vector (, entireness)
463 (, use-cache) (, save-cache) (, cache-path))))
465 (defmacro elmo-fetch-strategy-entireness (strategy)
466 ;; Return entireness of STRATEGY.
467 (` (aref (, strategy) 0)))
469 (defmacro elmo-fetch-strategy-use-cache (strategy)
470 ;; Return use-cache of STRATEGY.
471 (` (aref (, strategy) 1)))
473 (defmacro elmo-fetch-strategy-save-cache (strategy)
474 ;; Return save-cache of STRATEGY.
475 (` (aref (, strategy) 2)))
477 (defmacro elmo-fetch-strategy-cache-path (strategy)
478 ;; Return cache-path of STRATEGY.
479 (` (aref (, strategy) 3)))
481 (luna-define-method elmo-find-fetch-strategy
482 ((folder elmo-folder) entity &optional ignore-cache)
483 (let (cache-file size message-id number)
484 (setq size (elmo-msgdb-overview-entity-get-size entity))
485 (setq message-id (elmo-msgdb-overview-entity-get-id entity))
486 (setq number (elmo-msgdb-overview-entity-get-number entity))
487 (setq cache-file (elmo-file-cache-get message-id))
488 (setq ignore-cache (or ignore-cache
489 (null (elmo-message-use-cache-p folder number))))
491 (null (elmo-file-cache-status cache-file)))
492 ;; No cache or ignore-cache.
493 (if (and (not (elmo-folder-local-p folder))
494 elmo-message-fetch-threshold
496 (>= size elmo-message-fetch-threshold)
497 (or (not elmo-message-fetch-confirm)
498 (not (prog1 (y-or-n-p
499 (format "Fetch entire message(%dbytes)? "
502 ;; Don't fetch message at all.
504 ;; Don't use existing cache and fetch entire message at once.
505 (elmo-make-fetch-strategy
507 (elmo-message-use-cache-p folder number)
508 (elmo-file-cache-path cache-file)))
510 (if (not ignore-cache)
511 (elmo-make-fetch-strategy
513 ;; ...But ignore current section cache and re-fetch
515 (not (eq (elmo-file-cache-status cache-file) 'section))
517 (elmo-message-use-cache-p folder number)
518 (elmo-file-cache-path cache-file))))))
520 (luna-define-method elmo-folder-list-messages-internal
521 ((folder elmo-folder) &optional visible-only)
524 (luna-define-method elmo-folder-list-unreads-internal
525 ((folder elmo-folder) unread-marks &optional mark-alist)
528 (luna-define-method elmo-folder-list-importants-internal
529 ((folder elmo-folder) important-mark)
532 (defun elmo-folder-encache (folder numbers &optional unread)
533 "Encache messages in the FOLDER with NUMBERS.
534 If UNREAD is non-nil, messages are not marked as read."
535 (dolist (number numbers)
536 (elmo-message-encache folder number unread)))
538 (luna-define-generic elmo-message-encache (folder number &optional read)
539 "Encache message in the FOLDER with NUMBER.
540 If READ is non-nil, message is marked as read.")
542 (luna-define-method elmo-message-encache ((folder elmo-folder) number
546 (elmo-make-fetch-strategy 'entire
549 (elmo-file-cache-get-path
551 folder number 'message-id)))
554 (luna-define-generic elmo-message-fetch (folder number strategy
559 "Fetch a message and return as a string.
560 FOLDER is the ELMO folder structure.
561 NUMBER is the number of the message in the FOLDER.
562 STRATEGY is the message fetching strategy.
563 If optional argument SECTION is specified, only the SECTION of the message
564 is fetched (if possible).
565 If second optional argument OUTBUF is specified, fetched message is
566 inserted to the buffer and returns t if fetch was ended successfully.
567 If third optional argument UNREAD is non-nil, message is not marked as read.
568 Returns non-nil if fetching was succeed.")
570 (luna-define-generic elmo-message-fetch-with-cache-process (folder
575 "Fetch a message into current buffer with cache process.
576 FOLDER is the ELMO folder structure.
577 NUMBER is the number of the message in the FOLDER.
578 STRATEGY is the message fetching strategy.
579 If optional argument SECTION is specified, only the SECTION of the message
580 is fetched (if possible).
581 If second optional argument UNREAD is non-nil, message is not marked as read.
582 Returns non-nil if fetching was succeed.")
584 (luna-define-generic elmo-message-fetch-internal (folder number strategy
588 "Fetch a message into current buffer.
589 FOLDER is the ELMO folder structure.
590 NUMBER is the number of the message in the FOLDER.
591 STRATEGY is the message fetching strategy.
592 If optional argument SECTION is specified, only the SECTION of the message
593 is fetched (if possible).
594 If second optional argument UNREAD is non-nil, message is not marked as read.
595 Returns non-nil if fetching was succeed.")
597 (luna-define-generic elmo-message-fetch-field (folder number field)
598 "Fetch a message field value.
599 FOLDER is the ELMO folder structure.
600 NUMBER is the number of the message in the FOLDER.
601 FIELD is a symbol of the field name.")
603 (luna-define-generic elmo-message-folder (folder number)
604 "Get primitive folder of the message.")
606 (luna-define-generic elmo-folder-process-crosspost (folder
609 "Process crosspost for FOLDER.
610 If NUMBER-ALIST is set, it is used as number-alist.
611 Return a cons cell of (NUMBER-CROSSPOSTS . NEW-MARK-ALIST).")
613 (luna-define-generic elmo-folder-append-msgdb (folder append-msgdb)
614 "Append APPEND-MSGDB to the current msgdb of the folder.")
616 (luna-define-generic elmo-folder-newsgroups (folder)
617 "Return list of newsgroup name of FOLDER.")
619 (luna-define-method elmo-folder-newsgroups ((folder elmo-folder))
622 (luna-define-method elmo-folder-open ((folder elmo-folder)
623 &optional load-msgdb)
624 (elmo-generic-folder-open folder load-msgdb))
626 (defun elmo-generic-folder-open (folder load-msgdb)
627 (let ((inhibit-quit t))
629 (elmo-folder-set-msgdb-internal folder (elmo-msgdb-load folder)))
630 (elmo-folder-set-killed-list-internal
632 (elmo-msgdb-killed-list-load (elmo-folder-msgdb-path folder))))
633 (elmo-folder-open-internal folder))
635 (luna-define-method elmo-folder-open-internal ((folder elmo-folder))
636 nil ; default is do nothing.
639 (luna-define-method elmo-folder-check ((folder elmo-folder))
640 nil) ; default is noop.
642 (luna-define-method elmo-folder-commit ((folder elmo-folder))
643 (elmo-generic-folder-commit folder))
645 (defun elmo-generic-folder-commit (folder)
646 (when (elmo-folder-persistent-p folder)
647 (when (elmo-folder-message-modified-internal folder)
648 (elmo-msgdb-overview-save
649 (elmo-folder-msgdb-path folder)
650 (elmo-msgdb-get-overview (elmo-folder-msgdb folder)))
651 (elmo-msgdb-number-save
652 (elmo-folder-msgdb-path folder)
653 (elmo-msgdb-get-number-alist (elmo-folder-msgdb folder)))
654 (elmo-folder-set-info-max-by-numdb
656 (elmo-msgdb-get-number-alist
657 (elmo-folder-msgdb folder)))
658 (elmo-folder-set-message-modified-internal folder nil)
659 (elmo-msgdb-killed-list-save
660 (elmo-folder-msgdb-path folder)
661 (elmo-folder-killed-list-internal folder)))
662 (when (elmo-folder-mark-modified-internal folder)
663 (elmo-msgdb-mark-save
664 (elmo-folder-msgdb-path folder)
665 (elmo-msgdb-get-mark-alist (elmo-folder-msgdb folder)))
666 (elmo-folder-set-mark-modified-internal folder nil))))
668 (luna-define-method elmo-folder-close-internal ((folder elmo-folder))
672 (luna-define-method elmo-folder-close ((folder elmo-folder))
673 (elmo-generic-folder-close folder)
674 (elmo-folder-close-internal folder))
676 (defun elmo-generic-folder-close (folder)
677 (elmo-folder-commit folder)
678 (elmo-folder-set-msgdb-internal folder nil)
679 (elmo-folder-set-killed-list-internal folder nil))
681 (luna-define-method elmo-folder-plugged-p ((folder elmo-folder))
682 t) ; default is plugged.
684 (luna-define-method elmo-folder-set-plugged ((folder elmo-folder) plugged
686 nil) ; default is do nothing.
688 (luna-define-method elmo-folder-use-flag-p ((folder elmo-folder))
689 nil) ; default is no flag.
691 (luna-define-method elmo-folder-persistent-p ((folder elmo-folder))
692 (elmo-folder-persistent-internal folder))
694 (luna-define-method elmo-folder-creatable-p ((folder elmo-folder))
695 nil) ; default is not creatable.
697 (luna-define-method elmo-folder-writable-p ((folder elmo-folder))
698 nil) ; default is not writable.
700 (luna-define-method elmo-folder-delete ((folder elmo-folder))
701 (elmo-msgdb-delete-path folder))
703 (luna-define-method elmo-folder-rename ((folder elmo-folder) new-name)
704 (let* ((new-folder (elmo-make-folder new-name)))
705 (unless (eq (elmo-folder-type-internal folder)
706 (elmo-folder-type-internal new-folder))
707 (error "Not same folder type"))
708 (if (or (file-exists-p (elmo-folder-msgdb-path new-folder))
709 (elmo-folder-exists-p new-folder))
710 (error "Already exists folder: %s" new-name))
711 (elmo-folder-send folder 'elmo-folder-rename-internal new-folder)
712 (elmo-msgdb-rename-path folder new-folder)))
714 (defsubst elmo-folder-search-fast (folder condition numbers)
717 (member (elmo-filter-key condition) '("first" "last")))
718 (let ((len (length numbers))
719 (lastp (string= (elmo-filter-key condition) "last"))
720 (value (string-to-number (elmo-filter-value condition))))
721 (when (eq (elmo-filter-type condition) 'unmatch)
722 (setq lastp (not lastp)
723 value (- len value)))
725 (nthcdr (max (- len value) 0) numbers)
727 (let ((last (nthcdr (1- value) numbers)))
732 (luna-define-method elmo-folder-search ((folder elmo-folder)
735 (let ((numbers (or numbers (elmo-folder-list-messages folder))))
736 (or (elmo-folder-search-fast folder condition numbers)
737 (let ((msgdb (elmo-folder-msgdb folder))
738 (len (length numbers))
740 (when (> len elmo-display-progress-threshold)
741 (elmo-progress-set 'elmo-folder-search len "Searching..."))
743 (dolist (number numbers)
744 (let ((entity (elmo-msgdb-overview-get-entity number msgdb))
747 (setq result (elmo-msgdb-match-condition
751 (setq result condition))
752 (when (elmo-filter-condition-p result)
753 (setq result (elmo-message-match-condition
759 (setq matched (cons number matched))))
760 (elmo-progress-notify 'elmo-folder-search))
761 (elmo-progress-clear 'elmo-folder-search))
762 (nreverse matched)))))
764 (luna-define-method elmo-message-match-condition ((folder elmo-folder)
767 (let ((filename (cond
768 ((elmo-message-file-name folder number))
769 ((let* ((cache (elmo-file-cache-get
770 (elmo-message-field folder number
772 (cache-path (elmo-file-cache-path cache)))
773 (when (and cache-path
774 (not (elmo-cache-path-section-p cache-path)))
777 (file-readable-p filename))
779 (insert-file-contents-as-binary filename)
780 (elmo-set-buffer-multibyte default-enable-multibyte-characters)
781 ;; Should consider charset?
782 (decode-mime-charset-region (point-min) (point-max) elmo-mime-charset)
783 (elmo-buffer-field-condition-match condition number numbers)))))
785 (luna-define-method elmo-folder-pack-numbers ((folder elmo-folder))
786 nil) ; default is noop.
788 (luna-define-method elmo-folder-update-number ((folder elmo-folder))
789 nil) ; default is noop.
791 (luna-define-method elmo-folder-message-file-p ((folder elmo-folder))
792 nil) ; default is not file.
794 (luna-define-method elmo-folder-message-file-number-p ((folder elmo-folder))
795 nil) ; default is not number.
797 (luna-define-method elmo-folder-message-make-temp-file-p ((folder elmo-folder))
798 nil) ; default is not make temp file.
800 (luna-define-method elmo-message-file-name ((folder elmo-folder)
802 nil) ; default is no name.
804 (luna-define-method elmo-folder-local-p ((folder elmo-folder))
805 t) ; default is local.
807 (luna-define-method elmo-folder-have-subfolder-p ((folder elmo-folder))
811 ;; Folder info is a message number information cache (hashtable)
812 (defsubst elmo-folder-get-info (folder &optional hashtb)
813 "Return FOLDER info from HASHTB (default is `elmo-folder-info-hashtb')."
814 (elmo-get-hash-val (elmo-folder-name-internal folder)
815 (or hashtb elmo-folder-info-hashtb)))
817 (defun elmo-folder-set-info-hashtb (folder max numbers &optional new unread)
818 "Set FOLDER info (means MAX, NUMBERS, NEW and UNREAD)."
819 (let ((info (elmo-folder-get-info folder)))
821 (or new (setq new (nth 0 info)))
822 (or unread (setq unread (nth 1 info)))
823 (or numbers (setq numbers (nth 2 info)))
824 (or max (setq max (nth 3 info))))
825 (elmo-set-hash-val (elmo-folder-name-internal folder)
826 (list new unread numbers max)
827 elmo-folder-info-hashtb)))
829 (defun elmo-folder-set-info-max-by-numdb (folder msgdb-number)
830 "Set FOLDER info by MSGDB-NUMBER in msgdb."
831 (let ((num-db (sort (mapcar 'car msgdb-number) '<)))
832 (elmo-folder-set-info-hashtb
834 (or (nth (max 0 (1- (length num-db))) num-db) 0)
835 nil ;;(length num-db)
838 (defun elmo-folder-get-info-max (folder)
839 "Return max number of FODLER from folder info."
840 (nth 3 (elmo-folder-get-info folder)))
842 (defun elmo-folder-get-info-length (folder)
843 "Return length of FODLER from folder info."
844 (nth 2 (elmo-folder-get-info folder)))
846 (defun elmo-folder-get-info-unread (folder)
847 "Return unread of FODLER from folder info."
848 (nth 1 (elmo-folder-get-info folder)))
850 (defun elmo-folder-info-make-hashtb (info-alist hashtb)
851 "Setup folder info hashtable by INFO-ALIST on HASHTB."
852 (let* ((hashtb (or hashtb
853 (elmo-make-hash (length info-alist)))))
856 (let ((info (cadr x)))
857 (and (intern-soft (car x) hashtb)
858 (elmo-set-hash-val (car x)
859 (list (nth 2 info) ;; new
860 (nth 3 info) ;; unread
861 (nth 1 info) ;; length
865 (setq elmo-folder-info-hashtb hashtb)))
867 (defsubst elmo-diff-new (diff)
870 (defsubst elmo-diff-unread (diff)
871 (when (consp (cdr diff))
874 (defsubst elmo-diff-all (diff)
875 (if (consp (cdr diff))
879 (defsubst elmo-strict-folder-diff (folder)
880 "Return folder diff information strictly from FOLDER."
881 (let* ((dir (elmo-folder-msgdb-path folder))
882 (nalist (elmo-msgdb-get-number-alist (elmo-folder-msgdb folder)))
883 (in-db (sort (mapcar 'car nalist) '<))
884 (in-folder (elmo-folder-list-messages folder))
885 append-list delete-list diff)
886 (cons (if (equal in-folder in-db)
888 (setq diff (elmo-list-diff
892 (setq append-list (car diff))
893 (setq delete-list (cadr diff))
897 (- 0 (length delete-list))
899 (length in-folder))))
901 (luna-define-method elmo-folder-diff ((folder elmo-folder)
903 (elmo-generic-folder-diff folder numbers))
905 (defun elmo-generic-folder-diff (folder numbers)
906 (if (elmo-string-match-member (elmo-folder-name-internal folder)
907 elmo-strict-diff-folder-list)
908 (elmo-strict-folder-diff folder)
909 (let ((cached-in-db-max (elmo-folder-get-info-max folder))
910 (in-folder (elmo-folder-status folder))
915 (setq in-db-max (or (nth (max 0 (1- (length numbers))) numbers)
917 (if (not cached-in-db-max)
918 (let ((number-list (mapcar 'car
919 (elmo-msgdb-number-load
920 (elmo-folder-msgdb-path folder)))))
922 (setq in-db (sort number-list '<))
923 (setq in-db-max (or (nth (max 0 (1- (length in-db))) in-db)
925 (elmo-folder-set-info-hashtb folder in-db-max nil))
926 (setq in-db-max cached-in-db-max)))
927 (setq unsync (if (and in-db
929 (- (car in-folder) in-db-max)
933 (if (null (car in-folder))
935 (setq messages (cdr in-folder))
936 (if (and unsync messages (> unsync messages))
937 (setq unsync messages))
938 (cons (or unsync 0) (or messages 0)))))
940 (defvar elmo-folder-diff-async-callback nil)
941 (defvar elmo-folder-diff-async-callback-data nil)
943 (luna-define-method elmo-folder-diff-async ((folder elmo-folder))
944 (and elmo-folder-diff-async-callback
945 (funcall elmo-folder-diff-async-callback
947 (elmo-folder-diff folder))))
949 (luna-define-method elmo-folder-get-primitive-list ((folder elmo-folder))
952 (luna-define-method elmo-folder-contains-type ((folder elmo-folder) type)
953 (eq (elmo-folder-type-internal folder) type))
955 (luna-define-method elmo-folder-append-messages ((folder elmo-folder)
961 (elmo-generic-folder-append-messages folder src-folder numbers
962 unread-marks same-number))
964 (defun elmo-generic-folder-append-messages (folder src-folder numbers
965 unread-marks same-number)
966 (let (unseen seen-list succeed-numbers failure cache)
968 (set-buffer-multibyte nil)
972 (setq cache (elmo-file-cache-get
973 (elmo-message-field src-folder
980 src-folder (car numbers)
981 (if (elmo-folder-plugged-p src-folder)
982 (elmo-make-fetch-strategy
984 (and cache (elmo-file-cache-path cache)))
985 (or (and elmo-enable-disconnected-operation
987 (eq (elmo-file-cache-status cache) 'entire)
988 (elmo-make-fetch-strategy
990 (elmo-file-cache-path cache)))
991 (error "Unplugged")))
995 (elmo-folder-append-buffer
997 (setq unseen (member (elmo-message-mark
998 src-folder (car numbers))
1000 (if same-number (car numbers))))))
1001 (error (setq failure t)))
1002 ;; FETCH & APPEND finished
1005 (setq seen-list (cons (elmo-message-field
1006 src-folder (car numbers)
1009 (setq succeed-numbers (cons (car numbers) succeed-numbers)))
1010 (elmo-progress-notify 'elmo-folder-move-messages)
1011 (setq numbers (cdr numbers)))
1012 (if (and seen-list (elmo-folder-persistent-p folder))
1013 (elmo-msgdb-seen-save (elmo-folder-msgdb-path folder)
1014 (nconc (elmo-msgdb-seen-load
1015 (elmo-folder-msgdb-path folder))
1019 ;; Arguments should be reduced.
1020 (defun elmo-folder-move-messages (src-folder msgs dst-folder
1028 (let* ((messages msgs)
1029 (elmo-inhibit-display-retrieval-progress t)
1032 (if (eq dst-folder 'null)
1033 (setq succeeds messages)
1034 (unless (elmo-folder-writable-p dst-folder)
1035 (error "move: %d is not writable"
1036 (elmo-folder-name-internal dst-folder)))
1038 ;; src is already opened.
1039 (elmo-folder-open-internal dst-folder)
1040 (unless (setq succeeds (elmo-folder-append-messages dst-folder
1045 (error "move: append message to %s failed"
1046 (elmo-folder-name-internal dst-folder)))
1047 (elmo-folder-close dst-folder))
1048 (when (and (elmo-folder-persistent-p dst-folder)
1050 ;; Save to seen list.
1051 (let* ((dir (elmo-folder-msgdb-path dst-folder))
1052 (seen-list (elmo-msgdb-seen-load dir)))
1054 (elmo-msgdb-add-msgs-to-seen-list
1055 msgs (elmo-folder-msgdb src-folder)
1056 unread-marks seen-list))
1057 (elmo-msgdb-seen-save dir seen-list))))
1058 (if (and (not no-delete) succeeds)
1060 (if (not no-delete-info)
1061 (message "Cleaning up src folder..."))
1062 (if (and (elmo-folder-delete-messages src-folder succeeds)
1063 (elmo-msgdb-delete-msgs
1064 (elmo-folder-msgdb src-folder) succeeds))
1066 (message "move: delete messages from %s failed."
1067 (elmo-folder-name-internal src-folder))
1070 (not no-delete-info))
1071 (message "Cleaning up src folder...done"))
1075 (message "Copying messages...done")
1078 (message "No message was moved.")
1079 (message "Moving messages failed.")
1083 (defun elmo-folder-msgdb-path (folder)
1084 "Return the msgdb path for FOLDER."
1085 (or (elmo-folder-path-internal folder)
1086 (elmo-folder-set-path-internal
1088 (elmo-folder-expand-msgdb-path folder))))
1090 (defun elmo-message-mark (folder number)
1091 "Get mark of the message.
1092 FOLDER is the ELMO folder structure.
1093 NUMBER is a number of the message."
1094 (elmo-msgdb-get-mark (elmo-folder-msgdb folder) number))
1096 (defun elmo-folder-list-messages-mark-match (folder mark-regexp)
1097 "List messages in the FOLDER which have a mark that matches MARK-REGEXP"
1098 (let ((case-fold-search nil)
1101 (dolist (elem (elmo-msgdb-get-mark-alist (elmo-folder-msgdb folder)))
1102 (if (string-match mark-regexp (cadr elem))
1103 (setq matched (cons (car elem) matched)))))
1106 (defun elmo-message-field (folder number field)
1107 "Get message field value in the msgdb.
1108 FOLDER is the ELMO folder structure.
1109 NUMBER is a number of the message.
1110 FIELD is a symbol of the field."
1111 (elmo-msgdb-get-field (elmo-folder-msgdb folder) number field))
1113 (defun elmo-message-set-mark (folder number mark)
1114 "Set mark for the message in the FOLDER with NUMBER as MARK."
1115 (elmo-msgdb-set-mark
1116 (elmo-folder-msgdb folder)
1119 (luna-define-method elmo-message-use-cache-p ((folder elmo-folder) number)
1120 nil) ; default is not use cache.
1122 (luna-define-method elmo-message-folder ((folder elmo-folder) number)
1123 folder) ; default is folder
1125 (luna-define-method elmo-folder-unmark-important ((folder elmo-folder) numbers)
1128 (luna-define-method elmo-folder-mark-as-important ((folder elmo-folder)
1132 (luna-define-method elmo-folder-unmark-read ((folder elmo-folder) numbers)
1135 (luna-define-method elmo-folder-mark-as-read ((folder elmo-folder) numbers)
1138 (luna-define-method elmo-folder-process-crosspost ((folder elmo-folder)
1144 (defsubst elmo-folder-replace-marks (folder alist)
1145 "Replace marks of the FOLDER according to ALIST."
1147 (dolist (elem (elmo-msgdb-get-mark-alist (elmo-folder-msgdb folder)))
1148 (when (setq pair (assoc (cadr elem) alist))
1149 (if (elmo-message-use-cache-p folder (car elem))
1150 (elmo-msgdb-set-mark (elmo-folder-msgdb folder)
1153 (elmo-msgdb-set-mark (elmo-folder-msgdb folder)
1157 (defun elmo-generic-folder-append-msgdb (folder append-msgdb)
1159 (let* ((number-alist (elmo-msgdb-get-number-alist append-msgdb))
1160 (all-alist (copy-sequence (append
1161 (elmo-msgdb-get-number-alist
1162 (elmo-folder-msgdb folder))
1169 (setq all-alist (delq (car cur) all-alist))
1170 ;; same message id exists.
1171 (if (setq pair (rassoc (cdr (car cur)) all-alist))
1172 (setq to-be-deleted (nconc to-be-deleted (list (car pair)))))
1173 (setq cur (cdr cur)))
1174 (cond ((eq (elmo-folder-process-duplicates-internal folder)
1177 (setq overview (elmo-delete-if
1179 (memq (elmo-msgdb-overview-entity-get-number
1182 (elmo-msgdb-get-overview append-msgdb)))
1183 ;; Should be mark as read.
1184 (elmo-folder-mark-as-read folder to-be-deleted)
1185 (elmo-msgdb-set-overview append-msgdb overview))
1186 ((eq (elmo-folder-process-duplicates-internal folder)
1188 ;; Mark as read duplicates.
1189 (elmo-folder-mark-as-read folder to-be-deleted))
1192 (setq to-be-deleted nil)))
1193 (elmo-folder-set-msgdb-internal folder
1195 (elmo-folder-msgdb folder)
1197 (length to-be-deleted))
1200 (luna-define-method elmo-folder-append-msgdb ((folder elmo-folder)
1202 (elmo-generic-folder-append-msgdb folder append-msgdb))
1204 (defun elmo-folder-confirm-appends (appends)
1205 (let ((len (length appends))
1207 (if (and elmo-folder-update-threshold
1208 (> len elmo-folder-update-threshold)
1209 elmo-folder-update-confirm)
1210 (if (y-or-n-p (format "Too many messages(%d). Update all? " len))
1212 (setq in elmo-folder-update-threshold)
1215 (setq in (read-from-minibuffer "Update number: "
1217 in (string-to-int in))
1220 (if (y-or-n-p (format "%d messages are not appeared. OK? "
1221 (max (- len in) 0)))
1223 (nthcdr (max (- len in) 0) appends))
1224 (if (and elmo-folder-update-threshold
1225 (> len elmo-folder-update-threshold)
1226 (not elmo-folder-update-confirm))
1227 (nthcdr (max (- len elmo-folder-update-threshold) 0) appends)
1230 (luna-define-method elmo-message-fetch ((folder elmo-folder)
1237 (with-current-buffer outbuf
1239 (elmo-message-fetch-with-cache-process folder number
1240 strategy section unread))
1242 (elmo-message-fetch-with-cache-process folder number
1243 strategy section unread)
1246 (luna-define-method elmo-message-fetch-with-cache-process ((folder elmo-folder)
1250 (let ((cache-path (elmo-fetch-strategy-cache-path strategy))
1252 (cond ((eq (elmo-fetch-strategy-use-cache strategy) 'maybe)
1254 ((elmo-fetch-strategy-use-cache strategy)
1259 (while (and method-priorities
1262 (case (car method-priorities)
1264 (elmo-file-cache-load cache-path section))
1266 (when (and (condition-case error
1267 (elmo-message-fetch-internal folder number
1271 (error (setq err error) nil))
1272 (> (buffer-size) 0))
1273 (elmo-delete-cr-buffer)
1274 (when (and (elmo-fetch-strategy-save-cache strategy)
1276 (elmo-file-cache-save cache-path section))
1278 method-priorities (cdr method-priorities)))
1280 (and err (signal (car err) (cdr err))))))
1282 (luna-define-method elmo-folder-clear ((folder elmo-folder)
1283 &optional keep-killed)
1285 (elmo-folder-set-killed-list-internal folder nil))
1286 (elmo-folder-set-msgdb-internal folder (elmo-msgdb-clear)))
1288 (defun elmo-folder-synchronize (folder
1290 unread-uncached-mark ;"U"
1291 unread-cached-mark ;"!"
1292 read-uncached-mark ;"u"
1294 &optional ignore-msgdb
1296 "Synchronize the folder data to the newest status.
1297 FOLDER is the ELMO folder structure.
1298 NEW-MARK, UNREAD-CACHED-MARK, READ-UNCACHED-MARK, and IMPORTANT-MARK
1299 are mark strings for new messages, unread but cached messages,
1300 read but not cached messages, and important messages.
1301 If optional IGNORE-MSGDB is non-nil, current msgdb is thrown away except
1302 read mark status. If IGNORE-MSGDB is 'visible-only, only visible messages
1303 \(the messages which are not in the killed-list\) are thrown away and
1305 If NO-CHECK is non-nil, rechecking folder is skipped.
1308 \(NEW-MSGDB DELETE-LIST CROSSED\)
1309 NEW-MSGDB is the newly appended msgdb.
1310 DELETE-LIST is a list of deleted message number.
1311 CROSSED is cross-posted message number.
1312 If update process is interrupted, return nil."
1313 (let ((killed-list (elmo-folder-killed-list-internal folder))
1315 number-alist mark-alist
1316 old-msgdb diff diff-2 delete-list new-list new-msgdb mark
1317 seen-list crossed after-append)
1318 (setq old-msgdb (elmo-folder-msgdb folder))
1320 (setq seen-list (elmo-msgdb-seen-load (elmo-folder-msgdb-path folder)))
1321 (setq number-alist (elmo-msgdb-get-number-alist
1322 (elmo-folder-msgdb folder)))
1323 (setq mark-alist (elmo-msgdb-get-mark-alist
1324 (elmo-folder-msgdb folder)))
1327 (setq seen-list (nconc
1328 (elmo-msgdb-seen-list
1329 (elmo-folder-msgdb folder)
1330 (list important-mark read-uncached-mark))
1332 (elmo-folder-clear folder (eq ignore-msgdb 'visible-only))))
1333 (unless no-check (elmo-folder-check folder))
1336 (message "Checking folder diff...")
1337 ;; TODO: killed list is loaded in elmo-folder-open and
1338 ;; list-messages use internal killed-list-folder.
1339 (setq diff (elmo-list-diff (elmo-folder-list-messages
1341 (eq 'visible-only ignore-msgdb))
1342 (unless ignore-msgdb
1347 (message "Checking folder diff...done")
1348 (setq new-list (elmo-folder-confirm-appends (car diff)))
1350 (when (and (not (eq (length (car diff))
1352 (setq diff-2 (elmo-list-diff (car diff) new-list)))
1353 (elmo-msgdb-append-to-killed-list folder (car diff-2)))
1354 (setq delete-list (cadr diff))
1355 (if (or (equal diff '(nil nil))
1357 (and (eq (length (car diff)) 0)
1358 (eq (length (cadr diff)) 0)))
1360 (elmo-folder-update-number folder)
1361 (elmo-folder-process-crosspost folder)
1362 (list nil nil nil) ; no updates.
1364 (if delete-list (elmo-msgdb-delete-msgs
1365 (elmo-folder-msgdb folder) delete-list))
1367 (setq new-msgdb (elmo-folder-msgdb-create
1370 new-mark unread-cached-mark
1371 read-uncached-mark important-mark
1373 (elmo-msgdb-change-mark (elmo-folder-msgdb folder)
1374 new-mark unread-uncached-mark)
1376 (if (elmo-folder-persistent-p folder)
1377 (setq seen-list (elmo-msgdb-seen-save
1378 (elmo-folder-msgdb-path folder) nil)))
1379 (setq before-append nil)
1380 (setq crossed (elmo-folder-append-msgdb folder new-msgdb))
1381 ;; process crosspost.
1382 ;; Return a cons cell of (NUMBER-CROSSPOSTS . NEW-MARK-ALIST).
1383 (elmo-folder-process-crosspost folder)
1384 (elmo-folder-set-message-modified-internal folder t)
1385 (elmo-folder-set-mark-modified-internal folder t))
1387 (list new-msgdb delete-list crossed)))
1389 ;; Resume to the original status.
1391 (elmo-folder-set-msgdb-internal folder old-msgdb))
1392 (elmo-folder-set-killed-list-internal folder killed-list)
1395 (defun elmo-folder-messages (folder)
1396 "Return number of messages in the FOLDER."
1398 (elmo-msgdb-get-number-alist
1399 (elmo-folder-msgdb folder))))
1402 (defun elmo-msgdb-load (folder &optional silent)
1404 (message "Loading msgdb for %s..." (elmo-folder-name-internal folder)))
1405 (let ((msgdb (elmo-load-msgdb (elmo-folder-msgdb-path folder))))
1406 (elmo-folder-set-info-max-by-numdb folder
1407 (elmo-msgdb-get-number-alist msgdb))
1410 (message "Loading msgdb for %s...done"
1411 (elmo-folder-name-internal folder)))
1414 (defun elmo-msgdb-delete-path (folder)
1415 (let ((path (elmo-folder-msgdb-path folder)))
1416 (if (file-directory-p path)
1417 (elmo-delete-directory path t))))
1419 (defun elmo-msgdb-rename-path (old-folder new-folder)
1420 (let* ((old (directory-file-name (elmo-folder-msgdb-path old-folder)))
1421 (new (directory-file-name (elmo-folder-msgdb-path new-folder)))
1422 (new-dir (directory-file-name (file-name-directory new))))
1423 (if (not (file-directory-p old))
1425 (if (file-exists-p new)
1426 (error "Already exists directory: %s" new)
1427 (if (not (file-exists-p new-dir))
1428 (elmo-make-directory new-dir))
1429 (rename-file old new)))))
1431 (defun elmo-setup-subscribed-newsgroups (groups)
1432 "Setup subscribed newsgroups.
1433 GROUPS is a list of newsgroup name string.
1434 Return a hashtable for newsgroups."
1435 (let ((hashtb (or elmo-newsgroups-hashtb
1436 (setq elmo-newsgroups-hashtb
1437 (elmo-make-hash (length groups))))))
1438 (dolist (group groups)
1439 (or (elmo-get-hash-val group hashtb)
1440 (elmo-set-hash-val group nil hashtb)))
1441 (setq elmo-newsgroups-hashtb hashtb)))
1443 (defvar elmo-crosspost-message-alist-modified nil)
1444 (defun elmo-crosspost-message-alist-load ()
1445 "Load crosspost message alist."
1446 (setq elmo-crosspost-message-alist (elmo-crosspost-alist-load))
1447 (setq elmo-crosspost-message-alist-modified nil))
1449 (defun elmo-crosspost-message-alist-save ()
1450 "Save crosspost message alist."
1451 (when elmo-crosspost-message-alist-modified
1452 (let ((alist elmo-crosspost-message-alist)
1458 (not (intern-soft x elmo-newsgroups-hashtb)))
1459 (nth 1 (car alist))))
1461 (setcar (cdar alist) newsgroups)
1462 (setq elmo-crosspost-message-alist
1463 (delete (car alist) elmo-crosspost-message-alist)))
1464 (setq alist (cdr alist)))
1465 (elmo-crosspost-alist-save elmo-crosspost-message-alist)
1466 (setq elmo-crosspost-message-alist-modified nil))))
1468 (defun elmo-folder-make-temporary-directory (folder)
1469 ;; Make a temporary directory for FOLDER.
1470 (let ((temp-dir (make-temp-name
1472 (file-name-as-directory (elmo-folder-msgdb-path folder))
1474 (elmo-make-directory temp-dir)
1478 "Initialize ELMO module."
1479 (elmo-crosspost-message-alist-load)
1480 (elmo-resque-obsolete-variables)
1481 (elmo-dop-queue-load))
1484 "Quit and cleanup ELMO."
1485 (elmo-crosspost-message-alist-save)
1486 (elmo-dop-queue-save)
1487 ;; Not implemented yet.
1488 (let ((types elmo-folder-type-alist)
1493 (intern (format "elmo-%s-folder" (symbol-name (cdr (car types)))))))
1494 ;; Call all folder's `elmo-quit' method.
1496 (dolist (func (luna-class-find-functions class 'elmo-quit))
1497 (funcall func nil)))
1498 (setq types (cdr types)))))
1502 (elmo-define-folder ?% 'imap4)
1503 (elmo-define-folder ?- 'nntp)
1504 (elmo-define-folder ?\+ 'localdir)
1505 (elmo-define-folder ?\* 'multi)
1506 (elmo-define-folder ?\/ 'filter)
1507 (elmo-define-folder ?\$ 'archive)
1508 (elmo-define-folder ?& 'pop3)
1509 (elmo-define-folder ?= 'localnews)
1510 (elmo-define-folder ?| 'pipe)
1511 (elmo-define-folder ?. 'maildir)
1512 (elmo-define-folder ?' 'internal)
1513 (elmo-define-folder ?\[ 'nmz)
1514 (elmo-define-folder ?@ 'shimbun)
1516 ;;; Obsolete variables.
1517 (elmo-define-obsolete-variable 'elmo-default-imap4-mailbox
1518 'elmo-imap4-default-mailbox)
1519 (elmo-define-obsolete-variable 'elmo-default-imap4-server
1520 'elmo-imap4-default-server)
1521 (elmo-define-obsolete-variable 'elmo-default-imap4-authenticate-type
1522 'elmo-imap4-default-authenticate-type)
1523 (elmo-define-obsolete-variable 'elmo-default-imap4-user
1524 'elmo-imap4-default-user)
1525 (elmo-define-obsolete-variable 'elmo-default-imap4-port
1526 'elmo-imap4-default-port)
1527 (elmo-define-obsolete-variable 'elmo-default-imap4-stream-type
1528 'elmo-imap4-default-stream-type)
1529 (elmo-define-obsolete-variable 'elmo-default-nntp-server
1530 'elmo-nntp-default-server)
1531 (elmo-define-obsolete-variable 'elmo-default-nntp-user
1532 'elmo-nntp-default-user)
1533 (elmo-define-obsolete-variable 'elmo-default-nntp-port
1534 'elmo-nntp-default-port)
1535 (elmo-define-obsolete-variable 'elmo-default-nntp-stream-type
1536 'elmo-nntp-default-stream-type)
1537 (elmo-define-obsolete-variable 'elmo-default-pop3-server
1538 'elmo-pop3-default-server)
1539 (elmo-define-obsolete-variable 'elmo-default-pop3-user
1540 'elmo-pop3-default-user)
1541 (elmo-define-obsolete-variable 'elmo-default-pop3-authenticate-type
1542 'elmo-pop3-default-authenticate-type)
1543 (elmo-define-obsolete-variable 'elmo-default-pop3-port
1544 'elmo-pop3-default-port)
1545 (elmo-define-obsolete-variable 'elmo-default-pop3-stream-type
1546 'elmo-pop3-default-stream-type)
1547 (elmo-define-obsolete-variable 'elmo-cache-dirname
1548 'elmo-cache-directory)
1549 (elmo-define-obsolete-variable 'elmo-msgdb-dir
1550 'elmo-msgdb-directory)
1552 ;; Obsolete functions.
1553 ;; 2001-12-11: *-dir -> *-directory
1554 (defalias 'elmo-folder-make-temp-dir 'elmo-folder-make-temporary-directory)
1555 (make-obsolete 'elmo-folder-make-temp-dir
1556 'elmo-folder-make-temporary-directory)
1560 (autoload 'elmo-dop-queue-flush "elmo-dop")
1561 (autoload 'elmo-nntp-post "elmo-nntp")
1564 (product-provide (provide 'elmo) (require 'elmo-version))
1566 ;;; elmo.el ends here