~rjarry/aerc-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
5 3

[PATCH aerc v2] open: preserve the original filename

Maarten Aertsen <maarten@nlnetlabs.nl>
Details
Message ID
<20240413071009.52225-1-maarten@nlnetlabs.nl>
DKIM signature
pass
Download raw message
Patch: +12 -15
Change the name of the temporary file that is :open'ed using the system
handler from `aerc-<randint>.ext` to
`aerc-<randint>/<actual-filename.ext>`.  This preserves the original
filename, while retaining collision avoidance and the current base
location (os.TempDir()).

Changelog-changed: `:open` commands now preserve the original filename.
Signed-off-by: Maarten Aertsen <maarten@nlnetlabs.nl>
Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
---
v1->v2:
  - restore mimeType detection
  - make linter happy

 commands/msgview/open.go | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/commands/msgview/open.go b/commands/msgview/open.go
index 85005031..55d085f6 100644
--- a/commands/msgview/open.go
+++ b/commands/msgview/open.go
@@ -3,7 +3,6 @@ package msgview
import (
	"errors"
	"io"
	"mime"
	"os"
	"path/filepath"

@@ -42,23 +41,21 @@ func (o Open) Execute(args []string) error {
	p := mv.SelectedMessagePart()

	mv.MessageView().FetchBodyPart(p.Index, func(reader io.Reader) {
		extension := ""
		mimeType := ""

		// try to determine the correct extension
		if part, err := mv.MessageView().BodyStructure().PartAtIndex(p.Index); err == nil {
			mimeType = part.FullMIMEType()
			// see if we can get extension directly from the attachment name
			extension = filepath.Ext(part.FileName())
			// if there is no extension, try using the attachment mime type instead
			if extension == "" {
				if exts, _ := mime.ExtensionsByType(mimeType); len(exts) > 0 {
					extension = exts[0]
				}
			}
		part, err := mv.MessageView().BodyStructure().PartAtIndex(p.Index)
		if err != nil {
			app.PushError(err.Error())
			return
		}
		mimeType = part.FullMIMEType()

		tmpFile, err := os.CreateTemp(os.TempDir(), "aerc-*"+extension)
		tmpDir, err := os.MkdirTemp(os.TempDir(), "aerc-*")
		if err != nil {
			app.PushError(err.Error())
			return
		}
		tmpFile, err := os.Create(filepath.Join(tmpDir, part.FileName()))
		if err != nil {
			app.PushError(err.Error())
			return
@@ -74,7 +71,7 @@ func (o Open) Execute(args []string) error {
		go func() {
			defer log.PanicHandler()
			if o.Delete {
				defer os.Remove(tmpFile.Name())
				defer os.RemoveAll(tmpDir)
			}
			err = lib.XDGOpenMime(tmpFile.Name(), mimeType, o.Cmd)
			if err != nil {
-- 
2.44.0

[aerc/patches] build success

builds.sr.ht <builds@sr.ht>
Details
Message ID
<D0IT3YV005OS.2N93ZT6J0874G@fra01>
In-Reply-To
<20240413071009.52225-1-maarten@nlnetlabs.nl> (view parent)
DKIM signature
missing
Download raw message
aerc/patches: SUCCESS in 1m59s

[open: preserve the original filename][0] v2 from [Maarten Aertsen][1]

[0]: https://lists.sr.ht/~rjarry/aerc-devel/patches/50968
[1]: maarten@nlnetlabs.nl

✓ #1194566 SUCCESS aerc/patches/openbsd.yml     https://builds.sr.ht/~rjarry/job/1194566
✓ #1194565 SUCCESS aerc/patches/alpine-edge.yml https://builds.sr.ht/~rjarry/job/1194565
Details
Message ID
<D0IUZXLRWS93.1SFMYHXGWZW2N@ferdinandy.com>
In-Reply-To
<20240413071009.52225-1-maarten@nlnetlabs.nl> (view parent)
DKIM signature
missing
Download raw message
On Sat Apr 13, 2024 at 09:09, Maarten Aertsen <maarten@nlnetlabs.nl> wrote:
> Change the name of the temporary file that is :open'ed using the system
> handler from `aerc-<randint>.ext` to
> `aerc-<randint>/<actual-filename.ext>`.  This preserves the original
> filename, while retaining collision avoidance and the current base
> location (os.TempDir()).
>
> Changelog-changed: `:open` commands now preserve the original filename.
> Signed-off-by: Maarten Aertsen <maarten@nlnetlabs.nl>
> Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
> ---
Still works

Tested-by: Bence Ferdinandy <bence@ferdinandy.com>



-- 
+36305425054
bence.ferdinandy.com

Applied: [PATCH aerc v2] open: preserve the original filename

Details
Message ID
<171303699167.143680.8873777393412997965@ringo>
In-Reply-To
<20240413071009.52225-1-maarten@nlnetlabs.nl> (view parent)
DKIM signature
pass
Download raw message
Maarten Aertsen <maarten@nlnetlabs.nl> wrote:
> Change the name of the temporary file that is :open'ed using the system
> handler from `aerc-<randint>.ext` to
> `aerc-<randint>/<actual-filename.ext>`.  This preserves the original
> filename, while retaining collision avoidance and the current base
> location (os.TempDir()).
>
> Changelog-changed: `:open` commands now preserve the original filename.
> Signed-off-by: Maarten Aertsen <maarten@nlnetlabs.nl>
> Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
> ---
> v1->v2:
>   - restore mimeType detection
>   - make linter happy

Acked-by: Robin Jarry <robin@jarry.cc>

Applied, thanks.

To git@git.sr.ht:~rjarry/aerc
   777bbb77e806..d99c49de2fc1  master -> master
Details
Message ID
<D0J9HQPA16N9.F0V87NK47LWK@ringo>
In-Reply-To
<20240413071009.52225-1-maarten@nlnetlabs.nl> (view parent)
DKIM signature
pass
Download raw message
Maarten Aertsen, Apr 13, 2024 at 09:10:
> Change the name of the temporary file that is :open'ed using the system
> handler from `aerc-<randint>.ext` to
> `aerc-<randint>/<actual-filename.ext>`.  This preserves the original
> filename, while retaining collision avoidance and the current base
> location (os.TempDir()).
>
> Changelog-changed: `:open` commands now preserve the original filename.
> Signed-off-by: Maarten Aertsen <maarten@nlnetlabs.nl>
> Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
> ---
> v1->v2:
>   - restore mimeType detection
>   - make linter happy

Acked-by: Robin-Jarry <robin@jarry.cc>

Applied. Thanks!
Details
Message ID
<D0JAU30ZRKZK.GUQ2NVYSVCCE@ferdinandy.com>
In-Reply-To
<D0J9HQPA16N9.F0V87NK47LWK@ringo> (view parent)
DKIM signature
missing
Download raw message
On Sat Apr 13, 2024 at 22:02, Robin Jarry <robin@jarry.cc> wrote:
> Maarten Aertsen, Apr 13, 2024 at 09:10:
> > Change the name of the temporary file that is :open'ed using the system
> > handler from `aerc-<randint>.ext` to
> > `aerc-<randint>/<actual-filename.ext>`.  This preserves the original
> > filename, while retaining collision avoidance and the current base
> > location (os.TempDir()).
> >
> > Changelog-changed: `:open` commands now preserve the original filename.
> > Signed-off-by: Maarten Aertsen <maarten@nlnetlabs.nl>
> > Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
> > ---
> > v1->v2:
> >   - restore mimeType detection
> >   - make linter happy
>
> Acked-by: Robin-Jarry <robin@jarry.cc>
>
> Applied. Thanks!

Unfortunately, I just got an error with this (tbh I only tested v1 and v2
didn't only just make the linter happy).

This is the structure:

(multipart/related)
    (text/html)
    ATT00001 (image/png)


Trying to open (text/html) leads to
open /tmp/aerc-4275665241: is a directory

The patch I guess is missing a check for missing filenames.

Best,
Bence

-- 
+36305425054
bence.ferdinandy.com
Reply to thread Export thread (mbox)