CustomParams::allowlist($IMAPSYNC_OPTIONS, $IMAPSYNC_OPTIONS_DEFAULT), * 'hostname' => (string)getenv('MAILCOW_HOSTNAME'), * ]); * process_add_return($imapsync->api->addJob($attr)); * * Procedural legacy code (json_api.php, pages, functions.*.inc.php) uses fromGlobals() instead. */ class ImapsyncModule { /** Request keys whose values never reach a log */ private const SECRET_KEYS = ['password1', 'password2', 'oauth_client_secret', 'oauth_extra_params']; public function __construct( public readonly SourceService $sources, public readonly JobService $jobs, public readonly OAuthService $oauth, public readonly ImapsyncApiController $api ) { } /** * @param array $config 'allowlist' => effective custom param allowlist (CustomParams::allowlist()), * 'hostname' => MAILCOW_HOSTNAME (OAuth redirect URI); both optional */ public static function create(PDO $pdo, Context $context, array $config = []): self { $sourceRepository = new SourceRepository($pdo); $tokenRepository = new TokenRepository($pdo); $oauth = new OAuthService($sourceRepository, $tokenRepository, new OAuthClient(), (string)($config['hostname'] ?? '')); $sources = new SourceService($sourceRepository, $tokenRepository, $oauth, $context); $jobs = new JobService(new JobRepository($pdo), $sources, $tokenRepository, new SettingsRepository($pdo), $context, (array)($config['allowlist'] ?? [])); return new self($sources, $jobs, $oauth, new ImapsyncApiController($sources, $jobs, new ApiResponse(self::SECRET_KEYS))); } /** * Legacy entry point for procedural callers: the one place that reads the globals ($pdo, $_SESSION, * $IMAPSYNC_OPTIONS / $IMAPSYNC_OPTIONS_DEFAULT from vars(.local).inc.php, MAILCOW_HOSTNAME) * and passes them to create(). $context overrides the session caller (e.g. Context::system()). */ public static function fromGlobals(?Context $context = null): self { return self::create($GLOBALS['pdo'], $context ?? Context::fromSession($_SESSION ?? []), [ 'allowlist' => CustomParams::allowlist((array)($GLOBALS['IMAPSYNC_OPTIONS'] ?? []), (array)($GLOBALS['IMAPSYNC_OPTIONS_DEFAULT'] ?? [])), 'hostname' => (string)getenv('MAILCOW_HOSTNAME'), ]); } }