| 1 |
;;; mew-attach.el --- attachments for Mew Draft mode |
| 2 |
|
| 3 |
;; Author: Kazu Yamamoto <[email protected]> |
| 4 |
;; Created: Oct 2, 1996 |
| 5 |
|
| 6 |
;;; Code: |
| 7 |
|
| 8 |
(require 'mew) |
| 9 |
|
| 10 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 11 |
;; |
| 12 |
;; goodies |
| 13 |
;; |
| 14 |
|
| 15 |
(defun mew-draft-prepare-attachments (&optional no-scroll) |
| 16 |
"Prepare an attachment region in the bottom of the draft. |
| 17 |
To compose a multipart message, you should execute this command first." |
| 18 |
(interactive) |
| 19 |
(if (mew-attach-p) |
| 20 |
(message "Attachments region has already been prepared") |
| 21 |
(let* ((attachdir (mew-attachdir)) |
| 22 |
(cp (expand-file-name mew-draft-coverpage attachdir)) |
| 23 |
(dir (file-name-nondirectory attachdir))) |
| 24 |
(if (mew-attach-p) |
| 25 |
(message "Attachments already exist") |
| 26 |
(mew-attach-set) |
| 27 |
(mew-check-directory attachdir) |
| 28 |
(unless (file-exists-p cp) (write-region "" nil cp 'append 'no-msg)) |
| 29 |
(unless mew-encode-syntax |
| 30 |
(setq mew-encode-syntax (mew-encode-syntax-initial dir))) |
| 31 |
(mew-encode-syntax-print mew-encode-syntax) |
| 32 |
(mew-attach-goto-number 'here '(2)) |
| 33 |
(if (and (not no-scroll) |
| 34 |
(not (pos-visible-in-window-p |
| 35 |
(point-max) |
| 36 |
(get-buffer-window (current-buffer))))) |
| 37 |
(set-window-start (get-buffer-window (current-buffer)) |
| 38 |
(mew-attach-begin))) |
| 39 |
(setq buffer-undo-list nil))))) |
| 40 |
|
| 41 |
(defun mew-attach-expand-path (syntax nums) |
| 42 |
;; Ignore the first dir |
| 43 |
(let ((path "")) |
| 44 |
(while (cdr nums) |
| 45 |
(setq syntax (aref syntax (+ mew-syntax-magic (1- (car nums))))) |
| 46 |
(setq path (concat path (mew-syntax-get-file syntax))) |
| 47 |
(setq nums (cdr nums))) |
| 48 |
path)) |
| 49 |
|
| 50 |
(defun mew-attach-line () |
| 51 |
"Return the line number for the cursor from the beginning of the |
| 52 |
attachments region. |
| 53 |
0 if on the beginning boundary. |
| 54 |
-1 if on the ending boundary." |
| 55 |
(let (ret max) |
| 56 |
(save-excursion |
| 57 |
(beginning-of-line) |
| 58 |
(setq ret (count-lines (1+ (mew-attach-begin)) (point))) |
| 59 |
(goto-char (point-max)) |
| 60 |
(beginning-of-line) |
| 61 |
(setq max (count-lines (1+ (mew-attach-begin)) (point))) |
| 62 |
(if (or (= ret max) (= ret (1- max))) -1 ret)))) |
| 63 |
|
| 64 |
(defun mew-attach-line-lastp () |
| 65 |
(let ((here (point))) |
| 66 |
(save-excursion |
| 67 |
(goto-char (point-max)) |
| 68 |
(beginning-of-line) |
| 69 |
(= (count-lines here (point)) 2)))) |
| 70 |
|
| 71 |
(defun mew-attach-move-onto-file () |
| 72 |
(end-of-line) |
| 73 |
(re-search-backward " [^ ]" nil t) |
| 74 |
(forward-char)) |
| 75 |
|
| 76 |
(defun mew-attach-move-onto-body () |
| 77 |
(goto-char (1+ (mew-attach-begin))) |
| 78 |
(forward-char -1)) |
| 79 |
|
| 80 |
(defun mew-attach-directory-p () |
| 81 |
(save-excursion |
| 82 |
(mew-attach-move-onto-file) |
| 83 |
(looking-at (file-name-as-directory "[^ ]+")))) |
| 84 |
|
| 85 |
(defun mew-attach-dot-p () |
| 86 |
(save-excursion |
| 87 |
(mew-attach-move-onto-file) |
| 88 |
(looking-at "\\. *$"))) |
| 89 |
|
| 90 |
;; cursor only |
| 91 |
(defun mew-attach-line0-1 () |
| 92 |
(when (mew-attach-p) |
| 93 |
(let ((line (mew-attach-line))) |
| 94 |
(or (= line 0) (= line -1))))) |
| 95 |
|
| 96 |
;; cursor only |
| 97 |
(defun mew-attach-line01-1 () |
| 98 |
(when (mew-attach-p) |
| 99 |
(let ((line (mew-attach-line))) |
| 100 |
(or (= line 0) (= line 1) (= line -1))))) |
| 101 |
|
| 102 |
;; insert commands |
| 103 |
(defun mew-attach-not-line012-1 () |
| 104 |
(when (mew-attach-p) |
| 105 |
(let ((line (mew-attach-line))) |
| 106 |
(not (or (= line 0) (= line 1) (= line 2) (= line -1)))))) |
| 107 |
|
| 108 |
;; find commands |
| 109 |
(defun mew-attach-not-line012-1-dot () |
| 110 |
(when (mew-attach-p) |
| 111 |
(let ((line (mew-attach-line))) |
| 112 |
(not (or (mew-attach-dot-p) |
| 113 |
(= line 0) (= line 1) (= line 2) (= line -1)))))) |
| 114 |
|
| 115 |
;; delete commands |
| 116 |
(defun mew-attach-not-line02-1-dot () |
| 117 |
(when (mew-attach-p) |
| 118 |
(let ((line (mew-attach-line))) |
| 119 |
(not (or (mew-attach-dot-p) (= line 0) (= line 2) (= line -1)))))) |
| 120 |
|
| 121 |
|
| 122 |
;; modify commands |
| 123 |
(defun mew-attach-not-line0-1-dot () |
| 124 |
(when (mew-attach-p) |
| 125 |
(let ((line (mew-attach-line))) |
| 126 |
(not (or (mew-attach-dot-p) (= line 0) (= line -1)))))) |
| 127 |
|
| 128 |
;; cursor |
| 129 |
(defun mew-attach-line1-dot () |
| 130 |
(when (mew-attach-p) |
| 131 |
(let ((line (mew-attach-line))) |
| 132 |
(or (mew-attach-dot-p) (= line 1))))) |
| 133 |
|
| 134 |
(defun mew-attach-goto-number (direction nums) |
| 135 |
(let (numreg) |
| 136 |
(setq nums (nreverse nums)) |
| 137 |
(cond |
| 138 |
((eq direction 'next) |
| 139 |
(setq nums (cons (1+ (car nums)) (cdr nums)))) |
| 140 |
((eq direction 'prev) |
| 141 |
(setq nums (cons (1- (car nums)) (cdr nums)))) |
| 142 |
((eq direction 'up) |
| 143 |
(setq nums (cdr nums))) |
| 144 |
((eq direction 'down) |
| 145 |
(setq nums (cons 1 nums))) |
| 146 |
(t ())) |
| 147 |
(if (null nums) |
| 148 |
(progn |
| 149 |
(goto-char (1- (mew-attach-begin))) |
| 150 |
(re-search-forward "^..... " nil t) |
| 151 |
(mew-attach-move-onto-file)) |
| 152 |
(setq numreg (number-to-string (car nums))) |
| 153 |
(setq nums (cdr nums)) |
| 154 |
(dolist (num nums) |
| 155 |
(setq numreg (concat (number-to-string num) "." numreg))) |
| 156 |
(setq numreg (regexp-quote numreg)) |
| 157 |
(goto-char (1+ (mew-attach-begin))) |
| 158 |
(re-search-forward (concat "^....." numreg " ") nil t) |
| 159 |
(mew-attach-move-onto-file)))) |
| 160 |
|
| 161 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 162 |
;;; |
| 163 |
;;; Dialog |
| 164 |
;;; |
| 165 |
|
| 166 |
(defun mew-substitute-for-attach (msg) |
| 167 |
(substitute-command-keys (concat "\\<mew-draft-attach-map>" msg))) |
| 168 |
|
| 169 |
(defun mew-message-for-attach (msg) |
| 170 |
(message "%s" (mew-substitute-for-attach msg))) |
| 171 |
|
| 172 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 173 |
;; |
| 174 |
;; commands |
| 175 |
;; |
| 176 |
|
| 177 |
;; |
| 178 |
;; cursor commands |
| 179 |
;; |
| 180 |
|
| 181 |
(defun mew-attach-newline () |
| 182 |
"Insert RET before the attachments region." |
| 183 |
(interactive) |
| 184 |
(when (= (point) (1+ (mew-attach-begin))) |
| 185 |
(insert "\n") |
| 186 |
(mew-draft-attach-keymap))) |
| 187 |
|
| 188 |
(defun mew-attach-forward () |
| 189 |
"Go to the first subdirectory in attachments." |
| 190 |
(interactive) |
| 191 |
(if (mew-attach-line0-1) |
| 192 |
(mew-attach-goto-number 'here nil) |
| 193 |
(mew-attach-move-onto-file) |
| 194 |
(if (mew-attach-directory-p) |
| 195 |
(mew-attach-goto-number 'down (mew-syntax-nums)) |
| 196 |
(mew-attach-goto-number 'here (mew-syntax-nums))))) |
| 197 |
|
| 198 |
(defun mew-attach-backforward () |
| 199 |
"Go to the parent directory in attachments." |
| 200 |
(interactive) |
| 201 |
(if (mew-attach-line0-1) |
| 202 |
(mew-attach-move-onto-body) |
| 203 |
(let ((nums (mew-syntax-nums))) |
| 204 |
(if (= (length nums) 1) |
| 205 |
(mew-attach-goto-number 'here nil) |
| 206 |
(mew-attach-goto-number 'up (mew-syntax-nums)))))) |
| 207 |
|
| 208 |
(defun mew-attach-previous () |
| 209 |
"Go to the previous file in the current directory in attachments." |
| 210 |
(interactive) |
| 211 |
(if (mew-attach-line01-1) |
| 212 |
(mew-attach-move-onto-body) |
| 213 |
(if mew-attach-move-by-line |
| 214 |
(progn |
| 215 |
(forward-line -1) |
| 216 |
(mew-attach-move-onto-file)) |
| 217 |
(let* ((nums (mew-syntax-nums)) |
| 218 |
(last (nth (1- (length nums)) nums))) |
| 219 |
(if (= last 1) |
| 220 |
(mew-attach-goto-number 'here (mew-syntax-nums)) |
| 221 |
(mew-attach-goto-number 'prev (mew-syntax-nums))))))) |
| 222 |
|
| 223 |
(defun mew-attach-next () |
| 224 |
"Go to the next file in the current directory in attachments." |
| 225 |
(interactive) |
| 226 |
(if (mew-attach-line0-1) |
| 227 |
(mew-attach-goto-number 'here nil) |
| 228 |
(if mew-attach-move-by-line |
| 229 |
(if (mew-attach-line-lastp) |
| 230 |
() |
| 231 |
(forward-line) |
| 232 |
(mew-attach-move-onto-file)) |
| 233 |
(if (mew-attach-line1-dot) |
| 234 |
(mew-attach-goto-number 'here (mew-syntax-nums)) |
| 235 |
(mew-attach-goto-number 'next (mew-syntax-nums)))))) |
| 236 |
|
| 237 |
;; |
| 238 |
;; delete commands |
| 239 |
;; |
| 240 |
|
| 241 |
(defun mew-attach-delete () |
| 242 |
"Delete this file or this directory in attachments." |
| 243 |
(interactive) |
| 244 |
(if (not (mew-attach-not-line02-1-dot)) |
| 245 |
(message "Cannot delete here") |
| 246 |
(if (= (mew-attach-line) 1) |
| 247 |
(if (not (y-or-n-p "Delete entire attachments? ")) |
| 248 |
(message "Attachments were not deleted") |
| 249 |
(mew-delete-directory-recursively (mew-attachdir)) |
| 250 |
(setq mew-encode-syntax nil) |
| 251 |
(mew-attach-clear) |
| 252 |
(message "Attachments were deleted")) |
| 253 |
(let* ((nums (mew-syntax-nums)) |
| 254 |
(subdir (mew-attach-expand-path mew-encode-syntax nums)) |
| 255 |
(attachdir (mew-attachdir)) |
| 256 |
(syntax (mew-syntax-get-entry mew-encode-syntax nums)) |
| 257 |
(name (mew-syntax-get-file syntax)) |
| 258 |
(ename (if (string= subdir "") name (concat subdir name))) |
| 259 |
(fullname (expand-file-name ename attachdir)) |
| 260 |
(dirp (string-match (concat mew-path-separator "$") name)) |
| 261 |
(msg (if dirp |
| 262 |
"Delete %s with contained files? " |
| 263 |
"Delete %s? "))) |
| 264 |
;; attachdir / {subdir/} name |
| 265 |
(when (y-or-n-p (format msg ename)) |
| 266 |
(message "Deleting %s..." ename) |
| 267 |
(if (file-exists-p fullname) |
| 268 |
(if dirp |
| 269 |
(mew-delete-directory-recursively fullname) |
| 270 |
(mew-delete-file fullname))) |
| 271 |
(message "Deleting %s...done" ename) |
| 272 |
(setq mew-encode-syntax |
| 273 |
(mew-syntax-remove-entry mew-encode-syntax nums)) |
| 274 |
(mew-encode-syntax-print mew-encode-syntax)))))) |
| 275 |
|
| 276 |
;; |
| 277 |
;; insert commands |
| 278 |
;; |
| 279 |
|
| 280 |
(defun mew-attach-multipart () |
| 281 |
"Create a subdirectory(i.e. multipart) on '.' in attachments." |
| 282 |
(interactive) |
| 283 |
(if (not (mew-attach-not-line012-1)) |
| 284 |
(message "Cannot create a sub-multipart here") |
| 285 |
(let* ((nums (mew-syntax-nums)) |
| 286 |
(subdir (mew-attach-expand-path mew-encode-syntax nums)) |
| 287 |
(insert-default-directory nil) |
| 288 |
(attachdir (mew-attachdir)) |
| 289 |
dir dirpath) |
| 290 |
;; attachdir / {subdir/} dir |
| 291 |
(unless (string= subdir "") |
| 292 |
(setq attachdir (expand-file-name subdir attachdir))) |
| 293 |
;; attachdir / dir |
| 294 |
(setq dirpath (mew-random-filename attachdir 1 nil)) |
| 295 |
(if (file-exists-p dirpath) |
| 296 |
(message "Cannot make a directory, sorry") |
| 297 |
(setq dir (file-name-nondirectory dirpath)) |
| 298 |
(mew-make-directory dirpath) |
| 299 |
(setq mew-encode-syntax |
| 300 |
(mew-syntax-insert-entry |
| 301 |
mew-encode-syntax |
| 302 |
nums |
| 303 |
(mew-encode-syntax-multi dir mew-type-mlm))) |
| 304 |
(mew-encode-syntax-print mew-encode-syntax))))) |
| 305 |
|
| 306 |
(defun mew-attach-duplicate (func action setmode &optional from to default) |
| 307 |
(if (not (mew-attach-not-line012-1)) |
| 308 |
(message "Cannot %s here" action) |
| 309 |
(let* ((completion-ignored-extensions nil) |
| 310 |
(nums (mew-syntax-nums)) |
| 311 |
(subdir (mew-attach-expand-path mew-encode-syntax nums)) |
| 312 |
(attachdir (mew-attachdir)) |
| 313 |
(frompath from) |
| 314 |
(efile (and to (concat subdir to))) |
| 315 |
(tofile to) |
| 316 |
ct msg FILE) |
| 317 |
(while (or (null frompath) |
| 318 |
(file-directory-p (file-chase-links frompath)) |
| 319 |
(not (file-exists-p (file-chase-links frompath)))) |
| 320 |
(setq frompath (mew-draft-input-file-name |
| 321 |
(concat (mew-capitalize action) " from: ") default))) |
| 322 |
(while (or (null efile) |
| 323 |
(file-exists-p (expand-file-name efile attachdir))) |
| 324 |
(setq tofile (mew-input-string |
| 325 |
(concat (mew-capitalize action) " to %s(%s): ") |
| 326 |
subdir |
| 327 |
(file-name-nondirectory frompath))) |
| 328 |
(setq efile (concat subdir tofile))) |
| 329 |
(setq FILE (expand-file-name efile attachdir)) |
| 330 |
(funcall func frompath FILE) |
| 331 |
(if setmode (mew-set-file-modes FILE)) |
| 332 |
(setq ct (mew-ctdb-ct (mew-ctdb-by-file tofile))) |
| 333 |
(unless ct |
| 334 |
(setq ct (mew-content-type (mew-tinfo-get-case))) |
| 335 |
(cond |
| 336 |
((string= ct mew-ct-txt) |
| 337 |
(setq msg (mew-substitute-for-attach |
| 338 |
"Attached as text. Type '\\[mew-attach-toggle]' to toggle text to binary"))) |
| 339 |
((string= ct mew-ct-apo) |
| 340 |
(setq msg (mew-substitute-for-attach |
| 341 |
"Attached as binary. Type '\\[mew-attach-toggle]' to toggle binary to text"))))) |
| 342 |
(setq mew-encode-syntax |
| 343 |
(mew-syntax-insert-entry |
| 344 |
mew-encode-syntax |
| 345 |
nums |
| 346 |
(mew-encode-syntax-single tofile (list ct) nil nil nil 'cdp))) |
| 347 |
(mew-encode-syntax-print mew-encode-syntax) |
| 348 |
(if mew-attach-move-next-after-copy (mew-attach-next)) |
| 349 |
(if msg (message "%s" msg))))) |
| 350 |
|
| 351 |
(defun mew-attach-link (&optional from to) |
| 352 |
"Link a file with a symbolic link on '.' in attachments. |
| 353 |
FROM must be absolute path. TO must be a file name." |
| 354 |
(interactive) |
| 355 |
(mew-attach-duplicate 'mew-symbolic-link "link" nil from to)) |
| 356 |
|
| 357 |
(defun mew-attach-copy (&optional from to) |
| 358 |
"Copy a file (via networks) on '.' in attachments. |
| 359 |
FROM must be absolute path. TO must be a file name. |
| 360 |
To copy a remote file, use the \"/[user@]hostname:/filepath\" syntax." |
| 361 |
(interactive) |
| 362 |
(mew-attach-duplicate 'copy-file "copy" t from to)) |
| 363 |
|
| 364 |
(defun mew-attach-toggle () |
| 365 |
"Toggle text/binary in attachments." |
| 366 |
(interactive) |
| 367 |
(if (not (mew-attach-not-line0-1-dot)) |
| 368 |
(message "Cannot change %s here" mew-ct:) |
| 369 |
(let* ((nums (mew-syntax-nums)) |
| 370 |
(syntax (mew-syntax-get-entry mew-encode-syntax nums)) |
| 371 |
(file (mew-syntax-get-file syntax)) |
| 372 |
(ctl (mew-syntax-get-ct syntax)) |
| 373 |
(ct (mew-syntax-get-value ctl 'cap)) |
| 374 |
cte) |
| 375 |
(if (not (or (string= ct mew-ct-txt) (string= ct mew-ct-apo))) |
| 376 |
(message "Cannot toggle %s" ct) |
| 377 |
(if (string= ct mew-ct-txt) |
| 378 |
(setq ct mew-ct-apo) |
| 379 |
(setq ct mew-ct-txt)) |
| 380 |
(setq ctl (list ct)) |
| 381 |
(mew-syntax-set-ct syntax ctl) |
| 382 |
(setq cte (mew-ctdb-cte (mew-ctdb-by-ct ct))) |
| 383 |
(mew-syntax-set-cte syntax cte) |
| 384 |
(mew-syntax-set-cdp syntax (mew-syntax-cdp-format ct file)) |
| 385 |
(mew-encode-syntax-print mew-encode-syntax))))) |
| 386 |
|
| 387 |
(defun mew-attach-link-message () |
| 388 |
"Link the message displayed in Message mode with a symbolic link |
| 389 |
on '.' in attachments." |
| 390 |
(interactive) |
| 391 |
(let* ((fid (mew-frame-id)) |
| 392 |
(fld (mew-current-get-fld fid)) |
| 393 |
(msg (mew-current-get-msg fid)) |
| 394 |
default) |
| 395 |
(if fld (setq default (mew-expand-msg fld msg))) |
| 396 |
(if mew-use-symbolic-link-for-forwarding |
| 397 |
(mew-attach-duplicate 'mew-symbolic-link "link" nil nil nil default) |
| 398 |
(mew-attach-duplicate 'copy-file "copy" nil nil nil default)))) |
| 399 |
|
| 400 |
(defun mew-attach-find-new-file () |
| 401 |
"Open a new file into a buffer on '.' in attachments." |
| 402 |
(interactive) |
| 403 |
(if (not (mew-attach-not-line012-1)) |
| 404 |
(message "Cannot find a new file here") |
| 405 |
(let* ((nums (mew-syntax-nums)) |
| 406 |
(subdir (mew-attach-expand-path mew-encode-syntax nums)) |
| 407 |
(attachdir (mew-attachdir)) |
| 408 |
file filepath) |
| 409 |
;; attachdir / {subdir/} dir |
| 410 |
(unless (string= subdir "") |
| 411 |
(setq attachdir (expand-file-name subdir attachdir))) |
| 412 |
;; attachdir / file |
| 413 |
(setq filepath (mew-random-filename attachdir 1 nil mew-text-suffix)) |
| 414 |
(if (null filepath) |
| 415 |
(message "Cannot make a text file, sorry") |
| 416 |
(setq file (file-name-nondirectory filepath)) |
| 417 |
(setq mew-encode-syntax |
| 418 |
(mew-syntax-insert-entry |
| 419 |
mew-encode-syntax |
| 420 |
nums |
| 421 |
(mew-encode-syntax-single file (list mew-ct-txt) ;; for charset |
| 422 |
nil nil nil nil))) |
| 423 |
(mew-encode-syntax-print mew-encode-syntax) |
| 424 |
;; |
| 425 |
(switch-to-buffer (mew-find-file-noselect2 filepath)) |
| 426 |
(text-mode) |
| 427 |
;; buffer switched |
| 428 |
(local-set-key "\C-c\C-q" 'mew-kill-buffer))))) |
| 429 |
|
| 430 |
(defun mew-attach-audio () |
| 431 |
"Sampling voice and insert as audio file on '.' in attachments" |
| 432 |
(interactive) |
| 433 |
(if (not (mew-attach-not-line012-1)) |
| 434 |
(message "Cannot attach audio data here") |
| 435 |
(let* ((nums (mew-syntax-nums)) |
| 436 |
(subdir (mew-attach-expand-path mew-encode-syntax nums)) |
| 437 |
(attachdir (mew-attachdir)) |
| 438 |
file filepath recorded) |
| 439 |
;; attachdir / {subdir/} dir |
| 440 |
(unless (string= subdir "") |
| 441 |
(setq attachdir (expand-file-name subdir attachdir))) |
| 442 |
;; attachdir / file |
| 443 |
(setq filepath (mew-random-filename attachdir 1 nil mew-audio-suffix)) |
| 444 |
(if (null filepath) |
| 445 |
(message "Cannot make a file for audio, sorry") |
| 446 |
(setq file (file-name-nondirectory filepath)) |
| 447 |
(with-temp-buffer |
| 448 |
(condition-case nil |
| 449 |
(progn |
| 450 |
(if (not (y-or-n-p "Are you ready to record audio? ")) |
| 451 |
(message "Nothing is recoded") |
| 452 |
(mew-message-for-attach |
| 453 |
"Type '\\[keyboard-quit]' to finish recording...") |
| 454 |
(mew-plet |
| 455 |
(apply 'call-process |
| 456 |
(nth 0 mew-prog-audio2) |
| 457 |
nil t nil |
| 458 |
(nth 1 mew-prog-audio2))))) |
| 459 |
(quit |
| 460 |
(mew-message-for-attach |
| 461 |
"Type '\\[keyboard-quit]' to finish recording...done") |
| 462 |
(setq recorded t) |
| 463 |
(mew-flet |
| 464 |
(write-region (point-min) (point-max) filepath nil 'no-msg))))) |
| 465 |
(if recorded |
| 466 |
(setq mew-encode-syntax ;; buffer local |
| 467 |
(mew-syntax-insert-entry |
| 468 |
mew-encode-syntax |
| 469 |
nums |
| 470 |
(mew-encode-syntax-single file mew-type-ado |
| 471 |
nil nil nil 'cdp)))) |
| 472 |
(mew-encode-syntax-print mew-encode-syntax))))) |
| 473 |
|
| 474 |
;; |
| 475 |
;; modify commands |
| 476 |
;; |
| 477 |
|
| 478 |
(defun mew-attach-undo () |
| 479 |
"Unmark. The original mark appears." |
| 480 |
(interactive) |
| 481 |
(if (not (mew-attach-not-line0-1-dot)) |
| 482 |
(message "Cannot undo encoding here") |
| 483 |
(let* ((nums (mew-syntax-nums)) |
| 484 |
(syntax (mew-syntax-get-entry mew-encode-syntax nums))) |
| 485 |
(mew-syntax-set-privacy syntax nil) |
| 486 |
(mew-syntax-set-decrypters syntax nil) |
| 487 |
;; |
| 488 |
(mew-syntax-set-cte syntax |
| 489 |
(mew-ctdb-cte |
| 490 |
(mew-ctdb-by-ct |
| 491 |
(car (mew-syntax-get-ct syntax))))) |
| 492 |
(mew-encode-syntax-print mew-encode-syntax)))) |
| 493 |
|
| 494 |
(defun mew-attach-type () |
| 495 |
"Change the data type(Content-Type:) in attachments." |
| 496 |
(interactive) |
| 497 |
(if (not (mew-attach-not-line0-1-dot)) |
| 498 |
(message "Cannot change %s here" mew-ct:) |
| 499 |
(let* ((nums (mew-syntax-nums)) |
| 500 |
(syntax (mew-syntax-get-entry mew-encode-syntax nums)) |
| 501 |
(file (mew-syntax-get-file syntax)) |
| 502 |
(ctl (mew-syntax-get-ct syntax)) |
| 503 |
(ct (mew-syntax-get-value ctl 'cap)) |
| 504 |
cte) |
| 505 |
(setq ct (mew-input-type "Type for %s (%s): " file ct |
| 506 |
(if (mew-syntax-multipart-p syntax) |
| 507 |
mew-mime-content-type-multipart-list |
| 508 |
mew-mime-content-type-list))) |
| 509 |
(setq ctl (list ct)) |
| 510 |
(mew-syntax-set-ct syntax ctl) |
| 511 |
(setq cte (mew-ctdb-cte (mew-ctdb-by-ct ct))) |
| 512 |
(mew-syntax-set-cte syntax cte) |
| 513 |
(mew-syntax-set-cdp syntax (mew-syntax-cdp-format ct file)) |
| 514 |
(mew-encode-syntax-print mew-encode-syntax)))) |
| 515 |
|
| 516 |
(defun mew-attach-charset () |
| 517 |
"Specify the charset parameter for a Text/* object in attachments." |
| 518 |
(interactive) |
| 519 |
(mew-attach-charset-base "charset")) |
| 520 |
|
| 521 |
(defun mew-attach-icharset () |
| 522 |
"Specify a input coding-system for a text file in attachments." |
| 523 |
(interactive) |
| 524 |
(mew-attach-charset-base "icharset")) |
| 525 |
|
| 526 |
(defun mew-attach-charset-base (param) |
| 527 |
(if (not (mew-attach-not-line0-1-dot)) |
| 528 |
(message "Cannot specify character set here") |
| 529 |
(let* ((nums (mew-syntax-nums)) |
| 530 |
(syntax (mew-syntax-get-entry mew-encode-syntax nums)) |
| 531 |
(file (mew-syntax-get-file syntax)) |
| 532 |
(ctl (mew-syntax-get-ct syntax)) |
| 533 |
(ct (mew-syntax-get-value ctl 'cap)) |
| 534 |
(params (mew-syntax-get-params ctl)) |
| 535 |
(char (mew-syntax-get-param ctl param)) |
| 536 |
charset) |
| 537 |
(if (not (mew-ct-textp ct)) |
| 538 |
(message "Cannot use character set %s" ct) |
| 539 |
(unless char (setq char "guess")) |
| 540 |
(setq charset (mew-input-type |
| 541 |
(if (string= param "charset") |
| 542 |
"Output message charset for %s (%s): " |
| 543 |
"Input file charset for %s (%s): ") |
| 544 |
file char |
| 545 |
(cons "guess" mew-charset-list))) |
| 546 |
(setq params (mew-delete param params)) |
| 547 |
(if (string= charset "guess") |
| 548 |
(setq ctl (cons ct params)) |
| 549 |
(setq ctl (cons ct (cons (list param charset) params)))) |
| 550 |
(mew-syntax-set-ct syntax ctl) |
| 551 |
(mew-encode-syntax-print mew-encode-syntax))))) |
| 552 |
|
| 553 |
(defun mew-attach-description () |
| 554 |
"Input a description(Content-Description:) in attachments." |
| 555 |
(interactive) |
| 556 |
(if (not (mew-attach-not-line0-1-dot)) |
| 557 |
(message "Cannot describe here") |
| 558 |
(let* ((nums (mew-syntax-nums)) |
| 559 |
(syntax (mew-syntax-get-entry mew-encode-syntax nums)) |
| 560 |
(ocd (or (mew-syntax-get-cd syntax) (mew-syntax-get-file syntax))) |
| 561 |
(cd (read-string "Description: " ocd))) |
| 562 |
(if (string= cd "") |
| 563 |
(mew-syntax-set-cd syntax nil) |
| 564 |
(mew-syntax-set-cd syntax cd)) |
| 565 |
(mew-encode-syntax-print mew-encode-syntax)))) |
| 566 |
|
| 567 |
(defun mew-attach-disposition () |
| 568 |
"Input Content-Disposition: in attachments." |
| 569 |
(interactive) |
| 570 |
(if (not (mew-attach-not-line0-1-dot)) |
| 571 |
(message "Cannot set disposition here") |
| 572 |
(let* ((nums (mew-syntax-nums)) |
| 573 |
(syntax (mew-syntax-get-entry mew-encode-syntax nums)) |
| 574 |
(ctl (mew-syntax-get-ct syntax)) |
| 575 |
(ct (mew-syntax-get-value ctl 'cap)) |
| 576 |
(oldfile (or (mew-syntax-get-param (mew-syntax-get-cdp syntax) |
| 577 |
"filename") |
| 578 |
(mew-syntax-get-file syntax))) |
| 579 |
(file (read-string "Filename: " oldfile))) |
| 580 |
(if (string= file "") |
| 581 |
(mew-syntax-set-cdp syntax nil) |
| 582 |
(mew-syntax-set-cdp syntax (mew-syntax-cdp-format ct file nil 'force-file))) |
| 583 |
(mew-encode-syntax-print mew-encode-syntax)))) |
| 584 |
|
| 585 |
(defun mew-attach-base64 () |
| 586 |
"Put the 'B' mark to encode with Base64 in attachments." |
| 587 |
(interactive) |
| 588 |
(if (not (mew-attach-not-line0-1-dot)) |
| 589 |
(message "Cannot encode with base64 here") |
| 590 |
(let* ((nums (mew-syntax-nums)) |
| 591 |
(syntax (mew-syntax-get-entry mew-encode-syntax nums)) |
| 592 |
(ctl (mew-syntax-get-ct syntax)) |
| 593 |
(ct (mew-syntax-get-value ctl 'cap))) |
| 594 |
(if (or (mew-ct-messagep ct) (mew-ct-multipartp ct)) |
| 595 |
(message "Cannot encode with base64 here") |
| 596 |
(mew-syntax-set-cte syntax mew-b64) |
| 597 |
(mew-encode-syntax-print mew-encode-syntax))))) |
| 598 |
|
| 599 |
(defun mew-attach-quoted-printable () |
| 600 |
"Put the 'Q' mark to encode with Quoted-Printable in attachments" |
| 601 |
(interactive) |
| 602 |
(if (not (mew-attach-not-line0-1-dot)) |
| 603 |
(message "Cannot encode with quoted-printable here") |
| 604 |
(let* ((nums (mew-syntax-nums)) |
| 605 |
(syntax (mew-syntax-get-entry mew-encode-syntax nums)) |
| 606 |
(ctl (mew-syntax-get-ct syntax)) |
| 607 |
(ct (mew-syntax-get-value ctl 'cap))) |
| 608 |
(if (or (mew-ct-messagep ct) (mew-ct-multipartp ct)) |
| 609 |
(message "Cannot encode with quoted-printable here") |
| 610 |
(mew-syntax-set-cte syntax mew-qp) |
| 611 |
(mew-encode-syntax-print mew-encode-syntax))))) |
| 612 |
|
| 613 |
(defun mew-attach-gzip64 () |
| 614 |
"Put the 'G' mark to encode with Gzip64 in attachments. This is |
| 615 |
applicable only to Text/Plain and Application/Postscript since compression |
| 616 |
is not effective other objects. For example, JPEG is already compressed." |
| 617 |
(interactive) |
| 618 |
(if (not (mew-attach-not-line0-1-dot)) |
| 619 |
(message "Cannot apply gzip here") |
| 620 |
(let* ((nums (mew-syntax-nums)) |
| 621 |
(syntax (mew-syntax-get-entry mew-encode-syntax nums)) |
| 622 |
(ctl (mew-syntax-get-ct syntax)) |
| 623 |
(ct (mew-syntax-get-value ctl 'cap))) |
| 624 |
(if (or (mew-ct-messagep ct) |
| 625 |
(mew-ct-multipartp ct) |
| 626 |
(not (mew-ct-linebasep ct))) |
| 627 |
;; never use compress to types other than text/plain or |
| 628 |
;; application/postscript. Indeed, compression is not |
| 629 |
;; effective to compressed data such as jpeg. |
| 630 |
(message "Cannot apply gzip to %s" ct) |
| 631 |
(mew-syntax-set-cte syntax mew-xg) |
| 632 |
(mew-encode-syntax-print mew-encode-syntax))))) |
| 633 |
|
| 634 |
(defun mew-attach-zip () |
| 635 |
"Put the 'Z' mark and encrypt it with \"zip\" in attachments." |
| 636 |
(interactive) |
| 637 |
(if (not (mew-attach-not-line02-1-dot)) |
| 638 |
(message "Cannot encrypt with zip here") |
| 639 |
(let* ((nums (mew-syntax-nums)) |
| 640 |
(syntax (mew-syntax-get-entry mew-encode-syntax nums)) |
| 641 |
(ctl (mew-syntax-get-ct syntax)) |
| 642 |
(ct (mew-syntax-get-value ctl 'cap))) |
| 643 |
(if (or (mew-ct-messagep ct) (mew-ct-multipartp ct)) |
| 644 |
(message "Cannot encrypt with zip here") |
| 645 |
(if (not (mew-which-exec mew-prog-zip)) |
| 646 |
(message "\"zip\" not found") |
| 647 |
(let ((password (mew-read-passwd "Zip password: ")) |
| 648 |
(password1 (mew-read-passwd "Zip password again: "))) |
| 649 |
(if (not (string= password password1)) |
| 650 |
(message "Password mismatch!") |
| 651 |
(let* ((subdir (mew-attach-expand-path mew-encode-syntax nums)) |
| 652 |
(attachdir (mew-attachdir)) |
| 653 |
(name (mew-syntax-get-file syntax)) |
| 654 |
(ename (if (string= subdir "") name (concat subdir name))) |
| 655 |
(fullname (expand-file-name ename attachdir)) |
| 656 |
(zname (concat name ".zip")) |
| 657 |
(zfullname (concat fullname ".zip")) |
| 658 |
(zct "application/zip") |
| 659 |
(default-directory (file-name-directory fullname))) |
| 660 |
;; must not specify the "-e" option due to |
| 661 |
;; variety of zip versions. |
| 662 |
(call-process mew-prog-zip nil nil nil "-P" password zname name) |
| 663 |
(if (not (file-exists-p zfullname)) |
| 664 |
(if (string= password "") |
| 665 |
(message "\"zip\" does not allow zero length password") |
| 666 |
(message "\"zip\" does not support encryption")) |
| 667 |
(mew-syntax-set-ct syntax (list zct)) |
| 668 |
(mew-syntax-set-cte syntax mew-b64) |
| 669 |
(mew-syntax-set-file syntax zname) |
| 670 |
(mew-syntax-set-cdp syntax (mew-syntax-cdp-format zct zname)) |
| 671 |
(mew-encode-syntax-print mew-encode-syntax)))))))))) |
| 672 |
|
| 673 |
(defun mew-attach-pgp-sign () |
| 674 |
"Put the 'PS' mark to sign with PGP in attachments." |
| 675 |
(interactive) |
| 676 |
(cond |
| 677 |
((not (mew-attach-not-line0-1-dot)) |
| 678 |
(message "Cannot PGP sign here")) |
| 679 |
((null mew-pgp-ver) |
| 680 |
(message "%s does not exist" mew-prog-pgp)) |
| 681 |
(t |
| 682 |
(let* ((nums (mew-syntax-nums)) |
| 683 |
(syntax (mew-syntax-get-entry mew-encode-syntax nums)) |
| 684 |
(privacy (mew-syntax-get-privacy syntax)) |
| 685 |
(pgp-sign (mew-pcdb-ct (mew-pcdb-by-service 'pgp-signature)))) |
| 686 |
(cond |
| 687 |
((>= (length privacy) 2) |
| 688 |
(message "Too many marks")) |
| 689 |
((member (car pgp-sign) privacy) ;; xxx hard coding |
| 690 |
(message "Already marked")) |
| 691 |
(t |
| 692 |
(mew-syntax-set-privacy |
| 693 |
syntax (append privacy pgp-sign)) |
| 694 |
(mew-encode-syntax-print mew-encode-syntax))))))) |
| 695 |
|
| 696 |
(defun mew-attach-pgp-enc () |
| 697 |
"Put the 'PE' mark to encrypt with PGP in attachment. |
| 698 |
Input decrypters' addresses." |
| 699 |
(interactive) |
| 700 |
(cond |
| 701 |
((not (mew-attach-not-line0-1-dot)) |
| 702 |
(message "Cannot PGP encrypt here")) |
| 703 |
((null mew-pgp-ver) |
| 704 |
(message "%s does not exist" mew-prog-pgp)) |
| 705 |
(t |
| 706 |
(let* ((nums (mew-syntax-nums)) |
| 707 |
(syntax (mew-syntax-get-entry mew-encode-syntax nums)) |
| 708 |
(privacy (mew-syntax-get-privacy syntax)) |
| 709 |
(towhom (mew-header-parse-address-list mew-destination:-list)) |
| 710 |
(pgp-enc (mew-pcdb-ct (mew-pcdb-by-service 'pgp-encryption)))) |
| 711 |
(cond |
| 712 |
((>= (length privacy) 2) |
| 713 |
(message "Too many marks")) |
| 714 |
((member (car pgp-enc) privacy) ;; xxx hard coding |
| 715 |
(message "Already marked")) |
| 716 |
(t |
| 717 |
;; ask towhom before set privacy for C-g |
| 718 |
(if towhom |
| 719 |
(setq towhom (mew-input-address "To (%s): " (mew-join "," towhom))) |
| 720 |
(setq towhom (mew-input-address "To: "))) |
| 721 |
;; towhom is already canonicalized. |
| 722 |
(mew-syntax-set-privacy |
| 723 |
syntax (append privacy pgp-enc)) |
| 724 |
(mew-syntax-set-decrypters syntax towhom) |
| 725 |
(mew-encode-syntax-print mew-encode-syntax))))))) |
| 726 |
|
| 727 |
(defun mew-attach-smime-sign () |
| 728 |
"Put the 'PS' mark to sign with S/MIME in attachments." |
| 729 |
(interactive) |
| 730 |
(cond |
| 731 |
((not (mew-attach-not-line0-1-dot)) |
| 732 |
(message "Cannot S/MIME sign here")) |
| 733 |
((null mew-smime-ver) |
| 734 |
(message "%s does not exist" mew-prog-smime)) |
| 735 |
(t |
| 736 |
(let* ((nums (mew-syntax-nums)) |
| 737 |
(syntax (mew-syntax-get-entry mew-encode-syntax nums)) |
| 738 |
(privacy (mew-syntax-get-privacy syntax)) |
| 739 |
(smime-sign (mew-pcdb-ct (mew-pcdb-by-service 'smime-signature)))) |
| 740 |
(cond |
| 741 |
((>= (length privacy) 2) |
| 742 |
(message "Too many marks")) |
| 743 |
((member (car smime-sign) privacy) ;; xxx hard coding |
| 744 |
(message "Already marked")) |
| 745 |
(t |
| 746 |
(mew-syntax-set-privacy |
| 747 |
syntax (append privacy smime-sign)) |
| 748 |
(mew-encode-syntax-print mew-encode-syntax))))))) |
| 749 |
|
| 750 |
(defun mew-attach-smime-enc () |
| 751 |
"Put the 'SE' mark to encrypt with S/MIME in attachment. |
| 752 |
Input decrypters' addresses." |
| 753 |
(interactive) |
| 754 |
(cond |
| 755 |
((not (mew-attach-not-line0-1-dot)) |
| 756 |
(message "Cannot S/MIME encrypt here")) |
| 757 |
((null mew-smime-ver) |
| 758 |
(message "%s does not exist" mew-prog-smime)) |
| 759 |
(t |
| 760 |
(let* ((nums (mew-syntax-nums)) |
| 761 |
(syntax (mew-syntax-get-entry mew-encode-syntax nums)) |
| 762 |
(privacy (mew-syntax-get-privacy syntax)) |
| 763 |
(towhom (mew-header-parse-address-list mew-destination:-list)) |
| 764 |
(smime-enc (mew-pcdb-ct (mew-pcdb-by-service 'smime-encryption)))) |
| 765 |
(cond |
| 766 |
((>= (length privacy) 2) |
| 767 |
(message "Too many marks")) |
| 768 |
((member (car smime-enc) privacy) ;; xxx hard coding |
| 769 |
(message "Already marked")) |
| 770 |
(t |
| 771 |
;; ask towhom before set privacy for C-g |
| 772 |
(if towhom |
| 773 |
(setq towhom (mew-input-address "To (%s): " (mew-join "," towhom))) |
| 774 |
(setq towhom (mew-input-address "To: "))) |
| 775 |
;; towhom is already canonicalized. |
| 776 |
(mew-syntax-set-privacy |
| 777 |
syntax (append privacy smime-enc)) |
| 778 |
(mew-syntax-set-decrypters syntax towhom) |
| 779 |
(mew-encode-syntax-print mew-encode-syntax))))))) |
| 780 |
;; |
| 781 |
;; find commands |
| 782 |
;; |
| 783 |
|
| 784 |
(defun mew-attach-find-file () |
| 785 |
"Open this file into a buffer in attachments." |
| 786 |
(interactive) |
| 787 |
(if (not (mew-attach-not-line012-1-dot)) |
| 788 |
(message "Cannot find a file here") |
| 789 |
(let* ((nums (mew-syntax-nums)) |
| 790 |
(subdir (mew-attach-expand-path mew-encode-syntax nums)) |
| 791 |
(attachdir (mew-attachdir)) |
| 792 |
(syntax (mew-syntax-get-entry mew-encode-syntax nums)) |
| 793 |
(file (mew-syntax-get-file syntax)) |
| 794 |
efile FILE) |
| 795 |
(setq efile (if (string= subdir "") file (concat subdir file))) |
| 796 |
(setq FILE (expand-file-name efile attachdir)) |
| 797 |
(switch-to-buffer (mew-find-file-noselect2 FILE)) |
| 798 |
;; buffer switched |
| 799 |
(local-set-key "\C-c\C-q" 'mew-kill-buffer) |
| 800 |
(if (file-symlink-p FILE) |
| 801 |
(message "This file is a symbolic link. Take care"))))) |
| 802 |
|
| 803 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 804 |
;; |
| 805 |
;; Drag & Drop |
| 806 |
;; |
| 807 |
|
| 808 |
(defun mew-draft-dnd-handle-local-file (uri action) |
| 809 |
(let* ((from (dnd-get-local-file-name uri t)) |
| 810 |
(to (if from (file-name-nondirectory from) |
| 811 |
(error "Can not read %s" uri) nil))) |
| 812 |
(when from |
| 813 |
(unless (mew-attach-p) |
| 814 |
(mew-draft-prepare-attachments)) |
| 815 |
(goto-char (point-max)) |
| 816 |
(forward-line -2) |
| 817 |
(mew-attach-next) |
| 818 |
(cond |
| 819 |
((file-directory-p from) |
| 820 |
(message "Directory cannot be attached")) |
| 821 |
((or (eq action 'copy) |
| 822 |
(eq action 'private) |
| 823 |
(eq action 'move)) |
| 824 |
(mew-attach-copy from to)) |
| 825 |
((eq action 'link) |
| 826 |
(mew-attach-link from to)) |
| 827 |
(t |
| 828 |
(message "Nothing happened")))))) |
| 829 |
|
| 830 |
(defun mew-draft-dnd-handle-remote-url (_uri _action) |
| 831 |
(error "Remote files not supported") nil) |
| 832 |
|
| 833 |
(defvar mew-draft-dnd-handle-remote-file-function |
| 834 |
(if (eq system-type 'windows-nt) |
| 835 |
'mew-draft-dnd-handle-local-file |
| 836 |
'mew-draft-dnd-handle-remote-url)) |
| 837 |
|
| 838 |
(defun mew-draft-dnd-handle-file (uri action) |
| 839 |
(let ((local-file (dnd-get-local-file-uri uri))) |
| 840 |
(if local-file |
| 841 |
(mew-draft-dnd-handle-local-file local-file action) |
| 842 |
(if mew-draft-dnd-handle-remote-file-function |
| 843 |
(funcall mew-draft-dnd-handle-remote-file-function uri action) |
| 844 |
(error "Remote files not supported") nil)))) |
| 845 |
|
| 846 |
(provide 'mew-attach) |
| 847 |
|
| 848 |
;;; Copyright Notice: |
| 849 |
|
| 850 |
;; Copyright (C) 1996-2015 Mew developing team. |
| 851 |
;; All rights reserved. |
| 852 |
|
| 853 |
;; Redistribution and use in source and binary forms, with or without |
| 854 |
;; modification, are permitted provided that the following conditions |
| 855 |
;; are met: |
| 856 |
;; |
| 857 |
;; 1. Redistributions of source code must retain the above copyright |
| 858 |
;; notice, this list of conditions and the following disclaimer. |
| 859 |
;; 2. Redistributions in binary form must reproduce the above copyright |
| 860 |
;; notice, this list of conditions and the following disclaimer in the |
| 861 |
;; documentation and/or other materials provided with the distribution. |
| 862 |
;; 3. Neither the name of the team nor the names of its contributors |
| 863 |
;; may be used to endorse or promote products derived from this software |
| 864 |
;; without specific prior written permission. |
| 865 |
;; |
| 866 |
;; THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS'' AND |
| 867 |
;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 868 |
;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 869 |
;; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TEAM OR CONTRIBUTORS BE |
| 870 |
;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 871 |
;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 872 |
;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 873 |
;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 874 |
;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 875 |
;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 876 |
;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 877 |
|
| 878 |
;;; mew-attach.el ends here |