48758136c03b89757f7df1dd26331169c3d4ca02 — Drew DeVault 3 months ago 7a3765a
Implement sendmail support
M Makefile => Makefile +3 -0
@@ 31,6 31,7 @@ DOCS := \
 	aerc-config.5 \
 	aerc-imap.5 \
 	aerc-maildir.5 \
+	aerc-sendmail.5 \
 	aerc-smtp.5 \
 	aerc-tutorial.7
 


@@ 61,6 62,7 @@ install: all
 	install -m644 aerc-config.5 $(MANDIR)/man5/aerc-config.5
 	install -m644 aerc-imap.5 $(MANDIR)/man5/aerc-imap.5
 	install -m644 aerc-maildir.5 $(MANDIR)/man5/aerc-maildir.5
+	install -m644 aerc-sendmail.5 $(MANDIR)/man5/aerc-sendmail.5
 	install -m644 aerc-smtp.5 $(MANDIR)/man5/aerc-smtp.5
 	install -m644 aerc-tutorial.7 $(MANDIR)/man7/aerc-tutorial.7
 	install -m644 config/accounts.conf $(SHAREDIR)/accounts.conf


@@ 81,6 83,7 @@ uninstall:
 	$(RM) $(MANDIR)/man5/aerc-config.5
 	$(RM) $(MANDIR)/man5/aerc-imap.5
 	$(RM) $(MANDIR)/man5/aerc-maildir.5
+	$(RM) $(MANDIR)/man5/aerc-sendmail.5
 	$(RM) $(MANDIR)/man5/aerc-smtp.5
 	$(RM) $(MANDIR)/man7/aerc-tutorial.7
 	$(RM) -r $(SHAREDIR)

M commands/compose/send.go => commands/compose/send.go +36 -10
@@ 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()

M doc/aerc-config.5.scd => doc/aerc-config.5.scd +1 -1
@@ 417,7 417,7 @@ following special keys are supported:
 
 # SEE ALSO
 
-*aerc*(1) *aerc-imap*(5) *aerc-smtp*(5) *aerc-maildir*(5)
+*aerc*(1) *aerc-imap*(5) *aerc-smtp*(5) *aerc-maildir*(5) *aerc-sendmail*(5)
 
 # AUTHORS
 

M doc/aerc-imap.5.scd => doc/aerc-imap.5.scd +1 -1
@@ 63,7 63,7 @@ available:
 
 # SEE ALSO
 
-*aerc*(1) *aerc-config*(5) *aerc-smtp*(5)
+*aerc*(1) *aerc-config*(5)
 
 # AUTHORS
 

A doc/aerc-sendmail.5.scd => doc/aerc-sendmail.5.scd +31 -0
@@ 0,0 1,31 @@
+aerc-sendmail(5)
+
+# NAME
+
+aerc-sendmail - sendmail configuration for *aerc*(1)
+
+# SYNOPSIS
+
+aerc can defer to sendmail for the delivery of outgoing messages.
+
+# CONFIGURATION
+
+In accounts.conf (see *aerc-config*(5)), the following sendmail-specific
+options are available:
+
+*outgoing*
+	/path/to/sendmail
+
+	This should be set to the path to the sendmail binary you wish to use,
+	which is generally /usr/bin/sendmail. aerc will execute it with a list of
+	recipients on the command line and pipe the message to deliver to stdin.
+
+# SEE ALSO
+
+*aerc*(1) *aerc-config*(5)
+
+# AUTHORS
+
+Maintained by Drew DeVault <sir@cmpwn.com>, who is assisted by other open
+source contributors. For more information about aerc development, see
+https://git.sr.ht/~sircmpwn/aerc.

M doc/aerc-smtp.5.scd => doc/aerc-smtp.5.scd +1 -1
@@ 51,7 51,7 @@ available:
 
 # SEE ALSO
 
-*aerc*(1) *aerc-config*(5) *aerc-smtp*(5)
+*aerc*(1) *aerc-config*(5)
 
 # AUTHORS
 

M doc/aerc.1.scd => doc/aerc.1.scd +1 -1
@@ 246,7 246,7 @@ write log messages to that file:
 # SEE ALSO
 
 *aerc-config*(5) *aerc-imap*(5) *aerc-smtp*(5) *aerc-maildir*(5)
-*aerc-tutorial*(7)
+*aerc-sendmail*(5) *aerc-tutorial*(7)
 
 # AUTHORS