| 1 | Description: contribution files to Mew |
| 2 | Forked to <https://github.com/tats/mew-contrib> to maintain patches. |
| 3 | Added mew-nmz.el from <http://www.meadowy.org/~shirai/elips/mew-nmz.el.gz>. |
| 4 | Added mew-absfilter.el from <https://github.com/tabmore/mew>. |
| 5 | Origin: upstream, https://github.com/kazu-yamamoto/mew-contrib |
| 6 | |
| 7 | diff -urN mew.orig/contrib/mew-absfilter.el mew/contrib/mew-absfilter.el |
| 8 | --- mew.orig/contrib/mew-absfilter.el 1970-01-01 09:00:00.000000000 +0900 |
| 9 | +++ mew/contrib/mew-absfilter.el 2011-06-20 01:46:19.000000000 +0900 |
| 10 | @@ -0,0 +1,476 @@ |
| 11 | +;;; mew-absfilter.el --- spam filter with bsfilter for Mew |
| 12 | + |
| 13 | +;; Author: SAITO Takuya <[email protected]> |
| 14 | +;; $Id$ |
| 15 | + |
| 16 | +;; You can use, copy, distribute, and/or modify this file for any purpose. |
| 17 | +;; There is NO WARRANTY. |
| 18 | + |
| 19 | +;;; Commentary: |
| 20 | + |
| 21 | +;; You can find bsfilter at http://bsfilter.org/ |
| 22 | + |
| 23 | +;; To enable spam check after retrieve, put below into your ~/.emacs: |
| 24 | +;; (mew-absfilter-mode 1) |
| 25 | + |
| 26 | +;; If you want to do spam checking after shimbun retrieve, |
| 27 | +;; do not use `mew-shimbun-retrieve-all' because it kills the shimbun buffer. |
| 28 | + |
| 29 | +;; When you find bsfilter marks the clean message as spam, |
| 30 | +;; use "bc" (mew-absfilter-learn-clean) instead of "u" (mew-summary-undo) |
| 31 | + |
| 32 | +;; With "bx" (mew-absfilter-summary-exec-spam), you can process spam mark |
| 33 | +;; even in nntp. |
| 34 | + |
| 35 | +;;; History: |
| 36 | +;; v1.38, 2006-06-11 |
| 37 | +;; Masayuki Ataka <[email protected]> Support Mew 5 |
| 38 | +;; v1.39, 2007-01-17 |
| 39 | +;; Masayuki Ataka <[email protected]> Support non-nil mew-use-suffix |
| 40 | +;; v1.40, 2007-01-28 |
| 41 | +;; SAITO Takuya <[email protected]> tiny fix |
| 42 | + |
| 43 | +;;; Code: |
| 44 | + |
| 45 | +(require 'mew) |
| 46 | + |
| 47 | +;;; spam mark |
| 48 | +(defvar mew-absfilter-mark-spam ?\;) |
| 49 | + |
| 50 | +(defvar mew-absfilter-spam-folder "+spam" |
| 51 | + "*Spam folder. Must be a local folder.") |
| 52 | + |
| 53 | +(defface mew-absfilter-face-mark-spam |
| 54 | + '((((class color) (type tty)) (:foreground "green")) |
| 55 | + (((class color) (background light)) (:foreground "DimGray")) |
| 56 | + (((class color) (background dark)) (:foreground "gray")) |
| 57 | + (t nil)) |
| 58 | + "*Face to highlight the spam mark" |
| 59 | + :group 'mew-highlight) |
| 60 | + |
| 61 | +(defun mew-absfilter-mark-kill-spam (src msg) |
| 62 | + "Return t if kill summary line." |
| 63 | + (not (string= src mew-absfilter-spam-folder))) |
| 64 | + |
| 65 | +(defun mew-absfilter-mark-exec-spam (src msgs) |
| 66 | + "Refile MSGs from the SRC folder to `mew-absfilter-spam-folder'." |
| 67 | + (unless (string= src mew-absfilter-spam-folder) |
| 68 | + (let ((mew-trash-folder mew-absfilter-spam-folder) |
| 69 | + (mew-trash-folder-list nil)) |
| 70 | + (mew-mark-exec-delete src msgs)))) |
| 71 | + |
| 72 | +(defun mew-absfilter-summary-spam-one (&optional no-msg) |
| 73 | + "Put the spam mark(default is ';') on this message." |
| 74 | + (mew-mark-put-mark mew-absfilter-mark-spam no-msg 'valid-only)) |
| 75 | + |
| 76 | +;; register spam mark |
| 77 | +(add-to-list 'mew-mark-afterstep-spec |
| 78 | + (list mew-absfilter-mark-spam 2 2 2 2 0 2 0)) |
| 79 | +(add-to-list 'mew-mark-spec |
| 80 | + (list mew-absfilter-mark-spam "spam" 2 nil |
| 81 | + 'mew-absfilter-mark-kill-spam nil |
| 82 | + 'mew-absfilter-mark-exec-spam nil)) |
| 83 | +(add-to-list 'mew-highlight-mark-keywords |
| 84 | + (cons mew-absfilter-mark-spam 'mew-absfilter-face-mark-spam)) |
| 85 | + |
| 86 | + |
| 87 | +(defvar mew-absfilter-program "bsfilter") |
| 88 | +(defvar mew-absfilter-arg-check '("--quiet" "--list-spam")) |
| 89 | +(defvar mew-absfilter-arg-clean '("--sub-spam" "--add-clean" "--update")) |
| 90 | +(defvar mew-absfilter-arg-spam '("--sub-clean" "--add-spam" "--update")) |
| 91 | + |
| 92 | +(defvar mew-absfilter-spam-folder-max-msgs 3000) |
| 93 | + |
| 94 | +;; like mew-prog-grep-max-msgs |
| 95 | +(defvar mew-absfilter-max-msgs 10000) |
| 96 | + |
| 97 | +(defvar mew-absfilter-map |
| 98 | + (let ((map (make-sparse-keymap))) |
| 99 | + (define-key map "c" 'mew-absfilter-learn-clean) |
| 100 | + (define-key map "s" 'mew-absfilter-learn-spam) |
| 101 | + (define-key map "C" 'mew-absfilter-mark-learn-clean) |
| 102 | + (define-key map "S" 'mew-absfilter-mark-learn-spam) |
| 103 | + (define-key map "b" 'mew-absfilter-check-spam) |
| 104 | + (define-key map "x" 'mew-absfilter-summary-exec-spam) |
| 105 | + (define-key map "D" 'mew-absfilter-clean-spam-folder) |
| 106 | + map)) |
| 107 | + |
| 108 | +(define-key mew-summary-mode-map "b" mew-absfilter-map) |
| 109 | +;; (define-key mew-summary-mode-map |
| 110 | +;; [remap mew-summary-learn-spam] 'mew-absfilter-learn-spam) |
| 111 | +;; (define-key mew-summary-mode-map |
| 112 | +;; [remap mew-summary-learn-ham] 'mew-absfilter-learn-clean) |
| 113 | + |
| 114 | + |
| 115 | +(defvar mew-absfilter-summary-buffer-process nil) |
| 116 | +(make-variable-buffer-local 'mew-absfilter-summary-buffer-process) |
| 117 | +;; Use buffer-local-variable in process-buffer. |
| 118 | +;; process-{put,get} is avairable only in Emacs-21.4 or above. |
| 119 | +(defvar mew-absfilter-process-folder nil) |
| 120 | + |
| 121 | +(defun mew-absfilter-add-clean (files) |
| 122 | + (apply 'call-process |
| 123 | + mew-absfilter-program nil 0 nil |
| 124 | + (append mew-absfilter-arg-clean files))) |
| 125 | + |
| 126 | +(defun mew-absfilter-add-spam (files) |
| 127 | + (apply 'call-process |
| 128 | + mew-absfilter-program nil 0 nil |
| 129 | + (append mew-absfilter-arg-spam files))) |
| 130 | + |
| 131 | +(defmacro mew-absfilter-expand-msg (folder msg) |
| 132 | + "Expand message MSG in FOLDER. |
| 133 | +Function `mew-expand-msg' is defined after Mew 4.2.53. |
| 134 | +Use `mew-expand-folder' iff `mew-expand-msg' is not available." |
| 135 | + (if (fboundp 'mew-expand-msg) |
| 136 | + `(mew-expand-msg ,folder ,msg) |
| 137 | + `(mew-expand-folder ,folder ,msg))) |
| 138 | + |
| 139 | +(defmacro mew-absfilter-sumsyn-filename () |
| 140 | + "Get filename" |
| 141 | + (if (fboundp 'mew-msg-get-filename) |
| 142 | + `(mew-msg-get-filename (mew-sumsyn-message-number)) |
| 143 | + `(mew-sumsyn-message-number))) |
| 144 | + |
| 145 | +(defun mew-absfilter-match-string-message-number () |
| 146 | + (if (and (boundp 'mew-use-suffix) |
| 147 | + (boundp 'mew-suffix)) |
| 148 | + (mew-match-string 1) |
| 149 | + (mew-match-string 0))) |
| 150 | + |
| 151 | +;; spam check |
| 152 | +(defun mew-absfilter-collect-message-region (begin end) |
| 153 | + "Returns a list of message file name in region." |
| 154 | + (when (> end begin) |
| 155 | + (let (msgs) |
| 156 | + (save-excursion |
| 157 | + (save-restriction |
| 158 | + (narrow-to-region begin end) |
| 159 | + (goto-char (point-min)) |
| 160 | + (while (not (eobp)) |
| 161 | + (when (and (mew-summary-markable) |
| 162 | + (mew-sumsyn-match mew-regex-sumsyn-short)) |
| 163 | + (push (mew-absfilter-sumsyn-filename) msgs)) |
| 164 | + (forward-line)))) |
| 165 | + (nreverse msgs)))) |
| 166 | + |
| 167 | +(defun mew-absfilter-collect-spam-message () |
| 168 | + (let (spam) |
| 169 | + (save-excursion |
| 170 | + (goto-char (point-min)) |
| 171 | + (while (not (eobp)) |
| 172 | + (when (looking-at mew-regex-message-files2) |
| 173 | + (push (mew-absfilter-match-string-message-number) spam)) |
| 174 | + (forward-line))) |
| 175 | + (nreverse spam))) |
| 176 | + |
| 177 | +(defun mew-absfilter-check-spam-region (case:folder begin end) |
| 178 | + (with-current-buffer case:folder |
| 179 | + (mew-pickable |
| 180 | + (let ((msgs (mew-absfilter-collect-message-region begin end)) |
| 181 | + nxt) |
| 182 | + (when msgs |
| 183 | + (message "Spam checking %s..." case:folder)) |
| 184 | + (while msgs |
| 185 | + (let ((buf (get-buffer-create |
| 186 | + (generate-new-buffer-name " *mew bsfilter*"))) |
| 187 | + process) |
| 188 | + (with-current-buffer buf |
| 189 | + (cd (mew-expand-folder case:folder)) |
| 190 | + (mew-erase-buffer) |
| 191 | + (set (make-local-variable 'mew-absfilter-process-folder) |
| 192 | + case:folder)) |
| 193 | + (setq nxt (nthcdr mew-absfilter-max-msgs msgs)) |
| 194 | + (when nxt |
| 195 | + (setcdr (nthcdr (1- mew-absfilter-max-msgs) msgs) nil)) |
| 196 | + (setq process (apply 'start-process "mew-absfilter" buf |
| 197 | + mew-absfilter-program |
| 198 | + (append mew-absfilter-arg-check msgs))) |
| 199 | + (set-process-sentinel process 'mew-absfilter-sentinel) |
| 200 | + (add-to-list 'mew-absfilter-summary-buffer-process process)) |
| 201 | + (setq msgs nxt))))) |
| 202 | + (when mew-absfilter-summary-buffer-process |
| 203 | + (force-mode-line-update))) |
| 204 | + |
| 205 | +(defun mew-absfilter-apply-spam-action (case:folder spam) |
| 206 | + (when (and spam |
| 207 | + (get-buffer case:folder)) |
| 208 | + (save-excursion |
| 209 | + (let ((vfolder (mew-folder-to-thread case:folder))) |
| 210 | + ;; mark in thread if exists |
| 211 | + (when (and (get-buffer vfolder) |
| 212 | + (mew-virtual-thread-p vfolder) |
| 213 | + (with-current-buffer case:folder |
| 214 | + (mew-thread-cache-valid-p vfolder))) |
| 215 | + (let ((msgs spam)) |
| 216 | + (setq spam nil) |
| 217 | + (set-buffer vfolder) |
| 218 | + (save-excursion |
| 219 | + (dolist (msg msgs) |
| 220 | + (if (or (re-search-forward (mew-regex-sumsyn-msg msg) nil t) |
| 221 | + (re-search-backward (mew-regex-sumsyn-msg msg) nil t)) |
| 222 | + (mew-absfilter-summary-spam-one 'no-msg) |
| 223 | + ;; if msg is not found, try to mark in physical folder |
| 224 | + (push msg spam))))))) |
| 225 | + (when spam |
| 226 | + (set-buffer case:folder) |
| 227 | + (save-excursion |
| 228 | + (dolist (msg spam) |
| 229 | + (when (or (re-search-forward (mew-regex-sumsyn-msg msg) nil t) |
| 230 | + (re-search-backward (mew-regex-sumsyn-msg msg) nil t)) |
| 231 | + (mew-absfilter-summary-spam-one 'no-msg)))))))) |
| 232 | + |
| 233 | +(defun mew-absfilter-sentinel (process event) |
| 234 | + ;; exit status of "bsfilter --list-spam" |
| 235 | + ;; 0: some spams are found |
| 236 | + ;; 1: spam not found |
| 237 | + (mew-filter |
| 238 | + (let ((status (process-exit-status process)) |
| 239 | + (case:folder mew-absfilter-process-folder) |
| 240 | + (spam (mew-absfilter-collect-spam-message))) |
| 241 | + (when (zerop status) |
| 242 | + (mew-absfilter-apply-spam-action case:folder spam)) |
| 243 | + (with-current-buffer case:folder |
| 244 | + (setq mew-absfilter-summary-buffer-process |
| 245 | + (delq process mew-absfilter-summary-buffer-process))) |
| 246 | + (message "Spam checking %s...%s" |
| 247 | + case:folder |
| 248 | + (cond |
| 249 | + ((= status 0) |
| 250 | + (format "done (%d spam)" (length spam))) |
| 251 | + ((= status 1) |
| 252 | + (concat "done (spam not found)")) |
| 253 | + (t |
| 254 | + (concat "failed. " event)))) |
| 255 | + (kill-buffer (current-buffer))))) |
| 256 | + |
| 257 | +;; commands |
| 258 | +(defun mew-absfilter-learn-clean (&optional mark-only) |
| 259 | + "Learn this message as clean (not spam)." |
| 260 | + (interactive "P") |
| 261 | + (mew-summary-msg-or-part |
| 262 | + (mew-summary-goto-message) |
| 263 | + (when (mew-sumsyn-match mew-regex-sumsyn-short) |
| 264 | + (let* ((msg (mew-sumsyn-message-number)) |
| 265 | + (case:folder (mew-sumsyn-folder-name)) |
| 266 | + (file (mew-absfilter-expand-msg case:folder msg))) |
| 267 | + (when (eq (mew-summary-get-mark) mew-absfilter-mark-spam) |
| 268 | + (mew-summary-undo)) |
| 269 | + (unless mark-only |
| 270 | + (mew-absfilter-add-clean (list file)) |
| 271 | + (message "Learned as clean")))))) |
| 272 | + |
| 273 | +(defun mew-absfilter-learn-spam (&optional mark-only) |
| 274 | + "Learn this message as spam." |
| 275 | + (interactive "P") |
| 276 | + (mew-summary-msg-or-part |
| 277 | + (mew-summary-goto-message) |
| 278 | + (when (mew-sumsyn-match mew-regex-sumsyn-short) |
| 279 | + (let* ((msg (mew-sumsyn-message-number)) |
| 280 | + (case:folder (mew-sumsyn-folder-name)) |
| 281 | + (file (mew-absfilter-expand-msg case:folder msg))) |
| 282 | + (mew-absfilter-summary-spam-one) |
| 283 | + (unless mark-only |
| 284 | + (mew-absfilter-add-spam (list file)) |
| 285 | + (message "Learned as spam")))))) |
| 286 | + |
| 287 | +(defun mew-absfilter-mark-learn-clean (&optional mark-only) |
| 288 | + "Learn all messages marked with '*' as clean (not spam)." |
| 289 | + (interactive "P") |
| 290 | + (mew-summary-multi-msgs |
| 291 | + (mew-mark-undo-mark mew-mark-review) |
| 292 | + (unless mark-only |
| 293 | + (message "Learning as clean...") |
| 294 | + (mew-absfilter-add-clean FILES) |
| 295 | + (message "Learning as clean...done")))) |
| 296 | + |
| 297 | +(defun mew-absfilter-mark-learn-spam (&optional mark-only) |
| 298 | + "Learn all messages marked with '*' as spam." |
| 299 | + (interactive "P") |
| 300 | + (mew-summary-multi-msgs |
| 301 | + (mew-mark-undo-mark mew-mark-review) |
| 302 | + (unless mark-only |
| 303 | + (message "Learning as spam...") |
| 304 | + (mew-absfilter-add-spam FILES) |
| 305 | + (message "Learning as spam...done")))) |
| 306 | + |
| 307 | +;; (defun mew-absfilter-thread-mark-learn-spam () |
| 308 | +;; "Put the ';' mark on all messages of the current sub-thread." |
| 309 | +;; (interactive) |
| 310 | +;; (mew-thread-mark mew-absfilter-mark-spam 'valid-only)) |
| 311 | + |
| 312 | +(defun mew-absfilter-summary-exec-spam () |
| 313 | + "Process messages marked with ';'." |
| 314 | + (interactive) |
| 315 | + (let* ((ent (assoc mew-absfilter-mark-spam mew-mark-spec)) |
| 316 | + (mew-mark-spec (list ent))) |
| 317 | + ;; call `mew-summary-exec-local' even for imap or nntp |
| 318 | + (cond |
| 319 | + ((mew-virtual-p) |
| 320 | + (mew-summary-go-back-summary |
| 321 | + (mew-substitute-for-summary "\\[mew-summary-exec]"))) |
| 322 | + (t |
| 323 | + ;; This message can not be changed because |
| 324 | + ;; (message "Refiling and deleting...done") is called in |
| 325 | + ;; `mew-summary-exec-local'. |
| 326 | + (message "Refiling and deleting...") |
| 327 | + (force-mode-line-update) |
| 328 | + (mew-summary-exec-local (point-min) (point-max)))))) |
| 329 | + |
| 330 | +(defun mew-absfilter-check-spam (&optional arg) |
| 331 | + "Check spam messages with bsfilter." |
| 332 | + (interactive "P") |
| 333 | + (let ((region (if (or arg (mew-mark-active-p)) |
| 334 | + (mew-summary-get-region) |
| 335 | + (cons (point-min) (point-max))))) |
| 336 | + (mew-absfilter-check-spam-region (mew-summary-folder-name 'ext) |
| 337 | + (car region) (cdr region)))) |
| 338 | + |
| 339 | +(defun mew-absfilter-clean-spam-folder (&optional unlink) |
| 340 | + "Remove old spam. |
| 341 | +Save `mew-absfilter-spam-folder-max-msgs' messages." |
| 342 | + (interactive "P") |
| 343 | + (mew-summary-visit-folder mew-absfilter-spam-folder) |
| 344 | + (mew-rendezvous mew-summary-buffer-process) |
| 345 | + (mew-decode-syntax-delete) |
| 346 | + (save-excursion |
| 347 | + (goto-char (point-max)) |
| 348 | + (forward-line (- mew-absfilter-spam-folder-max-msgs)) |
| 349 | + (let ((pos (point))) |
| 350 | + (while (zerop (forward-line -1)) |
| 351 | + (mew-summary-mark-as (if unlink mew-mark-unlink mew-mark-delete))) |
| 352 | + (mew-summary-exec-region (point) pos)))) |
| 353 | + |
| 354 | + |
| 355 | +;;; Check after retrieve |
| 356 | +(defvar mew-absfilter-check t |
| 357 | + "When to check with bsfilter. |
| 358 | +If t, do full check. Otherwise, the value should be a list whose element |
| 359 | +is one of `local', `pop', `imap', `nntp', or `shimbun'.") |
| 360 | + |
| 361 | +;; biff scan inc sync exec get list jobs |
| 362 | +(defvar mew-absfilter-check-directive-list '(("+" inc) |
| 363 | + ("$" . nil) |
| 364 | + ("%" inc scan) |
| 365 | + ("-" scan))) |
| 366 | + |
| 367 | +;; Suppress byte-compiler warning. |
| 368 | +;; bnm and directive is local variable which can be used in |
| 369 | +;; mew-{local,pop,imap,nntp}-sentinel. |
| 370 | +(defvar bnm) |
| 371 | +(defvar directive) |
| 372 | + |
| 373 | +(defun mew-absfilter-check-spam-after-retrieve () |
| 374 | + "Check spam messages with bsfilter after retrieve." |
| 375 | + (when (stringp bnm) |
| 376 | + (let* ((proto (mew-folder-prefix (mew-case:folder-folder bnm))) |
| 377 | + (check (cdr (assoc proto mew-absfilter-check-directive-list)))) |
| 378 | + (when (memq directive check) |
| 379 | + (with-current-buffer bnm |
| 380 | + (mew-absfilter-check-spam-region bnm |
| 381 | + (mew-sinfo-get-start-point) |
| 382 | + (point-max))))))) |
| 383 | + |
| 384 | +;; mew-local-sentinel does not let-bind `directive' |
| 385 | +;; and that information is lost by (mew-info-clean-up pnm) |
| 386 | +;; when mew-scan-sentinel-hook is called. |
| 387 | +(defadvice mew-local-sentinel (around absfilter-check disable) |
| 388 | + "Bind `directive' for spam checking. |
| 389 | +Advised in mew-absfilter.el" |
| 390 | + (let ((directive (mew-local-get-directive (process-name process)))) |
| 391 | + ad-do-it)) |
| 392 | + |
| 393 | +;; Check after `mew-shimbun-retrieve' |
| 394 | +(defun mew-absfilter-shimbun-retrieve-set-start-point () |
| 395 | + "Set retrieve start point." |
| 396 | + (mew-sinfo-set-start-point (point-max))) |
| 397 | + |
| 398 | +(defun mew-absfilter-check-spam-after-shimbun-retrieve () |
| 399 | + "Check spam messages with absfilter after shimbun-retrieve." |
| 400 | + (mew-absfilter-check-spam-region (mew-summary-folder-name 'ext) |
| 401 | + (mew-sinfo-get-start-point) (point-max))) |
| 402 | + |
| 403 | +;; modeline |
| 404 | +(defadvice mew-summary-setup-mode-line (after absfilter-process disable) |
| 405 | + "Display \"bsfilter\" in mode line. |
| 406 | +Advised in mew-absfilter.el" |
| 407 | + (add-to-list 'mode-line-process |
| 408 | + (list 'mew-absfilter-summary-buffer-process " bsfilter"))) |
| 409 | + |
| 410 | +;; inhibit pack, exec |
| 411 | +(defadvice mew-summary-exclusive-p (after absfilter-process disable) |
| 412 | + "Return nil when operation may break marking spam. |
| 413 | +`mew-absfilter-apply-spam-action' may put spam mark on the wrong message |
| 414 | +if message number is changed during bsfilter is running. |
| 415 | +The example of such operations are: |
| 416 | + - \"O\" (mew-summary-pack) |
| 417 | + - 'Refile' + \"i\" (mew-summary-retrieve) |
| 418 | + |
| 419 | +Advised in mew-absfilter.el" |
| 420 | + (when (and mew-absfilter-summary-buffer-process |
| 421 | + (memq this-command '(mew-summary-exec mew-summary-pack))) |
| 422 | + (unless no-msg |
| 423 | + (message "bsfilter is running. Try again later")) |
| 424 | + (setq ad-return-value nil))) |
| 425 | + |
| 426 | +(defun mew-absfilter-mode-activate (initialize) |
| 427 | + (let ((all '(local pop imap nntp shimbun)) |
| 428 | + ad-func hook-func) |
| 429 | + (when (eq initialize t) |
| 430 | + (setq initialize all)) |
| 431 | + (if initialize |
| 432 | + (setq ad-func 'ad-enable-advice |
| 433 | + hook-func 'add-hook) |
| 434 | + (setq initialize all |
| 435 | + ad-func 'ad-disable-advice |
| 436 | + hook-func 'remove-hook)) |
| 437 | + (when (memq 'local initialize) |
| 438 | + (funcall ad-func 'mew-local-sentinel 'around 'absfilter-check) |
| 439 | + (ad-activate 'mew-local-sentinel) |
| 440 | + (funcall hook-func |
| 441 | + 'mew-scan-sentinel-hook |
| 442 | + 'mew-absfilter-check-spam-after-retrieve)) |
| 443 | + (when (memq 'pop initialize) |
| 444 | + (funcall hook-func |
| 445 | + 'mew-pop-sentinel-non-biff-hook |
| 446 | + 'mew-absfilter-check-spam-after-retrieve)) |
| 447 | + (when (memq 'imap initialize) |
| 448 | + (funcall hook-func |
| 449 | + 'mew-imap-sentinel-non-biff-hook |
| 450 | + 'mew-absfilter-check-spam-after-retrieve)) |
| 451 | + (when (memq 'nntp initialize) |
| 452 | + (funcall hook-func |
| 453 | + 'mew-nntp-sentinel-hook |
| 454 | + 'mew-absfilter-check-spam-after-retrieve)) |
| 455 | + (when (memq 'shimbun initialize) |
| 456 | + (funcall hook-func |
| 457 | + 'mew-shimbun-before-retrieve-hook |
| 458 | + 'mew-absfilter-shimbun-retrieve-set-start-point) |
| 459 | + (funcall hook-func |
| 460 | + 'mew-shimbun-retrieve-hook |
| 461 | + 'mew-absfilter-check-spam-after-shimbun-retrieve)) |
| 462 | + (funcall ad-func 'mew-summary-setup-mode-line 'after 'absfilter-process) |
| 463 | + (funcall ad-func 'mew-summary-exclusive-p 'after 'absfilter-process) |
| 464 | + (ad-activate 'mew-summary-setup-mode-line) |
| 465 | + (ad-activate 'mew-summary-exclusive-p))) |
| 466 | + |
| 467 | +(defvar mew-absfilter-mode nil) |
| 468 | +;;;###autoload |
| 469 | +(defun mew-absfilter-mode (&optional arg) |
| 470 | + "Enable or disable bsfilter checking. |
| 471 | +See `mew-absfilter-check' when bsfilter is run." |
| 472 | + (interactive "P") |
| 473 | + (let ((mode (if arg |
| 474 | + (> (prefix-numeric-value arg) 0) |
| 475 | + (not mew-absfilter-mode)))) |
| 476 | + (when (and mode |
| 477 | + (not (mew-which-exec mew-absfilter-program))) |
| 478 | + (error "`%s' not found" mew-absfilter-program)) |
| 479 | + (setq mew-absfilter-mode mode) |
| 480 | + (mew-absfilter-mode-activate (if mode mew-absfilter-check)) |
| 481 | + (when (interactive-p) |
| 482 | + (message "bsfilter checking is %s" (if mode "enabled" "disabled"))))) |
| 483 | + |
| 484 | +(provide 'mew-absfilter) |
| 485 | + |
| 486 | +;;; mew-absfilter.el ends here |
| 487 | diff -urN mew.orig/contrib/mew-browse.el mew/contrib/mew-browse.el |
| 488 | --- mew.orig/contrib/mew-browse.el 1970-01-01 09:00:00.000000000 +0900 |
| 489 | +++ mew/contrib/mew-browse.el 2011-06-15 00:20:15.000000000 +0900 |
| 490 | @@ -0,0 +1,343 @@ |
| 491 | +;;; mew-browse.el --- Handling URI with browse-url.el |
| 492 | + |
| 493 | +;; Author: Hideyuki SHIRAI <[email protected]> |
| 494 | +;; Modify: Shuichi Kitaguchi <[email protected]> |
| 495 | +;; Created: May 19, 1999 |
| 496 | +;; Revised: Nov 08, 2004 |
| 497 | + |
| 498 | +;;; |
| 499 | +;;; ~/.emacs settings. |
| 500 | +;;; |
| 501 | +;;; ... anything browse-url setting ... |
| 502 | +;; (require 'mew-browse) |
| 503 | + |
| 504 | +;;; SHIFT + (Middle|Right)-Click = browse-url or mew-user-agent-compose |
| 505 | +;;; for Emacs |
| 506 | +;; (define-key global-map [S-mouse-2] 'browse-url-at-mouse) |
| 507 | +;;; for XEmacs |
| 508 | +;; (define-key global-map [(shift button2)] 'browse-url-at-mouse) |
| 509 | +;; |
| 510 | + |
| 511 | +;;; Appending URI to specified file. |
| 512 | +;; |
| 513 | +;; mew-browse-noask ... ask or not when browse |
| 514 | +;; mew-browse-append-file ... URL collection file name |
| 515 | +;; mew-browse-append-always-file ... always, append URL to file (for dial-up) |
| 516 | +;; mew-browse-append-always-mailto ... always, URL is mailto: (for emacs19.28) |
| 517 | +;; mew-browse-append-file-sort ... always, sort URL file |
| 518 | +;; |
| 519 | +;;; example: |
| 520 | +;; (setq mew-browse-noask nil) |
| 521 | +;; (setq mew-browse-append-file "~/.browse") |
| 522 | +;; (setq mew-browse-append-always-file nil) |
| 523 | +;; (setq mew-browse-append-always-mailto nil) |
| 524 | +;; (setq mew-browse-append-file-sort nil) |
| 525 | +;; |
| 526 | + |
| 527 | +;;; Use mew-url-mailto instead of url-mailto in W3, add followings in your ~/.emacs file. |
| 528 | +;; |
| 529 | +;; (cond |
| 530 | +;; ((locate-library "url-mail") |
| 531 | +;; (eval-after-load "url-mail" |
| 532 | +;; '(fset 'url-mailto (symbol-function 'mew-url-mailto)))) |
| 533 | +;; ((locate-library "url") |
| 534 | +;; (eval-after-load "url" |
| 535 | +;; '(fset 'url-mailto (symbol-function 'mew-url-mailto))))) |
| 536 | +;; |
| 537 | + |
| 538 | +;;; Use from emacs-w3m, add followings in your ~/.emacs file. |
| 539 | +;; (setq w3m-mailto-url-function 'mew-url-mailto) |
| 540 | +;; |
| 541 | + |
| 542 | +;;; Use from MS-Windows application, set followings in your registry. |
| 543 | +;; registry key: '\\HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes\\mailto\\shell\\open\\command' |
| 544 | +;; registry value: 'drive:\\path\\gnudoitw.exe \"(mew-url-mailto \"%%1\")\"'" |
| 545 | +;; |
| 546 | + |
| 547 | +;;; Use from Mozilla & Firefox with MozEx, set followings on Mailer form of MozEx. |
| 548 | +;; "/path/gnudoit (mew-url-mailto-mozex "%r")" |
| 549 | +;; or |
| 550 | +;; "/path/emacseval (mew-url-mailto-mozex "%r")" |
| 551 | +;; |
| 552 | +;; `emacseval' is a shell script like this, |
| 553 | +;; ----cut here---- |
| 554 | +;; #!/bin/sh |
| 555 | +;; /usr/local/bin/emacsclient --eval "`echo $*`" |
| 556 | +;; ----cut here----" |
| 557 | +;; |
| 558 | + |
| 559 | +(eval-when-compile (require 'mew)) |
| 560 | + |
| 561 | +(if (string-match "XEmacs" emacs-version) |
| 562 | + (defvar mew-browse-button [(button2)] "*Mouse button in message mode.") |
| 563 | + (defvar mew-browse-button [mouse-2] "*Mouse button in message mode.")) |
| 564 | + |
| 565 | +(defvar mew-ext-prog-url mew-prog-text/html-ext) |
| 566 | +(defvar mew-ext-prog-url-args nil) |
| 567 | + |
| 568 | +(setq browse-url-browser-function 'mew-browse-url) |
| 569 | + |
| 570 | +(defvar mew-browse-url-mailto-switch-func nil |
| 571 | + "*Which do you like, nil, 'switch-to-buffer-other-window or 'switch-to-buffer-other-frame ?") |
| 572 | + |
| 573 | +(setq browse-url-regexp "\\(\\b\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?[-a-zA-Z0-9_=?#$@~`%&*+|\\/.,]*[-a-zA-Z0-9_=#$@~`%&*+|\\/]+\\)\\|\\(\\([^-A-Za-z0-9!_.%]\\|^\\)[-A-Za-z0-9._!%]+@[A-Za-z0-9][-A-Za-z0-9._!]+[A-Za-z0-9]\\)") |
| 574 | + |
| 575 | +(defvar mew-browse-noask t "*Ask or not when browse.") |
| 576 | +(defvar mew-browse-append-file nil "*URL collection file.") |
| 577 | +(defvar mew-browse-append-always-file nil "*For dialup user.") |
| 578 | +(defvar mew-browse-append-always-mailto nil "*For emacs19.28.") |
| 579 | +(defvar mew-browse-append-file-sort nil "*Sort URL file.") |
| 580 | + |
| 581 | +(defun mew-browse-url (url &optional args) |
| 582 | + "Exec browse URL or mew-user-agent-compose with parsing RFC2368." |
| 583 | + (interactive |
| 584 | + (list (read-from-minibuffer "Mew URL: "))) |
| 585 | + (when (or (not (boundp 'mew-init-p)) (null mew-init-p)) |
| 586 | + (save-excursion |
| 587 | + (require 'mew) |
| 588 | + (mew-init))) |
| 589 | + (let* ((append-buffer (and mew-browse-append-file |
| 590 | + (string= buffer-file-name |
| 591 | + (expand-file-name mew-browse-append-file)))) |
| 592 | + (append-nil (or append-buffer (not mew-browse-append-file))) |
| 593 | + (append-all (and (not append-nil) mew-browse-append-always-file)) |
| 594 | + (append-ask (and (not append-nil) (not mew-browse-append-always-file))) |
| 595 | + (browse-all (or append-buffer mew-browse-noask)) |
| 596 | + (browse-ask (and (not append-buffer) (not mew-browse-noask)))) |
| 597 | + (string-match "\\([a-zA-Z0-9][-a-zA-Z0-9!_=?#$@~`%&*+|\\/.,:]+\\)" url) |
| 598 | + (setq url (substring url (match-beginning 0) (match-end 0))) |
| 599 | + (unless (string-match ":" url) ;; emacs19.28 only |
| 600 | + (if (and (not mew-browse-append-always-mailto) |
| 601 | + (not (y-or-n-p (format "mailto:%s(y) or ftp://%s(n)? " url url)))) |
| 602 | + (setq url (concat "ftp://" url)) |
| 603 | + (setq url (concat "mailto:" url)))) |
| 604 | + (cond |
| 605 | + ((and append-all browse-all) |
| 606 | + (mew-browse-url-append url) |
| 607 | + (mew-browse-url-start url)) |
| 608 | + ((and append-ask browse-all) |
| 609 | + (when (y-or-n-p (format "Append %s? " url)) |
| 610 | + (mew-browse-url-append url)) |
| 611 | + (mew-browse-url-start url)) |
| 612 | + ((and append-nil browse-all) |
| 613 | + (mew-browse-url-start url)) |
| 614 | + ((and append-all browse-ask) |
| 615 | + (mew-browse-url-append url) |
| 616 | + (when (y-or-n-p (format "Browse %s? " url)) |
| 617 | + (mew-browse-url-start url))) |
| 618 | + ((and append-nil browse-ask) |
| 619 | + (when (y-or-n-p (format "Browse %s? " url)) |
| 620 | + (mew-browse-url-start url))) |
| 621 | + (t ;; (and append-ask browse-ask) |
| 622 | + (if (y-or-n-p (format "Browse %s(y) or Append(n)? " url)) |
| 623 | + (mew-browse-url-start url) |
| 624 | + (mew-browse-url-append url))) |
| 625 | + ))) |
| 626 | + |
| 627 | +(defun mew-browse-url-append (url) |
| 628 | + (let ((file (expand-file-name mew-browse-append-file)) |
| 629 | + (beg)) |
| 630 | + (save-excursion |
| 631 | + (find-file file) |
| 632 | + (set-buffer (current-buffer)) |
| 633 | + (goto-char (point-min)) |
| 634 | + (while (search-forward url nil t) |
| 635 | + (progn |
| 636 | + (beginning-of-line) |
| 637 | + (setq beg (point)) |
| 638 | + (forward-line) |
| 639 | + (delete-region beg (point)))) |
| 640 | + (goto-char (point-max)) |
| 641 | + (insert url "\n") |
| 642 | + (when mew-browse-append-file-sort |
| 643 | + (sort-lines nil (point-min) (point-max))) |
| 644 | + (write-file file) |
| 645 | + (kill-buffer (current-buffer)) |
| 646 | + (message "Append %s to %s done" url file) |
| 647 | + ))) |
| 648 | + |
| 649 | +(defun mew-browse-url-start (url) |
| 650 | + (message "Browse %s" url) |
| 651 | + (cond |
| 652 | + ((string-match "^mailto:" url) |
| 653 | + (mew-url-mailto url)) |
| 654 | + ((and (symbolp mew-ext-prog-url) (fboundp mew-ext-prog-url)) |
| 655 | + (funcall mew-ext-prog-url url)) |
| 656 | + ((equal mew-ext-prog-url "w3") |
| 657 | + (require 'w3) |
| 658 | + (w3-fetch-other-frame url)) |
| 659 | + (t |
| 660 | + (let ((orig mew-ext-prog-url-args) |
| 661 | + args replace) |
| 662 | + (while orig |
| 663 | + (if (string-match "%s" (car orig)) |
| 664 | + (progn |
| 665 | + (setq args (cons (format (car orig) url) args)) |
| 666 | + (setq esqp t) |
| 667 | + (setq replace t)) |
| 668 | + (setq args (cons (car orig) args))) |
| 669 | + (setq orig (cdr orig))) |
| 670 | + (setq args (nreverse args)) |
| 671 | + (apply (function start-process) |
| 672 | + (format "*mew %s*" mew-ext-prog-url) |
| 673 | + nil mew-ext-prog-url |
| 674 | + (if replace |
| 675 | + args |
| 676 | + (append args (list url)))))))) |
| 677 | + |
| 678 | +(defun mew-url-mailto (url) |
| 679 | + "Execute mew-user-agent-compose with parsing RFC2368. |
| 680 | + |
| 681 | +If use from emacs-w3m, add followings in your ~/.emacs file. |
| 682 | + (setq w3m-mailto-url-function 'mew-url-mailto) |
| 683 | + |
| 684 | +If use from MS-Windows application, set followings in your registry. |
| 685 | + registry key: '\\HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes\\mailto\\shell\\open\\command' |
| 686 | + registry value: 'drive:\\path\\gnudoitw.exe \"(mew-url-mailto \"%%1\")\"'" |
| 687 | + (interactive |
| 688 | + (list (read-from-minibuffer "Mew mailto: "))) |
| 689 | + (when (or (not (boundp 'mew-init-p)) (null mew-init-p)) |
| 690 | + (save-excursion |
| 691 | + (require 'mew) |
| 692 | + (mew-init))) |
| 693 | + (let ((lst (mew-browse-url-mailto-analysis url))) |
| 694 | + (mew-user-agent-compose (nth 0 lst) ;; to |
| 695 | + (nth 1 lst) ;; subject |
| 696 | + (nth 2 lst) ;; other |
| 697 | + nil mew-browse-url-mailto-switch-func))) |
| 698 | + |
| 699 | +(defun mew-url-mailto-mozex (url) |
| 700 | + "Execute mew-user-agent-compose from Mozilla and Firefox with MozEx. |
| 701 | + |
| 702 | +If use this command, set followings on Mailer form of MozEx. |
| 703 | +\"/path/gnudoit (mew-url-mailto-mozex \"%r\")\" |
| 704 | +or |
| 705 | +\"/path/emacseval (mew-url-mailto-mozex \"%r\")\" |
| 706 | + |
| 707 | +`emacseval' is a shell script like this, |
| 708 | +----cut here---- |
| 709 | +#!/bin/sh |
| 710 | +/usr/local/bin/emacsclient --eval \"`echo $*`\" |
| 711 | +----cut here----" |
| 712 | + (interactive) |
| 713 | + (when (or (not (boundp 'mew-init-p)) (null mew-init-p)) |
| 714 | + (save-excursion |
| 715 | + (require 'mew) |
| 716 | + (mew-init))) |
| 717 | + (let ((lst (mew-browse-url-mailto-analysis url 'mozex))) |
| 718 | + (mew-user-agent-compose (nth 0 lst) ;; to |
| 719 | + (nth 1 lst) ;; subject |
| 720 | + (nth 2 lst) ;; other |
| 721 | + nil mew-browse-url-mailto-switch-func))) |
| 722 | + |
| 723 | +;; return '(to subject other)" |
| 724 | +(defun mew-browse-url-mailto-analysis (url &optional mozex) |
| 725 | + (let (to subject other) |
| 726 | + (while (string-match "[ \t]+" url) |
| 727 | + (setq url (concat (substring url 0 (match-beginning 0)) |
| 728 | + (substring url (match-end 0))))) |
| 729 | + (if (string-match "^mailto:" url) |
| 730 | + (setq url (mew-browse-url-mailto-decamp (substring url (match-end 0)))) |
| 731 | + (setq url (mew-browse-url-mailto-decamp url))) |
| 732 | + (when (string-match "^\\([^?]+\\)" url) |
| 733 | + (setq to (mew-browse-url-mailto-hex-to-string |
| 734 | + (substring url (match-beginning 1) (match-end 1)))) |
| 735 | + (setq url (substring url (match-end 0)))) |
| 736 | + (while (string-match "^[?&]\\([^=]+\\)=\\([^&]*\\)" url) |
| 737 | + (let ((hname (substring url (match-beginning 1) (match-end 1))) |
| 738 | + (hvalue (mew-browse-url-mailto-hex-to-string |
| 739 | + (substring url (match-beginning 2) (match-end 2))))) |
| 740 | + (setq url (substring url (match-end 0))) |
| 741 | + (when mozex |
| 742 | + (setq hname (mew-browse-url-mailto-hex-to-string hname)) |
| 743 | + (while (string-match "[ \t\n]+" hname) |
| 744 | + (setq hname (replace-match "" nil nil hname))) |
| 745 | + (when (string-match "[ \t\n]+$" hvalue) |
| 746 | + (setq hvalue (replace-match "" nil nil hvalue)))) |
| 747 | + (cond |
| 748 | + ((string-match "^to$" hname) |
| 749 | + (if to |
| 750 | + (setq to (concat to ", " hvalue)) |
| 751 | + (setq to hvalue))) |
| 752 | + ((string-match "^subject$" hname) |
| 753 | + (setq subject hvalue)) |
| 754 | + (t |
| 755 | + (setq other (cons (cons (capitalize hname) hvalue) other)))))) |
| 756 | + `(,to ,subject ,other))) |
| 757 | + |
| 758 | +(defun mew-browse-url-mailto-decamp (str) |
| 759 | + (save-match-data |
| 760 | + (while (string-match "&" str) |
| 761 | + (setq str (concat (substring str 0 (match-beginning 0)) |
| 762 | + "&" |
| 763 | + (substring str (match-end 0))))) |
| 764 | + str)) |
| 765 | + |
| 766 | +(defun mew-browse-url-mailto-hex-to-string (str) |
| 767 | + (save-match-data |
| 768 | + (with-temp-buffer |
| 769 | + (insert str) |
| 770 | + (goto-char (point-min)) |
| 771 | + (let ((doit t) char cs) |
| 772 | + (while (re-search-forward "%\\([0-9a-fA-F][0-9a-fA-F]\\)" nil t) |
| 773 | + (setq char (mew-browse-url-mailto-2hexs-to-int |
| 774 | + (buffer-substring (match-beginning 1) (match-end 1)))) |
| 775 | + (delete-region (match-beginning 0) (match-end 0)) |
| 776 | + (insert char)) |
| 777 | + (setq cs (mew-charset-to-cs |
| 778 | + (mew-charset-guess-region (point-min) (point-max)))) |
| 779 | + (when (or (not cs) |
| 780 | + (eq cs mew-cs-unknown)) |
| 781 | + (setq cs mew-cs-autoconv)) |
| 782 | + (when (and (eq cs 'utf-8) |
| 783 | + (not mew-internal-utf-8p) |
| 784 | + (not (featurep 'un-define))) |
| 785 | + (condition-case nil |
| 786 | + (require 'un-define) |
| 787 | + (file-error |
| 788 | + (setq doit nil) |
| 789 | + (delete-region (point-min) (point-max)) |
| 790 | + (insert "Install Mule-UCS for UTF-8.\n")))) |
| 791 | + (when doit |
| 792 | + (mew-set-buffer-multibyte nil) |
| 793 | + (decode-coding-region (point-min) (point-max) cs) |
| 794 | + (mew-set-buffer-multibyte t)) |
| 795 | + (buffer-string))))) |
| 796 | + |
| 797 | +(defun mew-browse-url-mailto-2hexs-to-int (hex) |
| 798 | + (+ (* 16 (mew-hexchar-to-int (aref hex 0))) |
| 799 | + (mew-hexchar-to-int (aref hex 1)))) |
| 800 | + |
| 801 | +(provide 'mew-browse) |
| 802 | + |
| 803 | +;;; Copyright Notice: |
| 804 | + |
| 805 | +;; Copyright (C) 1999-2004 Mew developing team. |
| 806 | +;; All rights reserved. |
| 807 | + |
| 808 | +;; Redistribution and use in source and binary forms, with or without |
| 809 | +;; modification, are permitted provided that the following conditions |
| 810 | +;; are met: |
| 811 | +;; |
| 812 | +;; 1. Redistributions of source code must retain the above copyright |
| 813 | +;; notice, this list of conditions and the following disclaimer. |
| 814 | +;; 2. Redistributions in binary form must reproduce the above copyright |
| 815 | +;; notice, this list of conditions and the following disclaimer in the |
| 816 | +;; documentation and/or other materials provided with the distribution. |
| 817 | +;; 3. Neither the name of the team nor the names of its contributors |
| 818 | +;; may be used to endorse or promote products derived from this software |
| 819 | +;; without specific prior written permission. |
| 820 | +;; |
| 821 | +;; THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS'' AND |
| 822 | +;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 823 | +;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 824 | +;; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TEAM OR CONTRIBUTORS BE |
| 825 | +;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 826 | +;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 827 | +;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 828 | +;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 829 | +;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 830 | +;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 831 | +;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 832 | + |
| 833 | +;;; mew-browse.el ends here |
| 834 | diff -urN mew.orig/contrib/mew-caesar.el mew/contrib/mew-caesar.el |
| 835 | --- mew.orig/contrib/mew-caesar.el 1970-01-01 09:00:00.000000000 +0900 |
| 836 | +++ mew/contrib/mew-caesar.el 2011-06-15 00:20:15.000000000 +0900 |
| 837 | @@ -0,0 +1,242 @@ |
| 838 | +;; -*- emacs-lisp -*- |
| 839 | +;; |
| 840 | +;; mew-caesar.el --- Caesar encrypt/decrypt assistant package for Mew. |
| 841 | +;; |
| 842 | +;; Author: Hideyuki SHIRAI <[email protected]> |
| 843 | +;; Created: <02/07/1998> |
| 844 | +;; |
| 845 | +;; To use mew-caesar.el, install (tm|SEMI) package or "nkf" |
| 846 | +;; , and put the following codes in your .emacs. |
| 847 | +;; |
| 848 | +;; (add-hook 'mew-init-hook |
| 849 | +;; (lambda () |
| 850 | +;; (require 'mew-caesar))) |
| 851 | +;; |
| 852 | + |
| 853 | +(eval-when-compile |
| 854 | + (require 'mew)) |
| 855 | + |
| 856 | +(defconst mew-caesar-version "mew-caesar.el 0.21") |
| 857 | + |
| 858 | +(defvar mew-caesar-ext-prog |
| 859 | + (let (extprog) |
| 860 | + (cond |
| 861 | + ((or (memq system-type '(OS/2 emx)) |
| 862 | + (eq system-type 'windows-nt)) |
| 863 | + (cond |
| 864 | + ((setq extprog (mew-which "nkf.exe" exec-path)) |
| 865 | + extprog) |
| 866 | + ((setq extprog (mew-which "nkf32.exe" exec-path)) |
| 867 | + extprog) |
| 868 | + (t nil))) |
| 869 | + (t (setq extprog (mew-which "nkf" exec-path)) |
| 870 | + extprog))) |
| 871 | + "mew-caesar external program. |
| 872 | + Usually, auto searched \"nkf\", \"nkf.exe\" or \"nkf32.exe\"." |
| 873 | + ) |
| 874 | + |
| 875 | +(defvar mew-caesar-ext-prog-arg '("-r")) |
| 876 | + |
| 877 | +(defvar mew-caesar-function |
| 878 | + (cond |
| 879 | + ((or (featurep 'mule-caesar) |
| 880 | + (locate-library "mule-caesar")) |
| 881 | + (require 'mule-caesar) |
| 882 | + 'semi) |
| 883 | + ((or (featurep 'tm-def) |
| 884 | + (locate-library "tm-def")) |
| 885 | + (require 'tm-def) |
| 886 | + 'tm) |
| 887 | + (mew-caesar-ext-prog |
| 888 | + 'ext) |
| 889 | + (t |
| 890 | + (message "mew-caesar: program is not found") |
| 891 | + nil)) |
| 892 | + "mew-caesar function select. |
| 893 | + Usually auto selected, which |
| 894 | + 'semi(mule-caesar), 'tm(tm:caesar-region) or 'ext(mew-caesar-ext-prog)." |
| 895 | + ) |
| 896 | + |
| 897 | +(defvar mew-caesar-prog-xrot '(mew-caesar-mime-text/x-rot () nil)) |
| 898 | +(defconst mew-caesar-ct-rot13 "Text/X-Rot13-47-48") |
| 899 | +(defconst mew-caesar-rot13-suffix ".rot") |
| 900 | + |
| 901 | +(define-key mew-summary-mode-map "\C-cr" 'mew-caesar-summary-insert-xrot) |
| 902 | +(define-key mew-draft-attach-map "R" 'mew-caesar-attach-find-new-xrot) |
| 903 | + |
| 904 | +(setq mew-mime-content-type |
| 905 | + (append |
| 906 | + '(("text/x-rot13-47-48" "\\.rot$" nil mew-caesar-prog-xrot mew-icon-text) |
| 907 | + ("text/x-rot13.*" "\\.rot$" nil mew-caesar-prog-xrot mew-icon-text)) |
| 908 | + mew-mime-content-type)) |
| 909 | + |
| 910 | +(defun mew-caesar-mime-text/x-rot (cache beg end &optional params execute) |
| 911 | + (if (> end beg) |
| 912 | + (save-excursion |
| 913 | + (set-buffer (mew-buffer-message)) |
| 914 | + (let ((buffer-read-only nil)) |
| 915 | + (insert " # # ###### ####### ####### # #####\n" |
| 916 | + " # # # # # # # ## # #\n" |
| 917 | + " # # # # # # # # # #\n" |
| 918 | + " # ##### ###### # # # # #####\n" |
| 919 | + " # # # # # # # # #\n" |
| 920 | + " # # # # # # # # # #\n" |
| 921 | + " # # # # ####### # ##### #####\n" |
| 922 | + "\n") |
| 923 | + (insert "To save this part, type " |
| 924 | + (substitute-command-keys |
| 925 | + "\\<mew-summary-mode-map>\\[mew-summary-save].") |
| 926 | + "\nTo display this part in Message mode, type " |
| 927 | + (substitute-command-keys |
| 928 | + "\\<mew-summary-mode-map>\\[mew-caesar-summary-insert-xrot].")) |
| 929 | + (insert "\n\n-------------------- Original \"X-ROT13\" follows --------------------\n") |
| 930 | + (insert-buffer-substring cache beg end) |
| 931 | + )))) |
| 932 | + |
| 933 | +(defun mew-caesar-summary-insert-xrot () |
| 934 | + (interactive) |
| 935 | + (mew-summary-part |
| 936 | + (let* ((fld (mew-current-get-fld (mew-frame-id))) |
| 937 | + (msg (mew-current-get-msg (mew-frame-id))) |
| 938 | + (part (mew-syntax-nums)) |
| 939 | + (cache (mew-cache-hit fld msg 'must-hit)) |
| 940 | + (syntax (mew-cache-decode-syntax cache)) |
| 941 | + (stx (mew-syntax-get-entry syntax part)) |
| 942 | + (beg (mew-syntax-get-begin stx)) |
| 943 | + (end (mew-syntax-get-end stx)) |
| 944 | + (win (selected-window))) |
| 945 | + (unwind-protect |
| 946 | + (progn |
| 947 | + (mew-summary-toggle-disp-msg 'on) |
| 948 | + (mew-window-configure 'message) |
| 949 | + (set-buffer (mew-buffer-message)) |
| 950 | + (mew-elet |
| 951 | + (mew-summary-display-preamble) |
| 952 | + (insert-buffer-substring cache beg end) |
| 953 | + (mew-caesar-whole-buffer) |
| 954 | + ;; (goto-char (point-min)) |
| 955 | + (mew-summary-display-postscript))) |
| 956 | + (select-window win))))) |
| 957 | + |
| 958 | +(defun mew-caesar-attach-find-new-xrot () |
| 959 | + "Open a new Caesar encrypt file into a buffer on \".\" in attachments." |
| 960 | + (interactive) |
| 961 | + (if (not (mew-attach-not-line012-1)) |
| 962 | + (message "Cannot find a new file here") |
| 963 | + (let* ((nums (mew-syntax-nums)) |
| 964 | + (subdir (mew-attach-expand-path mew-encode-syntax nums)) |
| 965 | + (attachdir (mew-attachdir)) |
| 966 | + file filepath) |
| 967 | + ;; attachdir / {subdir/} dir |
| 968 | + (if (not (equal subdir "")) |
| 969 | + (setq attachdir (expand-file-name subdir attachdir))) |
| 970 | + ;; attachdir / file |
| 971 | + (setq filepath (mew-random-filename attachdir 1 nil mew-caesar-rot13-suffix)) |
| 972 | + (if (null filepath) |
| 973 | + (message "Could not make a text file, sorry") |
| 974 | + (setq file (file-name-nondirectory filepath)) |
| 975 | + (setq mew-encode-syntax |
| 976 | + (mew-syntax-insert-entry |
| 977 | + mew-encode-syntax |
| 978 | + nums |
| 979 | + (mew-encode-syntax-single file (list mew-caesar-ct-rot13)))) |
| 980 | + (mew-encode-syntax-print mew-encode-syntax) |
| 981 | + ;; |
| 982 | + (find-file filepath) |
| 983 | + ;; buffer switched |
| 984 | + (setq mode-name "X-Rot13") |
| 985 | + (setq mode-line-buffer-identification mew-mode-line-id) |
| 986 | + (local-set-key "\C-c\C-q" 'mew-kill-buffer) |
| 987 | + (local-set-key "\C-cr" 'mew-caesar-whole-buffer) |
| 988 | + (local-set-key "\C-c\C-s" 'mew-caesar-save-exit) |
| 989 | + (insert " # # ###### ####### ####### # #####\n" |
| 990 | + " # # # # # # # ## # #\n" |
| 991 | + " # # # # # # # # # #\n" |
| 992 | + " # ##### ###### # # # # #####\n" |
| 993 | + " # # # # # # # # #\n" |
| 994 | + " # # # # # # # # # #\n" |
| 995 | + " # # # # ####### # ##### #####\n") |
| 996 | + (insert "\n define-key \"\\C-cr\" -> mew-caesar-whole-buffer.") |
| 997 | + (insert "\n define-key \"\\C-c\\C-s\" -> mew-caesar-save-exit.") |
| 998 | + (insert "\n\n Press any key to start editting.") |
| 999 | + (read-char-exclusive) |
| 1000 | + (delete-region (point-min) (point-max)) |
| 1001 | + (run-hooks 'mew-caesar-xrot-mode-hook) |
| 1002 | + )))) |
| 1003 | + |
| 1004 | +(defun mew-caesar-save-exit () |
| 1005 | + "Caesar encrypt/decrypt at whole buffer, save and exit." |
| 1006 | + (interactive) |
| 1007 | + (mew-caesar-whole-buffer) |
| 1008 | + (if (y-or-n-p (format "Save & Exit ?")) |
| 1009 | + (progn |
| 1010 | + (save-buffer) |
| 1011 | + (kill-buffer (current-buffer))) |
| 1012 | + (mew-caesar-whole-buffer))) |
| 1013 | + |
| 1014 | +(defun mew-caesar-whole-buffer () |
| 1015 | + "Caesar encrypt/decrypt at whole buffer." |
| 1016 | + (interactive) |
| 1017 | + (mew-caesar-region (point-min) (point-max))) |
| 1018 | + |
| 1019 | +(defun mew-caesar-region (min max) |
| 1020 | + "Caesar encrypt/decrypt in region." |
| 1021 | + (interactive "r") |
| 1022 | + (save-excursion |
| 1023 | + (cond |
| 1024 | + ((eq mew-caesar-function 'semi) |
| 1025 | + (mule-caesar-region min max)) |
| 1026 | + ((eq mew-caesar-function 'tm) |
| 1027 | + (progn |
| 1028 | + (goto-char min) |
| 1029 | + (push-mark (point) nil t) |
| 1030 | + (goto-char max) |
| 1031 | + (tm:caesar-region))) |
| 1032 | + ((and (eq mew-caesar-function 'ext) |
| 1033 | + mew-caesar-ext-prog mew-caesar-ext-prog-arg) |
| 1034 | + (save-excursion |
| 1035 | + (mew-piolet |
| 1036 | + mew-cs-autoconv mew-cs-m17n |
| 1037 | + (apply (function call-process-region) |
| 1038 | + min max |
| 1039 | + mew-caesar-ext-prog |
| 1040 | + t t nil |
| 1041 | + mew-caesar-ext-prog-arg)))) |
| 1042 | + (t |
| 1043 | + (message "mew-caesar: program is not found"))) |
| 1044 | + )) |
| 1045 | + |
| 1046 | +(provide 'mew-caesar) |
| 1047 | + |
| 1048 | +;;; Copyright Notice: |
| 1049 | + |
| 1050 | +;; Copyright (C) 1998-2000 Hideyuki SHIRAI <[email protected]> |
| 1051 | +;; Copyright (C) 1994-2000 Mew developing team. |
| 1052 | +;; All rights reserved. |
| 1053 | + |
| 1054 | +;; Redistribution and use in source and binary forms, with or without |
| 1055 | +;; modification, are permitted provided that the following conditions |
| 1056 | +;; are met: |
| 1057 | +;; |
| 1058 | +;; 1. Redistributions of source code must retain the above copyright |
| 1059 | +;; notice, this list of conditions and the following disclaimer. |
| 1060 | +;; 2. Redistributions in binary form must reproduce the above copyright |
| 1061 | +;; notice, this list of conditions and the following disclaimer in the |
| 1062 | +;; documentation and/or other materials provided with the distribution. |
| 1063 | +;; 3. Neither the name of the team nor the names of its contributors |
| 1064 | +;; may be used to endorse or promote products derived from this software |
| 1065 | +;; without specific prior written permission. |
| 1066 | +;; |
| 1067 | +;; THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS'' AND |
| 1068 | +;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 1069 | +;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 1070 | +;; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TEAM OR CONTRIBUTORS BE |
| 1071 | +;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 1072 | +;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 1073 | +;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 1074 | +;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 1075 | +;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 1076 | +;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 1077 | +;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 1078 | + |
| 1079 | +;;; mew-caesar.el ends here |
| 1080 | diff -urN mew.orig/contrib/mew-edebug.el mew/contrib/mew-edebug.el |
| 1081 | --- mew.orig/contrib/mew-edebug.el 1970-01-01 09:00:00.000000000 +0900 |
| 1082 | +++ mew/contrib/mew-edebug.el 2011-06-20 01:46:27.000000000 +0900 |
| 1083 | @@ -0,0 +1,145 @@ |
| 1084 | +;; mew-edebug.el --- Help for using edebug for macros in Mew |
| 1085 | + |
| 1086 | +;; Author: Sen Nagata <[email protected]> |
| 1087 | +;; Created: Nov 11, 2001 |
| 1088 | +;; Version: 0.3 |
| 1089 | + |
| 1090 | +;; Set-up: |
| 1091 | +;; |
| 1092 | +;; Put this file somewhere in your `load-path' and the following in |
| 1093 | +;; your .emacs: |
| 1094 | +;; |
| 1095 | +;; (add-hook 'mew-init-hook |
| 1096 | +;; '(lambda () |
| 1097 | +;; (require 'mew-edebug))) |
| 1098 | +;; |
| 1099 | +;; Upon instrumenting a function with `edebug-defun', |
| 1100 | +;; `mew-edebug-macro-init' will be run to instrument Mew macros. |
| 1101 | + |
| 1102 | +;; Issues: |
| 1103 | +;; |
| 1104 | +;; I've tested many of the macros below with edebug. Although most |
| 1105 | +;; appear to work, I experienced problems with some |
| 1106 | +;; (e.g. `mew-time-rfc-*'). I don't know what the problem is yet, but |
| 1107 | +;; my current suspicion is that it has something to do with |
| 1108 | +;; `defsubst'. |
| 1109 | + |
| 1110 | +;;; Code: |
| 1111 | + |
| 1112 | +(require 'mew) |
| 1113 | + |
| 1114 | +(defvar mew-macro-names |
| 1115 | + '( |
| 1116 | + mew-header-encode-cond |
| 1117 | + mew-header-encode-cond2 |
| 1118 | + mew-complete-proto-folder |
| 1119 | + mew-decode-narrow-to-header |
| 1120 | + mew-draft-privacy-switch |
| 1121 | + mew-summary-header-mode |
| 1122 | + mew-no-warning-defvar |
| 1123 | + mew-no-warning-defun |
| 1124 | + mew-ntake |
| 1125 | + mew-add-first |
| 1126 | + mew-addq |
| 1127 | + mew-insert-after |
| 1128 | + mew-replace-with |
| 1129 | + mew-remove-entry |
| 1130 | + mew-folder-insert |
| 1131 | + mew-folder-delete |
| 1132 | + mew-elet |
| 1133 | + mew-filter |
| 1134 | + mew-time-rfc-day |
| 1135 | + mew-time-rfc-mon |
| 1136 | + mew-time-rfc-year |
| 1137 | + mew-time-rfc-hour |
| 1138 | + mew-time-rfc-min |
| 1139 | + mew-time-rfc-sec |
| 1140 | + mew-time-rfc-tmzn |
| 1141 | + mew-rendezvous |
| 1142 | + mew-defstruct |
| 1143 | + mew-defstruct-constructor |
| 1144 | + mew-defstruct-s/getter |
| 1145 | + mew-addrstr-parse-syntax-list-check-depth |
| 1146 | + mew-mark-alist-set |
| 1147 | + mew-mode-input-file-name |
| 1148 | + mew-mode-input-directory-name |
| 1149 | + mew-plet |
| 1150 | + mew-piolet |
| 1151 | + mew-flet |
| 1152 | + mew-frwlet |
| 1153 | + mew-alet |
| 1154 | + mew-passwd-rendezvous |
| 1155 | + mew-dolist-eob |
| 1156 | + mew-pick-lex-cut |
| 1157 | + mew-summary-refilable |
| 1158 | + mew-msgid-check |
| 1159 | + mew-summary-msg-or-part |
| 1160 | + mew-summary-msg |
| 1161 | + mew-summary-part |
| 1162 | + mew-summary-multi-msgs |
| 1163 | + mew-summary-only |
| 1164 | + mew-virtual-only |
| 1165 | + mew-thread-only |
| 1166 | + mew-pickable |
| 1167 | + mew-summary-not-in-queue |
| 1168 | + mew-summary-not-in-draft |
| 1169 | + mew-summary-not-in-nntp |
| 1170 | + mew-summary-local-or-imap |
| 1171 | + mew-summary-local-only |
| 1172 | + mew-summary-with-mewl |
| 1173 | + mew-summary-prepare-draft |
| 1174 | + mew-setface |
| 1175 | + mew-setface-bold |
| 1176 | + mew-defface |
| 1177 | + mew-defface-bold |
| 1178 | + )) |
| 1179 | + |
| 1180 | +(defun mew-edebug-macro-init () |
| 1181 | + "Call `def-edebug-spec' for each macro in `mew-macro-names'. |
| 1182 | + |
| 1183 | +This function should be invoked before instrumenting a function for |
| 1184 | +use with edebug." |
| 1185 | + (interactive) |
| 1186 | + (let ((macro-names mew-macro-names)) |
| 1187 | + (while macro-names |
| 1188 | + (eval `(def-edebug-spec ,(car macro-names) t)) |
| 1189 | + (setq macro-names (cdr macro-names))))) |
| 1190 | + |
| 1191 | +;; instrument Mew macros when edebug is used |
| 1192 | +(add-hook 'edebug-setup-hook |
| 1193 | + '(lambda () |
| 1194 | + (mew-edebug-macro-init))) |
| 1195 | + |
| 1196 | +(provide 'mew-edebug) |
| 1197 | + |
| 1198 | +;;; Copyright Notice: |
| 1199 | + |
| 1200 | +;; Copyright (C) 2001 Mew developing team. |
| 1201 | +;; All rights reserved. |
| 1202 | + |
| 1203 | +;; Redistribution and use in source and binary forms, with or without |
| 1204 | +;; modification, are permitted provided that the following conditions |
| 1205 | +;; are met: |
| 1206 | +;; |
| 1207 | +;; 1. Redistributions of source code must retain the above copyright |
| 1208 | +;; notice, this list of conditions and the following disclaimer. |
| 1209 | +;; 2. Redistributions in binary form must reproduce the above copyright |
| 1210 | +;; notice, this list of conditions and the following disclaimer in the |
| 1211 | +;; documentation and/or other materials provided with the distribution. |
| 1212 | +;; 3. Neither the name of the team nor the names of its contributors |
| 1213 | +;; may be used to endorse or promote products derived from this software |
| 1214 | +;; without specific prior written permission. |
| 1215 | +;; |
| 1216 | +;; THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS'' AND |
| 1217 | +;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 1218 | +;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 1219 | +;; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TEAM OR CONTRIBUTORS BE |
| 1220 | +;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 1221 | +;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 1222 | +;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 1223 | +;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 1224 | +;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 1225 | +;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 1226 | +;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 1227 | + |
| 1228 | +;;; mew-edebug.el ends here |
| 1229 | diff -urN mew.orig/contrib/mew-fancy-summary.el mew/contrib/mew-fancy-summary.el |
| 1230 | --- mew.orig/contrib/mew-fancy-summary.el 1970-01-01 09:00:00.000000000 +0900 |
| 1231 | +++ mew/contrib/mew-fancy-summary.el 2011-06-15 00:20:15.000000000 +0900 |
| 1232 | @@ -0,0 +1,565 @@ |
| 1233 | +;;; mew-fancy-summary.el --- Fontify Mew summary buffer |
| 1234 | +;; |
| 1235 | +;; Author: Shun-ichi TAHARA <[email protected]> |
| 1236 | +;; Hideyuki SHIRAI <[email protected]> |
| 1237 | +;; |
| 1238 | +;; Time-stamp: <03/13/2002 20:45 shirai> |
| 1239 | + |
| 1240 | +;;; Commentary: |
| 1241 | +;; |
| 1242 | +;; HOW TO USE |
| 1243 | +;; |
| 1244 | +;; 1. Set some customize variables and faces as you like. |
| 1245 | +;; |
| 1246 | +;; 2. Require this file in your init file of Emacsen. |
| 1247 | +;; |
| 1248 | +;; (add-hook 'mew-init-hook (lambda () (require 'mew-fancy-summary))) |
| 1249 | +;; |
| 1250 | +;; 3. BE SURE TO USE jit-lock, lazy-shot or lazy-lock. |
| 1251 | +;; |
| 1252 | +;; ;;; common setting |
| 1253 | +;; (require 'font-lock) |
| 1254 | +;; ;; (global-font-lock-mode t) ;; as you like. |
| 1255 | +;; |
| 1256 | +;; ;;; jit-lock-mode (for Emacs-21) |
| 1257 | +;; (setq font-lock-support-mode 'jit-lock-mode) ;; system default value. |
| 1258 | +;; |
| 1259 | +;; ;;; lazy-shot-mode (for XEmacs) |
| 1260 | +;; (require 'font-lock) |
| 1261 | +;; (setq font-lock-support-mode 'lazy-shot-mode) |
| 1262 | +;; (setq lazy-shot-verbose nil) |
| 1263 | +;; (setq lazy-shot-stealth-verbose nil) |
| 1264 | +;; |
| 1265 | +;; ;;; lazy-lock-mode (for All Emacsen) |
| 1266 | +;; (require 'font-lock) |
| 1267 | +;; (setq font-lock-support-mode 'lazy-lock-mode) |
| 1268 | +;; (when (featurep 'xemacs) |
| 1269 | +;; (setq lazy-lock-minimum-size 0)) |
| 1270 | +;; |
| 1271 | +;; 4. If you use 'jit-lock-mode' and feel 'scan is too slow' |
| 1272 | +;; , please put bellow code to your init file. |
| 1273 | +;; |
| 1274 | +;; (add-hook 'mew-init-hook |
| 1275 | +;; (lambda () |
| 1276 | +;; (defvar mew-fancy-disable nil) |
| 1277 | +;; (make-variable-buffer-local 'mew-fancy-disable) |
| 1278 | +;; (defadvice mew-scan (before fancy-disable activate) |
| 1279 | +;; (setq mew-fancy-disable t)) |
| 1280 | +;; (defadvice mew-scan-filter (before fancy-disable activate) |
| 1281 | +;; (when (and mew-fancy-disable font-lock-mode) |
| 1282 | +;; (setq mew-fancy-disable nil) |
| 1283 | +;; (font-lock-mode -1))) |
| 1284 | +;; )) |
| 1285 | +;; |
| 1286 | +;; BUGS |
| 1287 | +;; |
| 1288 | +;; 1. If you choice 'lazy-lock-mode', mew-summary-cook-folders() becomes |
| 1289 | +;; too slow. |
| 1290 | +;; |
| 1291 | + |
| 1292 | +;;; Code: |
| 1293 | + |
| 1294 | +(eval-when-compile (require 'mew)) |
| 1295 | +(defconst mew-fancy-summary-version "mew-fancy-summary 0.23") |
| 1296 | + |
| 1297 | +;;; User-customizable variables |
| 1298 | + |
| 1299 | +(defcustom mew-fancy-summary-face-spec |
| 1300 | + '((num . mew-fancy-summary-face-marginal) |
| 1301 | + (size . mew-fancy-summary-face-marginal) |
| 1302 | + (type . mew-fancy-summary-face-type) |
| 1303 | + (from . "From:") |
| 1304 | + (subj . "Subject:") |
| 1305 | + (date . "Date:") |
| 1306 | + (year . "Date:") |
| 1307 | + (time . "Date:")) |
| 1308 | + "*Alist of face specs for fancy-summary mode, corresponding to |
| 1309 | +scan-form entries. Each entry consists of a pair of symbol or string |
| 1310 | +and face, header name or function. |
| 1311 | + |
| 1312 | +The symbol is what can be set in scan-form, including user-extended |
| 1313 | +entry. |
| 1314 | + |
| 1315 | +If you want to highlight the raw string in 'mew-scan-form', put the |
| 1316 | +string and the corresponding face (or another possible) in this alist. |
| 1317 | +Also define the face, if needed. |
| 1318 | + |
| 1319 | +The face and the function are both set as a symbol in cdr of each |
| 1320 | +entry. As a special case, you can specify 'nil' not to highlight the |
| 1321 | +field. |
| 1322 | + |
| 1323 | +If the symbol is a function name, the function is called with an |
| 1324 | +integer argument indicating the width of the field (or 0 means |
| 1325 | +unlimited) and with the pointer pointing the top of the field to be |
| 1326 | +highlighted. In the function, you can fontify it as you like, and no |
| 1327 | +return values are needed (even the cursor position need not be cared). |
| 1328 | + |
| 1329 | +The string in cdr of the entry indicates a header name, and a face is |
| 1330 | +decided by 'mew-field-spec' with the header name." |
| 1331 | + :group 'mew-highlight |
| 1332 | + :type '(repeat (cons (choice symbol string) (choice face string function)))) |
| 1333 | + |
| 1334 | +(defcustom mew-fancy-summary-extended-face-spec |
| 1335 | + '((truncated . mew-fancy-summary-face-truncated) |
| 1336 | + (thread . mew-fancy-summary-face-marginal) |
| 1337 | + (special . mew-fancy-summary-face-special) |
| 1338 | + (ml . mew-fancy-summary-face-tag) |
| 1339 | + (attach . mew-fancy-summary-face-marginal) |
| 1340 | + (to . "To:")) |
| 1341 | + "*Alist of face specs for fancy-summary mode, not corresponding to |
| 1342 | +scan-form entries. Each entry consists of a pair of symbol and face, |
| 1343 | +header name or function. |
| 1344 | + |
| 1345 | +Symbol is one of those: 'truncated' for 'T' mark in the 'type' field |
| 1346 | +in scan-form, 'thread' for a thread indent, 'special' for the special |
| 1347 | +person (see also 'mew-fancy-summary-special-*'), 'ml' for a subject |
| 1348 | +prefix of ML (see also 'mew-fancy-summary-ml-regex'), and 'attach' for |
| 1349 | +a attachment line. |
| 1350 | + |
| 1351 | +For cdr of each element, see 'mew-fancy-summary-face-spec'." |
| 1352 | + :group 'mew-highlight |
| 1353 | + :type '(repeat (cons (choice symbol string) (choice face string function)))) |
| 1354 | + |
| 1355 | +(defcustom mew-fancy-summary-special-persons nil |
| 1356 | + "*List of the 'special' persons. |
| 1357 | + |
| 1358 | +If the From: header matches a member of this list, 'special' entry of |
| 1359 | +'mew-fancy-summary-extended-face-spec' is used for highlighting 'from' |
| 1360 | +part of scan-form." |
| 1361 | + :group 'mew-highlight |
| 1362 | + :type '(repeat string)) |
| 1363 | + |
| 1364 | +(defcustom mew-fancy-summary-special-addrbook nil |
| 1365 | + "*If non-nil, nicknames in the addrbook are treated as 'special' |
| 1366 | +person." |
| 1367 | + :group 'mew-highlight |
| 1368 | + :type 'boolean) |
| 1369 | + |
| 1370 | +(defcustom mew-fancy-summary-special-to t |
| 1371 | + "*If non-nil, 'from' part of scan-form about an entry of the mail |
| 1372 | +destinated to 'special' person (then displayed To: header) are also |
| 1373 | +highlighted specially." |
| 1374 | + :group 'mew-highlight |
| 1375 | + :type 'boolean) |
| 1376 | + |
| 1377 | +(defcustom mew-fancy-summary-ml-regex "[\[(][^])|\n\r]*[\])|]" |
| 1378 | + "*Regex string as a prefix of the subject of mails posted to ML." |
| 1379 | + :group 'mew-highlight |
| 1380 | + :type 'regexp) |
| 1381 | + |
| 1382 | +(defcustom mew-fancy-summary-external-highlighting-hook nil |
| 1383 | + "*Hook called to highlight an abnormal line. |
| 1384 | + |
| 1385 | +If the function in the hook highlighted the line successfully, it must |
| 1386 | +return t, otherwise nil." |
| 1387 | + :group 'mew-highlight |
| 1388 | + :type 'hook) |
| 1389 | + |
| 1390 | +;;; Faces |
| 1391 | + |
| 1392 | +(defface mew-fancy-summary-face-marginal nil |
| 1393 | + "*Face to highlight the marginal part of Summary buffer." |
| 1394 | + :group 'mew-highlight) |
| 1395 | + |
| 1396 | +(defface mew-fancy-summary-face-type nil |
| 1397 | + "*Face to highlight 'type' part of Summary buffer (except 'T' mark)." |
| 1398 | + :group 'mew-highlight) |
| 1399 | + |
| 1400 | +(defface mew-fancy-summary-face-truncated nil |
| 1401 | + "*Face to highlight 'T' mark at 'type' part of Summary buffer." |
| 1402 | + :group 'mew-highlight) |
| 1403 | + |
| 1404 | +(defface mew-fancy-summary-face-special nil |
| 1405 | + "*Face to highlight the special person in 'from' part of Summary buffer." |
| 1406 | + :group 'mew-highlight) |
| 1407 | + |
| 1408 | +(defface mew-fancy-summary-face-tag nil |
| 1409 | + "*Face to highlight the tag part of Summary buffer." |
| 1410 | + :group 'mew-highlight) |
| 1411 | + |
| 1412 | +;;; End of user-customizable stuffs |
| 1413 | + |
| 1414 | +;;; Internal variables |
| 1415 | + |
| 1416 | +(defvar mew-fancy-summary-special-list nil) |
| 1417 | +(defvar mew-fancy-summary-special-alist nil) |
| 1418 | + |
| 1419 | +(defvar mew-fancy-summary-scan-form nil) |
| 1420 | +(make-variable-buffer-local 'mew-fancy-summary-scan-form) |
| 1421 | + |
| 1422 | +(defvar mew-fancy-summary-thread-column nil) |
| 1423 | +(make-variable-buffer-local 'mew-fancy-summary-thread-column) |
| 1424 | + |
| 1425 | +;;; Initialization |
| 1426 | + |
| 1427 | +(add-hook 'mew-summary-mode-hook 'mew-fancy-summary-enable) |
| 1428 | +(add-hook 'mew-virtual-mode-hook 'mew-fancy-summary-enable) |
| 1429 | +(add-hook 'mew-thread-display-hook 'mew-fancy-summary-thread-enable) |
| 1430 | +(add-hook 'mew-pop-sentinel-hook 'mew-fancy-summary-block) |
| 1431 | +(add-hook 'mew-scan-sentinel-hook 'mew-fancy-summary-block) |
| 1432 | + |
| 1433 | +(setq mew-use-highlight-mark nil) ; Hilight mark by itself, not by Mew |
| 1434 | + |
| 1435 | +(defalias 'mew-summary-cook-region 'mew-fancy-summary-make-invisible-region) |
| 1436 | +(defalias 'mew-highlight-mark-line 'mew-fancy-summary-mark-line) |
| 1437 | +(defalias 'mew-highlight-unmark-line 'mew-fancy-summary-mark-line) |
| 1438 | + |
| 1439 | +;;; Setup |
| 1440 | + |
| 1441 | +(defadvice mew-addrbook-setup (after hl-setup activate) |
| 1442 | + "Setup fancy-summary when starting up Mew or executing \"Z\"." |
| 1443 | + (mew-fancy-summary-special-setup)) |
| 1444 | + |
| 1445 | +(defun mew-fancy-summary-special-setup () |
| 1446 | + (setq mew-fancy-summary-special-list mew-fancy-summary-special-persons) |
| 1447 | + (when mew-fancy-summary-special-addrbook |
| 1448 | + (let ((addrbook mew-addrbook-alist) nickname) |
| 1449 | + (while addrbook |
| 1450 | + (setq nickname (nth 2 (car addrbook))) |
| 1451 | + (when (and (stringp nickname) |
| 1452 | + (not (member nickname mew-fancy-summary-special-list))) |
| 1453 | + (setq mew-fancy-summary-special-list |
| 1454 | + (cons nickname mew-fancy-summary-special-list))) |
| 1455 | + (setq addrbook (cdr addrbook)))))) |
| 1456 | + |
| 1457 | +;;; Workarounds about highlighting in Mew |
| 1458 | + |
| 1459 | +(defun mew-fancy-summary-remove-invisible () |
| 1460 | + "Remove the invisible hook in Mew." |
| 1461 | + (jit-lock-unregister 'mew-summary-cook-region) |
| 1462 | + (remove-hook 'window-scroll-functions 'mew-summary-cook-window 'local) |
| 1463 | + (remove-hook 'pre-idle-hook 'mew-summary-cook-window)) |
| 1464 | + |
| 1465 | +(defun mew-fancy-summary-make-invisible-region (beg end &optional interrupt) |
| 1466 | + "Faster invisible function for summary with many text properties." |
| 1467 | + (when (and (memq major-mode |
| 1468 | + '(mew-summary-mode mew-virtual-mode mew-refile-view-mode)) |
| 1469 | + mew-summary-buffer-raw) |
| 1470 | + (let ((inhibit-point-motion-hooks t) ret start) |
| 1471 | + (catch 'loop |
| 1472 | + (mew-elet |
| 1473 | + (save-excursion |
| 1474 | + (goto-char beg) |
| 1475 | + (while (and (< (point) end) |
| 1476 | + (search-forward "\r" end t)) |
| 1477 | + (setq start (match-beginning 0)) |
| 1478 | + (unless (get-text-property start 'invisible) |
| 1479 | + (put-text-property start (line-end-position) 'invisible t)) |
| 1480 | + (forward-line) |
| 1481 | + (when (and interrupt (input-pending-p)) |
| 1482 | + (throw 'loop (setq ret t))))))) |
| 1483 | + (set-buffer-modified-p nil) |
| 1484 | + ret))) |
| 1485 | + |
| 1486 | +(defun mew-fancy-summary-mark-line (&rest args) |
| 1487 | + "Highlighting mark and unmark line is done by mew-fancy-summary." |
| 1488 | + (save-excursion |
| 1489 | + (mew-fancy-summary-region (point) (point) nil 'strip))) |
| 1490 | + |
| 1491 | +;;; Activating fancy summary |
| 1492 | + |
| 1493 | +(defun mew-fancy-summary-enable () |
| 1494 | + "Activate mew-fancy-summary in summary or virtual buffer." |
| 1495 | + (mew-fancy-summary-remove-invisible) |
| 1496 | + (unless (mew-thread-p) |
| 1497 | + (set (make-local-variable 'font-lock-fontify-buffer-function) |
| 1498 | + 'mew-fancy-summary-buffer) |
| 1499 | + (when (boundp 'font-lock-function) |
| 1500 | + (set (make-local-variable 'font-lock-function) |
| 1501 | + 'mew-fancy-summary-font-lock-function)) |
| 1502 | + (set (make-local-variable 'font-lock-fontify-region-function) |
| 1503 | + 'mew-fancy-summary-region) |
| 1504 | + (setq mew-fancy-summary-scan-form |
| 1505 | + (mew-get-summary-form (mew-summary-folder-name 'ext))) |
| 1506 | + (setq mew-fancy-summary-thread-column -1) |
| 1507 | + (font-lock-mode 1))) |
| 1508 | + |
| 1509 | +(defun mew-fancy-summary-font-lock-function (font-lock-mode) |
| 1510 | + (when font-lock-mode |
| 1511 | + (add-hook 'after-change-functions 'font-lock-after-change-function t t) |
| 1512 | + (font-lock-turn-on-thing-lock)) |
| 1513 | + (unless font-lock-mode |
| 1514 | + (remove-hook 'after-change-functions 'font-lock-after-change-function t) |
| 1515 | + (font-lock-unfontify-buffer) |
| 1516 | + (font-lock-turn-off-thing-lock))) |
| 1517 | + |
| 1518 | +(defun mew-fancy-summary-thread-enable () |
| 1519 | + "Activate mew-fancy-summary in thread buffer." |
| 1520 | + (when (mew-thread-p) |
| 1521 | + (mew-fancy-summary-remove-invisible) |
| 1522 | + (setq mew-fancy-summary-scan-form |
| 1523 | + (mew-get-summary-form (substring (mew-summary-folder-name 'ext) 1))) |
| 1524 | + (setq mew-fancy-summary-thread-column (mew-vinfo-get-column)) |
| 1525 | + (when (boundp 'font-lock-function) |
| 1526 | + (set (make-local-variable 'font-lock-function) |
| 1527 | + 'mew-fancy-summary-font-lock-function)) |
| 1528 | + (set (make-local-variable 'font-lock-fontify-buffer-function) |
| 1529 | + 'mew-fancy-summary-buffer) |
| 1530 | + (set (make-local-variable 'font-lock-fontify-region-function) |
| 1531 | + 'mew-fancy-summary-region) |
| 1532 | + (font-lock-mode 1))) |
| 1533 | + |
| 1534 | +;;; macros |
| 1535 | + |
| 1536 | +(defmacro mew-fancy-summary-get-face (key extended) |
| 1537 | + `(let ((face (cdr (assoc ,key (if ,extended |
| 1538 | + mew-fancy-summary-extended-face-spec |
| 1539 | + mew-fancy-summary-face-spec))))) |
| 1540 | + (if (stringp face) |
| 1541 | + (or (mew-nspec-valface (mew-nspec-by-key face)) |
| 1542 | + 'mew-face-header-marginal) |
| 1543 | + face))) |
| 1544 | + |
| 1545 | +(defsubst mew-fancy-summary-special-p (key len) |
| 1546 | + (when (and mew-fancy-summary-special-list (> (length key) 0)) |
| 1547 | + (member key (or (cdr (assq len mew-fancy-summary-special-alist)) |
| 1548 | + (let ((special mew-fancy-summary-special-list) |
| 1549 | + lst str) |
| 1550 | + (while special |
| 1551 | + (setq str (truncate-string-to-width (car special) len)) |
| 1552 | + (when (string-match "^.+\\( +\\)$" str) |
| 1553 | + (setq str (substring str 0 (match-beginning 1)))) |
| 1554 | + (setq lst (cons str lst)) |
| 1555 | + (setq special (cdr special))) |
| 1556 | + (setq mew-fancy-summary-special-alist |
| 1557 | + (cons (cons len lst) mew-fancy-summary-special-alist)) |
| 1558 | + lst))))) |
| 1559 | + |
| 1560 | +;;; Main |
| 1561 | + |
| 1562 | +(defun mew-fancy-summary-block () |
| 1563 | + (font-lock-mode 1)) |
| 1564 | + |
| 1565 | +(defun mew-fancy-summary-buffer () |
| 1566 | + "Highlight summary buffer with font-lock-mode." |
| 1567 | + (interactive) |
| 1568 | + (mew-fancy-summary-region (point-min) (point-max))) |
| 1569 | + |
| 1570 | +(defun mew-fancy-summary-region (beg end &optional loudly strip) |
| 1571 | + "Highlight the region of summary buffer with font-lock-mode." |
| 1572 | + (interactive "r") |
| 1573 | + (let ((pos (point)) linebeg lineend col numend) |
| 1574 | + (when (memq major-mode |
| 1575 | + '(mew-summary-mode mew-virtual-mode mew-refile-view-mode)) |
| 1576 | + (mew-elet |
| 1577 | + (setq end (progn (goto-char end) |
| 1578 | + (forward-line) |
| 1579 | + (point))) |
| 1580 | + (setq beg (progn (goto-char beg) |
| 1581 | + (beginning-of-line) |
| 1582 | + (point))) |
| 1583 | + (when strip |
| 1584 | + (put-text-property beg end 'face nil)) |
| 1585 | + (mew-fancy-summary-make-invisible-region beg end) |
| 1586 | + ;; Highlight each line |
| 1587 | + (while (< (point) end) |
| 1588 | + (setq linebeg (point)) |
| 1589 | + (setq col 0) |
| 1590 | + (cond |
| 1591 | + ;; unread line |
| 1592 | + ((and (not (mew-in-decode-syntax-p)) |
| 1593 | + (setq numend (point-min)) |
| 1594 | + (eq (char-after) mew-mark-unread)) |
| 1595 | + (let ((form mew-fancy-summary-scan-form) entry) |
| 1596 | + (while form |
| 1597 | + (setq entry (car form)) |
| 1598 | + (when (= col mew-fancy-summary-thread-column) |
| 1599 | + (setq col (+ col (mew-fancy-summary-do-highlight 'thread t)))) |
| 1600 | + (setq col (+ col (mew-fancy-summary-do-highlight entry nil numend))) |
| 1601 | + (setq form (cdr form)))) |
| 1602 | + (looking-at "[^\r\n]*") |
| 1603 | + (setq lineend (match-end 0)) |
| 1604 | + (put-text-property linebeg (1+ linebeg) 'face 'mew-face-mark-unread)) |
| 1605 | + ;; Normal line |
| 1606 | + ((and (not (mew-in-decode-syntax-p)) |
| 1607 | + (setq numend (point-min)) |
| 1608 | + (not (looking-at mew-regex-mark))) |
| 1609 | + (let ((form mew-fancy-summary-scan-form) entry) |
| 1610 | + (while form |
| 1611 | + (setq entry (car form)) |
| 1612 | + (when (= col mew-fancy-summary-thread-column) |
| 1613 | + (setq col (+ col (mew-fancy-summary-do-highlight 'thread t)))) |
| 1614 | + (setq col (+ col (mew-fancy-summary-do-highlight entry nil numend))) |
| 1615 | + (setq form (cdr form)))) |
| 1616 | + (looking-at "[^\r\n]*") |
| 1617 | + (setq lineend (match-end 0))) |
| 1618 | + ;; Marked line |
| 1619 | + ((and (not (mew-in-decode-syntax-p)) |
| 1620 | + (looking-at mew-regex-mark)) |
| 1621 | + (let ((mark (string-to-char (match-string 0)))) |
| 1622 | + (looking-at "[^\r\n]*") |
| 1623 | + (setq lineend (match-end 0)) |
| 1624 | + (put-text-property linebeg lineend |
| 1625 | + 'face (mew-highlight-mark-get-face mark)))) |
| 1626 | + ;; Others (usually, expanded multi-part) |
| 1627 | + (t |
| 1628 | + (unless (run-hook-with-args-until-success |
| 1629 | + ;; Highlight thread separator or folder of refile-view |
| 1630 | + ;; by your custom function |
| 1631 | + 'mew-fancy-summary-external-highlighting-hook nil) |
| 1632 | + (setq lineend (progn (end-of-line) (point))) |
| 1633 | + (put-text-property linebeg lineend |
| 1634 | + 'face (mew-fancy-summary-get-face 'attach t)) |
| 1635 | + (when mew-use-highlight-mouse-line |
| 1636 | + (remove-text-properties linebeg (min (1+ lineend) (point-max)) |
| 1637 | + '(mouse-face)))))) |
| 1638 | + (when mew-use-highlight-mouse-line |
| 1639 | + (put-text-property linebeg lineend |
| 1640 | + 'mouse-face mew-highlight-mouse-line-face)) |
| 1641 | + (forward-line))) |
| 1642 | + (set-buffer-modified-p nil) |
| 1643 | + (goto-char pos)))) |
| 1644 | + |
| 1645 | +;;; |
| 1646 | +(defun mew-fancy-summary-do-highlight (entry &optional extended numend) |
| 1647 | + (let ((l 0) (col (current-column)) beg end range face |
| 1648 | + (spec (mew-fancy-summary-get-spec entry extended))) |
| 1649 | + (while spec |
| 1650 | + (setq range (car (car spec))) |
| 1651 | + (setq face (cdr (car spec))) |
| 1652 | + (cond |
| 1653 | + ((eq range 'num) |
| 1654 | + (if (fboundp face) |
| 1655 | + (funcall face (- numend (point))) |
| 1656 | + (put-text-property (point) numend 'face face)) |
| 1657 | + (setq l (+ l (- numend (point)))) |
| 1658 | + (goto-char numend) |
| 1659 | + (setq col (current-column))) |
| 1660 | + ((stringp range) |
| 1661 | + (when (looking-at range) |
| 1662 | + (setq beg (match-beginning 0)) |
| 1663 | + (setq end (match-end 0)) |
| 1664 | + (if (fboundp face) |
| 1665 | + (funcall face range) |
| 1666 | + (put-text-property beg end 'face face)) |
| 1667 | + (goto-char end) |
| 1668 | + (setq l (+ l (- (current-column) col))) |
| 1669 | + (setq col (current-column)))) |
| 1670 | + ((> range 0) |
| 1671 | + (setq col (+ col (- range l))) |
| 1672 | + (setq beg (point)) |
| 1673 | + (if (fboundp face) |
| 1674 | + (funcall face (- range l)) |
| 1675 | + (move-to-column col) |
| 1676 | + (put-text-property beg (point) 'face face)) |
| 1677 | + (setq l range))) |
| 1678 | + (setq spec (cdr spec))) |
| 1679 | + l)) |
| 1680 | + |
| 1681 | +(defun mew-fancy-summary-get-spec (entry extended) |
| 1682 | + (let ((range (cond |
| 1683 | + ((stringp entry) (string-width entry)) |
| 1684 | + ((listp entry) (abs (car entry))) |
| 1685 | + (t 1))) |
| 1686 | + (elem (cond |
| 1687 | + ((listp entry) (nth 1 entry)) |
| 1688 | + (t entry))) |
| 1689 | + face) |
| 1690 | + (if (= range 0) ; To the tail of line |
| 1691 | + (setq range "[^\r\n]*[^ \r\n]")) |
| 1692 | + (setq face (mew-fancy-summary-get-face elem extended)) |
| 1693 | + (cond |
| 1694 | + ((eq elem t) ;; thread indent |
| 1695 | + nil) |
| 1696 | + ((eq elem 'num) |
| 1697 | + (list (cons elem face))) |
| 1698 | + ((eq elem 'type) |
| 1699 | + (cond |
| 1700 | + ((looking-at "T") |
| 1701 | + (list (cons range (mew-fancy-summary-get-face 'truncated t)))) |
| 1702 | + ((looking-at "[^ ]") |
| 1703 | + (list (cons range face))) |
| 1704 | + (t |
| 1705 | + (list (cons range nil))))) |
| 1706 | + ((eq elem 'thread) |
| 1707 | + (let ((indent (get-text-property (point) 'mew-thread-indent))) |
| 1708 | + (if (or (null indent) (= indent 0)) |
| 1709 | + nil |
| 1710 | + (list (cons (string-width |
| 1711 | + (mew-buffer-substring |
| 1712 | + (point) |
| 1713 | + (next-single-property-change (point) 'mew-thread-indent))) |
| 1714 | + face))))) |
| 1715 | + ((eq elem 'from) |
| 1716 | + (let* ((beg (point)) |
| 1717 | + (entry (mew-buffer-substring |
| 1718 | + beg |
| 1719 | + (prog2 |
| 1720 | + (move-to-column (+ (current-column) range)) |
| 1721 | + (point) |
| 1722 | + (goto-char beg)))) |
| 1723 | + (prelen (and (stringp mew-summary-form-from-me-prefix) |
| 1724 | + (string-width mew-summary-form-from-me-prefix))) |
| 1725 | + elen) |
| 1726 | + (if (string-match "[^\r\n]*[^ \r\n]" entry) |
| 1727 | + (setq entry (substring entry (match-beginning 0) (match-end 0))) |
| 1728 | + (setq entry "")) |
| 1729 | + (setq elen (string-width entry)) |
| 1730 | + (if (not (and prelen (> prelen 0) |
| 1731 | + (eq (string-match mew-summary-form-from-me-prefix entry) 0))) |
| 1732 | + ;; Mail to me |
| 1733 | + (if (mew-fancy-summary-special-p entry range) |
| 1734 | + (list (cons elen (mew-fancy-summary-get-face 'special t)) |
| 1735 | + (cons range nil)) |
| 1736 | + (list (cons elen face) (cons range nil))) |
| 1737 | + ;; Mail from me |
| 1738 | + (setq face (mew-fancy-summary-get-face 'to t)) |
| 1739 | + (if (and prelen mew-fancy-summary-special-to |
| 1740 | + (mew-fancy-summary-special-p (substring entry prelen) |
| 1741 | + (- range prelen))) |
| 1742 | + (list (cons prelen face) |
| 1743 | + (cons elen (mew-fancy-summary-get-face 'special t)) |
| 1744 | + (cons range nil)) |
| 1745 | + (list (cons elen face) (cons range nil)))))) |
| 1746 | + ((eq elem 'subj) |
| 1747 | + (list (cons mew-fancy-summary-ml-regex |
| 1748 | + (mew-fancy-summary-get-face 'ml t)) |
| 1749 | + (cons |
| 1750 | + (if (> mew-fancy-summary-thread-column 0) |
| 1751 | + (save-excursion |
| 1752 | + (move-to-column mew-fancy-summary-thread-column) |
| 1753 | + (- range |
| 1754 | + (* (mew-thread-get-property (point)) |
| 1755 | + mew-thread-indent-width))) |
| 1756 | + range) |
| 1757 | + face))) |
| 1758 | + (t |
| 1759 | + (list (cons range face)))))) |
| 1760 | + |
| 1761 | +;;; |
| 1762 | + |
| 1763 | +(provide 'mew-fancy-summary) |
| 1764 | + |
| 1765 | +;;; Copyright Notice: |
| 1766 | + |
| 1767 | +;; Copyright (C) 2001 Shun-ichi TAHARA <[email protected]> |
| 1768 | +;; Copyright (C) 1999-2001 Hideyuki SHIRAI <[email protected]> |
| 1769 | +;; Copyright (C) 1994-2001 Mew developing team. |
| 1770 | +;; All rights reserved. |
| 1771 | + |
| 1772 | +;; Redistribution and use in source and binary forms, with or without |
| 1773 | +;; modification, are permitted provided that the following conditions |
| 1774 | +;; are met: |
| 1775 | +;; |
| 1776 | +;; 1. Redistributions of source code must retain the above copyright |
| 1777 | +;; notice, this list of conditions and the following disclaimer. |
| 1778 | +;; 2. Redistributions in binary form must reproduce the above copyright |
| 1779 | +;; notice, this list of conditions and the following disclaimer in the |
| 1780 | +;; documentation and/or other materials provided with the distribution. |
| 1781 | +;; 3. Neither the name of the team nor the names of its contributors |
| 1782 | +;; may be used to endorse or promote products derived from this software |
| 1783 | +;; without specific prior written permission. |
| 1784 | +;; |
| 1785 | +;; THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS'' AND |
| 1786 | +;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 1787 | +;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 1788 | +;; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TEAM OR CONTRIBUTORS BE |
| 1789 | +;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 1790 | +;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 1791 | +;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 1792 | +;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 1793 | +;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 1794 | +;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 1795 | +;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 1796 | + |
| 1797 | +;;; mew-fancy-summary.el ends here |
| 1798 | diff -urN mew.orig/contrib/mew-nmz-fixer.el mew/contrib/mew-nmz-fixer.el |
| 1799 | --- mew.orig/contrib/mew-nmz-fixer.el 1970-01-01 09:00:00.000000000 +0900 |
| 1800 | +++ mew/contrib/mew-nmz-fixer.el 2011-06-15 00:20:15.000000000 +0900 |
| 1801 | @@ -0,0 +1,138 @@ |
| 1802 | +;; -*- mode: Emacs-Lisp -*- |
| 1803 | +;; |
| 1804 | +;;; mew-nmz-fixer.el |
| 1805 | +;; |
| 1806 | +;; Author: Hideyuki SHIRAI <[email protected]> |
| 1807 | +;; Created: 2001-01-14(Sun) |
| 1808 | +;; |
| 1809 | +;; nmz-mew-summary-fixer.pl $B$r;H$C$F!"(Bpack $B$d(B sort $B$7$?8e$K(B |
| 1810 | +;; mew-nmz $B7O(B Namazu index $B$r:G?7$KJ]$A$^$9!#(B |
| 1811 | +;; |
| 1812 | +;;; nmz-mew-summary-fixer.pl $B$O(B Rei FURUKAWA $B$5$s(B <[email protected]> |
| 1813 | +;;; $B$,:n@.$7$?(B message $B$H(B index $B$NBP1~99?7(B Program $B$G$9!#(B |
| 1814 | +;; |
| 1815 | +;; |
| 1816 | +;;;; $B;H$$J}(B ($B$^$:(B mew-nmz $B$r;H$($k$h$&$K$7$F$*$-$^$7$g$&(B) |
| 1817 | +;; (eval-after-load "mew-nmz" '(require 'mew-nmz-fixer)) |
| 1818 | +;; |
| 1819 | + |
| 1820 | +(eval-when-compile |
| 1821 | + (require 'mew) |
| 1822 | + (require 'mew-nmz)) |
| 1823 | + |
| 1824 | +;;;; $B$3$s$J46$8$G(B key $B$K(B bind $B$9$k$bNI$7!#(B |
| 1825 | + |
| 1826 | +(add-hook 'mew-summary-mode-hook |
| 1827 | + (lambda () |
| 1828 | + (define-key mew-summary-mode-map "zf" 'mew-nmz-fixer-exec))) |
| 1829 | + |
| 1830 | +;; add-hook |
| 1831 | +(add-hook 'mew-sort-hook 'mew-nmz-fixer-exec) |
| 1832 | +(add-hook 'mew-pack-hook 'mew-nmz-fixer-exec) |
| 1833 | + |
| 1834 | +;; variable |
| 1835 | +(defvar mew-nmz-prog-fixer "nmz-mew-summary-fixer.pl" |
| 1836 | + "*nmz-mew-summary-fixer.pl $B$N(B Program $BL>!#(B |
| 1837 | +Windows $B$N?M$O(B \"nmz-mew-summary-fixer\" $B$N$h$&$K3HD%;R$rL5$/$7$?J}$,9,$;$+$b!#(B") |
| 1838 | + |
| 1839 | +(defvar mew-nmz-prog-fixer-args |
| 1840 | + (if (memq system-type '(OS/2 emx windows-nt)) |
| 1841 | + '("--windows-drive") '()) |
| 1842 | + "*nmz-mew-summary-fixer.pl $B$KM?$($k(B option$B!#(B") |
| 1843 | + |
| 1844 | +;; internal variable |
| 1845 | +(defvar mew-nmz-fixer-process nil) |
| 1846 | +(make-variable-buffer-local 'mew-nmz-fixer-process) |
| 1847 | + |
| 1848 | +;; function |
| 1849 | +(defun mew-nmz-fixer-exec (&optional arg) |
| 1850 | + "Sort/Pack $B$N8e$G(B \"mew-nmz-summary-fixer\" $B$r5/F0$9$k!#(B |
| 1851 | +\"Another fixer running.\" $B$H$$$o$l$F:$$C$?$H$-$O!"(B'\\[universal-argument]' $BIU$-$G8F$S$^$7$g$&!#(B" |
| 1852 | + (interactive "P") |
| 1853 | + (mew-summary-only |
| 1854 | + (let* ((interactive-p (interactive-p)) |
| 1855 | + (fld (if interactive-p |
| 1856 | + (mew-input-folder (mew-sinfo-get-case) |
| 1857 | + (mew-summary-folder-name)) |
| 1858 | + (mew-summary-folder-name))) |
| 1859 | + (fixer (if (fboundp 'mew-which-exec) |
| 1860 | + (mew-which-exec mew-nmz-prog-fixer) |
| 1861 | + (mew-which mew-nmz-prog-fixer exec-path))) |
| 1862 | + (args mew-nmz-prog-fixer-args) |
| 1863 | + nmzdir) |
| 1864 | + (if arg |
| 1865 | + (progn |
| 1866 | + (setq mew-nmz-fixer-process nil) |
| 1867 | + (and interactive-p |
| 1868 | + (message "Set %s to free" mew-nmz-prog-fixer))) |
| 1869 | + (if (not (and fld fixer)) |
| 1870 | + (and interactive-p |
| 1871 | + (message "Cannot exec %s" mew-nmz-prog-fixer)) |
| 1872 | + (setq nmzdir (mew-nmz-expand-folder fld)) |
| 1873 | + (if mew-nmz-fixer-process |
| 1874 | + (message "Another fixer running") |
| 1875 | + (if (and |
| 1876 | + nmzdir |
| 1877 | + (file-exists-p nmzdir) |
| 1878 | + (file-directory-p nmzdir) |
| 1879 | + (file-exists-p (expand-file-name "NMZ.i" nmzdir)) |
| 1880 | + (file-exists-p (expand-file-name "NMZ.field.message-id" nmzdir)) |
| 1881 | + (file-exists-p (expand-file-name "NMZ.field.size" nmzdir)) |
| 1882 | + (file-exists-p (expand-file-name "NMZ.field.date" nmzdir)) |
| 1883 | + (not (file-name-all-completions "NMZ.lock" nmzdir))) |
| 1884 | + (progn |
| 1885 | + (and interactive-p |
| 1886 | + (message "Exec %s (%s)..." mew-nmz-prog-fixer fld)) |
| 1887 | + (mew-nmz-timestamp-new fld) |
| 1888 | + (setq mew-nmz-fixer-process |
| 1889 | + (apply (function start-process) |
| 1890 | + "nmz-fixer" (current-buffer) fixer |
| 1891 | + (append args |
| 1892 | + (list (mew-expand-folder fld) nmzdir)))) |
| 1893 | + (set-process-sentinel mew-nmz-fixer-process 'mew-nmz-fixer-sentinel)) |
| 1894 | + (and interactive-p |
| 1895 | + (message "Cannot exec %s at %s" mew-nmz-prog-fixer nmzdir))))))))) |
| 1896 | + |
| 1897 | +(defun mew-nmz-fixer-sentinel (process event) |
| 1898 | + (save-excursion |
| 1899 | + (when (and (get-buffer (process-buffer process)) |
| 1900 | + (buffer-live-p (process-buffer process))) |
| 1901 | + (set-buffer (process-buffer process)) |
| 1902 | + (setq mew-nmz-fixer-process nil) |
| 1903 | + (mew-nmz-timestamp-rename (buffer-name)) |
| 1904 | + (message "Exec %s (%s)...done" |
| 1905 | + mew-nmz-prog-fixer (buffer-name))))) |
| 1906 | + |
| 1907 | +(provide 'mew-nmz-fixer) |
| 1908 | + |
| 1909 | +;;; Copyright Notice: |
| 1910 | + |
| 1911 | +;; Copyright (C) 2001 Mew developing team. |
| 1912 | +;; All rights reserved. |
| 1913 | + |
| 1914 | +;; Redistribution and use in source and binary forms, with or without |
| 1915 | +;; modification, are permitted provided that the following conditions |
| 1916 | +;; are met: |
| 1917 | +;; |
| 1918 | +;; 1. Redistributions of source code must retain the above copyright |
| 1919 | +;; notice, this list of conditions and the following disclaimer. |
| 1920 | +;; 2. Redistributions in binary form must reproduce the above copyright |
| 1921 | +;; notice, this list of conditions and the following disclaimer in the |
| 1922 | +;; documentation and/or other materials provided with the distribution. |
| 1923 | +;; 3. Neither the name of the team nor the names of its contributors |
| 1924 | +;; may be used to endorse or promote products derived from this software |
| 1925 | +;; without specific prior written permission. |
| 1926 | +;; |
| 1927 | +;; THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS'' AND |
| 1928 | +;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 1929 | +;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 1930 | +;; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TEAM OR CONTRIBUTORS BE |
| 1931 | +;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 1932 | +;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 1933 | +;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 1934 | +;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 1935 | +;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 1936 | +;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 1937 | +;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 1938 | + |
| 1939 | +;;; mew-nmz-fixer.el ends here |
| 1940 | diff -urN mew.orig/contrib/mew-nmz.el mew/contrib/mew-nmz.el |
| 1941 | --- mew.orig/contrib/mew-nmz.el 1970-01-01 09:00:00.000000000 +0900 |
| 1942 | +++ mew/contrib/mew-nmz.el 2011-06-20 01:46:10.000000000 +0900 |
| 1943 | @@ -0,0 +1,1686 @@ |
| 1944 | +;; -*- Mode: Emacs-Lisp -*- |
| 1945 | +;; |
| 1946 | +;; mew-nmz.el --- Namazu interfaces for Mew |
| 1947 | +;; |
| 1948 | +;; Author: Hideyuki SHIRAI |
| 1949 | +;; Created: Dec 24, 2004 |
| 1950 | +;; |
| 1951 | +;; Put your ~/.mew.el |
| 1952 | +;; (require 'mew-nmz) |
| 1953 | +;; (setq mew-search-method 'namazu) |
| 1954 | +;; |
| 1955 | + |
| 1956 | +(require 'mew) |
| 1957 | + |
| 1958 | +(eval-when-compile |
| 1959 | + (condition-case nil |
| 1960 | + (require 'w3m-namazu) |
| 1961 | + (error nil))) |
| 1962 | + |
| 1963 | +;; Variables |
| 1964 | +(defconst mew-nmz-version "2010-06-08") |
| 1965 | + |
| 1966 | +(defgroup mew-nmz nil |
| 1967 | + "Namazu support with Mew." |
| 1968 | + :group 'mew) |
| 1969 | + |
| 1970 | +(defcustom mew-nmz-index-path "~/Namazu" |
| 1971 | + "*Namazu index top directory." |
| 1972 | + :group 'mew-nmz |
| 1973 | + :type 'directory) |
| 1974 | + |
| 1975 | +(defcustom mew-nmz-index-mail "Mail" |
| 1976 | + "*Namazu index mail directory name." |
| 1977 | + :group 'mew-nmz |
| 1978 | + :type 'string) |
| 1979 | + |
| 1980 | +(defcustom mew-nmz-setup-hook nil |
| 1981 | + "*Hook called on mew-nmz-setup." |
| 1982 | + :group 'mew-nmz |
| 1983 | + :type 'hook) |
| 1984 | + |
| 1985 | +(defcustom mew-nmz-prog "namazu" |
| 1986 | + "*Namazu program name." |
| 1987 | + :group 'mew-nmz |
| 1988 | + :type 'string) |
| 1989 | + |
| 1990 | +(defcustom mew-nmz-prog-args nil |
| 1991 | + "*Namazu's arguments." |
| 1992 | + :group 'mew-nmz |
| 1993 | + :type '(repeat string)) |
| 1994 | + |
| 1995 | +(defcustom mew-nmz-prog-mknmz "mknmz" |
| 1996 | + "*Namazu make index program." |
| 1997 | + :group 'mew-nmz |
| 1998 | + :type 'string) |
| 1999 | + |
| 2000 | +(defcustom mew-nmz-prog-mknmz-args '("--decode-base64") |
| 2001 | + "*Mknmz's argument, in addition to \"--no-encode-uri\", \"--mailnews\"." |
| 2002 | + :group 'mew-nmz |
| 2003 | + :type '(repeat string)) |
| 2004 | + |
| 2005 | +(defcustom mew-nmz-prog-mknmz-include "~/Namazu/mknmz-inc.pl" |
| 2006 | + "*Include file for mknmz." |
| 2007 | + :group 'mew-nmz |
| 2008 | + :type 'file) |
| 2009 | + |
| 2010 | +(defcustom mew-nmz-mknmz-skip-folders-regexp |
| 2011 | + (mapcar 'regexp-quote |
| 2012 | + (delq nil |
| 2013 | + `(,mew-draft-folder ,mew-trash-folder ,mew-queue-folder ,mew-attach-folder |
| 2014 | + ,mew-imap-queue-folder ,mew-imap-trash-folder ,mew-postq-folder |
| 2015 | + ,@mew-trash-folder-list ,@mew-imap-trash-folder-list |
| 2016 | + "+schedule"))) |
| 2017 | + "*Folders regexp to skip the index creating." |
| 2018 | + :group 'mew-nmz |
| 2019 | + :type '(repeat regexp)) |
| 2020 | + |
| 2021 | +(defcustom mew-nmz-mknmz-use-mode-line t |
| 2022 | + "*Display indicator of namazu in mode line." |
| 2023 | + :group 'mew-nmz |
| 2024 | + :type 'boolean) |
| 2025 | + |
| 2026 | +(defcustom mew-nmz-line-id '("Mew(nmz): %7b") |
| 2027 | + "*A value of mode-line-buffer-identification for Mew summary mode, when mknmzing." |
| 2028 | + :group 'mew-nmz |
| 2029 | + :type '(list string)) |
| 2030 | + |
| 2031 | +(defcustom mew-nmz-mknmz-timer-interval 0.1 |
| 2032 | + "*Seconds of interval to execute next mknmz." |
| 2033 | + :group 'mew-nmz |
| 2034 | + :type 'number) |
| 2035 | + |
| 2036 | +(defcustom mew-nmz-pick-default-field nil |
| 2037 | + "*Default prefix string to be appeared when inputting a namazu pick pattern. |
| 2038 | +A good example is \"+from:\"." |
| 2039 | + :group 'mew-nmz |
| 2040 | + :type '(choice string (const nil))) |
| 2041 | + |
| 2042 | +(defcustom mew-nmz-pick-field-list |
| 2043 | + '("subject=" "from=" "to=" "newsgroups=" "date=" |
| 2044 | + "message-id=" "cc=" "in-reply-to=" "references=") |
| 2045 | + "*A list of key for namazu pick pattern." |
| 2046 | + :group 'mew-nmz |
| 2047 | + :type '(repeat string)) |
| 2048 | + |
| 2049 | +(defcustom mew-nmz-pick-gather-field-list |
| 2050 | + `((,mew-from: address "from=" "to=" "cc=") |
| 2051 | + (,mew-to: address "from=" "to=" "cc=") |
| 2052 | + (,mew-cc: address "from=" "to=" "cc=") |
| 2053 | + (,mew-message-id: msgid "message-id=" "in-reply-to=" "references=") |
| 2054 | + (,mew-in-reply-to: msgid "message-id=" "in-reply-to=" "references=") |
| 2055 | + (,mew-references: msgid "message-id=" "in-reply-to=" "references=")) |
| 2056 | + "*A list of completion keyword from message." |
| 2057 | + :group 'mew-nmz |
| 2058 | + :type '(repeat (list string |
| 2059 | + (choice (const address) (const msgid)) |
| 2060 | + string string string))) |
| 2061 | + |
| 2062 | +(defcustom mew-nmz-search-parent-folder `(,mew-inbox-folder) |
| 2063 | + "*Search folder for parent or child, " |
| 2064 | + :group 'mew-nmz |
| 2065 | + :type '(repeat string)) |
| 2066 | + |
| 2067 | +(defcustom mew-nmz-db-max 64 |
| 2068 | + "*Namazu max index. |
| 2069 | +This value MUST be less then equal `INDEX_MAX' of libnamazu.h." |
| 2070 | + :group 'mew-nmz |
| 2071 | + :type 'integer) |
| 2072 | + |
| 2073 | +(defcustom mew-nmz-query-max-length 256 |
| 2074 | + "*Namazu query string max length. |
| 2075 | + This value MUST be less then equal `QUERY_MAX' of libnamazu.h." |
| 2076 | + :group 'mew-nmz |
| 2077 | + :type 'integer) |
| 2078 | + |
| 2079 | +(defcustom mew-nmz-mark-pick mew-mark-review |
| 2080 | + "*Mark for Namazu pick." |
| 2081 | + :group 'mew-nmz |
| 2082 | + :type 'character) |
| 2083 | + |
| 2084 | +(defcustom mew-nmz-mark-unindexed mew-mark-review |
| 2085 | + "*Mark for type unindexed messages." |
| 2086 | + :group 'mew-nmz |
| 2087 | + :type 'character) |
| 2088 | + |
| 2089 | +(defcustom mew-ask-virtual-folder-name nil |
| 2090 | + "*If *non-nil*, ask a virtual folder name." |
| 2091 | + :group 'mew-summary |
| 2092 | + :type 'boolean) |
| 2093 | + |
| 2094 | +(defcustom mew-nmz-cache-file-prefix ".mew-nmz-" |
| 2095 | + "*Prefix of the cache filename. Expand with mew-conf-path when use it." |
| 2096 | + :group 'mew-nmz |
| 2097 | + :type 'string) |
| 2098 | + |
| 2099 | +(defcustom mew-nmz-mknmz-index-file ".mewmknmz" |
| 2100 | + "*File name of the input file of mewmknmz. Expand with mew-conf-path when use it." |
| 2101 | + :group 'mew-nmz |
| 2102 | + :type 'string) |
| 2103 | + |
| 2104 | +(defcustom mew-nmz-input-folders-asterisk t |
| 2105 | + "*Add \"*\" at the end of input folder name." |
| 2106 | + :group 'mew-nmz |
| 2107 | + :type 'boolean) |
| 2108 | + |
| 2109 | +(defcustom mew-nmz-prog-gcnmz "gcnmz" |
| 2110 | + "*Program name for the garbage collection." |
| 2111 | + :group 'mew-nmz |
| 2112 | + :type 'string) |
| 2113 | + |
| 2114 | +(defcustom mew-nmz-use-gcnmz-folders-regexp `(,(regexp-quote mew-inbox-folder)) |
| 2115 | + "*Folders regexp to execute gcnmz." |
| 2116 | + :group 'mew-nmz |
| 2117 | + :type '(repeat regexp)) |
| 2118 | + |
| 2119 | +(defcustom mew-nmz-gcnmz-line-id '("Mew(gcn): %7b") |
| 2120 | + "*A value of mode-line-buffer-identification for Mew summary mode, when gcnmzing." |
| 2121 | + :group 'mew-nmz |
| 2122 | + :type '(list string)) |
| 2123 | + |
| 2124 | +(defcustom mew-nmz-prog-rfnmz "rfnmz" |
| 2125 | + "*Program name for the re-index." |
| 2126 | + :group 'mew-nmz |
| 2127 | + :type 'string) |
| 2128 | + |
| 2129 | +(defcustom mew-nmz-mknmz-index-file-coding-system |
| 2130 | + (when (boundp 'default-file-name-coding-system) |
| 2131 | + default-file-name-coding-system) |
| 2132 | + "*Coding system of index-file." |
| 2133 | + :group 'mew-nmz |
| 2134 | + :type '(coding-system :size 0)) |
| 2135 | + |
| 2136 | +;; internal variable, don't modify. |
| 2137 | +(defvar mew-nmz-gather-header-list nil) |
| 2138 | +(defvar mew-nmz-indexed-folders nil) |
| 2139 | + |
| 2140 | +(defvar mew-nmz-input-folder-hist nil) |
| 2141 | + |
| 2142 | +(defvar mew-nmz-mknmz-process nil) |
| 2143 | +(defvar mew-nmz-mknmz-process-folder nil) |
| 2144 | +(defvar mew-nmz-mknmz-process-file nil) |
| 2145 | + |
| 2146 | +(make-variable-buffer-local 'mew-nmz-mknmz-process) |
| 2147 | +(make-variable-buffer-local 'mew-nmz-mknmz-process-folder) |
| 2148 | +(make-variable-buffer-local 'mew-nmz-mknmz-process-file) |
| 2149 | + |
| 2150 | +(defconst mew-nmz-namazu-index-alias "_mew-namazu" |
| 2151 | + "*Alias name for mew-nmz-namazu.") |
| 2152 | +(defvar mew-nmz-namazu-content-type "message/mew") |
| 2153 | +(defvar mew-nmz-namazu-pattern nil) |
| 2154 | +(defvar mew-nmz-namazu-miss-folders nil) |
| 2155 | + |
| 2156 | +(defvar mew-nmz-setup-p nil) |
| 2157 | +(defvar mew-nmz-imap-case-alist nil) |
| 2158 | +(defvar mew-nmz-nntp-case-alist nil) |
| 2159 | +(defvar mew-nmz-pop-case-alist nil) |
| 2160 | +(defvar mew-nmz-fld-index-alist nil) |
| 2161 | +(defvar mew-nmz-url-fld-alist nil) |
| 2162 | +(defvar mew-nmz-mknmz-all-folders nil) |
| 2163 | +(defvar mew-nmz-mknmz-continue-timer nil) |
| 2164 | + |
| 2165 | +(defvar mew-nmz-mknmz-lang-alist |
| 2166 | + '(("Japanese" "ja"))) |
| 2167 | + |
| 2168 | +(defvar mew-nmz-cs-index (cond |
| 2169 | + ((mew-coding-system-p 'euc-japan-unix) |
| 2170 | + 'euc-japan-unix) |
| 2171 | + ((mew-coding-system-p 'euc-jp-unix) |
| 2172 | + 'euc-jp-unix) |
| 2173 | + (t mew-cs-text-for-write)) |
| 2174 | + "*Coding system to write 'NMZ.field.uri'.") |
| 2175 | + |
| 2176 | +(defconst mew-nmz-result-regex |
| 2177 | + (concat "^\\(.*\\)" (regexp-quote mew-path-separator) "\\([0-9]+\\)")) |
| 2178 | + |
| 2179 | +(defconst mew-nmz-use-drive-letter |
| 2180 | + (memq system-type '(OS/2 emx windows-nt cygwin))) |
| 2181 | + |
| 2182 | +;; Set up |
| 2183 | +(defvar mew-nmz-search-method `(namazu "Namazu" ,mew-nmz-prog |
| 2184 | + mew-nmz-search |
| 2185 | + mew-nmz-search-virtual |
| 2186 | + mew-nmz-mknmz |
| 2187 | + mew-nmz-mknmz-all-folders |
| 2188 | + mew-nmz-pick-canonicalize-pattern)) |
| 2189 | + |
| 2190 | +(eval-after-load "mew-search" |
| 2191 | + `(setq mew-search-switch |
| 2192 | + (cons mew-nmz-search-method mew-search-switch))) |
| 2193 | + |
| 2194 | +;; (define-key mew-summary-mode-map "k" (make-sparse-keymap)) |
| 2195 | +;; (define-key mew-summary-mode-map "kc" 'mew-summary-search-change-method) |
| 2196 | +;; (define-key mew-summary-mode-map "k?" 'mew-summary-search) |
| 2197 | +;; (define-key mew-summary-mode-map "k/" 'mew-summary-selection-by-search) |
| 2198 | +;; (define-key mew-summary-mode-map "km" 'mew-summary-make-index-folder) |
| 2199 | +;; (define-key mew-summary-mode-map "kM" 'mew-summary-make-index-all) |
| 2200 | + |
| 2201 | +(add-hook 'mew-summary-mode-hook |
| 2202 | + (lambda () |
| 2203 | + (define-key mew-summary-mode-map "kg" 'mew-nmz-gcnmz) |
| 2204 | + (define-key mew-summary-mode-map "ks" 'mew-nmz-mknmz-save-mewmknmz) |
| 2205 | + (define-key mew-summary-mode-map "kK" 'mew-nmz-mknmz-kill-process) |
| 2206 | + (define-key mew-summary-mode-map "ku" 'mew-nmz-mark-unindexed) |
| 2207 | + (define-key mew-summary-mode-map "k^" 'mew-nmz-search-parent) |
| 2208 | + (define-key mew-summary-mode-map "kp" 'mew-nmz-search-parent) |
| 2209 | + (define-key mew-summary-mode-map "kn" 'mew-nmz-search-child) |
| 2210 | + (define-key mew-summary-mode-map "kN" 'mew-nmz-namazu) |
| 2211 | + (define-key mew-summary-mode-map "kj" 'mew-nmz-jump-message))) |
| 2212 | + |
| 2213 | +(add-hook 'mew-message-mode-hook |
| 2214 | + (lambda () |
| 2215 | + (define-key mew-message-mode-map "k" (make-sparse-keymap)) |
| 2216 | + (define-key mew-message-mode-map "kp" 'mew-nmz-search-msgid-at-point) |
| 2217 | + (define-key mew-message-mode-map "kr" 'mew-nmz-search-msgid-region))) |
| 2218 | + |
| 2219 | +(defun mew-nmz-pick-field-list () |
| 2220 | + (let ((lst (append mew-pick-field-list |
| 2221 | + mew-nmz-pick-field-list |
| 2222 | + (mew-nmz-pick-pattern-gather-header)))) |
| 2223 | + (mew-uniq-list lst))) |
| 2224 | + |
| 2225 | +(defadvice mew-summary-search (around mew-nmz activate compile) |
| 2226 | + "Use mew-nmz gather-header." |
| 2227 | + (if (eq mew-search-method 'namazu) |
| 2228 | + (let ((mew-pick-field-list (mew-nmz-pick-field-list))) |
| 2229 | + ad-do-it) |
| 2230 | + ad-do-it)) |
| 2231 | + |
| 2232 | +(defadvice mew-summary-selection-by-search (around mew-nmz activate compile) |
| 2233 | + "Use mew-nmz gather-header." |
| 2234 | + (if (eq mew-search-method 'namazu) |
| 2235 | + (let ((mew-pick-field-list (mew-nmz-pick-field-list))) |
| 2236 | + ad-do-it) |
| 2237 | + ad-do-it)) |
| 2238 | + |
| 2239 | +(add-hook 'mew-summary-rename-folder-hook 'mew-nmz-folder-index-rename) |
| 2240 | +(add-hook 'mew-summary-delete-folder-hook 'mew-nmz-folder-index-delete) |
| 2241 | +(add-hook 'mew-status-update-hook 'mew-nmz-status-update) |
| 2242 | +(add-hook 'mew-quit-hook 'mew-nmz-cleanup) |
| 2243 | + |
| 2244 | +(when (and (featurep 'mw32script) |
| 2245 | + (fboundp 'define-process-argument-editing)) |
| 2246 | + ;; Argument setting for mknmz.bat, gcnmz.bat, rfnmz.bat |
| 2247 | + (let ((progs '("mknmz" "gcnmz" "rfnmz")) |
| 2248 | + prog) |
| 2249 | + (while progs |
| 2250 | + (setq prog (mew-which-exec (car progs))) |
| 2251 | + (setq progs (cdr progs)) |
| 2252 | + (when (and prog (string-match "\\.bat$" prog)) |
| 2253 | + (setq prog (regexp-quote prog)) |
| 2254 | + ;; (general-process-argument-editing-function |
| 2255 | + ;; ARGUMENT QUOTING ARGV0ISP &optional EP H2SP QP S2ISP) |
| 2256 | + (define-process-argument-editing |
| 2257 | + prog |
| 2258 | + (lambda (x) (general-process-argument-editing-function x nil nil)) |
| 2259 | + 'first))))) |
| 2260 | + |
| 2261 | +;; macro |
| 2262 | +(defmacro mew-nmz-imap-directory-file-name (fld case) |
| 2263 | + `(condition-case nil |
| 2264 | + (mew-imap-directory-file-name ,fld ,case) |
| 2265 | + (error ,fld))) |
| 2266 | + |
| 2267 | +(defmacro mew-nmz-cache-file-name (part) |
| 2268 | + `(expand-file-name (concat mew-nmz-cache-file-prefix |
| 2269 | + (symbol-name ,part) |
| 2270 | + "-alist") |
| 2271 | + mew-conf-path)) |
| 2272 | + |
| 2273 | +(defmacro mew-nmz-cache-alist-name (part) |
| 2274 | + `(intern (concat "mew-nmz-" (symbol-name ,part) "-alist"))) |
| 2275 | + |
| 2276 | +(defsubst mew-nmz-expand-folder (case:folder) |
| 2277 | + "Convert case:folder to the directory name of namazu's index." |
| 2278 | + (let* ((fld (mew-case:folder-folder case:folder)) |
| 2279 | + (imapp (mew-folder-imapp fld)) |
| 2280 | + (mew-mail-path (concat (file-name-as-directory mew-nmz-index-path) |
| 2281 | + mew-nmz-index-mail)) |
| 2282 | + (nmzdir (directory-file-name (mew-expand-folder case:folder)))) |
| 2283 | + (if (not imapp) |
| 2284 | + nmzdir |
| 2285 | + (while (string-match "[][]" nmzdir) |
| 2286 | + (setq nmzdir (concat (substring nmzdir 0 (match-beginning 0)) |
| 2287 | + "%%" |
| 2288 | + (substring nmzdir (match-end 0))))) |
| 2289 | + nmzdir))) |
| 2290 | + |
| 2291 | +(defsubst mew-nmz-case-folder-normalize (case:folder) |
| 2292 | + (let ((case (mew-case:folder-case case:folder)) |
| 2293 | + (fld (mew-case:folder-folder case:folder)) |
| 2294 | + (newcase "")) |
| 2295 | + (setq fld (directory-file-name fld)) |
| 2296 | + (when (mew-folder-imapp fld) |
| 2297 | + (setq fld (mew-nmz-imap-directory-file-name fld case))) |
| 2298 | + (cond |
| 2299 | + ((or (string= fld "") |
| 2300 | + (string= fld "*") |
| 2301 | + (mew-folder-imapp fld)) |
| 2302 | + (setq newcase (or (cdr (assoc case mew-nmz-imap-case-alist)) ""))) |
| 2303 | + ((mew-folder-popp fld) |
| 2304 | + (setq newcase (or (cdr (assoc case mew-nmz-pop-case-alist)) ""))) |
| 2305 | + ((mew-folder-nntpp fld) |
| 2306 | + (setq newcase (or (cdr (assoc case mew-nmz-nntp-case-alist)) "")))) |
| 2307 | + (if (string= newcase "") |
| 2308 | + fld |
| 2309 | + (concat newcase ":" fld)))) |
| 2310 | + |
| 2311 | +(defsubst mew-nmz-case-normalize (case:folder) |
| 2312 | + (let ((case (mew-case:folder-case case:folder)) |
| 2313 | + (fld (mew-case:folder-folder case:folder)) |
| 2314 | + (newcase "")) |
| 2315 | + (cond |
| 2316 | + ((or (string= fld "") |
| 2317 | + (string= fld "*") |
| 2318 | + (mew-folder-imapp fld)) |
| 2319 | + (setq newcase (or (cdr (assoc case mew-nmz-imap-case-alist)) ""))) |
| 2320 | + ((mew-folder-popp fld) |
| 2321 | + (setq newcase (or (cdr (assoc case mew-nmz-pop-case-alist)) ""))) |
| 2322 | + ((mew-folder-nntpp fld) |
| 2323 | + (setq newcase (or (cdr (assoc case mew-nmz-nntp-case-alist)) "")))) |
| 2324 | + newcase)) |
| 2325 | + |
| 2326 | +(defsubst mew-nmz-folder-to-nmzdir (folder) |
| 2327 | + (mew-nmz-setup) |
| 2328 | + (cdr (assoc (directory-file-name folder) mew-nmz-fld-index-alist))) |
| 2329 | + |
| 2330 | +(defsubst mew-nmz-url-to-folder (url) |
| 2331 | + (mew-nmz-setup) |
| 2332 | + (when (and mew-nmz-use-drive-letter |
| 2333 | + (string-match "^/\\([a-zA-Z]\\)|\\(/.*\\)" url)) |
| 2334 | + (setq url (concat |
| 2335 | + (substring url (match-beginning 1) (match-end 1)) |
| 2336 | + ":" |
| 2337 | + (substring url (match-beginning 2) (match-end 2))))) |
| 2338 | + (cdr (assoc (expand-file-name url) mew-nmz-url-fld-alist))) |
| 2339 | + |
| 2340 | +(defsubst mew-nmz-indexed-folder-p (fld) |
| 2341 | + (let ((nmzdir (mew-nmz-expand-folder fld))) |
| 2342 | + (and nmzdir |
| 2343 | + (file-directory-p nmzdir) |
| 2344 | + (file-exists-p (expand-file-name "NMZ.i" nmzdir))))) |
| 2345 | + |
| 2346 | +;; Mew interface |
| 2347 | +(defun mew-nmz-search (pattern folder &rest args) |
| 2348 | + (mew-nmz-multi-pick |
| 2349 | + (list (mew-nmz-expand-folder folder)) pattern nil 'single)) |
| 2350 | + |
| 2351 | +(defun mew-nmz-search-virtual (pattern flds &rest args) |
| 2352 | + (mew-nmz-setup) |
| 2353 | + (let* ((nmzdirs (mew-nmz-flds-to-indexs (or flds (list "*:*")))) |
| 2354 | + (fldmsgs (mew-nmz-multi-pick nmzdirs pattern nil)) |
| 2355 | + (file (mew-make-temp-name)) |
| 2356 | + (rttl 0) |
| 2357 | + fld) |
| 2358 | + (with-temp-buffer |
| 2359 | + (dolist (fldmsg fldmsgs) |
| 2360 | + (setq fld (car fldmsg)) |
| 2361 | + (unless (mew-folder-localp fld) |
| 2362 | + (setq fld (mew-path-to-folder (mew-expand-folder fld)))) |
| 2363 | + (insert (format "CD:%s\n" fld)) |
| 2364 | + (dolist (msg (cdr fldmsg)) |
| 2365 | + (insert msg "\n") |
| 2366 | + (setq rttl (1+ rttl)))) |
| 2367 | + (mew-frwlet |
| 2368 | + mew-cs-text-for-read mew-cs-text-for-write |
| 2369 | + (write-region (point-min) (point-max) file nil 'no-msg))) |
| 2370 | + (list file rttl))) |
| 2371 | + |
| 2372 | +;; codes |
| 2373 | +(defun mew-nmz-jump-message () |
| 2374 | + "Jump to physical folder and message from virtual folder |
| 2375 | +or jump to virtual folder from physical folder." |
| 2376 | + (interactive) |
| 2377 | + (let ((disp (mew-sinfo-get-disp-msg)) |
| 2378 | + fld msg) |
| 2379 | + (cond |
| 2380 | + ((mew-thread-p) |
| 2381 | + (mew-summary-goto-message) |
| 2382 | + (setq fld (or (mew-vinfo-get-original-folder) |
| 2383 | + (mew-vinfo-get-physical-folder))) |
| 2384 | + (setq msg (mew-summary-message-number))) |
| 2385 | + ((mew-virtual-p) |
| 2386 | + (mew-summary-goto-message) |
| 2387 | + (setq fld (mew-summary-folder-name)) |
| 2388 | + (setq msg (mew-summary-message-number))) |
| 2389 | + (t |
| 2390 | + (setq fld (mew-summary-folder-name)) |
| 2391 | + (setq msg (mew-summary-message-number)) |
| 2392 | + (save-excursion |
| 2393 | + (let ((regex (format "\r %s %s[^0-9]" (regexp-quote fld) msg))) |
| 2394 | + (setq fld (catch 'detect |
| 2395 | + (dolist (buf (delq (current-buffer) (buffer-list))) |
| 2396 | + (set-buffer buf) |
| 2397 | + (save-excursion |
| 2398 | + (when (and (mew-virtual-p) |
| 2399 | + (or (re-search-forward regex nil t) |
| 2400 | + (re-search-backward regex nil t))) |
| 2401 | + (throw 'detect (buffer-name buf))))) |
| 2402 | + nil)))))) |
| 2403 | + (if (not fld) |
| 2404 | + (message "Nothing to do") |
| 2405 | + (mew-nmz-goto-folder-msg fld msg nil disp) |
| 2406 | + (message "Jump to %s/%s" fld msg)))) |
| 2407 | + |
| 2408 | +(defun mew-nmz-mknmz-lang-arg () |
| 2409 | + (when (boundp 'current-language-environment) |
| 2410 | + (let* ((env current-language-environment) |
| 2411 | + (alist mew-nmz-mknmz-lang-alist) |
| 2412 | + (lang (nth 1 (assoc env alist)))) |
| 2413 | + (if lang (format "--indexing-lang=%s" lang))))) |
| 2414 | + |
| 2415 | +;; "Make Index" functions. |
| 2416 | +(defun mew-nmz-mknmz (&optional fld all disp) |
| 2417 | + "Make namazu index for mew-nmz. |
| 2418 | +If executed with '\\[universal-argument]', make indices without the check of timestamp files. |
| 2419 | +If executed with '\\[universal-argument] 0', remove indices before make index." |
| 2420 | + (interactive |
| 2421 | + (list (directory-file-name |
| 2422 | + (mew-input-folder (mew-sinfo-get-case) |
| 2423 | + (or (mew-sinfo-get-folder) mew-inbox-folder))) |
| 2424 | + nil)) |
| 2425 | + (save-excursion |
| 2426 | + (let ((msgenb (or (interactive-p) |
| 2427 | + (eq this-command 'mew-summary-make-index-folder) |
| 2428 | + disp)) |
| 2429 | + (force (and current-prefix-arg |
| 2430 | + (not (eq current-prefix-arg 0)))) |
| 2431 | + (remove (eq current-prefix-arg 0)) |
| 2432 | + (flddir (mew-expand-folder fld)) |
| 2433 | + (nmzdir (mew-nmz-expand-folder fld)) |
| 2434 | + (bufname (format "%s*Mew* mknmz*%s" |
| 2435 | + (if (memq mew-debug '(namazu t)) "" " ") |
| 2436 | + fld)) |
| 2437 | + (args mew-nmz-prog-mknmz-args) |
| 2438 | + (procname (concat mew-nmz-prog-mknmz "-" fld)) |
| 2439 | + (procname2 (concat mew-nmz-prog-gcnmz "-" fld)) |
| 2440 | + (incfile (and mew-nmz-prog-mknmz-include |
| 2441 | + (expand-file-name mew-nmz-prog-mknmz-include))) |
| 2442 | + (tmpfile (mew-make-temp-name)) |
| 2443 | + flist continue) |
| 2444 | + (unless fld |
| 2445 | + (setq fld (directory-file-name |
| 2446 | + (mew-input-folder (mew-sinfo-get-case) (mew-sinfo-get-folder))))) |
| 2447 | + (cond |
| 2448 | + ((not (mew-which-exec mew-nmz-prog-mknmz)) |
| 2449 | + (message "Please install mknmz")) |
| 2450 | + ((or (mew-folder-virtualp fld) (mew-nmz-skip-folder-p fld)) |
| 2451 | + (and msgenb (message "Cannot make namazu index in %s" fld)) |
| 2452 | + (setq continue t)) |
| 2453 | + ((or (get-process procname) (get-process procname2)) |
| 2454 | + (and msgenb (message "Detect running mknmz/gcnmz process in %s" fld)) |
| 2455 | + (setq continue t)) |
| 2456 | + ((and (not remove) (not force) (mew-nmz-index-new-p fld)) |
| 2457 | + (and msgenb (message "%s has a newer namazu index" fld)) |
| 2458 | + (setq continue t)) |
| 2459 | + ((and (not remove) (file-exists-p (expand-file-name "NMZ.lock2" nmzdir))) |
| 2460 | + (message "Something error in %s's index" fld) |
| 2461 | + (setq continue t)) |
| 2462 | + ((not (setq flist (mew-dir-messages (file-chase-links flddir) |
| 2463 | + nil 'full))) |
| 2464 | + (and msgenb (message "%s has no message" fld)) |
| 2465 | + (mew-nmz-index-delete nmzdir) |
| 2466 | + (setq continue t)) |
| 2467 | + ((and flddir nmzdir (file-directory-p flddir)) |
| 2468 | + (with-temp-buffer |
| 2469 | + (dolist (file flist) |
| 2470 | + (insert file "\n")) |
| 2471 | + (mew-frwlet |
| 2472 | + mew-cs-autoconv mew-cs-text-for-write |
| 2473 | + (write-region (point-min) (point-max) tmpfile nil 'nomsg))) |
| 2474 | + (setq args (delq nil |
| 2475 | + (append args |
| 2476 | + (list "--no-encode-uri" |
| 2477 | + ;; "--mailnews" |
| 2478 | + (mew-nmz-mknmz-lang-arg) |
| 2479 | + (when (and incfile (file-exists-p incfile)) |
| 2480 | + (format "--include=%s" incfile)) |
| 2481 | + (format "--target-list=%s" tmpfile) |
| 2482 | + ;; (format "--exclude=%s" |
| 2483 | + ;; (expand-file-name ".+/" flddir)) |
| 2484 | + (format "--output-dir=%s" nmzdir))))) |
| 2485 | + ;; flddir)))) |
| 2486 | + (unless (file-directory-p nmzdir) |
| 2487 | + (mew-make-directory nmzdir)) |
| 2488 | + (when remove |
| 2489 | + (mew-nmz-index-delete nmzdir)) |
| 2490 | + (set-buffer (get-buffer-create bufname)) |
| 2491 | + (erase-buffer) |
| 2492 | + ;; folder set |
| 2493 | + (and msgenb (message "Namazu indexing for %s..." fld)) |
| 2494 | + (insert (format "mew-mknmz-prog: %s\nmew-mknmz-args: %s\n" |
| 2495 | + (mew-which-exec mew-nmz-prog-mknmz) |
| 2496 | + (mapconcat 'identity args " "))) |
| 2497 | + (mew-nmz-timestamp-new fld) |
| 2498 | + (mew-piolet |
| 2499 | + mew-cs-autoconv mew-cs-text-for-write |
| 2500 | + (setq mew-nmz-mknmz-process |
| 2501 | + (apply (function start-process) |
| 2502 | + procname (current-buffer) mew-nmz-prog-mknmz args))) |
| 2503 | + (setq mew-nmz-mknmz-process-folder fld) |
| 2504 | + (setq mew-nmz-mknmz-process-file tmpfile) |
| 2505 | + (set-process-sentinel mew-nmz-mknmz-process 'mew-nmz-mknmz-sentinel) |
| 2506 | + (when (and mew-nmz-mknmz-use-mode-line |
| 2507 | + fld (get-buffer fld) (buffer-name (get-buffer fld))) |
| 2508 | + (save-excursion |
| 2509 | + (set-buffer (get-buffer fld)) |
| 2510 | + (setq mode-line-buffer-identification mew-nmz-line-id) |
| 2511 | + (set-buffer-modified-p nil))))) |
| 2512 | + (when (and continue all mew-nmz-mknmz-all-folders) |
| 2513 | + (mew-nmz-mknmz-continue-with-timer))))) |
| 2514 | + |
| 2515 | +(defun mew-nmz-mknmz-continue-with-timer () |
| 2516 | + (unless mew-nmz-mknmz-continue-timer |
| 2517 | + (setq mew-nmz-mknmz-continue-timer |
| 2518 | + (run-at-time mew-nmz-mknmz-timer-interval nil 'mew-nmz-mknmz-continue)))) |
| 2519 | + |
| 2520 | +(defun mew-nmz-mknmz-continue () |
| 2521 | + (when mew-nmz-mknmz-continue-timer |
| 2522 | + (cancel-timer mew-nmz-mknmz-continue-timer) |
| 2523 | + (setq mew-nmz-mknmz-continue-timer nil)) |
| 2524 | + (setq mew-nmz-mknmz-all-folders (cdr mew-nmz-mknmz-all-folders)) |
| 2525 | + (if mew-nmz-mknmz-all-folders |
| 2526 | + (mew-nmz-mknmz (car mew-nmz-mknmz-all-folders) 'all) |
| 2527 | + (ding) |
| 2528 | + (message "All mknmz done"))) |
| 2529 | + |
| 2530 | +(defun mew-nmz-mknmz-sentinel (process event) |
| 2531 | + (save-excursion |
| 2532 | + (set-buffer (process-buffer process)) |
| 2533 | + (let* ((fld mew-nmz-mknmz-process-folder) |
| 2534 | + (nmzdir (mew-nmz-expand-folder fld)) |
| 2535 | + msg success) |
| 2536 | + (when (and (file-exists-p mew-nmz-mknmz-process-file) |
| 2537 | + (file-writable-p mew-nmz-mknmz-process-file)) |
| 2538 | + (delete-file mew-nmz-mknmz-process-file)) |
| 2539 | + (goto-char (point-min)) |
| 2540 | + (if (search-forward-regexp "^ERROR:.*$" nil t) |
| 2541 | + (progn |
| 2542 | + (setq msg (format "Mew mknmz (%s)...%s" fld (match-string 0))) |
| 2543 | + (condition-case nil |
| 2544 | + (progn |
| 2545 | + (mew-nmz-index-delete nmzdir 'tmpfiles) |
| 2546 | + (delete-file (expand-file-name "NMZ.lock2" nmzdir)) |
| 2547 | + (delete-file (expand-file-name "NMZ.stamp.new" nmzdir))) |
| 2548 | + (error nil))) |
| 2549 | + (setq success t) |
| 2550 | + (mew-nmz-timestamp-rename fld) |
| 2551 | + (setq msg (format "Namazu indexing %s...done" fld)) |
| 2552 | + (when mew-nmz-setup-p |
| 2553 | + (setq fld (mew-nmz-case-folder-normalize fld)) |
| 2554 | + (unless (mew-nmz-folder-to-nmzdir fld) |
| 2555 | + (setq mew-nmz-fld-index-alist |
| 2556 | + (cons (cons fld nmzdir) mew-nmz-fld-index-alist)) |
| 2557 | + (setq mew-nmz-url-fld-alist |
| 2558 | + (cons (cons (mew-expand-folder fld) fld) |
| 2559 | + mew-nmz-url-fld-alist)) |
| 2560 | + (mew-nmz-cache-save)))) |
| 2561 | + (setq mew-nmz-mknmz-process nil) |
| 2562 | + (setq mew-nmz-mknmz-process-folder nil) |
| 2563 | + (when (and mew-nmz-mknmz-use-mode-line |
| 2564 | + fld (get-buffer fld) (buffer-name (get-buffer fld))) |
| 2565 | + (save-excursion |
| 2566 | + (set-buffer (get-buffer fld)) |
| 2567 | + (setq mode-line-buffer-identification |
| 2568 | + (if (fboundp 'mew-mode-line-id) |
| 2569 | + (mew-mode-line-id) |
| 2570 | + mew-mode-line-id)) |
| 2571 | + (set-buffer-modified-p nil))) |
| 2572 | + (set-buffer-modified-p nil) |
| 2573 | + (unless (memq mew-debug '(namazu t)) |
| 2574 | + (kill-buffer (current-buffer))) |
| 2575 | + (message "%s" msg) |
| 2576 | + (when (and success (mew-nmz-gcnmz-folder-p fld)) |
| 2577 | + (mew-nmz-gcnmz fld nmzdir)) |
| 2578 | + (when mew-nmz-mknmz-all-folders |
| 2579 | + (mew-nmz-mknmz-continue-with-timer))))) |
| 2580 | + |
| 2581 | +(defun mew-nmz-gcnmz (&optional fld nmzdir) |
| 2582 | + "Garbage collection for mew-nmz." |
| 2583 | + (interactive |
| 2584 | + (list (directory-file-name |
| 2585 | + (mew-input-folder (mew-sinfo-get-case) |
| 2586 | + (or (mew-sinfo-get-folder) mew-inbox-folder))) |
| 2587 | + nil)) |
| 2588 | + (unless nmzdir |
| 2589 | + (setq nmzdir (mew-nmz-expand-folder fld))) |
| 2590 | + (if (and (mew-which-exec mew-nmz-prog-gcnmz) |
| 2591 | + (file-directory-p nmzdir) |
| 2592 | + (file-exists-p (expand-file-name "NMZ.i" nmzdir))) |
| 2593 | + (let ((buf (get-buffer-create |
| 2594 | + (format "%s*Mew* gcnmz*%s" |
| 2595 | + (if (memq mew-debug '(namazu t)) "" " ") |
| 2596 | + fld))) |
| 2597 | + (procname (concat mew-nmz-prog-gcnmz "-" fld)) |
| 2598 | + (args `("--no-backup" ,nmzdir)) |
| 2599 | + process) |
| 2600 | + (save-excursion |
| 2601 | + (set-buffer buf) |
| 2602 | + (erase-buffer) |
| 2603 | + (setq mew-nmz-mknmz-process-folder fld) |
| 2604 | + (message "Mew gcnmz (%s)..." mew-nmz-mknmz-process-folder) |
| 2605 | + (insert (format "mew-gcnmz-prog: %s\nmew-gcnmz-args: %s\n" |
| 2606 | + (mew-which-exec mew-nmz-prog-gcnmz) |
| 2607 | + (mapconcat 'identity args " "))) |
| 2608 | + (setq process |
| 2609 | + (apply (function start-process) |
| 2610 | + procname (current-buffer) mew-nmz-prog-gcnmz args)) |
| 2611 | + (set-process-sentinel process 'mew-nmz-gcnmz-sentinel) |
| 2612 | + (when (and mew-nmz-mknmz-use-mode-line |
| 2613 | + fld (get-buffer fld) (buffer-name (get-buffer fld))) |
| 2614 | + (save-excursion |
| 2615 | + (set-buffer (get-buffer fld)) |
| 2616 | + (setq mode-line-buffer-identification mew-nmz-gcnmz-line-id) |
| 2617 | + (set-buffer-modified-p nil))))) |
| 2618 | + (when (interactive-p) |
| 2619 | + (message "gcnmz cannot run on %s" fld)))) |
| 2620 | + |
| 2621 | +(defun mew-nmz-gcnmz-sentinel (process event) |
| 2622 | + (when (buffer-name (process-buffer process)) |
| 2623 | + (set-buffer (process-buffer process)) |
| 2624 | + (let ((fld mew-nmz-mknmz-process-folder)) |
| 2625 | + (if (and fld event (stringp event) (string= event "kill")) |
| 2626 | + (progn |
| 2627 | + (message "Mew gcnmz (%s)...kill from user" fld) |
| 2628 | + (condition-case nil |
| 2629 | + (mew-nmz-index-delete (mew-nmz-expand-folder fld) 'tmpfiles) |
| 2630 | + (error nil))) |
| 2631 | + (message "Mew gcnmz (%s)...done" fld)) |
| 2632 | + (when (and mew-nmz-mknmz-use-mode-line |
| 2633 | + fld (get-buffer fld) (buffer-name (get-buffer fld))) |
| 2634 | + (save-excursion |
| 2635 | + (set-buffer (get-buffer fld)) |
| 2636 | + (setq mode-line-buffer-identification |
| 2637 | + (if (fboundp 'mew-mode-line-id) |
| 2638 | + (mew-mode-line-id) |
| 2639 | + mew-mode-line-id)) |
| 2640 | + (set-buffer-modified-p nil))) |
| 2641 | + (unless (memq mew-debug '(namazu t)) |
| 2642 | + (kill-buffer (current-buffer)))))) |
| 2643 | + |
| 2644 | +(defun mew-nmz-mknmz-kill-process () |
| 2645 | + "Kill the all processes of mknmz." |
| 2646 | + (interactive) |
| 2647 | + (when mew-nmz-mknmz-continue-timer |
| 2648 | + (cancel-timer mew-nmz-mknmz-continue-timer) |
| 2649 | + (setq mew-nmz-mknmz-continue-timer nil)) |
| 2650 | + (let ((proc-list (process-list)) |
| 2651 | + (regex1 (concat "^" mew-nmz-prog-mknmz "-")) |
| 2652 | + (regex2 (concat "^" mew-nmz-prog-gcnmz "-")) |
| 2653 | + buf kill) |
| 2654 | + (dolist (process proc-list) |
| 2655 | + (cond |
| 2656 | + ((string-match regex1 (process-name process)) |
| 2657 | + ;; mknmz |
| 2658 | + (setq buf (process-buffer process)) |
| 2659 | + (when (buffer-name buf) |
| 2660 | + (save-excursion |
| 2661 | + (set-buffer buf) |
| 2662 | + (set-process-sentinel process 'ignore) |
| 2663 | + (goto-char (point-max)) |
| 2664 | + (insert "\nERROR: Kill from user.\n") |
| 2665 | + (kill-process process) |
| 2666 | + (mew-nmz-mknmz-sentinel process "kill") |
| 2667 | + (setq kill t)))) |
| 2668 | + ((string-match regex2 (process-name process)) |
| 2669 | + ;; gcnmz |
| 2670 | + (setq buf (process-buffer process)) |
| 2671 | + (when (buffer-name buf) |
| 2672 | + (set-process-sentinel process 'ignore) |
| 2673 | + (kill-process process) |
| 2674 | + (mew-nmz-gcnmz-sentinel process "kill") |
| 2675 | + (setq kill t))))) |
| 2676 | + (setq mew-nmz-mknmz-all-folders nil) |
| 2677 | + (when (interactive-p) |
| 2678 | + (if kill |
| 2679 | + (message "All process of mknmz killed") |
| 2680 | + (message "No process of mknmz"))))) |
| 2681 | + |
| 2682 | +(defun mew-nmz-mknmz-get-all-folders () |
| 2683 | + (let ((protos (delq mew-folder-virtual (copy-sequence mew-folder-prefixes))) |
| 2684 | + (allcases (or mew-config-cases '(""))) |
| 2685 | + flist cases donecases flds fld dir) |
| 2686 | + (message "mew-nmz getting all folders...") |
| 2687 | + (dolist (proto protos) |
| 2688 | + (setq flds nil) |
| 2689 | + (setq cases allcases) |
| 2690 | + (setq donecases nil) |
| 2691 | + (dolist (case cases) |
| 2692 | + (if (or (string= case mew-case-default) |
| 2693 | + (string= case "")) |
| 2694 | + (setq case (mew-nmz-case-normalize proto)) |
| 2695 | + (setq case (mew-nmz-case-normalize |
| 2696 | + (concat case ":" proto)))) |
| 2697 | + (unless (member case donecases) |
| 2698 | + (setq donecases (cons case donecases)) |
| 2699 | + (setq flds |
| 2700 | + (cond |
| 2701 | + ((mew-folder-imapp proto) |
| 2702 | + (mapcar (lambda (x) (car x)) |
| 2703 | + (mew-imap-folder-alist case))) |
| 2704 | + ((mew-folder-nntpp proto) |
| 2705 | + (mapcar (lambda (x) (car x)) |
| 2706 | + (mew-nntp-folder-alist case))) |
| 2707 | + ((mew-folder-popp proto) |
| 2708 | + (mapcar (lambda (x) (car x)) |
| 2709 | + (mew-pop-folder-alist))) |
| 2710 | + (t |
| 2711 | + (mapcar (lambda (x) (car x)) |
| 2712 | + (mew-local-folder-alist))))) |
| 2713 | + (setq case (if (string= case "") |
| 2714 | + "" |
| 2715 | + (concat case ":"))) |
| 2716 | + (dolist (fld flds) |
| 2717 | + (setq fld (concat case fld)) |
| 2718 | + (setq dir (mew-expand-folder fld)) |
| 2719 | + (when (and dir |
| 2720 | + (file-exists-p dir) |
| 2721 | + (file-directory-p dir) |
| 2722 | + (file-exists-p (expand-file-name mew-summary-touch-file dir))) |
| 2723 | + (setq flist (cons (directory-file-name fld) flist))))))) |
| 2724 | + (prog1 |
| 2725 | + (setq flist (nreverse flist)) |
| 2726 | + (with-temp-buffer |
| 2727 | + (dolist (fld flist) |
| 2728 | + (unless (mew-nmz-skip-folder-p fld) |
| 2729 | + (insert (format "%s\t%s\t%s\n" |
| 2730 | + fld |
| 2731 | + (mew-expand-folder fld) |
| 2732 | + (mew-nmz-expand-folder fld)))) |
| 2733 | + (setq flist (cdr flist))) |
| 2734 | + (mew-frwlet |
| 2735 | + mew-cs-text-for-read mew-nmz-mknmz-index-file-coding-system |
| 2736 | + (write-region (point-min) (point-max) |
| 2737 | + (expand-file-name mew-nmz-mknmz-index-file mew-conf-path) |
| 2738 | + nil 'nomsg))) |
| 2739 | + (message "mew-nmz getting all folders...done")))) |
| 2740 | + |
| 2741 | +(defun mew-nmz-mknmz-all-folders (&optional args) |
| 2742 | + "Make namazu index all folders." |
| 2743 | + (interactive "P") |
| 2744 | + (setq args (or args current-prefix-arg)) |
| 2745 | + (when (or (null mew-nmz-mknmz-all-folders) |
| 2746 | + (and mew-nmz-mknmz-all-folders |
| 2747 | + (prog1 |
| 2748 | + (y-or-n-p "Another mew-nmz-mknmz-all-folders() detect. Kill it? ") |
| 2749 | + (mew-nmz-mknmz-kill-process)))) |
| 2750 | + (when (y-or-n-p (format "Make index in all %s? " |
| 2751 | + (if args "folders" "indexed folders"))) |
| 2752 | + (let (alist flist) |
| 2753 | + (if args |
| 2754 | + (progn |
| 2755 | + ;; all exist folder |
| 2756 | + (mew-nmz-cleanup 'remove) |
| 2757 | + (setq flist (mew-nmz-mknmz-get-all-folders))) |
| 2758 | + ;; all indexed folder |
| 2759 | + (mew-nmz-setup) |
| 2760 | + (setq alist mew-nmz-fld-index-alist) |
| 2761 | + (while alist |
| 2762 | + (setq flist (cons (car (car alist)) flist)) |
| 2763 | + (setq alist (cdr alist)))) |
| 2764 | + (setq flist (nreverse flist)) |
| 2765 | + ;; for mew-nmz-mknmz() |
| 2766 | + (setq current-prefix-arg nil) |
| 2767 | + (setq mew-nmz-mknmz-all-folders flist) |
| 2768 | + (when flist |
| 2769 | + (mew-nmz-mknmz (car flist) 'all)))))) |
| 2770 | + |
| 2771 | +(defun mew-nmz-mknmz-save-mewmknmz () |
| 2772 | + "Save the information for mknmz." |
| 2773 | + (interactive) |
| 2774 | + (mew-nmz-cleanup 'remove) |
| 2775 | + (mew-nmz-setup) |
| 2776 | + (mew-nmz-mknmz-get-all-folders)) |
| 2777 | + |
| 2778 | +(defun mew-nmz-mark-unindexed () |
| 2779 | + "Mark unindexed messages." |
| 2780 | + (interactive) |
| 2781 | + (mew-summary-only |
| 2782 | + (if (mew-summary-exclusive-p) |
| 2783 | + (save-excursion |
| 2784 | + (if (and (mew-summary-mark-collect |
| 2785 | + mew-nmz-mark-unindexed (point-min) (point-max)) |
| 2786 | + (y-or-n-p (format "Unmark '%c'? " mew-nmz-mark-unindexed))) |
| 2787 | + (mew-mark-undo-mark mew-nmz-mark-unindexed 'nomsg)) |
| 2788 | + (let* ((ufname |
| 2789 | + (expand-file-name "NMZ.field.uri" |
| 2790 | + (mew-nmz-expand-folder (buffer-name)))) |
| 2791 | + (mmsgs 0) |
| 2792 | + (umsgs 0) |
| 2793 | + msgnums) |
| 2794 | + (if (not (file-exists-p ufname)) |
| 2795 | + (message "%s has no index file" (buffer-name)) |
| 2796 | + (with-temp-buffer |
| 2797 | + (message "checking %s..." (file-name-nondirectory ufname)) |
| 2798 | + (insert-file-contents ufname) |
| 2799 | + (while (re-search-forward "/\\([0-9]+\\)$" nil t) |
| 2800 | + (setq msgnums (cons (string-to-number (match-string 1)) msgnums)))) |
| 2801 | + (message "checking %s..." (buffer-name)) |
| 2802 | + (goto-char (point-min)) |
| 2803 | + (while (not (eobp)) |
| 2804 | + (if (and (mew-sumsyn-match mew-regex-sumsyn-short) |
| 2805 | + (not (memq (string-to-number (mew-sumsyn-message-number)) msgnums)) |
| 2806 | + (not (mew-in-decode-syntax-p))) |
| 2807 | + (progn |
| 2808 | + (setq umsgs (1+ umsgs)) |
| 2809 | + (when (mew-summary-markable) |
| 2810 | + (mew-summary-mark-as mew-nmz-mark-unindexed) |
| 2811 | + (setq mmsgs (1+ mmsgs))))) |
| 2812 | + (forward-line)) |
| 2813 | + (cond |
| 2814 | + ((= umsgs 1) |
| 2815 | + (message "%d message does not have index, %d marked" |
| 2816 | + umsgs mmsgs)) |
| 2817 | + ((> umsgs 1) |
| 2818 | + (message "%d messages do not have index, %d marked" |
| 2819 | + umsgs mmsgs)) |
| 2820 | + (t |
| 2821 | + (message "all messages have index"))))))))) |
| 2822 | + |
| 2823 | +;; "search Message-ID" functions. |
| 2824 | +(defun mew-nmz-search-parent (&optional child mid) |
| 2825 | + "Search *parent* message and jump to that. |
| 2826 | +If executed with '\\[universal-argument]', search *child* message." |
| 2827 | + (interactive "P") |
| 2828 | + (when (memq major-mode '(mew-summary-mode mew-virtual-mode)) |
| 2829 | + (mew-summary-goto-message)) |
| 2830 | + (let ((fld (mew-summary-folder-name)) |
| 2831 | + (msg (mew-summary-message-number)) |
| 2832 | + (idh (list (list mew-in-reply-to: mew-references:) |
| 2833 | + (list mew-message-id:))) |
| 2834 | + (message (if child "children" "parent")) |
| 2835 | + (refilefld (copy-sequence mew-nmz-search-parent-folder)) |
| 2836 | + (proto (or (mew-proto-to-refile (or (mew-sinfo-get-folder) |
| 2837 | + (mew-minfo-get-summary) |
| 2838 | + "+")) |
| 2839 | + "+")) |
| 2840 | + (case (mew-sinfo-get-case)) |
| 2841 | + refiledir mess ref pid pos killbuff) |
| 2842 | + (if mid |
| 2843 | + (setq pid (list mid) idh nil) |
| 2844 | + (if (not (or msg (mew-syntax-number))) |
| 2845 | + (message "No message here") |
| 2846 | + (save-excursion |
| 2847 | + (mew-nmz-setup) |
| 2848 | + (mew-summary-display) |
| 2849 | + (if (setq mess (mew-cache-hit fld msg)) |
| 2850 | + (set-buffer mess) |
| 2851 | + (setq mess (generate-new-buffer mew-buffer-prefix)) |
| 2852 | + (setq killbuff t) |
| 2853 | + (set-buffer mess) |
| 2854 | + (mew-erase-buffer) |
| 2855 | + (mew-insert-message |
| 2856 | + fld msg mew-cs-text-for-read mew-header-reasonable-size)) |
| 2857 | + (let ((mew-inherit-refile-proto proto) |
| 2858 | + (mew-inherit-refile-case case)) |
| 2859 | + (setq refilefld (append (car (mew-refile-guess nil t)) refilefld))) |
| 2860 | + (if child |
| 2861 | + (setq idh (car (cdr idh))) |
| 2862 | + (setq idh (car idh))) |
| 2863 | + (dolist (rh idh) |
| 2864 | + (setq ref (mew-header-get-value rh)) |
| 2865 | + (while (and ref (string-match "<\\([^>]+\\)>" ref)) |
| 2866 | + (setq pid (cons (concat "\"" (match-string 1 ref) "\"") pid)) |
| 2867 | + (setq refilefld |
| 2868 | + (cons (nth 1 (assoc (car pid) mew-refile-msgid-alist)) refilefld)) |
| 2869 | + (setq ref (substring ref (match-end 0))))) |
| 2870 | + (setq refilefld (cons fld refilefld)) |
| 2871 | + (setq refilefld (mew-uniq-list (delete nil refilefld))) |
| 2872 | + (setq refiledir |
| 2873 | + (delete nil (mapcar |
| 2874 | + (lambda (x) |
| 2875 | + (mew-nmz-expand-folder x)) |
| 2876 | + refilefld)))))) |
| 2877 | + (when killbuff (mew-kill-buffer mess)) |
| 2878 | + (if (null pid) |
| 2879 | + (message "No required header") |
| 2880 | + (if (mew-syntax-number) |
| 2881 | + (while (not (mew-summary-message-number)) |
| 2882 | + (forward-line -1))) |
| 2883 | + (mew-sinfo-set-ret-pos (point)) |
| 2884 | + (let ((pattern1 "") |
| 2885 | + (pattern2 "") |
| 2886 | + (addpattern (if child "+in-reply-to:" "+message-id:")) |
| 2887 | + (range nil)) |
| 2888 | + (if (not child) |
| 2889 | + (setq pattern1 (concat addpattern (car pid))) |
| 2890 | + (setq pattern1 (concat addpattern (car pid))) |
| 2891 | + (setq addpattern "+references:") |
| 2892 | + (setq pattern1 (concat pattern1 " | " addpattern (car pid)))) |
| 2893 | + (setq pid (delete (car pid) pid)) |
| 2894 | + (while pid |
| 2895 | + (if (> (length (concat pattern2 addpattern (car pid))) |
| 2896 | + mew-nmz-query-max-length) |
| 2897 | + (setq pid nil) |
| 2898 | + (setq pattern2 (concat pattern2 addpattern (car pid))) |
| 2899 | + (setq addpattern (if child " | +references:" " | +message-id:")) |
| 2900 | + (setq pid (delete (car pid) pid)))) |
| 2901 | + (message "Searching %s..." message) |
| 2902 | + (let ((pattern (list pattern1 pattern2))) |
| 2903 | + (while (and (null range) pattern) |
| 2904 | + (if mid |
| 2905 | + () |
| 2906 | + (message "Searching %s...%s" message (mew-join ", " refilefld)) |
| 2907 | + (setq range (mew-nmz-multi-pick refiledir (car pattern))) |
| 2908 | + (when range |
| 2909 | + (catch 'detect |
| 2910 | + (dolist (ref refilefld) |
| 2911 | + (if (null (setq idh (assoc ref range))) |
| 2912 | + () |
| 2913 | + (setq fld (car idh)) |
| 2914 | + (if child |
| 2915 | + (setq range (cdr idh)) |
| 2916 | + (setq range (nreverse (cdr idh)))) |
| 2917 | + (throw 'detect t))) |
| 2918 | + nil))) |
| 2919 | + (unless range |
| 2920 | + ;; all folder search |
| 2921 | + (message "Searching %s...all folders" message) |
| 2922 | + (setq range (mew-nmz-multi-pick |
| 2923 | + (mew-nmz-expand-folder-regexp "*:*") |
| 2924 | + (car pattern) 'catch)) |
| 2925 | + (if (null range) |
| 2926 | + (setq pattern (cdr pattern)) |
| 2927 | + (setq fld (car (car range))) |
| 2928 | + (setq range (cdr (car range))) |
| 2929 | + (if (not child) (setq range (nreverse range))) |
| 2930 | + )))) |
| 2931 | + (if (null range) |
| 2932 | + (message "No message found") |
| 2933 | + (when (or (and (mew-thread-p) |
| 2934 | + (string= (mew-summary-folder-name) fld)) |
| 2935 | + (and (mew-virtual-p) |
| 2936 | + (not (mew-thread-p)))) |
| 2937 | + (save-excursion |
| 2938 | + (goto-char (point-min)) |
| 2939 | + (when (re-search-forward |
| 2940 | + (concat "\r \\(" (regexp-quote fld) "\\)? +" (car range) " ") nil t) |
| 2941 | + (setq fld (buffer-name)) |
| 2942 | + (goto-char (match-beginning 0)) |
| 2943 | + (beginning-of-line) |
| 2944 | + (setq pos (point))))) |
| 2945 | + (if (listp (car range)) |
| 2946 | + (setq fld (car (car range)) |
| 2947 | + mess (car (cdr (car range)))) |
| 2948 | + (setq mess (car range))) |
| 2949 | + (mew-nmz-goto-folder-msg fld mess pos) |
| 2950 | + (message "Searching %s...%s/%s" message fld mess)))))) |
| 2951 | + |
| 2952 | +(defun mew-nmz-search-child (&optional arg) |
| 2953 | + (interactive "P") |
| 2954 | + (mew-nmz-search-parent (not arg))) |
| 2955 | + |
| 2956 | +(defun mew-nmz-search-msgid-at-point () |
| 2957 | + (interactive) |
| 2958 | + (let (start end) |
| 2959 | + (if (and (re-search-backward "<" (save-excursion (beginning-of-line) (point)) t) |
| 2960 | + (setq start (point)) |
| 2961 | + (re-search-forward ">" (save-excursion (end-of-line) (point)) t) |
| 2962 | + (setq end (point))) |
| 2963 | + (mew-nmz-search-msgid (buffer-substring start end)) |
| 2964 | + (message "No Message-ID")))) |
| 2965 | + |
| 2966 | +(defun mew-nmz-search-msgid-region (start end) |
| 2967 | + (interactive "r") |
| 2968 | + (mew-nmz-search-msgid (buffer-substring start end))) |
| 2969 | + |
| 2970 | +(defun mew-nmz-search-msgid (mid) |
| 2971 | + (interactive "sMessage-ID: ") |
| 2972 | + (if (string-match "<\\([^>]+\\)>" mid) |
| 2973 | + (let ((mew-use-full-window t) |
| 2974 | + (pattern (concat "\"" (mew-match-string 1 mid) "\""))) |
| 2975 | + (when (eq major-mode 'mew-message-mode) |
| 2976 | + (mew-message-goto-summary)) |
| 2977 | + (mew-nmz-search-parent nil pattern)) |
| 2978 | + (message "No Message-ID"))) |
| 2979 | + |
| 2980 | +;; "Namazu virtual" function. |
| 2981 | +(defun mew-nmz-input-folders () |
| 2982 | + (mew-input-clear) |
| 2983 | + (mew-input-folder-clean-up) |
| 2984 | + (let ((map (copy-keymap mew-input-folder-map)) |
| 2985 | + (case:folder (concat (or (mew-summary-folder-name) "+") |
| 2986 | + (if mew-nmz-input-folders-asterisk "*" "")))) |
| 2987 | + (define-key map "*" 'mew-input-folder-self-insert) |
| 2988 | + (let* ((init "+*") ;; (mew-canonicalize-case-folder case:folder)) |
| 2989 | + (mew-input-complete-function 'mew-complete-folder) |
| 2990 | + (mew-circular-complete-function 'mew-circular-complete-case:) |
| 2991 | + (mew-input-folder-search-multi t) |
| 2992 | + (minibuffer-setup-hook (cons 'backward-char minibuffer-setup-hook)) |
| 2993 | + ;; mew-inherit-case must be nil |
| 2994 | + (ret (read-from-minibuffer "Namazu folder name: " |
| 2995 | + init map nil |
| 2996 | + 'mew-nmz-input-folder-hist))) |
| 2997 | + (when (string= ret "") |
| 2998 | + (setq ret init)) |
| 2999 | + (setq ret (mapcar 'mew-chop (mew-split ret ?,)))))) |
| 3000 | + |
| 3001 | +;; Use namazu-mode. |
| 3002 | +;; (setq w3m-namazu-arguments |
| 3003 | +;; '("-r" "-h" "-H" "-n" w3m-namazu-page-max "-w" whence)) |
| 3004 | + |
| 3005 | +(defun mew-nmz-namazu (&optional pattern indexs) |
| 3006 | + "Execute w3m-namazu. |
| 3007 | +If executed with '\\[universal-argument]', search result indexes." |
| 3008 | + (interactive) |
| 3009 | + (if (not (or (featurep 'w3m-namazu) |
| 3010 | + (condition-case nil |
| 3011 | + (require 'w3m-namazu) |
| 3012 | + (error nil)))) |
| 3013 | + (message "Please install \"emacs-w3m\"") |
| 3014 | + (mew-nmz-setup) |
| 3015 | + (if current-prefix-arg |
| 3016 | + ;; rest indexes |
| 3017 | + (let (current-prefix-arg) |
| 3018 | + (mew-nmz-namazu mew-nmz-namazu-pattern mew-nmz-namazu-miss-folders)) |
| 3019 | + (let ((i mew-nmz-db-max) |
| 3020 | + flds nmzdirs fldmsgs pickflds overmsg) |
| 3021 | + (setq flds (or indexs (mew-nmz-input-folders))) |
| 3022 | + (setq mew-nmz-namazu-pattern |
| 3023 | + (setq pattern |
| 3024 | + (or pattern |
| 3025 | + (let ((mew-pick-field-list (mew-nmz-pick-field-list))) |
| 3026 | + (mew-nmz-pick-canonicalize-pattern |
| 3027 | + (mew-input-pick-pattern "Namazu pick")))))) |
| 3028 | + (setq mew-nmz-namazu-miss-folders nil) |
| 3029 | + (setq nmzdirs (mew-nmz-flds-to-indexs flds)) |
| 3030 | + (when (> (length nmzdirs) mew-nmz-db-max) |
| 3031 | + (setq fldmsgs (mew-nmz-multi-pick nmzdirs pattern)) |
| 3032 | + (when fldmsgs |
| 3033 | + (dolist (fldmsg fldmsgs) |
| 3034 | + (setq pickflds (cons (car fldmsg) pickflds))) |
| 3035 | + (when (> (length pickflds) mew-nmz-db-max) |
| 3036 | + (setq mew-nmz-namazu-miss-folders |
| 3037 | + (nthcdr mew-nmz-db-max (nreverse pickflds))) |
| 3038 | + (setq overmsg (format "Warning: %d indexes over" |
| 3039 | + (length mew-nmz-namazu-miss-folders)))) |
| 3040 | + (setq nmzdirs nil) |
| 3041 | + (while (and pickflds (> i 0)) |
| 3042 | + (setq nmzdirs (cons (mew-nmz-expand-folder (car pickflds)) |
| 3043 | + nmzdirs)) |
| 3044 | + (setq pickflds (cdr pickflds)) |
| 3045 | + (setq i (1- i))))) |
| 3046 | + ;; message viewer set |
| 3047 | + (unless (assoc mew-nmz-namazu-content-type w3m-content-type-alist) |
| 3048 | + (setq w3m-content-type-alist |
| 3049 | + (cons `(,mew-nmz-namazu-content-type "/[0-9]+$" nil "text/plain") |
| 3050 | + w3m-content-type-alist))) |
| 3051 | + (add-hook 'w3m-display-hook 'w3m-mew-message-view t) |
| 3052 | + ;; remove pre mew-nmz-namazu's alist |
| 3053 | + (when (assoc mew-nmz-namazu-index-alias w3m-namazu-index-alist) |
| 3054 | + (setq w3m-namazu-index-alist |
| 3055 | + (delete (assoc mew-nmz-namazu-index-alias w3m-namazu-index-alist) |
| 3056 | + w3m-namazu-index-alist))) |
| 3057 | + ;; for next page |
| 3058 | + (setq w3m-namazu-index-alist |
| 3059 | + (append (list (cons mew-nmz-namazu-index-alias nmzdirs)) |
| 3060 | + w3m-namazu-index-alist)) |
| 3061 | + (w3m-namazu mew-nmz-namazu-index-alias pattern 'reload) |
| 3062 | + (when overmsg (message overmsg)))))) |
| 3063 | + |
| 3064 | +(defun w3m-mew-message-view (url) |
| 3065 | + (if (and (boundp 'mew-mail-path) |
| 3066 | + (w3m-url-local-p url) |
| 3067 | + (string-match (concat (file-name-as-directory |
| 3068 | + (expand-file-name mew-mail-path)) |
| 3069 | + ".+/[0-9]+$") |
| 3070 | + (expand-file-name (w3m-url-to-file-name url)))) |
| 3071 | + (unless (get-text-property (point-min) 'w3m-mew-namazu) |
| 3072 | + (mew-elet |
| 3073 | + (goto-char (point-min)) |
| 3074 | + (condition-case nil |
| 3075 | + (let (pos) |
| 3076 | + (mew-decode-rfc822-header) |
| 3077 | + (mew-header-goto-end) |
| 3078 | + (mew-header-arrange (point-min) (point)) |
| 3079 | + (mew-highlight-body-region (point) (point-max)) |
| 3080 | + ;; for emacs-w3m |
| 3081 | + (remove-text-properties (point-min) (point-max) |
| 3082 | + '(read-only nil)) |
| 3083 | + (setq pos (if (get-text-property (point-min) 'mew-visible) |
| 3084 | + (point-min) |
| 3085 | + (or (next-single-property-change (point-min) 'mew-visible) |
| 3086 | + (point-min)))) |
| 3087 | + (set-window-start (selected-window) pos)) |
| 3088 | + (error nil)) |
| 3089 | + (put-text-property (point-min) (point-min) 'w3m-mew-namazu t) |
| 3090 | + (set-buffer-modified-p nil))) |
| 3091 | + (remove-text-properties (point-min) (point-min) '(w3m-mew-namazu nil)))) |
| 3092 | + |
| 3093 | +;; Input "Namazu pattern" functions. |
| 3094 | + |
| 3095 | +;; Mew pickpattern converter |
| 3096 | +(defun mew-nmz-pick-canonicalize-pattern (pattern) |
| 3097 | + (let ((mew-inherit-pick-omit-and t)) |
| 3098 | + (mapconcat |
| 3099 | + 'mew-nmz-pick-native-text-namazu |
| 3100 | + (mew-pick-parse (mew-pick-lex pattern)) |
| 3101 | + " "))) |
| 3102 | + |
| 3103 | +(defun mew-nmz-pick-native-text-namazu (token) |
| 3104 | + (mew-pick-native-text "mew-nmz-pick-pattern-namazu-" token)) |
| 3105 | + |
| 3106 | +(defun mew-nmz-pick-pattern-namazu-and (sym) "and") |
| 3107 | +(defun mew-nmz-pick-pattern-namazu-or (sym) "or") |
| 3108 | +(defun mew-nmz-pick-pattern-namazu-open (sym) "(") |
| 3109 | +(defun mew-nmz-pick-pattern-namazu-close (sym) ")") |
| 3110 | +(defun mew-nmz-pick-pattern-namazu-not (sym) "not") |
| 3111 | +(defun mew-nmz-pick-pattern-namazu-key (key) key) |
| 3112 | +(defun mew-nmz-pick-pattern-namazu-kyvl (kyvl) |
| 3113 | + (when (string= (nth 0 kyvl) "=") |
| 3114 | + (format "+%s:%s" (nth 1 kyvl) (nth 2 kyvl)))) |
| 3115 | + |
| 3116 | +(defun mew-nmz-pick-pattern-gather-header () |
| 3117 | + (when mew-nmz-pick-gather-field-list |
| 3118 | + (save-excursion |
| 3119 | + (let* ((fld (mew-summary-folder-name)) |
| 3120 | + (msg (mew-summary-message-number)) |
| 3121 | + (buf (mew-cache-hit fld msg)) |
| 3122 | + (gathers mew-nmz-pick-gather-field-list) |
| 3123 | + killbuff retlst gather header duplchk mid addrs addr prefix) |
| 3124 | + (when (and (not buf) fld msg) |
| 3125 | + (setq buf (generate-new-buffer mew-buffer-prefix)) |
| 3126 | + (setq killbuff t) |
| 3127 | + (set-buffer buf) |
| 3128 | + (mew-erase-buffer) |
| 3129 | + (mew-insert-message |
| 3130 | + fld msg mew-cs-text-for-read mew-header-reasonable-size)) |
| 3131 | + (when (and buf (get-buffer buf) (buffer-name (get-buffer buf))) |
| 3132 | + (set-buffer buf) |
| 3133 | + (while gathers |
| 3134 | + (setq gather (car gathers)) |
| 3135 | + (setq header (mew-header-get-value (car gather))) |
| 3136 | + (when (and header (car (cdr gather))) |
| 3137 | + (cond |
| 3138 | + ((eq (car (cdr gather)) 'msgid) |
| 3139 | + (while (and header (string-match "<\\([^>]+\\)>" header)) |
| 3140 | + (setq mid (match-string 1 header)) |
| 3141 | + (setq header (substring header (match-end 0))) |
| 3142 | + (if (member mid duplchk) |
| 3143 | + () |
| 3144 | + (setq prefix (nthcdr 2 gather)) |
| 3145 | + (setq duplchk (cons mid duplchk)) |
| 3146 | + (while prefix |
| 3147 | + (setq retlst (cons (concat (car prefix) mid) retlst)) |
| 3148 | + (setq prefix (cdr prefix)))))) |
| 3149 | + ((eq (car (cdr gather)) 'address) |
| 3150 | + (setq addrs (mew-addrstr-parse-address-list header)) |
| 3151 | + (while (setq addr (car addrs)) |
| 3152 | + (setq addr (downcase addr)) |
| 3153 | + (if (not (member addr duplchk)) |
| 3154 | + (let ((prefix (nthcdr 2 gather))) |
| 3155 | + (setq duplchk (cons addr duplchk)) |
| 3156 | + (while prefix |
| 3157 | + (setq retlst (cons (concat (car prefix) addr) retlst)) |
| 3158 | + (setq prefix (cdr prefix))))) |
| 3159 | + (setq addrs (cdr addrs)))))) |
| 3160 | + (setq gathers (cdr gathers))) |
| 3161 | + (when killbuff (mew-kill-buffer buf)) |
| 3162 | + (when retlst |
| 3163 | + (setq retlst (append |
| 3164 | + retlst |
| 3165 | + (list |
| 3166 | + (concat " " (make-string (- (window-width) 10) ?-)))))) |
| 3167 | + (nreverse retlst)))))) |
| 3168 | + |
| 3169 | +;; "Namazu search engine" functions. |
| 3170 | +(defun mew-nmz-multi-pick (nmzdirs pattern &optional catch single) |
| 3171 | + "Get message numbers with many folders." |
| 3172 | + (let ((tmpdirs nmzdirs) |
| 3173 | + (defaultregex |
| 3174 | + (concat "^" (regexp-opt |
| 3175 | + (delq mew-folder-virtual (copy-sequence mew-folder-prefixes))))) |
| 3176 | + nxt prog-args intmsgs retmsgs sortfld defmsgs casemsgs cell) |
| 3177 | + (setq pattern (mew-cs-encode-arg pattern)) |
| 3178 | + (setq nmzdirs nil) |
| 3179 | + (while tmpdirs |
| 3180 | + (setq nxt (nthcdr mew-nmz-db-max tmpdirs)) |
| 3181 | + (if nxt (setcdr (nthcdr (1- mew-nmz-db-max) tmpdirs) nil)) |
| 3182 | + (setq nmzdirs (cons tmpdirs nmzdirs)) |
| 3183 | + (setq tmpdirs nxt)) |
| 3184 | + (setq nmzdirs (nreverse nmzdirs)) |
| 3185 | + (with-temp-buffer |
| 3186 | + (while (and nmzdirs |
| 3187 | + (or (not catch) |
| 3188 | + (and catch (null intmsgs)))) |
| 3189 | + (setq prog-args (delq nil (append mew-nmz-prog-args |
| 3190 | + (list "--all" "--list" "--no-decode-uri") |
| 3191 | + (list pattern) |
| 3192 | + (car nmzdirs)))) |
| 3193 | + (erase-buffer) |
| 3194 | + (mew-piolet |
| 3195 | + mew-cs-text-for-read mew-cs-text-for-write |
| 3196 | + (let ((file-name-coding-system nil)) |
| 3197 | + (apply (function call-process) |
| 3198 | + mew-nmz-prog nil t nil prog-args))) |
| 3199 | + (goto-char (point-min)) |
| 3200 | + (let (dir msgnum) |
| 3201 | + (while (not (eobp)) |
| 3202 | + (when (looking-at mew-nmz-result-regex) |
| 3203 | + (setq dir (mew-buffer-substring (match-beginning 1) (match-end 1))) |
| 3204 | + (setq msgnum (string-to-number |
| 3205 | + (mew-buffer-substring (match-beginning 2) (match-end 2)))) |
| 3206 | + (if (not (setq cell (assoc dir intmsgs))) |
| 3207 | + (setq intmsgs (cons (list dir (list msgnum)) intmsgs)) |
| 3208 | + (unless (memq msgnum (car (cdr cell))) |
| 3209 | + (nconc (car (cdr cell)) (list msgnum))))) |
| 3210 | + (forward-line)) |
| 3211 | + (setq nmzdirs (cdr nmzdirs)))) |
| 3212 | + (when intmsgs |
| 3213 | + (if single |
| 3214 | + ;; for search-mark |
| 3215 | + (mapcar 'number-to-string (sort (car (cdr (car intmsgs))) '<)) |
| 3216 | + ;; for virtual or w3m-namazu |
| 3217 | + (setq retmsgs intmsgs) |
| 3218 | + (while retmsgs |
| 3219 | + (setq sortfld (cons (car (car retmsgs)) sortfld)) |
| 3220 | + (setq retmsgs (cdr retmsgs))) |
| 3221 | + ;; no sort |
| 3222 | + ;; (setq sortfld (sort sortfld 'string<)) |
| 3223 | + (while sortfld |
| 3224 | + (setq cell (assoc (car sortfld) intmsgs)) |
| 3225 | + (setq retmsgs |
| 3226 | + (cons |
| 3227 | + (cons (mew-nmz-url-to-folder (car cell)) |
| 3228 | + (mapcar 'number-to-string (sort (car (cdr cell)) '<))) |
| 3229 | + retmsgs)) |
| 3230 | + (setq sortfld (cdr sortfld))) |
| 3231 | + ;; '((folder msg ...) (folder msg ...) ...) |
| 3232 | + (while retmsgs |
| 3233 | + (when (car (car retmsgs)) |
| 3234 | + (if (string-match defaultregex (car (car retmsgs))) |
| 3235 | + (setq defmsgs (cons (car retmsgs) defmsgs)) |
| 3236 | + (setq casemsgs (cons (car retmsgs) casemsgs)))) |
| 3237 | + (setq retmsgs (cdr retmsgs))) |
| 3238 | + (append defmsgs casemsgs)))))) |
| 3239 | + |
| 3240 | +;; miscellaneous functions |
| 3241 | +(defun mew-nmz-flds-to-indexs (flds) |
| 3242 | + (let ((suffix (append |
| 3243 | + '("*") |
| 3244 | + (delq mew-folder-virtual (copy-sequence mew-folder-prefixes)))) |
| 3245 | + nmzdirs tmp) |
| 3246 | + (setq suffix (concat (regexp-opt suffix) "$")) |
| 3247 | + (dolist (fld flds) |
| 3248 | + (setq fld (mew-nmz-case-folder-normalize fld)) |
| 3249 | + (cond |
| 3250 | + ((or (string-match suffix fld) |
| 3251 | + (string-match "^\\*" fld)) |
| 3252 | + (setq nmzdirs (append nmzdirs |
| 3253 | + (mew-nmz-expand-folder-regexp fld)))) |
| 3254 | + ((setq tmp (mew-nmz-folder-to-nmzdir fld)) |
| 3255 | + (setq nmzdirs (cons tmp nmzdirs))))) |
| 3256 | + (nreverse (mew-uniq-list nmzdirs)))) |
| 3257 | + |
| 3258 | +(defun mew-nmz-expand-folder-regexp (case:folder) |
| 3259 | + (mew-nmz-setup) |
| 3260 | + (let ((alist mew-nmz-fld-index-alist) |
| 3261 | + case fld caseregex nmzdirs tmpfld nmzdir protos newcase lst) |
| 3262 | + (if (string= case:folder "*:*") |
| 3263 | + ;; all case, all proto, all folder |
| 3264 | + (dolist (lst alist) |
| 3265 | + (setq nmzdirs (cons (cdr lst) nmzdirs))) |
| 3266 | + (if (string-match "^\\([^:]+\\):\\(.*\\)$" case:folder) |
| 3267 | + (setq case (match-string 1 case:folder) |
| 3268 | + fld (match-string 2 case:folder)) |
| 3269 | + (setq case "") |
| 3270 | + (setq fld case:folder)) |
| 3271 | + (when (string-match "^.*\\*$" fld) |
| 3272 | + (setq fld (substring fld 0 -1)) |
| 3273 | + (setq fld (directory-file-name fld))) |
| 3274 | + (cond |
| 3275 | + ((string= case "*") |
| 3276 | + ;; all case |
| 3277 | + (setq caseregex "^\\([^:]+:\\)?")) |
| 3278 | + ((or (string= case "") (string= mew-case-default case)) |
| 3279 | + ;; default case |
| 3280 | + (setq caseregex "^")) |
| 3281 | + ((string= fld "") |
| 3282 | + (setq protos (delq mew-folder-virtual (copy-sequence mew-folder-prefixes))) |
| 3283 | + (setq caseregex |
| 3284 | + (concat "^\\(\\(" |
| 3285 | + (mapconcat |
| 3286 | + (lambda (x) |
| 3287 | + (setq newcase (mew-nmz-case-normalize |
| 3288 | + (concat case ":" x))) |
| 3289 | + (if (string= newcase "") |
| 3290 | + (regexp-quote x) |
| 3291 | + (regexp-quote (concat case ":" x)))) |
| 3292 | + protos "\\)\\|\\(") |
| 3293 | + "\\)\\)"))) |
| 3294 | + (t |
| 3295 | + (setq case (mew-nmz-case-normalize (concat case ":" fld))) |
| 3296 | + (if (string= case "") |
| 3297 | + (setq caseregex "^") |
| 3298 | + (setq caseregex (concat "^" (regexp-quote case) ":"))))) |
| 3299 | + (if (string= fld "") |
| 3300 | + (setq caseregex (concat caseregex "[^:]+$")) |
| 3301 | + (setq caseregex (concat caseregex (regexp-quote fld)))) |
| 3302 | + (dolist (lst alist) |
| 3303 | + (setq tmpfld (car lst)) |
| 3304 | + (setq nmzdir (cdr lst)) |
| 3305 | + (when (string-match caseregex tmpfld) |
| 3306 | + (setq nmzdirs (cons nmzdir nmzdirs))))) |
| 3307 | + nmzdirs)) |
| 3308 | + |
| 3309 | +(defun mew-nmz-goto-folder-msg (fld msg &optional pos disp) |
| 3310 | + (when (string-match "^+#" fld) |
| 3311 | + (mew-nmz-setup) |
| 3312 | + (setq fld (or (cdr (assoc (mew-expand-folder fld) mew-nmz-url-fld-alist)) |
| 3313 | + fld))) |
| 3314 | + (mew-summary-visit-folder fld) |
| 3315 | + (if (mew-virtual-p) |
| 3316 | + (mew-summary-move-and-display msg disp) |
| 3317 | + (goto-char (point-min)) |
| 3318 | + (if (mew-nmz-re-search-message msg) |
| 3319 | + (setq pos (point)) |
| 3320 | + (setq pos |
| 3321 | + (catch 'det |
| 3322 | + (while mew-summary-buffer-process |
| 3323 | + (sit-for 0.1) |
| 3324 | + ;; accept-process-output or sleep-for is not enough |
| 3325 | + (discard-input) |
| 3326 | + (unless pos |
| 3327 | + (goto-char (point-min)) |
| 3328 | + (when (mew-nmz-re-search-message msg) |
| 3329 | + (setq pos (point)) |
| 3330 | + (throw 'det t)))) |
| 3331 | + pos))) |
| 3332 | + (if pos (goto-char pos)) |
| 3333 | + (mew-thread-move-cursor) |
| 3334 | + (mew-summary-display disp))) |
| 3335 | + |
| 3336 | +(defun mew-nmz-index-new-p (fld) |
| 3337 | + (let ((touchtime (mew-file-get-time |
| 3338 | + (expand-file-name |
| 3339 | + mew-summary-touch-file |
| 3340 | + (file-chase-links (mew-expand-folder fld))))) |
| 3341 | + (stamptime (mew-file-get-time |
| 3342 | + (expand-file-name |
| 3343 | + "NMZ.stamp" (mew-nmz-expand-folder fld))))) |
| 3344 | + (cond |
| 3345 | + ((null touchtime) nil) |
| 3346 | + ((null stamptime) nil) |
| 3347 | + ((> (nth 0 stamptime) (nth 0 touchtime)) t) |
| 3348 | + ((and (= (nth 0 stamptime) (nth 0 touchtime)) |
| 3349 | + (> (nth 1 stamptime) (nth 1 touchtime))) t) |
| 3350 | + (t nil)))) |
| 3351 | + |
| 3352 | +(defun mew-nmz-index-delete (nmzdir &optional tmpfiles) |
| 3353 | + "Delete namazu index files." |
| 3354 | + (when (file-directory-p nmzdir) |
| 3355 | + (let* ((regex (if tmpfiles "^NMZ\..*tmp$" "^NMZ\.")) |
| 3356 | + (flist (directory-files nmzdir 'full regex 'nosort))) |
| 3357 | + (dolist (file flist) |
| 3358 | + (setq file (expand-file-name file nmzdir)) |
| 3359 | + (and (file-exists-p file) |
| 3360 | + (file-writable-p file) |
| 3361 | + (delete-file file)))))) |
| 3362 | + |
| 3363 | +(defun mew-nmz-skip-folder-p (fld) |
| 3364 | + (let ((skips mew-nmz-mknmz-skip-folders-regexp)) |
| 3365 | + (catch 'match |
| 3366 | + (setq fld (mew-nmz-case-folder-normalize fld)) |
| 3367 | + (dolist (skip skips) |
| 3368 | + (when (string-match skip fld) |
| 3369 | + (throw 'match t))) |
| 3370 | + nil))) |
| 3371 | + |
| 3372 | +(defun mew-nmz-gcnmz-folder-p (fld) |
| 3373 | + (let ((regexps mew-nmz-use-gcnmz-folders-regexp)) |
| 3374 | + (catch 'match |
| 3375 | + (setq fld (mew-nmz-case-folder-normalize fld)) |
| 3376 | + (while regexps |
| 3377 | + (when (string-match (car regexps) fld) |
| 3378 | + (throw 'match t)) |
| 3379 | + (setq regexps (cdr regexps))) |
| 3380 | + nil))) |
| 3381 | + |
| 3382 | +(defun mew-nmz-timestamp-new (fld) |
| 3383 | + (let ((file (expand-file-name "NMZ.stamp.new" (mew-nmz-expand-folder fld)))) |
| 3384 | + (if (file-writable-p file) |
| 3385 | + (write-region "touched by Mew." nil file nil 'no-msg)))) |
| 3386 | + |
| 3387 | +(defun mew-nmz-timestamp-rename (fld) |
| 3388 | + (let ((nfile (expand-file-name "NMZ.stamp.new" (mew-nmz-expand-folder fld))) |
| 3389 | + (tfile (expand-file-name "NMZ.stamp" (mew-nmz-expand-folder fld)))) |
| 3390 | + (if (and (file-readable-p nfile) (file-writable-p tfile)) |
| 3391 | + (rename-file nfile tfile 'ok) |
| 3392 | + (if (file-writable-p nfile) |
| 3393 | + (delete-file nfile))))) |
| 3394 | + |
| 3395 | +(defun mew-nmz-re-search-message (msg) |
| 3396 | + (let ((here (point))) |
| 3397 | + (if (not (re-search-forward (concat "^.*\r +" msg "[^0-9]") nil t)) |
| 3398 | + (progn (goto-char here) |
| 3399 | + nil) |
| 3400 | + (beginning-of-line) |
| 3401 | + t))) |
| 3402 | + |
| 3403 | +;; index delete/rename |
| 3404 | +;; call from mew-summary-delete-folder() |
| 3405 | +;; case:folder MUST not branch |
| 3406 | +(defun mew-nmz-folder-index-delete (case:folder) |
| 3407 | + (let ((nmzdir (mew-nmz-expand-folder case:folder)) |
| 3408 | + (fld (mew-nmz-case-folder-normalize case:folder))) |
| 3409 | + (when (and (file-exists-p nmzdir) (file-directory-p nmzdir)) |
| 3410 | + (mew-delete-directory-recursively nmzdir) |
| 3411 | + (setq mew-nmz-fld-index-alist |
| 3412 | + (delete (assoc fld mew-nmz-fld-index-alist) mew-nmz-fld-index-alist)) |
| 3413 | + (setq mew-nmz-url-fld-alist |
| 3414 | + (delete (assoc (mew-expand-folder fld) mew-nmz-url-fld-alist) |
| 3415 | + mew-nmz-url-fld-alist)) |
| 3416 | + (mew-nmz-cache-save)))) |
| 3417 | + |
| 3418 | +;; call from mew-summary-rename-folder() |
| 3419 | +(defun mew-nmz-folder-index-rename (case:folder case:new-folder) |
| 3420 | + (let ((nmzdir (mew-nmz-expand-folder case:folder)) |
| 3421 | + (new-nmzdir (mew-nmz-expand-folder case:new-folder)) |
| 3422 | + (dir (file-name-as-directory (mew-expand-folder case:folder))) |
| 3423 | + (new-dir (file-name-as-directory (mew-expand-folder case:new-folder)))) |
| 3424 | + (when (and (file-exists-p nmzdir) (file-directory-p nmzdir) |
| 3425 | + (not (file-exists-p new-nmzdir))) |
| 3426 | + (mew-nmz-cleanup 'remove) |
| 3427 | + (rename-file nmzdir new-nmzdir) |
| 3428 | + (when mew-nmz-use-drive-letter |
| 3429 | + (when (string-match "^\\([a-zA-Z]\\):\\(/.*\\)" dir) |
| 3430 | + (setq dir (concat "/" |
| 3431 | + (substring dir (match-beginning 1) (match-end 1)) |
| 3432 | + "|" |
| 3433 | + (substring dir (match-beginning 2) (match-end 2))))) |
| 3434 | + (when (string-match "^\\([a-zA-Z]\\):\\(/.*\\)" new-dir) |
| 3435 | + (setq new-dir (concat "/" |
| 3436 | + (substring new-dir (match-beginning 1) (match-end 1)) |
| 3437 | + "|" |
| 3438 | + (substring new-dir (match-beginning 2) (match-end 2)))))) |
| 3439 | + (mew-nmz-folder-reindex-recursively new-nmzdir dir new-dir)))) |
| 3440 | + |
| 3441 | +(defun mew-nmz-folder-reindex-recursively (dir from to) |
| 3442 | + (let ((files (directory-files dir 'full mew-regex-files 'no-sort)) |
| 3443 | + urifile) |
| 3444 | + (when (member (setq urifile (expand-file-name "NMZ.field.uri" dir)) files) |
| 3445 | + (mew-nmz-folder-index-reindex dir urifile from to)) |
| 3446 | + (dolist (file files) |
| 3447 | + (when (file-directory-p file) |
| 3448 | + (mew-nmz-folder-reindex-recursively file from to))))) |
| 3449 | + |
| 3450 | +(defun mew-nmz-folder-index-reindex (dir file from to) |
| 3451 | + (setq from (concat "^" (regexp-quote from))) |
| 3452 | + (when (and (file-readable-p file) (file-regular-p file)) |
| 3453 | + (message "mew-nmz: reindexing %s..." dir) |
| 3454 | + (with-temp-buffer |
| 3455 | + (mew-frwlet |
| 3456 | + mew-cs-autoconv mew-nmz-cs-index |
| 3457 | + (insert-file-contents file) |
| 3458 | + (goto-char (point-min)) |
| 3459 | + (while (not (eobp)) |
| 3460 | + (when (looking-at from) |
| 3461 | + (delete-region (match-beginning 0) (match-end 0)) |
| 3462 | + (insert to)) |
| 3463 | + (forward-line 1)) |
| 3464 | + (write-region (point-min) (point-max) file nil 'nomsg))) |
| 3465 | + (when (mew-which-exec mew-nmz-prog-rfnmz) |
| 3466 | + (call-process mew-nmz-prog-rfnmz nil nil nil dir)) |
| 3467 | + (message "mew-nmz: reindexing %s...done" dir))) |
| 3468 | + |
| 3469 | +;; mew-nmz-setup |
| 3470 | +(defun mew-nmz-gather-indexed-folder (case folders-alist &optional proto) |
| 3471 | + (let ((ocase case) |
| 3472 | + fld nmzdir fld-index-alist url-fld-alist) |
| 3473 | + (unless case (setq case "")) |
| 3474 | + (dolist (flds folders-alist) |
| 3475 | + (setq fld (car flds)) |
| 3476 | + (when fld |
| 3477 | + (when (eq proto 'imap) |
| 3478 | + (setq fld (mew-nmz-imap-directory-file-name fld ocase))) |
| 3479 | + (setq fld (directory-file-name (if (string= case "") |
| 3480 | + fld |
| 3481 | + (concat case ":" fld)))) |
| 3482 | + (when (and (or (not (eq proto 'nntp)) |
| 3483 | + (file-directory-p (mew-expand-folder fld))) |
| 3484 | + (setq nmzdir (mew-nmz-expand-folder fld)) |
| 3485 | + (file-directory-p nmzdir) |
| 3486 | + (file-exists-p (expand-file-name "NMZ.i" nmzdir))) |
| 3487 | + (setq fld-index-alist (cons (cons fld nmzdir) fld-index-alist)) |
| 3488 | + (setq url-fld-alist (cons (cons (mew-expand-folder fld) fld) url-fld-alist))))) |
| 3489 | + (setq mew-nmz-fld-index-alist |
| 3490 | + (append mew-nmz-fld-index-alist (nreverse fld-index-alist))) |
| 3491 | + (setq mew-nmz-url-fld-alist |
| 3492 | + (append mew-nmz-url-fld-alist (nreverse url-fld-alist))))) |
| 3493 | + |
| 3494 | +(defun mew-nmz-setup () |
| 3495 | + (unless mew-nmz-setup-p |
| 3496 | + (unless (and (mew-which-exec mew-nmz-prog-mknmz) |
| 3497 | + (mew-which-exec mew-nmz-prog)) |
| 3498 | + (error "Please install namazu")) |
| 3499 | + (message "mew-nmz setup...") |
| 3500 | + (unless (mew-nmz-cache-load) |
| 3501 | + (mew-nmz-cleanup) |
| 3502 | + (let ((prefixes (delq mew-folder-virtual (copy-sequence mew-folder-prefixes))) |
| 3503 | + nmzdir-case-alist |
| 3504 | + case-alist cases case ocase gcase nmzdir alst) |
| 3505 | + (dolist (prefix prefixes) |
| 3506 | + (setq cases (mapcar (lambda (x) |
| 3507 | + (if (string= x mew-case-default) "" x)) |
| 3508 | + mew-config-cases)) |
| 3509 | + (when (member "" cases) |
| 3510 | + (setq cases (cons "" (delete "" cases)))) |
| 3511 | + (setq nmzdir-case-alist nil) |
| 3512 | + (setq case-alist nil) |
| 3513 | + (setq gcase nil) |
| 3514 | + (while (setq case (car cases)) |
| 3515 | + (setq nmzdir (mew-nmz-expand-folder (if (string= case "") |
| 3516 | + prefix |
| 3517 | + (concat case ":" prefix)))) |
| 3518 | + (if (setq alst (assoc nmzdir nmzdir-case-alist)) |
| 3519 | + (progn |
| 3520 | + (setq ocase (car (assoc (cdr alst) case-alist))) |
| 3521 | + (setq case-alist (cons (cons case ocase) case-alist))) |
| 3522 | + (setq nmzdir-case-alist |
| 3523 | + (cons (cons nmzdir case) nmzdir-case-alist)) |
| 3524 | + (setq case-alist (cons (cons case case) case-alist)) |
| 3525 | + (setq gcase (cons case gcase))) |
| 3526 | + (setq cases (cdr cases))) |
| 3527 | + (setq gcase (nreverse gcase)) |
| 3528 | + (cond |
| 3529 | + ((mew-folder-imapp prefix) |
| 3530 | + (setq mew-nmz-imap-case-alist (nreverse case-alist)) |
| 3531 | + (while (setq case (car gcase)) |
| 3532 | + (mew-nmz-gather-indexed-folder case (mew-imap-folder-alist case) 'imap) |
| 3533 | + (setq gcase (cdr gcase)))) |
| 3534 | + ((mew-folder-popp prefix) |
| 3535 | + (setq mew-nmz-pop-case-alist (nreverse case-alist)) |
| 3536 | + (while (setq case (car gcase)) |
| 3537 | + (mew-nmz-gather-indexed-folder case `((,mew-pop-inbox-folder))) |
| 3538 | + (setq gcase (cdr gcase)))) |
| 3539 | + ((mew-folder-nntpp prefix) |
| 3540 | + (setq mew-nmz-nntp-case-alist (nreverse case-alist)) |
| 3541 | + (while (setq case (car gcase)) |
| 3542 | + (mew-nmz-gather-indexed-folder case (mew-nntp-folder-alist case) 'nntp) |
| 3543 | + (setq gcase (cdr gcase)))) |
| 3544 | + (t ;; local |
| 3545 | + (mew-nmz-gather-indexed-folder nil (mew-local-folder-alist))))) |
| 3546 | + (mew-nmz-cache-save))) |
| 3547 | + (message "mew-nmz setup...done") |
| 3548 | + (setq mew-nmz-setup-p t) |
| 3549 | + (run-hooks 'mew-nmz-setup-hook))) |
| 3550 | + |
| 3551 | +(defun mew-nmz-status-update () |
| 3552 | + (mew-nmz-cleanup 'remove)) |
| 3553 | + |
| 3554 | +(defconst mew-nmz-cache-parts '(imap-case nntp-case pop-case fld-index url-fld)) |
| 3555 | + |
| 3556 | +(defun mew-nmz-cleanup (&optional remove) |
| 3557 | + (if remove (mew-nmz-cache-remove)) |
| 3558 | + (setq mew-nmz-setup-p nil) |
| 3559 | + (let ((parts (copy-sequence mew-nmz-cache-parts))) |
| 3560 | + (dolist (part parts) |
| 3561 | + (set (mew-nmz-cache-alist-name part) nil)))) |
| 3562 | + |
| 3563 | +(defun mew-nmz-cache-save () |
| 3564 | + (when (stringp mew-nmz-cache-file-prefix) |
| 3565 | + (let ((parts (copy-sequence mew-nmz-cache-parts)) |
| 3566 | + file alist) |
| 3567 | + (dolist (part parts) |
| 3568 | + (setq file (mew-nmz-cache-file-name part)) |
| 3569 | + (setq alist (symbol-value (mew-nmz-cache-alist-name part))) |
| 3570 | + (mew-lisp-save file alist 'nobackup 'unlimit))))) |
| 3571 | + |
| 3572 | +(defun mew-nmz-cache-load () |
| 3573 | + (when (stringp mew-nmz-cache-file-prefix) |
| 3574 | + (let ((parts (copy-sequence mew-nmz-cache-parts)) |
| 3575 | + file) |
| 3576 | + (catch 'noexist |
| 3577 | + (dolist (part parts) |
| 3578 | + (setq file (mew-nmz-cache-file-name part)) |
| 3579 | + (if (file-readable-p file) |
| 3580 | + (set (mew-nmz-cache-alist-name part) (mew-lisp-load file)) |
| 3581 | + (throw 'noexist nil))) |
| 3582 | + t)))) |
| 3583 | + |
| 3584 | +(defun mew-nmz-cache-remove () |
| 3585 | + (when (stringp mew-nmz-cache-file-prefix) |
| 3586 | + (let ((parts (copy-sequence mew-nmz-cache-parts)) |
| 3587 | + file) |
| 3588 | + (dolist (part parts) |
| 3589 | + (setq file (mew-nmz-cache-file-name part)) |
| 3590 | + (when (and (file-exists-p file) (file-writable-p file)) |
| 3591 | + (delete-file file)))))) |
| 3592 | + |
| 3593 | +;; mew-nmz-fixer |
| 3594 | +;; to be continue ... |
| 3595 | + |
| 3596 | +(provide 'mew-nmz) |
| 3597 | + |
| 3598 | +;;; Copyright Notice: |
| 3599 | + |
| 3600 | +;; Copyright (C) 1999-2007 Hideyuki SHIRAI |
| 3601 | +;; Copyright (C) 1994-2007 Mew developing team. |
| 3602 | +;; All rights reserved. |
| 3603 | + |
| 3604 | +;; Redistribution and use in source and binary forms, with or without |
| 3605 | +;; modification, are permitted provided that the following conditions |
| 3606 | +;; are met: |
| 3607 | +;; |
| 3608 | +;; 1. Redistributions of source code must retain the above copyright |
| 3609 | +;; notice, this list of conditions and the following disclaimer. |
| 3610 | +;; 2. Redistributions in binary form must reproduce the above copyright |
| 3611 | +;; notice, this list of conditions and the following disclaimer in the |
| 3612 | +;; documentation and/or other materials provided with the distribution. |
| 3613 | +;; 3. Neither the name of the team nor the names of its contributors |
| 3614 | +;; may be used to endorse or promote products derived from this software |
| 3615 | +;; without specific prior written permission. |
| 3616 | +;; |
| 3617 | +;; THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS'' AND |
| 3618 | +;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 3619 | +;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 3620 | +;; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TEAM OR CONTRIBUTORS BE |
| 3621 | +;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 3622 | +;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 3623 | +;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 3624 | +;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 3625 | +;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 3626 | +;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 3627 | +;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 3628 | + |
| 3629 | +;;; mew-nmz.el ends here |
| 3630 | diff -urN mew.orig/contrib/mew-refile-view.el mew/contrib/mew-refile-view.el |
| 3631 | --- mew.orig/contrib/mew-refile-view.el 1970-01-01 09:00:00.000000000 +0900 |
| 3632 | +++ mew/contrib/mew-refile-view.el 2011-06-15 00:20:15.000000000 +0900 |
| 3633 | @@ -0,0 +1,443 @@ |
| 3634 | +;;; mew-refile-view.el --- View refile alist |
| 3635 | + |
| 3636 | +;; Author: Takashi P.KATOH <[email protected]> |
| 3637 | +;; Created: Oct 22, 1998 |
| 3638 | +;; Revised: Jan 06, 2004 |
| 3639 | + |
| 3640 | +;;; Code: |
| 3641 | + |
| 3642 | +(defconst mew-refile-view-version "mew-refile-view.el version 0.07") |
| 3643 | + |
| 3644 | +(require 'mew) |
| 3645 | + |
| 3646 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 3647 | +;;; |
| 3648 | +;;; User customize variables |
| 3649 | +;;; |
| 3650 | + |
| 3651 | +;; -> mew-vars.el ? |
| 3652 | +(defvar mew-refile-view-exec-confirm t |
| 3653 | + "*Non nil means `mew-refile-view-exec' prompts the user for |
| 3654 | +confirmation before refiling.") |
| 3655 | + |
| 3656 | +(defvar mew-refile-view-show-trash nil |
| 3657 | + "*Non nil means trash folder (i.e. delete-marked messages) |
| 3658 | +will be also shown.") |
| 3659 | + |
| 3660 | +(defvar mew-refile-view-mode-hook nil) |
| 3661 | +(defvar mew-refile-view-mode-map nil) |
| 3662 | + |
| 3663 | +(defvar mew-refile-view-mode-menu-spec |
| 3664 | + '("Mew/RefileView" |
| 3665 | + ["Next page" scroll-up t] |
| 3666 | + ["Prev page" scroll-down t] |
| 3667 | + ["Top" beginning-of-buffer t] |
| 3668 | + ["Bottom" end-of-buffer t] |
| 3669 | + ["Prev message" mew-refile-view-prev-msg t] |
| 3670 | + ["Next message" mew-refile-view-next-msg t] |
| 3671 | + "----" |
| 3672 | + ["Show again" mew-refile-view-again t] |
| 3673 | + ["Goto summary" mew-refile-view-goto-summary t] |
| 3674 | + ["Unmark (single refile folder)" mew-refile-view-unmark-one t] |
| 3675 | + ["Unmark" mew-refile-view-unmark t] |
| 3676 | + ["Refile" mew-refile-view-refile t] |
| 3677 | + ["Delete" mew-refile-view-delete t] |
| 3678 | + ["Quit" mew-refile-view-quit t] |
| 3679 | + )) |
| 3680 | + |
| 3681 | +(if mew-refile-view-mode-map |
| 3682 | + () |
| 3683 | + (setq mew-refile-view-mode-map (make-sparse-keymap)) |
| 3684 | + (define-key mew-refile-view-mode-map " " 'scroll-up) |
| 3685 | + (define-key mew-refile-view-mode-map "\177" 'scroll-down) |
| 3686 | + (define-key mew-refile-view-mode-map "." 'mew-refile-view-goto-summary) |
| 3687 | + (define-key mew-refile-view-mode-map "h" 'mew-refile-view-goto-summary) |
| 3688 | + (define-key mew-refile-view-mode-map "n" 'mew-refile-view-next-msg) |
| 3689 | + (define-key mew-refile-view-mode-map "p" 'mew-refile-view-prev-msg) |
| 3690 | + (define-key mew-refile-view-mode-map "N" 'mew-refile-view-next-fld) |
| 3691 | + (define-key mew-refile-view-mode-map "P" 'mew-refile-view-prev-fld) |
| 3692 | + (define-key mew-refile-view-mode-map "l" 'mew-refile-view-again) |
| 3693 | + (define-key mew-refile-view-mode-map "u" 'mew-refile-view-unmark-one) |
| 3694 | + (define-key mew-refile-view-mode-map "U" 'mew-refile-view-unmark) |
| 3695 | + (define-key mew-refile-view-mode-map "o" 'mew-refile-view-refile) |
| 3696 | + (define-key mew-refile-view-mode-map "d" 'mew-refile-view-delete) |
| 3697 | + (define-key mew-refile-view-mode-map "x" 'mew-refile-view-exec) |
| 3698 | + (define-key mew-refile-view-mode-map "q" 'mew-refile-view-quit) |
| 3699 | + (define-key mew-refile-view-mode-map "Q" 'mew-refile-view-exit) |
| 3700 | + (define-key mew-refile-view-mode-map "<" 'beginning-of-buffer) |
| 3701 | + (define-key mew-refile-view-mode-map ">" 'end-of-buffer) |
| 3702 | + ) |
| 3703 | + |
| 3704 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 3705 | +;;; |
| 3706 | +;;; Refile view mode |
| 3707 | +;;; |
| 3708 | + |
| 3709 | +(defun mew-re-search-forward-and-backward (regexp bound noerror) |
| 3710 | + (or (re-search-forward regexp bound noerror) |
| 3711 | + (re-search-backward regexp bound noerror))) |
| 3712 | + |
| 3713 | +;; -> mew-vars ? |
| 3714 | +(defconst mew-refile-view-folder-regex "^[*+=]") |
| 3715 | +(defvar mew-original-folder nil) |
| 3716 | + |
| 3717 | +(defun mew-assoc-add (key alist mem) |
| 3718 | + (append (list (append (or (assoc key alist) (list key)) (list mem))) |
| 3719 | + (delete (assoc key alist) alist))) |
| 3720 | + |
| 3721 | +(defun mew-car-string< (a1 a2) |
| 3722 | + (let ((k1 (car a1)) (k2 (car a2))) |
| 3723 | + (string< k1 k2))) |
| 3724 | + |
| 3725 | +(defun mew-refile-view-make-alist (msg) |
| 3726 | + ;; (mew-sinfo-get-refile) -> '(("+foo" "1" "2") ("+bar" "4" "3")) |
| 3727 | + (let ((alist |
| 3728 | + (mapcar '(lambda (msg) (assoc msg (mew-sinfo-get-refile))) msg)) |
| 3729 | + result) |
| 3730 | + (while alist |
| 3731 | + (let ((flist (cdr (car alist)))) |
| 3732 | + (while flist |
| 3733 | + (setq result (mew-assoc-add (car flist) result (car (car alist))) |
| 3734 | + flist (cdr flist)))) |
| 3735 | + (setq alist (cdr alist))) |
| 3736 | + result)) |
| 3737 | + |
| 3738 | +(defun mew-refile-view (&optional prefix) |
| 3739 | + (interactive "P") |
| 3740 | + (mew-pickable |
| 3741 | + (if (interactive-p) |
| 3742 | + (mew-current-set-window-config)) |
| 3743 | + (let* ((folder (buffer-name)) |
| 3744 | + (bufname (format "*Mew refile view* (%s)" folder)) |
| 3745 | + (mew-refile-view-show-trash (or prefix mew-refile-view-show-trash)) |
| 3746 | + (refile (mew-summary-mark-collect mew-mark-refile |
| 3747 | + (point-min) (point-max))) |
| 3748 | + (trash |
| 3749 | + (if mew-refile-view-show-trash |
| 3750 | + (mew-summary-mark-collect mew-mark-delete |
| 3751 | + (point-min) (point-max)) |
| 3752 | + nil)) |
| 3753 | + (unlink |
| 3754 | + (if mew-refile-view-show-trash |
| 3755 | + (mew-summary-mark-collect mew-mark-unlink |
| 3756 | + (point-min) (point-max)) |
| 3757 | + nil)) |
| 3758 | + (ofld (substring folder 1)) |
| 3759 | + tmp) |
| 3760 | + (if (and (mew-thread-p) (get-buffer ofld)) |
| 3761 | + (progn |
| 3762 | + (save-excursion |
| 3763 | + (set-buffer ofld) |
| 3764 | + (setq tmp (mew-sinfo-get-refile))) |
| 3765 | + (mew-sinfo-set-refile tmp))) |
| 3766 | + (if (not (or refile trash unlink)) |
| 3767 | + (progn |
| 3768 | + (message "No refile marks") |
| 3769 | + (if (buffer-live-p (get-buffer bufname)) |
| 3770 | + (progn |
| 3771 | + (set-buffer bufname) |
| 3772 | + (setq buffer-read-only nil) |
| 3773 | + (erase-buffer) |
| 3774 | + (insert "No refile marks\n") |
| 3775 | + (setq buffer-read-only t)))) |
| 3776 | + (let ((alist (mew-refile-view-make-alist refile)) |
| 3777 | + tmpalist view summary num numlist) |
| 3778 | + (setq view (pop-to-buffer bufname)) |
| 3779 | + (setq buffer-read-only nil) |
| 3780 | + (erase-buffer) |
| 3781 | + (mew-buffers-setup bufname) |
| 3782 | + |
| 3783 | + (setq tmpalist alist) |
| 3784 | + (setq alist nil) |
| 3785 | + (while tmpalist |
| 3786 | + (if (string= mew-trash-folder (car (car tmpalist))) |
| 3787 | + (progn |
| 3788 | + (setq trash (append (cdr (car tmpalist)) trash)) |
| 3789 | + (setq alist (append (cdr tmpalist) alist)) |
| 3790 | + (setq tmpalist nil)) |
| 3791 | + (setq alist (cons (car tmpalist) alist)) |
| 3792 | + (setq tmpalist (cdr tmpalist)))) |
| 3793 | + ;; |
| 3794 | + (setq alist (sort alist 'mew-car-string<)) |
| 3795 | + (if trash |
| 3796 | + (setq alist (append alist (list (cons mew-trash-folder trash))))) |
| 3797 | + (if unlink |
| 3798 | + (setq alist (append alist (list (cons "+REMOVE" unlink))))) |
| 3799 | + (while alist |
| 3800 | + (set-buffer view) |
| 3801 | + (insert (concat (car (car alist)) "\n")) |
| 3802 | + (setq numlist (sort (mapcar 'string-to-int (cdr (car alist))) '<)) |
| 3803 | + (while numlist |
| 3804 | + (setq num (car numlist) |
| 3805 | + numlist (cdr numlist)) |
| 3806 | + ;; |
| 3807 | + (set-buffer (get-buffer folder)) |
| 3808 | + ;; Mew4 |
| 3809 | + (when (mew-re-search-forward-and-backward |
| 3810 | + (mew-regex-sumsyn-msg (int-to-string num)) nil t) |
| 3811 | + (if (mew-thread-p) |
| 3812 | + (setq summary |
| 3813 | + (concat |
| 3814 | + (mew-buffer-substring (line-beginning-position) |
| 3815 | + (progn (move-to-column (mew-vinfo-get-column)) |
| 3816 | + (point))) |
| 3817 | + (mew-buffer-substring (let ((mew-use-thread-cursor t)) |
| 3818 | + (progn (mew-thread-move-cursor) (point))) |
| 3819 | + (line-end-position)))) |
| 3820 | + (setq summary (mew-buffer-substring (line-beginning-position) |
| 3821 | + (line-end-position)))) |
| 3822 | + ;; |
| 3823 | + (set-buffer view) |
| 3824 | + (insert summary) |
| 3825 | + (let ((mew-highlight-mark-folder-list (list bufname))) |
| 3826 | + (mew-mark-unmark)) |
| 3827 | + (insert "\n"))) |
| 3828 | + (insert "\n") |
| 3829 | + (setq alist (cdr alist))) |
| 3830 | + (goto-char (point-min)) |
| 3831 | + (mew-refile-view-mode |
| 3832 | + (if (string-match mew-refile-view-folder-regex folder) |
| 3833 | + folder nil))) |
| 3834 | + )))) |
| 3835 | + |
| 3836 | +(defun mew-refile-view-goto-summary () |
| 3837 | + "Get back to Summary mode." |
| 3838 | + (interactive) |
| 3839 | + (let (num) |
| 3840 | + (save-excursion |
| 3841 | + (beginning-of-line) |
| 3842 | + (setq num (if (looking-at (concat "^[^\r\n]+" mew-regex-sumsyn-short)) |
| 3843 | + (mew-match-string 2)))) |
| 3844 | + (if (not (and mew-original-folder (get-buffer mew-original-folder))) |
| 3845 | + (progn |
| 3846 | + (message "No Summary buffer for %s" mew-original-folder) |
| 3847 | + nil) |
| 3848 | + (if (get-buffer-window mew-original-folder) |
| 3849 | + (select-window (get-buffer-window mew-original-folder)) |
| 3850 | + (mew-summary-switch-to-folder mew-original-folder)) |
| 3851 | + (if num (mew-summary-move-and-display num)) |
| 3852 | + t))) |
| 3853 | + |
| 3854 | +(defun mew-refile-view-again () |
| 3855 | + (interactive) |
| 3856 | + (if (not (and mew-original-folder (get-buffer mew-original-folder))) |
| 3857 | + (message "No Summary buffer for %s" mew-original-folder) |
| 3858 | + (set-buffer mew-original-folder) |
| 3859 | + (mew-refile-view))) |
| 3860 | + |
| 3861 | +(defun mew-refile-view-quit () |
| 3862 | + "Exit from mew-refile-view-mode." |
| 3863 | + (interactive) |
| 3864 | + (bury-buffer (current-buffer)) |
| 3865 | + (delete-windows-on (current-buffer)) |
| 3866 | + (mew-current-get-window-config)) |
| 3867 | + |
| 3868 | +(defun mew-refile-view-exit () |
| 3869 | + "Exit from mew-refile-view-mode." |
| 3870 | + (interactive) |
| 3871 | + (let ((buf (current-buffer))) |
| 3872 | + (delete-windows-on (current-buffer)) |
| 3873 | + (kill-buffer buf) |
| 3874 | + (mew-current-get-window-config))) |
| 3875 | + |
| 3876 | +(defun mew-refile-view-next-msg () |
| 3877 | + "Move to next message in Mew refile view buffer." |
| 3878 | + (interactive) |
| 3879 | + (let ((orig (point))) |
| 3880 | + (end-of-line) |
| 3881 | + (if (re-search-forward mew-regex-sumsyn-short nil t) |
| 3882 | + (beginning-of-line) |
| 3883 | + (goto-char orig)))) |
| 3884 | + |
| 3885 | +(defun mew-refile-view-prev-msg () |
| 3886 | + "Move to previous message in Mew refile view buffer." |
| 3887 | + (interactive) |
| 3888 | + (let ((orig (point))) |
| 3889 | + (beginning-of-line) |
| 3890 | + (if (re-search-backward mew-regex-sumsyn-short nil t) |
| 3891 | + (beginning-of-line) |
| 3892 | + (goto-char orig)))) |
| 3893 | + |
| 3894 | +(defun mew-refile-view-next-fld () |
| 3895 | + (interactive) |
| 3896 | + (let ((orig (point))) |
| 3897 | + (end-of-line) |
| 3898 | + (if (or (re-search-forward "^[+%=]" nil t) |
| 3899 | + (re-search-forward "^$" nil t)) |
| 3900 | + (beginning-of-line) |
| 3901 | + (goto-char orig)))) |
| 3902 | + |
| 3903 | +(defun mew-refile-view-prev-fld () |
| 3904 | + (interactive) |
| 3905 | + (let ((orig (point))) |
| 3906 | + (beginning-of-line) |
| 3907 | + (if (re-search-backward "^[+%=]" nil t) |
| 3908 | + (beginning-of-line) |
| 3909 | + (goto-char orig)))) |
| 3910 | + |
| 3911 | +(defun mew-refile-view-exec () |
| 3912 | + (interactive) |
| 3913 | + (if (not (and mew-original-folder (get-buffer mew-original-folder))) |
| 3914 | + (message "No Summary buffer for %s" mew-original-folder) |
| 3915 | + (if (or (not mew-refile-view-exec-confirm) |
| 3916 | + ;; or yes-or-no-p? |
| 3917 | + (y-or-n-p "Execute refiling for these messages? ")) |
| 3918 | + (let ((fld mew-original-folder) |
| 3919 | + thread) |
| 3920 | + (save-excursion |
| 3921 | + (if (save-excursion |
| 3922 | + (set-buffer fld) |
| 3923 | + (and (mew-thread-p) |
| 3924 | + (get-buffer (substring fld 1)))) |
| 3925 | + (progn |
| 3926 | + (setq thread t) |
| 3927 | + (set-buffer (substring fld 1))) |
| 3928 | + (set-buffer fld)) |
| 3929 | + (mew-summary-exec)) |
| 3930 | + (mew-refile-view-exit) |
| 3931 | + (if thread |
| 3932 | + (progn |
| 3933 | + (mew-kill-buffer fld) |
| 3934 | + (mew-summary-switch-to-folder (substring fld 1)))))))) |
| 3935 | + |
| 3936 | + |
| 3937 | +(defun mew-refile-view-unmark-one () |
| 3938 | + "Unmark this message. |
| 3939 | +If this message has multi-refile folders, remove one of them." |
| 3940 | + (interactive) |
| 3941 | + (mew-refile-view-msg 'undo 'one)) |
| 3942 | + |
| 3943 | +(defun mew-refile-view-unmark () |
| 3944 | + "Unmark this message." |
| 3945 | + (interactive) |
| 3946 | + (mew-refile-view-msg 'undo)) |
| 3947 | + |
| 3948 | +(defun mew-refile-view-refile () |
| 3949 | + "Refile this message." |
| 3950 | + (interactive) |
| 3951 | + (mew-refile-view-msg 'refile)) |
| 3952 | + |
| 3953 | +(defun mew-refile-view-delete () |
| 3954 | + "Delete this message." |
| 3955 | + (interactive) |
| 3956 | + (mew-refile-view-msg 'delete)) |
| 3957 | + |
| 3958 | +(defun mew-refile-view-msg (op &optional one) |
| 3959 | + (beginning-of-line) |
| 3960 | + (let ((orig-point (point)) |
| 3961 | + (orig-buff (current-buffer)) |
| 3962 | + msg reffld bufref fld ofld tmp) |
| 3963 | + (if (not (looking-at (concat "^[^\r\n]+" mew-regex-sumsyn-short))) |
| 3964 | + (message "No message") |
| 3965 | + (setq msg (mew-match-string 2)) |
| 3966 | + (if one |
| 3967 | + (save-excursion |
| 3968 | + (if (re-search-backward |
| 3969 | + (concat mew-refile-view-folder-regex ".+$") |
| 3970 | + nil t) |
| 3971 | + (setq reffld (buffer-substring (match-beginning 0) |
| 3972 | + (match-end 0)))))) |
| 3973 | + ;; in mew summary buffer |
| 3974 | + (if (mew-refile-view-goto-summary) |
| 3975 | + (mew-pickable |
| 3976 | + (cond |
| 3977 | + ((eq op 'refile) |
| 3978 | + (mew-summary-refile)) |
| 3979 | + ((eq op 'undo) |
| 3980 | + (if (not (and one msg reffld)) |
| 3981 | + (mew-summary-undo 1) |
| 3982 | + (setq bufref (assoc msg (mew-sinfo-get-refile))) |
| 3983 | + (if (< (length bufref) 3) |
| 3984 | + (mew-summary-undo 1) |
| 3985 | + ;; remove 1 folder |
| 3986 | + (setq bufref (delete reffld bufref)) |
| 3987 | + (setq tmp (mew-sinfo-get-refile)) |
| 3988 | + (mew-replace-with tmp bufref msg) |
| 3989 | + (mew-sinfo-set-refile tmp) |
| 3990 | + (if (mew-thread-p) |
| 3991 | + (progn |
| 3992 | + (setq fld (mew-summary-folder-name 'ext)) |
| 3993 | + (setq ofld (substring fld 1)) |
| 3994 | + (if (get-buffer ofld) |
| 3995 | + (save-excursion |
| 3996 | + (set-buffer ofld) |
| 3997 | + (mew-sinfo-set-refile tmp)))))))) |
| 3998 | + ((eq op 'delete) |
| 3999 | + (mew-summary-delete 1))) |
| 4000 | + (mew-refile-view))) |
| 4001 | + ;; we are out of mew summary buffer now |
| 4002 | + (pop-to-buffer orig-buff) |
| 4003 | + (if (< orig-point (point-max)) |
| 4004 | + (goto-char orig-point) |
| 4005 | + (goto-char (point-max))) |
| 4006 | + (beginning-of-line)))) |
| 4007 | + |
| 4008 | +(defun mew-refile-view-mode (&optional folder) |
| 4009 | + "Major mode for viewing refile alist. |
| 4010 | +The keys defined for this mode are: |
| 4011 | + |
| 4012 | +SPC Scroll up this message. |
| 4013 | +DEL Back-scroll this message. |
| 4014 | +. Get back to Summary mode. |
| 4015 | +h Get back to Summary mode. |
| 4016 | +n Move to next message. |
| 4017 | +p Move to previous message. |
| 4018 | +N Move to next folder. |
| 4019 | +P Move to previous folder. |
| 4020 | +l Reshow . |
| 4021 | +u Unmark. |
| 4022 | +o Refile again. |
| 4023 | +d Put delete mark on this message. |
| 4024 | +x Process marked messages. |
| 4025 | +q Quit. |
| 4026 | +Q Exit. |
| 4027 | +< Go to top. |
| 4028 | +> Go to bottom. |
| 4029 | +" |
| 4030 | + (interactive) |
| 4031 | + (setq major-mode 'mew-refile-view-mode) |
| 4032 | + (setq mode-name "Refile-View") |
| 4033 | + (setq mode-line-buffer-identification mew-mode-line-id) |
| 4034 | + (use-local-map mew-refile-view-mode-map) |
| 4035 | + (setq buffer-read-only t) |
| 4036 | + (setq selective-display t) |
| 4037 | + (setq selective-display-ellipses nil) |
| 4038 | + (setq truncate-lines t) |
| 4039 | + (make-local-variable 'mew-original-folder) |
| 4040 | + (setq mew-original-folder folder) |
| 4041 | + (mew-buffers-setup (buffer-name)) |
| 4042 | + (run-hooks 'mew-refile-view-mode-hook)) |
| 4043 | + |
| 4044 | +(provide 'mew-refile-view) |
| 4045 | + |
| 4046 | +;;; Copyright Notice: |
| 4047 | + |
| 4048 | +;; Copyright (C) 1998, 1999 Mew developing team. |
| 4049 | +;; All rights reserved. |
| 4050 | + |
| 4051 | +;; Redistribution and use in source and binary forms, with or without |
| 4052 | +;; modification, are permitted provided that the following conditions |
| 4053 | +;; are met: |
| 4054 | +;; |
| 4055 | +;; 1. Redistributions of source code must retain the above copyright |
| 4056 | +;; notice, this list of conditions and the following disclaimer. |
| 4057 | +;; 2. Redistributions in binary form must reproduce the above copyright |
| 4058 | +;; notice, this list of conditions and the following disclaimer in the |
| 4059 | +;; documentation and/or other materials provided with the distribution. |
| 4060 | +;; 3. Neither the name of the team nor the names of its contributors |
| 4061 | +;; may be used to endorse or promote products derived from this software |
| 4062 | +;; without specific prior written permission. |
| 4063 | +;; |
| 4064 | +;; THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS'' AND |
| 4065 | +;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 4066 | +;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 4067 | +;; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TEAM OR CONTRIBUTORS BE |
| 4068 | +;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 4069 | +;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 4070 | +;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 4071 | +;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 4072 | +;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 4073 | +;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 4074 | +;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 4075 | + |
| 4076 | +;;; mew-refile-view.el ends here |
| 4077 | diff -urN mew.orig/contrib/mew-toolbar-frame.el mew/contrib/mew-toolbar-frame.el |
| 4078 | --- mew.orig/contrib/mew-toolbar-frame.el 1970-01-01 09:00:00.000000000 +0900 |
| 4079 | +++ mew/contrib/mew-toolbar-frame.el 2011-06-15 00:20:15.000000000 +0900 |
| 4080 | @@ -0,0 +1,90 @@ |
| 4081 | +;;; mew-toolbar-frame.el -*-Emacs-Lisp-*- |
| 4082 | +;;; |
| 4083 | +;;; Commentary: |
| 4084 | +;;; Run Mew from toolbar in a separate frame. |
| 4085 | +;;; |
| 4086 | +;;; Keywords: |
| 4087 | +;;; Mew Xemacs ToolBar Frame |
| 4088 | +;;; |
| 4089 | +;;; Time-stamp: <99/07/02 16:37:17 jado@sophia> |
| 4090 | + |
| 4091 | +;;; How to use: |
| 4092 | +;;; Require it when initialize. |
| 4093 | + |
| 4094 | +;;; Code: |
| 4095 | + |
| 4096 | +(provide 'mew-toolbar-frame) |
| 4097 | + |
| 4098 | +;;; |
| 4099 | + |
| 4100 | +(setq toolbar-mail-reader 'Mew) |
| 4101 | +(setq toolbar-mail-commands-alist |
| 4102 | + (cons '(Mew . toolbar-mew) toolbar-mail-commands-alist)) |
| 4103 | + |
| 4104 | +(defvar toolbar-mail-use-separate-frame t |
| 4105 | + "*Whether Mew is invoked in a separate frame.") |
| 4106 | +(defvar toolbar-mail-frame nil |
| 4107 | + "The frame in which Mew is displayed.") |
| 4108 | +(defvar toolbar-mail-frame-plist nil |
| 4109 | + "*The properties of the frame in which mail is displayed.") |
| 4110 | +(define-obsolete-variable-alias 'toolbar-mail-frame-properties |
| 4111 | + 'toolbar-mail-frame-plist) |
| 4112 | + |
| 4113 | +(defun toolbar-mew () |
| 4114 | + "Run Mew in a separate frame." |
| 4115 | + (interactive) |
| 4116 | + (if (not toolbar-mail-use-separate-frame) |
| 4117 | + (mew) |
| 4118 | + (unless (frame-live-p toolbar-mail-frame) |
| 4119 | + (setq toolbar-mail-frame (make-frame toolbar-mail-frame-plist)) |
| 4120 | + (add-hook 'mew-suspend-hook |
| 4121 | + (lambda () |
| 4122 | + (when (frame-live-p toolbar-mail-frame) |
| 4123 | + (if (cdr (frame-list)) |
| 4124 | + (delete-frame toolbar-mail-frame)) |
| 4125 | + (setq toolbar-mail-frame nil)))) |
| 4126 | + (add-hook 'mew-quit-hook |
| 4127 | + (lambda () |
| 4128 | + (when (frame-live-p toolbar-mail-frame) |
| 4129 | + (if (cdr (frame-list)) |
| 4130 | + (delete-frame toolbar-mail-frame)) |
| 4131 | + (setq toolbar-mail-frame nil)))) |
| 4132 | + (select-frame toolbar-mail-frame) |
| 4133 | + (mew)) |
| 4134 | + (when (framep toolbar-mail-frame) |
| 4135 | + (when (frame-iconified-p toolbar-mail-frame) |
| 4136 | + (deiconify-frame toolbar-mail-frame)) |
| 4137 | + (select-frame toolbar-mail-frame) |
| 4138 | + (raise-frame toolbar-mail-frame)))) |
| 4139 | + |
| 4140 | +;;; Copyright Notice: |
| 4141 | + |
| 4142 | +;; Copyright (C) 1999 Mew developing team. |
| 4143 | +;; All rights reserved. |
| 4144 | + |
| 4145 | +;; Redistribution and use in source and binary forms, with or without |
| 4146 | +;; modification, are permitted provided that the following conditions |
| 4147 | +;; are met: |
| 4148 | +;; |
| 4149 | +;; 1. Redistributions of source code must retain the above copyright |
| 4150 | +;; notice, this list of conditions and the following disclaimer. |
| 4151 | +;; 2. Redistributions in binary form must reproduce the above copyright |
| 4152 | +;; notice, this list of conditions and the following disclaimer in the |
| 4153 | +;; documentation and/or other materials provided with the distribution. |
| 4154 | +;; 3. Neither the name of the team nor the names of its contributors |
| 4155 | +;; may be used to endorse or promote products derived from this software |
| 4156 | +;; without specific prior written permission. |
| 4157 | +;; |
| 4158 | +;; THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS'' AND |
| 4159 | +;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 4160 | +;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 4161 | +;; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TEAM OR CONTRIBUTORS BE |
| 4162 | +;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 4163 | +;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 4164 | +;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 4165 | +;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 4166 | +;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 4167 | +;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 4168 | +;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 4169 | + |
| 4170 | +;;; mew-toolbar-frame.el ends here |