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>
This commit is contained in:
Moritz Poldrack 2022-10-09 00:52:43 +02:00 committed by Robin Jarry
parent ba24e92062
commit 87d856c10c
2 changed files with 11 additions and 0 deletions

View file

@ -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

View file

@ -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
}