+(luna-define-method elmo-folder-exists-p-plugged ((folder elmo-nntp-folder))
+ (let ((session (elmo-nntp-get-session folder)))
+ (elmo-nntp-send-command
+ session
+ (format "group %s"
+ (elmo-nntp-folder-group-internal folder)))
+ (elmo-nntp-read-response session)))
+
+(defun elmo-nntp-retrieve-field (spec field from-msgs)
+ "Retrieve FIELD values from FROM-MSGS.
+Returns a list of cons cells like (NUMBER . VALUE)"
+ (let ((session (elmo-nntp-get-session spec)))
+ (if (elmo-nntp-xhdr-p session)
+ (progn
+ (elmo-nntp-select-group session (elmo-nntp-folder-group-internal spec))
+ (elmo-nntp-send-command session
+ (format "xhdr %s %s"
+ field
+ (if from-msgs
+ (format
+ "%d-%d"
+ (car from-msgs)
+ (nth
+ (max
+ (- (length from-msgs) 1) 0)
+ from-msgs))
+ "0-")))
+ (if (elmo-nntp-read-response session t)
+ (elmo-nntp-parse-xhdr-response
+ (elmo-nntp-read-contents session))
+ (elmo-nntp-set-xhdr session nil)
+ (error "NNTP XHDR command failed"))))))
+
+(defun elmo-nntp-search-primitive (spec condition &optional from-msgs)
+ (let ((search-key (elmo-filter-key condition)))
+ (cond
+ ((string= "last" search-key)
+ (let ((numbers (or from-msgs (elmo-folder-list-messages spec))))
+ (nthcdr (max (- (length numbers)
+ (string-to-int (elmo-filter-value condition)))
+ 0)
+ numbers)))
+ ((string= "first" search-key)
+ (let* ((numbers (or from-msgs (elmo-folder-list-messages spec)))
+ (rest (nthcdr (string-to-int (elmo-filter-value condition) )
+ numbers)))
+ (mapcar '(lambda (x) (delete x numbers)) rest)
+ numbers))
+ ((or (string= "since" search-key)
+ (string= "before" search-key))
+ (let* ((specified-date (elmo-date-make-sortable-string
+ (elmo-date-get-datevec (elmo-filter-value
+ condition))))
+ (since (string= "since" search-key))
+ field-date result)
+ (if (eq (elmo-filter-type condition) 'unmatch)
+ (setq since (not since)))
+ (setq result
+ (delq nil
+ (mapcar
+ (lambda (pair)
+ (setq field-date
+ (elmo-date-make-sortable-string
+ (timezone-fix-time
+ (cdr pair)
+ (current-time-zone) nil)))
+ (if (if since
+ (or (string= specified-date field-date)
+ (string< specified-date field-date))
+ (string< field-date
+ specified-date))
+ (car pair)))
+ (elmo-nntp-retrieve-field spec "date" from-msgs))))
+ (if from-msgs
+ (elmo-list-filter from-msgs result)
+ result)))
+ ((string= "body" search-key)
+ nil)
+ (t
+ (let ((val (elmo-filter-value condition))
+ (negative (eq (elmo-filter-type condition) 'unmatch))
+ (case-fold-search t)
+ result)
+ (setq result
+ (delq nil
+ (mapcar
+ (lambda (pair)
+ (if (string-match val
+ (eword-decode-string
+ (decode-mime-charset-string
+ (cdr pair) elmo-mime-charset)))
+ (unless negative (car pair))
+ (if negative (car pair))))
+ (elmo-nntp-retrieve-field spec search-key
+ from-msgs))))
+ (if from-msgs
+ (elmo-list-filter from-msgs result)
+ result))))))
+
+(defun elmo-nntp-search-internal (folder condition from-msgs)
+ (let (result)
+ (cond
+ ((vectorp condition)
+ (setq result (elmo-nntp-search-primitive
+ folder condition from-msgs)))
+ ((eq (car condition) 'and)
+ (setq result (elmo-nntp-search-internal folder
+ (nth 1 condition)
+ from-msgs)
+ result (elmo-list-filter result
+ (elmo-nntp-search-internal
+ folder (nth 2 condition)
+ from-msgs))))
+ ((eq (car condition) 'or)
+ (setq result (elmo-nntp-search-internal folder
+ (nth 1 condition)
+ from-msgs)
+ result (elmo-uniq-list
+ (nconc result
+ (elmo-nntp-search-internal folder
+ (nth 2 condition)
+ from-msgs)))
+ result (sort result '<))))))
+
+(luna-define-method elmo-folder-search :around ((folder elmo-nntp-folder)
+ condition &optional from-msgs)
+ (if (and (elmo-folder-plugged-p folder)
+ (not (string= "body" (elmo-filter-key condition))))
+ (elmo-nntp-search-internal folder condition from-msgs)
+ (luna-call-next-method)))
+
+(defun elmo-nntp-get-folders-info-prepare (folder session-keys)