forked from nextcloud/server
-
Notifications
You must be signed in to change notification settings - Fork 3
IONOS(sharebymail): add BeforeShare*MailSentEvent dispatched before each mail send (HDNEXT-1010) #262
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
IONOS(sharebymail): add BeforeShare*MailSentEvent dispatched before each mail send (HDNEXT-1010) #262
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a6c9dfc
refactor(sharebymail): extract createEMailTemplate params into $templ…
printminion-co b434bbf
IONOS(sharebymail): add BeforeShare*MailSentEvent dispatched before e…
printminion-co 8ab47ed
IONOS(sharebymail): add Event classes to composer autoload_static cla…
tanyaka 48b9e07
IONOS(sharebymail): fix ShareByMailProviderTest broken by templateDat…
tanyaka ba01f57
IONOS(sharebymail): add test coverage for BeforeShareNoteMailSentEven…
tanyaka 0f82ec4
IONOS(sharebymail): fix createPasswordSendActivity firing when mail i…
tanyaka e97f706
IONOS(nc_ionos_processes): update submodule to 9501a5e (send email fo…
printminion-co File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Submodule nc_ionos_processes
updated
27 files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
apps/sharebymail/lib/Event/AbstractBeforeShareMailSentEvent.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\ShareByMail\Event; | ||
|
|
||
| use OCP\EventDispatcher\Event; | ||
| use OCP\Mail\IMessage; | ||
| use OCP\Share\IShare; | ||
|
|
||
| /** | ||
| * Base class for all BeforeShare*MailSentEvent types. | ||
| * | ||
| * Carries the fully-prepared IMessage (already rendered) and the resolved | ||
| * recipient list. Listeners call markMailHandled() to suppress the native | ||
| * mailer->send(). | ||
| */ | ||
| abstract class AbstractBeforeShareMailSentEvent extends Event { | ||
| private bool $mailHandled = false; | ||
|
|
||
| /** | ||
| * @param string[] $resolvedEmails validated recipients | ||
| */ | ||
| public function __construct( | ||
| private readonly IShare $share, | ||
| private readonly array $resolvedEmails, | ||
| private readonly IMessage $message, | ||
| ) { | ||
| parent::__construct(); | ||
| } | ||
|
|
||
| public function getShare(): IShare { | ||
| return $this->share; | ||
| } | ||
|
|
||
| /** @return string[] */ | ||
| public function getResolvedEmails(): array { | ||
| return $this->resolvedEmails; | ||
| } | ||
|
|
||
| public function getMessage(): IMessage { | ||
| return $this->message; | ||
| } | ||
|
|
||
| /** | ||
| * Call to suppress the native mailer->send() for this message. | ||
| * Must be called before any send attempt — if the listener's own send | ||
| * throws, the exception propagates and the native send is also skipped. | ||
| */ | ||
| public function markMailHandled(): void { | ||
| $this->mailHandled = true; | ||
| } | ||
|
|
||
| public function isMailHandled(): bool { | ||
| return $this->mailHandled; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\ShareByMail\Event; | ||
|
|
||
| use OCP\Mail\IMessage; | ||
| use OCP\Share\IShare; | ||
|
|
||
| /** | ||
| * Fired by ShareByMailProvider::sendEmail() immediately before the native | ||
| * mailer->send() call for share-link notifications to recipients. | ||
| * | ||
| * @psalm-type TemplateData = array{ | ||
| * senderUserId: string, | ||
| * filename: string, | ||
| * link: string, | ||
| * initiator: string, | ||
| * expiration: \DateTime|null, | ||
| * shareWith: string, | ||
| * note: string, | ||
| * } | ||
| * | ||
| * @psalm-api | ||
| */ | ||
| class BeforeShareMailSentEvent extends AbstractBeforeShareMailSentEvent { | ||
| /** | ||
| * @param string[] $resolvedEmails | ||
| * @param TemplateData $templateData | ||
| */ | ||
| public function __construct( | ||
| IShare $share, | ||
| array $resolvedEmails, | ||
| IMessage $message, | ||
| private readonly array $templateData, | ||
| ) { | ||
| parent::__construct($share, $resolvedEmails, $message); | ||
| } | ||
|
|
||
| public function getSenderUserId(): string { | ||
| return $this->templateData['senderUserId']; | ||
| } | ||
|
|
||
| public function getFileName(): string { | ||
| return $this->templateData['filename']; | ||
| } | ||
|
|
||
| public function getResourceUrl(): string { | ||
| return $this->templateData['link']; | ||
| } | ||
|
|
||
| public function getNote(): string { | ||
| return $this->templateData['note']; | ||
| } | ||
|
|
||
| public function getShareWith(): string { | ||
| return $this->templateData['shareWith']; | ||
| } | ||
|
|
||
| public function getInitiatorDisplayName(): string { | ||
| return $this->templateData['initiator']; | ||
| } | ||
|
|
||
| public function getExpiration(): ?\DateTime { | ||
| return $this->templateData['expiration']; | ||
| } | ||
| } |
47 changes: 47 additions & 0 deletions
47
apps/sharebymail/lib/Event/BeforeShareNoteMailSentEvent.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\ShareByMail\Event; | ||
|
|
||
| use OCP\Mail\IMessage; | ||
| use OCP\Share\IShare; | ||
|
|
||
| /** | ||
| * Fired by ShareByMailProvider::sendNote() immediately before the native | ||
| * mailer->send() call for note-update notifications to recipients. | ||
| * | ||
| * @psalm-type TemplateData = array{ | ||
| * filename: string, | ||
| * note: string, | ||
| * } | ||
| * | ||
| * @psalm-api | ||
| */ | ||
| class BeforeShareNoteMailSentEvent extends AbstractBeforeShareMailSentEvent { | ||
| /** | ||
| * @param string[] $resolvedEmails | ||
| * @param TemplateData $templateData | ||
| */ | ||
| public function __construct( | ||
| IShare $share, | ||
| array $resolvedEmails, | ||
| IMessage $message, | ||
| private readonly array $templateData, | ||
| ) { | ||
| parent::__construct($share, $resolvedEmails, $message); | ||
| } | ||
|
|
||
| public function getFileName(): string { | ||
| return $this->templateData['filename']; | ||
| } | ||
|
|
||
| public function getNote(): string { | ||
| return $this->templateData['note']; | ||
| } | ||
| } |
66 changes: 66 additions & 0 deletions
66
apps/sharebymail/lib/Event/BeforeSharePasswordMailSentEvent.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\ShareByMail\Event; | ||
|
|
||
| use OCP\Mail\IMessage; | ||
| use OCP\Share\IShare; | ||
|
|
||
| /** | ||
| * Fired by ShareByMailProvider::sendPassword() and sendPasswordToOwner() | ||
| * immediately before the native mailer->send() call for password emails. | ||
| * | ||
| * For sendPassword(), initiatorEmail may be null when the initiator has no | ||
| * email address configured. For sendPasswordToOwner() it is always a non-null | ||
| * string (the call site throws earlier if the owner has no email address). | ||
| * | ||
| * @psalm-type TemplateData = array{ | ||
| * filename: string, | ||
| * password: string, | ||
| * initiator: string, | ||
| * initiatorEmail: string|null, | ||
| * shareWith: string, | ||
| * } | ||
| * | ||
| * @psalm-api | ||
| */ | ||
| class BeforeSharePasswordMailSentEvent extends AbstractBeforeShareMailSentEvent { | ||
| /** | ||
| * @param string[] $resolvedEmails | ||
| * @param TemplateData $templateData | ||
| */ | ||
| public function __construct( | ||
| IShare $share, | ||
| array $resolvedEmails, | ||
| IMessage $message, | ||
| private readonly array $templateData, | ||
| ) { | ||
| parent::__construct($share, $resolvedEmails, $message); | ||
| } | ||
|
|
||
| public function getFileName(): string { | ||
| return $this->templateData['filename']; | ||
| } | ||
|
|
||
| public function getPassword(): string { | ||
| return $this->templateData['password']; | ||
| } | ||
|
|
||
| public function getInitiatorDisplayName(): string { | ||
| return $this->templateData['initiator']; | ||
| } | ||
|
|
||
| public function getInitiatorEmail(): ?string { | ||
| return $this->templateData['initiatorEmail']; | ||
| } | ||
|
|
||
| public function getShareWith(): string { | ||
| return $this->templateData['shareWith']; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.