Pages

2006-09-30

mew-absfilter 1.37 へのパッチ その三

Mew でスパム・フィルター bsfilter を走らせる Elisp mew-absfilter.el のお話。本ブログで、mew-absfilter.el を最新の Mew (4.2.53 以降) に追随させる patch を公開していたのだけど、バグがあった。具体的には

(setq mew-use-suffix t)
(setq mew-suffix ".eml")

という設定に対して、mew-absfilter.el が bsfilter を上手く走らせられないというバグ。これは、保存したメールに拡張子 .eml を付けるという設定。拡張子を付けた時に、mew-absfilter.el が拡張子のついたメールを bsfilter に渡せなくなっていた。

この問題を修正するパッチを、問記事の末尾に載せる。対象は素の mew-absfilter.el 1.37。本ブログで提供している古い patch を当ててる方は、逆パッチして下さい。

mew-absfilter.el の設定、前パッチでの修正点 etc... は過去記事を参照されたし。

パッチ

--- mew-absfilter.el.org 2005-05-17 11:54:00.000000000 +0900
+++ mew-absfilter.el 2006-09-29 04:25:09.000000000 +0900
@@ -112,7 +112,7 @@
 
 ;; spam check
 (defun mew-absfilter-collect-message-region (begin end)
-  "Returns a list of message number in region."
+  "Returns a list of message number or number.suffix in region."
   (let (msgs)
     (save-excursion
       (save-restriction
@@ -121,7 +121,7 @@
  (while (not (eobp))
    (when (and (mew-summary-markable)
        (mew-sumsyn-match mew-regex-sumsyn-short))
-     (push (mew-sumsyn-message-number) msgs))
+     (push (mew-msg-get-filename (mew-sumsyn-message-number)) msgs))
    (forward-line))))
     (nreverse msgs)))
 
@@ -178,8 +178,8 @@
      (set-buffer vfolder)
      (save-excursion
        (dolist (msg msgs)
-  (if (or (re-search-forward (mew-regex-sumsyn-msg msg) nil t)
-   (re-search-backward (mew-regex-sumsyn-msg msg) nil t))
+  (if (or (re-search-forward (mew-absfilter-regex-sumsyn-msg msg) nil t)
+   (re-search-backward (mew-absfilter-regex-sumsyn-msg msg) nil t))
       (mew-absfilter-summary-spam-one 'no-msg)
     ;; if msg is not found, try to mark in physical folder
     (push msg spam)))))))
@@ -187,10 +187,16 @@
  (set-buffer case:folder)
  (save-excursion
    (dolist (msg spam)
-     (when (or (re-search-forward (mew-regex-sumsyn-msg msg) nil t)
-        (re-search-backward (mew-regex-sumsyn-msg msg) nil t))
+     (when (or (re-search-forward (mew-absfilter-regex-sumsyn-msg msg) nil t)
+        (re-search-backward (mew-absfilter-regex-sumsyn-msg msg) nil t))
        (mew-absfilter-summary-spam-one 'no-msg))))))))
 
+(defun mew-absfilter-regex-sumsyn-msg (msg)
+  (mew-regex-sumsyn-msg
+   (if mew-suffix
+       (substring msg 0 (- (length mew-suffix)))
+     msg)))
+
 (defun mew-absfilter-sentinel (process event)
   ;; exit status of "bsfilter --list-spam"
   ;;  0: some spams are found
@@ -224,7 +230,7 @@
    (when (mew-sumsyn-match mew-regex-sumsyn-short)
      (let* ((msg (mew-sumsyn-message-number))
      (case:folder (mew-sumsyn-folder-name))
-     (file (mew-expand-folder case:folder msg)))
+     (file (mew-absfilter-expand-msg case:folder msg)))
        (when (eq (mew-summary-get-mark) mew-absfilter-mark-spam)
   (mew-summary-undo))
        (unless mark-only
@@ -239,12 +245,20 @@
    (when (mew-sumsyn-match mew-regex-sumsyn-short)
      (let* ((msg (mew-sumsyn-message-number))
      (case:folder (mew-sumsyn-folder-name))
-     (file (mew-expand-folder case:folder msg)))
+     (file (mew-absfilter-expand-msg case:folder msg)))
        (mew-absfilter-summary-spam-one)
        (unless mark-only
   (mew-absfilter-add-spam (list file))
   (message "Learned as spam"))))))
 
+(defun mew-absfilter-expand-msg (folder msg)
+  "Expand message MSG in FOLDER.
+Function `mew-expand-new-msg' is defined after Mew 4.2.53.
+Use `mew-expand-folder' iff `mew-expand-new-msg' is not available."
+  (if (fboundp 'mew-expand-new-msg)
+      (mew-expand-new-msg folder msg)
+    (mew-expand-folder folder msg)))
+
 (defun mew-absfilter-mark-learn-clean (&optional mark-only)
   "Learn all messages marked with '*' as clean (not spam)."
   (interactive "P")

2 comments:

  1. おお、バッチリです!! スバラシイ。
    ありがとうございます。

    ReplyDelete
  2. よかったぁ。これで肩の荷が一つなくなりました。
    大変長らく待たせてしまい、本当にごめんなさい。

    また、不具合を見つけられましたら、遠慮なくおっしゃって下さい m(_ _)m。ではでは。

    ReplyDelete