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
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"@composer bin all update --ansi"
],
"lint": "find . -name \\*.php -not -path './vendor/*' -not -path './vendor-bin/*' -not -path './build/*' -print0 | xargs -0 -n1 php -l",
"cs:check": "php-cs-fixer fix --dry-run --diff",
"cs:fix": "php-cs-fixer fix",
"cs:check": "vendor-bin/cs-fixer/vendor/php-cs-fixer/shim/php-cs-fixer fix --dry-run --diff",
"cs:fix": "vendor-bin/cs-fixer/vendor/php-cs-fixer/shim/php-cs-fixer fix",
"psalm": "psalm --threads=1 --no-cache",
"test:unit": "phpunit tests -c tests/phpunit.xml --colors=always --fail-on-warning --fail-on-risky"
},
Expand Down
59 changes: 30 additions & 29 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 8 additions & 20 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
@@ -1,34 +1,19 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileLicenseText: 2024 Strato AG <t.lehmann@strato.de>
* SPDX-FileCopyrightText: 2026 STRATO GmbH
* SPDX-License-Identifier: AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

declare(strict_types=1);

namespace OCA\IonosProcesses\AppInfo;

use OCA\IonosProcesses\Listener\ShareCreatedEventListener;
use OCA\IonosProcesses\Listener\BeforeShareMailSentEventListener;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Share\Events\ShareCreatedEvent;

class Application extends App implements IBootstrap {
public const APP_ID = 'nc_ionos_processes';
Expand All @@ -41,7 +26,10 @@ public function __construct() {
public function register(IRegistrationContext $context): void {
include_once __DIR__ . '/../../vendor/autoload.php';

$context->registerEventListener(ShareCreatedEvent::class, ShareCreatedEventListener::class);
$context->registerEventListener(
\OCA\ShareByMail\Event\BeforeShareMailSentEvent::class,
BeforeShareMailSentEventListener::class,
);
}

public function boot(IBootContext $context): void {
Expand Down
75 changes: 75 additions & 0 deletions lib/Listener/BeforeShareMailSentEventListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 STRATO GmbH
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\IonosProcesses\Listener;

use OCA\IonosProcesses\Service\IonosMailerService;
use OCA\ShareByMail\Event\BeforeShareMailSentEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\IL10N;
use OCP\Share\IShare;
use Psr\Log\LoggerInterface;

/**
* Intercepts BeforeShareMailSentEvent fired by ShareByMailProvider::sendEmail()
* and routes share notifications through the internal IONOS mail delivery API.
*
* Calls markMailHandled() unconditionally in every TYPE_EMAIL code path so the
* native Nextcloud SMTP send is suppressed. IONOS send failures propagate as
* exceptions — no silent fallback to SMTP.
*
* Non-TYPE_EMAIL share types are not marked handled, so their native send still runs.
*
* @psalm-api
* @implements IEventListener<BeforeShareMailSentEvent>
*/
class BeforeShareMailSentEventListener implements IEventListener {
public const EVENT_NAME_SHARE_BY_LINK = 'share-by-link';

/** @psalm-api */
public function __construct(
private readonly LoggerInterface $logger,
private readonly IL10N $l10n,
private readonly IonosMailerService $mailer,
) {
}

public function handle(Event $event): void {
if (!($event instanceof BeforeShareMailSentEvent)) {
return;
}

$share = $event->getShare();

if ($share->getShareType() !== IShare::TYPE_EMAIL) {
return;
}

$resolvedEmails = $event->getResolvedEmails();
if (empty($resolvedEmails)) {
$event->markMailHandled();
$this->logger->warning("empty recipients for share with token '" . $share->getToken() . "', skipping");
return;
}

$data = [
'senderUserId' => $event->getSenderUserId(),
'fileName' => $event->getFileName(),
'resourceUrl' => $event->getResourceUrl(),
'note' => $event->getNote(),
'expirationDate' => $event->getExpiration()?->getTimestamp(),
'language' => $this->l10n->getLanguageCode(),
'receiverEmails' => $resolvedEmails,
];
Comment thread
tanyaka marked this conversation as resolved.

$event->markMailHandled();
$this->mailer->send(self::EVENT_NAME_SHARE_BY_LINK, $data);
}
}
89 changes: 0 additions & 89 deletions lib/Listener/ShareCreatedEventListener.php

This file was deleted.

Loading
Loading