1: <?php
2: /**
3: * This code is licensed under AGPLv3 license or Afterlogic Software License
4: * if commercial version of the product was purchased.
5: * For full statements of the licenses see LICENSE-AFTERLOGIC and LICENSE-AGPL3 files.
6: */
7:
8: namespace Aurora\Modules\Mail;
9:
10: if (PHP_SAPI !== 'cli') {
11: exit("Use the console for running this script");
12: }
13:
14: require_once \dirname(__file__) . "/../../../system/autoload.php";
15: \Aurora\System\Api::Init();
16:
17: function log($message)
18: {
19: \Aurora\System\Api::Log($message, \Aurora\System\Enums\LogLevel::Full, 'scheduled-autoresponder-');
20: }
21:
22: if (Module::getInstance()->oModuleSettings->AllowScheduledAutoresponder) {
23: $accounts = Models\MailAccount::where('Properties->' . 'Mail::AutoresponderScheduled', true)
24: ->where('Properties->' . 'Mail::AutoresponderStart', '<', time())->get();
25:
26: $sieveManager = Module::getInstance()->getSieveManager();
27:
28: foreach ($accounts as $account) {
29: /** @var \Aurora\Modules\Mail\Models\MailAccount $account */
30: log('Process account: ' . $account->Id);
31: $end = $account->getExtendedProp('Mail::AutoresponderEnd');
32: $disableAutoResponder = ($end !== null && $end < time());
33: if ($disableAutoResponder) {
34: log('Disable scheduled autoresponder');
35: $account->setExtendedProp('Mail::AutoresponderScheduled', false);
36: $account->save();
37: }
38:
39: $autoResponder = $sieveManager->getAutoresponder($account);
40: if ($autoResponder) {
41: if ($disableAutoResponder) {
42: log('Disable autoresponder');
43: $sieveManager->setAutoresponder($account, $autoResponder['Subject'], $autoResponder['Message'], false);
44: } elseif (!$autoResponder['Enable']) {
45: log('Enable autoresponder');
46: $sieveManager->setAutoresponder($account, $autoResponder['Subject'], $autoResponder['Message'], true);
47: }
48: } else {
49: log('Autoresponder not found');
50: }
51: }
52: } else {
53: log('Scheduled autoresponder disabled');
54: }
55: