Skip to content

Commit 1cd588c

Browse files
committed
UnidentifiedBounceReprocessor
1 parent 4ab076d commit 1cd588c

File tree

5 files changed

+48
-18
lines changed

5 files changed

+48
-18
lines changed

resources/translations/messages.en.xlf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,23 @@
296296
<target>Failed to send to: %email%</target>
297297
</trans-unit>
298298

299+
<trans-unit id="messaging.process_unidentified">
300+
<source>Reprocessing unidentified bounces</source>
301+
<target>Reprocessing unidentified bounces</target>
302+
</trans-unit>
303+
<trans-unit id="messaging.total_to_process">
304+
<source>%total% bounces to reprocess</source>
305+
<target>%total% bounces to reprocess</target>
306+
</trans-unit>
307+
<trans-unit id="messaging.bounce_process.report">
308+
<source>%count% out of %total% processed</source>
309+
<target>%count% out of %total% processed</target>
310+
</trans-unit>
311+
<trans-unit id="messaging.bounce_process.final_report">
312+
<source>%reparsed% bounces were re-processed and %reidentified% bounces were re-identified</source>
313+
<target>%reparsed% bounces were re-processed and %reidentified% bounces were re-identified</target>
314+
</trans-unit>
315+
299316
<!-- Subscription -->
300317
<trans-unit id="subscription.list_not_found">
301318
<source>Subscriber list not found.</source>

src/Domain/Messaging/Model/BounceStatus.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ enum BounceStatus: string
1010
case BouncedList = 'bounced list message %d';
1111
case DuplicateBounce = 'duplicate bounce for %d';
1212
case SystemMessage = 'bounced system message';
13-
case Unknown = 'unidentified bounce';
13+
case UnidentifiedBounce = 'unidentified bounce';
1414

1515
public function format(int $userId): string
1616
{

src/Domain/Messaging/Service/Processor/BounceDataProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function process(Bounce $bounce, ?string $msgId, ?int $userId, DateTimeIm
6464
return $this->handleMessageOnly(bounce: $bounce, msgId: (int)$msgId);
6565
}
6666

67-
$this->bounceManager->update(bounce: $bounce, status: BounceStatus::Unknown->value, comment: 'not processed');
67+
$this->bounceManager->update(bounce: $bounce, status: BounceStatus::UnidentifiedBounce->value, comment: 'not processed');
6868

6969
return false;
7070
}

src/Domain/Messaging/Service/Processor/UnidentifiedBounceReprocessor.php

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,66 +5,77 @@
55
namespace PhpList\Core\Domain\Messaging\Service\Processor;
66

77
use DateTimeImmutable;
8+
use PhpList\Core\Domain\Messaging\Model\BounceStatus;
89
use PhpList\Core\Domain\Messaging\Service\MessageParser;
910
use PhpList\Core\Domain\Messaging\Service\Manager\BounceManager;
1011
use Symfony\Component\Console\Style\SymfonyStyle;
12+
use Symfony\Contracts\Translation\TranslatorInterface;
1113

1214
class UnidentifiedBounceReprocessor
1315
{
1416
private BounceManager $bounceManager;
1517
private MessageParser $messageParser;
1618
private BounceDataProcessor $bounceDataProcessor;
17-
19+
private TranslatorInterface $translator;
1820

1921
public function __construct(
2022
BounceManager $bounceManager,
2123
MessageParser $messageParser,
2224
BounceDataProcessor $bounceDataProcessor,
25+
TranslatorInterface $translator,
2326
) {
2427
$this->bounceManager = $bounceManager;
2528
$this->messageParser = $messageParser;
2629
$this->bounceDataProcessor = $bounceDataProcessor;
30+
$this->translator = $translator;
2731
}
2832

2933
public function process(SymfonyStyle $inputOutput): void
3034
{
31-
$inputOutput->section('Reprocessing unidentified bounces');
32-
$bounces = $this->bounceManager->findByStatus('unidentified bounce');
35+
$inputOutput->section($this->translator->trans('Reprocessing unidentified bounces'));
36+
$bounces = $this->bounceManager->findByStatus(BounceStatus::UnidentifiedBounce->value);
3337
$total = count($bounces);
34-
$inputOutput->writeln(sprintf('%d bounces to reprocess', $total));
38+
$inputOutput->writeln($this->translator->trans('%total% bounces to reprocess', ['%total%' => $total]));
3539

3640
$count = 0;
3741
$reparsed = 0;
3842
$reidentified = 0;
3943
foreach ($bounces as $bounce) {
4044
$count++;
4145
if ($count % 25 === 0) {
42-
$inputOutput->writeln(sprintf('%d out of %d processed', $count, $total));
46+
$inputOutput->writeln($this->translator->trans('%count% out of %total% processed', [
47+
'%count%' => $count,
48+
'%total%' => $total
49+
]));
4350
}
4451

45-
$decodedBody = $this->messageParser->decodeBody($bounce->getHeader(), $bounce->getData());
52+
$decodedBody = $this->messageParser->decodeBody(header: $bounce->getHeader(), body: $bounce->getData());
4653
$userId = $this->messageParser->findUserId($decodedBody);
4754
$messageId = $this->messageParser->findMessageId($decodedBody);
4855

4956
if ($userId || $messageId) {
5057
$reparsed++;
5158
if ($this->bounceDataProcessor->process(
52-
$bounce,
53-
$messageId,
54-
$userId,
55-
new DateTimeImmutable()
59+
bounce: $bounce,
60+
msgId: $messageId,
61+
userId: $userId,
62+
bounceDate: new DateTimeImmutable()
5663
)
5764
) {
5865
$reidentified++;
5966
}
6067
}
6168
}
6269

63-
$inputOutput->writeln(sprintf('%d out of %d processed', $count, $total));
64-
$inputOutput->writeln(sprintf(
65-
'%d bounces were re-processed and %d bounces were re-identified',
66-
$reparsed,
67-
$reidentified
70+
$inputOutput->writeln($this->translator->trans('%count% out of %total% processed', [
71+
'%count%' => $count,
72+
'%total%' => $total
73+
]));
74+
$inputOutput->writeln($this->translator->trans(
75+
'%reparsed% bounces were re-processed and %reidentified% bounces were re-identified', [
76+
'%reparsed%' => $reparsed,
77+
'%reidentified%' => $reidentified,
78+
]
6879
));
6980
}
7081
}

tests/Unit/Domain/Messaging/Service/Processor/UnidentifiedBounceReprocessorTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use PHPUnit\Framework\MockObject\MockObject;
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Console\Style\SymfonyStyle;
16+
use Symfony\Component\Translation\Translator;
1617

1718
class UnidentifiedBounceReprocessorTest extends TestCase
1819
{
@@ -62,7 +63,8 @@ public function testProcess(): void
6263
$processor = new UnidentifiedBounceReprocessor(
6364
bounceManager: $this->bounceManager,
6465
messageParser: $this->messageParser,
65-
bounceDataProcessor: $this->dataProcessor
66+
bounceDataProcessor: $this->dataProcessor,
67+
translator: new Translator('en'),
6668
);
6769
$processor->process($this->io);
6870
}

0 commit comments

Comments
 (0)