about summary refs log tree commit diff stats
path: root/commands
diff options
context:
space:
mode:
Diffstat (limited to 'commands')
-rw-r--r--commands/compose/send.go46
1 files changed, 36 insertions, 10 deletions
diff --git a/commands/compose/send.go b/commands/compose/send.go
index 26df82a..0574075 100644
--- a/commands/compose/send.go
+++ b/commands/compose/send.go
@@ -6,6 +6,7 @@ import (
 	"io"
 	"net/mail"
 	"net/url"
+	"os/exec"
 	"strings"
 	"time"
 
@@ -56,14 +57,16 @@ func (_ Send) Execute(aerc *widgets.Aerc, args []string) error {
 		scheme string
 		auth   string = "plain"
 	)
-	parts := strings.Split(uri.Scheme, "+")
-	if len(parts) == 1 {
-		scheme = parts[0]
-	} else if len(parts) == 2 {
-		scheme = parts[0]
-		auth = parts[1]
-	} else {
-		return fmt.Errorf("Unknown transfer protocol %s", uri.Scheme)
+	if uri.Scheme != "" {
+		parts := strings.Split(uri.Scheme, "+")
+		if len(parts) == 1 {
+			scheme = parts[0]
+		} else if len(parts) == 2 {
+			scheme = parts[0]
+			auth = parts[1]
+		} else {
+			return fmt.Errorf("Unknown transfer protocol %s", uri.Scheme)
+		}
 	}
 
 	header, rcpts, err := composer.PrepareHeader()
@@ -102,7 +105,7 @@ func (_ Send) Execute(aerc *widgets.Aerc, args []string) error {
 		starttls = starttls_ == "yes"
 	}
 
-	sendAsync := func() (int, error) {
+	smtpAsync := func() (int, error) {
 		switch scheme {
 		case "smtp":
 			host := uri.Host
@@ -154,7 +157,6 @@ func (_ Send) Execute(aerc *widgets.Aerc, args []string) error {
 			defer conn.Close()
 		}
 
-		// TODO: sendmail
 		if saslClient != nil {
 			if err = conn.Auth(saslClient); err != nil {
 				return 0, errors.Wrap(err, "conn.Auth")
@@ -180,6 +182,30 @@ func (_ Send) Execute(aerc *widgets.Aerc, args []string) error {
 		return int(ctr.Count()), nil
 	}
 
+	sendmailAsync := func() (int, error) {
+		cmd := exec.Command(uri.Path, rcpts...)
+		wc, err := cmd.StdinPipe()
+		if err != nil {
+			return 0, errors.Wrap(err, "cmd.StdinPipe")
+		}
+		defer wc.Close()
+		go cmd.Run()
+		ctr := datacounter.NewWriterCounter(wc)
+		composer.WriteMessage(header, ctr)
+		return int(ctr.Count()), nil
+	}
+
+	sendAsync := func() (int, error) {
+		switch scheme {
+		case "smtp":
+		case "smtps":
+			return smtpAsync()
+		case "":
+			return sendmailAsync()
+		}
+		return 0, errors.New("Unknown scheme")
+	}
+
 	go func() {
 		aerc.SetStatus("Sending...")
 		nbytes, err := sendAsync()