From 421a8dcead0cc21d7163d45de9e4cf2a11cb3a84 Mon Sep 17 00:00:00 2001 From: SebastianKrupinski Date: Mon, 28 Oct 2024 19:21:04 -0400 Subject: [PATCH 01/10] feat: per account imap and smtp debugging Signed-off-by: SebastianKrupinski --- .github/workflows/test.yml | 2 +- appinfo/info.xml | 1 + lib/Account.php | 7 ++ lib/Command/DebugAccount.php | 78 +++++++++++++++++++ lib/Db/MailAccount.php | 9 +++ lib/IMAP/IMAPClientFactory.php | 12 ++- .../Version4100Date20241028000000.php | 38 +++++++++ lib/SMTP/SmtpClientFactory.php | 7 +- tests/Integration/Db/MailAccountTest.php | 4 +- .../Integration/Framework/ImapTestAccount.php | 1 + 10 files changed, 153 insertions(+), 6 deletions(-) create mode 100644 lib/Command/DebugAccount.php create mode 100644 lib/Migration/Version4100Date20241028000000.php diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a013a3df57..fba1881ded 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -184,7 +184,7 @@ jobs: run: echo "SELECT * FROM mysql.slow_log WHERE sql_text LIKE '%oc_mail%' AND sql_text NOT LIKE '%information_schema%'" | mysql -h 127.0.0.1 -u root -pmy-secret-pw - name: Print debug logs if: ${{ always() }} - run: cat nextcloud/data/horde_*.log + run: cat nextcloud/data/mail-*-*-imap.log - name: Report coverage uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4.6.0 if: ${{ always() && matrix.db == 'mysql' }} diff --git a/appinfo/info.xml b/appinfo/info.xml index 7d2bcbbbd9..24ce87ff96 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -80,6 +80,7 @@ Learn more about the Nextcloud Ethical AI Rating [in our blog](https://nextcloud OCA\Mail\Command\CleanUp OCA\Mail\Command\CreateAccount OCA\Mail\Command\CreateTagMigrationJobEntry + OCA\Mail\Command\DebugAccount OCA\Mail\Command\DeleteAccount OCA\Mail\Command\DiagnoseAccount OCA\Mail\Command\ExportAccount diff --git a/lib/Account.php b/lib/Account.php index f234e4886f..e294e75af2 100644 --- a/lib/Account.php +++ b/lib/Account.php @@ -61,6 +61,13 @@ public function getUserId() { return $this->account->getUserId(); } + /** + * @return int + */ + public function getDebug(): int { + return $this->account->getDebug(); + } + /** * Set the quota percentage * @param Quota $quota diff --git a/lib/Command/DebugAccount.php b/lib/Command/DebugAccount.php new file mode 100644 index 0000000000..25d53bcdf7 --- /dev/null +++ b/lib/Command/DebugAccount.php @@ -0,0 +1,78 @@ +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("Account $accountId does not exist"); + return 1; + } + + if ($imapDefault) { + $debug += $debugImapDefault; + } elseif ($imapFull) { + $debug += $debugImapFull; + } + + if ($smtpDefault) { + $debug += $debugSmtpDefault; + } + + $account->setDebug($debug); + $this->accountService->save($account); + + return 0; + } +} diff --git a/lib/Db/MailAccount.php b/lib/Db/MailAccount.php index 17099f0123..b99b8000b8 100644 --- a/lib/Db/MailAccount.php +++ b/lib/Db/MailAccount.php @@ -101,6 +101,8 @@ * @method void setSearchBody(bool $searchBody) * @method bool|null getOooFollowsSystem() * @method void setOooFollowsSystem(bool $oooFollowsSystem) + * @method int getDebug() + * @method void setDebug(int $debug) */ class MailAccount extends Entity { public const SIGNATURE_MODE_PLAIN = 0; @@ -183,6 +185,8 @@ class MailAccount extends Entity { /** @var bool|null */ protected $oooFollowsSystem; + protected int $debug = 0; + /** * @param array $params */ @@ -240,6 +244,9 @@ public function __construct(array $params = []) { if (isset($params['outOfOfficeFollowsSystem'])) { $this->setOutOfOfficeFollowsSystem($params['outOfOfficeFollowsSystem']); } + if (isset($params['debug'])) { + $this->setDebug($params['debug']); + } $this->addType('inboundPort', 'integer'); $this->addType('outboundPort', 'integer'); @@ -263,6 +270,7 @@ public function __construct(array $params = []) { $this->addType('junkMailboxId', 'integer'); $this->addType('searchBody', 'boolean'); $this->addType('oooFollowsSystem', 'boolean'); + $this->addType('debug', 'integer'); } public function getOutOfOfficeFollowsSystem(): bool { @@ -310,6 +318,7 @@ public function toJson() { 'junkMailboxId' => $this->getJunkMailboxId(), 'searchBody' => $this->getSearchBody(), 'outOfOfficeFollowsSystem' => $this->getOutOfOfficeFollowsSystem(), + 'debug' => $this->getDebug(), ]; if (!is_null($this->getOutboundHost())) { diff --git a/lib/IMAP/IMAPClientFactory.php b/lib/IMAP/IMAPClientFactory.php index 3f6d5d2c45..a3ccefd059 100644 --- a/lib/IMAP/IMAPClientFactory.php +++ b/lib/IMAP/IMAPClientFactory.php @@ -40,6 +40,9 @@ class IMAPClientFactory { private ITimeFactory $timeFactory; private HordeCacheFactory $hordeCacheFactory; + private int $debugDefault = 1 << 0; // 1 (0000 0001) + private int $debugFull = 1 << 1; // 2 (0000 0010) + public function __construct(ICrypto $crypto, IConfig $config, ICacheFactory $cacheFactory, @@ -117,8 +120,13 @@ public function getClient(Account $account, bool $useCache = true): Horde_Imap_C 'backend' => $this->hordeCacheFactory->newCache($account), ]; } - if ($this->config->getSystemValue('debug', false)) { - $params['debug'] = $this->config->getSystemValue('datadirectory') . '/horde_imap.log'; + $debug = $account->getDebug(); + if ($debug & $this->debugDefault || $debug & $this->debugFull) { + $fn = 'mail-' . $account->getUserId() . '-' . $account->getId() . '-imap.log'; + $params['debug'] = $this->config->getSystemValue('datadirectory') . '/' . $fn; + if ($debug & $this->debugFull) { + $params['debug_literal'] = true; + } } $client = new HordeImapClient($params); diff --git a/lib/Migration/Version4100Date20241028000000.php b/lib/Migration/Version4100Date20241028000000.php new file mode 100644 index 0000000000..69eae2dab9 --- /dev/null +++ b/lib/Migration/Version4100Date20241028000000.php @@ -0,0 +1,38 @@ +getTable('mail_accounts'); + if (!$accountsTable->hasColumn('debug')) { + $accountsTable->addColumn('debug', Types::SMALLINT, [ + 'notnull' => false, + 'default' => 0, + ]); + } + return $schema; + } +} diff --git a/lib/SMTP/SmtpClientFactory.php b/lib/SMTP/SmtpClientFactory.php index 3d63195fba..14c9da3b05 100644 --- a/lib/SMTP/SmtpClientFactory.php +++ b/lib/SMTP/SmtpClientFactory.php @@ -28,6 +28,8 @@ class SmtpClientFactory { /** @var HostNameFactory */ private $hostNameFactory; + private int $debugDefault = 1 << 4; // 16 (0001 0000) + public function __construct(IConfig $config, ICrypto $crypto, HostNameFactory $hostNameFactory) { @@ -77,8 +79,9 @@ public function create(Account $account): Horde_Mail_Transport { $decryptedAccessToken, ); } - if ($this->config->getSystemValue('debug', false)) { - $params['debug'] = $this->config->getSystemValue('datadirectory') . '/horde_smtp.log'; + if ($account->getDebug() & $this->debugDefault) { + $fn = 'mail-' . $account->getUserId() . '-' . $account->getId() . '-smtp.log'; + $params['debug'] = $this->config->getSystemValue('datadirectory') . '/' . $fn; } return new Horde_Mail_Transport_Smtphorde($params); } diff --git a/tests/Integration/Db/MailAccountTest.php b/tests/Integration/Db/MailAccountTest.php index d960e46b3a..632d275ed5 100644 --- a/tests/Integration/Db/MailAccountTest.php +++ b/tests/Integration/Db/MailAccountTest.php @@ -54,7 +54,7 @@ public function testToAPI() { 'editorMode' => 'html', 'provisioningId' => null, 'order' => 13, - 'showSubscribedOnly' => null, + 'showSubscribedOnly' => false, 'personalNamespace' => null, 'draftsMailboxId' => null, 'sentMailboxId' => null, @@ -70,6 +70,7 @@ public function testToAPI() { 'snoozeMailboxId' => null, 'searchBody' => false, 'outOfOfficeFollowsSystem' => true, + 'debug' => 0, ], $a->toJson()); } @@ -107,6 +108,7 @@ public function testMailAccountConstruct() { 'snoozeMailboxId' => null, 'searchBody' => false, 'outOfOfficeFollowsSystem' => false, + 'debug' => 0, ]; $a = new MailAccount($expected); // TODO: fix inconsistency diff --git a/tests/Integration/Framework/ImapTestAccount.php b/tests/Integration/Framework/ImapTestAccount.php index c55941ae6a..2017bb465e 100644 --- a/tests/Integration/Framework/ImapTestAccount.php +++ b/tests/Integration/Framework/ImapTestAccount.php @@ -47,6 +47,7 @@ public function createTestAccount(?string $userId = null) { $mailAccount->setOutboundUser('user@domain.tld'); $mailAccount->setOutboundPassword(OC::$server->getCrypto()->encrypt('mypassword')); $mailAccount->setOutboundSslMode('none'); + $mailAccount->setDebug(1); $acc = $accountService->save($mailAccount); /** @var MailboxSync $mbSync */ From f832baa5ec0461bfce2155505408a5e5f9a5a0bd Mon Sep 17 00:00:00 2001 From: SebastianKrupinski Date: Tue, 5 Nov 2024 11:23:05 -0500 Subject: [PATCH 02/10] fixup! feat: per account imap and smtp debugging Signed-off-by: SebastianKrupinski --- lib/Command/DebugAccount.php | 6 +++--- lib/IMAP/IMAPClientFactory.php | 4 ++-- lib/SMTP/SmtpClientFactory.php | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Command/DebugAccount.php b/lib/Command/DebugAccount.php index 25d53bcdf7..1e1bbfc7f7 100644 --- a/lib/Command/DebugAccount.php +++ b/lib/Command/DebugAccount.php @@ -49,9 +49,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int $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) + $debugImapDefault = 1; + $debugImapFull = 2; + $debugSmtpDefault = 16; try { $account = $this->accountService->findById($accountId)->getMailAccount(); diff --git a/lib/IMAP/IMAPClientFactory.php b/lib/IMAP/IMAPClientFactory.php index a3ccefd059..ad06a73d41 100644 --- a/lib/IMAP/IMAPClientFactory.php +++ b/lib/IMAP/IMAPClientFactory.php @@ -40,8 +40,8 @@ class IMAPClientFactory { private ITimeFactory $timeFactory; private HordeCacheFactory $hordeCacheFactory; - private int $debugDefault = 1 << 0; // 1 (0000 0001) - private int $debugFull = 1 << 1; // 2 (0000 0010) + private int $debugDefault = 1; + private int $debugFull = 2; public function __construct(ICrypto $crypto, IConfig $config, diff --git a/lib/SMTP/SmtpClientFactory.php b/lib/SMTP/SmtpClientFactory.php index 14c9da3b05..6bc043abcd 100644 --- a/lib/SMTP/SmtpClientFactory.php +++ b/lib/SMTP/SmtpClientFactory.php @@ -28,7 +28,7 @@ class SmtpClientFactory { /** @var HostNameFactory */ private $hostNameFactory; - private int $debugDefault = 1 << 4; // 16 (0001 0000) + private int $debugDefault = 16; public function __construct(IConfig $config, ICrypto $crypto, From 3f64efdee6b2774de6e3448936b27c59355a30de Mon Sep 17 00:00:00 2001 From: SebastianKrupinski Date: Tue, 5 Nov 2024 16:27:16 -0500 Subject: [PATCH 03/10] fixup! feat: per account imap and smtp debugging Signed-off-by: SebastianKrupinski --- lib/Account.php | 9 ++++++--- lib/Command/DebugAccount.php | 13 +++++-------- lib/Db/MailAccount.php | 8 ++++---- lib/IMAP/IMAPClientFactory.php | 7 ++----- lib/Migration/Version4100Date20241028000000.php | 7 ++++--- lib/SMTP/SmtpClientFactory.php | 5 ++--- 6 files changed, 23 insertions(+), 26 deletions(-) diff --git a/lib/Account.php b/lib/Account.php index e294e75af2..5e9335b671 100644 --- a/lib/Account.php +++ b/lib/Account.php @@ -62,10 +62,13 @@ public function getUserId() { } /** - * @return int + * @return array */ - public function getDebug(): int { - return $this->account->getDebug(); + public function getDebug(): array { + if (!empty($this->account->getDebug())) { + return explode('|', $this->account->getDebug()); + } + return []; } /** diff --git a/lib/Command/DebugAccount.php b/lib/Command/DebugAccount.php index 1e1bbfc7f7..9640c5c83c 100644 --- a/lib/Command/DebugAccount.php +++ b/lib/Command/DebugAccount.php @@ -48,10 +48,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $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; - $debugImapFull = 2; - $debugSmtpDefault = 16; + $debug = []; try { $account = $this->accountService->findById($accountId)->getMailAccount(); @@ -61,16 +58,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int } if ($imapDefault) { - $debug += $debugImapDefault; + $debug[] = 'imap'; } elseif ($imapFull) { - $debug += $debugImapFull; + $debug[] = 'imap-full'; } if ($smtpDefault) { - $debug += $debugSmtpDefault; + $debug[] = 'smtp'; } - $account->setDebug($debug); + $account->setDebug(implode('|', $debug)); $this->accountService->save($account); return 0; diff --git a/lib/Db/MailAccount.php b/lib/Db/MailAccount.php index b99b8000b8..4c9b622ca0 100644 --- a/lib/Db/MailAccount.php +++ b/lib/Db/MailAccount.php @@ -101,8 +101,8 @@ * @method void setSearchBody(bool $searchBody) * @method bool|null getOooFollowsSystem() * @method void setOooFollowsSystem(bool $oooFollowsSystem) - * @method int getDebug() - * @method void setDebug(int $debug) + * @method string getDebug() + * @method void setDebug(string $debug) */ class MailAccount extends Entity { public const SIGNATURE_MODE_PLAIN = 0; @@ -185,7 +185,7 @@ class MailAccount extends Entity { /** @var bool|null */ protected $oooFollowsSystem; - protected int $debug = 0; + protected string $debug = ''; /** * @param array $params @@ -270,7 +270,7 @@ public function __construct(array $params = []) { $this->addType('junkMailboxId', 'integer'); $this->addType('searchBody', 'boolean'); $this->addType('oooFollowsSystem', 'boolean'); - $this->addType('debug', 'integer'); + $this->addType('debug', 'string'); } public function getOutOfOfficeFollowsSystem(): bool { diff --git a/lib/IMAP/IMAPClientFactory.php b/lib/IMAP/IMAPClientFactory.php index ad06a73d41..71746f1f1d 100644 --- a/lib/IMAP/IMAPClientFactory.php +++ b/lib/IMAP/IMAPClientFactory.php @@ -40,9 +40,6 @@ class IMAPClientFactory { private ITimeFactory $timeFactory; private HordeCacheFactory $hordeCacheFactory; - private int $debugDefault = 1; - private int $debugFull = 2; - public function __construct(ICrypto $crypto, IConfig $config, ICacheFactory $cacheFactory, @@ -121,10 +118,10 @@ public function getClient(Account $account, bool $useCache = true): Horde_Imap_C ]; } $debug = $account->getDebug(); - if ($debug & $this->debugDefault || $debug & $this->debugFull) { + if (in_array('imap', $debug) || in_array('imap-full', $debug)) { $fn = 'mail-' . $account->getUserId() . '-' . $account->getId() . '-imap.log'; $params['debug'] = $this->config->getSystemValue('datadirectory') . '/' . $fn; - if ($debug & $this->debugFull) { + if (in_array('imap-full', $debug)) { $params['debug_literal'] = true; } } diff --git a/lib/Migration/Version4100Date20241028000000.php b/lib/Migration/Version4100Date20241028000000.php index 69eae2dab9..de01235fbb 100644 --- a/lib/Migration/Version4100Date20241028000000.php +++ b/lib/Migration/Version4100Date20241028000000.php @@ -28,9 +28,10 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt $accountsTable = $schema->getTable('mail_accounts'); if (!$accountsTable->hasColumn('debug')) { - $accountsTable->addColumn('debug', Types::SMALLINT, [ - 'notnull' => false, - 'default' => 0, + $accountsTable->addColumn('debug', Types::STRING, [ + 'length' => 32, + 'notnull' => true, + 'default' => '', ]); } return $schema; diff --git a/lib/SMTP/SmtpClientFactory.php b/lib/SMTP/SmtpClientFactory.php index 6bc043abcd..ea14c83e75 100644 --- a/lib/SMTP/SmtpClientFactory.php +++ b/lib/SMTP/SmtpClientFactory.php @@ -28,8 +28,6 @@ class SmtpClientFactory { /** @var HostNameFactory */ private $hostNameFactory; - private int $debugDefault = 16; - public function __construct(IConfig $config, ICrypto $crypto, HostNameFactory $hostNameFactory) { @@ -79,7 +77,8 @@ public function create(Account $account): Horde_Mail_Transport { $decryptedAccessToken, ); } - if ($account->getDebug() & $this->debugDefault) { + $debug = $account->getDebug(); + if (in_array('smtp', $debug)) { $fn = 'mail-' . $account->getUserId() . '-' . $account->getId() . '-smtp.log'; $params['debug'] = $this->config->getSystemValue('datadirectory') . '/' . $fn; } From 29e8e0bd35edbe40c3b15909cdf9ed85e30db329 Mon Sep 17 00:00:00 2001 From: SebastianKrupinski Date: Tue, 5 Nov 2024 16:30:40 -0500 Subject: [PATCH 04/10] fixup! feat: per account imap and smtp debugging Signed-off-by: SebastianKrupinski --- appinfo/info.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appinfo/info.xml b/appinfo/info.xml index 24ce87ff96..e1d9123af2 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -34,7 +34,7 @@ The rating depends on the installed text processing backend. See [the rating ove Learn more about the Nextcloud Ethical AI Rating [in our blog](https://nextcloud.com/blog/nextcloud-ethical-ai-rating/). ]]> - 4.1.0-alpha.2 + 4.2.0-alpha.1 agpl Christoph Wurst GretaD From 97a09c08a41202cfe4d530d1bf1aa7aee6b5f762 Mon Sep 17 00:00:00 2001 From: SebastianKrupinski Date: Tue, 5 Nov 2024 17:43:45 -0500 Subject: [PATCH 05/10] fixup! feat: per account imap and smtp debugging Signed-off-by: SebastianKrupinski --- tests/Integration/Db/MailAccountTest.php | 4 ++-- tests/Integration/Framework/ImapTestAccount.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Integration/Db/MailAccountTest.php b/tests/Integration/Db/MailAccountTest.php index 632d275ed5..5ded8209e6 100644 --- a/tests/Integration/Db/MailAccountTest.php +++ b/tests/Integration/Db/MailAccountTest.php @@ -70,7 +70,7 @@ public function testToAPI() { 'snoozeMailboxId' => null, 'searchBody' => false, 'outOfOfficeFollowsSystem' => true, - 'debug' => 0, + 'debug' => '', ], $a->toJson()); } @@ -108,7 +108,7 @@ public function testMailAccountConstruct() { 'snoozeMailboxId' => null, 'searchBody' => false, 'outOfOfficeFollowsSystem' => false, - 'debug' => 0, + 'debug' => '', ]; $a = new MailAccount($expected); // TODO: fix inconsistency diff --git a/tests/Integration/Framework/ImapTestAccount.php b/tests/Integration/Framework/ImapTestAccount.php index 2017bb465e..12104f1b84 100644 --- a/tests/Integration/Framework/ImapTestAccount.php +++ b/tests/Integration/Framework/ImapTestAccount.php @@ -47,7 +47,7 @@ public function createTestAccount(?string $userId = null) { $mailAccount->setOutboundUser('user@domain.tld'); $mailAccount->setOutboundPassword(OC::$server->getCrypto()->encrypt('mypassword')); $mailAccount->setOutboundSslMode('none'); - $mailAccount->setDebug(1); + $mailAccount->setDebug('imap'); $acc = $accountService->save($mailAccount); /** @var MailboxSync $mbSync */ From 7aa605d4fcb01fdb73ad32694898b68b5bba4be7 Mon Sep 17 00:00:00 2001 From: SebastianKrupinski Date: Wed, 6 Nov 2024 19:43:15 -0500 Subject: [PATCH 06/10] fixup! feat: per account imap and smtp debugging Signed-off-by: SebastianKrupinski --- lib/Account.php | 5 ++++- lib/Migration/Version4100Date20241028000000.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Account.php b/lib/Account.php index 5e9335b671..7df013c920 100644 --- a/lib/Account.php +++ b/lib/Account.php @@ -65,7 +65,10 @@ public function getUserId() { * @return array */ public function getDebug(): array { - if (!empty($this->account->getDebug())) { + if (isset($_SERVER['NC_MAIL_DEBUG'])) { + return explode('|', $_SERVER['NC_MAIL_DEBUG']); + } + elseif (!empty($this->account->getDebug())) { return explode('|', $this->account->getDebug()); } return []; diff --git a/lib/Migration/Version4100Date20241028000000.php b/lib/Migration/Version4100Date20241028000000.php index de01235fbb..348a0676a2 100644 --- a/lib/Migration/Version4100Date20241028000000.php +++ b/lib/Migration/Version4100Date20241028000000.php @@ -30,7 +30,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt if (!$accountsTable->hasColumn('debug')) { $accountsTable->addColumn('debug', Types::STRING, [ 'length' => 32, - 'notnull' => true, + 'notnull' => false, 'default' => '', ]); } From 7cc73f6abee5f98713e33456b2f8dd60fc8fa450 Mon Sep 17 00:00:00 2001 From: SebastianKrupinski Date: Wed, 6 Nov 2024 19:55:24 -0500 Subject: [PATCH 07/10] fixup! fixup! feat: per account imap and smtp debugging Signed-off-by: SebastianKrupinski --- lib/Account.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Account.php b/lib/Account.php index 7df013c920..05cc3ce4b8 100644 --- a/lib/Account.php +++ b/lib/Account.php @@ -67,8 +67,7 @@ public function getUserId() { public function getDebug(): array { if (isset($_SERVER['NC_MAIL_DEBUG'])) { return explode('|', $_SERVER['NC_MAIL_DEBUG']); - } - elseif (!empty($this->account->getDebug())) { + } elseif (!empty($this->account->getDebug())) { return explode('|', $this->account->getDebug()); } return []; From 21c5495177543cbfadce9350d803a5bf2e7506f5 Mon Sep 17 00:00:00 2001 From: SebastianKrupinski Date: Wed, 6 Nov 2024 19:58:41 -0500 Subject: [PATCH 08/10] fixup! fixup! feat: per account imap and smtp debugging Signed-off-by: SebastianKrupinski --- appinfo/info.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appinfo/info.xml b/appinfo/info.xml index 9232874251..e1d9123af2 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -33,7 +33,7 @@ Positive: The rating depends on the installed text processing backend. See [the rating overview](https://docs.nextcloud.com/server/latest/admin_manual/ai/index.html) for details. Learn more about the Nextcloud Ethical AI Rating [in our blog](https://nextcloud.com/blog/nextcloud-ethical-ai-rating/). - ]]> 4.2.0-alpha.1 agpl Christoph Wurst From 378fa95dccf94744cf84095b98c0a7e4ea9e00a3 Mon Sep 17 00:00:00 2001 From: SebastianKrupinski Date: Thu, 7 Nov 2024 13:19:09 -0500 Subject: [PATCH 09/10] fixup! fixup! feat: per account imap and smtp debugging Signed-off-by: SebastianKrupinski --- lib/Account.php | 11 +++-------- lib/IMAP/IMAPClientFactory.php | 5 ++++- lib/SMTP/SmtpClientFactory.php | 5 ++++- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/Account.php b/lib/Account.php index 05cc3ce4b8..4ea4028769 100644 --- a/lib/Account.php +++ b/lib/Account.php @@ -62,15 +62,10 @@ public function getUserId() { } /** - * @return array + * @return string */ - public function getDebug(): array { - if (isset($_SERVER['NC_MAIL_DEBUG'])) { - return explode('|', $_SERVER['NC_MAIL_DEBUG']); - } elseif (!empty($this->account->getDebug())) { - return explode('|', $this->account->getDebug()); - } - return []; + public function getDebug(): string { + return $this->account->getDebug(); } /** diff --git a/lib/IMAP/IMAPClientFactory.php b/lib/IMAP/IMAPClientFactory.php index 71746f1f1d..9ed22f5cb2 100644 --- a/lib/IMAP/IMAPClientFactory.php +++ b/lib/IMAP/IMAPClientFactory.php @@ -117,7 +117,10 @@ public function getClient(Account $account, bool $useCache = true): Horde_Imap_C 'backend' => $this->hordeCacheFactory->newCache($account), ]; } - $debug = $account->getDebug(); + $debug = array_merge( + explode('|', $this->config->getSystemValue('MAIL_DEBUG')), + explode('|', $account->getDebug()) + ); if (in_array('imap', $debug) || in_array('imap-full', $debug)) { $fn = 'mail-' . $account->getUserId() . '-' . $account->getId() . '-imap.log'; $params['debug'] = $this->config->getSystemValue('datadirectory') . '/' . $fn; diff --git a/lib/SMTP/SmtpClientFactory.php b/lib/SMTP/SmtpClientFactory.php index ea14c83e75..d0ddb33693 100644 --- a/lib/SMTP/SmtpClientFactory.php +++ b/lib/SMTP/SmtpClientFactory.php @@ -77,7 +77,10 @@ public function create(Account $account): Horde_Mail_Transport { $decryptedAccessToken, ); } - $debug = $account->getDebug(); + $debug = array_merge( + explode('|', $this->config->getSystemValue('MAIL_DEBUG', '')), + explode('|', $account->getDebug()) + ); if (in_array('smtp', $debug)) { $fn = 'mail-' . $account->getUserId() . '-' . $account->getId() . '-smtp.log'; $params['debug'] = $this->config->getSystemValue('datadirectory') . '/' . $fn; From 2c0f6fe044f21c68570e0c4e2cac7845dc45be2f Mon Sep 17 00:00:00 2001 From: SebastianKrupinski Date: Thu, 7 Nov 2024 14:04:27 -0500 Subject: [PATCH 10/10] fixup! fixup! feat: per account imap and smtp debugging Signed-off-by: SebastianKrupinski --- lib/IMAP/IMAPClientFactory.php | 2 +- lib/SMTP/SmtpClientFactory.php | 2 +- tests/Unit/SMTP/SmtpClientFactoryTest.php | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/IMAP/IMAPClientFactory.php b/lib/IMAP/IMAPClientFactory.php index 9ed22f5cb2..14e8b9dba9 100644 --- a/lib/IMAP/IMAPClientFactory.php +++ b/lib/IMAP/IMAPClientFactory.php @@ -118,7 +118,7 @@ public function getClient(Account $account, bool $useCache = true): Horde_Imap_C ]; } $debug = array_merge( - explode('|', $this->config->getSystemValue('MAIL_DEBUG')), + explode('|', $this->config->getSystemValueString('MAIL_DEBUG')), explode('|', $account->getDebug()) ); if (in_array('imap', $debug) || in_array('imap-full', $debug)) { diff --git a/lib/SMTP/SmtpClientFactory.php b/lib/SMTP/SmtpClientFactory.php index d0ddb33693..68fc222415 100644 --- a/lib/SMTP/SmtpClientFactory.php +++ b/lib/SMTP/SmtpClientFactory.php @@ -78,7 +78,7 @@ public function create(Account $account): Horde_Mail_Transport { ); } $debug = array_merge( - explode('|', $this->config->getSystemValue('MAIL_DEBUG', '')), + explode('|', $this->config->getSystemValueString('MAIL_DEBUG')), explode('|', $account->getDebug()) ); if (in_array('smtp', $debug)) { diff --git a/tests/Unit/SMTP/SmtpClientFactoryTest.php b/tests/Unit/SMTP/SmtpClientFactoryTest.php index 456cb0c98f..6e63e48d46 100644 --- a/tests/Unit/SMTP/SmtpClientFactoryTest.php +++ b/tests/Unit/SMTP/SmtpClientFactoryTest.php @@ -69,13 +69,16 @@ public function testSmtpTransport() { ->method('getSystemValue') ->willReturnMap([ ['app.mail.transport', 'smtp', 'smtp'], - ['debug', false, false], ['app.mail.smtp.timeout', 20, 2], ]); $this->config->expects($this->any()) ->method('getSystemValueBool') ->with('app.mail.verify-tls-peer', true) ->willReturn(true); + $this->config->expects($this->any()) + ->method('getSystemValueString') + ->with('MAIL_DEBUG') + ->willReturn(''); $this->crypto->expects($this->once()) ->method('decrypt') ->with('obenc')