32 lines
748 B
PHP
32 lines
748 B
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Services\SandboxMailParser;
|
|
use Illuminate\Console\Command;
|
|
|
|
class SandboxReceive extends Command
|
|
{
|
|
protected $signature = 'sandbox:receive {--to=* : Envelope recipients}';
|
|
protected $description = 'Receive a raw email from Postfix pipe and store in sandbox';
|
|
|
|
public function handle(SandboxMailParser $parser): int
|
|
{
|
|
$raw = '';
|
|
$stdin = fopen('php://stdin', 'r');
|
|
while (!feof($stdin)) {
|
|
$raw .= fread($stdin, 8192);
|
|
}
|
|
fclose($stdin);
|
|
|
|
if (empty(trim($raw))) {
|
|
return 1;
|
|
}
|
|
|
|
$recipients = $this->option('to') ?? [];
|
|
$parser->parseAndStore($raw, $recipients);
|
|
|
|
return 0;
|
|
}
|
|
}
|