[Mew-dist 10469] mew-sol.el 0.2
sen_ml at example.com
sen_ml at example.com
1999年 8月 26日 (木) 16:33:40 JST
mew-sol.el をちょっと update しました。
mew-summary-mark-unsol という関数が新しく加わりました。
# mania comment: コードの書き換えもしたので、mew-summary-mark-skel と
mew-summary-mark-region-skel を使用し、カスタム mew-summary-pick-*
関数を用意すると比較的に簡単に mew-summary-mark-* 系の関数を実装できると
思います。
1) mew-summary-mark-sol ->
2) mew-summary-mark-skel ->
3) mew-summary-mark-sol-region ->
4) mew-summary-mark-region-skel ->
5) mew-summary-pick-sol
("->" は「次の行の関数を呼び出す」というつもりです)
1, 3, 5 は自分で書きますが、1 と 3 は単純で、5 が「みそ」です。
-------------- next part --------------
;;; mew-sol.el --- mark messages w/ From: matching addresses in Addrbook
;;; Written by: Sen Nagata <sen at example.com>
;;; Important Note: most of the functions in here are based on code in
;;; mew-picks.el which was not written by me
;; Keywords: solicited, unsolicited, mew
;; Version: 0.2
;;; Commentary:
;;
;; installation:
;;
;; -put this file in an appropriate directory so emacs can find it
;;
;; -put:
;;
;; (add-hook 'mew-init-hook (lambda () (require 'mew-sol)))
;;
;; in .emacs (or wherever you place your mew settings)
;;
;; usage:
;;
;; -invoke mew
;;
;; -use the command `mew-summary-mark-sol' to mark solicited
;; messages for a given folder in summary mode. by 'solicited messages'
;; i mean messages w/ From: addresses that appear in Addrbook
;;
;; -use the command `mew-summary-mark-unsol' to mark unsolicited
;; messages for a given folder in summary mode. by 'unsolicited messages'
;; i mean messages w/ From: addresses that do not appear in Addrbook
;;
;; notes:
;;
;; -hacked mew-dups.el :-)
;;; History:
;;
;; 0.2:
;;
;; first version of `mew-summary-mark-unsol'
;; thanks to Hideyuki SHIRAI <shirai at example.com> for help
;;
;; abstracted out portions of `mew-summary-mark-sol-region' as
;; `mew-summary-mark-region-skel' and implemented a second version of
;; `mew-summary-mark-unsol-region'
;;
;; 0.1:
;;
;; initial implementation
;;; Code:
(defconst mew-sol-version "mew-sol.el 0.2")
(defconst mew-sol-address-alist nil
"Association list of addresses from which mail is solicited.")
;; based heavily on `mew-summary-search-mark-region'
;; there are basically two major changes:
;;
;; 1) no pattern
;; 2) can call functions other than `mew-summary-pick'
;;
(defun mew-summary-mark-region-skel (r1 r2 pick-function)
(if (equal (point-min) (point-max))
(message "No messages in this buffer.")
(let ((folder (buffer-name))
first last range)
(message "Picking messages in %s ..." folder)
(goto-char r1)
(if (eobp)
() ;; r1 <= r2, so if r1 = (point-max) then no message.
(setq first (mew-summary-message-number))
(goto-char r2)
(if (eobp)
(progn
(forward-line -1)
(setq r2 (point))))
(setq last (mew-summary-message-number))
;; this is the major change
(setq range
(apply pick-function (list folder (concat first "-" last)))))
(message "Picking messages in %s ... done" folder)
(if (null range)
(message "No message to be marked.")
(message "Marking messages ... ")
(goto-char r1)
(while (and range (< (point) r2))
(if (re-search-forward (format "^[ ]*%s[^0-9]" (car range)) nil t)
(if (not (mew-summary-marked-p))
(mew-summary-mark-as mew-mark-review)))
(setq range (cdr range)))
(beginning-of-line)
(set-buffer-modified-p nil)
(message "Marking messages ... done")))))
;; based heavily on `mew-summary-pick'
(defun mew-summary-pick-sol (folder &optional range)
(let (msgs address)
(setq range (or range "all"))
(save-excursion
(mew-set-buffer-tmp)
(mew-im-call-process nil mew-prog-imls
(format "--src=%s" folder)
"--form=%n %P"
range)
;; imls doesn't fail?
;; two sections removed that were in mew-summary-picks
(goto-char (point-min))
(while (not (eobp))
;; why are there trailing spaces?
;; cheating on regex for address probably...
(if (re-search-forward "^\\([0-9]+\\) \\([^ ]+\\) .*$")
(if (assoc (mew-match 2) mew-sol-address-alist)
(setq msgs (cons (mew-match 1) msgs))))
(forward-line))
(nreverse msgs))))
;; based heavily on `mew-summary-pick'
(defun mew-summary-pick-unsol (folder &optional range)
(let (msgs address)
(setq range (or range "all"))
(save-excursion
(mew-set-buffer-tmp)
(mew-im-call-process nil mew-prog-imls
(format "--src=%s" folder)
"--form=%n %P"
range)
;; imls doesn't fail?
;; two sections removed that were in mew-summary-picks
(goto-char (point-min))
(while (not (eobp))
;; why are there trailing spaces?
;; cheating on regex for address probably...
(if (re-search-forward "^\\([0-9]+\\) \\([^ ]+\\) .*$")
(if (not (assoc (mew-match 2) mew-sol-address-alist))
(setq msgs (cons (mew-match 1) msgs))))
(forward-line))
(nreverse msgs))))
(defun mew-summary-mark-sol-region (r1 r2)
(interactive "r")
(mew-summary-mark-region-skel r1 r2 'mew-summary-pick-sol))
(defun mew-summary-mark-unsol-region (r1 r2)
(interactive "r")
(mew-summary-mark-region-skel r1 r2 'mew-summary-pick-unsol))
;; based heavily on `mew-summary-search-mark'
(defun mew-summary-mark-skel (region-function &optional arg)
(mew-summary-only
(if arg
(apply region-function (list (region-beginning) (region-end)))
(apply region-function (list (point-min) (point-max))))))
(defun mew-summary-mark-sol (&optional arg)
"Pick solicited messages."
(interactive "P")
(mew-summary-mark-skel 'mew-summary-mark-sol-region arg))
(defun mew-summary-mark-unsol (&optional arg)
"Pick unsolicited messages."
(interactive "P")
(mew-summary-mark-skel 'mew-summary-mark-unsol-region arg))
(defun mew-sol-get-addresses-from-addrbook ()
"Build `mew-sol-address-alist' from `mew-addrbook-alist'. "
(let (result-alist)
(mapcar
(lambda (x)
;; we are looking for elements of mew-addrbook-alist which are
;; lists of email addresses
(if (listp (car (cdr x)))
(mapcar
;; create a cons cell using each email address and add the result
;; to our alist
(lambda (y)
(setq result-alist
(cons (cons y "")
result-alist)))
(car (cdr x)))))
mew-addrbook-alist)
result-alist))
(defun mew-sol-make-address-alist ()
(setq mew-sol-address-alist (mew-sol-get-addresses-from-addrbook)))
;; this needs to happen after Addrbook is read in...unfortunately,
;; that happens after mew-init-hook -- so my hack for the moment is to
;; use advice
(require 'advice)
(defadvice mew-status-update (after mew-sol-address-alist-calc activate)
(mew-sol-make-address-alist))
; why didn't using mew-addrbook-make-alist work? however, it looks like
; `mew-status-update' might be a good place to do things anyway
;(defadvice mew-addrbook-make-alist (after mew-sol-address-alist-calc activate)
(provide 'mew-sol)
;;; mew-sol.el ends here
; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ;; by Hideyuki SHIRAI <shirai at example.com>
; (defun mew-summary-mark-exchange (&optional arg)
; (interactive "P")
; (let ((mark-tmp ?#))
; (mew-summary-exchange-mark mew-mark-multi mark-tmp)
; (mew-summary-mark-swap)
; (mew-summary-mark-all)
; (if (not arg)
; (mew-summary-batch-unmark (list mew-mark-multi) nil))
; (mew-summary-exchange-mark mark-tmp mew-mark-multi))
; (message "Marks exchanged."))
; ;; quick hack version
; (defun mew-summary-mark-unsol (&optional arg)
; "Pick unsolicited messages."
; (interactive "P")
; (if arg
; (mew-summary-mark-sol arg)
; (mew-summary-mark-sol))
; (mew-summary-mark-swap)
; (mew-summary-mark-all)
; ;; from `mew-summary-undo-all'
; (let ((char ?@))
; (mew-summary-batch-unmark (list char) 'msg)))
; (defun mew-summary-mark-unsol (&optional arg)
; "Pick unsolicited messages."
; (interactive "P")
; (if arg
; (mew-summary-mark-sol arg)
; (mew-summary-mark-sol))
; (mew-summary-mark-exchange))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Mew-dist メーリングリストの案内