summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-07-27 11:19:49 -0400
committerDrew DeVault <sir@cmpwn.com>2019-07-27 11:19:49 -0400
commit48758136c03b89757f7df1dd26331169c3d4ca02 (patch)
treef5c379b9be3ce1fa0fcc37c26d6b1a6131742121
parent7a3765a36bfa1c54f8bc77c761a741d5529addcf (diff)
downloadaerc-48758136c03b89757f7df1dd26331169c3d4ca02.tar.gz
Implement sendmail support
-rw-r--r--Makefile3
-rw-r--r--commands/compose/send.go46
-rw-r--r--doc/aerc-config.5.scd2
-rw-r--r--doc/aerc-imap.5.scd2
-rw-r--r--doc/aerc-sendmail.5.scd31
-rw-r--r--doc/aerc-smtp.5.scd2
-rw-r--r--doc/aerc.1.scd2
7 files changed, 74 insertions, 14 deletions
diff --git a/Makefile b/Makefile
index 4e76dcb..a78ef1c 100644
--- a/Makefile
+++ b/Makefile
@@ -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)
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()
diff --git a/doc/aerc-config.5.scd b/doc/aerc-config.5.scd
index 592b7af..7282311 100644
--- a/doc/aerc-config.5.scd
+++ b/doc/aerc-config.5.scd
@@ -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
 
diff --git a/doc/aerc-imap.5.scd b/doc/aerc-imap.5.scd
index 4307238..a34855f 100644
--- a/doc/aerc-imap.5.scd
+++ b/doc/aerc-imap.5.scd
@@ -63,7 +63,7 @@ available:
 
 # SEE ALSO
 
-*aerc*(1) *aerc-config*(5) *aerc-smtp*(5)
+*aerc*(1) *aerc-config*(5)
 
 # AUTHORS
 
diff --git a/doc/aerc-sendmail.5.scd b/doc/aerc-sendmail.5.scd
new file mode 100644
index 0000000..90118fb
--- /dev/null
+++ b/doc/aerc-sendmail.5.scd
@@ -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.
diff --git a/doc/aerc-smtp.5.scd b/doc/aerc-smtp.5.scd
index 15e03de..e455001 100644
--- a/doc/aerc-smtp.5.scd
+++ b/doc/aerc-smtp.5.scd
@@ -51,7 +51,7 @@ available:
 
 # SEE ALSO
 
-*aerc*(1) *aerc-config*(5) *aerc-smtp*(5)
+*aerc*(1) *aerc-config*(5)
 
 # AUTHORS
 
diff --git a/doc/aerc.1.scd b/doc/aerc.1.scd
index 7989ad9..8401d64 100644
--- a/doc/aerc.1.scd
+++ b/doc/aerc.1.scd
@@ -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