Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2019-10-02 12:47:00 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2020-01-31 18:43:51 +0300
commitc287787f8df599b567f399f6022ffc88db3a0582 (patch)
tree6d1863eff65f5c43db73c1e36df6938c505ef58e /lib/Migration
parent31f89d71f860c8c2f75234537a8d64f38da696ab (diff)
Add a cache for IMAP message in the database
Co-authored-by: Roeland Jago Douma <roeland@famdouma.nl> Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at> Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib/Migration')
-rw-r--r--lib/Migration/FixAccountSyncs.php64
-rw-r--r--lib/Migration/Version1020Date20191002091034.php33
-rw-r--r--lib/Migration/Version1020Date20191002091035.php157
3 files changed, 254 insertions, 0 deletions
diff --git a/lib/Migration/FixAccountSyncs.php b/lib/Migration/FixAccountSyncs.php
new file mode 100644
index 000000000..319e0cb4e
--- /dev/null
+++ b/lib/Migration/FixAccountSyncs.php
@@ -0,0 +1,64 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @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 OCA\Mail\BackgroundJob\SyncJob;
+use OCA\Mail\Db\MailAccount;
+use OCA\Mail\Db\MailAccountMapper;
+use OCP\BackgroundJob\IJobList;
+use OCP\Migration\IOutput;
+use OCP\Migration\IRepairStep;
+
+class FixAccountSyncs implements IRepairStep {
+
+ /** @var IJobList */
+ private $jobList;
+ /** @var MailAccountMapper */
+ private $mapper;
+
+ public function __construct(IJobList $jobList, MailAccountMapper $mapper) {
+ $this->jobList = $jobList;
+ $this->mapper = $mapper;
+ }
+
+ public function getName(): string {
+ return 'Insert sync background job for all accounts';
+ }
+
+ public function run(IOutput $output) {
+ /** @var MailAccount[] $accounts */
+ $accounts = $this->mapper->getAllAccounts();
+
+ $output->startProgress(count($accounts));
+
+ foreach ($accounts as $account) {
+ $this->jobList->add(SyncJob::class, ['accountId' => $account->getId()]);
+ $output->advance();
+ }
+
+ $output->finishProgress();
+ }
+
+}
diff --git a/lib/Migration/Version1020Date20191002091034.php b/lib/Migration/Version1020Date20191002091034.php
new file mode 100644
index 000000000..4020be614
--- /dev/null
+++ b/lib/Migration/Version1020Date20191002091034.php
@@ -0,0 +1,33 @@
+<?php declare(strict_types=1);
+
+namespace OCA\Mail\Migration;
+
+use Closure;
+use OCP\DB\ISchemaWrapper;
+use OCP\IDBConnection;
+use OCP\Migration\SimpleMigrationStep;
+use OCP\Migration\IOutput;
+
+class Version1020Date20191002091034 extends SimpleMigrationStep {
+
+ /** @var IDBConnection */
+ protected $connection;
+
+ /**
+ * @param IOutput $output
+ * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
+ * @param array $options
+ *
+ * @return ISchemaWrapper
+ */
+ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
+ /** @var ISchemaWrapper $schema */
+ $schema = $schemaClosure();
+
+ $mailboxTable = $schema->getTable('mail_mailboxes');
+ $mailboxTable->dropColumn('sync_token');
+
+ return $schema;
+ }
+
+}
diff --git a/lib/Migration/Version1020Date20191002091035.php b/lib/Migration/Version1020Date20191002091035.php
new file mode 100644
index 000000000..d0cb3b054
--- /dev/null
+++ b/lib/Migration/Version1020Date20191002091035.php
@@ -0,0 +1,157 @@
+<?php declare(strict_types=1);
+
+namespace OCA\Mail\Migration;
+
+use Closure;
+use OCP\DB\ISchemaWrapper;
+use OCP\IDBConnection;
+use OCP\Migration\SimpleMigrationStep;
+use OCP\Migration\IOutput;
+
+class Version1020Date20191002091035 extends SimpleMigrationStep {
+
+ /** @var IDBConnection */
+ protected $connection;
+
+ public function __construct(IDBConnection $connection) {
+ $this->connection = $connection;
+ }
+
+ /**
+ * @param IOutput $output
+ * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
+ * @param array $options
+ *
+ * @return ISchemaWrapper
+ */
+ public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
+ /** @var ISchemaWrapper $schema */
+ $schema = $schemaClosure();
+
+ $messagesTable = $schema->createTable('mail_messages');
+ $messagesTable->addColumn('id', 'integer', [
+ 'autoincrement' => true,
+ 'notnull' => true,
+ 'length' => 20,
+ ]);
+ $messagesTable->addColumn('uid', 'integer', [
+ 'notnull' => true,
+ 'length' => 4,
+ ]);
+ $messagesTable->addColumn('message_id', 'string', [
+ 'notnull' => false,
+ 'length' => 255,
+ ]);
+ $messagesTable->addColumn('mailbox_id', 'string', [
+ 'notnull' => true,
+ 'length' => 4,
+ ]);
+ $messagesTable->addColumn('subject', 'string', [
+ 'notnull' => true,
+ 'length' => 255,
+ 'default' => '',
+ ]);
+ $messagesTable->addColumn('sent_at', 'integer', [
+ 'notnull' => true,
+ 'length' => 4,
+ ]);
+ $messagesTable->addColumn('flag_answered', 'boolean', [
+ 'notnull' => true,
+ 'default' => false,
+ ]);
+ $messagesTable->addColumn('flag_deleted', 'boolean', [
+ 'notnull' => true,
+ 'default' => false,
+ ]);
+ $messagesTable->addColumn('flag_draft', 'boolean', [
+ 'notnull' => true,
+ 'default' => false,
+ ]);
+ $messagesTable->addColumn('flag_flagged', 'boolean', [
+ 'notnull' => true,
+ 'default' => false,
+ ]);
+ $messagesTable->addColumn('flag_seen', 'boolean', [
+ 'notnull' => true,
+ 'default' => false,
+ ]);
+ $messagesTable->addColumn('flag_forwarded', 'boolean', [
+ 'notnull' => true,
+ 'default' => false,
+ ]);
+ $messagesTable->addColumn('flag_junk', 'boolean', [
+ 'notnull' => true,
+ 'default' => false,
+ ]);
+ $messagesTable->addColumn('flag_notjunk', 'boolean', [
+ 'notnull' => true,
+ 'default' => false,
+ ]);
+ $messagesTable->addColumn('updated_at', 'integer', [
+ 'notnull' => false,
+ 'length' => 4,
+ ]);
+ $messagesTable->setPrimaryKey(['id']);
+ // We allow each UID just once
+ $messagesTable->addUniqueIndex([
+ 'uid',
+ 'mailbox_id',
+ ]);
+ $messagesTable->addIndex(['sent_at'], 'mail_message_sent_idx');
+
+ $recipientsTable = $schema->createTable('mail_recipients');
+ $recipientsTable->addColumn('id', 'integer', [
+ 'autoincrement' => true,
+ 'notnull' => true,
+ 'length' => 20,
+ ]);
+ $recipientsTable->addColumn('message_id', 'integer', [
+ 'notnull' => true,
+ 'length' => 20,
+ ]);
+ $recipientsTable->addColumn('type', 'integer', [
+ 'notnull' => true,
+ 'length' => 2,
+ ]);
+ $recipientsTable->addColumn('label', 'string', [
+ 'notnull' => false,
+ 'length' => 255,
+ ]);
+ $recipientsTable->addColumn('email', 'string', [
+ 'notnull' => true,
+ 'length' => 255,
+ ]);
+ $recipientsTable->setPrimaryKey(['id']);
+ $recipientsTable->addIndex(['message_id'], 'mail_recipient_msg_id_idx');
+ $recipientsTable->addIndex(['email'], 'mail_recipient_email_idx');
+
+ $mailboxTable = $schema->getTable('mail_mailboxes');
+ $mailboxTable->addColumn('sync_new_lock', 'integer', [
+ 'notnull' => false,
+ 'length' => 4,
+ ]);
+ $mailboxTable->addColumn('sync_changed_lock', 'integer', [
+ 'notnull' => false,
+ 'length' => 4,
+ ]);
+ $mailboxTable->addColumn('sync_vanished_lock', 'integer', [
+ 'notnull' => false,
+ 'length' => 4,
+ ]);
+ $mailboxTable->addColumn('sync_new_token', 'string', [
+ 'notnull' => false,
+ 'length' => 255,
+ ]);
+ $mailboxTable->addColumn('sync_changed_token', 'string', [
+ 'notnull' => false,
+ 'length' => 255,
+ ]);
+ $mailboxTable->addColumn('sync_vanished_token', 'string', [
+ 'notnull' => false,
+ 'length' => 255,
+ ]);
+
+ return $schema;
+ }
+
+}