From 805a29aef9320545ec113208df5a04e454ac7fb8 Mon Sep 17 00:00:00 2001 From: Bence Ferdinandy Date: Sat, 13 Apr 2024 13:39:51 +0200 Subject: attach: use absolute paths instead of relative Sometimes it is easier to change folders when adding attachments, but currently we store relative paths, which doesn't work with this. Add the absolute paths when attaching files. Replace the current user home dir with ~ to make it prettier in the UI. Implements: https://todo.sr.ht/~rjarry/aerc/134 Signed-off-by: Bence Ferdinandy Acked-by: Robin Jarry --- app/compose.go | 4 ++++ lib/attachment.go | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/compose.go b/app/compose.go index 9f9ebf39..38d94359 100644 --- a/app/compose.go +++ b/app/compose.go @@ -8,6 +8,7 @@ import ( "net/textproto" "os" "os/exec" + "path/filepath" "sort" "strconv" "strings" @@ -29,6 +30,7 @@ import ( "git.sr.ht/~rjarry/aerc/lib/state" "git.sr.ht/~rjarry/aerc/lib/templates" "git.sr.ht/~rjarry/aerc/lib/ui" + "git.sr.ht/~rjarry/aerc/lib/xdg" "git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/worker/types" "git.sr.ht/~rockorager/vaxis" @@ -1119,6 +1121,8 @@ func (c *Composer) GetAttachments() []string { } func (c *Composer) AddAttachment(path string) { + path, _ = filepath.Abs(path) + path = xdg.TildeHome(path) c.attachments = append(c.attachments, lib.NewFileAttachment(path)) c.resetReview() } diff --git a/lib/attachment.go b/lib/attachment.go index a5f1b034..4dd3f41d 100644 --- a/lib/attachment.go +++ b/lib/attachment.go @@ -11,6 +11,7 @@ import ( "strings" "git.sr.ht/~rjarry/aerc/lib/log" + "git.sr.ht/~rjarry/aerc/lib/xdg" "github.com/emersion/go-message/mail" "github.com/pkg/errors" ) @@ -68,7 +69,7 @@ func (fa *FileAttachment) Name() string { } func (fa *FileAttachment) WriteTo(w *mail.Writer) error { - f, err := os.Open(fa.path) + f, err := os.Open(xdg.ExpandHome(fa.path)) if err != nil { return errors.Wrap(err, "os.Open") } -- cgit