From: teranisi Date: Mon, 2 Dec 2002 14:13:27 +0000 (+0000) Subject: Synch `elmo-split' with main trunk. X-Git-Tag: wl-2_10_0pre3~1 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2c30c044e59c88e4fa1e67bde80780d6b3153590;p=elisp%2Fwanderlust.git Synch `elmo-split' with main trunk. --- diff --git a/doc/wl-ja.texi b/doc/wl-ja.texi index f23ac49..32b1bf8 100644 --- a/doc/wl-ja.texi +++ b/doc/wl-ja.texi @@ -6286,17 +6286,18 @@ pop3 × △ △ △ 規則の基本単位は @lisp -(@samp{条件} @samp{フォルダ} [@code{continue}]) +(@samp{CONDITION} @samp{ACTION} [@code{continue}]) @end lisp -という一組です。 -第一の要素 @samp{条件} は S 式です。書式についてはすぐ後で説明します。 -第二の要素 @samp{フォルダ} はメッセージの振り分け先のフォルダ名です。 -もし第三の要素 @code{continue} がシンボルとして与えられると、 -その条件が満たされたとしても振り分け規則の評価を続けます。 +の組で、@samp{CONDITION} が真の場合に @samp{ACTION} を実行します。 +第一の要素 @samp{CONDITION} には条件を S 式で記述します。書式については +すぐ後で説明します。第二の要素 @samp{ACTION} にはメッセージの振り分け先 +のフォルダ名、もしくはシンボルを指定します。 +第三の要素 @code{continue} をシンボルとして与えると、@samp{CONDITION} が +満たされた場合にも振り分け規則の評価を継続します。 -@samp{条件} の記法は以下のようになります。実際の書き方は上で挙げた例を -参考にして下さい。 +@samp{CONDITION} の記法は以下のようになります。実際の書き方は上で挙げた +例を参考にして下さい。 @enumerate @item @@ -6323,7 +6324,17 @@ pop3 × △ △ △ @end table @item -任意の数の引数を取る関数。 +1 つの整数 (@samp{SIZE}) を引数としてとる関数。 + +@table @code +@item @code{<} +メッセージのサイズが @samp{SIZE} より小さければ真。 +@item @code{>} +メッセージのサイズが @samp{SIZE} より大きければ真。 +@end table + +@item +任意数の引数を取る関数。 @table @code @item @code{or} @@ -6338,6 +6349,36 @@ pop3 × △ △ △ シンボルが指定されると、それを評価します。 @end enumerate +@samp{ACTION} の値として指定できるのは以下のいずれかです。 + +@enumerate +@item +フォルダ名 + +文字列が指定されるとそれを振り分け先のフォルダ名とみなして、そのフォルダ +へメッセージを追加します。 + +@item +@samp{delete} + +シンボル @samp{delete} が指定されると @code{elmo-split-folder} 内にある +メッセージの実体を削除します。 + +@item +@samp{noop} + +シンボル @samp{noop} が指定された場合、そのメッセージに対しては何もせず、 +そのままの状態に保ちます。 + +@item +関数 + +関数が指定された場合、それを実行します。 +@end enumerate + +全ての振り分け規則を通過したメッセージは、変数 +@code{elmo-split-default-action} で指定した @samp{ACTION} に沿って処理さ +れます。 @node Address Book, Customization, Split messages, Top @chapter アドレス帳 diff --git a/doc/wl.texi b/doc/wl.texi index 06536f4..988b7e9 100644 --- a/doc/wl.texi +++ b/doc/wl.texi @@ -6375,14 +6375,16 @@ example, please. The basic unit of the rule is a combination like @lisp -(@samp{CONDITION} @samp{FOLDER} [@code{continue}]) +(@samp{CONDITION} @samp{ACTION} [@code{continue}]) @end lisp -The 1st element @samp{CONDITION} is a balanced expression (sexp). Its -grammar will be explained below. The 2nd element @samp{FOLDER} is the -name of the folder to split messages into. When the 3rd element -@code{continue} is specified as symbol, evaluating rules is not stopped -even when the condition is satisfied. +If @samp{CONDITION} is true, @samp{ACTION} is performed. +The 1st element @samp{CONDITION} is a condition represented by a +balanced expression (sexp). Its grammar will be explained below. +The 2nd element @samp{ACTION} is the name of the folder to split +messages into, or a symbol. When the 3rd element @code{continue} is +specified as symbol, evaluating rules is not stopped even when the +condition is satisfied. The grammar for @samp{CONDITION} is as follows. See example above to learn how to write the condition practically. @@ -6411,6 +6413,16 @@ from matching @code{\(\)} patterns in the previous @samp{VALUE}. @end table @item +Functions which accept an integer argument (@samp{SIZE}). + +@table @code +@item @code{<} +True if the size of the message is less than @samp{SIZE}. +@item @code{>} +True if the size of the message is greater than @samp{SIZE}. +@end table + +@item Functions which accept any number of arguments. @table @code @@ -6426,6 +6438,35 @@ A symbol. When a symbol is specified, it is evaluated. @end enumerate +You can specify followings as 2nd @samp{ACTION}. + +@enumerate +@item +folder name + +If some string is specified, it will be regarded as the destination +folder, and the message will be appended to it. + +@item +@samp{delete} + +If the symbol @samp{delete} is specified, delete the substance of the +message in @code{elmo-split-folder} + +@item +@samp{noop} + +If the symbol @samp{noop} is specified, do nothing on the message and +keep it as it is. + +@item +function + +If some function is specified, execute it. +@end enumerate + +If the message passes all rules, it will be dealed along @samp{ACTION} +specified by @code{elmo-split-default-action}. @node Address Book, Customization, Split messages, Top @chapter Address Book diff --git a/elmo/ChangeLog b/elmo/ChangeLog index 0902de7..2381178 100644 --- a/elmo/ChangeLog +++ b/elmo/ChangeLog @@ -35,6 +35,11 @@ of elmo-string-matched-assoc to use match-data. (Thanks to Mito ) +2002-11-17 Yoichi NAKAYAMA + + * elmo-split.el (elmo-split->): New function. + (elmo-split-<): Ditto. + 2002-11-14 Yuuichi Teranishi * elmo-msgdb.el (elmo-msgdb-get-message-id-from-buffer): Added @@ -51,6 +56,13 @@ info part to the cur files when the new files already have it. (Adviced by Jared Rhine ) +2002-11-06 Yoichi NAKAYAMA + + * elmo-split.el (elmo-split-default-action): New variable. + (elmo-split-subr): Use it if all other conditions are passed. + Extend `fname' and rename it as `action'. (implemented + Teranishi-san's idea in [wl:10800]) + 2002-10-26 Yuuichi Teranishi * elmo-version.el (elmo-version): Up to 2.10.0. diff --git a/elmo/elmo-split.el b/elmo/elmo-split.el index 1038818..d86e2c0 100644 --- a/elmo/elmo-split.el +++ b/elmo/elmo-split.el @@ -43,7 +43,7 @@ (defcustom elmo-split-rule nil "Split rule for the command `elmo-split'. The format of this variable is a list of RULEs which has form like: -\(CONDITION FOLDER [continue]\) +\(CONDITION ACTION [continue]\) The 1st element CONDITION is a sexp which consists of following. @@ -71,7 +71,13 @@ FIELD-NAME is a symbol of the field name. When a symbol is specified, it is evaluated. -The 2nd element FOLDER is the name of the folder to split messages into. +The 2nd element ACTION is the name of the destination folder or some symbol. +If CONDITION is satisfied, the message is splitted according to this value. + +If ACTION is a string, it will be considered as the name of destination folder. +Symbol `delete' means that the substance of the message will be removed. On the +other hand, symbol `noop' is used to do nothing and keep the substance of the +message as it is. Or, if some function is specified, it will be called. When the 3rd element `continue' is specified as symbol, evaluating rules is not stopped even when the condition is satisfied. @@ -105,6 +111,14 @@ Example: (repeat (string :tag "folder name"))) :group 'elmo) +(defcustom elmo-split-default-action 'noop + "Default action for messages which pass all rules." + :type '(choice (const :tag "do not touch" noop) + (const :tag "delete" delete) + (string :tag "folder name") + (function :tag "function")) + :group 'elmo) + (defcustom elmo-split-log-coding-system 'x-ctext "A coding-system for writing log file." :type 'coding-system @@ -138,6 +152,12 @@ Example: (throw 'done nil))) t)) +(defun elmo-split-> (buffer size) + (> (buffer-size buffer) size)) + +(defun elmo-split-< (buffer size) + (< (buffer-size buffer) size)) + (defun elmo-split-address-equal (buffer field value) (with-current-buffer buffer (let ((addrs (mapcar @@ -252,7 +272,9 @@ If prefix argument ARG is specified, do a reharsal (no harm)." (let ((elmo-inhibit-display-retrieval-progress t) (count 0) (fcount 0) - msgs fname target-folder failure) + (default-rule `((t ,elmo-split-default-action))) + msgs action target-folder failure delete-substance + record-log log-string) (message "Splitting...") (elmo-folder-open-internal folder) (setq msgs (elmo-folder-list-messages folder)) @@ -268,52 +290,96 @@ If prefix argument ARG is specified, do a reharsal (no harm)." nil (current-buffer) 'unread)) (setq elmo-split-message-entity (mime-parse-buffer)) (catch 'terminate - (dolist (rule elmo-split-rule) + (dolist (rule (append elmo-split-rule default-rule)) (setq elmo-split-match-string-internal nil) (when (elmo-split-eval (current-buffer) (car rule)) - (if elmo-split-match-string-internal - (setq fname (elmo-expand-newtext - (nth 1 rule) - elmo-split-match-string-internal)) - (setq fname (nth 1 rule))) + (if (and (stringp (nth 1 rule)) + elmo-split-match-string-internal) + (setq action (elmo-expand-newtext + (nth 1 rule) + elmo-split-match-string-internal)) + (setq action (nth 1 rule))) + ;; 1. ACTION & DELETION (unless reharsal - (setq failure nil) - (condition-case nil - (progn - (setq target-folder (elmo-make-folder fname)) - (unless (elmo-folder-exists-p target-folder) - (when - (and - (elmo-folder-creatable-p - target-folder) - (y-or-n-p - (format - "Folder %s does not exist, Create it? " - fname))) - (elmo-folder-create target-folder))) - (elmo-folder-open-internal target-folder) - (elmo-folder-append-buffer target-folder 'unread) - (elmo-folder-close-internal target-folder)) - (error (setq failure t) - (incf fcount))) - (unless failure + (setq failure nil + delete-substance nil + record-log nil + log-string nil) + (cond + ((stringp action) + (condition-case nil + (progn + (setq target-folder (elmo-make-folder action)) + (unless (elmo-folder-exists-p target-folder) + (when + (and + (elmo-folder-creatable-p target-folder) + (y-or-n-p + (format + "Folder %s does not exist, Create it? " + action))) + (elmo-folder-create target-folder))) + (elmo-folder-open-internal target-folder) + (elmo-folder-append-buffer target-folder 'unread) + (elmo-folder-close-internal target-folder)) + (error (setq failure t) + (incf fcount))) + (setq record-log t + delete-substance + (not (or failure + (eq (nth 2 rule) 'continue)))) + (incf count)) + ((eq action 'delete) + (setq record-log t + delete-substance t)) + ((eq action 'noop) + ;; do nothing + ) + ((functionp action) + (funcall action)) + (t + (error "Wrong action specified in elmo-split-rule"))) + (when delete-substance (ignore-errors - (elmo-folder-delete-messages folder (list msg)))) - (incf count)) - (elmo-split-log - (concat "From " - (nth 1 (std11-extract-address-components - (or (std11-field-body "from") ""))) - " " (or (std11-field-body "date") "") "\n" - " Subject: " - (eword-decode-string (or (std11-field-body - "subject") "")) - "\n" - (if reharsal - " Test: " - " Folder: ") - fname "/0" "\n") - reharsal) + (elmo-folder-delete-messages folder (list msg))))) + ;; 2. RECORD LOG + (when (or record-log + reharsal) + (elmo-split-log + (concat "From " + (nth 1 (std11-extract-address-components + (or (std11-field-body "from") ""))) + " " (or (std11-field-body "date") "") "\n" + " Subject: " + (eword-decode-string (or (std11-field-body + "subject") "")) + "\n" + (if reharsal + (cond + ((stringp action) + (concat " Test: " action "\n")) + ((eq action 'delete) + " Test: /dev/null\n") + ((eq action 'noop) + " Test: do nothing\n") + ((function action) + (format " Test: function:%s\n" + (symbol-name action))) + (t + " ERROR: wrong action specified\n")) + (cond + (failure + (concat " FAILED: " action "\n")) + ((stringp action) + (concat " Folder: " action "\n")) + ((eq action 'delete) + " Deleted\n") + (log-string + log-string) + (t + (debug))))) + reharsal)) + ;; 3. CONTINUATION CHECK (unless (eq (nth 2 rule) 'continue) (throw 'terminate nil)))))) (elmo-progress-notify 'elmo-split)))