Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit703596e

Browse files
committed
feature#46326 SMTP Transport to provide the (final) Message-ID if available (Raphaël Droz)
This PR was squashed before being merged into the 6.2 branch.Discussion----------SMTP Transport to provide the (final) Message-ID if availablebug#46323 [Mailer] SMTP transport does not provide the (final) Message-ID| Q | A| ------------- | ---| Branch? | 6.1| Bug fix? | yes| New feature? | no| Deprecations? | no| Tickets |Fix#46323| License | MIT| Doc PR | symfony/symfony-docs#Questions / Answers:- **Q**: Why storing 250 inside **`$mtaResult`** instead of using the already available `$message->getDebug()`?- A: Because the later may be huge (especially in case of attachment) and running a regexp over it would be less than safe. Instead `$mtaResult` only contains one line- **Q**: Why a new **`public`** method?- A: Because child SMTP Transport may make other assumptions about the return `250 Ok` value and provide a custom logic / regexp.- **Q**: Why **regexp**?- A: Because there is no official standard for this line (other than the `250 Ok` prefix)Additionally (seehttps://symfony.com/releases):- [ ] Always add tests and ensure they pass. _I can't. Don't have the time. Left to maintainers / other contributors_- [x] Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too.)- [x] Features and deprecations must be submitted against the latest branch.- [x] Changelog entry should followhttps://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry- [x] Never break backward compatibility (seehttps://symfony.com/bc).Commits-------441c9b0 SMTP Transport to provide the (final) Message-ID if available
2 parents5675aa8 +441c9b0 commit703596e

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

‎src/Symfony/Component/Mailer/Transport/Smtp/SmtpTransport.php‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class SmtpTransport extends AbstractTransport
3838
privateint$pingThreshold =100;
3939
privatefloat$lastMessageTime =0;
4040
privateAbstractStream$stream;
41+
privatestring$mtaResult ='';
4142
privatestring$domain ='[127.0.0.1]';
4243

4344
publicfunction__construct(AbstractStream$stream =null,EventDispatcherInterface$dispatcher =null,LoggerInterface$logger =null)
@@ -146,11 +147,38 @@ public function send(RawMessage $message, Envelope $envelope = null): ?SentMessa
146147
throw$e;
147148
}
148149

150+
$messageId =$this->parseMessageId($this->mtaResult);
151+
if ($messageId) {
152+
$message->setMessageId($messageId);
153+
}
154+
149155
$this->checkRestartThreshold();
150156

151157
return$message;
152158
}
153159

160+
protectedfunctionparseMessageId(string$mtaResult): ?string
161+
{
162+
$regexps = [
163+
'/250 Ok (?P<id>[0-9a-f-]+)\r?$/mis',
164+
'/250 Ok:? queued as (?P<id>[A-Z0-9]+)\r?$/mis'
165+
];
166+
167+
if ($mtaResult ==='') {
168+
returnnull;
169+
}
170+
171+
$matches = [];
172+
foreach ($regexpsas$regexp) {
173+
preg_match($regexp,$mtaResult,$matches);
174+
if (!empty($matches['id'])) {
175+
return$matches['id'];
176+
}
177+
}
178+
179+
returnnull;
180+
}
181+
154182
publicfunction__toString():string
155183
{
156184
if ($this->streaminstanceof SocketStream) {
@@ -213,7 +241,7 @@ protected function doSend(SentMessage $message): void
213241
$this->getLogger()->debug(sprintf('Email transport "%s" stopped',__CLASS__));
214242
throw$e;
215243
}
216-
$this->executeCommand("\r\n.\r\n", [250]);
244+
$this->mtaResult =$this->executeCommand("\r\n.\r\n", [250]);
217245
$message->appendDebug($this->stream->getDebug());
218246
$this->lastMessageTime =microtime(true);
219247
}catch (TransportExceptionInterface$e) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp