-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
- Loading branch information
1 parent
3fa2ab1
commit 6f5890f
Showing
20 changed files
with
837 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?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\Events; | ||
|
||
use OCA\Mail\Account; | ||
use OCA\Mail\Db\Mailbox; | ||
use OCA\Mail\Db\Message; | ||
use OCP\EventDispatcher\Event; | ||
|
||
class NewMessagesSynchronized extends Event { | ||
|
||
/** @var Account */ | ||
private $account; | ||
|
||
/** @var Mailbox */ | ||
private $mailbox; | ||
|
||
/** @var array|Message[] */ | ||
private $messages; | ||
|
||
/** | ||
* @param Account $account | ||
* @param Mailbox $mailbox | ||
* @param Message[] $messages | ||
*/ | ||
public function __construct(Account $account, | ||
Mailbox $mailbox, | ||
array $messages) { | ||
parent::__construct(); | ||
$this->account = $account; | ||
$this->mailbox = $mailbox; | ||
$this->messages = $messages; | ||
} | ||
|
||
public function getAccount(): Account { | ||
return $this->account; | ||
} | ||
|
||
public function getMailbox(): Mailbox { | ||
return $this->mailbox; | ||
} | ||
|
||
/** | ||
* @return Message[] | ||
*/ | ||
public function getMessages() { | ||
return $this->messages; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?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\Listener; | ||
|
||
use OCA\Mail\Events\NewMessagesSynchronized; | ||
use OCA\Mail\Service\Classification\MessageClassifier; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\EventDispatcher\IEventListener; | ||
|
||
class NewMessageClassificationListener implements IEventListener { | ||
|
||
/** @var MessageClassifier */ | ||
private $classifier; | ||
|
||
public function __construct(MessageClassifier $classifier) { | ||
$this->classifier = $classifier; | ||
} | ||
|
||
public function handle(Event $event): void { | ||
if (!($event instanceof NewMessagesSynchronized)) { | ||
return; | ||
} | ||
|
||
foreach ($event->getMessages() as $message) { | ||
if ($this->classifier->isImportant($event->getAccount(), $event->getMailbox(), $message)) { | ||
$message->setFlagImportant(true); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?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\Service\Classification; | ||
|
||
use OCA\Mail\Account; | ||
use OCA\Mail\Db\Mailbox; | ||
use OCA\Mail\Db\Message; | ||
|
||
abstract class AClassifier { | ||
|
||
public abstract function isImportant(Account $account, Mailbox $mailbox, Message $message): bool; | ||
|
||
public final function or(AClassifier $next): AClassifier { | ||
return new class($this, $next) extends AClassifier { | ||
/** @var AClassifier */ | ||
private $outer; | ||
|
||
/** @var AClassifier */ | ||
private $next; | ||
|
||
public function __construct(AClassifier $outer, AClassifier $next) { | ||
$this->outer = $outer; | ||
$this->next = $next; | ||
} | ||
|
||
public function isImportant(Account $account, Mailbox $mailbox, Message $message): bool { | ||
return $this->outer->isImportant($account, $mailbox, $message) || $this->next->isImportant($account, $mailbox, $message); | ||
} | ||
}; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?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\Service\Classification; | ||
|
||
use OCA\Mail\Account; | ||
use OCA\Mail\Db\Mailbox; | ||
use OCA\Mail\Db\Message; | ||
|
||
class MessageClassifier { | ||
|
||
/** @var AClassifier */ | ||
private $oftenImportantSenderClassifier; | ||
|
||
/** @var AClassifier */ | ||
private $oftenContactedSenderClassifier; | ||
|
||
/** @var AClassifier */ | ||
private $oftenReadSenderClassifier; | ||
|
||
/** @var AClassifier */ | ||
private $oftenRepliedSenderClassifier; | ||
|
||
public function __construct(OftenImportantSenderClassifier $oftenImportantSenderClassifier, | ||
OftenContactedSenderClassifier $oftenContactedSenderClassifier, | ||
OftenReadSenderClassifier $oftenReadSenderClassifier, | ||
OftenRepliedSenderClassifier $oftenRepliedSenderClassifier) { | ||
$this->oftenImportantSenderClassifier = $oftenImportantSenderClassifier; | ||
$this->oftenContactedSenderClassifier = $oftenContactedSenderClassifier; | ||
$this->oftenReadSenderClassifier = $oftenReadSenderClassifier; | ||
$this->oftenRepliedSenderClassifier = $oftenRepliedSenderClassifier; | ||
} | ||
|
||
public function isImportant(Account $account, | ||
Mailbox $mailbox, | ||
Message $message): bool { | ||
return $this->oftenImportantSenderClassifier | ||
->or($this->oftenContactedSenderClassifier) | ||
->or($this->oftenReadSenderClassifier) | ||
->or($this->oftenRepliedSenderClassifier) | ||
->isImportant($account, $mailbox, $message); | ||
} | ||
|
||
} |
Oops, something went wrong.