Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/BackgroundJob/ContextChat/SubmitContentJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OCA\Mail\Db\MailboxMapper;
use OCA\Mail\Db\Message;
use OCA\Mail\Db\MessageMapper;
use OCA\Mail\Exception\ClientException;
use OCA\Mail\Exception\ServiceException;
use OCA\Mail\Exception\SmimeDecryptException;
use OCA\Mail\Service\AccountService;
Expand Down Expand Up @@ -115,7 +116,7 @@ protected function run($argument): void {
}
try {
$imapMessage = $this->mailManager->getImapMessage($account, $mailbox, $message, true);
} catch (ServiceException $e) {
} catch (ServiceException|ClientException $e) {
// couldn't load message, let's skip it. Retrying would be too costly
continue;
} catch (SmimeDecryptException $e) {
Expand Down
47 changes: 47 additions & 0 deletions tests/Unit/BackgroundJob/ContextChat/SubmitContentJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use OCA\Mail\Db\MessageMapper;
use OCA\Mail\Events\MessageDeletedEvent;
use OCA\Mail\Events\NewMessagesSynchronized;
use OCA\Mail\Exception\ClientException;
use OCA\Mail\Model\IMAPMessage;
use OCA\Mail\Service\AccountService;
use OCA\Mail\Service\ContextChat\TaskService;
Expand Down Expand Up @@ -307,6 +308,52 @@ public function testRunWithContextChatWithEncryptedMessage(): void {
$this->submitContentJob->start($this->createMock(IJobList::class));
}

public function testRunWithContextChatSkipsMessageVanishedFromRemote(): void {
$this->contentManager->expects($this->once())
->method('isContextChatAvailable')
->willReturn(true);
$task = new Task();
$task->setLastMessageId(0);
$task->setMailboxId(1);
$task->setId(1);
$this->taskService->expects($this->once())->method('findNext')->willReturn($task);
$mailbox = new Mailbox();
$mailbox->setId(1);
$mailbox->setAccountId(5);
$this->mailboxMapper->expects($this->once())->method('findById')->willReturn($mailbox);
$this->time->expects($this->any())->method('getTime')
->willReturn(
// returned when Job#start asks
12 * 60 * 60,
12 * 60 * 60,
// returned when filtering messages
ContextChatProvider::CONTEXT_CHAT_MESSAGE_MAX_AGE,
// returned before processing messages
0,
// returned on first message
0,
0,
0,
0,
);
$this->messageMapper->expects($this->once())->method('findIdsAfter')
->with($mailbox, 0, 0, ContextChatProvider::CONTEXT_CHAT_IMPORT_MAX_ITEMS)->willReturn([1]);
$account = $this->createMock(Account::class);
$account->expects($this->any())->method('getUserId')->willReturn('user123');
$this->accountService->expects($this->once())->method('findById')->with()->willReturn($account);
$message = new Message();
$message->setId(1);
$message->setUid(1);
$this->messageMapper->expects($this->once())->method('findByIds')->willReturn([$message]);
$this->mailManager->expects($this->once())->method('getImapMessage')
->willThrowException(new ClientException('Message not found on remote server'));
$this->contentManager->expects($this->never())->method('submitContent');
$this->taskService->expects($this->once())->method('setLastMessage')->with($task->getMailboxId(), 1);

$this->submitContentJob->setLastRun(0);
$this->submitContentJob->start($this->createMock(IJobList::class));
}

public function testRunWithContextChatWithFindNextTaskException(): void {
$this->contentManager->expects($this->once())
->method('isContextChatAvailable')
Expand Down
Loading