From 5fc6c8408450a8a7e7b6d33632155d6aca0db9be Mon Sep 17 00:00:00 2001 From: Vitaly Ovchinnikov Date: Wed, 7 Jun 2023 14:27:13 +0300 Subject: save: new option for saving attachments Add a new `-A` option to `:save` that works in the same manner as `-a`, but saves all the named parts of an email, not just attachments. The reason is that I have an email with this structure: multipart/related multipart/alternative text/plain text/html image/png (image001.png) image/png (image002.png) image/png (image003.png) text/plain (env.txt) Where the `env.txt` is a "real" attachment, while the images are just a part of the HTML version of the email. However, in this particular email it was important to see them which can't be done with text UI and opening the HTML part with the browser also didn't work. Saving them to a temorary folder did the job and this can be useful in other scenarios. So before the patch we could do `:save -ap /some/path` and get just the `env.txt` saved there. After the patch we could also do `:save -Ap /some/path` and get all the images and the text file saved into the folder. Signed-off-by: Vitaly Ovchinnikov Tested-by: Moritz Poldrack --- CHANGELOG.md | 2 ++ commands/msgview/save.go | 17 ++++++++++------- doc/aerc.1.scd | 4 +++- widgets/msgviewer.go | 4 ++-- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c321b001..33876008 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added +- Add a `-A` option to `:save` for saving all the named parts, not just + attachments - Colorize can style diff chunk function names with `diff_chunk_func`. - Warn before sending emails with an empty subject with `empty-subject-warning` in `aerc.conf`. diff --git a/commands/msgview/save.go b/commands/msgview/save.go index 7d82ff95..5bd4c188 100644 --- a/commands/msgview/save.go +++ b/commands/msgview/save.go @@ -26,7 +26,7 @@ func init() { } func (Save) Options() string { - return "fpa" + return "fpaA" } func (Save) Aliases() []string { @@ -45,10 +45,11 @@ func (s Save) Complete(aerc *widgets.Aerc, args []string) []string { } type saveParams struct { - force bool - createDirs bool - trailingSlash bool - attachments bool + force bool + createDirs bool + trailingSlash bool + attachments bool + allAttachments bool } func (s Save) Execute(aerc *widgets.Aerc, args []string) error { @@ -67,6 +68,8 @@ func (s Save) Execute(aerc *widgets.Aerc, args []string) error { params.createDirs = true case 'a': params.attachments = true + case 'A': + params.allAttachments = true } } @@ -106,8 +109,8 @@ func (s Save) Execute(aerc *widgets.Aerc, args []string) error { return fmt.Errorf("SelectedTabContent is not a MessageViewer") } - if params.attachments { - parts := mv.AttachmentParts() + if params.attachments || params.allAttachments { + parts := mv.AttachmentParts(params.allAttachments) if len(parts) == 0 { return fmt.Errorf("This message has no attachments") } diff --git a/doc/aerc.1.scd b/doc/aerc.1.scd index 0c89460b..a637960f 100644 --- a/doc/aerc.1.scd +++ b/doc/aerc.1.scd @@ -477,7 +477,7 @@ message list, the message in the message viewer, etc). the same than for *:open* but the opener program will be looked up according to the URL scheme MIME type: _x-scheme-handler/_. -*:save* [*-fpa*] __ +*:save* [*-fpaA*] __ Saves the current message part to the given path. If the path is not an absolute path, *[general].default-save-path* from _aerc.conf_ will be prepended to the path given. @@ -492,6 +492,8 @@ message list, the message in the message viewer, etc). *-a*: Save all attachments. Individual filenames cannot be specified. + *-A*: Same as *-a* but saves all the named parts, not just attachments. + *:mark* [*-atvT*] Marks messages. Commands will execute on all marked messages instead of the highlighted one if applicable. The flags below can be combined as needed. diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go index 6752fbff..bb30734d 100644 --- a/widgets/msgviewer.go +++ b/widgets/msgviewer.go @@ -337,11 +337,11 @@ func (mv *MessageViewer) SelectedMessagePart() *PartInfo { } } -func (mv *MessageViewer) AttachmentParts() []*PartInfo { +func (mv *MessageViewer) AttachmentParts(all bool) []*PartInfo { var attachments []*PartInfo for _, p := range mv.switcher.parts { - if p.part.Disposition == "attachment" { + if p.part.Disposition == "attachment" || (all && p.part.FileName() != "") { pi := &PartInfo{ Index: p.index, Msg: p.msg.MessageInfo(), -- cgit