From e8578edef275e434a2e2318808d0275d25fad378 Mon Sep 17 00:00:00 2001 From: SebastianKrupinski Date: Sat, 7 Sep 2024 20:18:50 -0400 Subject: [PATCH] feat: add iMip Request Handling Signed-off-by: SebastianKrupinski --- lib/Service/IMipService.php | 6 ++++- tests/Unit/Service/IMipServiceTest.php | 33 +++++++++++++------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/lib/Service/IMipService.php b/lib/Service/IMipService.php index 88617bccd1..8c1f8d39a3 100644 --- a/lib/Service/IMipService.php +++ b/lib/Service/IMipService.php @@ -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); diff --git a/tests/Unit/Service/IMipServiceTest.php b/tests/Unit/Service/IMipServiceTest.php index 6b1bd6e2e2..f6dc6fdb22 100644 --- a/tests/Unit/Service/IMipServiceTest.php +++ b/tests/Unit/Service/IMipServiceTest.php @@ -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); @@ -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); @@ -252,9 +252,10 @@ public function testIsRequest(): void { $mailAccount = new MailAccount(); $mailAccount->setId(200); $mailAccount->setEmail('vincent@stardew-valley.edu'); + $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); @@ -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', + 'pam@stardew-bus-service.com', + $account->getEmail(), + $imapMessage->scheduling[0]['contents']); + $this->messageMapper->expects(self::once()) + ->method('updateImipData'); $this->service->process(); } @@ -349,8 +352,6 @@ public function testIsReply(): void { 'pam@stardew-bus-service.com', $account->getEmail(), $imapMessage->scheduling[0]['contents']); - $this->calendarManager->expects(self::never()) - ->method('handleIMipCancel'); $this->messageMapper->expects(self::once()) ->method('updateImipData');