summary refs log tree commit diff stats
path: root/widgets
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-07-19 14:15:48 -0400
committerDrew DeVault <sir@cmpwn.com>2019-07-19 14:15:48 -0400
commit7a489cb0011a34a68d3e77d0174076857cc37902 (patch)
treed21df8ea9b872ccc08cff117f203ad0d80b94a26 /widgets
parentb3a66866b95d77f202f571efedd2f7ec309aacf5 (diff)
downloadaerc-7a489cb0011a34a68d3e77d0174076857cc37902.tar.gz
Add Unix socket for communicating with aerc
Diffstat (limited to 'widgets')
-rw-r--r--widgets/aerc.go40
-rw-r--r--widgets/compose.go7
2 files changed, 47 insertions, 0 deletions
diff --git a/widgets/aerc.go b/widgets/aerc.go
index a73caec..14cf3c4 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
+}
diff --git a/widgets/compose.go b/widgets/compose.go
index f1c8014..401815c 100644
--- a/widgets/compose.go
+++ b/widgets/compose.go
@@ -138,6 +138,13 @@ func (c *Composer) FocusTerminal() *Composer {
 	return c
 }
 
+func (c *Composer) FocusSubject() *Composer {
+	c.focusable[c.focused].Focus(false)
+	c.focused = 2
+	c.focusable[c.focused].Focus(true)
+	return c
+}
+
 func (c *Composer) OnSubjectChange(fn func(subject string)) {
 	c.headers.subject.OnChange(func() {
 		fn(c.headers.subject.input.String())