[Web][Dovecot] imapsync: update to 2.314, refresh OAuth tokens of running jobs, add source presets

This commit is contained in:
FreddleSpl0it committed 2026-10-22 18:27:49 +02:00
1 parent 474f1c688b
commit c145f858e2
15 files changed
+7060 -3406

No files matched your search

@@ -7,6 +7,7 @@ namespace Mailcow\Imapsync\Controller;
use Mailcow\Core\AccessDenied;
use Mailcow\Core\ApiResponse;
use Mailcow\Core\UserError;
use Mailcow\Imapsync\Model\Source;
use Mailcow\Imapsync\Service\JobService;
use Mailcow\Imapsync\Service\SourceService;
use PDOException;
@@ -37,8 +38,11 @@ class ImapsyncApiController
/** POST add/syncjob_source */
public function addSource(array $attr): bool
{
return $this->handle('add', 'source', $attr,
fn(array $log): bool => $this->response->success(['imapsync_source_added', $this->sources->create($attr)->name], $log));
return $this->handle('add', 'source', $attr, function (array $log) use ($attr): bool {
$source = $this->sources->create($attr);
$this->tokenFailure($source, $log);
return $this->response->success(['imapsync_source_added', $source->name], $log);
});
}
/** POST edit/syncjob: one message per id; `id` in $attr wins over $items (array_merge like before) */
@@ -70,8 +74,11 @@ class ImapsyncApiController
$data = array_merge(['id' => $items], $attr);
return $this->handle('edit', 'source', $data, function (array $log) use ($data): bool {
$this->sources->requireEditor();
return $this->batch(array_filter((array)($data['id'] ?? []), 'is_numeric'), $log,
fn(int $id): array => ['imapsync_source_modified', $this->sources->update($id, $data)->name]);
return $this->batch(array_filter((array)($data['id'] ?? []), 'is_numeric'), $log, function (int $id) use ($data, $log): array {
$source = $this->sources->update($id, $data);
$this->tokenFailure($source, $log);
return ['imapsync_source_modified', $source->name];
});
});
}
@@ -201,6 +208,14 @@ class ImapsyncApiController
$this->response->flush();
}
/** The token fetched when saving a client_credentials source failed: the source is saved, report the error */
private function tokenFailure(Source $source, array $log): void
{
if ($source->usesClientCredentials() && $source->active === 1 && $source->lastRefreshError !== null) {
$this->response->danger(['imapsync_source_token_refresh_failed', $source->name . ' (' . $source->lastRefreshError . ')'], $log);
}
}
/**
* Runs one write call: $work gets the log entry and returns the result for process_*_return().
* A UserError becomes a danger message, a database error stops the call with one `mysql_error` message.