Skip to content

[Web] Capture sendmail stdin in remote Playground instances - #4063

Merged
adamziel merged 1 commit into
trunkfrom
codex/register-sendmail-remote
Jul 15, 2026
Merged

[Web] Capture sendmail stdin in remote Playground instances#4063
adamziel merged 1 commit into
trunkfrom
codex/register-sendmail-remote

Conversation

@adamziel

@adamziel adamziel commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Adds sendmailSpawnHandler() (introduced in #3996) to PHP.wasm objects instantiated in the remote.html web worker. The handler catches any emails sent by WordPress and re-exposes it through an event listener as follows:

php.setCommandSpawnHandler('sendmail', sendmailSpawnHandler(php));

// In the website package:
php.addEventListener('sendmail.spawned', async (event) => {
	if (event.type !== 'sendmail.spawned') {
		return;
	}
	const rawMessage = await new Response(event.stdin).arrayBuffer();
	// Parse or relay rawMessage.
});

The goal is to expose these emails in the UI in a follow-up PR.

@adamziel
adamziel force-pushed the codex/register-sendmail-remote branch from 8a34311 to 6e59fca Compare July 15, 2026 17:10
@adamziel
adamziel force-pushed the codex/sendmail-mail-capture branch from 1023fef to 49267b4 Compare July 15, 2026 17:21
@adamziel
adamziel force-pushed the codex/register-sendmail-remote branch from 6e59fca to c2b98db Compare July 15, 2026 17:22
@adamziel
adamziel force-pushed the codex/sendmail-mail-capture branch from 49267b4 to 24034e3 Compare July 15, 2026 17:49
@adamziel
adamziel force-pushed the codex/register-sendmail-remote branch from c2b98db to 004de73 Compare July 15, 2026 17:49
@adamziel
adamziel force-pushed the codex/sendmail-mail-capture branch from 24034e3 to 7a67a7a Compare July 15, 2026 18:22
@adamziel
adamziel force-pushed the codex/register-sendmail-remote branch from 004de73 to 9dbf463 Compare July 15, 2026 18:23
@adamziel
adamziel force-pushed the codex/sendmail-mail-capture branch from 7a67a7a to 8ef5dcb Compare July 15, 2026 19:37
@adamziel
adamziel force-pushed the codex/register-sendmail-remote branch from 9dbf463 to 76e69da Compare July 15, 2026 19:37
@adamziel
adamziel force-pushed the codex/sendmail-mail-capture branch from 8ef5dcb to f5a59cd Compare July 15, 2026 19:41
@adamziel
adamziel force-pushed the codex/register-sendmail-remote branch from 76e69da to 4163e1d Compare July 15, 2026 19:41
adamziel added a commit that referenced this pull request Jul 15, 2026
PHP can write a message to `sendmail` through `mail()`, `popen()`, or
`proc_open()`, but PHP-WASM has no reusable transport for observing
those bytes. This adds a sendmail-compatible null transport. It never
delivers mail. It emits `sendmail.spawned` with raw stdin as a live
`ReadableStream<Uint8Array>`.

Registration is explicit:

```ts
import { sendmailSpawnHandler } from '@php-wasm/util';

php.setCommandSpawnHandler('sendmail', sendmailSpawnHandler(php));
php.addEventListener('sendmail.spawned', async (event) => {
	if (event.type !== 'sendmail.spawned') {
		return;
	}
	const rawMessage = await new Response(event.stdin).arrayBuffer();
	// Parse or relay rawMessage.
});
```

The event fires with the first stdin chunk, before PHP finishes writing.
The transport stays alive until stdin closes. Empty input exits with
`EX_TEMPFAIL` and emits no event. Input above 20 MB errors the stream
and exits with status 1. Cancelling the stream stops delivery to that
reader but keeps draining stdin, so PHP can finish writing and receive
the transport's exit status. There is no backpressure to PHP; a slow
listener may buffer the full message.

Node tests cover `mail()`, `proc_open()`, delayed input, empty and
oversized input, and runtime rotation. Browser tests cover live delivery
to multiple listeners and cancellation while PHP continues writing.

This PR does not install the transport by default. #4063 installs it in
remote Playground instances.

#4064 provides the marked stdin event transport and per-listener streams
used here.

Co-authored-by: Adam Zieliński <adam@adamziel.com>
Base automatically changed from codex/sendmail-mail-capture to trunk July 15, 2026 20:08
@adamziel
adamziel requested review from a team and JanJakes July 15, 2026 20:08
@adamziel
adamziel force-pushed the codex/register-sendmail-remote branch from 4163e1d to 6868c43 Compare July 15, 2026 20:09
@adamziel
adamziel merged commit 6c2935a into trunk Jul 15, 2026
53 checks passed
@adamziel
adamziel deleted the codex/register-sendmail-remote branch July 15, 2026 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment