-
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.
Add request-response based synchronizer around horde sync
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
- Loading branch information
1 parent
b98fe0e
commit ee414f4
Showing
9 changed files
with
456 additions
and
4 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
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,41 @@ | ||
<?php | ||
|
||
/** | ||
* @author Christoph Wurst <christoph@winzerhof-wurst.at> | ||
* | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* 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, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace OCA\Mail\IMAP; | ||
|
||
use Exception; | ||
use Horde_Imap_Client_Base; | ||
use OCA\Mail\Folder; | ||
use OCA\Mail\Model\IMAPMessage; | ||
|
||
class MessageMapper { | ||
|
||
/** | ||
* @param Horde_Imap_Client_Base $imapClient | ||
* @param Folder $mailbox | ||
* @param array $ids | ||
* @return IMAPMessage[] | ||
*/ | ||
public function findByIds(Horde_Imap_Client_Base $imapClient, $mailbox, array $ids) { | ||
throw new Exception('not implemented'); | ||
} | ||
|
||
} |
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,57 @@ | ||
<?php | ||
|
||
/** | ||
* @author Christoph Wurst <christoph@winzerhof-wurst.at> | ||
* | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* 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, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace OCA\Mail\IMAP\Sync; | ||
|
||
class Request { | ||
|
||
/** @var string */ | ||
private $mailbox; | ||
|
||
/** @var string */ | ||
private $syncToken; | ||
|
||
/** | ||
* @param string $mailbox | ||
* @param string $syncToken | ||
*/ | ||
public function __construct($mailbox, $syncToken) { | ||
$this->mailbox = $mailbox; | ||
$this->syncToken = $syncToken; | ||
} | ||
|
||
/** | ||
* Get the mailbox name | ||
* | ||
* @return string | ||
*/ | ||
public function getMailbox() { | ||
return $this->mailbox; | ||
} | ||
|
||
/** | ||
* @return string the Horde sync token | ||
*/ | ||
public function getToken() { | ||
return $this->syncToken; | ||
} | ||
|
||
} |
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,68 @@ | ||
<?php | ||
|
||
/** | ||
* @author Christoph Wurst <christoph@winzerhof-wurst.at> | ||
* | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* 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, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace OCA\Mail\IMAP\Sync; | ||
|
||
use Exception; | ||
use JsonSerializable; | ||
use OCA\Mail\Model\IMAPMessage; | ||
|
||
class Response implements JsonSerializable { | ||
|
||
/** @var string */ | ||
private $syncToken; | ||
|
||
/** @var IMAPMessage[] */ | ||
private $newMessages; | ||
|
||
/** @var IMAPMessage[] */ | ||
private $changedMessages; | ||
|
||
/** @var array */ | ||
private $vanishedMessages; | ||
|
||
/** | ||
* @param string $syncToken | ||
* @param IMAPMessage[] $newMessages | ||
* @param IMAPMessage[] $changedMessages | ||
* @param array $vanishedMessages | ||
*/ | ||
public function __construct($syncToken, array $newMessages = [], array $changedMessages = [], | ||
array $vanishedMessages = []) { | ||
$this->syncToken = $syncToken; | ||
$this->newMessages = $newMessages; | ||
$this->changedMessages = $changedMessages; | ||
$this->vanishedMessages = $vanishedMessages; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function jsonSerialize() { | ||
return [ | ||
'newMessages' => $this->newMessages, | ||
'changedMessages' => $this->changedMessages, | ||
'vanishedMessages' => $this->vanishedMessages, | ||
'token' => $this->syncToken, | ||
]; | ||
} | ||
|
||
} |
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,57 @@ | ||
<?php | ||
|
||
/** | ||
* @author Christoph Wurst <christoph@winzerhof-wurst.at> | ||
* | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* 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, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace OCA\Mail\IMAP\Sync; | ||
|
||
use Horde_Imap_Client_Base; | ||
use OCA\Mail\IMAP\MessageMapper; | ||
use OCA\Mail\IMAP\Sync\Request; | ||
use OCA\Mail\IMAP\Sync\Response; | ||
|
||
class Synchronizer { | ||
|
||
/** @var MessageMapper */ | ||
private $messageMapper; | ||
|
||
/** | ||
* @param MessageMapper $messageMapper | ||
*/ | ||
public function __construct(MessageMapper $messageMapper) { | ||
$this->messageMapper = $messageMapper; | ||
} | ||
|
||
/** | ||
* @param Horde_Imap_Client_Base $imapClient | ||
* @param Request $request | ||
* @return Response | ||
*/ | ||
public function sync(Horde_Imap_Client_Base $imapClient, Request $request) { | ||
$hordeSync = $imapClient->sync($request->getMailbox(), $request->getToken()); | ||
|
||
$newMessages = $this->messageMapper->findByIds($imapClient, $request->getMailbox(), $hordeSync->newmsgsuids->ids); | ||
$changedMessages = $this->messageMapper->findByIds($imapClient, $request->getMailbox(), $hordeSync->flagsuids->ids); | ||
$vanishedMessages = $hordeSync->vanisheduids->ids; | ||
|
||
$newSyncToken = $imapClient->getSyncToken($request->getMailbox()); | ||
return new Response($newSyncToken, $newMessages, $changedMessages, $vanishedMessages); | ||
} | ||
|
||
} |
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,55 @@ | ||
<?php | ||
|
||
/** | ||
* @author Christoph Wurst <christoph@winzerhof-wurst.at> | ||
* | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* 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, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace OCA\Mail\Tests\IMAP\Sync; | ||
|
||
use OCA\Mail\IMAP\Sync\Request; | ||
use PHPUnit_Framework_TestCase; | ||
|
||
class RequestTest extends PHPUnit_Framework_TestCase { | ||
|
||
/** @var string */ | ||
private $mailbox; | ||
|
||
/** @var string */ | ||
private $syncToken; | ||
|
||
/** @var Request */ | ||
private $request; | ||
|
||
protected function setUp() { | ||
parent::setUp(); | ||
|
||
$this->mailbox = 'inbox'; | ||
$this->syncToken = 'ab123'; | ||
|
||
$this->request = new Request($this->mailbox, $this->syncToken); | ||
} | ||
|
||
public function testGetMailbox() { | ||
$this->assertEquals($this->mailbox, $this->request->getMailbox()); | ||
} | ||
|
||
public function testGetSyncToken() { | ||
$this->assertEquals($this->syncToken, $this->request->getToken()); | ||
} | ||
|
||
} |
Oops, something went wrong.