Queuing mail with Rust and qmail

I am working on an application that needs to send email with qmail-queue. For those not familiar with this system, qmail-queue reads a pre-formatted email message on file descriptor 0 (stdin as usual) and then reads the envelope data (sender and list of recipients) on file descriptor 1 (stdout but in the opposite direction as usual).

I am looking at std::process, and I can't find a way to hook into stdout this way. Both Command and Child are designed for the normal use case, for reading from stdout (that the child process writes to).

Is there a way to accomplish this non-standard redirect in the standard library, or do I need to wire it up more manually with the libc crate?


1 Like

You can fork your own process, with fd substituted by anything you want. It's a bit more low-level, without nice std-lib support, and more of what you would do in raw C, but it's still possible in Rust. See https://github.com/dpc/colerr/blob/master/src/main.rs#L96

1 Like

Command has a stdin method that allows you set up a pipe between the parent and child process. The stdin member of Child should then have a non-None value, allows you to call methods like write on it. This seems to me like it should address your use case.

Yes, Command has a stdin method. The problem is I need to pipe data in to qmail-queue via both file descriptor 0 (stdin) and 1 (stdout), which is not how they are commonly used, and not how Command.stdout is wired up. As dpc pointed out, I'll just use libc for this.