-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Daniel Kesselberg <[email protected]>
- Loading branch information
Showing
19 changed files
with
755 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,102 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright Copyright (c) 2023 Daniel Kesselberg <[email protected]> | ||
* | ||
* @author Daniel Kesselberg <[email protected]> | ||
* | ||
* @license AGPL-3.0-or-later | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* 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, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace OCA\Mail\Listener; | ||
|
||
use OCA\Mail\Contracts\IMailManager; | ||
use OCA\Mail\Events\MessageFlaggedEvent; | ||
use OCA\Mail\Exception\ClientException; | ||
use OCA\Mail\Exception\ServiceException; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\EventDispatcher\IEventListener; | ||
use Psr\Log\LoggerInterface; | ||
|
||
/** | ||
* @template-implements IEventListener<Event|MessageFlaggedEvent> | ||
*/ | ||
class MoveJunkListener implements IEventListener { | ||
public function __construct( | ||
private IMailManager $mailManager, | ||
private LoggerInterface $logger, | ||
) { | ||
} | ||
|
||
public function handle(Event $event): void { | ||
if (!$event instanceof MessageFlaggedEvent || $event->getFlag() !== '$junk') { | ||
return; | ||
} | ||
|
||
$account = $event->getAccount(); | ||
$mailAccount = $account->getMailAccount(); | ||
|
||
if (!$mailAccount->isMoveJunk()) { | ||
return; | ||
} | ||
|
||
$mailbox = $event->getMailbox(); | ||
|
||
if ($event->isSet() && $mailAccount->getJunkMailboxId() !== $mailbox->getId()) { | ||
try { | ||
$junkMailbox = $this->mailManager->getMailbox($account->getUserId(), $mailAccount->getJunkMailboxId()); | ||
} catch (ClientException) { | ||
$this->logger->debug('move to junk enabled, but junk mailbox does not exist. account_id: {account_id}, junk_mailbox_id: {junk_mailbox_id}', [ | ||
'account_id' => $account->getId(), | ||
'junk_mailbox_id' => $mailAccount->getJunkMailboxId(), | ||
]); | ||
return; | ||
} | ||
|
||
try { | ||
$this->mailManager->moveMessage( | ||
$account, | ||
$mailbox->getName(), | ||
$event->getUid(), | ||
$account, | ||
$junkMailbox->getName(), | ||
); | ||
} catch (ServiceException $e) { | ||
$this->logger->error('move message to junk mailbox failed. account_id: {account_id}', [ | ||
'exception' => $e, | ||
'account_id' => $account->getId(), | ||
]); | ||
} | ||
} elseif (!$event->isSet() && 'INBOX' !== $mailbox->getName()) { | ||
try { | ||
$this->mailManager->moveMessage( | ||
$account, | ||
$mailbox->getName(), | ||
$event->getUid(), | ||
$account, | ||
'INBOX', | ||
); | ||
} catch (ServiceException $e) { | ||
$this->logger->error('move message to inbox failed. account_id: {account_id}', [ | ||
'exception' => $e, | ||
'account_id' => $account->getId(), | ||
]); | ||
} | ||
} | ||
} | ||
} |
This file contains 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,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright Copyright (c) 2023 Daniel Kesselberg <[email protected]> | ||
* | ||
* @author Daniel Kesselberg <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* 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/>. | ||
* | ||
*/ | ||
|
||
namespace OCA\Mail\Migration; | ||
|
||
use Closure; | ||
use OCP\DB\ISchemaWrapper; | ||
use OCP\Migration\IOutput; | ||
use OCP\Migration\SimpleMigrationStep; | ||
|
||
class Version3001Date20230307113544 extends SimpleMigrationStep { | ||
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { | ||
/** @var ISchemaWrapper $schema */ | ||
$schema = $schemaClosure(); | ||
|
||
$accountsTable = $schema->getTable('mail_accounts'); | ||
$accountsTable->addColumn('junk_mailbox_id', 'integer', [ | ||
'notnull' => false, | ||
'default' => null, | ||
'length' => 20, | ||
]); | ||
$accountsTable->addColumn('move_junk', 'boolean', [ | ||
'notnull' => false, | ||
'default' => false, | ||
]); | ||
|
||
return $schema; | ||
} | ||
} |
This file contains 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 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 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
Oops, something went wrong.