Skip to content

Commit

Permalink
feat: add iMip Request Handling
Browse files Browse the repository at this point in the history
Signed-off-by: SebastianKrupinski <[email protected]>
  • Loading branch information
SebastianKrupinski committed Nov 8, 2024
1 parent b9a0733 commit e8578ed
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
6 changes: 5 additions & 1 deletion lib/Service/IMipService.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ public function process(): void {
$sender = $imapMessage->getFrom()->first()->getEmail();
$recipient = $account->getEmail();
foreach ($imapMessage->scheduling as $schedulingInfo) { // an IMAP message could contain more than one iMIP object
if ($schedulingInfo['method'] === 'REPLY') {
if ($schedulingInfo['method'] === 'REQUEST' && method_exists($this->calendarManager, 'handleIMipRequest')) {
$processed = $this->calendarManager->handleIMipRequest($principalUri, $sender, $recipient, $schedulingInfo['contents']);
$message->setImipProcessed($processed);
$message->setImipError(!$processed);
} elseif ($schedulingInfo['method'] === 'REPLY') {
$processed = $this->calendarManager->handleIMipReply($principalUri, $sender, $recipient, $schedulingInfo['contents']);
$message->setImipProcessed($processed);
$message->setImipError(!$processed);
Expand Down
33 changes: 17 additions & 16 deletions tests/Unit/Service/IMipServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ class IMipServiceTest extends TestCase {
protected function setUp(): void {
parent::setUp();

// iMIP is NC25+
if (!method_exists(IManager::class, 'handleImipReply')) {
self::markTestIncomplete();
}


$this->accountService = $this->createMock(AccountService::class);
$this->calendarManager = $this->createMock(IManager::class);
$this->mailboxMapper = $this->createMock(MailboxMapper::class);
Expand Down Expand Up @@ -242,6 +236,12 @@ public function testImapConnectionServiceException(): void {
}

public function testIsRequest(): void {

// iMip Request is NC31+
if (!method_exists(IManager::class, 'handleImipRequest')) {
self::markTestIncomplete();
}

$message = new Message();
$message->setImipMessage(true);
$message->setUid(1);
Expand All @@ -252,9 +252,10 @@ public function testIsRequest(): void {
$mailAccount = new MailAccount();
$mailAccount->setId(200);
$mailAccount->setEmail('[email protected]');
$mailAccount->setUserId('vincent');
$account = new Account($mailAccount);
$imapMessage = $this->createMock(IMAPMessage::class);
$imapMessage->scheduling[] = ['method' => 'REQUEST'];
$imapMessage->scheduling[] = ['method' => 'REQUEST', 'contents' => 'VCALENDAR'];
$addressList = $this->createMock(AddressList::class);
$address = $this->createMock(Address::class);

Expand Down Expand Up @@ -282,15 +283,17 @@ public function testIsRequest(): void {
->willReturn($address);
$address->expects(self::once())
->method('getEmail')
->willReturn('pam@stardew-bus-company.com');
->willReturn('pam@stardew-bus-service.com');
$this->logger->expects(self::never())
->method('info');
$this->calendarManager->expects(self::never())
->method('handleIMipReply');
$this->calendarManager->expects(self::never())
->method('handleIMipCancel');
$this->messageMapper->expects(self::never())
->method('updateBulk');
$this->calendarManager->expects(self::once())
->method('handleIMipRequest')
->with('principals/users/vincent',
'[email protected]',
$account->getEmail(),
$imapMessage->scheduling[0]['contents']);
$this->messageMapper->expects(self::once())
->method('updateImipData');

$this->service->process();
}
Expand Down Expand Up @@ -349,8 +352,6 @@ public function testIsReply(): void {
'[email protected]',
$account->getEmail(),
$imapMessage->scheduling[0]['contents']);
$this->calendarManager->expects(self::never())
->method('handleIMipCancel');
$this->messageMapper->expects(self::once())
->method('updateImipData');

Expand Down

0 comments on commit e8578ed

Please sign in to comment.