+
+
+ {{ t('mail', 'Automatically create tentative appointments in calendar') }}
+
+
+
+
+
diff --git a/tests/Unit/Service/IMipServiceTest.php b/tests/Unit/Service/IMipServiceTest.php
index 0b2bd7a265..fa31224c30 100644
--- a/tests/Unit/Service/IMipServiceTest.php
+++ b/tests/Unit/Service/IMipServiceTest.php
@@ -23,7 +23,9 @@
use OCA\Mail\Service\AccountService;
use OCA\Mail\Service\IMipService;
use OCA\Mail\Service\MailManager;
+use OCA\Mail\Util\ServerVersion;
use OCP\Calendar\IManager;
+use OCP\ServerVersion as OCPServerVersion;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
@@ -36,6 +38,7 @@ class IMipServiceTest extends TestCase {
/** @var AccountService|MockObject */
private $accountService;
+
private IManager $calendarManager;
/** @var MailManager|MockObject */
@@ -46,6 +49,10 @@ class IMipServiceTest extends TestCase {
private IMipService $service;
+ private ServerVersion|MockObject $serverVersion;
+
+ private OCPServerVersion $OCPServerVersion;
+
protected function setUp(): void {
parent::setUp();
@@ -55,6 +62,8 @@ protected function setUp(): void {
$this->logger = $this->createMock(LoggerInterface::class);
$this->mailManager = $this->createMock(MailManager::class);
$this->messageMapper = $this->createMock(MessageMapper::class);
+ $this->serverVersion = $this->createMock(ServerVersion::class);
+ $this->OCPServerVersion = new OCPServerVersion();
$this->service = new IMipService(
$this->accountService,
@@ -62,7 +71,8 @@ protected function setUp(): void {
$this->logger,
$this->mailboxMapper,
$this->mailManager,
- $this->messageMapper
+ $this->messageMapper,
+ $this->serverVersion
);
}
@@ -76,6 +86,8 @@ public function testNoSchedulingInformation(): void {
->method('findById');
$this->accountService->expects(self::never())
->method('findById');
+ $this->calendarManager->expects(self::never())
+ ->method('handleIMipRequest');
$this->calendarManager->expects(self::never())
->method('handleIMipReply');
$this->calendarManager->expects(self::never())
@@ -112,6 +124,8 @@ public function testIsSpecialUse(): void {
->willReturn($account);
$this->messageMapper->expects(self::once())
->method('updateImipData');
+ $this->calendarManager->expects(self::never())
+ ->method('handleIMipRequest');
$this->calendarManager->expects(self::never())
->method('handleIMipReply');
$this->calendarManager->expects(self::never())
@@ -145,6 +159,8 @@ public function testIsArchive(): void {
->willReturn($account);
$this->messageMapper->expects(self::once())
->method('updateImipData');
+ $this->calendarManager->expects(self::never())
+ ->method('handleIMipRequest');
$this->calendarManager->expects(self::never())
->method('handleIMipReply');
$this->calendarManager->expects(self::never())
@@ -183,6 +199,8 @@ public function testNoSchedulingInfo(): void {
->method('getImapMessagesForScheduleProcessing')
->with($account, $mailbox, [$message->getUid()])
->willReturn([$imapMessage]);
+ $this->calendarManager->expects(self::never())
+ ->method('handleIMipRequest');
$this->calendarManager->expects(self::never())
->method('handleIMipReply');
$this->calendarManager->expects(self::never())
@@ -225,6 +243,8 @@ public function testImapConnectionServiceException(): void {
->willThrowException(new ServiceException());
$this->logger->expects(self::once())
->method('error');
+ $this->calendarManager->expects(self::never())
+ ->method('handleIMipRequest');
$this->calendarManager->expects(self::never())
->method('handleIMipReply');
$this->calendarManager->expects(self::never())
@@ -266,6 +286,9 @@ public function testIsRequest(): void {
->method('getImapMessagesForScheduleProcessing')
->with($account, $mailbox, [$message->getUid()])
->willReturn([$imapMessage]);
+ $this->serverVersion->expects(self::once())
+ ->method('getMajorVersion')
+ ->willReturn(32);
$imapMessage->expects(self::once())
->method('getUid')
->willReturn(1);
@@ -323,11 +346,12 @@ public function testIsReply(): void {
->method('getImapMessagesForScheduleProcessing')
->with($account, $mailbox, [$message->getUid()])
->willReturn([$imapMessage]);
+ $this->serverVersion->expects(self::once())
+ ->method('getMajorVersion')
+ ->willReturn(32);
$imapMessage->expects(self::once())
->method('getUid')
->willReturn(1);
- $this->logger->expects(self::never())
- ->method('info');
$imapMessage->expects(self::once())
->method('getFrom')
->willReturn($addressList);
@@ -337,9 +361,6 @@ public function testIsReply(): void {
$address->expects(self::once())
->method('getEmail')
->willReturn('pam@stardew-bus-service.com');
- $imapMessage->expects(self::never())
- ->method('getInReplyTo')
- ->willReturn($addressList);
$this->calendarManager->expects(self::once())
->method('handleIMipReply')
->with('principals/users/vincent',
@@ -383,6 +404,207 @@ public function testIsCancel(): void {
->method('getImapMessagesForScheduleProcessing')
->with($account, $mailbox, [$message->getUid()])
->willReturn([$imapMessage]);
+ $this->serverVersion->expects(self::once())
+ ->method('getMajorVersion')
+ ->willReturn(32);
+ $imapMessage->expects(self::once())
+ ->method('getUid')
+ ->willReturn(1);
+ $this->logger->expects(self::never())
+ ->method('info');
+ $imapMessage->expects(self::once())
+ ->method('getFrom')
+ ->willReturn($addressList);
+ $addressList->expects(self::once())
+ ->method('first')
+ ->willReturn($address);
+ $address->expects(self::once())
+ ->method('getEmail')
+ ->willReturn('pam@stardew-bus-service.com');
+ $this->calendarManager->expects(self::once())
+ ->method('handleIMipCancel')
+ ->with('principals/users/vincent',
+ 'pam@stardew-bus-service.com',
+ null,
+ $account->getEmail(),
+ $imapMessage->scheduling[0]['contents']
+ );
+ $this->messageMapper->expects(self::once())
+ ->method('updateImipData');
+
+ $this->service->process();
+ }
+
+ public function testIsRequestServerVersion33(): void {
+ if ($this->OCPServerVersion->getMajorVersion() < 33) {
+ $this->markTestSkipped('Requires Nextcloud 33 or higher');
+ }
+
+ $message = new Message();
+ $message->setImipMessage(true);
+ $message->setUid(1);
+ $message->setMailboxId(100);
+ $mailbox = new Mailbox();
+ $mailbox->setId(100);
+ $mailbox->setAccountId(200);
+ $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', 'contents' => 'VCALENDAR'];
+ $addressList = $this->createMock(AddressList::class);
+ $address = $this->createMock(Address::class);
+
+ $this->messageMapper->expects(self::once())
+ ->method('findIMipMessagesAscending')
+ ->willReturn([$message]);
+ $this->mailboxMapper->expects(self::once())
+ ->method('findById')
+ ->willReturn($mailbox);
+ $this->accountService->expects(self::once())
+ ->method('findById')
+ ->willReturn($account);
+ $this->mailManager->expects(self::once())
+ ->method('getImapMessagesForScheduleProcessing')
+ ->with($account, $mailbox, [$message->getUid()])
+ ->willReturn([$imapMessage]);
+ $this->serverVersion->expects(self::once())
+ ->method('getMajorVersion')
+ ->willReturn(33);
+ $imapMessage->expects(self::once())
+ ->method('getUid')
+ ->willReturn(1);
+ $imapMessage->expects(self::once())
+ ->method('getFrom')
+ ->willReturn($addressList);
+ $addressList->expects(self::once())
+ ->method('first')
+ ->willReturn($address);
+ $address->expects(self::once())
+ ->method('getEmail')
+ ->willReturn('pam@stardew-bus-service.com');
+ $this->logger->expects(self::never())
+ ->method('info');
+ $this->calendarManager->expects(self::once())
+ ->method('handleIMip')
+ ->with('vincent', 'VCALENDAR', [
+ 'recipient' => 'vincent@stardew-valley.edu',
+ 'absent' => 'ignore',
+ 'absentCreateStatus' => 'tentative',
+ ])
+ ->willReturn(true);
+ $this->messageMapper->expects(self::once())
+ ->method('updateImipData');
+
+ $this->service->process();
+ }
+
+ public function testIsReplyServerVersion33(): void {
+ if ($this->OCPServerVersion->getMajorVersion() < 33) {
+ $this->markTestSkipped('Requires Nextcloud 33 or higher');
+ }
+
+ $message = new Message();
+ $message->setImipMessage(true);
+ $message->setUid(1);
+ $message->setMailboxId(100);
+ $mailbox = new Mailbox();
+ $mailbox->setId(100);
+ $mailbox->setAccountId(200);
+ $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' => 'REPLY', 'contents' => 'VCARD'];
+ $addressList = $this->createMock(AddressList::class);
+ $address = $this->createMock(Address::class);
+
+ $this->messageMapper->expects(self::once())
+ ->method('findIMipMessagesAscending')
+ ->willReturn([$message]);
+ $this->mailboxMapper->expects(self::once())
+ ->method('findById')
+ ->willReturn($mailbox);
+ $this->accountService->expects(self::once())
+ ->method('findById')
+ ->willReturn($account);
+ $this->mailManager->expects(self::once())
+ ->method('getImapMessagesForScheduleProcessing')
+ ->with($account, $mailbox, [$message->getUid()])
+ ->willReturn([$imapMessage]);
+ $this->serverVersion->expects(self::once())
+ ->method('getMajorVersion')
+ ->willReturn(33);
+ $imapMessage->expects(self::once())
+ ->method('getUid')
+ ->willReturn(1);
+ $this->logger->expects(self::never())
+ ->method('info');
+ $imapMessage->expects(self::once())
+ ->method('getFrom')
+ ->willReturn($addressList);
+ $addressList->expects(self::once())
+ ->method('first')
+ ->willReturn($address);
+ $address->expects(self::once())
+ ->method('getEmail')
+ ->willReturn('pam@stardew-bus-service.com');
+ $this->calendarManager->expects(self::once())
+ ->method('handleIMip')
+ ->with('vincent', 'VCARD', [
+ 'recipient' => 'vincent@stardew-valley.edu',
+ 'absent' => 'ignore',
+ 'absentCreateStatus' => 'tentative',
+ ])
+ ->willReturn(true);
+ $this->messageMapper->expects(self::once())
+ ->method('updateImipData');
+
+ $this->service->process();
+ }
+
+ public function testIsCancelServerVersion33(): void {
+ if ($this->OCPServerVersion->getMajorVersion() < 33) {
+ $this->markTestSkipped('Requires Nextcloud 33 or higher');
+ }
+
+ $message = new Message();
+ $message->setImipMessage(true);
+ $message->setUid(1);
+ $message->setMailboxId(100);
+ $mailbox = new Mailbox();
+ $mailbox->setId(100);
+ $mailbox->setAccountId(200);
+ $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' => 'CANCEL', 'contents' => 'VCARD'];
+ $addressList = $this->createMock(AddressList::class);
+ $address = $this->createMock(Address::class);
+
+ $this->messageMapper->expects(self::once())
+ ->method('findIMipMessagesAscending')
+ ->willReturn([$message]);
+ $this->mailboxMapper->expects(self::once())
+ ->method('findById')
+ ->willReturn($mailbox);
+ $this->accountService->expects(self::once())
+ ->method('findById')
+ ->willReturn($account);
+ $this->mailManager->expects(self::once())
+ ->method('getImapMessagesForScheduleProcessing')
+ ->with($account, $mailbox, [$message->getUid()])
+ ->willReturn([$imapMessage]);
+ $this->serverVersion->expects(self::once())
+ ->method('getMajorVersion')
+ ->willReturn(33);
$imapMessage->expects(self::once())
->method('getUid')
->willReturn(1);
@@ -407,7 +629,8 @@ public function testIsCancel(): void {
null,
$account->getEmail(),
$imapMessage->scheduling[0]['contents']
- );
+ )
+ ->willReturn(true);
$this->messageMapper->expects(self::once())
->method('updateImipData');