Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions .coderabbit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ reviews:
suggested_labels: false
high_level_summary_in_walkthrough: false
poem: false
finishing_touches:
docstrings:
enabled: false
path_instructions:
- path: "src/Domain/**"
instructions: |
Expand Down
3 changes: 1 addition & 2 deletions src/Domain/Identity/Service/AdminCopyEmailSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ public function __invoke(string $subject, string $message, array $lists = []): v

foreach ($mails as $adminMail) {
$data = new MessagePrecacheDto();
$data->to = $adminMail;
$data->subject = $this->installationName . ' ' . $subject;
$data->content = $message;

$email = $this->systemEmailBuilder->buildSystemEmail(data: $data);
$email = $this->systemEmailBuilder->buildSystemEmail(data: $data, toEmail: $adminMail);
if ($email === null) {
$this->logger->warning('Failed to build admin copy email for recipient ' . $adminMail);
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ private function handleEmailSending(
$result = $this->campaignEmailBuilder->buildCampaignEmail(
messageId: $campaign->getId(),
data: $processed,
toEmail: $subscriber->getEmail(),
skipBlacklistCheck: false,
inBlast: true,
htmlPref: $subscriber->hasHtmlEmail(),
Expand All @@ -236,13 +237,13 @@ private function handleEmailSending(
$this->updateUserMessageStatus($userMessage, UserMessageStatus::NotSent);

$data = new MessagePrecacheDto();
$data->to = $this->configProvider->getValue(ConfigOption::ReportAddress);
$data->subject = $this->translator->trans('phpList system error');
$data->content = $this->translator->trans($e->getMessage());

$email = $this->systemEmailBuilder->buildCampaignEmail(
messageId: $campaign->getId(),
data: $data,
toEmail: $this->configProvider->getValue(ConfigOption::ReportAddress) ?? '',
);

$envelope = new Envelope(
Expand Down Expand Up @@ -270,7 +271,6 @@ private function handleAdminNotifications(Message $campaign, array $loadedMessag
$notifications = explode(',', $loadedMessageData['notify_start']);
foreach ($notifications as $notification) {
$data = new MessagePrecacheDto();
$data->to = $notification;
$data->subject = $this->translator->trans('Campaign started');
$data->content = $this->translator->trans(
'phplist has started sending the campaign with subject %subject%',
Expand All @@ -280,6 +280,7 @@ private function handleAdminNotifications(Message $campaign, array $loadedMessag
$email = $this->systemEmailBuilder->buildCampaignEmail(
messageId: $campaign->getId(),
data: $data,
toEmail: $notification
);

if (!$email) {
Expand Down
3 changes: 0 additions & 3 deletions src/Domain/Messaging/Model/Dto/MessagePrecacheDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class MessagePrecacheDto
public ?string $replyToName = null;
public ?string $fromName = null;
public ?string $fromEmail = null;
public ?string $to = null;
public string $subject = '';
public string $content = '';
public string $textContent = '';
Expand All @@ -23,8 +22,6 @@ class MessagePrecacheDto
public ?string $template = null;
public ?string $templateText = null;
public ?int $templateId = null;
// public string $htmlCharset= 'UTF-8';
// public string $textCharset= 'UTF-8';
public bool $userSpecificUrl = false;
public bool $googleTrack = false;
public array $adminAttributes = [];
Expand Down
3 changes: 1 addition & 2 deletions src/Domain/Messaging/Service/Builder/BaseEmailBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ protected function validateRecipientAndSubject(?string $to, ?string $subject): b

protected function passesBlacklistCheck(string $to, ?bool $skipBlacklistCheck): bool
{

if (!$skipBlacklistCheck && $this->blacklistRepository->isEmailBlacklisted($to)) {
$this->eventLogManager->log('', sprintf('Error, %s is blacklisted, not sending', $to));
$subscriber = $this->subscriberRepository->findOneByEmail($to);
Expand Down Expand Up @@ -103,7 +102,7 @@ protected function createBaseEmail(
?string $fromEmail,
?string $fromName,
?string $subject,
) : Email {
): Email {
$email = (new Email());
$destinationEmail = $this->resolveDestinationEmail($to);

Expand Down
28 changes: 22 additions & 6 deletions src/Domain/Messaging/Service/Builder/EmailBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use PhpList\Core\Domain\Configuration\Service\Manager\EventLogManager;
use PhpList\Core\Domain\Configuration\Service\Provider\ConfigProvider;
use PhpList\Core\Domain\Messaging\Exception\AttachmentException;
use PhpList\Core\Domain\Messaging\Exception\SubscriberNotFoundException;
use PhpList\Core\Domain\Messaging\Model\Dto\MessagePrecacheDto;
use PhpList\Core\Domain\Messaging\Service\AttachmentAdder;
use PhpList\Core\Domain\Messaging\Service\Constructor\CampaignMailContentBuilder;
Expand Down Expand Up @@ -65,20 +66,24 @@ public function __construct(
);
}

/** @return array{Email, OutputFormat}|null */
/**
* @return array{Email, OutputFormat}|null
* @throws SubscriberNotFoundException
*/
public function buildCampaignEmail(
int $messageId,
MessagePrecacheDto $data,
string $toEmail,
?bool $skipBlacklistCheck = false,
?bool $inBlast = true,
?bool $htmlPref = false,
?bool $isTestMail = false,
): ?array {
if (!$this->validateRecipientAndSubject(to: $data->to, subject: $data->subject)) {
if (!$this->validateRecipientAndSubject(to: $toEmail, subject: $data->subject)) {
return null;
}

if (!$this->passesBlacklistCheck(to: $data->to, skipBlacklistCheck: $skipBlacklistCheck)) {
if (!$this->passesBlacklistCheck(to: $toEmail, skipBlacklistCheck: $skipBlacklistCheck)) {
return null;
}

Expand All @@ -87,15 +92,15 @@ public function buildCampaignEmail(
$subject = (!$isTestMail ? '' : $this->translator->trans('(test)') . ' ') . $data->subject;

$email = $this->createBaseEmail(
to: $data->to,
to: $toEmail,
fromEmail: $fromEmail,
fromName: $fromName,
subject: $subject,
);
$this->addBaseCampaignHeaders(
email: $email,
messageId: $messageId,
originalTo: $data->to,
originalTo: $toEmail,
destinationEmail: $email->getTo()[0]->getAddress(),
inBlast: $inBlast,
);
Expand All @@ -109,7 +114,18 @@ public function buildCampaignEmail(
}
}

[$htmlMessage, $textMessage] = ($this->mailContentBuilder)(messagePrecacheDto: $data, campaignId: $messageId);
$receiver = $this->subscriberRepository->findOneByEmail($toEmail);
if (!$receiver) {
throw new SubscriberNotFoundException(
sprintf('Subscriber with email %s not found', $toEmail)
);
}

[$htmlMessage, $textMessage] = ($this->mailContentBuilder)(
messagePrecacheDto: $data,
receiver: $receiver,
campaignId: $messageId,
);
$sentAs = $this->applyContentAndFormatting(
email: $email,
htmlMessage: $htmlMessage,
Expand Down
3 changes: 3 additions & 0 deletions src/Domain/Messaging/Service/Builder/ForwardEmailBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,11 @@ public function buildForwardEmail(

$subject = $this->translator->trans('Fwd') . ': ' . stripslashes($data->subject);

$receiver = $this->subscriberRepository->findOneByEmail($friendEmail) ?? (new Subscriber($friendEmail));

[$htmlMessage, $textMessage] = ($this->mailContentBuilder)(
messagePrecacheDto: $data,
receiver: $receiver,
campaignId: $messageId,
forwardedBy: $forwardedBy,
forwardedPersonalNote: $forwardedPersonalNote,
Expand Down
18 changes: 10 additions & 8 deletions src/Domain/Messaging/Service/Builder/SystemEmailBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ public function __construct(
public function buildCampaignEmail(
int $messageId,
MessagePrecacheDto $data,
string $toEmail,
?bool $skipBlacklistCheck = false,
): ?Email {
if (!$this->validateRecipientAndSubject(to: $data->to, subject: $data->subject)) {
if (!$this->validateRecipientAndSubject(to: $toEmail, subject: $data->subject)) {
return null;
}

if (!$this->passesBlacklistCheck(to: $data->to, skipBlacklistCheck: $skipBlacklistCheck)) {
if (!$this->passesBlacklistCheck(to: $toEmail, skipBlacklistCheck: $skipBlacklistCheck)) {
return null;
}

Expand All @@ -69,7 +70,7 @@ public function buildCampaignEmail(
$replyTo = $messageReplyToAddress ?: $fromEmail;

$email = $this->createBaseEmail(
to: $data->to,
to: $toEmail,
fromEmail: $fromEmail,
fromName: $fromName,
subject: $data->subject,
Expand All @@ -79,7 +80,7 @@ public function buildCampaignEmail(
$this->addBaseCampaignHeaders(
email: $email,
messageId: $messageId,
originalTo: $data->to,
originalTo: $toEmail,
destinationEmail: $email->getTo()[0]->getAddress(),
inBlast: false,
);
Expand All @@ -97,13 +98,14 @@ public function buildCampaignEmail(

public function buildSystemEmail(
MessagePrecacheDto $data,
string $toEmail,
?bool $skipBlacklistCheck = false,
): ?Email {
if (!$this->validateRecipientAndSubject(to: $data->to, subject: $data->subject)) {
if (!$this->validateRecipientAndSubject(to: $toEmail, subject: $data->subject)) {
return null;
}

if (!$this->passesBlacklistCheck(to: $data->to, skipBlacklistCheck: $skipBlacklistCheck)) {
if (!$this->passesBlacklistCheck(to: $toEmail, skipBlacklistCheck: $skipBlacklistCheck)) {
return null;
}

Expand All @@ -113,14 +115,14 @@ public function buildSystemEmail(
$replyTo = $messageReplyToAddress ?: $fromEmail;

$email = $this->createBaseEmail(
to: $data->to,
to: $toEmail,
fromEmail: $fromEmail,
fromName: $fromName,
subject: $data->subject,
);
$email->replyTo($replyTo);

$this->addSystemHeaders(email: $email, originalTo: $data->to,);
$this->addSystemHeaders(email: $email, originalTo: $toEmail);

[$htmlMessage, $textMessage] = ($this->mailConstructor)(messagePrecacheDto: $data);
$email->text($textMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use PhpList\Core\Domain\Messaging\Model\Dto\MessagePrecacheDto;
use PhpList\Core\Domain\Subscription\Model\Subscriber;
use PhpList\Core\Domain\Subscription\Repository\SubscriberRepository;
use PhpList\Core\Domain\Messaging\Exception\SubscriberNotFoundException;
use Symfony\Component\DependencyInjection\Attribute\Autowire;

class CampaignMailContentBuilder
Expand All @@ -35,21 +34,16 @@ public function __construct(

public function __invoke(
MessagePrecacheDto $messagePrecacheDto,
Subscriber $receiver,
?int $campaignId = null,
?Subscriber $forwardedBy = null,
?string $forwardedPersonalNote = null,
): array {
$subscriber = $this->subscriberRepository->findOneByEmail($messagePrecacheDto->to);
if (!$subscriber) {
throw new SubscriberNotFoundException(
sprintf('Subscriber with email %s not found', $messagePrecacheDto->to)
);
}
$addDefaultStyle = false;

if ($messagePrecacheDto->userSpecificUrl) {
$userData = $this->subscriberRepository->getDataById($subscriber->getId());
$this->replaceUserSpecificRemoteContent($messagePrecacheDto, $subscriber, $userData);
if ($messagePrecacheDto->userSpecificUrl && $receiver->getId()) {
$userData = $this->subscriberRepository->getDataById($receiver->getId());
$this->replaceUserSpecificRemoteContent($messagePrecacheDto, $receiver, $userData);
}

$content = $messagePrecacheDto->content;
Expand Down Expand Up @@ -80,7 +74,7 @@ public function __invoke(

$textMessage = $this->placeholderProcessor->process(
value: $textMessage,
receiver: $subscriber,
receiver: $receiver,
format: OutputFormat::Text,
messagePrecacheDto: $messagePrecacheDto,
campaignId: $campaignId,
Expand All @@ -89,7 +83,7 @@ public function __invoke(

$htmlMessage = $this->placeholderProcessor->process(
value: $htmlMessage,
receiver: $subscriber,
receiver: $receiver,
format: OutputFormat::Html,
messagePrecacheDto: $messagePrecacheDto,
campaignId: $campaignId,
Expand Down
1 change: 0 additions & 1 deletion src/Domain/Messaging/Service/MessageDataLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ private function buildDefaultMessageData(): array
'footer' => $this->configProvider->getValue(ConfigOption::MessageFooter),
'forwardfooter' => $this->configProvider->getValue(ConfigOption::ForwardFooter),
'status' => '',
'tofield' => '',
'replyto' => '',
'targetlist' => [],
'criteria_match' => '',
Expand Down
1 change: 0 additions & 1 deletion src/Domain/Messaging/Service/MessagePrecacheService.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ private function populateBasicFields(
): void {
$messagePrecacheDto->fromName = $loadedMessageData['fromname'];
$messagePrecacheDto->fromEmail = $loadedMessageData['fromemail'];
$messagePrecacheDto->to = $loadedMessageData['tofield'];

//0013076: different content when forwarding 'to a friend'
$messagePrecacheDto->subject = $forwardContent
Expand Down
3 changes: 2 additions & 1 deletion src/Domain/Subscription/Model/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ class Subscriber implements DomainModel, Identity, CreationDate, ModificationDat
#[ORM\Column(name: 'foreignkey', type: 'string', length: 100, nullable: true)]
private ?string $foreignKey = null;

public function __construct()
public function __construct(string $email)
{
$this->email = $email;
$this->subscriptions = new ArrayCollection();
$this->attributes = new ArrayCollection();
$this->extraData = '';
Expand Down
6 changes: 2 additions & 4 deletions src/Domain/Subscription/Service/Manager/SubscriberManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public function __construct(

public function createSubscriber(CreateSubscriberDto $subscriberDto): Subscriber
{
$subscriber = new Subscriber();
$subscriber->setEmail($subscriberDto->email);
$subscriber = new Subscriber($subscriberDto->email);
$confirmed = (bool)$subscriberDto->requestConfirmation;
$subscriber->setConfirmed(!$confirmed);
$subscriber->setBlacklisted(false);
Expand Down Expand Up @@ -106,8 +105,7 @@ public function deleteSubscriber(Subscriber $subscriber): void

public function createFromImport(ImportSubscriberDto $subscriberDto): Subscriber
{
$subscriber = new Subscriber();
$subscriber->setEmail($subscriberDto->email);
$subscriber = new Subscriber($subscriberDto->email);
$subscriber->setConfirmed($subscriberDto->confirmed);
$subscriber->setBlacklisted($subscriberDto->blacklisted);
$subscriber->setHtmlEmail($subscriberDto->htmlEmail);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ public function load(ObjectManager $manager): void
}
$row = array_combine($headers, $data);

$subscriber = new Subscriber();
$subscriber = new Subscriber($row['email']);
$this->setSubjectId($subscriber, (int)$row['id']);

$subscriber->setEmail($row['email']);
$subscriber->setConfirmed((bool) $row['confirmed']);
$subscriber->setBlacklisted((bool) $row['blacklisted']);
$subscriber->setBounceCount((int) $row['bouncecount']);
Expand Down
Loading
Loading