-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: per account imap and smtp debugging
Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com>
- Loading branch information
1 parent
43cfb5a
commit 421a8dc
Showing
10 changed files
with
153 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Mail\Command; | ||
|
||
use OCA\Mail\Service\AccountService; | ||
use OCP\AppFramework\Db\DoesNotExistException; | ||
use Psr\Log\LoggerInterface; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class DebugAccount extends Command { | ||
protected const ARGUMENT_ACCOUNT_ID = 'account-id'; | ||
protected const OPTION_IMAP_DEFAULT = 'imap'; | ||
protected const OPTION_IMAP_FULL = 'imap-full'; | ||
protected const OPTION_SMTP_DEFAULT = 'smtp'; | ||
|
||
public function __construct( | ||
private AccountService $accountService, | ||
private LoggerInterface $logger, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
protected function configure() { | ||
$this->setName('mail:account:debug'); | ||
$this->setDescription('Enable or Disable IMAP/SMTP debugging on a account'); | ||
$this->addArgument(self::ARGUMENT_ACCOUNT_ID, InputArgument::REQUIRED); | ||
$this->addOption(self::OPTION_IMAP_DEFAULT, null, InputOption::VALUE_NONE); | ||
$this->addOption(self::OPTION_IMAP_FULL, null, InputOption::VALUE_NONE); | ||
$this->addOption(self::OPTION_SMTP_DEFAULT, null, InputOption::VALUE_NONE); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int { | ||
$accountId = (int)$input->getArgument(self::ARGUMENT_ACCOUNT_ID); | ||
$imapDefault = $input->getOption(self::OPTION_IMAP_DEFAULT); | ||
$imapFull = $input->getOption(self::OPTION_IMAP_FULL); | ||
$smtpDefault = $input->getOption(self::OPTION_SMTP_DEFAULT); | ||
$debug = 0; | ||
$debugImapDefault = 1 << 0; // 1 (0000 0001) | ||
$debugImapFull = 1 << 1; // 2 (0000 0010) | ||
$debugSmtpDefault = 1 << 4; // 16 (0001 0000) | ||
|
||
try { | ||
$account = $this->accountService->findById($accountId)->getMailAccount(); | ||
} catch (DoesNotExistException $e) { | ||
$output->writeln("<error>Account $accountId does not exist</error>"); | ||
return 1; | ||
} | ||
|
||
if ($imapDefault) { | ||
$debug += $debugImapDefault; | ||
} elseif ($imapFull) { | ||
$debug += $debugImapFull; | ||
} | ||
|
||
if ($smtpDefault) { | ||
$debug += $debugSmtpDefault; | ||
} | ||
|
||
$account->setDebug($debug); | ||
$this->accountService->save($account); | ||
|
||
return 0; | ||
} | ||
} |
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,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Mail\Migration; | ||
|
||
use Closure; | ||
use OCP\DB\ISchemaWrapper; | ||
use OCP\DB\Types; | ||
use OCP\Migration\IOutput; | ||
use OCP\Migration\SimpleMigrationStep; | ||
|
||
class Version4100Date20241028000000 extends SimpleMigrationStep { | ||
|
||
/** | ||
* @param IOutput $output | ||
* @param Closure(): ISchemaWrapper $schemaClosure | ||
* @param array $options | ||
* @return null|ISchemaWrapper | ||
*/ | ||
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { | ||
$schema = $schemaClosure(); | ||
|
||
$accountsTable = $schema->getTable('mail_accounts'); | ||
if (!$accountsTable->hasColumn('debug')) { | ||
$accountsTable->addColumn('debug', Types::SMALLINT, [ | ||
'notnull' => false, | ||
'default' => 0, | ||
]); | ||
} | ||
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