toWire($tag); $this->logger?->debug('IMAP command sent: {raw}', [ 'tag' => $tag, 'command' => strtok($frame->commandLine(), ' ') ?: $frame->commandLine(), 'raw' => $this->sanitizeWire($wire), ]); $this->connection->write($wire); } private function sanitizeWire(string $wire): string { $trimmed = rtrim($wire, "\r\n"); if (preg_match('/^(\S+\s+LOGIN\s+".*?"\s+)".*"$/i', $trimmed, $matches)) { return $matches[1] . '"[REDACTED]"'; } if (preg_match('/^(\S+\s+AUTHENTICATE\s+\S+)(?:\s+.+)?$/i', $trimmed, $matches)) { return $matches[1] . ' [REDACTED]'; } return $trimmed; } }