From 7a489cb0011a34a68d3e77d0174076857cc37902 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 19 Jul 2019 14:15:48 -0400 Subject: Add Unix socket for communicating with aerc --- widgets/aerc.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'widgets/aerc.go') diff --git a/widgets/aerc.go b/widgets/aerc.go index a73caecc..14cf3c44 100644 --- a/widgets/aerc.go +++ b/widgets/aerc.go @@ -1,7 +1,10 @@ package widgets import ( + "errors" "log" + "net/url" + "strings" "time" "github.com/gdamore/tcell" @@ -302,3 +305,40 @@ func (aerc *Aerc) BeginExCommand() { aerc.statusbar.Push(exline) aerc.focus(exline) } + +func (aerc *Aerc) Mailto(addr *url.URL) error { + acct := aerc.SelectedAccount() + if acct == nil { + return errors.New("No account selected") + } + defaults := make(map[string]string) + defaults["To"] = addr.Opaque + headerMap := map[string]string{ + "cc": "Cc", + "in-reply-to": "In-Reply-To", + "subject": "Subject", + } + for key, vals := range addr.Query() { + if header, ok := headerMap[strings.ToLower(key)]; ok { + defaults[header] = strings.Join(vals, ",") + } + } + composer := NewComposer(aerc.Config(), + acct.AccountConfig(), acct.Worker()).Defaults(defaults) + composer.FocusSubject() + title := "New email" + if subj, ok := defaults["Subject"]; ok { + title = subj + composer.FocusTerminal() + } + tab := aerc.NewTab(composer, title) + composer.OnSubjectChange(func(subject string) { + if subject == "" { + tab.Name = "New email" + } else { + tab.Name = subject + } + tab.Content.Invalidate() + }) + return nil +} -- cgit