aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMoritz Poldrack <git@moritz.sh>2022-10-09 00:52:43 +0200
committerRobin Jarry <robin@jarry.cc>2022-10-12 22:16:45 +0200
commit87d856c10cd500fb588d2af4cb2f590e21c6cee4 (patch)
tree085918762e0263691f70546542c6b40157520faa
parentba24e92062f1a9b38065d503fd1dde749c27a56c (diff)
downloadaerc-87d856c10cd500fb588d2af4cb2f590e21c6cee4.tar.gz
mailto: allow attaching of files
Some programs like Skanpage allow sharing files via email and attaching them automatically from the mailto: link. This patch introduces parsing of the attach query argument in mailto links and attaches the listed files. A potential file:// URL has it's prefix removed. Signed-off-by: Moritz Poldrack <git@moritz.sh> Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r--CHANGELOG.md1
-rw-r--r--widgets/aerc.go10
2 files changed, 11 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f3ab262e..e897e4b1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Specify opener as the first `:open` param instead of always using default
handler (i.e. `:open gimp` to open attachment in GIMP).
- Restored XOAUTH2 support for IMAP and SMTP.
+- Support for attaching files with `mailto:`-links
### Changed
diff --git a/widgets/aerc.go b/widgets/aerc.go
index 56972771..35c32fe3 100644
--- a/widgets/aerc.go
+++ b/widgets/aerc.go
@@ -644,6 +644,7 @@ func (aerc *Aerc) Mailto(addr *url.URL) error {
var subject string
var body string
var acctName string
+ var attachments []string
h := &mail.Header{}
to, err := mail.ParseAddressList(addr.Opaque)
if err != nil && addr.Opaque != "" {
@@ -679,6 +680,11 @@ func (aerc *Aerc) Mailto(addr *url.URL) error {
case "subject":
subject = strings.Join(vals, ",")
h.SetText("Subject", subject)
+ case "attach":
+ for _, path := range vals {
+ // remove a potential file:// prefix.
+ attachments = append(attachments, strings.TrimPrefix(path, "file://"))
+ }
default:
// any other header gets ignored on purpose to avoid control headers
// being injected
@@ -720,6 +726,10 @@ func (aerc *Aerc) Mailto(addr *url.URL) error {
}
ui.Invalidate()
})
+
+ for _, file := range attachments {
+ composer.AddAttachment(file)
+ }
return nil
}