diff options
author | Daniel Kesselberg <mail@danielkesselberg.de> | 2021-09-08 14:55:11 +0300 |
---|---|---|
committer | Daniel Kesselberg <mail@danielkesselberg.de> | 2021-09-08 18:56:43 +0300 |
commit | 1595883bdaebb3496966c55eacb25c0f8a6ed1dc (patch) | |
tree | f56cb98516a413fa7db0493ead46d71766f7ee38 /lib | |
parent | bde8a5b5252120ae6a058b44fa82319c466297a2 (diff) |
Allow empty delimiter
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Db/Mailbox.php | 4 | ||||
-rw-r--r-- | lib/Folder.php | 13 | ||||
-rw-r--r-- | lib/IMAP/FolderMapper.php | 15 | ||||
-rw-r--r-- | lib/Migration/Version1110Date20210908114229.php | 32 |
4 files changed, 46 insertions, 18 deletions
diff --git a/lib/Db/Mailbox.php b/lib/Db/Mailbox.php index 478421634..1df1c86a3 100644 --- a/lib/Db/Mailbox.php +++ b/lib/Db/Mailbox.php @@ -53,8 +53,8 @@ use function strtolower; * @method void setSyncVanishedLock(int|null $ts) * @method string getAttributes() * @method void setAttributes(string $attributes) - * @method string getDelimiter() - * @method void setDelimiter(string $delimiter) + * @method string|null getDelimiter() + * @method void setDelimiter(string|null $delimiter) * @method int getMessages() * @method void setMessages(int $messages) * @method int getUnseen() diff --git a/lib/Folder.php b/lib/Folder.php index 062eeae25..009cff8e8 100644 --- a/lib/Folder.php +++ b/lib/Folder.php @@ -45,13 +45,7 @@ class Folder { /** @var string[] */ private $specialUse; - /** - * @param Account $account - * @param Horde_Imap_Client_Mailbox $mailbox - * @param array $attributes - * @param string $delimiter - */ - public function __construct(int $accountId, Horde_Imap_Client_Mailbox $mailbox, array $attributes, $delimiter) { + public function __construct(int $accountId, Horde_Imap_Client_Mailbox $mailbox, array $attributes, ?string $delimiter) { $this->accountId = $accountId; $this->mailbox = $mailbox; $this->attributes = $attributes; @@ -67,10 +61,7 @@ class Folder { return $this->mailbox->utf8; } - /** - * @return string - */ - public function getDelimiter() { + public function getDelimiter(): ?string { return $this->delimiter; } diff --git a/lib/IMAP/FolderMapper.php b/lib/IMAP/FolderMapper.php index e419adca0..fa4f63f06 100644 --- a/lib/IMAP/FolderMapper.php +++ b/lib/IMAP/FolderMapper.php @@ -23,16 +23,16 @@ declare(strict_types=1); namespace OCA\Mail\IMAP; -use function array_filter; -use function array_map; -use function in_array; -use function reset; use Horde_Imap_Client; use Horde_Imap_Client_Exception; use Horde_Imap_Client_Socket; use OCA\Mail\Account; use OCA\Mail\Exception\ServiceException; use OCA\Mail\Folder; +use function array_filter; +use function array_map; +use function in_array; +use function reset; class FolderMapper { @@ -236,8 +236,13 @@ class FolderMapper { 'junk' => ['junk', 'spam', 'bulk mail'], ]; - $lowercaseExplode = explode($folder->getDelimiter(), $folder->getMailbox(), 2); + if ($folder->getDelimiter() === null) { + $lowercaseExplode = [$folder->getMailbox()]; + } else { + $lowercaseExplode = explode($folder->getDelimiter(), $folder->getMailbox(), 2); + } $lowercaseId = strtolower(array_pop($lowercaseExplode)); + foreach ($specialFoldersDict as $specialRole => $specialNames) { if (in_array($lowercaseId, $specialNames)) { $folder->addSpecialUse($specialRole); diff --git a/lib/Migration/Version1110Date20210908114229.php b/lib/Migration/Version1110Date20210908114229.php new file mode 100644 index 000000000..f1a469f51 --- /dev/null +++ b/lib/Migration/Version1110Date20210908114229.php @@ -0,0 +1,32 @@ +<?php + +declare(strict_types=1); + +namespace OCA\Mail\Migration; + +use Closure; +use OCP\DB\ISchemaWrapper; +use OCP\Migration\IOutput; +use OCP\Migration\SimpleMigrationStep; + +class Version1110Date20210908114229 extends SimpleMigrationStep { + + /** + * @param IOutput $output + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` + * @param array $options + * @return null|ISchemaWrapper + */ + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + + $mailboxTable = $schema->getTable('mail_mailboxes'); + $mailboxTable->changeColumn('delimiter', [ + 'notnull' => false, + 'length' => 1, + ]); + + return $schema; + } +} |