diff options
| author | Paul Nelson | 2025-07-07 22:18:39 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2025-07-26 18:22:09 +0300 |
| commit | c3f30ee2046f4a2caeb009565ea20e977af00990 (patch) | |
| tree | fa823cc20d9de86abfbd56e85dccd1bf092545d3 | |
| parent | 05dca1f51f940119a2810b028b9461407dbae3cc (diff) | |
| download | emacs-c3f30ee2046f4a2caeb009565ea20e977af00990.tar.gz emacs-c3f30ee2046f4a2caeb009565ea20e977af00990.zip | |
Add post-save actions for Rmail attachments
* lisp/mail/rmailmm.el (rmail-mime-save-action): New user
option.
(rmail-mime-save): Use it.
* doc/emacs/rmail.texi (Rmail Display): Document it (bug#78971).
| -rw-r--r-- | doc/emacs/rmail.texi | 21 | ||||
| -rw-r--r-- | etc/NEWS | 7 | ||||
| -rw-r--r-- | lisp/mail/rmailmm.el | 38 |
3 files changed, 65 insertions, 1 deletions
diff --git a/doc/emacs/rmail.texi b/doc/emacs/rmail.texi index 08add98b733..70fabace693 100644 --- a/doc/emacs/rmail.texi +++ b/doc/emacs/rmail.texi | |||
| @@ -1229,6 +1229,27 @@ summarizes the part's index, size, and content type. Depending on the | |||
| 1229 | content type, it may also contain one or more buttons; these perform | 1229 | content type, it may also contain one or more buttons; these perform |
| 1230 | actions such as saving the part into a file. | 1230 | actions such as saving the part into a file. |
| 1231 | 1231 | ||
| 1232 | @vindex rmail-mime-save-action | ||
| 1233 | When you save a MIME attachment to a file, Rmail can perform follow-up | ||
| 1234 | actions according to the value of @code{rmail-mime-save-action}. By | ||
| 1235 | default, this value is @code{nil}, which means Rmail does nothing. | ||
| 1236 | Other predefined values are: | ||
| 1237 | |||
| 1238 | @table @code | ||
| 1239 | @item visit-file | ||
| 1240 | Visit the saved file in Emacs. | ||
| 1241 | |||
| 1242 | @item visit-directory | ||
| 1243 | Visit the file's directory in Dired and move point to the file. | ||
| 1244 | |||
| 1245 | @item open-external | ||
| 1246 | Open the file with an external program appropriate for its type. | ||
| 1247 | @end table | ||
| 1248 | |||
| 1249 | You can also set @code{rmail-mime-save-action} to a custom function. | ||
| 1250 | This function will be called with the absolute filename of the saved | ||
| 1251 | attachment as its only argument. | ||
| 1252 | |||
| 1232 | @table @kbd | 1253 | @table @kbd |
| 1233 | @findex rmail-mime-toggle-hidden | 1254 | @findex rmail-mime-toggle-hidden |
| 1234 | @item @key{RET} | 1255 | @item @key{RET} |
| @@ -1344,6 +1344,13 @@ replies. | |||
| 1344 | 'rmail-re-abbrevs'. 'rmail-re-abbrevs' is still honored if it was | 1344 | 'rmail-re-abbrevs'. 'rmail-re-abbrevs' is still honored if it was |
| 1345 | already set. | 1345 | already set. |
| 1346 | 1346 | ||
| 1347 | +++ | ||
| 1348 | *** New user option 'rmail-mime-save-action'. | ||
| 1349 | This option specifies an action to take after saving a MIME attachment. | ||
| 1350 | Predefined values include visiting the file in Emacs, jumping to the | ||
| 1351 | file in Dired, or opening the file with an external program. You can | ||
| 1352 | also provide a custom function. | ||
| 1353 | |||
| 1347 | ** Message | 1354 | ** Message |
| 1348 | 1355 | ||
| 1349 | +++ | 1356 | +++ |
diff --git a/lisp/mail/rmailmm.el b/lisp/mail/rmailmm.el index aa38cbf14d5..173f95fd325 100644 --- a/lisp/mail/rmailmm.el +++ b/lisp/mail/rmailmm.el | |||
| @@ -242,6 +242,27 @@ TRUNCATED is non-nil if the text of this entity was truncated.")) | |||
| 242 | 242 | ||
| 243 | ;;; Buttons | 243 | ;;; Buttons |
| 244 | 244 | ||
| 245 | (defcustom rmail-mime-save-action nil | ||
| 246 | "Action to perform after saving a MIME attachment in Rmail. | ||
| 247 | The value can be one of the following: | ||
| 248 | |||
| 249 | - nil: Do nothing (default). | ||
| 250 | - `visit-file': Visit the saved file in Emacs. | ||
| 251 | - `visit-directory': Visit the file's directory in Dired. | ||
| 252 | - `open-external': Open the file with an external program. | ||
| 253 | - A function: Call the function with the absolute filename as argument. | ||
| 254 | |||
| 255 | Email attachments can be dangerous. When this variable is set to one of | ||
| 256 | the predefined actions, the user will be prompted to confirm the action | ||
| 257 | before it is performed. If you set this variable to a function, it will | ||
| 258 | be called without confirmation. Please exercise caution." | ||
| 259 | :type '(choice (const :tag "Do nothing" nil) | ||
| 260 | (const :tag "Visit file in Emacs" visit-file) | ||
| 261 | (const :tag "Visit directory in Dired" visit-directory) | ||
| 262 | (const :tag "Open with external program" open-external) | ||
| 263 | (function :tag "Custom function")) | ||
| 264 | :version "31.1") | ||
| 265 | |||
| 245 | (defun rmail-mime-save (button) | 266 | (defun rmail-mime-save (button) |
| 246 | "Save the attachment using info in the BUTTON." | 267 | "Save the attachment using info in the BUTTON." |
| 247 | (let* ((rmail-mime-mbox-buffer rmail-view-buffer) | 268 | (let* ((rmail-mime-mbox-buffer rmail-view-buffer) |
| @@ -282,7 +303,22 @@ TRUNCATED is non-nil if the text of this entity was truncated.")) | |||
| 282 | (ignore-errors (base64-decode-region (point-min) (point-max)))) | 303 | (ignore-errors (base64-decode-region (point-min) (point-max)))) |
| 283 | ((string= transfer-encoding "quoted-printable") | 304 | ((string= transfer-encoding "quoted-printable") |
| 284 | (quoted-printable-decode-region (point-min) (point-max)))))) | 305 | (quoted-printable-decode-region (point-min) (point-max)))))) |
| 285 | (write-region nil nil filename nil nil nil t)))) | 306 | (write-region nil nil filename nil nil nil t)) |
| 307 | (pcase rmail-mime-save-action | ||
| 308 | ('nil nil) | ||
| 309 | ('visit-file | ||
| 310 | (when (yes-or-no-p (format "Visit attachment `%s' in Emacs? " | ||
| 311 | (file-name-nondirectory filename))) | ||
| 312 | (find-file filename))) | ||
| 313 | ('visit-directory | ||
| 314 | (when (yes-or-no-p (format "Visit attachment `%s' in Dired? " | ||
| 315 | (file-name-nondirectory filename))) | ||
| 316 | (dired-jump nil filename))) | ||
| 317 | ('open-external | ||
| 318 | (when (yes-or-no-p (format "Open attachment `%s' with external program? " | ||
| 319 | (file-name-nondirectory filename))) | ||
| 320 | (shell-command-do-open (list filename)))) | ||
| 321 | ((pred functionp) (funcall rmail-mime-save-action filename))))) | ||
| 286 | 322 | ||
| 287 | (define-button-type 'rmail-mime-save 'action 'rmail-mime-save) | 323 | (define-button-type 'rmail-mime-save 'action 'rmail-mime-save) |
| 288 | 324 | ||