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
38 (require 'elmo-signal
)
40 (eval-when-compile (require 'cl
))
42 (if (or (featurep 'dbm
)
45 (featurep 'berkeley-db
))
46 (require 'elmo-database
))
48 (defcustom elmo-message-fetch-threshold
30000
50 :type
'(choice (integer :tag
"Threshold (bytes)")
51 (const :tag
"No limitation" nil
))
54 (defcustom elmo-message-fetch-confirm t
55 "If non-nil, confirm fetching if message size is larger than
56 `elmo-message-fetch-threshold'.
57 Otherwise, entire fetching of the message is aborted without confirmation."
61 (defcustom elmo-folder-update-threshold
500
63 :type
'(choice (integer :tag
"Number of messages")
64 (const :tag
"No limitation" nil
))
67 (defcustom elmo-folder-update-confirm t
68 "Confirm if update number exceeds `elmo-folder-update-threshold'."
72 (defcustom elmo-msgdb-path-encode-threshold nil
73 "*Encode msgdb path if its length is longer than this value."
74 :type
'(choice (const :tag
"No encode" nil
)
78 (defvar elmo-message-displaying nil
79 "A global switch to indicate message is displaying or not.")
82 (defvar elmo-folder-type-alist nil
)
84 (defvar elmo-newsgroups-hashtb nil
)
86 (elmo-define-error 'elmo-error
"Error" 'error
)
87 (elmo-define-error 'elmo-open-error
"Cannot open" 'elmo-error
)
88 (elmo-define-error 'elmo-authenticate-error
"Login failed" 'elmo-open-error
)
89 (elmo-define-error 'elmo-imap4-bye-error
"IMAP4 session was terminated" 'elmo-open-error
)
92 (elmo-define-signal flag-changing
(number old-flags new-flags
)
93 "Notify the changing flag of the messages with NUMBER.")
95 (elmo-define-signal flag-changed
(numbers)
96 "Notify the change flag of the messages with NUMBERS.")
98 (elmo-define-signal status-changed
(numbers)
99 "Notify the change status of the message with NUMBERS.")
101 (elmo-define-signal update-overview
(number)
102 "Notify update overview of the message with NUMBER.")
104 (elmo-define-signal message-number-changed
(old-number new-number
)
105 "Notify change of message number within the folder.")
109 (autoload 'md5
"md5")
110 (autoload 'elmo-dop-queue-flush
"elmo-dop")
111 (autoload 'elmo-nntp-post
"elmo-nntp")
112 (autoload 'elmo-global-flag-p
"elmo-flag")
113 (autoload 'elmo-local-flag-p
"elmo-flag")
114 (autoload 'elmo-global-flag-detach
"elmo-flag")
115 (autoload 'elmo-global-flag-detach-messages
"elmo-flag")
116 (autoload 'elmo-global-flag-set
"elmo-flag")
117 (autoload 'elmo-global-flag-replace-referrer
"elmo-flag")
118 (autoload 'elmo-get-global-flags
"elmo-flag")
119 (autoload 'elmo-global-flags-initialize
"elmo-flag")
120 (autoload 'elmo-global-mark-migrate
"elmo-flag")
121 (autoload 'elmo-folder-list-global-flag-messages
"elmo-flag")
122 (autoload 'elmo-search-register-engine
"elmo-search"))
124 (defun elmo-define-folder (prefix backend
)
126 If a folder name begins with PREFIX, use BACKEND."
127 (let ((pair (assq prefix elmo-folder-type-alist
)))
131 (setcdr pair backend
))
132 (setq elmo-folder-type-alist
(cons (cons prefix backend
)
133 elmo-folder-type-alist
)))))
135 (defmacro elmo-folder-type
(name)
136 "Get folder type from NAME string."
137 `(and (stringp ,name
)
138 (cdr (assoc (string-to-char ,name
) elmo-folder-type-alist
))))
141 ;; A elmo folder provides uniformed (orchestrated) access
142 ;; to the internet messages.
144 (luna-define-class elmo-folder
() (type ; folder type symbol.
145 name
; orignal folder name string.
146 prefix
; prefix for folder name
147 path
; directory path for msgdb.
148 msgdb
; msgdb (may be nil).
149 killed-list
; killed list.
150 flag-table
; flag table.
151 persistent
; non-nil if persistent.
152 process-duplicates
; read or hide
153 biff
; folder for biff
154 mime-charset
; charset for encode & decode
156 (luna-define-internal-accessors 'elmo-folder
))
158 (luna-define-generic elmo-folder-initialize
(folder name
)
159 ;; Initialize a FOLDER structure with NAME."
162 (defmacro elmo-folder-send
(folder message
&rest args
)
163 "Let FOLDER receive the MESSAGE with ARGS."
164 `(luna-send ,folder
,message
,folder
,@args
))
167 (defun elmo-make-folder (name &optional non-persistent mime-charset
)
168 "Make an ELMO folder structure specified by NAME.
169 If optional argument NON-PERSISTENT is non-nil, the folder msgdb is not saved.
170 If optional argument MIME-CHARSET is specified, it is used for
171 encode and decode a multibyte string."
172 (let ((type (elmo-folder-type name
))
173 prefix split class folder original
)
174 (setq original
(elmo-string name
))
177 (setq prefix
(elmo-string (substring name
0 1)))
178 (setq name
(elmo-string (substring name
1))))
179 (setq type
(intern (car (setq split
(split-string name
":")))))
180 (if (>= (length split
) 2)
181 (setq name
(substring name
(+ 1 (length (car split
)))))
182 (error "Error in folder name `%s'" original
))
183 (setq prefix
(concat (car split
) ":")))
184 (setq class
(format "elmo-%s" (symbol-name type
)))
185 (require (intern class
))
186 (setq folder
(luna-make-entity (intern (concat class
"-folder"))
190 :persistent
(not non-persistent
)
191 :mime-charset mime-charset
))
193 (elmo-folder-send folder
'elmo-folder-initialize name
))))
195 (defvar elmo-get-folder-function nil
)
197 (defun elmo-get-folder (name)
198 (or (and elmo-get-folder-function
199 (funcall elmo-get-folder-function name
))
200 (elmo-make-folder name
)))
202 ;; Note that this function is for internal use only.
203 (luna-define-generic elmo-folder-msgdb
(folder)
204 "Return the msgdb of FOLDER (on-demand loading).
205 \(For internal use only.\)")
207 (luna-define-method elmo-folder-msgdb
((folder elmo-folder
))
208 (or (elmo-folder-msgdb-internal folder
)
209 (elmo-folder-set-msgdb-internal folder
210 (elmo-folder-msgdb-load folder
))))
212 (luna-define-generic elmo-folder-open
(folder &optional load-msgdb
)
213 "Open and setup (load saved status) FOLDER.
214 If optional LOAD-MSGDB is non-nil, msgdb is loaded.
215 \(otherwise, msgdb is loaded on-demand)")
217 (luna-define-generic elmo-folder-open-internal
(folder)
218 "Open FOLDER (without loading saved folder status).")
220 (luna-define-generic elmo-folder-check
(folder)
221 "Check the FOLDER to obtain newest information at the next list operation.")
223 (luna-define-generic elmo-folder-clear
(folder &optional keep-killed
)
224 "Clear FOLDER to the initial state.
225 If optional KEEP-KILLED is non-nil, killed-list is not cleared.")
227 (luna-define-generic elmo-folder-commit
(folder)
228 "Save current status of FOLDER.")
230 (luna-define-generic elmo-folder-close
(folder)
231 "Close, save and clearnup FOLDER.")
233 (luna-define-generic elmo-folder-close-internal
(folder)
234 "Close FOLDER (without saving folder status).")
236 (luna-define-generic elmo-folder-plugged-p
(folder)
237 "Returns t if FOLDER is plugged.")
239 (luna-define-generic elmo-folder-set-plugged
(folder plugged
&optional add
)
240 "Set FOLDER as plugged.")
242 (luna-define-generic elmo-net-port-info
(folder)
243 "Get port information of FOLDER.")
245 (luna-define-generic elmo-folder-use-flag-p
(folder)
246 "Returns t if FOLDER treats unread/important flag itself.")
248 (luna-define-generic elmo-folder-diff
(folder)
250 Return value is cons cell or list:
251 - a cons cell (new . all)
252 - a list (new unread all)")
254 (luna-define-generic elmo-folder-status
(folder)
255 "Returns a cons cell of (MAX-NUMBER . MESSAGES) in the FOLDER.")
257 (luna-define-generic elmo-folder-reserve-status-p
(folder)
258 "If non-nil, the folder should not close folder after `elmo-folder-status'.")
260 (luna-define-generic elmo-folder-list-messages
(folder &optional visible-only
262 "Return a list of message numbers contained in FOLDER.
263 If optional VISIBLE-ONLY is non-nil, killed messages are not listed.
264 If second optional IN-MSGDB is non-nil, only messages in the msgdb are listed.")
266 (luna-define-method elmo-folder-list-messages
((folder elmo-folder
)
267 &optional visible-only in-msgdb
)
268 (let ((list (if in-msgdb
270 (elmo-folder-list-messages-internal folder visible-only
)))
271 (killed-list (elmo-folder-killed-list-internal folder
)))
274 (setq list
(elmo-msgdb-list-messages (elmo-folder-msgdb folder
))))
276 (elmo-living-messages list killed-list
)
277 (if (and in-msgdb killed-list
)
278 (elmo-uniq-sorted-list
279 (sort (nconc (elmo-number-set-to-number-list killed-list
) list
) #'<)
283 (luna-define-generic elmo-folder-list-messages-internal
(folder &optional
285 ;; Return a list of message numbers contained in FOLDER.
286 ;; Return t if the message list is not available.
289 (luna-define-generic elmo-folder-list-flagged
(folder flag
&optional in-msgdb
)
290 "List messages in the FOLDER with FLAG.
291 FLAG is a symbol which is one of the following:
293 `unread' (unread messages (new messages are included))
294 `answered' (answered or forwarded)
295 `important' (marked as important)
298 `digest' (unread + important + other flags)
299 `any' (digest + answered + other flags)
300 If optional IN-MSGDB is non-nil, retrieve flag information from msgdb.")
302 (luna-define-method elmo-folder-list-flagged
((folder elmo-folder
) flag
304 (let ((msgs (if in-msgdb
306 (elmo-folder-list-flagged-internal folder flag
))))
308 (setq msgs
(elmo-msgdb-list-flagged (elmo-folder-msgdb folder
) flag
)))
312 (nconc (elmo-folder-list-global-flag-messages folder flag
) msgs
)
315 (luna-define-generic elmo-folder-list-flagged-internal
(folder flag
)
316 "Return a list of message in the FOLDER with FLAG.
317 Return t if the message list is not available.")
319 (luna-define-method elmo-folder-list-flagged-internal
((folder elmo-folder
)
323 (luna-define-generic elmo-folder-list-subfolders
(folder &optional one-level
)
324 "Returns a list of subfolders contained in FOLDER.
325 If optional argument ONE-LEVEL is non-nil, only children of FOLDER is returned.
326 \(a folder which have children is returned as a list\)
327 Otherwise, all descendent folders are returned.")
329 (luna-define-generic elmo-folder-have-subfolder-p
(folder)
330 "Return non-nil when FOLDER has subfolders.")
332 (luna-define-generic elmo-folder-exists-p
(folder)
333 "Returns non-nil when FOLDER exists.")
335 (luna-define-generic elmo-folder-creatable-p
(folder)
336 "Returns non-nil when FOLDER is creatable.")
338 (luna-define-generic elmo-folder-writable-p
(folder)
339 "Returns non-nil when FOLDER is writable.")
341 (luna-define-generic elmo-folder-persistent-p
(folder)
342 "Return non-nil when FOLDER is persistent.")
344 (luna-define-generic elmo-folder-create
(folder)
347 (luna-define-generic elmo-message-deletable-p
(folder number
)
348 "Returns non-nil when the message in the FOLDER with NUMBER is deletable.")
350 (luna-define-generic elmo-folder-delete
(folder)
351 "Delete FOLDER completely.")
353 (luna-define-generic elmo-folder-rename
(folder new-name
)
354 "Rename FOLDER to NEW-NAME (string).")
356 (luna-define-generic elmo-folder-delete-messages
(folder numbers
)
357 "Delete messages with msgdb entity.
358 FOLDER is the ELMO folder structure.
359 NUMBERS is a list of message numbers to be deleted.
360 It is not recommended to use this function other than internal use.
361 Use `elmo-folder-move-messages' with dst-folder 'null instead.")
363 (luna-define-generic elmo-folder-delete-messages-internal
(folder numbers
)
364 "Delete messages, but no delete msgdb entity.
365 FOLDER is the ELMO folder structure.
366 NUMBERS is a list of message numbers to be deleted.
367 Override this method by each implement of `elmo-folder'.")
369 (luna-define-generic elmo-folder-search
(folder condition
&optional numbers
)
370 "Search and return list of message numbers.
371 FOLDER is the ELMO folder structure.
372 CONDITION is a condition structure for searching.
373 If optional argument NUMBERS is specified and is a list of message numbers,
374 messages are searched from the list.")
376 (luna-define-generic elmo-message-match-condition
(folder number
379 "Return non-nil when the message in the FOLDER with NUMBER is matched.
380 CONDITION is a condition structure for testing.
381 NUMBERS is a list of message numbers,
382 use to be test for \"last\" and \"first\" predicates.")
384 (luna-define-generic elmo-folder-msgdb-create
(folder numbers flag-table
)
385 "Create a message database (implemented in each backends).
386 FOLDER is the ELMO folder structure.
387 NUMBERS is a list of message numbers to create msgdb.
388 FLAG-TABLE is a hashtable of message-id and flag.")
390 (luna-define-generic elmo-folder-set-flag
(folder numbers flag
393 FOLDER is a ELMO folder structure.
394 NUMBERS is a list of message number to set flag.
396 FLAG is a symbol which is one of the following:
397 `unread' (set the message as unread)
398 `answered' (set the message as answered)
399 `important' (set the message as important)
401 `read' (remove new and unread flags)
402 If optional IS-LOCAL is non-nil, update only local (not server) status.")
404 (luna-define-generic elmo-folder-unset-flag
(folder numbers flag
406 "Unset messages flag.
407 FOLDER is a ELMO folder structure.
408 NUMBERS is a list of message number to unset flag.
410 FLAG is a symbol which is one of the following:
411 `unread' (remove unread and new flag)
412 `answered' (remove answered flag)
413 `important' (remove important flag)
415 `read' (set unread flag)
416 `all' (remove all flags)
417 If optional IS-LOCAL is non-nil, update only local (not server) status.")
419 (luna-define-generic elmo-message-flag-available-p
(folder number flag
)
420 "Return non-nil when a message in the FOLDER with NUMBER treats FLAG.")
422 (luna-define-generic elmo-folder-next-message-number
(folder)
423 "The next message number that will be assigned to a new message.
424 FOLDER is the ELMO folder structure.")
426 (luna-define-generic elmo-folder-append-buffer
(folder &optional flags
428 "Append current buffer as a new message.
429 FOLDER is the destination folder (ELMO folder structure).
430 FLAGS is the flag list for the appended message (list of symbols).
431 If FLAGS contain `read', the message is appended as `not-unread'.
432 If it is nil, the appended message will be treated as `new'.
433 If optional argument NUMBER is specified, the new message number is set
435 Return nil on failure.")
437 (luna-define-generic elmo-folder-pack-numbers
(folder)
438 "Pack message numbers of FOLDER.")
440 (luna-define-generic elmo-folder-update-number
(folder)
441 "Update number of FOLDER.")
443 (luna-define-generic elmo-folder-diff-async
(folder)
444 "Get diff of FOLDER asynchronously.")
446 (luna-define-generic elmo-folder-expand-msgdb-path
(folder)
447 "Expand path for FOLDER.")
449 (luna-define-generic elmo-folder-get-primitive-list
(folder)
450 "Get primitive folder structure list contained in FOLDER.")
452 (luna-define-generic elmo-folder-contains-type
(folder type
)
453 "Returns t if FOLDER contains TYPE.")
455 (luna-define-generic elmo-folder-local-p
(folder)
456 "Returns t if FOLDER is local.")
458 (luna-define-generic elmo-folder-message-file-p
(folder)
459 "Returns t if all messages in the FOLDER are files.")
462 (luna-define-generic elmo-message-use-cache-p
(folder number
)
463 "Returns t if the message in the FOLDER with NUMBER uses cache.")
465 (luna-define-generic elmo-message-file-name
(folder number
)
466 "Return the file name of a message specified by FOLDER and NUMBER.")
470 ;;; Use original file
471 (luna-define-generic elmo-folder-message-file-number-p
(folder)
472 "Return t if the file name in the FOLDER is the message number.")
474 (luna-define-generic elmo-folder-message-file-directory
(folder)
475 "Return the directory of the message files of FOLDER.")
477 ;;; Use temporary file
478 (luna-define-generic elmo-folder-message-make-temp-file-p
(folder)
479 "Return t if the messages in the FOLDER makes local temporary file.")
481 (luna-define-generic elmo-folder-message-make-temp-files
(folder
485 "Make a new temporary files from the messages in the FOLDER with NUMBERS.
486 If START-NUMBER is specified, temporary files begin from the number.
487 Otherwise, same number is used for temporary files.
488 Return newly created temporary directory name which contains temporary files.")
490 (luna-define-generic elmo-message-file-p
(folder number
)
491 "Return t if message in the FOLDER with NUMBER is a file.")
493 (luna-define-generic elmo-message-flags
(folder number
)
494 "Return a list of flags.
495 FOLDER is a ELMO folder structure.
496 NUMBER is a number of the message.")
498 (defun elmo-message-flags-for-append (folder number
&optional message-id
)
499 "Return a list of flags for `elmo-folder-append-buffer'.
500 FOLDER is a ELMO folder structure.
501 NUMBER is a number of the message.
502 If optional argument MESSAGES-ID is not specified, get it from current buffer."
503 (let ((this-id (elmo-message-field folder number
'message-id
)))
505 (string= this-id
(or message-id
506 (elmo-msgdb-get-message-id-from-buffer)))
507 (or (elmo-message-flags folder number
)
508 ;; message exists, but no flag.
511 (luna-define-method elmo-message-flag-available-p
((folder elmo-folder
) number
513 (elmo-msgdb-flag-available-p (elmo-folder-msgdb folder
) flag
))
515 (luna-define-method elmo-message-flags
((folder elmo-folder
) number
)
516 (elmo-msgdb-flags (elmo-folder-msgdb folder
) number
))
518 (defsubst elmo-message-flagged-p
(folder number flag
)
519 "Return non-nil if the message is set FLAG.
520 FOLDER is a ELMO folder structure.
521 NUMBER is a message number to test."
522 (let ((cur-flags (elmo-message-flags folder number
)))
525 (not (memq 'unread cur-flags
)))
527 (memq flag cur-flags
)))))
529 (luna-define-generic elmo-find-fetch-strategy
(folder number
533 "Return the message fetching strategy suitable for the message with NUMBER.
534 FOLDER is the ELMO folder structure.
535 If optional argument IGNORE-CACHE is non-nil, existing cache is ignored.
536 If second optional argument REQUIRE-ENTIRENESS is non-nil,
537 ensure that entireness of the returned strategy is entire.
538 Returned value is a elmo-fetch-strategy object.
539 If return value is nil, message should not be nil.")
541 (defmacro elmo-make-fetch-strategy
(entireness
546 "Make elmo-message-fetching strategy.
547 ENTIRENESS is 'entire or 'section.
548 'entire means fetch message entirely at once.
549 'section means fetch message section by section.
550 If optional USE-CACHE is non-nil, existing cache is used and otherwise,
551 existing cache is thrown away.
552 If SAVE-CACHE is non-nil, fetched message is saved.
553 CACHE-PATH is the cache path to be used as a message cache file."
554 `(vector ,entireness
,use-cache
,save-cache
,cache-path
))
556 (defmacro elmo-fetch-strategy-entireness
(strategy)
557 "Return entireness of STRATEGY."
560 (defmacro elmo-fetch-strategy-use-cache
(strategy)
561 "Return use-cache of STRATEGY."
564 (defmacro elmo-fetch-strategy-save-cache
(strategy)
565 "Return save-cache of STRATEGY."
568 (defmacro elmo-fetch-strategy-cache-path
(strategy)
569 "Return cache-path of STRATEGY."
572 (luna-define-method elmo-find-fetch-strategy
((folder elmo-folder
) number
576 (let ((entity (elmo-message-entity folder number
)))
578 (elmo-make-fetch-strategy 'entire
)
579 (let* ((size (elmo-message-entity-field entity
'size
))
580 (message-id (elmo-message-entity-field entity
'message-id
))
581 (cache-file (elmo-file-cache-get message-id
))
582 (use-cache (elmo-message-use-cache-p folder number
)))
583 (if (and (not ignore-cache
)
585 (eq (elmo-file-cache-status cache-file
) 'entire
))
586 ;; Cache exists and use it.
587 (elmo-make-fetch-strategy
590 use-cache
; Save cache.
591 (elmo-file-cache-path cache-file
))
592 ;; No cache or ignore-cache.
593 (if (and (not (elmo-folder-local-p folder
))
594 (not require-entireness
)
595 elmo-message-fetch-threshold
597 (>= size elmo-message-fetch-threshold
)
598 (or (not elmo-message-fetch-confirm
)
601 (format "Fetch entire message(%dbytes)? "
604 ;; Don't fetch message at all.
606 ;; Don't use existing cache and fetch entire message at once.
607 (elmo-make-fetch-strategy
609 nil
; Don't use cache.
610 use-cache
; Save cache.
611 (elmo-file-cache-path cache-file
))))))))
613 (luna-define-method elmo-folder-list-messages-internal
614 ((folder elmo-folder
) &optional visible-only
)
617 (luna-define-generic elmo-message-encache
(folder number
&optional read
)
618 "Encache message in the FOLDER with NUMBER.
619 If READ is non-nil, message is flaged as read.")
621 (luna-define-method elmo-message-encache
((folder elmo-folder
) number
627 (elmo-make-fetch-strategy 'entire
630 (setq path
(elmo-file-cache-get-path
632 folder number
'message-id
))))
636 (luna-define-generic elmo-message-fetch-bodystructure
(folder number strategy
)
637 "Fetch bodystructure of the message in FOLDER with NUMBER using STRATEGY.")
639 (luna-define-generic elmo-message-fetch
(folder number strategy
643 "Fetch a message into current buffer.
644 FOLDER is the ELMO folder structure.
645 NUMBER is the number of the message in the FOLDER.
646 STRATEGY is the message fetching strategy.
647 If optional argument UNREAD is non-nil, message is not flaged as read.
648 If second optional argument SECTION is specified, only the
649 SECTION of the message is fetched (if possible).
650 Returns non-nil if fetching was succeed.")
652 (luna-define-generic elmo-message-fetch-internal
(folder number strategy
656 "Fetch a message into current buffer.
657 FOLDER is the ELMO folder structure.
658 NUMBER is the number of the message in the FOLDER.
659 STRATEGY is the message fetching strategy.
660 If optional argument SECTION is specified, only the SECTION of the message
661 is fetched (if possible).
662 If second optional argument UNREAD is non-nil, message is not flaged as read.
663 Returns non-nil if fetching was succeed.")
665 (luna-define-generic elmo-message-fetch-field
(folder number field
)
666 "Fetch a message field value.
667 FOLDER is the ELMO folder structure.
668 NUMBER is the number of the message in the FOLDER.
669 FIELD is a symbol of the field name.")
671 (luna-define-generic elmo-message-folder
(folder number
)
672 "Get primitive folder of the message.")
674 (luna-define-generic elmo-folder-process-crosspost
(folder)
675 "Process crosspost for FOLDER.
676 Return a cons cell of (NUMBER-CROSSPOSTS . NEW-FLAG-ALIST).")
678 (luna-define-generic elmo-folder-newsgroups
(folder)
679 "Return list of newsgroup name of FOLDER.")
681 (luna-define-generic elmo-folder-search-requires-msgdb-p
(folder condition
)
682 "Return non-nil if searching in FOLDER by CONDITION requires msgdb fetch.")
684 (defun elmo-folder-search-requires-msgdb-p-internal (folder condition
)
685 (if (listp condition
)
686 (or (elmo-folder-search-requires-msgdb-p-internal
687 folder
(nth 1 condition
))
688 (elmo-folder-search-requires-msgdb-p-internal
689 folder
(nth 2 condition
)))
690 (and (not (string= (elmo-filter-key condition
) "last"))
691 (not (string= (elmo-filter-key condition
) "first")))))
693 (luna-define-method elmo-folder-search-requires-msgdb-p
((folder elmo-folder
)
695 (elmo-folder-search-requires-msgdb-p-internal folder condition
))
697 (luna-define-method elmo-folder-newsgroups
((folder elmo-folder
))
700 (luna-define-method elmo-folder-open
((folder elmo-folder
)
701 &optional load-msgdb
)
702 (elmo-generic-folder-open folder load-msgdb
))
704 (defun elmo-generic-folder-open (folder load-msgdb
)
705 (let ((inhibit-quit t
))
706 (if load-msgdb
(elmo-folder-msgdb folder
))
707 (elmo-folder-set-killed-list-internal
709 (elmo-msgdb-killed-list-load (elmo-folder-msgdb-path folder
))))
710 (elmo-folder-open-internal folder
))
712 (luna-define-method elmo-folder-open-internal
((folder elmo-folder
))
713 nil
; default is do nothing.
716 (luna-define-method elmo-folder-check
((folder elmo-folder
))
717 nil
) ; default is noop.
719 (luna-define-method elmo-folder-commit
((folder elmo-folder
))
720 (elmo-generic-folder-commit folder
))
722 (defun elmo-generic-folder-commit (folder)
723 (when (elmo-folder-persistent-p folder
)
724 (let ((msgdb (elmo-folder-msgdb-internal folder
)))
726 (when (elmo-msgdb-message-modified-p msgdb
)
727 (elmo-folder-set-info-max-by-numdb
729 (elmo-folder-list-messages folder nil
'in-msgdb
)))
730 (elmo-msgdb-save msgdb
)))
731 (elmo-msgdb-killed-list-save
732 (elmo-folder-msgdb-path folder
)
733 (elmo-folder-killed-list-internal folder
))))
735 (luna-define-method elmo-folder-close-internal
((folder elmo-folder
))
739 (luna-define-method elmo-folder-close
((folder elmo-folder
))
740 (elmo-generic-folder-close folder
)
741 (elmo-folder-close-internal folder
))
743 (defun elmo-generic-folder-close (folder)
744 (elmo-folder-commit folder
)
745 (elmo-folder-set-msgdb-internal folder nil
)
746 (elmo-folder-set-killed-list-internal folder nil
))
748 (luna-define-method elmo-folder-plugged-p
((folder elmo-folder
))
749 t
) ; default is plugged.
751 (luna-define-method elmo-folder-set-plugged
((folder elmo-folder
) plugged
753 nil
) ; default is do nothing.
755 (luna-define-method elmo-folder-use-flag-p
((folder elmo-folder
))
756 nil
) ; default is no flag.
758 (luna-define-method elmo-folder-persistent-p
((folder elmo-folder
))
759 (elmo-folder-persistent-internal folder
))
761 (luna-define-method elmo-folder-creatable-p
((folder elmo-folder
))
762 nil
) ; default is not creatable.
764 (luna-define-method elmo-folder-writable-p
((folder elmo-folder
))
765 nil
) ; default is not writable.
767 (luna-define-method elmo-folder-delete
((folder elmo-folder
))
768 (when (yes-or-no-p (format "Delete msgdb of \"%s\"? "
769 (elmo-folder-name-internal folder
)))
770 (elmo-msgdb-delete-path folder
)
773 (luna-define-method elmo-folder-rename
((folder elmo-folder
) new-name
)
774 (let ((new-folder (elmo-make-folder
777 (elmo-folder-mime-charset-internal folder
))))
778 (unless (eq (elmo-folder-type-internal folder
)
779 (elmo-folder-type-internal new-folder
))
780 (error "Not same folder type"))
781 (when (or (file-exists-p (elmo-folder-msgdb-path new-folder
))
782 (elmo-folder-exists-p new-folder
))
783 (error "Already exists folder: %s" new-name
))
784 (elmo-folder-send folder
'elmo-folder-rename-internal new-folder
)
785 (elmo-global-flag-replace-referrer (elmo-folder-name-internal folder
)
787 (elmo-msgdb-rename-path folder new-folder
)))
789 (luna-define-method elmo-folder-delete-messages
((folder elmo-folder
)
791 (and (elmo-folder-delete-messages-internal folder numbers
)
792 (elmo-folder-detach-messages folder numbers
)))
794 (luna-define-method elmo-folder-search
((folder elmo-folder
)
797 (let ((numbers (or numbers
(elmo-folder-list-messages folder
)))
798 (msgdb (elmo-folder-msgdb folder
))
800 (setq results
(elmo-msgdb-search msgdb condition numbers
))
803 (elmo-condition-optimize condition
)
804 (when (and (consp condition
)
805 (eq (car condition
) 'and
)
806 (listp (setq results
(elmo-msgdb-search msgdb
809 (setq numbers results
810 condition
(nth 2 condition
)))
812 (elmo-with-progress-display (elmo-folder-search (length numbers
))
814 (dolist (number numbers
)
816 (setq result
(elmo-msgdb-match-condition msgdb
820 (when (elmo-filter-condition-p result
)
821 (setq result
(elmo-message-match-condition folder
826 (setq matched
(cons number matched
))))
827 (elmo-progress-notify 'elmo-folder-search
)))
828 (nreverse matched
)))))
830 (defun elmo-message-buffer-match-condition (condition number
)
831 (let* ((handler (luna-make-entity 'modb-buffer-entity-handler
))
832 (result (elmo-condition-match
834 (lambda (condition handler entity
)
835 (elmo-msgdb-message-match-condition handler
840 (elmo-msgdb-make-message-entity
843 :buffer
(current-buffer))))))
844 (and result
(not (elmo-filter-condition-p result
)))))
846 (luna-define-method elmo-message-match-condition
((folder elmo-folder
)
849 (let* (cache cache-path
851 ((elmo-message-file-name folder number
))
853 (setq cache
(elmo-file-cache-get
854 (elmo-message-field folder number
856 (setq cache-path
(elmo-file-cache-path cache
))
858 (not (elmo-cache-path-section-p cache-path
))))
860 (when (and filename
(file-readable-p filename
))
862 (set-buffer-multibyte nil
)
863 ;;(insert-file-contents-as-binary filename)
864 (elmo-message-fetch folder number
865 (elmo-make-fetch-strategy 'entire
870 (set-buffer-multibyte default-enable-multibyte-characters
)
871 (decode-coding-region (point-min) (point-max)
872 elmo-mime-display-as-is-coding-system
)
873 (elmo-message-buffer-match-condition condition number
)))))
875 (luna-define-method elmo-folder-pack-numbers
((folder elmo-folder
))
876 nil
) ; default is noop.
878 (luna-define-method elmo-folder-update-number
((folder elmo-folder
))
879 nil
) ; default is noop.
881 (luna-define-method elmo-folder-message-file-p
((folder elmo-folder
))
882 nil
) ; default is not file.
884 (luna-define-method elmo-folder-message-file-number-p
((folder elmo-folder
))
885 nil
) ; default is not number.
887 (luna-define-method elmo-folder-message-make-temp-file-p
((folder elmo-folder
))
888 nil
) ; default is not make temp file.
890 (luna-define-method elmo-message-file-name
((folder elmo-folder
)
892 nil
) ; default is no name.
894 (luna-define-method elmo-folder-local-p
((folder elmo-folder
))
895 t
) ; default is local.
897 (luna-define-method elmo-folder-have-subfolder-p
((folder elmo-folder
))
901 (luna-define-generic elmo-folder-flag-table
(folder &optional if-exists
)
902 "Return the flag-table of FOLDER.
903 If optional argument IF-EXISTS is nil, load on demand.
904 \(For internal use only.\)")
906 (luna-define-generic elmo-folder-close-flag-table
(folder)
907 "Close flag-table of FOLDER.")
909 (luna-define-method elmo-folder-flag-table
((folder elmo-folder
)
911 (or (elmo-folder-flag-table-internal folder
)
913 (elmo-folder-set-flag-table-internal
915 (elmo-flag-table-load (elmo-folder-msgdb-path folder
))))))
917 (luna-define-method elmo-folder-close-flag-table
((folder elmo-folder
))
918 (elmo-flag-table-save (elmo-folder-msgdb-path folder
)
919 (elmo-folder-flag-table folder
))
920 (elmo-folder-set-flag-table-internal folder nil
))
922 (defun elmo-folder-preserve-flags (folder msgid flags
)
923 "Preserve FLAGS into FOLDER for a message that has MSGID."
924 (when (and msgid flags
)
925 (let ((flag-table (elmo-folder-flag-table folder
'if-exists
))
927 (when (setq load-now
(null flag-table
))
928 (setq flag-table
(elmo-folder-flag-table folder
)))
929 (elmo-flag-table-set flag-table msgid flags
)
931 (elmo-folder-close-flag-table folder
)))))
934 ;; Folder info is a message number information cache (hashtable)
935 (defsubst elmo-folder-get-info
(folder &optional hashtb
)
936 "Return FOLDER info from HASHTB (default is `elmo-folder-info-hashtb')."
937 (elmo-get-hash-val (elmo-folder-name-internal folder
)
938 (or hashtb elmo-folder-info-hashtb
)))
940 (defun elmo-folder-set-info-hashtb (folder max numbers
&optional new unread
)
941 "Set FOLDER info (means MAX, NUMBERS, NEW and UNREAD)."
942 (let ((info (elmo-folder-get-info folder
)))
944 (or new
(setq new
(nth 0 info
)))
945 (or unread
(setq unread
(nth 1 info
)))
946 (or numbers
(setq numbers
(nth 2 info
)))
947 (or max
(setq max
(nth 3 info
))))
948 (elmo-set-hash-val (elmo-folder-name-internal folder
)
949 (list new unread numbers max
)
950 elmo-folder-info-hashtb
)))
952 (defun elmo-folder-set-info-max-by-numdb (folder numbers
)
953 "Set FOLDER info by MSGDB-NUMBER in msgdb."
954 (elmo-folder-set-info-hashtb
956 (if numbers
(apply #'max numbers
) 0)
957 nil
;;(length num-db)
960 (defun elmo-folder-get-info-max (folder)
961 "Return max number of FODLER from folder info."
962 (nth 3 (elmo-folder-get-info folder
)))
964 (defun elmo-folder-get-info-length (folder)
965 "Return length of FODLER from folder info."
966 (nth 2 (elmo-folder-get-info folder
)))
968 (defun elmo-folder-get-info-unread (folder)
969 "Return unread of FODLER from folder info."
970 (nth 1 (elmo-folder-get-info folder
)))
972 (defun elmo-folder-info-make-hashtb (info-alist hashtb
)
973 "Setup folder info hashtable by INFO-ALIST on HASHTB."
974 (let* ((hashtb (or hashtb
975 (elmo-make-hash (length info-alist
)))))
978 (let ((info (cadr x
)))
979 (and (intern-soft (car x
) hashtb
)
980 (elmo-set-hash-val (car x
)
981 (list (nth 2 info
) ;; new
982 (nth 3 info
) ;; unread
983 (nth 1 info
) ;; length
987 (setq elmo-folder-info-hashtb hashtb
)))
989 (defsubst elmo-diff-new
(diff)
992 (defsubst elmo-diff-unread
(diff)
993 (when (consp (cdr diff
))
996 (defsubst elmo-diff-all
(diff)
997 (if (consp (cdr diff
))
1001 (defsubst elmo-strict-folder-diff
(folder)
1002 "Return folder diff information strictly from FOLDER."
1003 (let ((in-db (sort (elmo-folder-list-messages folder nil
'in-msgdb
) '<))
1004 (in-folder (elmo-folder-list-messages folder
))
1005 append-list delete-list diff
)
1006 (cons (if (equal in-folder in-db
)
1008 (setq diff
(elmo-list-diff in-folder in-db
))
1009 (setq append-list
(car diff
))
1010 (setq delete-list
(cadr diff
))
1012 (length append-list
)
1014 (- 0 (length delete-list
))
1016 (length in-folder
))))
1018 (luna-define-method elmo-folder-diff
((folder elmo-folder
))
1019 (elmo-generic-folder-diff folder
))
1021 (defun elmo-generic-folder-diff (folder)
1022 (if (elmo-string-match-member (elmo-folder-name-internal folder
)
1023 elmo-strict-diff-folder-list
)
1024 (elmo-strict-folder-diff folder
)
1025 (let ((cached-in-db-max (elmo-folder-get-info-max folder
))
1026 (in-folder (elmo-folder-status folder
))
1030 (if (not cached-in-db-max
)
1031 (let ((number-list (elmo-folder-list-messages folder
1034 (setq in-db number-list
)
1035 (setq in-db-max
(if in-db
(apply #'max in-db
) 0))
1036 (elmo-folder-set-info-hashtb folder in-db-max nil
))
1037 (setq in-db-max cached-in-db-max
))
1038 (setq unsync
(if (and in-db
(car in-folder
))
1039 (- (car in-folder
) in-db-max
)
1040 (if (and in-folder
(null in-db
))
1043 (setq messages
(cdr in-folder
))
1044 (if (and unsync messages
(> unsync messages
))
1045 (setq unsync messages
))
1046 (cons (or unsync
0) (or messages
0)))))
1048 (defvar elmo-folder-diff-async-callback nil
)
1049 (defvar elmo-folder-diff-async-callback-data nil
)
1051 (luna-define-method elmo-folder-diff-async
((folder elmo-folder
))
1052 (and elmo-folder-diff-async-callback
1053 (funcall elmo-folder-diff-async-callback
1055 (elmo-folder-diff folder
))))
1057 (luna-define-method elmo-folder-get-primitive-list
((folder elmo-folder
))
1060 (luna-define-method elmo-folder-contains-type
((folder elmo-folder
) type
)
1061 (eq (elmo-folder-type-internal folder
) type
))
1063 (luna-define-method elmo-folder-next-message-number
((folder elmo-folder
))
1064 (+ 1 (elmo-max-of-list (or (elmo-folder-list-messages folder
)
1068 (luna-define-class elmo-file-tag
))
1070 (defconst elmo-append-messages-dispatch-table
1071 '(((nil . null
) . elmo-folder-append-messages-
*-null
)
1072 ((filter . nil
) . elmo-folder-append-messages-filter-
*)
1073 ((nil . filter
) . elmo-folder-append-messages-
*-filter
)
1074 ((pipe . nil
) . elmo-folder-append-messages-pipe-
*)
1075 ((nil . pipe
) . elmo-folder-append-messages-
*-pipe
)
1076 ((multi . nil
) . elmo-folder-append-messages-multi-
*)
1077 ((nil . flag
) . elmo-folder-append-messages-
*-flag
)
1078 ((imap4 . imap4
) . elmo-folder-append-messages-imap4-imap4
)
1079 ((elmo-file-tag . localdir
) . elmo-folder-append-messages-
*-localdir
)
1080 ((elmo-file-tag . maildir
) . elmo-folder-append-messages-
*-maildir
)
1081 ((nil . archive
) . elmo-folder-append-messages-
*-archive
)
1082 ((nil . nil
) . elmo-generic-folder-append-messages
)))
1084 (defun elmo-folder-type-p (folder type
)
1086 (eq (elmo-folder-type-internal folder
) type
)
1087 (labels ((member-if (predicate list
)
1089 (or (funcall predicate
(car list
))
1090 (member-if predicate
(cdr list
)))))
1091 (subtypep (name type
)
1093 (let ((class (luna-find-class name
)))
1095 (member-if (lambda (name)
1096 (subtypep name type
))
1097 (luna-class-parents class
)))))))
1098 (subtypep (luna-class-name folder
)
1099 (or (intern-soft (format "elmo-%s-folder" type
))
1102 (defun elmo-folder-append-messages (dst-folder src-folder numbers
1103 &optional same-number caller
)
1104 "Append messages from folder.
1105 DST-FOLDER is the ELMO folder structure.
1106 Caller should make sure DST-FOLDER is `writable'.
1107 \(Can be checked with `elmo-folder-writable-p'\).
1108 SRC-FOLDER is the source ELMO folder structure.
1109 NUMBERS is the message numbers to be appended in the SRC-FOLDER.
1110 If second optional argument SAME-NUMBER is specified,
1111 message number is preserved \(if possible\).
1112 Returns a list of message numbers successfully appended."
1113 (let ((rest (if caller
1114 (cdr (memq (rassq caller elmo-append-messages-dispatch-table
)
1115 elmo-append-messages-dispatch-table
))
1116 elmo-append-messages-dispatch-table
))
1119 (let ((types (car (car rest
))))
1120 (if (and (elmo-folder-type-p src-folder
(car types
))
1121 (elmo-folder-type-p dst-folder
(cdr types
)))
1122 (setq result
(funcall (cdr (car rest
))
1123 dst-folder src-folder numbers same-number
)
1125 (setq rest
(cdr rest
)))))
1128 (defun elmo-generic-folder-append-messages (folder src-folder numbers
1130 (let ((src-msgdb-exists (not (zerop (elmo-folder-length src-folder
))))
1132 succeed-numbers failure cache id
)
1133 (elmo-folder-flag-table folder
) ; load
1135 (set-buffer-multibyte nil
)
1138 id
(and src-msgdb-exists
1139 (elmo-message-field src-folder
(car numbers
)
1142 (setq cache
(elmo-file-cache-get id
)
1147 src-folder
(car numbers
)
1148 (if (elmo-folder-plugged-p src-folder
)
1149 (elmo-make-fetch-strategy
1151 (and cache
(elmo-file-cache-path cache
)))
1152 (or (and elmo-enable-disconnected-operation
1154 (eq (elmo-file-cache-status cache
) 'entire
)
1155 (elmo-make-fetch-strategy
1157 (elmo-file-cache-path cache
)))
1158 (error "Unplugged")))
1161 (elmo-folder-append-buffer
1163 (elmo-message-flags-for-append src-folder
(car numbers
))
1164 (if same-number
(car numbers
))))))
1165 (error (setq failure t
)))
1166 ;; FETCH & APPEND finished
1168 (setq succeed-numbers
(cons (car numbers
) succeed-numbers
)))
1169 (elmo-progress-notify 'elmo-folder-move-messages
)
1170 (setq numbers
(cdr numbers
)))
1171 (when (elmo-folder-persistent-p folder
)
1172 (elmo-folder-close-flag-table folder
))
1175 ;; Arguments should be reduced.
1176 (defun elmo-folder-move-messages (src-folder msgs dst-folder
1181 (let* ((messages msgs
)
1184 (if (eq dst-folder
'null
)
1185 (setq succeeds messages
)
1186 (unless (elmo-folder-writable-p dst-folder
)
1187 (error "move: %d is not writable"
1188 (elmo-folder-name-internal dst-folder
)))
1190 ;; src is already opened.
1191 (elmo-folder-open-internal dst-folder
)
1192 (unless (setq succeeds
(elmo-folder-append-messages dst-folder
1196 (error "move: append message to %s failed"
1197 (elmo-folder-name-internal dst-folder
)))
1198 (elmo-folder-close dst-folder
)))
1199 (if (and (not no-delete
) succeeds
)
1201 (if (elmo-folder-delete-messages src-folder succeeds
)
1203 (elmo-global-flag-detach-messages
1204 src-folder succeeds
(eq dst-folder
'null
))
1206 (message "move: delete messages from %s failed."
1207 (elmo-folder-name-internal src-folder
))
1212 ;; (message "Copying messages...done")
1215 (message "No message was moved.")
1216 (message "Moving messages failed.")
1220 (defun elmo-folder-msgdb-path (folder)
1221 "Return the msgdb path for FOLDER."
1222 (or (elmo-folder-path-internal folder
)
1223 (elmo-folder-set-path-internal
1225 (if (null elmo-msgdb-path-encode-threshold
)
1226 (elmo-folder-expand-msgdb-path folder
)
1227 (let* ((path (directory-file-name
1228 (elmo-folder-expand-msgdb-path folder
)))
1229 (dirname (file-name-nondirectory path
)))
1230 (if (<= (length dirname
) elmo-msgdb-path-encode-threshold
)
1233 (setq dirname
(md5 dirname
))
1234 (when (> (length dirname
) elmo-msgdb-path-encode-threshold
)
1235 (error "Cannot shrink msgdb path for `%s'"
1236 (elmo-folder-name-internal folder
)))
1237 (expand-file-name dirname
(file-name-directory path
))))))))
1239 (luna-define-generic elmo-message-cached-p
(folder number
)
1240 "Return non-nil if the message is cached.")
1242 (luna-define-method elmo-message-cached-p
((folder elmo-folder
) number
)
1243 (elmo-message-flagged-p folder number
'cached
))
1245 (luna-define-generic elmo-message-killed-p
(folder number
)
1246 "Return non-nil if the message is killed.")
1248 (luna-define-method elmo-message-killed-p
((folder elmo-folder
) number
)
1249 (let ((killed-list (elmo-folder-killed-list-internal folder
)))
1251 (elmo-number-set-member number killed-list
))))
1253 (defun elmo-message-accessible-p (folder number
)
1254 "Get accessibility of the message.
1255 Return non-nil when message is accessible."
1256 (or (elmo-folder-plugged-p folder
)
1257 (elmo-folder-local-p folder
)
1258 (< number
0) ; in dop spool
1259 (elmo-message-cached-p folder number
)))
1261 (luna-define-generic elmo-message-set-cached
(folder number cached
)
1262 "Set cache status of the message in the msgdb.
1263 FOLDER is the ELMO folder structure.
1264 NUMBER is a number of the message.
1265 If CACHED is t, message is set as cached.")
1267 (luna-define-method elmo-message-set-cached
((folder elmo-folder
)
1270 (elmo-msgdb-set-flag (elmo-folder-msgdb folder
) number
'cached
)
1271 (elmo-msgdb-unset-flag (elmo-folder-msgdb folder
) number
'cached
))
1272 (elmo-emit-signal 'status-changed folder
(list number
)))
1274 (defun elmo-message-copy-entity (entity)
1275 (elmo-msgdb-copy-message-entity (elmo-message-entity-handler entity
)
1278 (luna-define-generic elmo-message-number
(folder message-id
)
1279 "Get message number from MSGDB which corresponds to MESSAGE-ID.")
1281 (luna-define-method elmo-message-number
((folder elmo-folder
) message-id
)
1282 (elmo-msgdb-message-number (elmo-folder-msgdb folder
) message-id
))
1284 (luna-define-generic elmo-message-entity
(folder key
)
1285 "Return the message-entity structure which matches to the KEY.
1286 KEY is a number or a string.
1287 A number is for message number in the FOLDER.
1288 A string is for message-id of the message.")
1290 (luna-define-method elmo-message-entity
((folder elmo-folder
) key
)
1291 (elmo-msgdb-message-entity (elmo-folder-msgdb folder
) key
))
1293 (luna-define-generic elmo-message-entity-parent
(folder entity
)
1294 "Return the parent message-entity structure in the FOLDER.
1295 ENTITY is the message-entity to get the parent.")
1297 (luna-define-method elmo-message-entity-parent
((folder elmo-folder
) entity
)
1298 (elmo-msgdb-get-parent-entity entity
(elmo-folder-msgdb folder
)))
1300 (put 'elmo-folder-do-each-message-entity
'lisp-indent-function
'1)
1301 (def-edebug-spec elmo-folder-do-each-message-entity
1302 ((symbolp form
&rest form
) &rest form
))
1304 (defsubst elmo-folder-list-message-entities
(folder)
1305 ;; List all message entities in the FOLDER.
1307 (lambda (number) (elmo-message-entity folder number
))
1308 (elmo-folder-list-messages folder nil t
))) ; XXX killed-list is not used.
1310 (defmacro elmo-folder-do-each-message-entity
(spec &rest form
)
1311 "Iterator for message entity in the folder.
1312 \(elmo-folder-do-each-message-entity \(entity folder\)
1313 ... do the process using entity...
1315 `(dolist (,(car spec
) (elmo-folder-list-message-entities ,(car (cdr spec
))))
1318 (luna-define-generic elmo-folder-count-flags
(folder)
1319 "Count flagged message number in the msgdb of the FOLDER.
1320 Return alist of flag and numbers.
1324 \(answered . 3\)\)")
1326 (luna-define-method elmo-folder-count-flags
((folder elmo-folder
))
1327 (elmo-msgdb-flag-count (elmo-folder-msgdb folder
)))
1329 (defun elmo-message-set-flag (folder number flag
&optional is-local
)
1331 FOLDER is a ELMO folder structure.
1332 NUMBER is a message number to set flag.
1334 FLAG is a symbol which is one of the following:
1335 `unread' (set the message as unread)
1336 `answered' (set the message as answered)
1337 `important' (set the message as important)
1339 `read' (remove new and unread flags)
1340 If optional IS-LOCAL is non-nil, update only local (not server) status."
1341 ;; XXX Transitional implementation.
1342 (elmo-folder-set-flag folder
(list number
) flag is-local
))
1344 (defun elmo-message-unset-flag (folder number flag
&optional is-local
)
1345 "Unset message flag.
1346 FOLDER is a ELMO folder structure.
1347 NUMBER is a message number to set flag.
1349 FLAG is a symbol which is one of the following:
1350 `unread' (remove unread and new flag)
1351 `answered' (remove answered flag)
1352 `important' (remove important flag)
1354 `read' (set unread flag)
1355 If optional IS-LOCAL is non-nil, update only local (not server) status."
1356 ;; XXX Transitional implementation.
1357 (elmo-folder-unset-flag folder
(list number
) flag is-local
))
1359 (luna-define-generic elmo-message-field
(folder number field
&optional type
)
1360 "Get message field value in the msgdb.
1361 FOLDER is the ELMO folder structure.
1362 NUMBER is a number of the message.
1363 FIELD is a symbol of the field.
1364 If optional argument TYPE is specified, return converted value.")
1366 (luna-define-method elmo-message-field
((folder elmo-folder
)
1367 number field
&optional type
)
1368 (elmo-msgdb-message-field (elmo-folder-msgdb folder
) number field type
))
1370 (luna-define-generic elmo-message-set-field
(folder number field value
)
1371 "Set message field value in the msgdb.
1372 FOLDER is the ELMO folder structure.
1373 NUMBER is a number of the message.
1374 FIELD is a symbol of the field.
1375 VALUE is a value to set.")
1377 (luna-define-method elmo-message-set-field
((folder elmo-folder
) number
1379 (elmo-message-entity-set-field (elmo-message-entity folder number
)
1382 (luna-define-method elmo-message-use-cache-p
((folder elmo-folder
) number
)
1383 nil
) ; default is not use cache.
1385 (luna-define-method elmo-message-folder
((folder elmo-folder
) number
)
1386 folder
) ; default is folder
1388 (luna-define-method elmo-folder-set-flag
((folder elmo-folder
)
1392 (when (elmo-folder-msgdb-internal folder
)
1393 (dolist (number numbers
)
1394 (let ((old-flags (elmo-message-flags folder number
)))
1395 (when (elmo-global-flag-p flag
)
1396 (let ((message-id (elmo-message-field folder number
'message-id
)))
1397 (elmo-global-flag-set flag folder number message-id
)))
1398 (elmo-msgdb-set-flag (elmo-folder-msgdb folder
) number flag
)
1399 (elmo-emit-signal 'flag-changing
1403 (elmo-message-flags folder number
))))
1404 (elmo-emit-signal 'flag-changed folder numbers
)))
1406 (defun elmo-message-has-global-flag-p (folder number
)
1407 "Return non-nil when the message in the FOLDER with NUMBER has global flag."
1408 (let ((flags (elmo-message-flags folder number
))
1411 (when (and (elmo-global-flag-p (car flags
))
1412 (not (memq (car flags
) '(answered unread cached
))))
1415 (setq flags
(cdr flags
)))
1418 (defun elmo-message-set-global-flags (folder number flags
&optional local
)
1419 "Set global flags of the message in the FOLDER with NUMBER as FLAGS.
1420 If Optional LOCAL is non-nil, don't update server flag."
1421 (dolist (flag flags
)
1422 (unless (elmo-global-flag-p flag
)
1423 (error "Not a global flag")))
1424 (let ((old-flags (elmo-get-global-flags (elmo-message-flags folder number
))))
1425 (dolist (flag flags
)
1426 (unless (memq flag old-flags
)
1427 (elmo-message-set-flag folder number flag local
)))
1428 (dolist (flag old-flags
)
1429 (unless (memq flag flags
)
1430 (elmo-message-unset-flag folder number flag local
)))))
1432 (luna-define-method elmo-folder-unset-flag
((folder elmo-folder
)
1436 (when (elmo-folder-msgdb-internal folder
)
1437 (dolist (number numbers
)
1438 (let ((old-flags (elmo-message-flags folder number
)))
1439 (when (elmo-global-flag-p flag
)
1440 (elmo-global-flag-detach flag folder number
'always
))
1441 (elmo-msgdb-unset-flag (elmo-folder-msgdb folder
) number flag
)
1442 (elmo-emit-signal 'flag-changing
1446 (elmo-message-flags folder number
))))
1447 (elmo-emit-signal 'flag-changed folder numbers
)))
1449 (luna-define-method elmo-folder-process-crosspost
((folder elmo-folder
))
1453 ;;(luna-define-generic elmo-folder-append-message-entity (folder entity
1456 ;; "Append ENTITY to the folder.")
1458 (defun elmo-msgdb-merge (folder msgdb-merge
)
1459 "Return a list of messages which have duplicated message-id."
1460 (let (msgdb duplicates
)
1461 (setq msgdb
(or (elmo-folder-msgdb-internal folder
)
1462 (elmo-make-msgdb (elmo-folder-msgdb-path folder
))))
1463 (setq duplicates
(elmo-msgdb-append msgdb msgdb-merge
))
1464 (elmo-folder-set-msgdb-internal folder msgdb
)
1467 (defsubst elmo-folder-append-msgdb
(folder append-msgdb
)
1469 (let ((duplicates (elmo-msgdb-merge folder append-msgdb
)))
1470 (cond ((eq (elmo-folder-process-duplicates-internal folder
)
1472 ;; Let duplicates be a temporary killed message.
1473 (elmo-folder-kill-messages folder duplicates
)
1474 ;; Should be flag as read.
1475 (elmo-folder-unset-flag folder duplicates
'unread
))
1476 ((eq (elmo-folder-process-duplicates-internal folder
)
1478 ;; Flag as read duplicates.
1479 (elmo-folder-unset-flag folder duplicates
'unread
))
1482 (setq duplicates nil
)))
1483 (length duplicates
))
1486 (defun elmo-folder-confirm-appends (folder appends
)
1487 (let ((len (length appends
))
1489 (if (and elmo-folder-update-threshold
1490 (> len elmo-folder-update-threshold
)
1491 elmo-folder-update-confirm
)
1492 (if (y-or-n-p (format
1493 "Too many messages(%d) in %s. Update all? "
1494 len
(elmo-folder-name-internal folder
)))
1496 (setq in elmo-folder-update-threshold
)
1499 (setq in
(read-from-minibuffer "Update number: "
1501 in
(string-to-number in
))
1504 (if (y-or-n-p (format
1505 "%d messages are killed (not appeared). OK? "
1506 (max (- len in
) 0)))
1508 (nthcdr (max (- len in
) 0) appends
))
1509 (if (and elmo-folder-update-threshold
1510 (> len elmo-folder-update-threshold
)
1511 (not elmo-folder-update-confirm
))
1512 (nthcdr (max (- len elmo-folder-update-threshold
) 0) appends
)
1515 (luna-define-method elmo-message-fetch-bodystructure
((folder elmo-folder
)
1519 (defun elmo-message-fetch-string (folder number strategy
1524 (set-buffer-multibyte nil
)
1525 (when (elmo-message-fetch folder number strategy unread section
)
1528 (luna-define-method elmo-message-fetch
((folder elmo-folder
)
1534 (let ((cache-path (elmo-fetch-strategy-cache-path strategy
))
1536 (cond ((eq (elmo-fetch-strategy-use-cache strategy
) 'maybe
)
1538 ((elmo-fetch-strategy-use-cache strategy
)
1542 result err updated-server-flag
)
1543 (while (and method-priorities
1546 (case (car method-priorities
)
1548 (elmo-file-cache-load cache-path section
))
1550 (when (condition-case error
1551 (elmo-message-fetch-internal folder number
1555 (error (setq err error
) nil
))
1556 (setq updated-server-flag t
)
1557 (when (and (elmo-fetch-strategy-save-cache strategy
)
1559 (elmo-file-cache-save cache-path section
))
1561 method-priorities
(cdr method-priorities
)))
1563 (when (and (not unread
)
1564 (elmo-message-flagged-p folder number
'unread
))
1565 (elmo-message-unset-flag folder number
'unread updated-server-flag
))
1567 (signal (car err
) (cdr err
))))
1570 (defun elmo-folder-kill-messages-range (folder beg end
)
1571 (elmo-folder-set-killed-list-internal
1574 (elmo-folder-killed-list-internal folder
)
1575 (list (cons beg end
)))))
1577 (defun elmo-folder-kill-messages (folder numbers
)
1578 "Kill(hide) messages in the FOLDER with NUMBERS."
1579 (elmo-folder-set-killed-list-internal
1581 (elmo-number-set-append-list
1582 (elmo-folder-killed-list-internal folder
)
1584 (elmo-folder-unset-flag folder numbers
'all
'local-only
))
1586 (luna-define-generic elmo-folder-recover-messages
(folder numbers
)
1587 "Recover killed messages in the FOLDER with NUMBERS.")
1589 (luna-define-method elmo-folder-recover-messages
((folder elmo-folder
) numbers
)
1590 (let ((msgdb (elmo-folder-msgdb folder
)))
1591 (elmo-folder-set-killed-list-internal
1593 (elmo-number-set-delete-list
1594 (elmo-folder-killed-list-internal folder
)
1596 (dolist (number numbers
)
1597 (if (elmo-file-cache-exists-p
1598 (elmo-message-field folder number
'message-id
))
1599 (elmo-msgdb-set-flag msgdb number
'cached
)
1600 (elmo-msgdb-unset-flag msgdb number
'cached
)))
1601 (elmo-emit-signal 'status-changed folder numbers
)))
1603 (luna-define-method elmo-folder-clear
((folder elmo-folder
)
1604 &optional keep-killed
)
1606 (elmo-folder-set-killed-list-internal folder nil
))
1607 (if (eq elmo-msgdb-convert-type
'sync
)
1608 (elmo-folder-set-msgdb-internal
1610 (elmo-make-msgdb (elmo-folder-msgdb-path folder
)))
1611 (elmo-msgdb-clear (elmo-folder-msgdb folder
))))
1613 (luna-define-generic elmo-folder-synchronize
(folder
1619 "Synchronize the folder data to the newest status.
1620 FOLDER is the ELMO folder structure.
1622 If optional DISABLE-KILLED is non-nil, killed messages are also synchronized.
1623 If optional IGNORE-MSGDB is non-nil, current msgdb is thrown away except
1625 If NO-CHECK is non-nil, rechecking folder is skipped.
1626 If optional argument MASK is specified and is a list of message numbers,
1627 synchronize messages only which are contained the list.
1628 Return amount of cross-posted messages.
1629 If update process is interrupted, return nil.")
1631 (luna-define-method elmo-folder-synchronize
((folder elmo-folder
)
1637 (let ((old-msgdb (elmo-folder-msgdb folder
))
1638 (killed-list (elmo-folder-killed-list-internal folder
))
1639 (flag-table (elmo-flag-table-load (elmo-folder-msgdb-path folder
)))
1642 (elmo-msgdb-flag-table (elmo-folder-msgdb folder
) flag-table
)
1643 (elmo-folder-clear folder
(not disable-killed
)))
1644 (unless no-check
(elmo-folder-check folder
))
1646 (let ((killed-list (elmo-folder-killed-list-internal folder
))
1648 delete-list new-list new-msgdb crossed
)
1649 (message "Checking folder diff...")
1651 '(diff-new diff-del
)
1652 (elmo-list-diff (elmo-folder-list-messages folder
)
1653 (elmo-folder-list-messages folder nil
'in-msgdb
)))
1655 (setq diff-new
(sort diff-new
#'<))
1656 (unless disable-killed
1657 (setq diff-new
(elmo-living-messages diff-new killed-list
)))
1658 (when (and mask
(not ignore-msgdb
))
1659 (setq diff-new
(elmo-list-filter mask diff-new
))))
1660 (message "Checking folder diff...done")
1661 (setq new-list
(elmo-folder-confirm-appends folder diff-new
))
1662 ;; Append to killed list as (MIN-OF-DISAPPEARED . MAX-OF-DISAPPEARED)
1663 (when (not (eq (length diff-new
)
1665 (let* ((diff (elmo-list-diff diff-new new-list
))
1666 (disappeared (sort (car diff
) #'<)))
1668 (elmo-folder-kill-messages-range folder
1670 (elmo-last disappeared
)))))
1671 (setq delete-list diff-del
)
1672 (if (and (null diff-new
) (null diff-del
))
1674 (elmo-folder-update-number folder
)
1675 (elmo-folder-process-crosspost folder
)
1676 0) ; `0' means no updates.
1678 (elmo-folder-detach-messages folder delete-list
))
1680 (elmo-msgdb-out-of-date-messages (elmo-folder-msgdb folder
))
1681 (setq new-msgdb
(elmo-folder-msgdb-create
1682 folder new-list flag-table
))
1684 (if (elmo-folder-persistent-p folder
)
1685 (elmo-flag-table-save (elmo-folder-msgdb-path folder
)
1687 (setq before-append nil
)
1688 (setq crossed
(elmo-folder-append-msgdb folder new-msgdb
))
1689 ;; process crosspost.
1690 ;; Return a cons cell of (NUMBER-CROSSPOSTS . NEW-FLAG-ALIST).
1691 (elmo-folder-process-crosspost folder
))
1695 ;; Resume to the original status.
1696 (if before-append
(elmo-folder-set-msgdb-internal folder old-msgdb
))
1697 (elmo-folder-set-killed-list-internal folder killed-list
)
1700 (luna-define-generic elmo-folder-detach-messages
(folder numbers
)
1701 "Remove messages with NUMBERS from MSGDB.")
1703 (luna-define-method elmo-folder-detach-messages
((folder elmo-folder
)
1705 (when (elmo-msgdb-delete-messages (elmo-folder-msgdb folder
) numbers
)
1706 ;; Remove NUMBERS from killed message list.
1707 (elmo-folder-set-killed-list-internal
1709 (elmo-number-set-delete-list
1710 (elmo-folder-killed-list-internal folder
)
1714 (luna-define-generic elmo-folder-length
(folder)
1715 "Return number of messages in the FOLDER.")
1717 (luna-define-method elmo-folder-length
((folder elmo-folder
))
1718 (if (elmo-folder-msgdb-internal folder
)
1719 (elmo-msgdb-length (elmo-folder-msgdb folder
))
1722 (defun elmo-folder-msgdb-load (folder &optional silent
)
1724 (message "Loading msgdb for %s..." (elmo-folder-name-internal folder
)))
1725 (let ((msgdb (elmo-load-msgdb (elmo-folder-msgdb-path folder
)
1726 (elmo-folder-mime-charset-internal folder
))))
1727 (elmo-folder-set-info-max-by-numdb
1729 (elmo-msgdb-list-messages msgdb
))
1731 (message "Loading msgdb for %s...done"
1732 (elmo-folder-name-internal folder
)))
1735 (defun elmo-msgdb-delete-path (folder)
1736 (let ((path (elmo-folder-msgdb-path folder
)))
1737 (if (file-directory-p path
)
1738 (elmo-delete-directory path t
))))
1740 (defun elmo-msgdb-rename-path (old-folder new-folder
)
1741 (let* ((old (directory-file-name (elmo-folder-msgdb-path old-folder
)))
1742 (new (directory-file-name (elmo-folder-msgdb-path new-folder
)))
1743 (new-dir (directory-file-name (file-name-directory new
))))
1744 (if (not (file-directory-p old
))
1746 (if (file-exists-p new
)
1747 (error "Already exists directory: %s" new
)
1748 (if (not (file-exists-p new-dir
))
1749 (elmo-make-directory new-dir
))
1750 (rename-file old new
)))))
1752 (defun elmo-setup-subscribed-newsgroups (groups)
1753 "Setup subscribed newsgroups.
1754 GROUPS is a list of newsgroup name string.
1755 Return a hashtable for newsgroups."
1756 (let ((hashtb (or elmo-newsgroups-hashtb
1757 (setq elmo-newsgroups-hashtb
1758 (elmo-make-hash (length groups
))))))
1759 (dolist (group groups
)
1760 (or (elmo-get-hash-val group hashtb
)
1761 (elmo-set-hash-val group nil hashtb
)))
1762 (setq elmo-newsgroups-hashtb hashtb
)))
1764 (defvar elmo-crosspost-message-alist-modified nil
)
1765 (defun elmo-crosspost-message-alist-load ()
1766 "Load crosspost message alist."
1767 (setq elmo-crosspost-message-alist
(elmo-crosspost-alist-load))
1768 (setq elmo-crosspost-message-alist-modified nil
))
1770 (defun elmo-crosspost-message-alist-save ()
1771 "Save crosspost message alist."
1772 (when elmo-crosspost-message-alist-modified
1773 (let ((alist elmo-crosspost-message-alist
)
1779 (not (intern-soft x elmo-newsgroups-hashtb
)))
1780 (nth 1 (car alist
))))
1782 (setcar (cdar alist
) newsgroups
)
1783 (setq elmo-crosspost-message-alist
1784 (delete (car alist
) elmo-crosspost-message-alist
)))
1785 (setq alist
(cdr alist
)))
1786 (elmo-crosspost-alist-save elmo-crosspost-message-alist
)
1787 (setq elmo-crosspost-message-alist-modified nil
))))
1789 (defun elmo-folder-make-temporary-directory (folder)
1790 ;; Make a temporary directory for FOLDER.
1791 (let ((temp-dir (make-temp-name
1793 (file-name-as-directory (elmo-folder-msgdb-path folder
))
1795 (elmo-make-directory temp-dir
)
1798 ;; ELMO status structure.
1799 (defmacro elmo-message-status
(folder number
&optional flags killed
)
1800 "Make ELMO status structure from FOLDER and NUMBER.
1801 A value in this structure is cached at first access."
1802 `(vector ,folder
,number
,flags
,killed
))
1804 (defmacro elmo-message-status-folder
(status)
1807 (defmacro elmo-message-status-number
(status)
1810 (defmacro elmo-message-status-set-flags
(status flags
)
1811 `(aset ,status
2 (or ,flags
'(read))))
1813 (defsubst elmo-message-status-flags
(status)
1815 (elmo-message-status-set-flags
1817 (elmo-message-flags (elmo-message-status-folder status
)
1818 (elmo-message-status-number status
)))))
1820 (defsubst elmo-message-status-cached-p
(status)
1821 (memq 'cached
(elmo-message-status-flags status
)))
1823 (defmacro elmo-message-status-set-killed
(status killed
)
1824 `(aset ,status
3 (if ,killed
'killed
'living
)))
1826 (defsubst elmo-message-status-killed-p
(status)
1829 (elmo-message-status-set-killed
1831 (elmo-message-killed-p (elmo-message-status-folder status
)
1832 (elmo-message-status-number status
))))))
1836 "Initialize ELMO module."
1837 (elmo-crosspost-message-alist-load)
1838 (elmo-resque-obsolete-variables)
1839 (elmo-dop-queue-load)
1840 (run-hooks 'elmo-init-hook
))
1843 "Quit and cleanup ELMO."
1844 (elmo-crosspost-message-alist-save)
1845 (elmo-dop-queue-save)
1846 ;; Not implemented yet.
1847 (let ((types elmo-folder-type-alist
)
1852 (intern (format "elmo-%s-folder"
1853 (symbol-name (cdr (car types
)))))))
1854 ;; Call all folder's `elmo-quit' method.
1856 (dolist (func (luna-class-find-functions class
'elmo-quit
))
1857 (funcall func nil
)))
1858 (setq types
(cdr types
)))))
1860 (luna-define-method elmo-folder-rename-internal
((folder elmo-folder
)
1862 (error "Cannot rename %s folder"
1863 (symbol-name (elmo-folder-type-internal folder
))))
1866 (elmo-define-folder ?%
'imap4
)
1867 (elmo-define-folder ?-
'nntp
)
1868 (elmo-define-folder ?\
+ 'localdir
)
1869 (elmo-define-folder ?\
* 'multi
)
1870 (elmo-define-folder ?\
/ 'filter
)
1871 (elmo-define-folder ?\$
'archive
)
1872 (elmo-define-folder ?
& 'pop3
)
1873 (elmo-define-folder ?
= 'localnews
)
1874 (elmo-define-folder ?|
'pipe
)
1875 (elmo-define-folder ?.
'maildir
)
1876 (elmo-define-folder ?
' 'internal
)
1877 (elmo-define-folder ?\
[ 'search
)
1878 (elmo-define-folder ?
@ 'shimbun
)
1880 ;;; Obsolete variables.
1881 (elmo-define-obsolete-variable 'elmo-default-imap4-mailbox
1882 'elmo-imap4-default-mailbox
)
1883 (elmo-define-obsolete-variable 'elmo-default-imap4-server
1884 'elmo-imap4-default-server
)
1885 (elmo-define-obsolete-variable 'elmo-default-imap4-authenticate-type
1886 'elmo-imap4-default-authenticate-type
)
1887 (elmo-define-obsolete-variable 'elmo-default-imap4-user
1888 'elmo-imap4-default-user
)
1889 (elmo-define-obsolete-variable 'elmo-default-imap4-port
1890 'elmo-imap4-default-port
)
1891 (elmo-define-obsolete-variable 'elmo-default-imap4-stream-type
1892 'elmo-imap4-default-stream-type
)
1893 (elmo-define-obsolete-variable 'elmo-default-nntp-server
1894 'elmo-nntp-default-server
)
1895 (elmo-define-obsolete-variable 'elmo-default-nntp-user
1896 'elmo-nntp-default-user
)
1897 (elmo-define-obsolete-variable 'elmo-default-nntp-port
1898 'elmo-nntp-default-port
)
1899 (elmo-define-obsolete-variable 'elmo-default-nntp-stream-type
1900 'elmo-nntp-default-stream-type
)
1901 (elmo-define-obsolete-variable 'elmo-default-pop3-server
1902 'elmo-pop3-default-server
)
1903 (elmo-define-obsolete-variable 'elmo-default-pop3-user
1904 'elmo-pop3-default-user
)
1905 (elmo-define-obsolete-variable 'elmo-default-pop3-authenticate-type
1906 'elmo-pop3-default-authenticate-type
)
1907 (elmo-define-obsolete-variable 'elmo-default-pop3-port
1908 'elmo-pop3-default-port
)
1909 (elmo-define-obsolete-variable 'elmo-default-pop3-stream-type
1910 'elmo-pop3-default-stream-type
)
1911 (elmo-define-obsolete-variable 'elmo-cache-dirname
1912 'elmo-cache-directory
)
1913 (elmo-define-obsolete-variable 'elmo-msgdb-dir
1914 'elmo-msgdb-directory
)
1915 (elmo-define-obsolete-variable 'elmo-global-flag-list
1917 (elmo-define-obsolete-variable 'elmo-nmz-default-index-path
1918 'elmo-search-namazu-default-index-path
)
1919 (elmo-define-obsolete-variable 'elmo-nmz-index-alias-alist
1920 'elmo-search-namazu-index-alias-alist
)
1921 (elmo-define-obsolete-variable 'elmo-nmz-use-drive-letter
1922 'elmo-search-use-drive-letter
)
1925 ;; Obsolete functions.
1926 ;; 2001-12-11: *-dir -> *-directory
1927 (defalias 'elmo-folder-make-temp-dir
'elmo-folder-make-temporary-directory
)
1928 (make-obsolete 'elmo-folder-make-temp-dir
1929 'elmo-folder-make-temporary-directory
)
1932 (product-provide (provide 'elmo
) (require 'elmo-version
))
1934 ;;; elmo.el ends here