| 1 |
;;; mew-exec.el |
| 2 |
|
| 3 |
;; Author: Kazu Yamamoto <[email protected]> |
| 4 |
;; Created: Mar 2, 1997 |
| 5 |
|
| 6 |
;;; Code: |
| 7 |
|
| 8 |
(require 'mew) |
| 9 |
|
| 10 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 11 |
;;; |
| 12 |
;;; exec-func |
| 13 |
;;; |
| 14 |
|
| 15 |
(defun mew-mark-kill-refile (src msg) |
| 16 |
(let ((refinfo (mew-refile-get msg)) |
| 17 |
myself) |
| 18 |
(setq myself (or (null refinfo) (member src refinfo))) |
| 19 |
(if myself (mew-summary-refile-remove-body)) |
| 20 |
(not myself))) |
| 21 |
|
| 22 |
(defun mew-mark-exec-refile (src msgs) |
| 23 |
"Refile MSGs from the SRC folder." |
| 24 |
(let (dsts tmp msg-dsts dsts-msgses) |
| 25 |
(dolist (msg msgs) |
| 26 |
(setq msg-dsts (mew-refile-get msg)) |
| 27 |
(setq dsts (cdr msg-dsts)) |
| 28 |
(if dsts ;; sanity check |
| 29 |
(if (setq tmp (assoc dsts dsts-msgses)) |
| 30 |
(nconc tmp (list msg)) |
| 31 |
(setq dsts-msgses (cons (list dsts msg) dsts-msgses)))) |
| 32 |
(mew-refile-reset msg)) |
| 33 |
;; refile at once |
| 34 |
(dolist (dsts-msgs dsts-msgses) |
| 35 |
(mew-summary-mv-msgs src dsts-msgs)))) |
| 36 |
|
| 37 |
(defun mew-mark-exec-unlink (src dels) |
| 38 |
"Unlink DELS from the SRC folder. |
| 39 |
DELS represents the messages to be deleted." |
| 40 |
(when dels |
| 41 |
(mew-summary-unlink-msgs src dels))) |
| 42 |
|
| 43 |
(defun mew-mark-exec-delete (src dels) |
| 44 |
"Delete messages from the SRC folder according to 'mew-trash-folder' |
| 45 |
and 'mew-trash-folder-list'. |
| 46 |
DELS represents the messages to be deleted." |
| 47 |
(when dels |
| 48 |
;; see also mew-summary-exec-remote-get-execinfo. |
| 49 |
(cond |
| 50 |
((null mew-trash-folder) |
| 51 |
(mew-summary-unlink-msgs src dels)) |
| 52 |
(mew-trash-folder-list |
| 53 |
(if (or (member src mew-trash-folder-list) |
| 54 |
(string= src mew-trash-folder)) |
| 55 |
(mew-summary-unlink-msgs src dels) |
| 56 |
(mew-summary-totrash-msgs src dels))) |
| 57 |
(t |
| 58 |
(if (string= src mew-trash-folder) |
| 59 |
(mew-summary-unlink-msgs src dels) |
| 60 |
(mew-summary-totrash-msgs src dels)))))) |
| 61 |
|
| 62 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 63 |
;;; |
| 64 |
;;; sanity-func |
| 65 |
;;; |
| 66 |
|
| 67 |
(defun mew-mark-sanity-refile (msgs) |
| 68 |
"Check the destination folder for MSGS." |
| 69 |
(let (uniq-dsts udst err-dsts dir) |
| 70 |
(dolist (msg msgs) |
| 71 |
(dolist (dst (cdr (mew-refile-get msg))) |
| 72 |
(mew-addq uniq-dsts dst))) |
| 73 |
(mew-addq uniq-dsts mew-trash-folder) |
| 74 |
(dolist (uniq-dst uniq-dsts) |
| 75 |
(setq udst (mew-case-folder mew-inherit-exec-case uniq-dst)) |
| 76 |
(setq dir (mew-expand-folder udst)) |
| 77 |
(if (file-exists-p dir) |
| 78 |
(if (file-directory-p dir) |
| 79 |
(unless (file-writable-p dir) |
| 80 |
(set-file-modes dir mew-folder-mode)) |
| 81 |
(setq err-dsts (cons udst err-dsts))) ;; NG |
| 82 |
(mew-make-directory dir))) |
| 83 |
err-dsts)) |
| 84 |
|
| 85 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 86 |
;;; |
| 87 |
;;; Unlinking, moving, to-trash |
| 88 |
;;; |
| 89 |
|
| 90 |
(defun mew-folder-suffix (folder) |
| 91 |
(if (or (mew-folder-queuep folder) (mew-folder-postqp folder)) |
| 92 |
mew-queue-info-suffix |
| 93 |
(if (mew-folder-draftp folder) |
| 94 |
mew-draft-info-suffix))) |
| 95 |
|
| 96 |
(defun mew-summary-unlink-msgs (src dels) |
| 97 |
(let ((suffix (mew-folder-suffix src)) |
| 98 |
file infofile) |
| 99 |
(dolist (del dels) |
| 100 |
(setq file (mew-expand-msg src del)) |
| 101 |
;; if file does not exist, the marked line will be deleted anyway. |
| 102 |
(mew-delete-file file) |
| 103 |
(when suffix |
| 104 |
(setq infofile (concat file suffix)) |
| 105 |
(mew-delete-file infofile))))) |
| 106 |
|
| 107 |
(defun mew-i2s (num cache) |
| 108 |
(if cache |
| 109 |
(concat "0" (number-to-string num)) ;; "0" is the mark for invalid messages |
| 110 |
(number-to-string num))) |
| 111 |
|
| 112 |
(defun mew-summary-mv-msgs (src dsts-msgs) |
| 113 |
(let* ((dsts (car dsts-msgs)) ;; (+foo +bar) |
| 114 |
(msgs (cdr dsts-msgs)) ;; (1 2 3) |
| 115 |
(srcx (mew-case:folder-folder src)) |
| 116 |
(myselfp (member srcx dsts)) |
| 117 |
(cache mew-inherit-offline) |
| 118 |
(suffix (mew-folder-suffix srcx)) |
| 119 |
msgs- srcfile dstfile dst num strnum infofile) |
| 120 |
(if myselfp |
| 121 |
;; msg stays in the src folder with the same number |
| 122 |
(progn |
| 123 |
(setq dsts (delete srcx dsts)) |
| 124 |
(dolist (msg msgs) |
| 125 |
(if (file-regular-p (mew-expand-msg src msg)) |
| 126 |
(setq msgs- (cons msg msgs-)))) |
| 127 |
(setq msgs- (nreverse msgs-)) |
| 128 |
(setq msgs msgs-)) |
| 129 |
(setq dst (mew-case-folder mew-inherit-exec-case (car dsts))) |
| 130 |
(setq dsts (cdr dsts)) |
| 131 |
(setq num (string-to-number (mew-folder-new-message dst 'num-only cache))) |
| 132 |
(dolist (msg msgs) |
| 133 |
(setq srcfile (mew-expand-msg src msg)) |
| 134 |
(when (and (file-exists-p srcfile) (file-writable-p srcfile)) |
| 135 |
(setq strnum (mew-i2s num cache)) |
| 136 |
(setq msgs- (cons strnum msgs-)) |
| 137 |
(setq dstfile (mew-expand-new-msg dst strnum)) |
| 138 |
(setq num (1+ num)) |
| 139 |
(rename-file srcfile dstfile 'override) |
| 140 |
(mew-set-file-times dstfile) |
| 141 |
(when suffix |
| 142 |
(setq infofile (concat srcfile suffix)) |
| 143 |
(mew-delete-file infofile)))) |
| 144 |
(mew-touch-folder dst) |
| 145 |
(setq msgs- (nreverse msgs-)) |
| 146 |
(setq src dst)) ;; myselfp |
| 147 |
(dolist (ent dsts) |
| 148 |
(setq dst (mew-case-folder mew-inherit-exec-case ent)) |
| 149 |
(setq num (string-to-number (mew-folder-new-message dst 'num-only cache))) |
| 150 |
(dolist (msg msgs-) |
| 151 |
(setq srcfile (mew-expand-msg src msg)) |
| 152 |
(setq strnum (mew-i2s num cache)) |
| 153 |
(setq dstfile (mew-expand-new-msg dst strnum)) |
| 154 |
(setq num (1+ num)) |
| 155 |
(mew-link srcfile dstfile)) |
| 156 |
(mew-touch-folder dst)))) |
| 157 |
|
| 158 |
(defun mew-summary-totrash-msgs (src dels) |
| 159 |
(let* ((trash (mew-case-folder mew-inherit-exec-case mew-trash-folder)) |
| 160 |
(trashdir (mew-expand-folder trash)) |
| 161 |
(cache mew-inherit-offline) |
| 162 |
(suffix (mew-folder-suffix src)) |
| 163 |
num srcfile dstfile infofile) |
| 164 |
(unless (file-directory-p trashdir) (make-directory trashdir)) |
| 165 |
(setq num (string-to-number (mew-folder-new-message trash 'num-only cache))) |
| 166 |
;; must be here after ensuring that +trash exists. |
| 167 |
(dolist (del dels) |
| 168 |
(setq srcfile (mew-expand-msg src del)) ;; xxx |
| 169 |
(setq dstfile (mew-expand-new-msg trash (mew-i2s num cache))) |
| 170 |
(setq num (1+ num)) |
| 171 |
(when (file-regular-p srcfile) |
| 172 |
;; if not, the marked line will be deleted anyway. |
| 173 |
(rename-file srcfile dstfile 'override) |
| 174 |
(mew-set-file-times dstfile)) |
| 175 |
(when suffix |
| 176 |
(setq infofile (concat srcfile suffix)) |
| 177 |
(mew-delete-file infofile))) |
| 178 |
(mew-touch-folder trash))) |
| 179 |
|
| 180 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 181 |
;;; |
| 182 |
;;; Commands for mark processing |
| 183 |
;;; |
| 184 |
|
| 185 |
(defun mew-summary-exec (&optional arg) |
| 186 |
"\\<mew-summary-mode-map> Process marked messages. When called with |
| 187 |
'\\[universal-argument]', process marked messages in the specified |
| 188 |
region. To cancel the '*' mark, use '\\[mew-summary-undo]' or |
| 189 |
'\\[mew-summary-undo-all]'." |
| 190 |
(interactive "P") |
| 191 |
(let (beg end region) |
| 192 |
(if (mew-mark-active-p) (setq arg t)) |
| 193 |
(cond |
| 194 |
(arg |
| 195 |
(setq region (mew-summary-get-region)) |
| 196 |
(setq beg (car region)) |
| 197 |
(setq end (cdr region))) |
| 198 |
(t |
| 199 |
(setq beg (point-min)) |
| 200 |
(setq end (point-max)))) |
| 201 |
(mew-summary-exec-region beg end))) |
| 202 |
|
| 203 |
(defun mew-summary-exec-one (&optional arg) |
| 204 |
"Process the current marked message. |
| 205 |
When called with '\\[universal-argument]', process |
| 206 |
all marked messages before the current message." |
| 207 |
(interactive "P") |
| 208 |
(mew-summary-goto-message) |
| 209 |
(mew-decode-syntax-delete) |
| 210 |
(save-window-excursion |
| 211 |
(let (beg end) |
| 212 |
(save-excursion |
| 213 |
(beginning-of-line) |
| 214 |
(setq beg (if arg (point-min) (point))) |
| 215 |
(end-of-line) |
| 216 |
(setq end (1+ (point)))) |
| 217 |
(if (> end (point-max)) |
| 218 |
(message "No message") |
| 219 |
(mew-summary-exec-region beg end))))) |
| 220 |
|
| 221 |
(defun mew-summary-exec-delete () |
| 222 |
"Process messages marked with 'D'." |
| 223 |
(interactive) |
| 224 |
(let* ((ent (assoc mew-mark-delete mew-mark-spec)) |
| 225 |
(mew-mark-spec (list ent))) |
| 226 |
(mew-summary-exec-region (point-min) (point-max)))) |
| 227 |
|
| 228 |
(defun mew-summary-exec-unlink () |
| 229 |
"Process messages marked with 'X'." |
| 230 |
(interactive) |
| 231 |
(let* ((ent (assoc mew-mark-unlink mew-mark-spec)) |
| 232 |
(mew-mark-spec (list ent))) |
| 233 |
(mew-summary-exec-region (point-min) (point-max)))) |
| 234 |
|
| 235 |
(defun mew-summary-exec-refile (&optional arg) |
| 236 |
"Process messages marked with 'o'. |
| 237 |
If called with '\\[universal-argument]', only messages whose |
| 238 |
destination is the same as that of the current message are processed." |
| 239 |
(interactive "P") |
| 240 |
(let* ((ent (assoc mew-mark-refile mew-mark-spec)) |
| 241 |
(mew-mark-spec (list ent))) |
| 242 |
(if (not arg) |
| 243 |
(mew-summary-exec-region (point-min) (point-max)) |
| 244 |
(let* ((msg (mew-summary-message-number)) |
| 245 |
(dst (cdr (mew-refile-get msg))) |
| 246 |
func) |
| 247 |
(if (not dst) |
| 248 |
(message "No message to be refiled here") |
| 249 |
(setq func (lambda (num) (equal dst (cdr (mew-refile-get num))))) |
| 250 |
(mew-summary-exec-region (point-min) (point-max) func)))))) |
| 251 |
|
| 252 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 253 |
;;; |
| 254 |
;;; Exec region |
| 255 |
;;; |
| 256 |
|
| 257 |
(defun mew-summary-move-and-display (msg &optional redisplay) |
| 258 |
(when (mew-summary-search-msg msg) |
| 259 |
(mew-summary-display redisplay))) |
| 260 |
|
| 261 |
(defun mew-summary-go-back-summary (key) |
| 262 |
(let ((msg (mew-summary-message-number)) |
| 263 |
(fld (mew-summary-physical-folder))) |
| 264 |
(if (not (and fld (get-buffer fld))) |
| 265 |
(message "No physical folder") |
| 266 |
(mew-summary-visit-folder fld nil 'no-ls) |
| 267 |
(if msg |
| 268 |
(mew-summary-move-and-display msg) |
| 269 |
(goto-char (point-max))) |
| 270 |
(message "Now in %s. Type '%s' again" fld key)))) |
| 271 |
|
| 272 |
(defun mew-summary-exec-region (beg end &optional func) |
| 273 |
(let ((folder (mew-sinfo-get-folder))) |
| 274 |
(cond |
| 275 |
((mew-folder-nntpp folder) |
| 276 |
(message "This command cannot be used in this folder")) |
| 277 |
((mew-folder-remotep folder) |
| 278 |
(message "Refiling and deleting...") |
| 279 |
(force-mode-line-update) |
| 280 |
(mew-summary-exec-remote beg end func)) |
| 281 |
((mew-virtual-p) |
| 282 |
(mew-summary-go-back-summary |
| 283 |
(mew-substitute-for-summary "\\[mew-summary-exec]"))) |
| 284 |
(t |
| 285 |
(message "Refiling and deleting...") |
| 286 |
(force-mode-line-update) |
| 287 |
(mew-summary-exec-local beg end func))))) |
| 288 |
|
| 289 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 290 |
;;; |
| 291 |
;;; Refile log |
| 292 |
;;; |
| 293 |
|
| 294 |
(defun mew-exec-refile-log (buf) |
| 295 |
(when (get-buffer buf) |
| 296 |
(with-current-buffer buf |
| 297 |
(mew-frwlet mew-cs-dummy mew-cs-m17n |
| 298 |
(write-region (point-min) (point-max) |
| 299 |
(expand-file-name mew-refile-log-file mew-conf-path) |
| 300 |
'append 'no-msg))) |
| 301 |
(mew-remove-buffer buf))) |
| 302 |
|
| 303 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 304 |
;;; |
| 305 |
;;; Processing marks for local |
| 306 |
;;; |
| 307 |
|
| 308 |
(defun mew-mark-kill-line () |
| 309 |
(let (start) |
| 310 |
(beginning-of-line) |
| 311 |
(setq start (point)) |
| 312 |
(forward-line) |
| 313 |
(mew-elet (delete-region start (point))))) |
| 314 |
|
| 315 |
(defun mew-summary-exec-local (beg end &optional func-decide) |
| 316 |
(when (mew-summary-exclusive-p) |
| 317 |
(save-excursion |
| 318 |
(condition-case nil |
| 319 |
(let* ((marks (mew-mark-get-all-marks)) |
| 320 |
(src (mew-summary-folder-name 'ext)) |
| 321 |
(lbuf (mew-refile-log-buffer src)) |
| 322 |
(m (copy-marker end)) |
| 323 |
(cnt 0) |
| 324 |
(case-fold-search nil) |
| 325 |
msg msgs err-folders func-exec func-sanity killp regex) |
| 326 |
(dolist (mark marks) |
| 327 |
(setq func-exec (mew-markdb-func-exec mark)) |
| 328 |
(when func-exec |
| 329 |
(setq killp (mew-markdb-killp mark)) |
| 330 |
(setq regex (mew-mark-regex mark)) |
| 331 |
(setq msgs nil) |
| 332 |
(goto-char beg) |
| 333 |
(while (re-search-forward regex m t) |
| 334 |
(setq msg (mew-summary-message-number)) |
| 335 |
(when (or (not func-decide) (funcall func-decide msg)) |
| 336 |
(setq msgs (cons msg msgs)) |
| 337 |
(cond |
| 338 |
((fboundp killp) |
| 339 |
(if (funcall killp src msg) |
| 340 |
(mew-mark-kill-line) |
| 341 |
(mew-mark-remove))) |
| 342 |
((eq killp t) |
| 343 |
(mew-mark-kill-line))))) |
| 344 |
(setq msgs (nreverse msgs)) |
| 345 |
(when msgs |
| 346 |
(when (= cnt 0) |
| 347 |
;; opening... |
| 348 |
(mew-summary-lock t "Executing") |
| 349 |
(mew-summary-reset)) |
| 350 |
(setq cnt (1+ cnt)) |
| 351 |
;; refiling and deleting... |
| 352 |
(setq func-sanity (mew-markdb-func-sanity mark)) |
| 353 |
(when (and func-sanity |
| 354 |
(setq err-folders (funcall func-sanity msgs))) |
| 355 |
(mew-summary-unlock) |
| 356 |
(mew-warn |
| 357 |
"Nothing proceeded. Folder(s) MUST be a file!: %s" |
| 358 |
(mew-join "," err-folders))) |
| 359 |
(funcall func-exec src msgs)))) |
| 360 |
(if (= cnt 0) |
| 361 |
(message "No marks") |
| 362 |
;; ending... |
| 363 |
(mew-cache-clean-up) |
| 364 |
(mew-summary-folder-cache-save) |
| 365 |
(set-buffer-modified-p nil) |
| 366 |
(mew-summary-unlock) |
| 367 |
(when (and (eobp) (not (pos-visible-in-window-p))) |
| 368 |
(forward-line -1) |
| 369 |
;; This ensures that some messages are displayed in Summary. |
| 370 |
(recenter)) |
| 371 |
(run-hooks 'mew-summary-exec-hook) |
| 372 |
(mew-exec-refile-log lbuf) |
| 373 |
(message "Refiling and deleting...done"))) |
| 374 |
(quit |
| 375 |
(set-buffer-modified-p nil) |
| 376 |
(mew-summary-unlock)))))) |
| 377 |
|
| 378 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 379 |
;;; |
| 380 |
;;; Processing marks for remote |
| 381 |
;;; |
| 382 |
|
| 383 |
(defun mew-mark-invisible-line () |
| 384 |
(let (start) |
| 385 |
(beginning-of-line) |
| 386 |
(setq start (point)) |
| 387 |
(forward-line) |
| 388 |
(mew-elet |
| 389 |
(put-text-property start (point) 'invisible t) |
| 390 |
;; For Emacs only. To make invisible text act as we want |
| 391 |
(put-text-property start (point) 'front-sticky t)))) |
| 392 |
|
| 393 |
(mew-defstruct execinfo remove kill refile move rttl dttl) |
| 394 |
(mew-defstruct refileinfo uid size delete folders) |
| 395 |
|
| 396 |
(defun mew-summary-exec-remote-get-execinfo (beg end modify &optional func-decide) |
| 397 |
;; for POP or IMAP |
| 398 |
;; If modify, marked lines get invisible. They are removed |
| 399 |
;; IMAP's sentinel. |
| 400 |
;; Otherwise, marked lines retain and they are to be processed |
| 401 |
;; by mew-summary-exec-local(). |
| 402 |
(let* ((case (mew-sinfo-get-case)) |
| 403 |
(folder (mew-sinfo-get-folder)) |
| 404 |
(m (copy-marker end)) |
| 405 |
(case-fold-search nil) |
| 406 |
(rttl 0) (dttl 0) |
| 407 |
trash trash-list lomov |
| 408 |
siz msg uid ref flds del regex trss rmvs kils refs movs |
| 409 |
refinfo refile-back) |
| 410 |
(when (mew-folder-imapp folder) |
| 411 |
;; see also mew-mark-exec-delete. |
| 412 |
(setq trash (mew-imap-trash-folder case)) |
| 413 |
(setq trash-list (mew-imap-trash-folder-list case)) |
| 414 |
(setq lomov t) |
| 415 |
(cond |
| 416 |
((null trash) |
| 417 |
) |
| 418 |
(trash-list |
| 419 |
(if (or (member folder trash-list) |
| 420 |
(string= folder trash)) |
| 421 |
(setq trash nil))) |
| 422 |
(t |
| 423 |
(if (string= folder trash) |
| 424 |
(setq trash nil))))) |
| 425 |
(save-excursion |
| 426 |
(mew-decode-syntax-delete) |
| 427 |
;; |
| 428 |
;; refile |
| 429 |
;; |
| 430 |
(when (mew-markdb-by-mark mew-mark-refile) |
| 431 |
(setq regex (mew-mark-regex mew-mark-refile)) |
| 432 |
(goto-char beg) |
| 433 |
(while (re-search-forward regex m t) |
| 434 |
(re-search-forward mew-regex-sumsyn-long) |
| 435 |
(setq msg (mew-sumsyn-message-number)) |
| 436 |
(setq uid (mew-sumsyn-message-uid)) |
| 437 |
(setq siz (mew-sumsyn-message-size)) |
| 438 |
(when (or (not func-decide) (funcall func-decide msg)) |
| 439 |
(setq refinfo (mew-refile-get msg)) |
| 440 |
(setq refile-back (cons refinfo refile-back)) |
| 441 |
(setq flds (cdr refinfo)) |
| 442 |
;; |
| 443 |
(setq del nil) |
| 444 |
(if (member folder flds) |
| 445 |
(setq flds (delete folder flds)) ;; destructive |
| 446 |
(setq del t) |
| 447 |
(when modify |
| 448 |
(if lomov |
| 449 |
(setq movs (cons msg movs)) |
| 450 |
(setq kils (cons msg kils))))) |
| 451 |
(when flds |
| 452 |
(setq ref (mew-make-refileinfo :uid uid |
| 453 |
:size siz |
| 454 |
:delete del |
| 455 |
:folders flds)) |
| 456 |
(setq refs (cons ref refs))) |
| 457 |
(if modify |
| 458 |
(if del |
| 459 |
(mew-mark-invisible-line) |
| 460 |
(mew-summary-refile-remove-body) |
| 461 |
(mew-mark-remove))))) |
| 462 |
(setq refs (nreverse refs)) |
| 463 |
(setq rttl (length refs)) |
| 464 |
(setq movs (nreverse movs)) |
| 465 |
(if modify (mew-sinfo-set-refile-back refile-back)) |
| 466 |
(when lomov |
| 467 |
(let ((mew-inherit-exec-case case)) |
| 468 |
(mew-mark-sanity-refile movs)))) |
| 469 |
;; |
| 470 |
;; delete |
| 471 |
;; |
| 472 |
(when (mew-markdb-by-mark mew-mark-delete) |
| 473 |
(setq regex (mew-mark-regex mew-mark-delete)) |
| 474 |
(goto-char beg) |
| 475 |
(while (re-search-forward regex m t) |
| 476 |
(re-search-forward mew-regex-sumsyn-long) |
| 477 |
(setq msg (mew-sumsyn-message-number)) |
| 478 |
(setq uid (mew-sumsyn-message-uid)) |
| 479 |
(setq siz (mew-sumsyn-message-size)) |
| 480 |
(if trash |
| 481 |
(setq trss (cons (mew-make-refileinfo :uid uid |
| 482 |
:size siz |
| 483 |
:delete t |
| 484 |
:folders (list trash)) |
| 485 |
trss)) |
| 486 |
(setq rmvs (cons uid rmvs))) |
| 487 |
(when modify |
| 488 |
(setq kils (cons msg kils)) |
| 489 |
(mew-mark-invisible-line)) |
| 490 |
(setq dttl (1+ dttl)))) |
| 491 |
;; |
| 492 |
;; unlink |
| 493 |
;; |
| 494 |
(when (mew-markdb-by-mark mew-mark-unlink) |
| 495 |
(setq regex (mew-mark-regex mew-mark-unlink)) |
| 496 |
(goto-char beg) |
| 497 |
(while (re-search-forward regex m t) |
| 498 |
(re-search-forward mew-regex-sumsyn-long) |
| 499 |
(setq msg (mew-sumsyn-message-number)) |
| 500 |
(setq uid (mew-sumsyn-message-uid)) |
| 501 |
(setq siz (mew-sumsyn-message-size)) |
| 502 |
(setq rmvs (cons uid rmvs)) |
| 503 |
(when modify |
| 504 |
(setq kils (cons msg kils)) |
| 505 |
(mew-mark-invisible-line)) |
| 506 |
(setq dttl (1+ dttl)))) |
| 507 |
;; |
| 508 |
(setq rmvs (nreverse rmvs)) |
| 509 |
(setq trss (nreverse trss)) |
| 510 |
(if trss (setq refs (nconc trss refs))) |
| 511 |
;; |
| 512 |
(set-buffer-modified-p nil) |
| 513 |
(cond |
| 514 |
((and (null rmvs) (null refs)) nil) |
| 515 |
(modify |
| 516 |
(force-mode-line-update) ;; xxx |
| 517 |
(mew-make-execinfo :remove rmvs |
| 518 |
:kill kils |
| 519 |
:refile refs |
| 520 |
:move movs |
| 521 |
:rttl rttl |
| 522 |
:dttl dttl)) |
| 523 |
(t |
| 524 |
(mew-make-execinfo :remove rmvs |
| 525 |
:refile refs |
| 526 |
:rttl 0 |
| 527 |
:dttl 0)))))) |
| 528 |
|
| 529 |
(defun mew-summary-exec-remote (beg end &optional func-decide) |
| 530 |
(if (mew-folder-nntpp (mew-sinfo-get-folder)) |
| 531 |
(message "This command cannot be used in this folder") |
| 532 |
(when (mew-summary-exclusive-p) |
| 533 |
(let* ((case (mew-sinfo-get-case)) |
| 534 |
(folder (mew-sinfo-get-folder)) |
| 535 |
(bnm (mew-summary-folder-name 'ext)) |
| 536 |
(lbuf (mew-refile-log-buffer bnm)) |
| 537 |
(execinfo (mew-summary-exec-remote-get-execinfo beg end 'modify func-decide))) |
| 538 |
(if (not execinfo) |
| 539 |
(message "No messages to be processed") |
| 540 |
(mew-summary-reset) |
| 541 |
(while (eq (get-text-property (point) 'invisible) t) |
| 542 |
(forward-line)) |
| 543 |
(cond |
| 544 |
((mew-folder-popp folder) |
| 545 |
(mew-pop-retrieve case 'exec bnm execinfo)) |
| 546 |
((mew-folder-imapp folder) |
| 547 |
(mew-imap-retrieve case 'exec bnm execinfo))) |
| 548 |
(mew-exec-refile-log lbuf)))))) |
| 549 |
|
| 550 |
(defun mew-mark-kill-invisible () |
| 551 |
(save-excursion |
| 552 |
(goto-char (point-min)) |
| 553 |
(while (not (eobp)) |
| 554 |
(if (get-text-property (point) 'invisible) |
| 555 |
(mew-mark-kill-line) |
| 556 |
(forward-line))))) |
| 557 |
|
| 558 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 559 |
;;; |
| 560 |
;;; Processing marks for offline |
| 561 |
;;; |
| 562 |
|
| 563 |
(defun mew-summary-exec-offline (&optional arg) |
| 564 |
"\\<mew-summary-mode-map>Process marked messages in an IMAP folder *offline*. Messages to be refiled in |
| 565 |
a remote folder are moved to the corresponding folder but they are |
| 566 |
marked invalid. Invalid message are marked with '#'. |
| 567 |
Invalid messages will be overridden when the remote folder is scanned online. |
| 568 |
A job to delete or refile messages, which is created by this command, |
| 569 |
is queued in a queue folder (%queue for IMAP). To flush jobs in |
| 570 |
the queue, type '\\[mew-summary-send-message]' in the queue online." |
| 571 |
(interactive "P") |
| 572 |
(cond |
| 573 |
((mew-virtual-p) |
| 574 |
(mew-summary-go-back-summary |
| 575 |
(mew-substitute-for-summary "\\[mew-summary-exec-offline]"))) |
| 576 |
((not (mew-folder-imapp (mew-sinfo-get-folder))) |
| 577 |
(message "This command cannot be used in this folder")) |
| 578 |
(t |
| 579 |
(if (mew-mark-active-p) (setq arg t)) |
| 580 |
(let (beg end region) |
| 581 |
(cond |
| 582 |
(arg |
| 583 |
(setq region (mew-summary-get-region)) |
| 584 |
(setq beg (car region)) |
| 585 |
(setq end (cdr region))) |
| 586 |
(t |
| 587 |
(setq beg (point-min)) |
| 588 |
(setq end (point-max)))) |
| 589 |
(message "Refiling and deleting...") |
| 590 |
(force-mode-line-update) |
| 591 |
(mew-summary-exec-offline-region beg end))))) |
| 592 |
|
| 593 |
(mew-defstruct jobinfo mailbox execinfo mark-hist) |
| 594 |
|
| 595 |
(defun mew-summary-exec-offline-region (beg end) |
| 596 |
"Process the current marked message offline." |
| 597 |
(interactive) |
| 598 |
(let* ((execinfo (mew-summary-exec-remote-get-execinfo beg end nil)) |
| 599 |
(rmvs (mew-execinfo-get-remove execinfo)) |
| 600 |
(refs (mew-execinfo-get-refile execinfo)) |
| 601 |
job) |
| 602 |
(if (not execinfo) |
| 603 |
(message "No messages to be processed") |
| 604 |
(let* ((fld (mew-sinfo-get-folder)) |
| 605 |
(case (mew-sinfo-get-case)) |
| 606 |
(imapq (mew-case-folder case (mew-imap-queue-folder case))) |
| 607 |
(imapq-dir (mew-expand-folder imapq)) |
| 608 |
file file-info) |
| 609 |
(unless (file-directory-p imapq-dir) (mew-make-directory imapq-dir)) |
| 610 |
(setq file (mew-folder-new-message imapq)) |
| 611 |
(setq file-info (concat file mew-imapq-info-suffix)) |
| 612 |
(setq job (mew-make-jobinfo :mailbox fld |
| 613 |
:execinfo execinfo |
| 614 |
:mark-hist (mew-sinfo-get-mark-hist))) |
| 615 |
(mew-lisp-save file-info job 'nobackup 'unlimit) |
| 616 |
(with-temp-buffer |
| 617 |
(mew-header-insert mew-subj: (format "IMAP jobs for %s" fld)) |
| 618 |
(mew-header-insert mew-date: (mew-time-ctz-to-rfc (current-time))) |
| 619 |
(mew-header-insert mew-from: "Mew IMAP manager") |
| 620 |
(insert "\n") |
| 621 |
(insert "Messages to be refiled:\n") |
| 622 |
(dolist (ref refs) |
| 623 |
(insert (format (if (mew-refileinfo-get-delete ref) |
| 624 |
"\t%s will be copied to %s\n" |
| 625 |
"\t%s will be moved to %s\n") |
| 626 |
(mew-refileinfo-get-uid ref) |
| 627 |
(mew-join "," (mew-refileinfo-get-folders ref))))) |
| 628 |
(insert "\n") |
| 629 |
(when rmvs |
| 630 |
(insert "Messages to be deleted:\n") |
| 631 |
(insert "\t" (mew-join "," rmvs) "\n")) |
| 632 |
(mew-frwlet mew-cs-dummy nil |
| 633 |
(write-region (point-min) (point-max) file nil 'no-msg))) |
| 634 |
(mew-touch-folder imapq) |
| 635 |
;; refile log is not necessary since mew-summary-exec-local does it. |
| 636 |
(let ((mew-inherit-exec-case case) |
| 637 |
(mew-inherit-offline t) |
| 638 |
(mew-trash-folder (mew-imap-trash-folder case))) |
| 639 |
(mew-summary-exec-local beg end)))))) |
| 640 |
|
| 641 |
(defun mew-summary-exec-offline-one (&optional arg) |
| 642 |
"Process the message on the cursor offline." |
| 643 |
(interactive "P") |
| 644 |
(if (not (mew-folder-imapp (mew-sinfo-get-folder))) |
| 645 |
(message "This command cannot be used in this folder") |
| 646 |
(mew-summary-goto-message) |
| 647 |
(mew-decode-syntax-delete) |
| 648 |
(save-window-excursion |
| 649 |
(let (beg end) |
| 650 |
(save-excursion |
| 651 |
(beginning-of-line) |
| 652 |
(setq beg (if arg (point-min) (point))) |
| 653 |
(end-of-line) |
| 654 |
(setq end (1+ (point)))) |
| 655 |
(if (> end (point-max)) |
| 656 |
(message "No message") |
| 657 |
(force-mode-line-update) ;; xxx |
| 658 |
(mew-summary-exec-offline-region beg end)))))) |
| 659 |
|
| 660 |
(provide 'mew-exec) |
| 661 |
|
| 662 |
;;; Copyright Notice: |
| 663 |
|
| 664 |
;; Copyright (C) 1997-2015 Mew developing team. |
| 665 |
;; All rights reserved. |
| 666 |
|
| 667 |
;; Redistribution and use in source and binary forms, with or without |
| 668 |
;; modification, are permitted provided that the following conditions |
| 669 |
;; are met: |
| 670 |
;; |
| 671 |
;; 1. Redistributions of source code must retain the above copyright |
| 672 |
;; notice, this list of conditions and the following disclaimer. |
| 673 |
;; 2. Redistributions in binary form must reproduce the above copyright |
| 674 |
;; notice, this list of conditions and the following disclaimer in the |
| 675 |
;; documentation and/or other materials provided with the distribution. |
| 676 |
;; 3. Neither the name of the team nor the names of its contributors |
| 677 |
;; may be used to endorse or promote products derived from this software |
| 678 |
;; without specific prior written permission. |
| 679 |
;; |
| 680 |
;; THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS'' AND |
| 681 |
;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 682 |
;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 683 |
;; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TEAM OR CONTRIBUTORS BE |
| 684 |
;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 685 |
;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 686 |
;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 687 |
;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 688 |
;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 689 |
;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 690 |
;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 691 |
|
| 692 |
;;; mew-exec.el ends here |