Skip to content

[Mailer] Logger vs debug mailer #32583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[Mailer] added support ffor debug info when using SMTP
  • Loading branch information
fabpot committed Jul 18, 2019
commit fded3cd68cf4422d427a15a503f2fe21428c29d5
27 changes: 14 additions & 13 deletions src/Symfony/Component/Mailer/Transport/Smtp/SmtpTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ public function send(RawMessage $message, SmtpEnvelope $envelope = null): ?SentM
*/
public function executeCommand(string $command, array $codes): string
{
$this->getLogger()->debug(sprintf('Email transport "%s" sent command "%s"', __CLASS__, trim($command)));
$this->stream->write($command);
$response = $this->getFullResponse();
$this->assertResponseCode($response, $codes);
Expand All @@ -145,18 +144,22 @@ public function executeCommand(string $command, array $codes): string

protected function doSend(SentMessage $message): void
{
$envelope = $message->getEnvelope();
$this->doMailFromCommand($envelope->getSender()->toString());
foreach ($envelope->getRecipients() as $recipient) {
$this->doRcptToCommand($recipient->toString());
}
try {
$envelope = $message->getEnvelope();
$this->doMailFromCommand($envelope->getSender()->toString());
foreach ($envelope->getRecipients() as $recipient) {
$this->doRcptToCommand($recipient->toString());
}

$this->executeCommand("DATA\r\n", [354]);
foreach (AbstractStream::replace("\r\n.", "\r\n..", $message->toIterable()) as $chunk) {
$this->stream->write($chunk);
$this->executeCommand("DATA\r\n", [354]);
foreach (AbstractStream::replace("\r\n.", "\r\n..", $message->toIterable()) as $chunk) {
$this->stream->write($chunk, false);
}
$this->stream->flush();
$this->executeCommand("\r\n.\r\n", [250]);
} finally {
$message->appendDebug($this->stream->getDebug());
}
$this->stream->flush();
$this->executeCommand("\r\n.\r\n", [250]);
}

protected function doHeloCommand(): void
Expand Down Expand Up @@ -237,8 +240,6 @@ private function assertResponseCode(string $response, array $codes): void
list($code) = sscanf($response, '%3d');
$valid = \in_array($code, $codes);

$this->getLogger()->debug(sprintf('Email transport "%s" received response "%s" (%s).', __CLASS__, trim($response), $valid ? 'ok' : 'error'));

if (!$valid) {
throw new TransportException(sprintf('Expected response code "%s" but got code "%s", with message "%s".', implode('/', $codes), $code, trim($response)), $code);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,16 @@ abstract class AbstractStream
protected $in;
protected $out;

public function write(string $bytes): void
private $debug = '';

public function write(string $bytes, $debug = true): void
{
if ($debug) {
foreach (explode("\n", trim($bytes)) as $line) {
$this->debug .= sprintf("> %s\n", $line);
}
}

$bytesToWrite = \strlen($bytes);
$totalBytesWritten = 0;
while ($totalBytesWritten < $bytesToWrite) {
Expand Down Expand Up @@ -74,9 +82,19 @@ public function readLine(): string
}
}

$this->debug .= sprintf('< %s', $line);

return $line;
}

public function getDebug(): string
{
$debug = $this->debug;
$this->debug = '';

return $debug;
}

public static function replace(string $from, string $to, iterable $chunks): \Generator
{
if ('' === $from) {
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy