Forward mailto links to server via ./aerc <mailto>

This commit is contained in:
Drew DeVault 2019-07-19 14:34:13 -04:00
parent 7a489cb001
commit 66a9052f0f
2 changed files with 25 additions and 3 deletions

11
aerc.go
View file

@ -94,15 +94,15 @@ var (
) )
func usage() { func usage() {
log.Fatal("Usage: aerc [-v]") log.Fatal("Usage: aerc [-v] [mailto:...]")
} }
func main() { func main() {
// TODO: Support starting with mailto links, ad-hoc accounts, etc
opts, optind, err := getopt.Getopts(os.Args, "v") opts, optind, err := getopt.Getopts(os.Args, "v")
if err != nil { if err != nil {
log.Print(err) log.Print(err)
usage() usage()
return
} }
for _, opt := range opts { for _, opt := range opts {
switch opt.Option { switch opt.Option {
@ -111,8 +111,13 @@ func main() {
return return
} }
} }
if optind != len(os.Args) { args := os.Args[optind:]
if len(args) > 1 {
usage() usage()
return
} else if len(args) == 1 {
lib.ConnectAndExec(args[0])
return
} }
var ( var (

View file

@ -2,6 +2,7 @@ package lib
import ( import (
"bufio" "bufio"
"errors"
"fmt" "fmt"
"log" "log"
"net" "net"
@ -80,3 +81,19 @@ func (as *AercServer) handleClient(conn net.Conn) {
} }
as.logger.Printf("Closed Unix connection %d", clientId) as.logger.Printf("Closed Unix connection %d", clientId)
} }
func ConnectAndExec(msg string) error {
sockpath := path.Join(xdg.RuntimeDir(), "aerc.sock")
conn, err := net.Dial("unix", sockpath)
if err != nil {
return err
}
conn.Write([]byte(msg + "\n"))
scanner := bufio.NewScanner(conn)
if !scanner.Scan() {
return errors.New("No response from server")
}
result := scanner.Text()
fmt.Println(result)
return nil
}