1 ;;; mew-sol.el --- mark messages w/ From: matching addresses in Addrbook
3 ;;; Written by: Sen Nagata <sen@eccosys.com>
4 ;;; Important Note: most of the functions in here are based on code in
5 ;;; mew-picks.el which was not written by me
7 ;; Keywords: solicited, unsolicited, mew
14 ;; -put this file in an appropriate directory so emacs can find it
18 ;; (add-hook 'mew-init-hook (lambda () (require 'mew-sol)))
20 ;; in .emacs (or wherever you place your mew settings)
26 ;; -use the command `mew-summary-mark-sol' to mark solicited
27 ;; messages for a given folder in summary mode. by 'solicited messages'
28 ;; i mean messages w/ From: addresses that appear in Addrbook
30 ;; -use the command `mew-summary-mark-unsol' to mark unsolicited
31 ;; messages for a given folder in summary mode. by 'unsolicited messages'
32 ;; i mean messages w/ From: addresses that do not appear in Addrbook
36 ;; -hacked mew-dups.el :-)
42 ;; patches from Hideyuki SHIRAI <shirai@rdmg.mgcs.mei.co.jp> for
43 ;; `mew-summary-pick-unsol' and the defadvice bit (`mew-status-update' ->
44 ;; `mew-addrbook-setup')
48 ;; first version of `mew-summary-mark-unsol'
49 ;; thanks to Hideyuki SHIRAI <shirai@rdmg.mgcs.mei.co.jp> for help
51 ;; abstracted out portions of `mew-summary-mark-sol-region' as
52 ;; `mew-summary-mark-region-skel' and implemented a second version of
53 ;; `mew-summary-mark-unsol-region'
57 ;; initial implementation
60 (defconst mew-sol-version "mew-sol.el 0.3")
62 (defconst mew-sol-address-alist nil
63 "Association list of addresses from which mail is solicited.")
65 ;; based heavily on `mew-summary-search-mark-region'
66 ;; there are basically two major changes:
69 ;; 2) can call functions other than `mew-summary-pick'
71 (defun mew-summary-mark-region-skel (r1 r2 pick-function)
72 (if (equal (point-min) (point-max))
73 (message "No messages in this buffer.")
74 (let ((folder (buffer-name))
76 (message "Picking messages in %s ..." folder)
79 () ;; r1 <= r2, so if r1 = (point-max) then no message.
80 (setq first (mew-summary-message-number))
86 (setq last (mew-summary-message-number))
87 ;; this is the major change
89 (apply pick-function (list folder (concat first "-" last)))))
90 (message "Picking messages in %s ... done" folder)
92 (message "No message to be marked.")
93 (message "Marking messages ... ")
95 (while (and range (< (point) r2))
96 (if (re-search-forward (format "^[ ]*%s[^0-9]" (car range)) nil t)
97 (if (not (mew-summary-marked-p))
98 (mew-summary-mark-as mew-mark-review)))
99 (setq range (cdr range)))
101 (set-buffer-modified-p nil)
102 (message "Marking messages ... done")))))
104 ;; based heavily on `mew-summary-pick'
105 (defun mew-summary-pick-sol (folder &optional range)
107 (setq range (or range "all"))
110 (mew-im-call-process nil mew-prog-imls
111 (format "--src=%s" folder)
115 ;; imls doesn't fail?
116 ;; two sections removed that were in mew-summary-picks
118 (goto-char (point-min))
120 ;; why are there trailing spaces?
121 ;; cheating on regex for address probably...
122 (if (re-search-forward "^\\([0-9]+\\) \\([^ ]+\\) .*$")
123 (if (assoc (mew-match 2) mew-sol-address-alist)
124 (setq msgs (cons (mew-match 1) msgs))))
128 ;; based heavily on `mew-summary-pick'
129 (defun mew-summary-pick-unsol (folder &optional range)
131 (setq range (or range "all"))
134 (mew-im-call-process nil mew-prog-imls
135 (format "--src=%s" folder)
139 ;; imls doesn't fail?
140 ;; two sections removed that were in mew-summary-picks
142 (goto-char (point-min))
144 ;; why are there trailing spaces?
145 ;; cheating on regex for address probably...
146 (if (re-search-forward "^\\([0-9]+\\) \\([^ ]+\\) .*$")
147 (if (and (not (assoc (mew-match 2) mew-sol-address-alist))
148 (not (string-match "^to:" (mew-match 2))))
149 (setq msgs (cons (mew-match 1) msgs))))
153 (defun mew-summary-mark-sol-region (r1 r2)
155 (mew-summary-mark-region-skel r1 r2 'mew-summary-pick-sol))
157 (defun mew-summary-mark-unsol-region (r1 r2)
159 (mew-summary-mark-region-skel r1 r2 'mew-summary-pick-unsol))
161 ;; based heavily on `mew-summary-search-mark'
162 (defun mew-summary-mark-skel (region-function &optional arg)
165 (apply region-function (list (region-beginning) (region-end)))
166 (apply region-function (list (point-min) (point-max))))))
168 (defun mew-summary-mark-sol (&optional arg)
169 "Pick solicited messages."
171 (mew-summary-mark-skel 'mew-summary-mark-sol-region arg))
173 (defun mew-summary-mark-unsol (&optional arg)
174 "Pick unsolicited messages."
176 (mew-summary-mark-skel 'mew-summary-mark-unsol-region arg))
178 (defun mew-sol-get-addresses-from-addrbook ()
179 "Build `mew-sol-address-alist' from `mew-addrbook-alist'. "
184 ;; we are looking for elements of mew-addrbook-alist which are
185 ;; lists of email addresses
186 (if (listp (car (cdr x)))
188 ;; create a cons cell using each email address and add the result
199 (defun mew-sol-make-address-alist ()
200 (setq mew-sol-address-alist (mew-sol-get-addresses-from-addrbook)))
202 ;; this needs to happen after Addrbook is read in...unfortunately,
203 ;; that happens after mew-init-hook -- so my hack for the moment is to
206 (defadvice mew-addrbook-setup (after mew-sol-address-alist-calc activate)
207 (mew-sol-make-address-alist))
209 ; why didn't using mew-addrbook-make-alist work? however, it looks like
210 ; `mew-status-update' might be a good place to do things anyway
211 ;(defadvice mew-addrbook-make-alist (after mew-sol-address-alist-calc activate)
216 ;;; mew-sol.el ends here
218 ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
220 ; ;; by Hideyuki SHIRAI <shirai@rdmg.mgcs.mei.co.jp>
221 ; (defun mew-summary-mark-exchange (&optional arg)
223 ; (let ((mark-tmp ?#))
224 ; (mew-summary-exchange-mark mew-mark-multi mark-tmp)
225 ; (mew-summary-mark-swap)
226 ; (mew-summary-mark-all)
228 ; (mew-summary-batch-unmark (list mew-mark-multi) nil))
229 ; (mew-summary-exchange-mark mark-tmp mew-mark-multi))
230 ; (message "Marks exchanged."))
232 ; ;; quick hack version
233 ; (defun mew-summary-mark-unsol (&optional arg)
234 ; "Pick unsolicited messages."
237 ; (mew-summary-mark-sol arg)
238 ; (mew-summary-mark-sol))
239 ; (mew-summary-mark-swap)
240 ; (mew-summary-mark-all)
241 ; ;; from `mew-summary-undo-all'
243 ; (mew-summary-batch-unmark (list char) 'msg)))
245 ; (defun mew-summary-mark-unsol (&optional arg)
246 ; "Pick unsolicited messages."
249 ; (mew-summary-mark-sol arg)
250 ; (mew-summary-mark-sol))
251 ; (mew-summary-mark-exchange))
253 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;