diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-07-03 14:43:46 +0300 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-07-13 12:24:26 +0300 |
commit | 1bff124f2ec279032e2093d68b62057ab4459087 (patch) | |
tree | a619dcad47f97a9cc8832fd2961b63f5d742d24b /lib/IMAP | |
parent | 437d06e6557827cf043d5364192b9ffd757676ab (diff) |
Build threads after each IMAP sync
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/IMAP')
-rw-r--r-- | lib/IMAP/Threading/DatabaseMessage.php | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/lib/IMAP/Threading/DatabaseMessage.php b/lib/IMAP/Threading/DatabaseMessage.php new file mode 100644 index 000000000..d85654a4f --- /dev/null +++ b/lib/IMAP/Threading/DatabaseMessage.php @@ -0,0 +1,91 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2020 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @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\IMAP\Threading; + +use function json_decode; + +class DatabaseMessage extends Message { + + /** @var int */ + private $databaseId; + + /** @var string|null */ + private $threadRootId; + + /** @var bool */ + private $dirty = false; + + public function __construct(int $databaseId, + string $subject, + string $id, + array $references, + ?string $threadRootId) { + parent::__construct($subject, $id, $references); + + $this->databaseId = $databaseId; + $this->threadRootId = $threadRootId; + } + + public static function fromRowData(int $id, + string $subject, + ?string $messageId, + ?string $references, + ?string $inReplyTo, + ?string $threadRootId): self { + $referencesForThreading = $references !== null ? json_decode($references, true) : []; + if (!empty($inReplyTo)) { + $referencesForThreading[] = $inReplyTo; + } + + return new self( + $id, + $subject, + $messageId, + $referencesForThreading, + $threadRootId + ); + } + + public function getDatabaseId(): int { + return $this->databaseId; + } + + public function getThreadRootId(): ?string { + return $this->threadRootId; + } + + public function setThreadRootId(?string $threadRootId): void { + // Only update the thread ID if it has a value, is different and we haven't set one before + if ($threadRootId !== null && $this->threadRootId !== $threadRootId && !$this->dirty) { + $this->dirty = true; + $this->threadRootId = $threadRootId; + } + } + + public function isDirty(): bool { + return $this->dirty; + } +} |