Skip to content

Commit 1bfa02a

Browse files
committed
fixup! Add imip processing
1 parent f113610 commit 1bfa02a

4 files changed

Lines changed: 35 additions & 11 deletions

File tree

appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
- **🙈 We’re not reinventing the wheel!** Based on the great [Horde](https://horde.org) libraries.
1313
- **📬 Want to host your own mail server?** We do not have to reimplement this as you could set up [Mail-in-a-Box](https://mailinabox.email)!
1414
]]></description>
15-
<version>1.14.0-alpha.4</version>
15+
<version>1.14.0-alpha.5</version>
1616
<licence>agpl</licence>
1717
<author>Greta Doçi</author>
1818
<author homepage="https://github.com/nextcloud/groupware">Nextcloud Groupware Team</author>

lib/Db/MessageMapper.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,15 +1232,16 @@ public function resetInReplyTo(): int {
12321232
* @return Message[]
12331233
*/
12341234
public function findIMipMessages(): array {
1235+
$time = $this->timeFactory->getTime() - 60 * 60 * 24 * 14;
12351236
$qb = $this->db->getQueryBuilder();
12361237

12371238
$select = $qb->select('*')
12381239
->from($this->getTableName())
1239-
->andWhere(
1240+
->where(
12401241
$qb->expr()->eq('imip_message', $qb->createNamedParameter(true, IQueryBuilder::PARAM_BOOL), IQueryBuilder::PARAM_BOOL),
12411242
$qb->expr()->eq('imip_processed', $qb->createNamedParameter(false, IQueryBuilder::PARAM_BOOL), IQueryBuilder::PARAM_BOOL),
12421243
$qb->expr()->eq('imip_error', $qb->createNamedParameter(false, IQueryBuilder::PARAM_BOOL), IQueryBuilder::PARAM_BOOL),
1243-
$qb->expr()->gt('sent_at', ($this->timeFactory->getTime() - 60 * 60 * 24 * 14), $qb->createNamedParameter(false, IQueryBuilder::PARAM_INT)),
1244+
$qb->expr()->gt('sent_at', $qb->createNamedParameter($time, IQueryBuilder::PARAM_INT)),
12441245
);
12451246

12461247
return $this->findEntities($select);

lib/Service/IMipService.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function __construct(
6060
$this->logger = $logger;
6161
}
6262

63-
public function process() {
63+
public function process(): void {
6464
$messages = $this->messageMapper->findIMipMessages();
6565

6666
// Collect all mailboxes in memory
@@ -106,28 +106,28 @@ public function process() {
106106

107107

108108
try {
109-
$imapMessage = $this->mailManager->getImapMessage($account, $mailbox, $message->getUid());
109+
$imapMessage = $this->mailManager->getImapMessageForScheduleProcessing($account, $mailbox, $message->getUid());
110110
} catch (ServiceException $e) {
111111
$message->setImipError(true);
112112
$processedMessages[$account->getId()][] = $message;
113113
continue;
114114
}
115115

116-
if (empty($imapMessage->scheduling)) {
116+
if (empty($imapMessage->scheduling[0])) {
117117
// No scheduling info, maybe the DB is wrong
118118
$message->setImipError(true);
119119
$processedMessages[$account->getId()][] = $message;
120120
continue;
121121
}
122122

123-
$principalUri = '';
123+
$principalUri = 'principals/users/' . $account->getUserId();
124124
$sender = $imapMessage->getFrom()->first()->getEmail();
125125
$recipient = $account->getEmail();
126126
$processed = false;
127-
if ($imapMessage->scheduling['method'] === 'REPLY') {
128-
$processed = $this->calendarManager->handleIMipReply($principalUri, $sender, $recipient, $imapMessage->scheduling['content']);
127+
if ($imapMessage->scheduling[0]['method'] === 'REPLY') {
128+
$processed = $this->calendarManager->handleIMipReply($principalUri, $sender, $recipient, $imapMessage->scheduling[0]['contents']);
129129
} elseif ($imapMessage->scheduling['method'] === 'CANCEL') {
130-
$processed = $this->calendarManager->handleIMipCancel($principalUri, $sender, $recipient, $imapMessage->scheduling['content']);
130+
$processed = $this->calendarManager->handleIMipCancel($principalUri, $sender, $recipient, $imapMessage->scheduling[0]['contents']);
131131
}
132132
$message->setImipProcessed($processed);
133133
$message->setImipError(!$processed);
@@ -139,7 +139,7 @@ public function process() {
139139
continue;
140140
}
141141
try {
142-
$this->messageMapper->updateBulk($accounts[$accountId], false, $processedMessages[$accountId]);
142+
$this->messageMapper->updateBulk($accounts[$accountId], false, ...$processedMessages[$accountId]);
143143
} catch (\Throwable $e) {
144144
$this->logger->error('Could not update iMip messages for account ' . $accountId, ['exception' => $e]);
145145
}

lib/Service/MailManager.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,29 @@ public function getImapMessage(Account $account,
194194
}
195195
}
196196

197+
public function getImapMessageForScheduleProcessing(Account $account,
198+
Mailbox $mailbox,
199+
int $uid,
200+
bool $loadBody = false): IMAPMessage {
201+
$client = $this->imapClientFactory->getClient($account);
202+
try {
203+
return $this->imapMessageMapper->find(
204+
$client,
205+
$mailbox->getName(),
206+
$uid,
207+
true
208+
);
209+
} catch (Horde_Imap_Client_Exception|DoesNotExistException $e) {
210+
throw new ServiceException(
211+
'Could not load message',
212+
(int)$e->getCode(),
213+
$e
214+
);
215+
} finally {
216+
$client->logout();
217+
}
218+
}
219+
197220
public function getThread(Account $account, string $threadRootId): array {
198221
return $this->dbMessageMapper->findThread($account, $threadRootId);
199222
}

0 commit comments

Comments
 (0)