~sircmpwn/aerc

Adds FIFO support v1 PROPOSED

Sebastian
Sebastian: 1
 Adds FIFO support

 4 files changed, 49 insertions(+), 0 deletions(-)
Sebastian
Thanks for the feedback. I'll make some changes to the patch.

On Mon Mar 29, 2021 at 5:34 AM EDT, wagner riffel wrote:
> This ability through a pipe is quite unusual, there is any other email
> client that has this feature?
My desire for a feature like this comes from me wanting programs
running within the terminal emulator to be able to open new tabs within
aerc. Simply writing a command to a FIFO seems like the simplest and
most intuitive way to do this.
More specifically, I usually have my RSS reader open as a tab in aerc,
because it makes sense to me that email and RSS feeds go together.
However, opening articles in my RSS reader just opens them in the
foreground of that tab, rather than in a new aerc tab, which would
integrate more nicely. With the ability to write aerc commands to a
FIFO, implementing this functionality would be trivial.
> I think that if we instead take a
> "commands" file to be executed as an argument, would be more roboust
> than all the bookkeeping involved with the fifo file; (configuration,
> stat, create, remove...)
I agree. I'll remove the configuration option and instead use a command
line argument which points to an already existing FIFO, so aerc doesn't
have to create nor remove anything. This also has the benefit that the
absense of the command line argument can indicate that no FIFO should
be read from.

On Mon Mar 29, 2021 at 4:46 AM EDT, "Reto" wrote:
> Why are you creating a new FIFO when we already have a socket available?
> Can't we just plug this in as a new command in the socket handler?
I'm not entirely sure how the socket works in aerc; I wasn't able to
find any mention of it in the documentation (though it's possible I
didn't look hard enough :). I would imagine that writing to a FIFO
would be simpler, though. Although I will remove the code that makes
aerc responsible for creating and managing the FIFO.

Once again, thanks for the feedback. I'm relatively inexperienced with
Go, but I'm trying my best to write code that's as clean and concise as
possible.
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/aerc/patches/21583/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH] Adds FIFO support Export this patch

Sebastian
This commit give aerc the ability to read commands through a FIFO
(named pipe). A configuration option in aerc.conf is added in the
general section called `fifo-path`, which takes in a string for the
destination of the FIFO. The default is /usr/share/aerc/fifo. Text
written to the FIFO is interpreted as a command and immediately
executed by aerc.
---
This is my first time using git send-email; sorry if I messed anything up
 Makefile         |  1 +
 aerc.go          |  2 ++
 config/config.go |  5 +++++
 widgets/aerc.go  | 41 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 49 insertions(+)

diff --git a/Makefile b/Makefile
index 661acef..46a4c85 100644
--- a/Makefile
+++ b/Makefile
@@ -91,6 +91,7 @@ install: all
	install -m644 templates/quoted_reply $(DESTDIR)$(SHAREDIR)/templates/quoted_reply
	install -m644 templates/forward_as_body $(DESTDIR)$(SHAREDIR)/templates/forward_as_body
	install -m644 config/default_styleset $(DESTDIR)$(SHAREDIR)/stylesets/default
	mkfifo -m666 $(DESTDIR)$(SHAREDIR)/fifo

RMDIR_IF_EMPTY:=sh -c '\
if test -d $$0 && ! ls -1qA $$0 | grep -q . ; then \
diff --git a/aerc.go b/aerc.go
index 33acb43..c056702 100644
--- a/aerc.go
+++ b/aerc.go
@@ -185,6 +185,8 @@ func main() {
		as.OnMailto = aerc.Mailto
	}

	go aerc.ListenFifo()

	// set the aerc version so that we can use it in the template funcs
	templates.SetVersion(Version)

diff --git a/config/config.go b/config/config.go
index 8b409fe..e59588d 100644
--- a/config/config.go
+++ b/config/config.go
@@ -24,6 +24,7 @@ import (

type GeneralConfig struct {
	DefaultSavePath string `ini:"default-save-path"`
	FifoPath        string `ini:"fifo-path"`
}

type UIConfig struct {
@@ -486,6 +487,10 @@ func LoadConfigFromFile(root *string, sharedir string) (*AercConfig, error) {
		},
		Ini: file,

		General: GeneralConfig{
			FifoPath: "/usr/share/aerc/fifo",
		},

		Ui: UIConfig{
			IndexFormat:     "%D %-17.17n %s",
			TimestampFormat: "2006-01-02 03:04 PM",
diff --git a/widgets/aerc.go b/widgets/aerc.go
index 6df0c95..1e311a6 100644
--- a/widgets/aerc.go
+++ b/widgets/aerc.go
@@ -4,9 +4,12 @@ import (
	"errors"
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"net/url"
	"os"
	"strings"
	"syscall"
	"time"

	"github.com/emersion/go-message/mail"
@@ -424,6 +427,44 @@ func (aerc *Aerc) focus(item ui.Interactive) {
	}
}

func (aerc *Aerc) ListenFifo() {
	fifopath := aerc.conf.General.FifoPath

	// check if fifo already exists
	fileinfo, err := os.Stat(fifopath)
	if err != nil {
		// make fifo
		err = syscall.Mkfifo(fifopath, 0o666)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Fatal: Failed to make FIFO: %v\n", err)
			os.Exit(1)
		}
	} else if !strings.Contains(fileinfo.Mode().String(), "p") {
		fmt.Fprintf(os.Stderr, "Fatal: File already exists, and isn't a FIFO")
		os.Exit(1)
	}
	defer os.Remove(fifopath)

	// read+exec loop
	for true {
		data, err := ioutil.ReadFile(fifopath)
		if err != nil {
			aerc.PushError(err.Error())
		} else {
			cmd := string(data)
			parts, err := shlex.Split(cmd)
			if err != nil {
				aerc.PushError(err.Error())
			}
			err = aerc.cmd(parts)
			if err != nil {
				aerc.PushError(err.Error())
			}
			aerc.logger.Printf("%s", data)
		}
	}
}

func (aerc *Aerc) BeginExCommand(cmd string) {
	previous := aerc.focused
	exline := NewExLine(aerc.conf, cmd, func(cmd string) {
-- 
2.31.0
Hi Sebastian,
Thanks for the patch, the functionality looks interesting.

On Sun, Mar 28, 2021 at 11:19:28PM -0400, Sebastian wrote: