[mew-dist 27259] Re: Hyper Estraier

Tatsuya Kinoshita tats at example.com
2006年 8月 27日 (日) 20:04:55 JST


On August 2, 2006, [mew-dist 27177],
kazu (at iij.ad.jp) wrote:

> これを Mew でやる場合、大変な努力が必要です。
> 
> たとえば、HE では、
>   (from=alice OR to=alice) AND キーワード
> とは書けるけど、
>   (from=alice OR to=bob) AND キーワード
>   (from=alice AND キーワード1) OR (to=bob AND キーワード2)
> は書けません。
> 
> すなわち、Mew と HE では、許される構文が異なります。
> すると、現在の抽象化できている構文解析プログラムではなく、
> HE 専用の構文解析プログラムを書かないといけませんね。

Hyper Estraierでのヘッダー検索について、括弧やORなどの複雑な条件に
ついては当面あきらめるとして、AND検索だけはできるようにしてみました。
いかがでしょうか。

(from=alice | to=alice) & キーワード
とは書けませんが、
head=alice & キーワード
とは書けるようになります。
from=alice & to!=bob & キーワード
といった検索も可能です。

注意点:
* AND検索にしか対応していないので、
  from=alice | to=bob と書いても
  from=alice & to=bob として処理されます。
* `head'での検索対象は、ヘッダー全体ではなく、
  変数mew-pick-pattern-est-head-fieldsに設定されたフィールドのみとなります。

----
 Unlimited permission is granted to use, copy, distribute and/or modify
 this patch.  There is NO WARRANTY.
--- mew.orig/mew-pick.el
+++ mew/mew-pick.el
@@ -650,29 +650,28 @@
 (defun mew-pick-pattern-est-not   (sym) "ANDNOT")
 (defun mew-pick-pattern-est-key   (key) key)
 (defun mew-pick-pattern-est-kyvl  (kyvl)
-  (error "'%s' is not supported" kyvl))
+  (let ((op (nth 0 kyvl))
+	(ky (nth 1 kyvl))
+	(vl (nth 2 kyvl))
+	estky estop)
+    (if (string= ky "head")
+	(setq estky mew-pick-pattern-est-head-fields)
+      (setq estky ky))
+    (cond
+     ((string= op "=")
+      (setq estop "ISTRINC"))
+     ((string= op "==")
+      (setq estop "STRINC"))
+     ((string= op "!=")
+      (setq estop "!ISTRINC"))
+     ((string= op "!==")
+      (setq estop "!STRINC"))
+     (t
+      (error "'%s' is not supported" op)))
+    ;; "\f" is terminator of -attr for mew-search-est()
+    (format "-attr %s %s %s\f" estky estop vl)))
 
-;; To the -attr option.
-;;
-;; (defun mew-pick-pattern-est-kyvl  (kyvl)
-;;   (let ((op (nth 0 kyvl))
-;; 	(ky (nth 1 kyvl))
-;; 	(vl (nth 2 kyvl))
-;; 	ret)
-;;     (setq ret (cons vl ret))
-;;     (cond
-;;      ((string= op "=")
-;;       (setq ret (cons "STRINC" ret)))
-;;      (t
-;;       (error "'%s' is not supported" op)))
-;;     (cond
-;;      ((string= ky "subject")
-;;       (setq ret (cons "@title" ret)))
-;;      ((string= ky "from")
-;;       (setq ret (cons "@author" ret)))
-;;      (t
-;;       (error "'%s' is not supported" ky)))
-;;     (mapconcat 'identity ret " ")))
+(defvar mew-pick-pattern-est-head-fields "date,subject,from,to,cc,resent-from,resent-to,resent-cc,reply-to,mail-followup-to,x-mail-count,x-ml-count,x-ml-name,x-seqno,x-sequence,mailinglist-id,message-id,in-reply-to,references,newsgroups,followup-to")
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;
--- mew.orig/mew-search.el
+++ mew/mew-search.el
@@ -524,6 +524,7 @@
   (let* ((ent (mew-search-get-ent mew-search-method))
 	 (prog (mew-search-get-prog ent))
 	 (casket (expand-file-name mew-search-est-db mew-conf-path))
+	 attrlst
 	 maildir len attr)
     (mew-plet
      (mew-alet
@@ -532,7 +533,17 @@
       (setq path (substring path len))
       (setq path (file-name-as-directory path))
       (setq attr (format "@uri STRINC %s" (mew-q-encode-string path ?%)))
-      (call-process prog nil t nil "search" "-vu" "-max" "-1" "-ord" "@cdate NUMA" "-attr" attr casket pattern)))))
+      (if (string-match "^ *-attr " pattern)
+	  (setq pattern (concat "AND " pattern)))
+      (while (string-match " *\\(AND\\|ANDNOT\\|OR\\) +-attr \\([^\f]+\\)\f" pattern)
+	;; ANDNOT and OR are unsupported, regarded as AND
+	(setq attrlst (cons "-attr" (cons (match-string 2 pattern) attrlst)))
+	(setq pattern (replace-match "" nil t pattern)))
+      (while (string-match "^ *\\(AND\\|OR\\) +" pattern)
+	  (setq pattern (replace-match "" nil t pattern)))
+      (if (string-match "^ *ANDNOT " pattern)
+	  (setq pattern (concat "[UVSET] " pattern)))
+      (apply 'call-process (append (list prog nil t nil "search" "-vu" "-max" "-1" "-ord" "@cdate NUMA" "-attr" attr) attrlst (list casket pattern)))))))
 
 (defun mew-search-with-est (pattern folder)
   (let* ((path (mew-expand-folder folder))
----

-- 
木下達也



Mew-dist メーリングリストの案内