diff options
author | Greta <gretadoci@gmail.com> | 2020-09-30 15:10:12 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-30 15:10:12 +0300 |
commit | 57b4f5c0b013a7f6e133c5f872310dab1c3f63ae (patch) | |
tree | 4ce458bbb78db982870ecc97c8956e2071d6acc9 /lib/IMAP | |
parent | c440563285ffc94a84d088450d4f5c5c0472e61e (diff) | |
parent | 41709feb12685f741850528e411b881c5fe65317 (diff) |
Merge pull request #3683 from nextcloud/enhancement/thread-export-command
Add a CLI command to export thread data
Diffstat (limited to 'lib/IMAP')
-rw-r--r-- | lib/IMAP/Threading/DatabaseMessage.php | 26 | ||||
-rw-r--r-- | lib/IMAP/Threading/Message.php | 11 |
2 files changed, 35 insertions, 2 deletions
diff --git a/lib/IMAP/Threading/DatabaseMessage.php b/lib/IMAP/Threading/DatabaseMessage.php index d85654a4f..da79522ce 100644 --- a/lib/IMAP/Threading/DatabaseMessage.php +++ b/lib/IMAP/Threading/DatabaseMessage.php @@ -25,9 +25,12 @@ declare(strict_types=1); namespace OCA\Mail\IMAP\Threading; +use JsonSerializable; +use function array_map; +use function array_merge; use function json_decode; -class DatabaseMessage extends Message { +class DatabaseMessage extends Message implements JsonSerializable { /** @var int */ private $databaseId; @@ -88,4 +91,25 @@ class DatabaseMessage extends Message { public function isDirty(): bool { return $this->dirty; } + + public function redact(callable $hash): DatabaseMessage { + return new self( + $this->databaseId, + $this->hasReSubject() ? "Re: " . $hash($this->getSubject()) : $hash($this->getSubject()), + $hash($this->getId()), + array_map(function (string $ref) use ($hash) { + return $hash($ref); + }, $this->getReferences()), + $this->threadRootId === null ? null : $hash($this->threadRootId) + ); + } + + public function jsonSerialize(): array { + return array_merge( + parent::jsonSerialize(), + [ + 'databaseId' => $this->databaseId, + ] + ); + } } diff --git a/lib/IMAP/Threading/Message.php b/lib/IMAP/Threading/Message.php index 7b3684963..8fd7170ae 100644 --- a/lib/IMAP/Threading/Message.php +++ b/lib/IMAP/Threading/Message.php @@ -25,10 +25,11 @@ declare(strict_types=1); namespace OCA\Mail\IMAP\Threading; +use JsonSerializable; use function str_replace; use function strpos; -class Message { +class Message implements JsonSerializable { /** @var string */ private $subject; @@ -72,4 +73,12 @@ class Message { public function getReferences(): array { return $this->references; } + + public function jsonSerialize(): array { + return [ + 'subject' => $this->subject, + 'id' => $this->id, + 'references' => $this->references, + ]; + } } |