\e$B5,B'$N4pK\C10L$O\e(B
@lisp
-(@samp{\e$B>r7o\e(B} @samp{\e$B%U%)%k%@\e(B} [@code{continue}])
+(@samp{CONDITION} @samp{ACTION} [@code{continue}])
@end lisp
-\e$B$H$$$&0lAH$G$9!#\e(B
-\e$BBh0l$NMWAG\e(B @samp{\e$B>r7o\e(B} \e$B$O\e(B S \e$B<0$G$9!#=q<0$K$D$$$F$O$9$08e$G@bL@$7$^$9!#\e(B
-\e$BBhFs$NMWAG\e(B @samp{\e$B%U%)%k%@\e(B} \e$B$O%a%C%;!<%8$N?6$jJ,$1@h$N%U%)%k%@L>$G$9!#\e(B
-\e$B$b$7Bh;0$NMWAG\e(B @code{continue} \e$B$,%7%s%\%k$H$7$FM?$($i$l$k$H!"\e(B
-\e$B$=$N>r7o$,K~$?$5$l$?$H$7$F$b?6$jJ,$15,B'$NI>2A$rB3$1$^$9!#\e(B
+\e$B$NAH$G!"\e(B@samp{CONDITION} \e$B$,??$N>l9g$K\e(B @samp{ACTION} \e$B$r<B9T$7$^$9!#\e(B
+\e$BBh0l$NMWAG\e(B @samp{CONDITION} \e$B$K$O>r7o$r\e(B S \e$B<0$G5-=R$7$^$9!#=q<0$K$D$$$F$O\e(B
+\e$B$9$08e$G@bL@$7$^$9!#BhFs$NMWAG\e(B @samp{ACTION} \e$B$K$O%a%C%;!<%8$N?6$jJ,$1@h\e(B
+\e$B$N%U%)%k%@L>!"$b$7$/$O%7%s%\%k$r;XDj$7$^$9!#\e(B
+\e$BBh;0$NMWAG\e(B @code{continue} \e$B$r%7%s%\%k$H$7$FM?$($k$H!"\e(B@samp{CONDITION} \e$B$,\e(B
+\e$BK~$?$5$l$?>l9g$K$b?6$jJ,$15,B'$NI>2A$r7QB3$7$^$9!#\e(B
-@samp{\e$B>r7o\e(B} \e$B$N5-K!$O0J2<$N$h$&$K$J$j$^$9!#<B:]$N=q$-J}$O>e$G5s$2$?Nc$r\e(B
-\e$B;29M$K$7$F2<$5$$!#\e(B
+@samp{CONDITION} \e$B$N5-K!$O0J2<$N$h$&$K$J$j$^$9!#<B:]$N=q$-J}$O>e$G5s$2$?\e(B
+\e$BNc$r;29M$K$7$F2<$5$$!#\e(B
@enumerate
@item
@end table
@item
-\e$BG$0U$N?t$N0z?t$r<h$k4X?t!#\e(B
+1 \e$B$D$N@0?t\e(B (@samp{SIZE}) \e$B$r0z?t$H$7$F$H$k4X?t!#\e(B
+
+@table @code
+@item @code{<}
+\e$B%a%C%;!<%8$N%5%$%:$,\e(B @samp{SIZE} \e$B$h$j>.$5$1$l$P??!#\e(B
+@item @code{>}
+\e$B%a%C%;!<%8$N%5%$%:$,\e(B @samp{SIZE} \e$B$h$jBg$-$1$l$P??!#\e(B
+@end table
+
+@item
+\e$BG$0U?t$N0z?t$r<h$k4X?t!#\e(B
@table @code
@item @code{or}
\e$B%7%s%\%k$,;XDj$5$l$k$H!"$=$l$rI>2A$7$^$9!#\e(B
@end enumerate
+@samp{ACTION} \e$B$NCM$H$7$F;XDj$G$-$k$N$O0J2<$N$$$:$l$+$G$9!#\e(B
+
+@enumerate
+@item
+\e$B%U%)%k%@L>\e(B
+
+\e$BJ8;zNs$,;XDj$5$l$k$H$=$l$r?6$jJ,$1@h$N%U%)%k%@L>$H$_$J$7$F!"$=$N%U%)%k%@\e(B
+\e$B$X%a%C%;!<%8$rDI2C$7$^$9!#\e(B
+
+@item
+@samp{delete}
+
+\e$B%7%s%\%k\e(B @samp{delete} \e$B$,;XDj$5$l$k$H\e(B @code{elmo-split-folder} \e$BFb$K$"$k\e(B
+\e$B%a%C%;!<%8$N<BBN$r:o=|$7$^$9!#\e(B
+
+@item
+@samp{noop}
+
+\e$B%7%s%\%k\e(B @samp{noop} \e$B$,;XDj$5$l$?>l9g!"$=$N%a%C%;!<%8$KBP$7$F$O2?$b$;$:!"\e(B
+\e$B$=$N$^$^$N>uBV$KJ]$A$^$9!#\e(B
+
+@item
+\e$B4X?t\e(B
+
+\e$B4X?t$,;XDj$5$l$?>l9g!"$=$l$r<B9T$7$^$9!#\e(B
+@end enumerate
+
+\e$BA4$F$N?6$jJ,$15,B'$rDL2a$7$?%a%C%;!<%8$O!"JQ?t\e(B
+@code{elmo-split-default-action} \e$B$G;XDj$7$?\e(B @samp{ACTION} \e$B$K1h$C$F=hM}$5\e(B
+\e$B$l$^$9!#\e(B
@node Address Book, Customization, Split messages, Top
@chapter \e$B%"%I%l%9D"\e(B
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.
@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
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
of elmo-string-matched-assoc to use match-data.
(Thanks to Mito <mito@mxa.nes.nec.co.jp>)
+2002-11-17 Yoichi NAKAYAMA <yoichi@eken.phys.nagoya-u.ac.jp>
+
+ * elmo-split.el (elmo-split->): New function.
+ (elmo-split-<): Ditto.
+
2002-11-14 Yuuichi Teranishi <teranisi@gohome.org>
* elmo-msgdb.el (elmo-msgdb-get-message-id-from-buffer): Added
info part to the cur files when the new files already have it.
(Adviced by Jared Rhine <jared@wordzoo.com>)
+2002-11-06 Yoichi NAKAYAMA <yoichi@eken.phys.nagoya-u.ac.jp>
+
+ * 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 <teranisi@gohome.org>
* elmo-version.el (elmo-version): Up to 2.10.0.
(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.
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.
(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
(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
(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))
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)))