| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | namespace Aurora\Modules\Mail; |
| 9: | |
| 10: | use Aurora\Api; |
| 11: | use Aurora\Modules\Core\Models\Tenant; |
| 12: | use Aurora\Modules\Core\Models\User; |
| 13: | use Aurora\Modules\Mail\Classes\Message; |
| 14: | use Aurora\Modules\Mail\Enums\SearchInFoldersType; |
| 15: | use Aurora\Modules\Mail\Models\Identity; |
| 16: | use Aurora\Modules\Mail\Models\TrustedSender; |
| 17: | use Aurora\System\Application; |
| 18: | use Aurora\System\Enums\LogLevel; |
| 19: | use Aurora\System\Exceptions\InvalidArgumentException; |
| 20: | use MailSo\Base\HtmlUtils; |
| 21: | use PHPMailer\DKIMValidator\Validator as DKIMValidator; |
| 22: | use PHPMailer\DKIMValidator\DKIMException; |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | class Module extends \Aurora\System\Module\AbstractModule |
| 34: | { |
| 35: | |
| 36: | |
| 37: | |
| 38: | protected $oMailManager = null; |
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: | protected $oAccountsManager = null; |
| 44: | |
| 45: | |
| 46: | |
| 47: | |
| 48: | protected $oServersManager = null; |
| 49: | |
| 50: | |
| 51: | |
| 52: | |
| 53: | protected $oIdentitiesManager = null; |
| 54: | |
| 55: | |
| 56: | |
| 57: | |
| 58: | protected $oSieveManager = null; |
| 59: | |
| 60: | |
| 61: | |
| 62: | |
| 63: | protected $oFilecacheManager = null; |
| 64: | |
| 65: | |
| 66: | |
| 67: | |
| 68: | |
| 69: | |
| 70: | public function init() |
| 71: | { |
| 72: | $this->aErrors = [ |
| 73: | Enums\ErrorCodes::CannotConnectToMailServer => $this->i18N('ERROR_CONNECT_TO_MAIL_SERVER'), |
| 74: | Enums\ErrorCodes::CannotLoginCredentialsIncorrect => $this->i18N('ERROR_CREDENTIALS_INCORRECT'), |
| 75: | Enums\ErrorCodes::FolderAlreadyExists => $this->i18N('ERROR_FOLDER_EXISTS'), |
| 76: | Enums\ErrorCodes::FolderNameContainsDelimiter => $this->i18N('ERROR_FOLDER_NAME_CONTAINS_DELIMITER'), |
| 77: | Enums\ErrorCodes::CannotRenameNonExistenFolder => $this->i18N('ERROR_RENAME_NONEXISTEN_FOLDER'), |
| 78: | Enums\ErrorCodes::CannotGetMessage => $this->i18N('ERROR_GET_MESSAGE'), |
| 79: | Enums\ErrorCodes::CannotMoveMessage => $this->i18N('ERROR_MOVE_MESSAGE'), |
| 80: | Enums\ErrorCodes::CannotSendMessageInvalidRecipients => $this->i18N('ERROR_SEND_MESSAGE_INVALID_RECIPIENTS'), |
| 81: | Enums\ErrorCodes::CannotSendMessageToRecipients => $this->i18N('ERROR_SEND_MESSAGE_TO_RECIPIENTS'), |
| 82: | Enums\ErrorCodes::CannotSendMessageToExternalRecipients => $this->i18N('ERROR_SEND_MESSAGE_TO_EXTERNAL_RECIPIENTS'), |
| 83: | Enums\ErrorCodes::CannotSaveMessageToSentItems => $this->i18N('ERROR_SEND_MESSAGE_NOT_SAVED'), |
| 84: | Enums\ErrorCodes::CannotUploadMessage => $this->i18N('ERROR_UPLOAD_MESSAGE'), |
| 85: | Enums\ErrorCodes::CannotUploadMessageFileNotEml => $this->i18N('ERROR_UPLOAD_MESSAGE_FILE_NOT_EML'), |
| 86: | Enums\ErrorCodes::DomainIsNotAllowedForLoggingIn => $this->i18N('DOMAIN_IS_NOT_ALLOWED_FOR_LOGGING_IN'), |
| 87: | Enums\ErrorCodes::TenantQuotaExceeded => $this->i18N('ERROR_TENANT_QUOTA_EXCEEDED'), |
| 88: | ]; |
| 89: | |
| 90: | $this->AddEntries( |
| 91: | array( |
| 92: | 'message-newtab' => 'EntryMessageNewtab', |
| 93: | 'mail-attachment' => 'EntryDownloadAttachment', |
| 94: | 'mail-attachments-cookieless' => 'EntryDownloadAttachmentCookieless' |
| 95: | ) |
| 96: | ); |
| 97: | |
| 98: | $this->subscribeEvent('Login', array($this, 'onLogin')); |
| 99: | $this->subscribeEvent('Core::DeleteUser::before', array($this, 'onBeforeDeleteUser')); |
| 100: | $this->subscribeEvent('Core::GetAccounts', array($this, 'onGetAccounts')); |
| 101: | $this->subscribeEvent('Autodiscover::GetAutodiscover::after', array($this, 'onAfterGetAutodiscover')); |
| 102: | $this->subscribeEvent('Core::DeleteTenant::after', array($this, 'onAfterDeleteTenant')); |
| 103: | $this->subscribeEvent('Core::DeleteUser::after', array($this, 'onAfterDeleteUser')); |
| 104: | $this->subscribeEvent('Core::GetDigestHash', array($this, 'onGetDigestHash')); |
| 105: | $this->subscribeEvent('Core::GetAccountUsedToAuthorize', array($this, 'onGetAccountUsedToAuthorize')); |
| 106: | $this->subscribeEvent('System::RunEntry::before', array($this, 'onBeforeRunEntry')); |
| 107: | $this->subscribeEvent('System::CastExtendedProp', array($this, 'onCastExtendedProp')); |
| 108: | $this->subscribeEvent('ChangePassword::after', array($this, 'onAfterChangePassword')); |
| 109: | |
| 110: | $this->aDeniedMethodsByWebApi = [ |
| 111: | 'BuildMessage', |
| 112: | 'checkAccountAccess' |
| 113: | ]; |
| 114: | |
| 115: | \MailSo\Config::$PreferStartTlsIfAutoDetect = !!$this->oModuleSettings->PreferStarttls; |
| 116: | } |
| 117: | |
| 118: | |
| 119: | |
| 120: | |
| 121: | public static function getInstance() |
| 122: | { |
| 123: | return parent::getInstance(); |
| 124: | } |
| 125: | |
| 126: | |
| 127: | |
| 128: | |
| 129: | public static function Decorator() |
| 130: | { |
| 131: | return parent::Decorator(); |
| 132: | } |
| 133: | |
| 134: | |
| 135: | |
| 136: | |
| 137: | public function getModuleSettings() |
| 138: | { |
| 139: | return $this->oModuleSettings; |
| 140: | } |
| 141: | |
| 142: | |
| 143: | |
| 144: | |
| 145: | |
| 146: | public function getAccountsManager() |
| 147: | { |
| 148: | if ($this->oAccountsManager === null) { |
| 149: | $this->oAccountsManager = new Managers\Accounts\Manager($this); |
| 150: | } |
| 151: | |
| 152: | return $this->oAccountsManager; |
| 153: | } |
| 154: | |
| 155: | public function setAccountsManager($oManager) |
| 156: | { |
| 157: | $this->oAccountsManager = $oManager; |
| 158: | } |
| 159: | |
| 160: | |
| 161: | |
| 162: | |
| 163: | |
| 164: | public function getServersManager() |
| 165: | { |
| 166: | if ($this->oServersManager === null) { |
| 167: | $this->oServersManager = new Managers\Servers\Manager($this); |
| 168: | } |
| 169: | |
| 170: | return $this->oServersManager; |
| 171: | } |
| 172: | |
| 173: | |
| 174: | |
| 175: | |
| 176: | |
| 177: | public function getIdentitiesManager() |
| 178: | { |
| 179: | if ($this->oIdentitiesManager === null) { |
| 180: | $this->oIdentitiesManager = new Managers\Identities\Manager($this); |
| 181: | } |
| 182: | |
| 183: | return $this->oIdentitiesManager; |
| 184: | } |
| 185: | |
| 186: | |
| 187: | |
| 188: | |
| 189: | |
| 190: | public function getMailManager() |
| 191: | { |
| 192: | if ($this->oMailManager === null) { |
| 193: | $this->oMailManager = new Managers\Main\Manager($this); |
| 194: | } |
| 195: | |
| 196: | return $this->oMailManager; |
| 197: | } |
| 198: | |
| 199: | public function setMailManager($oManager) |
| 200: | { |
| 201: | $this->oMailManager = $oManager; |
| 202: | } |
| 203: | |
| 204: | |
| 205: | |
| 206: | |
| 207: | |
| 208: | public function getSieveManager() |
| 209: | { |
| 210: | if ($this->oSieveManager === null) { |
| 211: | $this->oSieveManager = new Managers\Sieve\Manager($this); |
| 212: | } |
| 213: | |
| 214: | return $this->oSieveManager; |
| 215: | } |
| 216: | |
| 217: | |
| 218: | |
| 219: | |
| 220: | |
| 221: | public function getFilecacheManager() |
| 222: | { |
| 223: | if ($this->oFilecacheManager === null) { |
| 224: | $this->oFilecacheManager = new \Aurora\System\Managers\Filecache(); |
| 225: | } |
| 226: | |
| 227: | return $this->oFilecacheManager; |
| 228: | } |
| 229: | |
| 230: | |
| 231: | |
| 232: | |
| 233: | |
| 234: | |
| 235: | public static function checkAccountAccess($oAccount) |
| 236: | { |
| 237: | if (\Aurora\System\Api::accessCheckIsSkipped()) { |
| 238: | |
| 239: | return; |
| 240: | } |
| 241: | |
| 242: | $bAccessDenied = true; |
| 243: | $oAuthenticatedUser = \Aurora\System\Api::getAuthenticatedUser(); |
| 244: | $iUserRole = $oAuthenticatedUser instanceof User ? $oAuthenticatedUser->Role : \Aurora\System\Enums\UserRole::Anonymous; |
| 245: | switch ($iUserRole) { |
| 246: | case (\Aurora\System\Enums\UserRole::SuperAdmin): |
| 247: | |
| 248: | $bAccessDenied = false; |
| 249: | break; |
| 250: | case (\Aurora\System\Enums\UserRole::TenantAdmin): |
| 251: | |
| 252: | $oUser = null; |
| 253: | if ($oAccount !== null) { |
| 254: | $oUser = \Aurora\Modules\Core\Module::getInstance()->GetUser($oAccount->IdUser); |
| 255: | } |
| 256: | if ($oUser instanceof User) { |
| 257: | if ($oAuthenticatedUser->IdTenant === $oUser->IdTenant) { |
| 258: | $bAccessDenied = false; |
| 259: | } |
| 260: | } |
| 261: | break; |
| 262: | case (\Aurora\System\Enums\UserRole::NormalUser): |
| 263: | |
| 264: | if ($oAccount !== null) { |
| 265: | if ($oAccount instanceof Models\MailAccount && $oAccount->IdUser === $oAuthenticatedUser->Id) { |
| 266: | $bAccessDenied = false; |
| 267: | } |
| 268: | } |
| 269: | break; |
| 270: | case (\Aurora\System\Enums\UserRole::Customer): |
| 271: | case (\Aurora\System\Enums\UserRole::Anonymous): |
| 272: | |
| 273: | break; |
| 274: | } |
| 275: | if ($bAccessDenied) { |
| 276: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::AccessDenied); |
| 277: | } |
| 278: | } |
| 279: | |
| 280: | |
| 281: | |
| 282: | |
| 283: | |
| 284: | |
| 285: | |
| 286: | |
| 287: | |
| 288: | |
| 289: | |
| 290: | |
| 291: | |
| 292: | |
| 293: | |
| 294: | |
| 295: | |
| 296: | |
| 297: | |
| 298: | |
| 299: | |
| 300: | |
| 301: | |
| 302: | |
| 303: | |
| 304: | |
| 305: | |
| 306: | |
| 307: | |
| 308: | |
| 309: | |
| 310: | |
| 311: | |
| 312: | |
| 313: | |
| 314: | |
| 315: | |
| 316: | |
| 317: | |
| 318: | |
| 319: | |
| 320: | |
| 321: | |
| 322: | |
| 323: | |
| 324: | |
| 325: | |
| 326: | |
| 327: | |
| 328: | |
| 329: | |
| 330: | |
| 331: | |
| 332: | |
| 333: | |
| 334: | |
| 335: | |
| 336: | |
| 337: | |
| 338: | |
| 339: | |
| 340: | |
| 341: | |
| 342: | |
| 343: | |
| 344: | public function GetSettings() |
| 345: | { |
| 346: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous); |
| 347: | |
| 348: | $aSettings = array( |
| 349: | 'Accounts' => array(), |
| 350: | 'AllowAddAccounts' => $this->oModuleSettings->AllowAddAccounts, |
| 351: | 'AllowAutosaveInDrafts' => (bool)$this->oModuleSettings->AllowAutosaveInDrafts, |
| 352: | 'AllowChangeMailQuotaOnMailServer' => $this->oModuleSettings->AllowChangeMailQuotaOnMailServer, |
| 353: | 'AllowDefaultAccountForUser' => $this->oModuleSettings->AllowDefaultAccountForUser, |
| 354: | 'AllowIdentities' => $this->oModuleSettings->AllowIdentities, |
| 355: | 'OnlyUserEmailsInIdentities' => $this->oModuleSettings->OnlyUserEmailsInIdentities, |
| 356: | 'AllowInsertImage' => $this->oModuleSettings->AllowInsertImage, |
| 357: | 'AutoSaveIntervalSeconds' => $this->oModuleSettings->AutoSaveIntervalSeconds, |
| 358: | 'AllowTemplateFolders' => $this->oModuleSettings->AllowTemplateFolders, |
| 359: | 'AllowInsertTemplateOnCompose' => $this->oModuleSettings->AllowInsertTemplateOnCompose, |
| 360: | 'MaxTemplatesCountOnCompose' => $this->oModuleSettings->MaxTemplatesCountOnCompose, |
| 361: | 'AllowAlwaysRefreshFolders' => $this->oModuleSettings->AllowAlwaysRefreshFolders, |
| 362: | 'AutocreateMailAccountOnNewUserFirstLogin' => $this->oModuleSettings->AutocreateMailAccountOnNewUserFirstLogin, |
| 363: | 'IgnoreImapSubscription' => $this->oModuleSettings->IgnoreImapSubscription, |
| 364: | 'ImageUploadSizeLimit' => $this->oModuleSettings->ImageUploadSizeLimit, |
| 365: | 'AllowUnifiedInbox' => $this->oModuleSettings->AllowUnifiedInbox, |
| 366: | 'SmtpAuthType' => (new \Aurora\Modules\Mail\Enums\SmtpAuthType())->getMap(), |
| 367: | 'MessagesSortBy' => $this->oModuleSettings->MessagesSortBy, |
| 368: | 'AllowScheduledAutoresponder' => $this->oModuleSettings->AllowScheduledAutoresponder, |
| 369: | ); |
| 370: | |
| 371: | $oUser = \Aurora\System\Api::getAuthenticatedUser(); |
| 372: | if ($oUser && $oUser->isNormalOrTenant()) { |
| 373: | $aAcc = $this->GetAccounts($oUser->Id); |
| 374: | $aResponseAcc = []; |
| 375: | foreach ($aAcc as $oAccount) { |
| 376: | $aResponseAcc[] = $oAccount->toResponseArray(); |
| 377: | } |
| 378: | $aSettings['Accounts'] = $aResponseAcc; |
| 379: | |
| 380: | if (null !== $oUser->getExtendedProp(self::GetName() . '::AllowAutosaveInDrafts')) { |
| 381: | $aSettings['AllowAutosaveInDrafts'] = $oUser->getExtendedProp(self::GetName() . '::AllowAutosaveInDrafts'); |
| 382: | } |
| 383: | } |
| 384: | $aArgs = []; |
| 385: | $this->broadcastEvent('GetSettings::after', $aArgs, $aSettings); |
| 386: | return $aSettings; |
| 387: | } |
| 388: | |
| 389: | |
| 390: | |
| 391: | |
| 392: | |
| 393: | |
| 394: | |
| 395: | |
| 396: | |
| 397: | |
| 398: | |
| 399: | |
| 400: | |
| 401: | |
| 402: | |
| 403: | |
| 404: | |
| 405: | |
| 406: | |
| 407: | |
| 408: | |
| 409: | |
| 410: | |
| 411: | |
| 412: | |
| 413: | |
| 414: | |
| 415: | |
| 416: | |
| 417: | |
| 418: | |
| 419: | |
| 420: | |
| 421: | |
| 422: | |
| 423: | |
| 424: | |
| 425: | |
| 426: | |
| 427: | |
| 428: | |
| 429: | |
| 430: | |
| 431: | |
| 432: | |
| 433: | |
| 434: | |
| 435: | |
| 436: | |
| 437: | |
| 438: | |
| 439: | |
| 440: | |
| 441: | |
| 442: | |
| 443: | |
| 444: | |
| 445: | public function UpdateSettings($AutocreateMailAccountOnNewUserFirstLogin = null, $AllowAddAccounts = null, $AllowAutosaveInDrafts = null) |
| 446: | { |
| 447: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 448: | |
| 449: | $oUser = \Aurora\System\Api::getAuthenticatedUser(); |
| 450: | if ($oUser) { |
| 451: | if ($oUser->isNormalOrTenant()) { |
| 452: | if ($AllowAutosaveInDrafts !== null) { |
| 453: | $oUser->setExtendedProp(self::GetName() . '::AllowAutosaveInDrafts', $AllowAutosaveInDrafts); |
| 454: | } |
| 455: | $oCoreDecorator = \Aurora\Modules\Core\Module::Decorator(); |
| 456: | return $oCoreDecorator->UpdateUserObject($oUser); |
| 457: | } |
| 458: | if ($oUser->Role === \Aurora\System\Enums\UserRole::SuperAdmin) { |
| 459: | if ($AutocreateMailAccountOnNewUserFirstLogin !== null) { |
| 460: | $this->setConfig('AutocreateMailAccountOnNewUserFirstLogin', $AutocreateMailAccountOnNewUserFirstLogin); |
| 461: | } |
| 462: | if ($AllowAddAccounts !== null) { |
| 463: | $this->setConfig('AllowAddAccounts', $AllowAddAccounts); |
| 464: | } |
| 465: | return $this->saveModuleConfig(); |
| 466: | } |
| 467: | } |
| 468: | |
| 469: | return false; |
| 470: | } |
| 471: | |
| 472: | public function GetEntitySpaceLimits($Type, $UserId = null, $TenantId = null) |
| 473: | { |
| 474: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::TenantAdmin); |
| 475: | $oAuthenticatedUser = \Aurora\System\Api::getAuthenticatedUser(); |
| 476: | |
| 477: | if ($Type === 'User' && is_int($UserId) && $UserId > 0) { |
| 478: | $oUser = \Aurora\Modules\Core\Module::Decorator()->GetUserWithoutRoleCheck($UserId); |
| 479: | if ($oAuthenticatedUser->Role === \Aurora\System\Enums\UserRole::SuperAdmin || |
| 480: | $oAuthenticatedUser->Role === \Aurora\System\Enums\UserRole::TenantAdmin && $oAuthenticatedUser->IdTenant === $oUser->IdTenant) { |
| 481: | $oTenant = \Aurora\System\Api::getTenantById($oUser->IdTenant); |
| 482: | return [ |
| 483: | 'UserSpaceLimitMb' => $oUser->getExtendedProp(self::GetName() . '::UserSpaceLimitMb'), |
| 484: | 'AllowChangeUserSpaceLimit' => $oTenant->getExtendedProp(self::GetName() . '::AllowChangeUserSpaceLimit'), |
| 485: | ]; |
| 486: | } |
| 487: | } |
| 488: | |
| 489: | if ($Type === 'Tenant' && is_int($TenantId) && $TenantId > 0) { |
| 490: | $oTenant = \Aurora\System\Api::getTenantById($TenantId); |
| 491: | if ($oTenant instanceof Tenant && $oAuthenticatedUser instanceof User && |
| 492: | ($oAuthenticatedUser->Role === \Aurora\System\Enums\UserRole::SuperAdmin || |
| 493: | $oAuthenticatedUser->Role === \Aurora\System\Enums\UserRole::TenantAdmin && $oAuthenticatedUser->IdTenant === $TenantId)) { |
| 494: | return [ |
| 495: | 'TenantSpaceLimitMb' => $oTenant->getExtendedProp(self::GetName() . '::TenantSpaceLimitMb'), |
| 496: | 'UserSpaceLimitMb' => $oTenant->getExtendedProp(self::GetName() . '::UserSpaceLimitMb'), |
| 497: | 'AllowChangeUserSpaceLimit' => $oTenant->getExtendedProp(self::GetName() . '::AllowChangeUserSpaceLimit'), |
| 498: | 'AllocatedSpaceMb' => $oTenant->getExtendedProp(self::GetName() . '::AllocatedSpaceMb'), |
| 499: | ]; |
| 500: | } |
| 501: | } |
| 502: | |
| 503: | return []; |
| 504: | } |
| 505: | |
| 506: | protected function updateAllocatedTenantSpace($iTenantId, $iNewUserQuota, $iPrevUserQuota) |
| 507: | { |
| 508: | $oTenant = \Aurora\System\Api::getTenantById($iTenantId); |
| 509: | if ($oTenant) { |
| 510: | $iAllocatedSpaceMb = $oTenant->getExtendedProp(self::GetName() . '::AllocatedSpaceMb'); |
| 511: | $iAllocatedSpaceMb += $iNewUserQuota - $iPrevUserQuota; |
| 512: | if ($iAllocatedSpaceMb < 0) { |
| 513: | $iAllocatedSpaceMb = 0; |
| 514: | } |
| 515: | $oTenant->setExtendedProp(self::GetName() . '::AllocatedSpaceMb', $iAllocatedSpaceMb); |
| 516: | \Aurora\Modules\Core\Module::Decorator()->getTenantsManager()->updateTenant($oTenant); |
| 517: | } |
| 518: | } |
| 519: | |
| 520: | public function UpdateEntitySpaceLimits($Type, $UserId, $TenantId, $TenantSpaceLimitMb, $UserSpaceLimitMb = null) |
| 521: | { |
| 522: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::TenantAdmin); |
| 523: | $oAuthenticatedUser = \Aurora\System\Api::getAuthenticatedUser(); |
| 524: | |
| 525: | if ($oAuthenticatedUser instanceof User && $Type === 'User' && is_int($UserId) && $UserId > 0) { |
| 526: | $oUser = \Aurora\Modules\Core\Module::Decorator()->GetUserWithoutRoleCheck($UserId); |
| 527: | if ($oUser instanceof User |
| 528: | && ($oAuthenticatedUser->Role === \Aurora\System\Enums\UserRole::SuperAdmin |
| 529: | || $oAuthenticatedUser->Role === \Aurora\System\Enums\UserRole::TenantAdmin && $oAuthenticatedUser->IdTenant === $oUser->IdTenant)) { |
| 530: | $aPrevUserQuota = self::Decorator()->GetEntitySpaceLimits('User', $UserId, $oUser->IdTenant); |
| 531: | $aTenantQuota = self::Decorator()->GetEntitySpaceLimits('Tenant', $UserId, $oUser->IdTenant); |
| 532: | $mResult = false; |
| 533: | if (is_array($aTenantQuota) && isset($aTenantQuota['AllocatedSpaceMb']) && is_array($aPrevUserQuota) && isset($aPrevUserQuota['UserSpaceLimitMb'])) { |
| 534: | $iNewAllocatedSpaceMb = $aTenantQuota['AllocatedSpaceMb'] - $aPrevUserQuota['UserSpaceLimitMb'] + $UserSpaceLimitMb; |
| 535: | if ($aTenantQuota['TenantSpaceLimitMb'] > 0 && $aTenantQuota['TenantSpaceLimitMb'] < $iNewAllocatedSpaceMb) { |
| 536: | throw new \Aurora\Modules\Mail\Exceptions\Exception(Enums\ErrorCodes::TenantQuotaExceeded); |
| 537: | } |
| 538: | $aArgs = [ |
| 539: | 'TenantId' => $TenantId, |
| 540: | 'Email' => $oUser->PublicId, |
| 541: | 'QuotaMb' => $UserSpaceLimitMb |
| 542: | ]; |
| 543: | $this->broadcastEvent( |
| 544: | 'UpdateQuota', |
| 545: | $aArgs, |
| 546: | $mResult |
| 547: | ); |
| 548: | } |
| 549: | if ($mResult !== false) { |
| 550: | $this->updateAllocatedTenantSpace($TenantId, $UserSpaceLimitMb, $aPrevUserQuota['UserSpaceLimitMb']); |
| 551: | $oUser->setExtendedProp(self::GetName() . '::UserSpaceLimitMb', $UserSpaceLimitMb); |
| 552: | $oUser->save(); |
| 553: | } |
| 554: | return $mResult; |
| 555: | } |
| 556: | } |
| 557: | |
| 558: | if ($Type === 'Tenant' && is_int($TenantId) && $TenantId > 0) { |
| 559: | $oTenant = \Aurora\Modules\Core\Module::Decorator()->GetTenantWithoutRoleCheck($TenantId); |
| 560: | if ($oTenant && ($oAuthenticatedUser->Role === \Aurora\System\Enums\UserRole::SuperAdmin || |
| 561: | $oAuthenticatedUser->Role === \Aurora\System\Enums\UserRole::TenantAdmin && $oAuthenticatedUser->IdTenant === $TenantId)) { |
| 562: | $oTenant->setExtendedProp(self::GetName() . '::TenantSpaceLimitMb', $TenantSpaceLimitMb); |
| 563: | if (is_int($UserSpaceLimitMb)) { |
| 564: | $oTenant->setExtendedProp(self::GetName() . '::UserSpaceLimitMb', $UserSpaceLimitMb); |
| 565: | } |
| 566: | return $oTenant->save(); |
| 567: | } |
| 568: | } |
| 569: | |
| 570: | return false; |
| 571: | } |
| 572: | |
| 573: | |
| 574: | |
| 575: | |
| 576: | |
| 577: | |
| 578: | |
| 579: | |
| 580: | |
| 581: | |
| 582: | |
| 583: | |
| 584: | |
| 585: | |
| 586: | |
| 587: | |
| 588: | |
| 589: | |
| 590: | |
| 591: | |
| 592: | |
| 593: | |
| 594: | |
| 595: | |
| 596: | |
| 597: | |
| 598: | |
| 599: | |
| 600: | |
| 601: | |
| 602: | |
| 603: | |
| 604: | |
| 605: | |
| 606: | |
| 607: | |
| 608: | |
| 609: | |
| 610: | |
| 611: | |
| 612: | |
| 613: | |
| 614: | |
| 615: | |
| 616: | |
| 617: | |
| 618: | |
| 619: | |
| 620: | |
| 621: | |
| 622: | |
| 623: | |
| 624: | |
| 625: | |
| 626: | |
| 627: | |
| 628: | |
| 629: | |
| 630: | public function GetAccounts($UserId) |
| 631: | { |
| 632: | $mResult = false; |
| 633: | |
| 634: | $oAuthenticatedUser = \Aurora\System\Api::getAuthenticatedUser(); |
| 635: | if ($oAuthenticatedUser && $oAuthenticatedUser->Id === $UserId) { |
| 636: | |
| 637: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 638: | } else { |
| 639: | |
| 640: | |
| 641: | |
| 642: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::SuperAdmin); |
| 643: | } |
| 644: | |
| 645: | $aAccounts = $this->getAccountsManager()->getUserAccounts($UserId); |
| 646: | |
| 647: | $mResult = []; |
| 648: | foreach ($aAccounts as $oAccount) { |
| 649: | if ($oAuthenticatedUser && $oAccount->IncomingLogin === $oAuthenticatedUser->PublicId) { |
| 650: | array_unshift($mResult, $oAccount); |
| 651: | } else { |
| 652: | $mResult[] = $oAccount; |
| 653: | } |
| 654: | } |
| 655: | |
| 656: | |
| 657: | return $mResult; |
| 658: | } |
| 659: | |
| 660: | |
| 661: | |
| 662: | |
| 663: | |
| 664: | |
| 665: | |
| 666: | |
| 667: | |
| 668: | |
| 669: | |
| 670: | |
| 671: | |
| 672: | |
| 673: | |
| 674: | |
| 675: | |
| 676: | |
| 677: | |
| 678: | |
| 679: | |
| 680: | |
| 681: | |
| 682: | |
| 683: | |
| 684: | |
| 685: | |
| 686: | |
| 687: | |
| 688: | |
| 689: | |
| 690: | |
| 691: | |
| 692: | |
| 693: | |
| 694: | |
| 695: | |
| 696: | |
| 697: | |
| 698: | |
| 699: | |
| 700: | |
| 701: | |
| 702: | |
| 703: | |
| 704: | |
| 705: | |
| 706: | |
| 707: | |
| 708: | |
| 709: | |
| 710: | |
| 711: | |
| 712: | |
| 713: | |
| 714: | |
| 715: | |
| 716: | |
| 717: | |
| 718: | |
| 719: | |
| 720: | |
| 721: | |
| 722: | |
| 723: | |
| 724: | |
| 725: | |
| 726: | |
| 727: | |
| 728: | |
| 729: | public function GetAccount($AccountId) |
| 730: | { |
| 731: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 732: | |
| 733: | $oAccount = $this->getAccountsManager()->getAccountById($AccountId); |
| 734: | |
| 735: | self::checkAccountAccess($oAccount); |
| 736: | |
| 737: | return $oAccount; |
| 738: | } |
| 739: | |
| 740: | public function GetAccountByEmail($Email, $UserId = 0) |
| 741: | { |
| 742: | $oAuthenticatedUser = \Aurora\System\Api::getAuthenticatedUser(); |
| 743: | $oUser = $UserId !== 0 ? \Aurora\Modules\Core\Module::Decorator()->GetUserWithoutRoleCheck($UserId) : null; |
| 744: | |
| 745: | |
| 746: | if ($oAuthenticatedUser instanceof User && $oUser instanceof User) { |
| 747: | if ($oUser->Id === $oAuthenticatedUser->Id) { |
| 748: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 749: | } elseif ($oAuthenticatedUser->Role === \Aurora\System\Enums\UserRole::TenantAdmin && $oUser->IdTenant === $oAuthenticatedUser->IdTenant) { |
| 750: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::TenantAdmin); |
| 751: | } |
| 752: | } else { |
| 753: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::SuperAdmin); |
| 754: | } |
| 755: | |
| 756: | $mResult = false; |
| 757: | $oAccount = $this->getAccountsManager()->getAccountByEmail($Email, $UserId); |
| 758: | if ($oAccount instanceof \Aurora\Modules\Mail\Models\MailAccount && $UserId === $oAccount->IdUser) { |
| 759: | $mResult = $oAccount; |
| 760: | } |
| 761: | |
| 762: | return $mResult; |
| 763: | } |
| 764: | |
| 765: | |
| 766: | |
| 767: | |
| 768: | |
| 769: | |
| 770: | |
| 771: | |
| 772: | |
| 773: | |
| 774: | |
| 775: | |
| 776: | |
| 777: | |
| 778: | |
| 779: | |
| 780: | |
| 781: | |
| 782: | |
| 783: | |
| 784: | |
| 785: | |
| 786: | |
| 787: | |
| 788: | |
| 789: | |
| 790: | |
| 791: | |
| 792: | |
| 793: | |
| 794: | |
| 795: | |
| 796: | |
| 797: | |
| 798: | |
| 799: | |
| 800: | |
| 801: | |
| 802: | |
| 803: | |
| 804: | |
| 805: | |
| 806: | |
| 807: | |
| 808: | |
| 809: | |
| 810: | |
| 811: | |
| 812: | |
| 813: | |
| 814: | |
| 815: | |
| 816: | |
| 817: | |
| 818: | |
| 819: | |
| 820: | |
| 821: | |
| 822: | |
| 823: | |
| 824: | |
| 825: | |
| 826: | |
| 827: | |
| 828: | |
| 829: | |
| 830: | |
| 831: | |
| 832: | |
| 833: | |
| 834: | |
| 835: | |
| 836: | |
| 837: | |
| 838: | |
| 839: | |
| 840: | |
| 841: | |
| 842: | |
| 843: | public function CreateAccount( |
| 844: | $UserId = 0, |
| 845: | $FriendlyName = '', |
| 846: | $Email = '', |
| 847: | $IncomingLogin = '', |
| 848: | $IncomingPassword = '', |
| 849: | $Server = null, |
| 850: | $XAuth = null |
| 851: | ) { |
| 852: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 853: | |
| 854: | \Aurora\System\Api::CheckAccess($UserId); |
| 855: | |
| 856: | $Email = \strtolower($Email); |
| 857: | $IncomingLogin = strtolower($IncomingLogin); |
| 858: | |
| 859: | $oAccount = $this->GetAccountByEmail($Email, $UserId); |
| 860: | $oServer = false; |
| 861: | |
| 862: | if ($oAccount instanceof \Aurora\Modules\Mail\Models\MailAccount) { |
| 863: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::AccountExists); |
| 864: | } else { |
| 865: | if ($Email) { |
| 866: | $sDomain = \MailSo\Base\Utils::GetDomainFromEmail($Email); |
| 867: | $bCustomServerCreated = false; |
| 868: | $iServerId = isset($Server) ? $Server['ServerId'] : 0; |
| 869: | if ($Server !== null && $iServerId === 0) { |
| 870: | $oNewServer = new \Aurora\Modules\Mail\Models\Server(); |
| 871: | $oNewServer->Name = $Server['IncomingServer']; |
| 872: | $oNewServer->IncomingServer = $Server['IncomingServer']; |
| 873: | $oNewServer->IncomingPort = $Server['IncomingPort']; |
| 874: | $oNewServer->IncomingUseSsl = $Server['IncomingUseSsl']; |
| 875: | $oNewServer->OutgoingServer = $Server['OutgoingServer']; |
| 876: | $oNewServer->OutgoingPort = $Server['OutgoingPort']; |
| 877: | $oNewServer->OutgoingUseSsl = $Server['OutgoingUseSsl']; |
| 878: | $oNewServer->SmtpAuthType = $Server['SmtpAuthType']; |
| 879: | $oNewServer->Domains = $sDomain; |
| 880: | $oNewServer->EnableThreading = $Server['EnableThreading']; |
| 881: | $iServerId = $this->getServersManager()->createServer($oNewServer); |
| 882: | $bCustomServerCreated = true; |
| 883: | } |
| 884: | |
| 885: | if ($Server === null) { |
| 886: | $aServerResult = self::Decorator()->GetMailServerByDomain($sDomain, true); |
| 887: | if (isset($aServerResult['Server'])) { |
| 888: | $oServer = $aServerResult['Server']; |
| 889: | $iServerId = $oServer->Id; |
| 890: | } |
| 891: | } |
| 892: | |
| 893: | $oAccount = new \Aurora\Modules\Mail\Models\MailAccount(); |
| 894: | |
| 895: | $oAccount->IdUser = $UserId; |
| 896: | $oAccount->FriendlyName = $FriendlyName; |
| 897: | $oAccount->Email = $Email; |
| 898: | $oAccount->IncomingLogin = $IncomingLogin; |
| 899: | $oAccount->setPassword($IncomingPassword); |
| 900: | if ($iServerId > 0) { |
| 901: | $oServer = $this->getServersManager()->getServer($iServerId); |
| 902: | } |
| 903: | |
| 904: | if ($oServer) { |
| 905: | $oAccount->Server()->associate($oServer); |
| 906: | $oAccount->UseThreading = $oServer->EnableThreading; |
| 907: | } |
| 908: | |
| 909: | $oAccount->XOAuth = $XAuth; |
| 910: | |
| 911: | $bAccoutResult = false; |
| 912: | $oResException = null; |
| 913: | $bDoImapLoginOnAccountCreate = $this->oModuleSettings->DoImapLoginOnAccountCreate && is_null($XAuth); |
| 914: | if ($bDoImapLoginOnAccountCreate) { |
| 915: | $oResException = $this->getMailManager()->validateAccountConnection($oAccount, false); |
| 916: | } |
| 917: | |
| 918: | $oUser = \Aurora\Modules\Core\Module::Decorator()->GetUserWithoutRoleCheck($UserId); |
| 919: | $aQuota = []; |
| 920: | $iQuota = 0; |
| 921: | |
| 922: | if ($oResException === null && $oUser instanceof User && $oUser->PublicId === $oAccount->Email) { |
| 923: | $aTenantQuota = self::Decorator()->GetEntitySpaceLimits('Tenant', $UserId, $oUser->IdTenant); |
| 924: | if (is_array($aTenantQuota) && isset($aTenantQuota['AllocatedSpaceMb']) && isset($aTenantQuota['TenantSpaceLimitMb'])) { |
| 925: | if ($bDoImapLoginOnAccountCreate) { |
| 926: | $aQuota = $this->getMailManager()->getQuota($oAccount); |
| 927: | } else { |
| 928: | $aQuota[1] = 0; |
| 929: | } |
| 930: | $iQuota = (is_array($aQuota) && isset($aQuota[1])) ? $aQuota[1] / 1024 : 0; |
| 931: | $iNewAllocatedSpaceMb = $aTenantQuota['AllocatedSpaceMb'] + $iQuota; |
| 932: | if ($aTenantQuota['TenantSpaceLimitMb'] > 0 && $aTenantQuota['TenantSpaceLimitMb'] < $iNewAllocatedSpaceMb) { |
| 933: | $oResException = new \Aurora\Modules\Mail\Exceptions\Exception(Enums\ErrorCodes::TenantQuotaExceeded, null, $this->i18N('ERROR_TENANT_QUOTA_EXCEEDED')); |
| 934: | } |
| 935: | } |
| 936: | } |
| 937: | |
| 938: | if ($oResException === null) { |
| 939: | if ($oUser instanceof User && $oUser->PublicId === $Email && |
| 940: | !$this->getAccountsManager()->useToAuthorizeAccountExists($Email)) { |
| 941: | $oAccount->UseToAuthorize = true; |
| 942: | } |
| 943: | $bAccoutResult = $this->getAccountsManager()->createAccount($oAccount); |
| 944: | } |
| 945: | |
| 946: | if ($bAccoutResult) { |
| 947: | if ($oAccount->Email === $oUser->PublicId && $bDoImapLoginOnAccountCreate) { |
| 948: | if (empty($aQuota)) { |
| 949: | $aQuota = $this->getMailManager()->getQuota($oAccount); |
| 950: | $iQuota = (is_array($aQuota) && isset($aQuota[1])) ? $aQuota[1] / 1024 : 0; |
| 951: | } |
| 952: | $this->updateAllocatedTenantSpace($oUser->IdTenant, $iQuota, 0); |
| 953: | $oUser->setExtendedProp(self::GetName() . '::UserSpaceLimitMb', $iQuota); |
| 954: | $oUser->save(); |
| 955: | } |
| 956: | if ($oServer && $oServer->EnableSieve && $this->oModuleSettings->EnableAllowBlockLists) { |
| 957: | try { |
| 958: | $this->getSieveManager()->setAllowBlockLists($oAccount, [], []); |
| 959: | } catch (\Exception $oEx) { |
| 960: | Api::LogException($oEx); |
| 961: | } |
| 962: | } |
| 963: | return $oAccount; |
| 964: | } elseif ($bCustomServerCreated) { |
| 965: | $this->getServersManager()->deleteServer($iServerId); |
| 966: | } |
| 967: | |
| 968: | if ($oResException !== null) { |
| 969: | throw $oResException; |
| 970: | } |
| 971: | } |
| 972: | } |
| 973: | return false; |
| 974: | } |
| 975: | |
| 976: | |
| 977: | |
| 978: | |
| 979: | |
| 980: | |
| 981: | |
| 982: | |
| 983: | |
| 984: | |
| 985: | |
| 986: | |
| 987: | |
| 988: | |
| 989: | |
| 990: | |
| 991: | |
| 992: | |
| 993: | |
| 994: | |
| 995: | |
| 996: | |
| 997: | |
| 998: | |
| 999: | |
| 1000: | |
| 1001: | |
| 1002: | |
| 1003: | |
| 1004: | |
| 1005: | |
| 1006: | |
| 1007: | |
| 1008: | |
| 1009: | |
| 1010: | |
| 1011: | |
| 1012: | |
| 1013: | |
| 1014: | |
| 1015: | |
| 1016: | |
| 1017: | |
| 1018: | |
| 1019: | |
| 1020: | |
| 1021: | |
| 1022: | |
| 1023: | |
| 1024: | |
| 1025: | |
| 1026: | |
| 1027: | |
| 1028: | |
| 1029: | |
| 1030: | |
| 1031: | |
| 1032: | |
| 1033: | |
| 1034: | |
| 1035: | |
| 1036: | |
| 1037: | |
| 1038: | |
| 1039: | |
| 1040: | |
| 1041: | |
| 1042: | |
| 1043: | |
| 1044: | |
| 1045: | |
| 1046: | public function UpdateAccount( |
| 1047: | $AccountID, |
| 1048: | $UseToAuthorize = false, |
| 1049: | $Email = null, |
| 1050: | $FriendlyName = null, |
| 1051: | $IncomingLogin = null, |
| 1052: | $IncomingPassword = null, |
| 1053: | $Server = null, |
| 1054: | $UseThreading = null, |
| 1055: | $SaveRepliesToCurrFolder = null |
| 1056: | ) { |
| 1057: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 1058: | |
| 1059: | if ($AccountID > 0) { |
| 1060: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 1061: | |
| 1062: | self::checkAccountAccess($oAccount); |
| 1063: | |
| 1064: | if ($oAccount) { |
| 1065: | if (!empty($Email)) { |
| 1066: | $oAccount->Email = $Email; |
| 1067: | } |
| 1068: | if ($UseToAuthorize === false || $UseToAuthorize === true && !$this->getAccountsManager()->useToAuthorizeAccountExists($oAccount->Email, $oAccount->Id)) { |
| 1069: | $oAccount->UseToAuthorize = $UseToAuthorize; |
| 1070: | } |
| 1071: | if ($FriendlyName !== null) { |
| 1072: | $oAccount->FriendlyName = $FriendlyName; |
| 1073: | } |
| 1074: | if (!empty($IncomingLogin)) { |
| 1075: | $oAccount->IncomingLogin = $IncomingLogin; |
| 1076: | } |
| 1077: | if (!empty($IncomingPassword)) { |
| 1078: | $oAccount->setPassword($IncomingPassword); |
| 1079: | } |
| 1080: | if ($Server !== null) { |
| 1081: | if ($Server['ServerId'] === 0) { |
| 1082: | $sDomains = explode('@', $oAccount->Email)[1]; |
| 1083: | $oNewServer = new \Aurora\Modules\Mail\Models\Server(); |
| 1084: | $oNewServer->Name = $Server['IncomingServer']; |
| 1085: | $oNewServer->IncomingServer = $Server['IncomingServer']; |
| 1086: | $oNewServer->IncomingPort = $Server['IncomingPort']; |
| 1087: | $oNewServer->IncomingUseSsl = $Server['IncomingUseSsl']; |
| 1088: | $oNewServer->OutgoingServer = $Server['OutgoingServer']; |
| 1089: | $oNewServer->OutgoingPort = $Server['OutgoingPort']; |
| 1090: | $oNewServer->OutgoingUseSsl = $Server['OutgoingUseSsl']; |
| 1091: | $oNewServer->SmtpAuthType = $Server['SmtpAuthType']; |
| 1092: | $oNewServer->Domains = $sDomains; |
| 1093: | $oNewServer->EnableThreading = $Server['EnableThreading']; |
| 1094: | $iNewServerId = $this->getServersManager()->createServer($oNewServer); |
| 1095: | $oAccount->ServerId = $iNewServerId; |
| 1096: | } elseif ($oAccount->ServerId === $Server['ServerId']) { |
| 1097: | $oAccServer = $oAccount->getServer(); |
| 1098: | if ($oAccServer && $oAccServer->OwnerType === \Aurora\Modules\Mail\Enums\ServerOwnerType::Account) { |
| 1099: | $oAccServer->Name = $Server['IncomingServer']; |
| 1100: | $oAccServer->IncomingServer = $Server['IncomingServer']; |
| 1101: | $oAccServer->IncomingPort = $Server['IncomingPort']; |
| 1102: | $oAccServer->IncomingUseSsl = $Server['IncomingUseSsl']; |
| 1103: | $oAccServer->OutgoingServer = $Server['OutgoingServer']; |
| 1104: | $oAccServer->OutgoingPort = $Server['OutgoingPort']; |
| 1105: | $oAccServer->OutgoingUseSsl = $Server['OutgoingUseSsl']; |
| 1106: | $oAccServer->SmtpAuthType = $Server['SmtpAuthType']; |
| 1107: | |
| 1108: | $this->getServersManager()->updateServer($oAccServer); |
| 1109: | } |
| 1110: | } else { |
| 1111: | $oAccServer = $oAccount->getServer(); |
| 1112: | if ($oAccServer && $oAccServer->OwnerType === \Aurora\Modules\Mail\Enums\ServerOwnerType::Account) { |
| 1113: | $this->getServersManager()->deleteServer($oAccServer->Id); |
| 1114: | } |
| 1115: | $oAccount->ServerId = $Server['ServerId']; |
| 1116: | } |
| 1117: | } |
| 1118: | |
| 1119: | if ($UseThreading !== null) { |
| 1120: | $oAccount->UseThreading = $UseThreading; |
| 1121: | } |
| 1122: | |
| 1123: | if ($SaveRepliesToCurrFolder !== null) { |
| 1124: | $oAccount->SaveRepliesToCurrFolder = $SaveRepliesToCurrFolder; |
| 1125: | } |
| 1126: | |
| 1127: | if ($this->getAccountsManager()->updateAccount($oAccount)) { |
| 1128: | return $oAccount; |
| 1129: | } |
| 1130: | } |
| 1131: | } else { |
| 1132: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::InvalidInputParameter); |
| 1133: | } |
| 1134: | |
| 1135: | return false; |
| 1136: | } |
| 1137: | |
| 1138: | public function UpdateAccountUnifiedMailbox( |
| 1139: | $AccountID, |
| 1140: | $IncludeInUnifiedMailbox, |
| 1141: | $ShowUnifiedMailboxLabel, |
| 1142: | $UnifiedMailboxLabelText, |
| 1143: | $UnifiedMailboxLabelColor |
| 1144: | ) { |
| 1145: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 1146: | if (!$this->oModuleSettings->AllowUnifiedInbox) { |
| 1147: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::AccessDenied); |
| 1148: | } |
| 1149: | if (!is_int($AccountID) || $AccountID <= 0 || !is_bool($IncludeInUnifiedMailbox) || !is_bool($ShowUnifiedMailboxLabel) || |
| 1150: | !is_string($UnifiedMailboxLabelText) || !is_string($UnifiedMailboxLabelColor)) { |
| 1151: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::InvalidInputParameter); |
| 1152: | } |
| 1153: | |
| 1154: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 1155: | |
| 1156: | self::checkAccountAccess($oAccount); |
| 1157: | |
| 1158: | if ($oAccount instanceof Models\MailAccount) { |
| 1159: | $oAccount->IncludeInUnifiedMailbox = $IncludeInUnifiedMailbox; |
| 1160: | $oAccount->ShowUnifiedMailboxLabel = $ShowUnifiedMailboxLabel; |
| 1161: | $oAccount->UnifiedMailboxLabelText = $UnifiedMailboxLabelText; |
| 1162: | $oAccount->UnifiedMailboxLabelColor = $UnifiedMailboxLabelColor; |
| 1163: | |
| 1164: | if ($this->getAccountsManager()->updateAccount($oAccount)) { |
| 1165: | return $oAccount; |
| 1166: | } |
| 1167: | } |
| 1168: | |
| 1169: | return false; |
| 1170: | } |
| 1171: | |
| 1172: | |
| 1173: | |
| 1174: | |
| 1175: | |
| 1176: | |
| 1177: | |
| 1178: | |
| 1179: | |
| 1180: | |
| 1181: | |
| 1182: | |
| 1183: | |
| 1184: | |
| 1185: | |
| 1186: | |
| 1187: | |
| 1188: | |
| 1189: | |
| 1190: | |
| 1191: | |
| 1192: | |
| 1193: | |
| 1194: | |
| 1195: | |
| 1196: | |
| 1197: | |
| 1198: | |
| 1199: | |
| 1200: | |
| 1201: | |
| 1202: | |
| 1203: | |
| 1204: | |
| 1205: | |
| 1206: | |
| 1207: | |
| 1208: | |
| 1209: | |
| 1210: | |
| 1211: | |
| 1212: | |
| 1213: | |
| 1214: | |
| 1215: | |
| 1216: | |
| 1217: | |
| 1218: | |
| 1219: | |
| 1220: | |
| 1221: | |
| 1222: | |
| 1223: | |
| 1224: | |
| 1225: | public function DeleteAccount($AccountID) |
| 1226: | { |
| 1227: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 1228: | |
| 1229: | $bResult = false; |
| 1230: | |
| 1231: | if ($AccountID > 0) { |
| 1232: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 1233: | |
| 1234: | self::checkAccountAccess($oAccount); |
| 1235: | |
| 1236: | if ($oAccount) { |
| 1237: | $this->getIdentitiesManager()->deleteAccountIdentities($oAccount->Id); |
| 1238: | $this->getMailManager()->deleteSystemFolderNames($oAccount->Id); |
| 1239: | |
| 1240: | $oServer = $oAccount->getServer(); |
| 1241: | |
| 1242: | $oUser = \Aurora\Modules\Core\Module::Decorator()->GetUserWithoutRoleCheck($oAccount->IdUser); |
| 1243: | if ($oUser instanceof User && $oAccount->Email === $oUser->PublicId) { |
| 1244: | $iQuota = $oUser->getExtendedProp(self::GetName() . '::UserSpaceLimitMb'); |
| 1245: | $this->updateAllocatedTenantSpace($oUser->IdTenant, 0, $iQuota); |
| 1246: | } |
| 1247: | |
| 1248: | $aArgs = [ |
| 1249: | 'Account' => $oAccount, |
| 1250: | 'User' => $oUser |
| 1251: | ]; |
| 1252: | $this->broadcastEvent( |
| 1253: | 'BeforeDeleteAccount', |
| 1254: | $aArgs |
| 1255: | ); |
| 1256: | $bResult = $this->getAccountsManager()->deleteAccount($oAccount); |
| 1257: | |
| 1258: | if ($bResult && $oServer && $oServer->OwnerType === \Aurora\Modules\Mail\Enums\ServerOwnerType::Account) { |
| 1259: | $this->getServersManager()->deleteServer($oServer->Id); |
| 1260: | } |
| 1261: | } |
| 1262: | |
| 1263: | return $bResult; |
| 1264: | } else { |
| 1265: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::InvalidInputParameter); |
| 1266: | } |
| 1267: | } |
| 1268: | |
| 1269: | |
| 1270: | |
| 1271: | |
| 1272: | |
| 1273: | |
| 1274: | |
| 1275: | |
| 1276: | |
| 1277: | |
| 1278: | |
| 1279: | |
| 1280: | |
| 1281: | |
| 1282: | |
| 1283: | |
| 1284: | |
| 1285: | |
| 1286: | |
| 1287: | |
| 1288: | |
| 1289: | |
| 1290: | |
| 1291: | |
| 1292: | |
| 1293: | |
| 1294: | |
| 1295: | |
| 1296: | |
| 1297: | |
| 1298: | |
| 1299: | |
| 1300: | |
| 1301: | |
| 1302: | |
| 1303: | |
| 1304: | |
| 1305: | |
| 1306: | |
| 1307: | |
| 1308: | |
| 1309: | |
| 1310: | |
| 1311: | |
| 1312: | |
| 1313: | |
| 1314: | |
| 1315: | |
| 1316: | |
| 1317: | |
| 1318: | |
| 1319: | |
| 1320: | |
| 1321: | |
| 1322: | |
| 1323: | |
| 1324: | |
| 1325: | |
| 1326: | |
| 1327: | |
| 1328: | |
| 1329: | public function GetServers($TenantId = 0, $Offset = 0, $Limit = 0, $Search = '') |
| 1330: | { |
| 1331: | $oAuthenticatedUser = \Aurora\System\Api::getAuthenticatedUser(); |
| 1332: | if ($oAuthenticatedUser instanceof User && $oAuthenticatedUser->isNormalOrTenant()) { |
| 1333: | if ($TenantId === 0) { |
| 1334: | $TenantId = $oAuthenticatedUser->IdTenant; |
| 1335: | } elseif ($TenantId !== $oAuthenticatedUser->IdTenant) { |
| 1336: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::AccessDenied); |
| 1337: | } |
| 1338: | } else { |
| 1339: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::SuperAdmin); |
| 1340: | } |
| 1341: | |
| 1342: | return [ |
| 1343: | 'Items' => $this->getServersManager()->getServerList($TenantId, $Offset, $Limit, $Search)->all(), |
| 1344: | 'Count' => $this->getServersManager()->getServersCount($TenantId, $Search), |
| 1345: | ]; |
| 1346: | } |
| 1347: | |
| 1348: | |
| 1349: | |
| 1350: | |
| 1351: | |
| 1352: | |
| 1353: | |
| 1354: | |
| 1355: | |
| 1356: | |
| 1357: | |
| 1358: | |
| 1359: | |
| 1360: | |
| 1361: | |
| 1362: | |
| 1363: | |
| 1364: | |
| 1365: | |
| 1366: | |
| 1367: | |
| 1368: | |
| 1369: | |
| 1370: | |
| 1371: | |
| 1372: | |
| 1373: | |
| 1374: | |
| 1375: | |
| 1376: | |
| 1377: | |
| 1378: | |
| 1379: | |
| 1380: | |
| 1381: | |
| 1382: | |
| 1383: | |
| 1384: | |
| 1385: | |
| 1386: | |
| 1387: | |
| 1388: | |
| 1389: | |
| 1390: | |
| 1391: | |
| 1392: | |
| 1393: | |
| 1394: | |
| 1395: | |
| 1396: | |
| 1397: | |
| 1398: | |
| 1399: | |
| 1400: | |
| 1401: | |
| 1402: | |
| 1403: | |
| 1404: | |
| 1405: | |
| 1406: | |
| 1407: | |
| 1408: | |
| 1409: | |
| 1410: | |
| 1411: | |
| 1412: | |
| 1413: | |
| 1414: | |
| 1415: | |
| 1416: | |
| 1417: | |
| 1418: | public function GetServer($ServerId) |
| 1419: | { |
| 1420: | $oServer = $this->getServersManager()->getServer($ServerId); |
| 1421: | $oAuthenticatedUser = \Aurora\System\Api::getAuthenticatedUser(); |
| 1422: | if ($oAuthenticatedUser instanceof User && $oAuthenticatedUser->isNormalOrTenant()) { |
| 1423: | if ($oServer->TenantId !== $oAuthenticatedUser->IdTenant) { |
| 1424: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::AccessDenied); |
| 1425: | } |
| 1426: | } else { |
| 1427: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::SuperAdmin); |
| 1428: | } |
| 1429: | |
| 1430: | return $oServer; |
| 1431: | } |
| 1432: | |
| 1433: | |
| 1434: | |
| 1435: | |
| 1436: | |
| 1437: | |
| 1438: | |
| 1439: | |
| 1440: | |
| 1441: | |
| 1442: | |
| 1443: | |
| 1444: | |
| 1445: | |
| 1446: | |
| 1447: | |
| 1448: | |
| 1449: | |
| 1450: | |
| 1451: | |
| 1452: | |
| 1453: | |
| 1454: | |
| 1455: | |
| 1456: | |
| 1457: | |
| 1458: | |
| 1459: | |
| 1460: | |
| 1461: | |
| 1462: | |
| 1463: | |
| 1464: | |
| 1465: | |
| 1466: | |
| 1467: | |
| 1468: | |
| 1469: | |
| 1470: | |
| 1471: | |
| 1472: | |
| 1473: | |
| 1474: | |
| 1475: | |
| 1476: | |
| 1477: | |
| 1478: | |
| 1479: | |
| 1480: | |
| 1481: | |
| 1482: | |
| 1483: | |
| 1484: | |
| 1485: | |
| 1486: | |
| 1487: | |
| 1488: | |
| 1489: | |
| 1490: | |
| 1491: | |
| 1492: | |
| 1493: | |
| 1494: | |
| 1495: | |
| 1496: | |
| 1497: | |
| 1498: | |
| 1499: | |
| 1500: | |
| 1501: | |
| 1502: | |
| 1503: | |
| 1504: | |
| 1505: | |
| 1506: | |
| 1507: | |
| 1508: | |
| 1509: | |
| 1510: | |
| 1511: | |
| 1512: | |
| 1513: | |
| 1514: | |
| 1515: | |
| 1516: | |
| 1517: | |
| 1518: | |
| 1519: | |
| 1520: | |
| 1521: | |
| 1522: | |
| 1523: | |
| 1524: | |
| 1525: | |
| 1526: | |
| 1527: | |
| 1528: | |
| 1529: | |
| 1530: | public function CreateServer( |
| 1531: | $Name, |
| 1532: | $IncomingServer, |
| 1533: | $IncomingPort, |
| 1534: | $IncomingUseSsl, |
| 1535: | $OutgoingServer, |
| 1536: | $OutgoingPort, |
| 1537: | $OutgoingUseSsl, |
| 1538: | $SmtpAuthType, |
| 1539: | $Domains, |
| 1540: | $EnableThreading = true, |
| 1541: | $EnableSieve = false, |
| 1542: | $SievePort = 4190, |
| 1543: | $SmtpLogin = '', |
| 1544: | $SmtpPassword = '', |
| 1545: | $UseFullEmailAddressAsLogin = true, |
| 1546: | $TenantId = 0, |
| 1547: | $SetExternalAccessServers = false, |
| 1548: | $ExternalAccessImapServer = '', |
| 1549: | $ExternalAccessImapPort = 143, |
| 1550: | $ExternalAccessImapAlterPort = 0, |
| 1551: | $ExternalAccessImapUseSsl = false, |
| 1552: | $ExternalAccessPop3Server = '', |
| 1553: | $ExternalAccessPop3Port = 143, |
| 1554: | $ExternalAccessPop3AlterPort = 0, |
| 1555: | $ExternalAccessPop3UseSsl = false, |
| 1556: | $ExternalAccessSmtpServer = '', |
| 1557: | $ExternalAccessSmtpPort = 25, |
| 1558: | $ExternalAccessSmtpAlterPort = 0, |
| 1559: | $ExternalAccessSmtpUseSsl = false, |
| 1560: | $OAuthEnable = false, |
| 1561: | $OAuthName = '', |
| 1562: | $OAuthType = '', |
| 1563: | $OAuthIconUrl = '' |
| 1564: | ) { |
| 1565: | $oAuthenticatedUser = \Aurora\System\Api::getAuthenticatedUser(); |
| 1566: | if ($oAuthenticatedUser instanceof User && $oAuthenticatedUser->Role === \Aurora\Modules\Mail\Enums\ServerOwnerType::Tenant) { |
| 1567: | if ($TenantId !== $oAuthenticatedUser->IdTenant) { |
| 1568: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::AccessDenied); |
| 1569: | } |
| 1570: | } else { |
| 1571: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::SuperAdmin); |
| 1572: | } |
| 1573: | |
| 1574: | $sOwnerType = ($TenantId === 0) ? \Aurora\Modules\Mail\Enums\ServerOwnerType::SuperAdmin : \Aurora\Modules\Mail\Enums\ServerOwnerType::Tenant; |
| 1575: | |
| 1576: | $oServer = new \Aurora\Modules\Mail\Models\Server(); |
| 1577: | $oServer->OwnerType = $sOwnerType; |
| 1578: | $oServer->TenantId = $TenantId; |
| 1579: | $oServer->Name = $Name; |
| 1580: | $oServer->IncomingServer = $IncomingServer; |
| 1581: | $oServer->IncomingPort = $IncomingPort; |
| 1582: | $oServer->IncomingUseSsl = $IncomingUseSsl; |
| 1583: | $oServer->OutgoingServer = $OutgoingServer; |
| 1584: | $oServer->OutgoingPort = $OutgoingPort; |
| 1585: | $oServer->OutgoingUseSsl = $OutgoingUseSsl; |
| 1586: | $oServer->SmtpAuthType = $SmtpAuthType; |
| 1587: | $oServer->SmtpLogin = $SmtpLogin; |
| 1588: | $oServer->SmtpPassword = $SmtpPassword; |
| 1589: | $oServer->Domains = $this->getServersManager()->trimDomains($Domains); |
| 1590: | $oServer->EnableThreading = $EnableThreading; |
| 1591: | $oServer->EnableSieve = $EnableSieve; |
| 1592: | $oServer->SievePort = $SievePort; |
| 1593: | $oServer->UseFullEmailAddressAsLogin = $UseFullEmailAddressAsLogin; |
| 1594: | $oServer->SetExternalAccessServers = $SetExternalAccessServers; |
| 1595: | if ($oServer->SetExternalAccessServers) { |
| 1596: | $oServer->ExternalAccessImapServer = $ExternalAccessImapServer; |
| 1597: | $oServer->ExternalAccessImapPort = $ExternalAccessImapPort; |
| 1598: | $oServer->ExternalAccessImapAlterPort = $ExternalAccessImapAlterPort; |
| 1599: | $oServer->ExternalAccessImapUseSsl = $ExternalAccessImapUseSsl; |
| 1600: | |
| 1601: | $oServer->ExternalAccessPop3Server = $ExternalAccessPop3Server; |
| 1602: | $oServer->ExternalAccessPop3Port = $ExternalAccessPop3Port; |
| 1603: | $oServer->ExternalAccessPop3AlterPort = $ExternalAccessPop3AlterPort; |
| 1604: | $oServer->ExternalAccessPop3UseSsl = $ExternalAccessPop3UseSsl; |
| 1605: | |
| 1606: | $oServer->ExternalAccessSmtpServer = $ExternalAccessSmtpServer; |
| 1607: | $oServer->ExternalAccessSmtpPort = $ExternalAccessSmtpPort; |
| 1608: | $oServer->ExternalAccessSmtpAlterPort = $ExternalAccessSmtpAlterPort; |
| 1609: | $oServer->ExternalAccessSmtpUseSsl = $ExternalAccessSmtpUseSsl; |
| 1610: | } |
| 1611: | $oServer->OAuthEnable = $OAuthEnable; |
| 1612: | if ($oServer->OAuthEnable) { |
| 1613: | $oServer->OAuthName = $OAuthName; |
| 1614: | $oServer->OAuthType = $OAuthType; |
| 1615: | $oServer->OAuthIconUrl = $OAuthIconUrl; |
| 1616: | } |
| 1617: | |
| 1618: | return $this->getServersManager()->createServer($oServer); |
| 1619: | } |
| 1620: | |
| 1621: | |
| 1622: | |
| 1623: | |
| 1624: | |
| 1625: | |
| 1626: | |
| 1627: | |
| 1628: | |
| 1629: | |
| 1630: | |
| 1631: | |
| 1632: | |
| 1633: | |
| 1634: | |
| 1635: | |
| 1636: | |
| 1637: | |
| 1638: | |
| 1639: | |
| 1640: | |
| 1641: | |
| 1642: | |
| 1643: | |
| 1644: | |
| 1645: | |
| 1646: | |
| 1647: | |
| 1648: | |
| 1649: | |
| 1650: | |
| 1651: | |
| 1652: | |
| 1653: | |
| 1654: | |
| 1655: | |
| 1656: | |
| 1657: | |
| 1658: | |
| 1659: | |
| 1660: | |
| 1661: | |
| 1662: | |
| 1663: | |
| 1664: | |
| 1665: | |
| 1666: | |
| 1667: | |
| 1668: | |
| 1669: | |
| 1670: | |
| 1671: | |
| 1672: | |
| 1673: | |
| 1674: | |
| 1675: | |
| 1676: | |
| 1677: | |
| 1678: | |
| 1679: | |
| 1680: | |
| 1681: | |
| 1682: | |
| 1683: | |
| 1684: | |
| 1685: | |
| 1686: | |
| 1687: | |
| 1688: | |
| 1689: | |
| 1690: | |
| 1691: | |
| 1692: | |
| 1693: | |
| 1694: | |
| 1695: | |
| 1696: | |
| 1697: | |
| 1698: | |
| 1699: | |
| 1700: | |
| 1701: | |
| 1702: | |
| 1703: | |
| 1704: | |
| 1705: | |
| 1706: | |
| 1707: | |
| 1708: | |
| 1709: | |
| 1710: | |
| 1711: | |
| 1712: | |
| 1713: | |
| 1714: | |
| 1715: | |
| 1716: | |
| 1717: | |
| 1718: | |
| 1719: | |
| 1720: | public function UpdateServer( |
| 1721: | $ServerId, |
| 1722: | $Name, |
| 1723: | $IncomingServer, |
| 1724: | $IncomingPort, |
| 1725: | $IncomingUseSsl, |
| 1726: | $OutgoingServer, |
| 1727: | $OutgoingPort, |
| 1728: | $OutgoingUseSsl, |
| 1729: | $SmtpAuthType, |
| 1730: | $Domains, |
| 1731: | $EnableThreading, |
| 1732: | $EnableSieve, |
| 1733: | $SievePort, |
| 1734: | $SmtpLogin = '', |
| 1735: | $SmtpPassword = '', |
| 1736: | $UseFullEmailAddressAsLogin = true, |
| 1737: | $TenantId = 0, |
| 1738: | $SetExternalAccessServers = false, |
| 1739: | $ExternalAccessImapServer = '', |
| 1740: | $ExternalAccessImapPort = 143, |
| 1741: | $ExternalAccessImapAlterPort = 0, |
| 1742: | $ExternalAccessImapUseSsl = false, |
| 1743: | $ExternalAccessPop3Server = '', |
| 1744: | $ExternalAccessPop3Port = 143, |
| 1745: | $ExternalAccessPop3AlterPort = 0, |
| 1746: | $ExternalAccessPop3UseSsl = false, |
| 1747: | $ExternalAccessSmtpServer = '', |
| 1748: | $ExternalAccessSmtpPort = 25, |
| 1749: | $ExternalAccessSmtpAlterPort = 0, |
| 1750: | $ExternalAccessSmtpUseSsl = false, |
| 1751: | $OAuthEnable = false, |
| 1752: | $OAuthName = '', |
| 1753: | $OAuthType = '', |
| 1754: | $OAuthIconUrl = '' |
| 1755: | ) { |
| 1756: | $bResult = false; |
| 1757: | |
| 1758: | $oServer = $this->getServersManager()->getServer($ServerId); |
| 1759: | |
| 1760: | if ($oServer->OwnerType === \Aurora\Modules\Mail\Enums\ServerOwnerType::SuperAdmin) { |
| 1761: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::SuperAdmin); |
| 1762: | } else { |
| 1763: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::TenantAdmin); |
| 1764: | } |
| 1765: | |
| 1766: | if ($oServer && ($oServer->OwnerType === \Aurora\Modules\Mail\Enums\ServerOwnerType::SuperAdmin || |
| 1767: | $oServer->OwnerType === \Aurora\Modules\Mail\Enums\ServerOwnerType::Tenant && $oServer->TenantId === $TenantId)) { |
| 1768: | $oServer->Name = $Name; |
| 1769: | $oServer->IncomingServer = $IncomingServer; |
| 1770: | $oServer->IncomingPort = $IncomingPort; |
| 1771: | $oServer->IncomingUseSsl = $IncomingUseSsl; |
| 1772: | $oServer->OutgoingServer = $OutgoingServer; |
| 1773: | $oServer->OutgoingPort = $OutgoingPort; |
| 1774: | $oServer->OutgoingUseSsl = $OutgoingUseSsl; |
| 1775: | $oServer->SmtpAuthType = $SmtpAuthType; |
| 1776: | $oServer->SmtpLogin = $SmtpLogin; |
| 1777: | |
| 1778: | |
| 1779: | if ($SmtpPassword !== '*****') { |
| 1780: | $oServer->SmtpPassword = $SmtpPassword; |
| 1781: | } |
| 1782: | $oServer->Domains = $this->getServersManager()->trimDomains($Domains); |
| 1783: | $oServer->EnableThreading = $EnableThreading; |
| 1784: | $oServer->EnableSieve = $EnableSieve; |
| 1785: | $oServer->SievePort = $SievePort; |
| 1786: | $oServer->UseFullEmailAddressAsLogin = $UseFullEmailAddressAsLogin; |
| 1787: | $oServer->SetExternalAccessServers = $SetExternalAccessServers; |
| 1788: | if ($oServer->SetExternalAccessServers) { |
| 1789: | $oServer->ExternalAccessImapServer = $ExternalAccessImapServer; |
| 1790: | $oServer->ExternalAccessImapPort = $ExternalAccessImapPort; |
| 1791: | $oServer->ExternalAccessImapAlterPort = $ExternalAccessImapAlterPort; |
| 1792: | $oServer->ExternalAccessImapUseSsl = $ExternalAccessImapUseSsl; |
| 1793: | |
| 1794: | $oServer->ExternalAccessPop3Server = $ExternalAccessPop3Server; |
| 1795: | $oServer->ExternalAccessPop3Port = $ExternalAccessPop3Port; |
| 1796: | $oServer->ExternalAccessPop3AlterPort = $ExternalAccessPop3AlterPort; |
| 1797: | $oServer->ExternalAccessPop3UseSsl = $ExternalAccessPop3UseSsl; |
| 1798: | |
| 1799: | $oServer->ExternalAccessSmtpServer = $ExternalAccessSmtpServer; |
| 1800: | $oServer->ExternalAccessSmtpPort = $ExternalAccessSmtpPort; |
| 1801: | $oServer->ExternalAccessSmtpAlterPort = $ExternalAccessSmtpAlterPort; |
| 1802: | $oServer->ExternalAccessImapUseSsl = $ExternalAccessImapUseSsl; |
| 1803: | $oServer->ExternalAccessSmtpUseSsl = $ExternalAccessSmtpUseSsl; |
| 1804: | } |
| 1805: | $oServer->OAuthEnable = $OAuthEnable; |
| 1806: | if ($oServer->OAuthEnable) { |
| 1807: | $oServer->OAuthName = $OAuthName; |
| 1808: | $oServer->OAuthType = $OAuthType; |
| 1809: | $oServer->OAuthIconUrl = $OAuthIconUrl; |
| 1810: | } |
| 1811: | |
| 1812: | $bResult = $this->getServersManager()->updateServer($oServer); |
| 1813: | } else { |
| 1814: | $bResult = false; |
| 1815: | } |
| 1816: | |
| 1817: | return $bResult; |
| 1818: | } |
| 1819: | |
| 1820: | |
| 1821: | |
| 1822: | |
| 1823: | |
| 1824: | |
| 1825: | |
| 1826: | |
| 1827: | |
| 1828: | |
| 1829: | |
| 1830: | |
| 1831: | |
| 1832: | |
| 1833: | |
| 1834: | |
| 1835: | |
| 1836: | |
| 1837: | |
| 1838: | |
| 1839: | |
| 1840: | |
| 1841: | |
| 1842: | |
| 1843: | |
| 1844: | |
| 1845: | |
| 1846: | |
| 1847: | |
| 1848: | |
| 1849: | |
| 1850: | |
| 1851: | |
| 1852: | |
| 1853: | |
| 1854: | |
| 1855: | |
| 1856: | |
| 1857: | |
| 1858: | |
| 1859: | |
| 1860: | |
| 1861: | |
| 1862: | |
| 1863: | |
| 1864: | |
| 1865: | |
| 1866: | |
| 1867: | |
| 1868: | |
| 1869: | |
| 1870: | |
| 1871: | |
| 1872: | |
| 1873: | |
| 1874: | public function DeleteServer($ServerId, $TenantId = 0) |
| 1875: | { |
| 1876: | $oAuthenticatedUser = \Aurora\System\Api::getAuthenticatedUser(); |
| 1877: | if ($oAuthenticatedUser instanceof User && $oAuthenticatedUser->Role === \Aurora\Modules\Mail\Enums\ServerOwnerType::Tenant) { |
| 1878: | if ($TenantId !== $oAuthenticatedUser->IdTenant) { |
| 1879: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::AccessDenied); |
| 1880: | } |
| 1881: | } else { |
| 1882: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::SuperAdmin); |
| 1883: | } |
| 1884: | |
| 1885: | $mPrimaryAccounts = $this->getAccountsManager()->getAccounts(['ServerId' => $ServerId, 'UseToAuthorize' => true]); |
| 1886: | if ($mPrimaryAccounts) { |
| 1887: | foreach ($mPrimaryAccounts as $oAccount) { |
| 1888: | \Aurora\Modules\Core\Module::Decorator()->DeleteUser($oAccount->IdUser); |
| 1889: | } |
| 1890: | } |
| 1891: | |
| 1892: | $mSecondaryAccounts = $this->getAccountsManager()->getAccounts(['ServerId' => $ServerId, 'UseToAuthorize' => false]); |
| 1893: | if ($mSecondaryAccounts) { |
| 1894: | foreach ($mSecondaryAccounts as $oAccount) { |
| 1895: | self::Decorator()->DeleteAccount($oAccount->Id); |
| 1896: | } |
| 1897: | } |
| 1898: | |
| 1899: | return $this->getServersManager()->deleteServer($ServerId, $TenantId); |
| 1900: | } |
| 1901: | |
| 1902: | |
| 1903: | |
| 1904: | |
| 1905: | |
| 1906: | |
| 1907: | |
| 1908: | |
| 1909: | |
| 1910: | |
| 1911: | |
| 1912: | |
| 1913: | |
| 1914: | |
| 1915: | |
| 1916: | |
| 1917: | |
| 1918: | |
| 1919: | |
| 1920: | |
| 1921: | |
| 1922: | |
| 1923: | |
| 1924: | |
| 1925: | |
| 1926: | |
| 1927: | |
| 1928: | |
| 1929: | |
| 1930: | |
| 1931: | |
| 1932: | |
| 1933: | |
| 1934: | |
| 1935: | |
| 1936: | |
| 1937: | |
| 1938: | |
| 1939: | |
| 1940: | |
| 1941: | |
| 1942: | |
| 1943: | |
| 1944: | |
| 1945: | |
| 1946: | |
| 1947: | |
| 1948: | |
| 1949: | |
| 1950: | |
| 1951: | |
| 1952: | |
| 1953: | |
| 1954: | |
| 1955: | |
| 1956: | |
| 1957: | |
| 1958: | |
| 1959: | |
| 1960: | |
| 1961: | |
| 1962: | |
| 1963: | |
| 1964: | |
| 1965: | |
| 1966: | |
| 1967: | |
| 1968: | |
| 1969: | |
| 1970: | |
| 1971: | |
| 1972: | |
| 1973: | |
| 1974: | |
| 1975: | |
| 1976: | |
| 1977: | |
| 1978: | |
| 1979: | public function GetFolders($AccountID) |
| 1980: | { |
| 1981: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 1982: | |
| 1983: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 1984: | |
| 1985: | self::checkAccountAccess($oAccount); |
| 1986: | |
| 1987: | $oFolderCollection = $this->getMailManager()->getFolders($oAccount); |
| 1988: | return array( |
| 1989: | 'Folders' => $oFolderCollection, |
| 1990: | 'Namespace' => $oFolderCollection->GetNamespace() |
| 1991: | ); |
| 1992: | } |
| 1993: | |
| 1994: | public function getSortInfo($SortBy, $SortOrder) |
| 1995: | { |
| 1996: | $aMessagesSortBy = $this->oModuleSettings->MessagesSortBy; |
| 1997: | |
| 1998: | if ($SortOrder === null && $aMessagesSortBy !== false && isset($aMessagesSortBy['Allow']) && (bool) $aMessagesSortBy['Allow'] === true) { |
| 1999: | $oSortOrder = new \Aurora\System\Enums\SortOrder(); |
| 2000: | $aSortOrderMap = $oSortOrder->getMap(); |
| 2001: | $SortOrder = isset($aMessagesSortBy['SortOrder']) ? $aSortOrderMap[\strtoupper($aMessagesSortBy['SortOrder'])] : ''; |
| 2002: | } |
| 2003: | |
| 2004: | if ($SortBy === null) { |
| 2005: | if ($aMessagesSortBy !== false && isset($aMessagesSortBy['Allow']) && (bool) $aMessagesSortBy['Allow'] === true) { |
| 2006: | $SortBy = isset($aMessagesSortBy['DefaultSortBy']) ? $aMessagesSortBy['DefaultSortBy'] : ''; |
| 2007: | } |
| 2008: | } else { |
| 2009: | if ($aMessagesSortBy === false || isset($aMessagesSortBy['Allow']) && (bool) $aMessagesSortBy['Allow'] === false) { |
| 2010: | $SortBy = ''; |
| 2011: | } |
| 2012: | } |
| 2013: | |
| 2014: | if (empty($SortBy)) { |
| 2015: | $SortOrder = \Aurora\System\Enums\SortOrder::ASC; |
| 2016: | } |
| 2017: | |
| 2018: | return [$SortBy, $SortOrder]; |
| 2019: | } |
| 2020: | |
| 2021: | |
| 2022: | |
| 2023: | |
| 2024: | |
| 2025: | |
| 2026: | |
| 2027: | |
| 2028: | |
| 2029: | |
| 2030: | |
| 2031: | |
| 2032: | |
| 2033: | |
| 2034: | |
| 2035: | |
| 2036: | |
| 2037: | |
| 2038: | |
| 2039: | |
| 2040: | |
| 2041: | |
| 2042: | |
| 2043: | |
| 2044: | |
| 2045: | |
| 2046: | |
| 2047: | |
| 2048: | |
| 2049: | |
| 2050: | |
| 2051: | |
| 2052: | |
| 2053: | |
| 2054: | |
| 2055: | |
| 2056: | |
| 2057: | |
| 2058: | |
| 2059: | |
| 2060: | |
| 2061: | |
| 2062: | |
| 2063: | |
| 2064: | |
| 2065: | |
| 2066: | |
| 2067: | |
| 2068: | |
| 2069: | |
| 2070: | |
| 2071: | |
| 2072: | |
| 2073: | |
| 2074: | |
| 2075: | |
| 2076: | |
| 2077: | |
| 2078: | |
| 2079: | |
| 2080: | |
| 2081: | |
| 2082: | |
| 2083: | |
| 2084: | |
| 2085: | |
| 2086: | |
| 2087: | |
| 2088: | |
| 2089: | |
| 2090: | |
| 2091: | |
| 2092: | |
| 2093: | |
| 2094: | |
| 2095: | |
| 2096: | |
| 2097: | |
| 2098: | |
| 2099: | |
| 2100: | |
| 2101: | |
| 2102: | |
| 2103: | |
| 2104: | |
| 2105: | |
| 2106: | |
| 2107: | |
| 2108: | |
| 2109: | |
| 2110: | |
| 2111: | |
| 2112: | |
| 2113: | |
| 2114: | |
| 2115: | |
| 2116: | |
| 2117: | |
| 2118: | |
| 2119: | |
| 2120: | |
| 2121: | |
| 2122: | |
| 2123: | |
| 2124: | |
| 2125: | |
| 2126: | |
| 2127: | |
| 2128: | |
| 2129: | |
| 2130: | |
| 2131: | |
| 2132: | |
| 2133: | |
| 2134: | |
| 2135: | |
| 2136: | |
| 2137: | |
| 2138: | |
| 2139: | |
| 2140: | |
| 2141: | |
| 2142: | |
| 2143: | |
| 2144: | |
| 2145: | |
| 2146: | public function GetMessages($AccountID, $Folder, $Offset = 0, $Limit = 20, $Search = '', $Filters = '', $UseThreading = false, $InboxUidnext = '', $SortBy = null, $SortOrder = null) |
| 2147: | { |
| 2148: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 2149: | |
| 2150: | $sSearch = \trim((string) $Search); |
| 2151: | |
| 2152: | $aFilters = array(); |
| 2153: | $sFilters = \strtolower(\trim((string) $Filters)); |
| 2154: | if (0 < \strlen($sFilters)) { |
| 2155: | $aFilters = \array_filter(\explode(',', $sFilters), function ($sValue) { |
| 2156: | return '' !== trim($sValue); |
| 2157: | }); |
| 2158: | } |
| 2159: | |
| 2160: | $iOffset = (int) $Offset; |
| 2161: | $iLimit = (int) $Limit; |
| 2162: | |
| 2163: | if (0 === \strlen(trim($Folder)) || 0 > $iOffset || 0 >= $iLimit || 200 < $iLimit) { |
| 2164: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::InvalidInputParameter); |
| 2165: | } |
| 2166: | |
| 2167: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 2168: | |
| 2169: | self::checkAccountAccess($oAccount); |
| 2170: | |
| 2171: | $aSortInfo = $this->getSortInfo($SortBy, $SortOrder); |
| 2172: | |
| 2173: | $sSortBy = \strtoupper($aSortInfo[0]); |
| 2174: | $sSortOrder = $aSortInfo[1] === \Aurora\System\Enums\SortOrder::DESC ? 'REVERSE' : ''; |
| 2175: | |
| 2176: | return $this->getMailManager()->getMessageList( |
| 2177: | $oAccount, |
| 2178: | $Folder, |
| 2179: | $iOffset, |
| 2180: | $iLimit, |
| 2181: | $sSearch, |
| 2182: | $UseThreading, |
| 2183: | $aFilters, |
| 2184: | $InboxUidnext, |
| 2185: | $sSortBy, |
| 2186: | $sSortOrder |
| 2187: | ); |
| 2188: | } |
| 2189: | |
| 2190: | protected function getFoldersForSearch($oAccount, $Folder, $Search, &$sSearch) |
| 2191: | { |
| 2192: | $iSearchInFoldersType = SearchInFoldersType::Cur; |
| 2193: | if (!empty(trim($Search))) { |
| 2194: | $aSearch = explode(' ', $Search); |
| 2195: | if (is_array($aSearch) && count($aSearch) > 0) { |
| 2196: | $iKey = array_search('folders:sub', $aSearch); |
| 2197: | if ($iKey !== false) { |
| 2198: | $iSearchInFoldersType = SearchInFoldersType::Sub; |
| 2199: | unset($aSearch[$iKey]); |
| 2200: | } else { |
| 2201: | $iKey = array_search('folders:all', $aSearch); |
| 2202: | if ($iKey !== false) { |
| 2203: | $iSearchInFoldersType = SearchInFoldersType::All; |
| 2204: | unset($aSearch[$iKey]); |
| 2205: | } |
| 2206: | } |
| 2207: | $sSearch = implode(' ', $aSearch); |
| 2208: | } |
| 2209: | } |
| 2210: | |
| 2211: | $aFolders = []; |
| 2212: | $bCreateUnExistenSystemFolders = $Folder === ''; |
| 2213: | if ($iSearchInFoldersType === SearchInFoldersType::Cur) { |
| 2214: | $oFoldersColl = $this->getMailManager()->getFolders($oAccount, $bCreateUnExistenSystemFolders); |
| 2215: | $oFolder = $oFoldersColl->getFolder($Folder); |
| 2216: | $aFolders = [$oFolder]; |
| 2217: | } else { |
| 2218: | if ($iSearchInFoldersType === SearchInFoldersType::All) { |
| 2219: | $Folder = ''; |
| 2220: | } |
| 2221: | $oFoldersColl = $this->getMailManager()->getFolders($oAccount, $bCreateUnExistenSystemFolders, $Folder); |
| 2222: | |
| 2223: | $oFoldersColl->foreachWithSubFolders(function ($oFolder) use (&$aFolders) { |
| 2224: | if ($oFolder->isSubscribed() && $oFolder->isSelectable()) { |
| 2225: | if ($oFolder->getFolderXListType() !== \Aurora\Modules\Mail\Enums\FolderType::All) { |
| 2226: | $aFolders[] = $oFolder; |
| 2227: | } |
| 2228: | } |
| 2229: | }); |
| 2230: | } |
| 2231: | |
| 2232: | return $aFolders; |
| 2233: | } |
| 2234: | |
| 2235: | public function GetMessagesByFolders($AccountID, $Folder = '', $Offset = 0, $Limit = 20, $Search = '', $Filters = '', $UseThreading = false, $InboxUidnext = '', $SortBy = null, $SortOrder = null) |
| 2236: | { |
| 2237: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 2238: | |
| 2239: | $sSearch = \trim((string) $Search); |
| 2240: | |
| 2241: | $aFilters = []; |
| 2242: | $sFilters = \strtolower(\trim((string) $Filters)); |
| 2243: | if (0 < \strlen($sFilters)) { |
| 2244: | $aFilters = \array_filter(\explode(',', $sFilters), function ($sValue) { |
| 2245: | return '' !== trim($sValue); |
| 2246: | }); |
| 2247: | } |
| 2248: | |
| 2249: | $iOffset = (int) $Offset; |
| 2250: | $iLimit = (int) $Limit; |
| 2251: | |
| 2252: | if (0 > $iOffset || 0 >= $iLimit || 200 < $iLimit) { |
| 2253: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::InvalidInputParameter); |
| 2254: | } |
| 2255: | |
| 2256: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 2257: | |
| 2258: | self::checkAccountAccess($oAccount); |
| 2259: | |
| 2260: | $aSortInfo = $this->getSortInfo($SortBy, $SortOrder); |
| 2261: | |
| 2262: | $sSortBy = \strtoupper($aSortInfo[0]); |
| 2263: | $sSortOrder = $aSortInfo[1] === \Aurora\System\Enums\SortOrder::DESC ? 'REVERSE' : ''; |
| 2264: | |
| 2265: | $oMessageCollectionResult = \Aurora\Modules\Mail\Classes\MessageCollection::createInstance(); |
| 2266: | $oMessageCollectionResult->FolderName = $Folder; |
| 2267: | $oMessageCollectionResult->Limit = $iLimit; |
| 2268: | $oMessageCollectionResult->Offset = $iOffset; |
| 2269: | $oMessageCollectionResult->Search = $Search; |
| 2270: | $oMessageCollectionResult->Filters = implode(',', $aFilters); |
| 2271: | |
| 2272: | $aFolderUids = []; |
| 2273: | $aUids = []; |
| 2274: | $iMessagesCount = 0; |
| 2275: | $iMessagesResultCount = 0; |
| 2276: | $iMessagesUnseenCount = 0; |
| 2277: | $aFoldersHash = []; |
| 2278: | |
| 2279: | $sSortBy = 'ARRIVAL'; |
| 2280: | $sSortOrder = $SortOrder === \Aurora\System\Enums\SortOrder::DESC ? 'REVERSE' : ''; |
| 2281: | |
| 2282: | $aFolders = $this->getFoldersForSearch($oAccount, $Folder, $Search, $sSearch); |
| 2283: | foreach ($aFolders as $oFolder) { |
| 2284: | $sFolder = $oFolder->getRawFullName(); |
| 2285: | $aUnifiedInfo = $this->getMailManager()->getUnifiedMailboxMessagesInfo($oAccount, $sFolder, $sSearch, $aFilters, $UseThreading, $iOffset + $iLimit, $sSortBy, $sSortOrder); |
| 2286: | if (is_array($aUnifiedInfo['Uids']) && count($aUnifiedInfo['Uids']) > 0) { |
| 2287: | foreach ($aUnifiedInfo['Uids'] as $iKey => $aUid) { |
| 2288: | $aUnifiedInfo['Uids'][$iKey]['folder'] = $sFolder; |
| 2289: | } |
| 2290: | $aUids = array_merge( |
| 2291: | $aUids, |
| 2292: | $aUnifiedInfo['Uids'] |
| 2293: | ); |
| 2294: | } |
| 2295: | $iMessagesCount += $aUnifiedInfo['Count']; |
| 2296: | $iMessagesResultCount += $aUnifiedInfo['ResultCount']; |
| 2297: | $iMessagesUnseenCount += $aUnifiedInfo['UnreadCount']; |
| 2298: | $aFoldersHash[] = $sFolder . ':' . $aUnifiedInfo['FolderHash']; |
| 2299: | } |
| 2300: | |
| 2301: | |
| 2302: | usort($aUids, function ($a, $b) use ($SortOrder) { |
| 2303: | if ($SortOrder === \Aurora\System\Enums\SortOrder::DESC) { |
| 2304: | return (strtotime($a['internaldate']) < strtotime($b['internaldate'])) ? 1 : -1; |
| 2305: | } else { |
| 2306: | return (strtotime($a['internaldate']) > strtotime($b['internaldate'])) ? 1 : -1; |
| 2307: | } |
| 2308: | }); |
| 2309: | if (count($aUids) >= 0) { |
| 2310: | $aUids = array_slice($aUids, $iOffset, $iLimit); |
| 2311: | } |
| 2312: | |
| 2313: | $aAllMessages = []; |
| 2314: | $aNextUids = []; |
| 2315: | $aFoldersHash = []; |
| 2316: | |
| 2317: | $aInboxUidsNext = []; |
| 2318: | if (!empty($InboxUidnext)) { |
| 2319: | $aInboxUids = \explode('.', $InboxUidnext); |
| 2320: | foreach ($aInboxUids as $aUid) { |
| 2321: | $aUidsNext = \explode(':', $aUid); |
| 2322: | if (count($aUidsNext) === 2) { |
| 2323: | $aInboxUidsNext[$aUidsNext[0]] = $aUidsNext[1]; |
| 2324: | } |
| 2325: | } |
| 2326: | } |
| 2327: | |
| 2328: | foreach ($aUids as $aUid) { |
| 2329: | $aFolderUids[$aUid['folder']][] = $aUid['uid']; |
| 2330: | } |
| 2331: | foreach ($aFolderUids as $sFolder => $aFldUids) { |
| 2332: | $sFolder = (string) $sFolder; |
| 2333: | $sInboxUidnext = isset($aInboxUidsNext[$sFolder]) ? $aInboxUidsNext[$sFolder] : ''; |
| 2334: | |
| 2335: | $oMessageCollection = $this->getMailManager()->getMessageListByUids( |
| 2336: | $oAccount, |
| 2337: | $sFolder, |
| 2338: | $aFldUids, |
| 2339: | $sInboxUidnext |
| 2340: | ); |
| 2341: | |
| 2342: | if ($UseThreading) { |
| 2343: | $oMessageCollection->ForeachList(function ( $oMessage) use ($aUids, $sFolder) { |
| 2344: | $iUid = $oMessage->getUid(); |
| 2345: | $aUidInfo = current(array_filter($aUids, function ($aUid) use ($sFolder, $iUid) { |
| 2346: | return $aUid['folder'] === $sFolder && $aUid['uid'] == $iUid; |
| 2347: | })); |
| 2348: | if (isset($aUidInfo['threads']) && is_array($aUidInfo['threads'])) { |
| 2349: | $oMessage->setThreads($aUidInfo['threads']); |
| 2350: | } |
| 2351: | }); |
| 2352: | } |
| 2353: | |
| 2354: | foreach ($oMessageCollection->New as $aNew) { |
| 2355: | $aNew['Folder'] = $sFolder; |
| 2356: | $oMessageCollectionResult->New[] = $aNew; |
| 2357: | } |
| 2358: | |
| 2359: | $aNextUids[] = $sFolder . ':' . $oMessageCollection->UidNext; |
| 2360: | $aMessages = $oMessageCollection->GetAsArray(); |
| 2361: | foreach ($aMessages as $oMessage) { |
| 2362: | |
| 2363: | |
| 2364: | $oMessage->setUnifiedUid($oAccount->Id . ':' . $sFolder . ':' . $oMessage->getUid()); |
| 2365: | } |
| 2366: | $aAllMessages = array_merge($aAllMessages, $aMessages); |
| 2367: | } |
| 2368: | |
| 2369: | |
| 2370: | usort($aAllMessages, function ($a, $b) use ($SortOrder) { |
| 2371: | if ($SortOrder === \Aurora\System\Enums\SortOrder::DESC) { |
| 2372: | return ($a->getReceivedOrDateTimeStamp() < $b->getReceivedOrDateTimeStamp()) ? 1 : -1; |
| 2373: | } else { |
| 2374: | return ($a->getReceivedOrDateTimeStamp() > $b->getReceivedOrDateTimeStamp()) ? 1 : -1; |
| 2375: | } |
| 2376: | }); |
| 2377: | |
| 2378: | $oMessageCollectionResult->Uids = array_map(function ($oMessage) { |
| 2379: | return $oMessage->getUnifiedUid(); |
| 2380: | }, $aAllMessages); |
| 2381: | |
| 2382: | $oMessageCollectionResult->MessageCount = $iMessagesCount; |
| 2383: | $oMessageCollectionResult->MessageResultCount = $iMessagesResultCount; |
| 2384: | $oMessageCollectionResult->MessageUnseenCount = $iMessagesUnseenCount; |
| 2385: | $oMessageCollectionResult->UidNext = implode('.', $aNextUids); |
| 2386: | $oMessageCollectionResult->FolderHash = implode('.', $aFoldersHash); |
| 2387: | $oMessageCollectionResult->AddArray($aAllMessages); |
| 2388: | |
| 2389: | return $oMessageCollectionResult; |
| 2390: | } |
| 2391: | |
| 2392: | public function GetUnifiedMailboxMessages($UserId, $Folder = 'INBOX', $Offset = 0, $Limit = 20, $Search = '', $Filters = '', $UseThreading = false, $InboxUidnext = '', $SortOrder = \Aurora\System\Enums\SortOrder::DESC) |
| 2393: | { |
| 2394: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 2395: | \Aurora\System\Api::CheckAccess($UserId); |
| 2396: | if (!$this->oModuleSettings->AllowUnifiedInbox) { |
| 2397: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::AccessDenied); |
| 2398: | } |
| 2399: | |
| 2400: | $aFilters = array(); |
| 2401: | $sFilters = \strtolower(\trim((string) $Filters)); |
| 2402: | if (0 < \strlen($sFilters)) { |
| 2403: | $aFilters = \array_filter(\explode(',', $sFilters), function ($sValue) { |
| 2404: | return '' !== trim($sValue); |
| 2405: | }); |
| 2406: | } |
| 2407: | |
| 2408: | $oMessageCollectionResult = \Aurora\Modules\Mail\Classes\MessageCollection::createInstance(); |
| 2409: | $oMessageCollectionResult->FolderName = $Folder; |
| 2410: | $oMessageCollectionResult->Limit = $Limit; |
| 2411: | $oMessageCollectionResult->Offset = $Offset; |
| 2412: | $oMessageCollectionResult->Search = $Search; |
| 2413: | $oMessageCollectionResult->Filters = implode(',', $aFilters); |
| 2414: | |
| 2415: | $aAccounts = $this->getAccountsManager()->getUserAccounts($UserId); |
| 2416: | $aAccountsCache = []; |
| 2417: | $aUids = []; |
| 2418: | $aAccountUids = []; |
| 2419: | $iMessagesCount = 0; |
| 2420: | $iMessagesResultCount = 0; |
| 2421: | $iMessagesUnseenCount = 0; |
| 2422: | $aFoldersHash = []; |
| 2423: | |
| 2424: | $sSortBy = 'ARRIVAL'; |
| 2425: | $sSortOrder = $SortOrder === \Aurora\System\Enums\SortOrder::DESC ? 'REVERSE' : ''; |
| 2426: | |
| 2427: | foreach ($aAccounts as $oAccount) { |
| 2428: | if ($oAccount->IncludeInUnifiedMailbox) { |
| 2429: | $aAccountsCache[$oAccount->Id]['Account'] = $oAccount; |
| 2430: | $aAccountUids[$oAccount->Id] = []; |
| 2431: | $sSearch = $Search; |
| 2432: | |
| 2433: | $aFolders = $this->getFoldersForSearch($oAccount, $Folder, $Search, $sSearch); |
| 2434: | |
| 2435: | $aFolderFullNamesRaw = array_map(function ($oFolder) { |
| 2436: | return $oFolder->getRawFullName(); |
| 2437: | }, $aFolders); |
| 2438: | |
| 2439: | $aFoldersInfo = $this->getMailManager()->getFolderListInformation($oAccount, $aFolderFullNamesRaw, true); |
| 2440: | foreach ($aFolderFullNamesRaw as $sFolder) { |
| 2441: | $aUnifiedInfo = $this->getMailManager()->getUnifiedMailboxMessagesInfo( |
| 2442: | $oAccount, |
| 2443: | $sFolder, |
| 2444: | $sSearch, |
| 2445: | $aFilters, |
| 2446: | $UseThreading, |
| 2447: | $Offset + $Limit, |
| 2448: | $sSortBy, |
| 2449: | $sSortOrder |
| 2450: | ); |
| 2451: | if (is_array($aUnifiedInfo['Uids']) && count($aUnifiedInfo['Uids']) > 0) { |
| 2452: | foreach ($aUnifiedInfo['Uids'] as $iKey => $aUid) { |
| 2453: | $aUnifiedInfo['Uids'][$iKey]['folder'] = $sFolder; |
| 2454: | } |
| 2455: | $aUids = array_merge( |
| 2456: | $aUids, |
| 2457: | $aUnifiedInfo['Uids'] |
| 2458: | ); |
| 2459: | } |
| 2460: | |
| 2461: | $iMessagesCount += (int) $aFoldersInfo[$sFolder][0]; |
| 2462: | $iMessagesResultCount += $aUnifiedInfo['ResultCount']; |
| 2463: | $iMessagesUnseenCount += $aFoldersInfo[$sFolder][1]; |
| 2464: | $aFoldersHash[] = $aFoldersInfo[$sFolder][3]; |
| 2465: | } |
| 2466: | } |
| 2467: | } |
| 2468: | |
| 2469: | |
| 2470: | usort($aUids, function ($a, $b) use ($SortOrder) { |
| 2471: | if ($SortOrder === \Aurora\System\Enums\SortOrder::DESC) { |
| 2472: | return (strtotime($a['internaldate']) < strtotime($b['internaldate'])) ? 1 : -1; |
| 2473: | } else { |
| 2474: | return (strtotime($a['internaldate']) > strtotime($b['internaldate'])) ? 1 : -1; |
| 2475: | } |
| 2476: | }); |
| 2477: | if (count($aUids) >= 0) { |
| 2478: | $aUids = array_slice($aUids, $Offset, $Limit); |
| 2479: | } |
| 2480: | |
| 2481: | $aAllMessages = []; |
| 2482: | $aNextUids = []; |
| 2483: | |
| 2484: | $aInboxUidsNext = []; |
| 2485: | if (!empty($InboxUidnext)) { |
| 2486: | $aInboxUids = \explode('.', $InboxUidnext); |
| 2487: | foreach ($aInboxUids as $aUid) { |
| 2488: | $aUidsNext = \explode(':', $aUid); |
| 2489: | if (count($aUidsNext) === 3) { |
| 2490: | $aInboxUidsNext[$aUidsNext[0]][$aUidsNext[1]] = $aUidsNext[2]; |
| 2491: | } |
| 2492: | } |
| 2493: | } |
| 2494: | |
| 2495: | foreach ($aUids as $aUid) { |
| 2496: | $aAccountUids[$aUid['accountid']][$aUid['folder']][] = $aUid['uid']; |
| 2497: | } |
| 2498: | foreach ($aAccountUids as $iAccountId => $aFolders) { |
| 2499: | $oAccount = $aAccountsCache[$iAccountId]['Account']; |
| 2500: | foreach ($aFolders as $sFolder => $aFolderUids) { |
| 2501: | $sInboxUidnext = isset($aInboxUidsNext[$iAccountId][$sFolder]) ? $aInboxUidsNext[$iAccountId][$sFolder] : ''; |
| 2502: | $oMessageCollection = $this->getMailManager()->getMessageListByUids( |
| 2503: | $oAccount, |
| 2504: | $sFolder, |
| 2505: | $aFolderUids, |
| 2506: | $sInboxUidnext |
| 2507: | ); |
| 2508: | |
| 2509: | if ($UseThreading) { |
| 2510: | $oMessageCollection->ForeachList(function ( $oMessage) use ($aUids, $iAccountId, $sFolder) { |
| 2511: | $iUid = $oMessage->getUid(); |
| 2512: | $aUidInfo = current(array_filter($aUids, function ($aUid) use ($iAccountId, $iUid, $sFolder) { |
| 2513: | return $aUid['folder'] === $sFolder && $aUid['accountid'] === $iAccountId && $aUid['uid'] == $iUid; |
| 2514: | })); |
| 2515: | if (isset($aUidInfo['threads']) && is_array($aUidInfo['threads'])) { |
| 2516: | $oMessage->setThreads($aUidInfo['threads']); |
| 2517: | } |
| 2518: | }); |
| 2519: | } |
| 2520: | $sPrefix = $oAccount->Id . ':' . $sFolder . ':'; |
| 2521: | |
| 2522: | foreach ($oMessageCollection->New as $aNew) { |
| 2523: | $aNew['AccountId'] = $oAccount->Id; |
| 2524: | $aNew['Folder'] = $sFolder; |
| 2525: | |
| 2526: | $oMessageCollectionResult->New[] = $aNew; |
| 2527: | } |
| 2528: | |
| 2529: | $aNextUids[] = $sPrefix . $oMessageCollection->UidNext; |
| 2530: | $aMessages = $oMessageCollection->GetAsArray(); |
| 2531: | foreach ($aMessages as $oMessage) { |
| 2532: | |
| 2533: | |
| 2534: | $oMessage->setUnifiedUid($sPrefix . $oMessage->getUid()); |
| 2535: | } |
| 2536: | $aAllMessages = array_merge($aAllMessages, $aMessages); |
| 2537: | } |
| 2538: | } |
| 2539: | |
| 2540: | |
| 2541: | usort($aAllMessages, function ($a, $b) use ($SortOrder) { |
| 2542: | if ($SortOrder === \Aurora\System\Enums\SortOrder::DESC) { |
| 2543: | return ($a->getReceivedOrDateTimeStamp() < $b->getReceivedOrDateTimeStamp()) ? 1 : -1; |
| 2544: | } else { |
| 2545: | return ($a->getReceivedOrDateTimeStamp() > $b->getReceivedOrDateTimeStamp()) ? 1 : -1; |
| 2546: | } |
| 2547: | }); |
| 2548: | |
| 2549: | $oMessageCollectionResult->Uids = array_map(function ($oMessage) { |
| 2550: | return $oMessage->getUnifiedUid(); |
| 2551: | }, $aAllMessages); |
| 2552: | |
| 2553: | $oMessageCollectionResult->MessageCount = $iMessagesCount; |
| 2554: | $oMessageCollectionResult->MessageResultCount = $iMessagesResultCount; |
| 2555: | $oMessageCollectionResult->MessageUnseenCount = $iMessagesUnseenCount; |
| 2556: | $oMessageCollectionResult->UidNext = implode('.', $aNextUids); |
| 2557: | $oMessageCollectionResult->FolderHash = implode('.', $aFoldersHash); |
| 2558: | $oMessageCollectionResult->AddArray($aAllMessages); |
| 2559: | |
| 2560: | return $oMessageCollectionResult; |
| 2561: | } |
| 2562: | |
| 2563: | public function GetMessagesInfo($AccountID, $Folder, $Search = null, $UseThreading = false, $SortBy = null, $SortOrder = null) |
| 2564: | { |
| 2565: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 2566: | |
| 2567: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 2568: | |
| 2569: | self::checkAccountAccess($oAccount); |
| 2570: | |
| 2571: | $aSortInfo = $this->getSortInfo($SortBy, $SortOrder); |
| 2572: | |
| 2573: | $sSortBy = \strtoupper($aSortInfo[0]); |
| 2574: | $sSortOrder = $aSortInfo[1] === \Aurora\System\Enums\SortOrder::DESC ? 'REVERSE' : ''; |
| 2575: | |
| 2576: | return $this->getMailManager()->GetMessagesInfo( |
| 2577: | $oAccount, |
| 2578: | $Folder, |
| 2579: | $Search, |
| 2580: | $UseThreading, |
| 2581: | $sSortBy, |
| 2582: | $sSortOrder |
| 2583: | ); |
| 2584: | } |
| 2585: | |
| 2586: | public function GetUnifiedRelevantFoldersInformation($AccountsData) |
| 2587: | { |
| 2588: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 2589: | if (!$this->oModuleSettings->AllowUnifiedInbox) { |
| 2590: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::AccessDenied); |
| 2591: | } |
| 2592: | |
| 2593: | if (!\is_array($AccountsData) || 0 === \count($AccountsData)) { |
| 2594: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::InvalidInputParameter); |
| 2595: | } |
| 2596: | |
| 2597: | $aResult = []; |
| 2598: | $iUnifiedCount = 0; |
| 2599: | $iUnifiedUnseenCount = 0; |
| 2600: | $aUnifiedUidNext = []; |
| 2601: | $aUnifiedFolderHash = []; |
| 2602: | foreach ($AccountsData as $aAccountData) { |
| 2603: | $iAccountId = $aAccountData['AccountID']; |
| 2604: | $oAccount = $this->getAccountsManager()->getAccountById($iAccountId); |
| 2605: | if ($oAccount instanceof Models\MailAccount) { |
| 2606: | self::checkAccountAccess($oAccount); |
| 2607: | $aCounts = self::Decorator()->GetRelevantFoldersInformation($iAccountId, $aAccountData['Folders'], $aAccountData['UseListStatusIfPossible']); |
| 2608: | $aCounts['AccountId'] = $iAccountId; |
| 2609: | $aResult[] = $aCounts; |
| 2610: | if (isset($aCounts['Counts']['INBOX']) && $oAccount->IncludeInUnifiedMailbox) { |
| 2611: | $iUnifiedCount += $aCounts['Counts']['INBOX'][0]; |
| 2612: | $iUnifiedUnseenCount += $aCounts['Counts']['INBOX'][1]; |
| 2613: | $aUnifiedUidNext[] = $iAccountId . ':' . $aCounts['Counts']['INBOX'][2]; |
| 2614: | $aUnifiedFolderHash[] = $iAccountId . ':' . $aCounts['Counts']['INBOX'][3]; |
| 2615: | } |
| 2616: | } |
| 2617: | } |
| 2618: | |
| 2619: | return [ |
| 2620: | 'Accounts' => $aResult, |
| 2621: | 'Unified' => [$iUnifiedCount, $iUnifiedUnseenCount, implode('.', $aUnifiedUidNext), implode('.', $aUnifiedFolderHash)] |
| 2622: | ]; |
| 2623: | } |
| 2624: | |
| 2625: | |
| 2626: | |
| 2627: | |
| 2628: | |
| 2629: | |
| 2630: | |
| 2631: | |
| 2632: | |
| 2633: | |
| 2634: | |
| 2635: | |
| 2636: | |
| 2637: | |
| 2638: | |
| 2639: | |
| 2640: | |
| 2641: | |
| 2642: | |
| 2643: | |
| 2644: | |
| 2645: | |
| 2646: | |
| 2647: | |
| 2648: | |
| 2649: | |
| 2650: | |
| 2651: | |
| 2652: | |
| 2653: | |
| 2654: | |
| 2655: | |
| 2656: | |
| 2657: | |
| 2658: | |
| 2659: | |
| 2660: | |
| 2661: | |
| 2662: | |
| 2663: | |
| 2664: | |
| 2665: | |
| 2666: | |
| 2667: | |
| 2668: | |
| 2669: | |
| 2670: | |
| 2671: | |
| 2672: | |
| 2673: | |
| 2674: | |
| 2675: | |
| 2676: | |
| 2677: | |
| 2678: | |
| 2679: | |
| 2680: | |
| 2681: | |
| 2682: | |
| 2683: | |
| 2684: | |
| 2685: | public function GetRelevantFoldersInformation($AccountID, $Folders, $UseListStatusIfPossible) |
| 2686: | { |
| 2687: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 2688: | |
| 2689: | if (!\is_array($Folders) || 0 === \count($Folders)) { |
| 2690: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::InvalidInputParameter); |
| 2691: | } |
| 2692: | |
| 2693: | $aResult = array(); |
| 2694: | |
| 2695: | try { |
| 2696: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 2697: | |
| 2698: | self::checkAccountAccess($oAccount); |
| 2699: | |
| 2700: | $aResult = $this->getMailManager()->getFolderListInformation($oAccount, $Folders, $UseListStatusIfPossible); |
| 2701: | } catch (\MailSo\Net\Exceptions\ConnectionException $oException) { |
| 2702: | throw $oException; |
| 2703: | } catch (\MailSo\Imap\Exceptions\LoginException $oException) { |
| 2704: | throw $oException; |
| 2705: | } catch (\Aurora\Modules\Mail\Exceptions\Exception $oException) { |
| 2706: | throw $oException; |
| 2707: | } catch (\Exception $oException) { |
| 2708: | \Aurora\System\Api::Log((string) $oException); |
| 2709: | } |
| 2710: | |
| 2711: | return array( |
| 2712: | 'Counts' => $aResult, |
| 2713: | ); |
| 2714: | } |
| 2715: | |
| 2716: | |
| 2717: | |
| 2718: | |
| 2719: | |
| 2720: | |
| 2721: | |
| 2722: | |
| 2723: | |
| 2724: | |
| 2725: | |
| 2726: | |
| 2727: | |
| 2728: | |
| 2729: | |
| 2730: | |
| 2731: | |
| 2732: | |
| 2733: | |
| 2734: | |
| 2735: | |
| 2736: | |
| 2737: | |
| 2738: | |
| 2739: | |
| 2740: | |
| 2741: | |
| 2742: | |
| 2743: | |
| 2744: | |
| 2745: | |
| 2746: | |
| 2747: | |
| 2748: | |
| 2749: | |
| 2750: | |
| 2751: | |
| 2752: | |
| 2753: | |
| 2754: | |
| 2755: | |
| 2756: | |
| 2757: | |
| 2758: | |
| 2759: | |
| 2760: | |
| 2761: | |
| 2762: | |
| 2763: | |
| 2764: | |
| 2765: | |
| 2766: | |
| 2767: | |
| 2768: | public function GetQuota($AccountID) |
| 2769: | { |
| 2770: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 2771: | |
| 2772: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 2773: | |
| 2774: | self::checkAccountAccess($oAccount); |
| 2775: | |
| 2776: | $aQuota = $this->getMailManager()->getQuota($oAccount); |
| 2777: | $iQuota = (is_array($aQuota) && isset($aQuota[1])) ? $aQuota[1] / 1024 : 0; |
| 2778: | $oUser = \Aurora\Modules\Core\Module::Decorator()->GetUserWithoutRoleCheck($oAccount->IdUser); |
| 2779: | $iUserSpaceLimitMb = ($oUser instanceof User) ? $oUser->getExtendedProp(self::GetName() . '::UserSpaceLimitMb') : 0; |
| 2780: | if ($iQuota !== $iUserSpaceLimitMb) { |
| 2781: | $this->updateAllocatedTenantSpace($oUser->IdTenant, $iQuota, $iUserSpaceLimitMb); |
| 2782: | $oUser->setExtendedProp(self::GetName() . '::UserSpaceLimitMb', $iQuota); |
| 2783: | $oUser->save(); |
| 2784: | } |
| 2785: | |
| 2786: | return $aQuota; |
| 2787: | } |
| 2788: | |
| 2789: | |
| 2790: | |
| 2791: | |
| 2792: | |
| 2793: | |
| 2794: | |
| 2795: | |
| 2796: | |
| 2797: | |
| 2798: | |
| 2799: | |
| 2800: | |
| 2801: | |
| 2802: | |
| 2803: | |
| 2804: | |
| 2805: | |
| 2806: | |
| 2807: | |
| 2808: | |
| 2809: | |
| 2810: | |
| 2811: | |
| 2812: | |
| 2813: | |
| 2814: | |
| 2815: | |
| 2816: | |
| 2817: | |
| 2818: | |
| 2819: | |
| 2820: | |
| 2821: | |
| 2822: | |
| 2823: | |
| 2824: | |
| 2825: | |
| 2826: | |
| 2827: | |
| 2828: | |
| 2829: | |
| 2830: | |
| 2831: | |
| 2832: | |
| 2833: | |
| 2834: | |
| 2835: | |
| 2836: | |
| 2837: | |
| 2838: | |
| 2839: | |
| 2840: | |
| 2841: | |
| 2842: | |
| 2843: | |
| 2844: | |
| 2845: | |
| 2846: | |
| 2847: | |
| 2848: | |
| 2849: | |
| 2850: | |
| 2851: | |
| 2852: | |
| 2853: | |
| 2854: | |
| 2855: | |
| 2856: | |
| 2857: | |
| 2858: | |
| 2859: | |
| 2860: | |
| 2861: | |
| 2862: | |
| 2863: | |
| 2864: | |
| 2865: | |
| 2866: | |
| 2867: | |
| 2868: | |
| 2869: | |
| 2870: | |
| 2871: | |
| 2872: | |
| 2873: | |
| 2874: | |
| 2875: | |
| 2876: | |
| 2877: | |
| 2878: | |
| 2879: | |
| 2880: | |
| 2881: | |
| 2882: | |
| 2883: | |
| 2884: | |
| 2885: | |
| 2886: | |
| 2887: | |
| 2888: | |
| 2889: | |
| 2890: | |
| 2891: | |
| 2892: | |
| 2893: | |
| 2894: | |
| 2895: | |
| 2896: | |
| 2897: | |
| 2898: | |
| 2899: | |
| 2900: | |
| 2901: | public function GetMessagesBodies($AccountID, $Folder, $Uids, $MessageBodyTruncationThreshold = null) |
| 2902: | { |
| 2903: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 2904: | |
| 2905: | if (0 === \strlen(\trim($Folder)) || !\is_array($Uids) || 0 === \count($Uids)) { |
| 2906: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::InvalidInputParameter); |
| 2907: | } |
| 2908: | |
| 2909: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 2910: | $oImapClient = &$this->getMailManager()->_getImapClient($oAccount); |
| 2911: | $oImapClient->FolderExamine($Folder); |
| 2912: | |
| 2913: | $aBodystructuresFetchResponse = $oImapClient->Fetch(array( |
| 2914: | \MailSo\Imap\Enumerations\FetchType::BODYSTRUCTURE), \implode(',', $Uids), true); |
| 2915: | $aBodystructures = []; |
| 2916: | foreach ($aBodystructuresFetchResponse as $oBodystructureFetchResponse) { |
| 2917: | $aBodystructures[(int) $oBodystructureFetchResponse->GetFetchValue('UID')] = $oBodystructureFetchResponse; |
| 2918: | } |
| 2919: | unset($aBodystructuresFetchResponse); |
| 2920: | |
| 2921: | |
| 2922: | |
| 2923: | $aList = array(); |
| 2924: | foreach ($Uids as $iUid) { |
| 2925: | if (\is_numeric($iUid)) { |
| 2926: | $oBody = isset($aBodystructures[$iUid]) ? $aBodystructures[$iUid] : null; |
| 2927: | $oMessage = $this->Decorator()->GetMessage($AccountID, $Folder, (string) $iUid, '', $MessageBodyTruncationThreshold, $oBody); |
| 2928: | if ($oMessage instanceof \Aurora\Modules\Mail\Classes\Message) { |
| 2929: | $aList[] = $oMessage; |
| 2930: | } |
| 2931: | |
| 2932: | unset($oMessage); |
| 2933: | } |
| 2934: | } |
| 2935: | |
| 2936: | return $aList; |
| 2937: | } |
| 2938: | |
| 2939: | |
| 2940: | |
| 2941: | |
| 2942: | |
| 2943: | |
| 2944: | |
| 2945: | |
| 2946: | |
| 2947: | |
| 2948: | |
| 2949: | |
| 2950: | |
| 2951: | |
| 2952: | |
| 2953: | |
| 2954: | |
| 2955: | |
| 2956: | |
| 2957: | |
| 2958: | |
| 2959: | |
| 2960: | |
| 2961: | |
| 2962: | |
| 2963: | |
| 2964: | |
| 2965: | |
| 2966: | |
| 2967: | |
| 2968: | |
| 2969: | |
| 2970: | |
| 2971: | |
| 2972: | |
| 2973: | |
| 2974: | |
| 2975: | |
| 2976: | |
| 2977: | |
| 2978: | |
| 2979: | |
| 2980: | |
| 2981: | |
| 2982: | |
| 2983: | |
| 2984: | |
| 2985: | |
| 2986: | |
| 2987: | |
| 2988: | |
| 2989: | |
| 2990: | |
| 2991: | |
| 2992: | |
| 2993: | |
| 2994: | |
| 2995: | |
| 2996: | |
| 2997: | |
| 2998: | |
| 2999: | |
| 3000: | |
| 3001: | |
| 3002: | |
| 3003: | |
| 3004: | |
| 3005: | |
| 3006: | |
| 3007: | |
| 3008: | |
| 3009: | |
| 3010: | |
| 3011: | |
| 3012: | |
| 3013: | |
| 3014: | |
| 3015: | |
| 3016: | |
| 3017: | |
| 3018: | |
| 3019: | |
| 3020: | |
| 3021: | |
| 3022: | |
| 3023: | |
| 3024: | |
| 3025: | |
| 3026: | |
| 3027: | |
| 3028: | |
| 3029: | |
| 3030: | |
| 3031: | |
| 3032: | |
| 3033: | |
| 3034: | |
| 3035: | |
| 3036: | |
| 3037: | |
| 3038: | |
| 3039: | |
| 3040: | |
| 3041: | |
| 3042: | |
| 3043: | |
| 3044: | |
| 3045: | |
| 3046: | |
| 3047: | |
| 3048: | |
| 3049: | |
| 3050: | public function GetMessage($AccountID, $Folder, $Uid, $Rfc822MimeIndex = '', $MessageBodyTruncationThreshold = null, $oBody = null) |
| 3051: | { |
| 3052: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 3053: | |
| 3054: | $iUid = 0 < \strlen($Uid) && \is_numeric($Uid) ? (int) $Uid : 0; |
| 3055: | |
| 3056: | if (0 === \strlen(\trim($Folder)) || 0 >= $iUid) { |
| 3057: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::InvalidInputParameter); |
| 3058: | } |
| 3059: | |
| 3060: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 3061: | |
| 3062: | self::checkAccountAccess($oAccount); |
| 3063: | |
| 3064: | if (0 === \strlen($Folder) || !\is_numeric($iUid) || 0 >= (int) $iUid) { |
| 3065: | throw new InvalidArgumentException(); |
| 3066: | } |
| 3067: | |
| 3068: | $oImapClient = &$this->getMailManager()->_getImapClient($oAccount); |
| 3069: | |
| 3070: | $oImapClient->FolderExamine($Folder); |
| 3071: | |
| 3072: | $oMessage = false; |
| 3073: | |
| 3074: | $aTextMimeIndexes = array(); |
| 3075: | |
| 3076: | if (!isset($oBody)) { |
| 3077: | $aFetchResponse = $oImapClient->Fetch(array( |
| 3078: | \MailSo\Imap\Enumerations\FetchType::BODYSTRUCTURE), $iUid, true); |
| 3079: | $oBodyStructure = (0 < \count($aFetchResponse)) ? $aFetchResponse[0]->GetFetchBodyStructure($Rfc822MimeIndex) : null; |
| 3080: | } else { |
| 3081: | $oBodyStructure = $oBody->GetFetchBodyStructure($Rfc822MimeIndex); |
| 3082: | } |
| 3083: | |
| 3084: | $aCustomParts = array(); |
| 3085: | if ($oBodyStructure) { |
| 3086: | $aTextParts = $oBodyStructure->SearchHtmlOrPlainParts(); |
| 3087: | if (\is_array($aTextParts) && 0 < \count($aTextParts)) { |
| 3088: | foreach ($aTextParts as $oPart) { |
| 3089: | $aTextMimeIndexes[] = array($oPart->PartID(), $oPart->Size()); |
| 3090: | } |
| 3091: | } |
| 3092: | |
| 3093: | $aParts = $oBodyStructure->GetAllParts(); |
| 3094: | |
| 3095: | $this->broadcastEvent( |
| 3096: | 'GetBodyStructureParts', |
| 3097: | $aParts, |
| 3098: | $aCustomParts |
| 3099: | ); |
| 3100: | } |
| 3101: | |
| 3102: | $bTruncated = false; |
| 3103: | $aFetchItems = array( |
| 3104: | \MailSo\Imap\Enumerations\FetchType::INDEX, |
| 3105: | \MailSo\Imap\Enumerations\FetchType::UID, |
| 3106: | \MailSo\Imap\Enumerations\FetchType::RFC822_SIZE, |
| 3107: | \MailSo\Imap\Enumerations\FetchType::INTERNALDATE, |
| 3108: | \MailSo\Imap\Enumerations\FetchType::FLAGS, |
| 3109: | 0 < strlen($Rfc822MimeIndex) |
| 3110: | ? \MailSo\Imap\Enumerations\FetchType::BODY_PEEK . '[' . $Rfc822MimeIndex . '.HEADER]' |
| 3111: | : \MailSo\Imap\Enumerations\FetchType::BODY_HEADER_PEEK |
| 3112: | ); |
| 3113: | |
| 3114: | if (0 < \count($aTextMimeIndexes)) { |
| 3115: | if (0 < \strlen($Rfc822MimeIndex) && \is_numeric($Rfc822MimeIndex)) { |
| 3116: | $sLine = \MailSo\Imap\Enumerations\FetchType::BODY_PEEK . '[' . $aTextMimeIndexes[0][0] . '.1]'; |
| 3117: | if (\is_numeric($MessageBodyTruncationThreshold) && 0 < $MessageBodyTruncationThreshold && $MessageBodyTruncationThreshold < $aTextMimeIndexes[0][1]) { |
| 3118: | $sLine .= '<0.' . ((int) $MessageBodyTruncationThreshold) . '>'; |
| 3119: | $bTruncated = true; |
| 3120: | } |
| 3121: | |
| 3122: | $aFetchItems[] = $sLine; |
| 3123: | } else { |
| 3124: | foreach ($aTextMimeIndexes as $aTextMimeIndex) { |
| 3125: | $sLine = \MailSo\Imap\Enumerations\FetchType::BODY_PEEK . '[' . $aTextMimeIndex[0] . ']'; |
| 3126: | if (\is_numeric($MessageBodyTruncationThreshold) && 0 < $MessageBodyTruncationThreshold && $MessageBodyTruncationThreshold < $aTextMimeIndex[1]) { |
| 3127: | $sLine .= '<0.' . ((int) $MessageBodyTruncationThreshold) . '>'; |
| 3128: | $bTruncated = true; |
| 3129: | } |
| 3130: | |
| 3131: | $aFetchItems[] = $sLine; |
| 3132: | } |
| 3133: | } |
| 3134: | } |
| 3135: | |
| 3136: | foreach ($aCustomParts as $oCustomPart) { |
| 3137: | $aFetchItems[] = \MailSo\Imap\Enumerations\FetchType::BODY_PEEK . '[' . $oCustomPart->PartID() . ']'; |
| 3138: | } |
| 3139: | |
| 3140: | if (!$oBodyStructure) { |
| 3141: | $aFetchItems[] = \MailSo\Imap\Enumerations\FetchType::BODYSTRUCTURE; |
| 3142: | } |
| 3143: | |
| 3144: | $aFetchResponse = $oImapClient->Fetch($aFetchItems, $iUid, true); |
| 3145: | if (0 < \count($aFetchResponse)) { |
| 3146: | $oMessage = \Aurora\Modules\Mail\Classes\Message::createInstance($Folder, $aFetchResponse[0], $oBodyStructure, $Rfc822MimeIndex, $bTruncated); |
| 3147: | } |
| 3148: | |
| 3149: | if ($oMessage) { |
| 3150: | $oMessage->setAccountId($oAccount->Id); |
| 3151: | $sFromEmail = ''; |
| 3152: | $oFromCollection = $oMessage->getFrom(); |
| 3153: | if ($oFromCollection && 0 < $oFromCollection->Count()) { |
| 3154: | $oFrom = &$oFromCollection->GetByIndex(0); |
| 3155: | if ($oFrom) { |
| 3156: | $sFromEmail = trim($oFrom->GetEmail()); |
| 3157: | } |
| 3158: | } |
| 3159: | |
| 3160: | if (0 < \strlen($sFromEmail)) { |
| 3161: | $bAlwaysShowImagesInMessage = !!$this->oModuleSettings->AlwaysShowImagesInMessage; |
| 3162: | $oMessage->setSafety($bAlwaysShowImagesInMessage ? true : |
| 3163: | $this->getMailManager()->isSafetySender($oAccount->IdUser, $sFromEmail)); |
| 3164: | } |
| 3165: | |
| 3166: | $aData = array(); |
| 3167: | foreach ($aCustomParts as $oCustomPart) { |
| 3168: | $sData = $aFetchResponse[0]->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::BODY . '[' . $oCustomPart->PartID() . ']'); |
| 3169: | if (!empty($sData)) { |
| 3170: | $sData = \MailSo\Base\Utils::DecodeEncodingValue($sData, $oCustomPart->MailEncodingName()); |
| 3171: | $sData = \MailSo\Base\Utils::ConvertEncoding( |
| 3172: | $sData, |
| 3173: | \MailSo\Base\Utils::NormalizeCharset($oCustomPart->Charset(), true), |
| 3174: | \MailSo\Base\Enumerations\Charset::UTF_8 |
| 3175: | ); |
| 3176: | } |
| 3177: | $aData[] = array( |
| 3178: | 'Data' => $sData, |
| 3179: | 'Part' => $oCustomPart |
| 3180: | ); |
| 3181: | } |
| 3182: | |
| 3183: | $this->broadcastEvent('ExtendMessageData', $aData, $oMessage); |
| 3184: | } |
| 3185: | |
| 3186: | if (!($oMessage instanceof \Aurora\Modules\Mail\Classes\Message)) { |
| 3187: | throw new \Aurora\Modules\Mail\Exceptions\Exception(Enums\ErrorCodes::CannotGetMessage); |
| 3188: | } |
| 3189: | |
| 3190: | return $oMessage; |
| 3191: | } |
| 3192: | |
| 3193: | |
| 3194: | |
| 3195: | |
| 3196: | |
| 3197: | |
| 3198: | |
| 3199: | |
| 3200: | |
| 3201: | public function Unsubscribe($AccountID, $Folder, $Uid) |
| 3202: | { |
| 3203: | $mResult = false; |
| 3204: | |
| 3205: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 3206: | |
| 3207: | self::checkAccountAccess($oAccount); |
| 3208: | |
| 3209: | $validate = false; |
| 3210: | $this->getMailManager()->directMessageToStream( |
| 3211: | $oAccount, |
| 3212: | function ($rResource) use (&$validate) { |
| 3213: | if (\is_resource($rResource)) { |
| 3214: | $rawMessage = stream_get_contents($rResource); |
| 3215: | |
| 3216: | try { |
| 3217: | $dkimValidator = new DKIMValidator($rawMessage); |
| 3218: | $validateResult = @$dkimValidator->validate(); |
| 3219: | |
| 3220: | $validateCount = count($validateResult); |
| 3221: | $validateSuccessCount = 0; |
| 3222: | if ($validateCount > 0) { |
| 3223: | foreach ($validateResult as $val) { |
| 3224: | if ($val[0]['status'] === 'SUCCESS') { |
| 3225: | $validateSuccessCount++; |
| 3226: | } |
| 3227: | } |
| 3228: | } |
| 3229: | |
| 3230: | $validate = $validateCount === $validateSuccessCount; |
| 3231: | } catch (DKIMException $e) { |
| 3232: | $validate = false; |
| 3233: | } |
| 3234: | } |
| 3235: | }, |
| 3236: | $Folder, |
| 3237: | $Uid |
| 3238: | ); |
| 3239: | |
| 3240: | if ($validate) { |
| 3241: | $oMessage = self::Decorator()->GetMessage($AccountID, $Folder, $Uid); |
| 3242: | if ($oMessage instanceof Message) { |
| 3243: | $aParsedHeaders = $oMessage->parseUnsubscribeHeaders(); |
| 3244: | |
| 3245: | if ($aParsedHeaders['OneClick']) { |
| 3246: | if (!empty($aParsedHeaders['Url'])) { |
| 3247: | $iCode = 0; |
| 3248: | $this->oHttp->SendPostRequest( |
| 3249: | $aParsedHeaders['Url'], |
| 3250: | ['List-Unsubscribe' => 'One-Click'], |
| 3251: | '', |
| 3252: | $iCode, |
| 3253: | \Aurora\Api::SystemLogger() |
| 3254: | ); |
| 3255: | $mResult = ($iCode == 200); |
| 3256: | } elseif (!empty($aParsedHeaders['Email'])) { |
| 3257: | $sEmailCheck = str_ireplace('mailto:', '', $aParsedHeaders['Email']); |
| 3258: | $aEmailData = explode('?', $sEmailCheck); |
| 3259: | $mResult = self::Decorator()->SendMessage( |
| 3260: | $AccountID, |
| 3261: | null, |
| 3262: | null, |
| 3263: | 0, |
| 3264: | [], |
| 3265: | "", |
| 3266: | $aEmailData[0], |
| 3267: | "", |
| 3268: | "", |
| 3269: | [], |
| 3270: | 'Unsubscribe' |
| 3271: | ); |
| 3272: | } |
| 3273: | } |
| 3274: | } |
| 3275: | } |
| 3276: | |
| 3277: | return $mResult; |
| 3278: | } |
| 3279: | |
| 3280: | public function GetMessageByMessageID($AccountID, $Folder, $UidFrom, $MessageID) |
| 3281: | { |
| 3282: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 3283: | |
| 3284: | self::checkAccountAccess($oAccount); |
| 3285: | $mResult = false; |
| 3286: | $iUID = $this->getMailManager()->getMessageUIDByMessageID($oAccount, $Folder, $UidFrom, $MessageID); |
| 3287: | if ($iUID !== false) { |
| 3288: | $aMessages = $this->GetMessagesBodies($AccountID, $Folder, [$iUID]); |
| 3289: | if (is_array($aMessages) && count($aMessages) > 0) { |
| 3290: | $mResult = $aMessages[0]; |
| 3291: | } |
| 3292: | } |
| 3293: | |
| 3294: | return $mResult; |
| 3295: | } |
| 3296: | |
| 3297: | |
| 3298: | |
| 3299: | |
| 3300: | |
| 3301: | |
| 3302: | |
| 3303: | |
| 3304: | |
| 3305: | |
| 3306: | |
| 3307: | |
| 3308: | |
| 3309: | |
| 3310: | |
| 3311: | |
| 3312: | |
| 3313: | |
| 3314: | |
| 3315: | |
| 3316: | |
| 3317: | |
| 3318: | |
| 3319: | |
| 3320: | |
| 3321: | |
| 3322: | |
| 3323: | |
| 3324: | |
| 3325: | |
| 3326: | |
| 3327: | |
| 3328: | |
| 3329: | |
| 3330: | |
| 3331: | |
| 3332: | |
| 3333: | |
| 3334: | |
| 3335: | |
| 3336: | |
| 3337: | |
| 3338: | |
| 3339: | |
| 3340: | |
| 3341: | |
| 3342: | |
| 3343: | |
| 3344: | |
| 3345: | |
| 3346: | |
| 3347: | |
| 3348: | |
| 3349: | |
| 3350: | |
| 3351: | |
| 3352: | |
| 3353: | |
| 3354: | |
| 3355: | public function SetMessagesSeen($AccountID, $Folder, $Uids, $SetAction) |
| 3356: | { |
| 3357: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 3358: | |
| 3359: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 3360: | |
| 3361: | self::checkAccountAccess($oAccount); |
| 3362: | |
| 3363: | return $this->setMessageFlag($AccountID, $Folder, $Uids, $SetAction, \MailSo\Imap\Enumerations\MessageFlag::SEEN); |
| 3364: | } |
| 3365: | |
| 3366: | |
| 3367: | |
| 3368: | |
| 3369: | |
| 3370: | |
| 3371: | |
| 3372: | |
| 3373: | |
| 3374: | |
| 3375: | |
| 3376: | |
| 3377: | |
| 3378: | |
| 3379: | |
| 3380: | |
| 3381: | |
| 3382: | |
| 3383: | |
| 3384: | |
| 3385: | |
| 3386: | |
| 3387: | |
| 3388: | |
| 3389: | |
| 3390: | |
| 3391: | |
| 3392: | |
| 3393: | |
| 3394: | |
| 3395: | |
| 3396: | |
| 3397: | |
| 3398: | |
| 3399: | |
| 3400: | |
| 3401: | |
| 3402: | |
| 3403: | |
| 3404: | |
| 3405: | |
| 3406: | |
| 3407: | |
| 3408: | |
| 3409: | |
| 3410: | |
| 3411: | |
| 3412: | |
| 3413: | |
| 3414: | |
| 3415: | |
| 3416: | |
| 3417: | |
| 3418: | |
| 3419: | |
| 3420: | |
| 3421: | |
| 3422: | |
| 3423: | |
| 3424: | public function SetMessageFlagged($AccountID, $Folder, $Uids, $SetAction) |
| 3425: | { |
| 3426: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 3427: | |
| 3428: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 3429: | |
| 3430: | self::checkAccountAccess($oAccount); |
| 3431: | |
| 3432: | return $this->setMessageFlag($AccountID, $Folder, $Uids, $SetAction, \MailSo\Imap\Enumerations\MessageFlag::FLAGGED); |
| 3433: | } |
| 3434: | |
| 3435: | |
| 3436: | |
| 3437: | |
| 3438: | |
| 3439: | |
| 3440: | |
| 3441: | |
| 3442: | |
| 3443: | |
| 3444: | |
| 3445: | |
| 3446: | |
| 3447: | |
| 3448: | |
| 3449: | |
| 3450: | |
| 3451: | |
| 3452: | |
| 3453: | |
| 3454: | |
| 3455: | |
| 3456: | |
| 3457: | |
| 3458: | |
| 3459: | |
| 3460: | |
| 3461: | |
| 3462: | |
| 3463: | |
| 3464: | |
| 3465: | |
| 3466: | |
| 3467: | |
| 3468: | |
| 3469: | |
| 3470: | |
| 3471: | |
| 3472: | |
| 3473: | |
| 3474: | |
| 3475: | |
| 3476: | |
| 3477: | |
| 3478: | |
| 3479: | |
| 3480: | |
| 3481: | |
| 3482: | |
| 3483: | |
| 3484: | |
| 3485: | |
| 3486: | |
| 3487: | |
| 3488: | |
| 3489: | |
| 3490: | public function SetAllMessagesSeen($AccountID, $Folder) |
| 3491: | { |
| 3492: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 3493: | |
| 3494: | if (0 === \strlen(\trim($Folder))) { |
| 3495: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::InvalidInputParameter); |
| 3496: | } |
| 3497: | |
| 3498: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 3499: | |
| 3500: | self::checkAccountAccess($oAccount); |
| 3501: | |
| 3502: | return $this->getMailManager()->setMessageFlag( |
| 3503: | $oAccount, |
| 3504: | $Folder, |
| 3505: | array(), |
| 3506: | \MailSo\Imap\Enumerations\MessageFlag::SEEN, |
| 3507: | \Aurora\Modules\Mail\Enums\MessageStoreAction::Add, |
| 3508: | true |
| 3509: | ); |
| 3510: | } |
| 3511: | |
| 3512: | |
| 3513: | |
| 3514: | |
| 3515: | |
| 3516: | |
| 3517: | |
| 3518: | |
| 3519: | |
| 3520: | |
| 3521: | |
| 3522: | |
| 3523: | |
| 3524: | |
| 3525: | |
| 3526: | |
| 3527: | |
| 3528: | |
| 3529: | |
| 3530: | |
| 3531: | |
| 3532: | |
| 3533: | |
| 3534: | |
| 3535: | |
| 3536: | |
| 3537: | |
| 3538: | |
| 3539: | |
| 3540: | |
| 3541: | |
| 3542: | |
| 3543: | |
| 3544: | |
| 3545: | |
| 3546: | |
| 3547: | |
| 3548: | |
| 3549: | |
| 3550: | |
| 3551: | |
| 3552: | |
| 3553: | |
| 3554: | |
| 3555: | |
| 3556: | |
| 3557: | |
| 3558: | |
| 3559: | |
| 3560: | |
| 3561: | |
| 3562: | |
| 3563: | |
| 3564: | |
| 3565: | |
| 3566: | |
| 3567: | |
| 3568: | |
| 3569: | |
| 3570: | public function CopyMessages($AccountID, $Folder, $ToFolder, $Uids) |
| 3571: | { |
| 3572: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 3573: | |
| 3574: | $aUids = \Aurora\System\Utils::ExplodeIntUids((string) $Uids); |
| 3575: | |
| 3576: | if (0 === \strlen(\trim($Folder)) || 0 === \strlen(\trim($ToFolder)) || !\is_array($aUids) || 0 === \count($aUids)) { |
| 3577: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::InvalidInputParameter); |
| 3578: | } |
| 3579: | |
| 3580: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 3581: | |
| 3582: | self::checkAccountAccess($oAccount); |
| 3583: | |
| 3584: | try { |
| 3585: | $this->getMailManager()->copyMessage($oAccount, $Folder, $ToFolder, $aUids); |
| 3586: | } catch (\MailSo\Imap\Exceptions\NegativeResponseException $oException) { |
| 3587: | $oResponse = $oException->GetLastResponse(); |
| 3588: | throw new \Aurora\Modules\Mail\Exceptions\Exception( |
| 3589: | Enums\ErrorCodes::CannotMoveMessageQuota, |
| 3590: | $oException, |
| 3591: | $oResponse instanceof \MailSo\Imap\Response ? $oResponse->Tag . ' ' . $oResponse->StatusOrIndex . ' ' . $oResponse->HumanReadable : '' |
| 3592: | ); |
| 3593: | } catch (\Exception $oException) { |
| 3594: | throw new \Aurora\Modules\Mail\Exceptions\Exception( |
| 3595: | Enums\ErrorCodes::CannotMoveMessage, |
| 3596: | $oException, |
| 3597: | $oException->getMessage() |
| 3598: | ); |
| 3599: | } |
| 3600: | |
| 3601: | return true; |
| 3602: | } |
| 3603: | |
| 3604: | |
| 3605: | |
| 3606: | |
| 3607: | |
| 3608: | |
| 3609: | |
| 3610: | |
| 3611: | |
| 3612: | |
| 3613: | |
| 3614: | |
| 3615: | |
| 3616: | |
| 3617: | |
| 3618: | |
| 3619: | |
| 3620: | |
| 3621: | |
| 3622: | |
| 3623: | |
| 3624: | |
| 3625: | |
| 3626: | |
| 3627: | |
| 3628: | |
| 3629: | |
| 3630: | |
| 3631: | |
| 3632: | |
| 3633: | |
| 3634: | |
| 3635: | |
| 3636: | |
| 3637: | |
| 3638: | |
| 3639: | |
| 3640: | |
| 3641: | |
| 3642: | |
| 3643: | |
| 3644: | |
| 3645: | |
| 3646: | |
| 3647: | |
| 3648: | |
| 3649: | |
| 3650: | |
| 3651: | |
| 3652: | |
| 3653: | |
| 3654: | |
| 3655: | |
| 3656: | |
| 3657: | |
| 3658: | |
| 3659: | |
| 3660: | |
| 3661: | |
| 3662: | public function MoveMessages($AccountID, $Folder, $ToFolder, $Uids) |
| 3663: | { |
| 3664: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 3665: | |
| 3666: | $aUids = \Aurora\System\Utils::ExplodeIntUids((string) $Uids); |
| 3667: | |
| 3668: | if (0 === \strlen(\trim($Folder)) || 0 === \strlen(\trim($ToFolder)) || !\is_array($aUids) || 0 === \count($aUids)) { |
| 3669: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::InvalidInputParameter); |
| 3670: | } |
| 3671: | |
| 3672: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 3673: | |
| 3674: | self::checkAccountAccess($oAccount); |
| 3675: | |
| 3676: | try { |
| 3677: | $this->getMailManager()->moveMessage($oAccount, $Folder, $ToFolder, $aUids); |
| 3678: | } catch (\MailSo\Imap\Exceptions\NegativeResponseException $oException) { |
| 3679: | $oResponse = $oException->GetLastResponse(); |
| 3680: | throw new \Aurora\Modules\Mail\Exceptions\Exception( |
| 3681: | Enums\ErrorCodes::CannotMoveMessageQuota, |
| 3682: | $oException, |
| 3683: | $oResponse instanceof \MailSo\Imap\Response ? $oResponse->Tag . ' ' . $oResponse->StatusOrIndex . ' ' . $oResponse->HumanReadable : '' |
| 3684: | ); |
| 3685: | } catch (\Exception $oException) { |
| 3686: | throw new \Aurora\Modules\Mail\Exceptions\Exception( |
| 3687: | Enums\ErrorCodes::CannotMoveMessage, |
| 3688: | $oException, |
| 3689: | $oException->getMessage() |
| 3690: | ); |
| 3691: | } |
| 3692: | |
| 3693: | return true; |
| 3694: | } |
| 3695: | |
| 3696: | |
| 3697: | |
| 3698: | |
| 3699: | |
| 3700: | |
| 3701: | |
| 3702: | |
| 3703: | |
| 3704: | |
| 3705: | |
| 3706: | |
| 3707: | |
| 3708: | |
| 3709: | |
| 3710: | |
| 3711: | |
| 3712: | |
| 3713: | |
| 3714: | |
| 3715: | |
| 3716: | |
| 3717: | |
| 3718: | |
| 3719: | |
| 3720: | |
| 3721: | |
| 3722: | |
| 3723: | |
| 3724: | |
| 3725: | |
| 3726: | |
| 3727: | |
| 3728: | |
| 3729: | |
| 3730: | |
| 3731: | |
| 3732: | |
| 3733: | |
| 3734: | |
| 3735: | |
| 3736: | |
| 3737: | |
| 3738: | |
| 3739: | |
| 3740: | |
| 3741: | |
| 3742: | |
| 3743: | |
| 3744: | |
| 3745: | |
| 3746: | |
| 3747: | |
| 3748: | |
| 3749: | |
| 3750: | |
| 3751: | |
| 3752: | |
| 3753: | public function DeleteMessages($AccountID, $Folder, $Uids) |
| 3754: | { |
| 3755: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 3756: | |
| 3757: | $aUids = \Aurora\System\Utils::ExplodeIntUids((string) $Uids); |
| 3758: | |
| 3759: | if (0 === \strlen(\trim($Folder)) || !\is_array($aUids) || 0 === \count($aUids)) { |
| 3760: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::InvalidInputParameter); |
| 3761: | } |
| 3762: | |
| 3763: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 3764: | |
| 3765: | self::checkAccountAccess($oAccount); |
| 3766: | |
| 3767: | $this->getMailManager()->deleteMessage($oAccount, $Folder, $aUids); |
| 3768: | |
| 3769: | return true; |
| 3770: | } |
| 3771: | |
| 3772: | |
| 3773: | |
| 3774: | |
| 3775: | |
| 3776: | |
| 3777: | |
| 3778: | |
| 3779: | |
| 3780: | |
| 3781: | |
| 3782: | |
| 3783: | |
| 3784: | |
| 3785: | |
| 3786: | |
| 3787: | |
| 3788: | |
| 3789: | |
| 3790: | |
| 3791: | |
| 3792: | |
| 3793: | |
| 3794: | |
| 3795: | |
| 3796: | |
| 3797: | |
| 3798: | |
| 3799: | |
| 3800: | |
| 3801: | |
| 3802: | |
| 3803: | |
| 3804: | |
| 3805: | |
| 3806: | |
| 3807: | |
| 3808: | |
| 3809: | |
| 3810: | |
| 3811: | |
| 3812: | |
| 3813: | |
| 3814: | |
| 3815: | |
| 3816: | |
| 3817: | |
| 3818: | |
| 3819: | |
| 3820: | |
| 3821: | |
| 3822: | |
| 3823: | |
| 3824: | |
| 3825: | |
| 3826: | |
| 3827: | |
| 3828: | |
| 3829: | |
| 3830: | |
| 3831: | |
| 3832: | public function CreateFolder($AccountID, $FolderNameInUtf8, $FolderParentFullNameRaw, $Delimiter) |
| 3833: | { |
| 3834: | $bResult = true; |
| 3835: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 3836: | |
| 3837: | if (0 === \strlen($FolderNameInUtf8) || 1 !== \strlen($Delimiter)) { |
| 3838: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::InvalidInputParameter); |
| 3839: | } |
| 3840: | |
| 3841: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 3842: | |
| 3843: | self::checkAccountAccess($oAccount); |
| 3844: | |
| 3845: | try { |
| 3846: | $this->getMailManager()->createFolder($oAccount, $FolderNameInUtf8, $Delimiter, $FolderParentFullNameRaw); |
| 3847: | } catch (\MailSo\Mail\Exceptions\AlreadyExistsFolder $oException) { |
| 3848: | throw new \Aurora\Modules\Mail\Exceptions\Exception( |
| 3849: | Enums\ErrorCodes::FolderAlreadyExists, |
| 3850: | $oException, |
| 3851: | $oException->getMessage() |
| 3852: | ); |
| 3853: | } |
| 3854: | |
| 3855: | $aFoldersOrderList = $this->getMailManager()->getFoldersOrder($oAccount); |
| 3856: | if (\is_array($aFoldersOrderList) && 0 < \count($aFoldersOrderList)) { |
| 3857: | $aFoldersOrderListNew = $aFoldersOrderList; |
| 3858: | |
| 3859: | $sFolderNameInUtf7Imap = \MailSo\Base\Utils::ConvertEncoding( |
| 3860: | $FolderNameInUtf8, |
| 3861: | \MailSo\Base\Enumerations\Charset::UTF_8, |
| 3862: | \MailSo\Base\Enumerations\Charset::UTF_7_IMAP |
| 3863: | ); |
| 3864: | |
| 3865: | $sFolderFullNameRaw = (0 < \strlen($FolderParentFullNameRaw) ? $FolderParentFullNameRaw . $Delimiter : '') . |
| 3866: | $sFolderNameInUtf7Imap; |
| 3867: | |
| 3868: | $sFolderFullNameUtf8 = \MailSo\Base\Utils::ConvertEncoding( |
| 3869: | $sFolderFullNameRaw, |
| 3870: | \MailSo\Base\Enumerations\Charset::UTF_7_IMAP, |
| 3871: | \MailSo\Base\Enumerations\Charset::UTF_8 |
| 3872: | ); |
| 3873: | |
| 3874: | $aFoldersOrderListNew[] = $sFolderFullNameRaw; |
| 3875: | |
| 3876: | $aFoldersOrderListUtf8 = \array_map(function ($sValue) { |
| 3877: | return \MailSo\Base\Utils::ConvertEncoding( |
| 3878: | $sValue, |
| 3879: | \MailSo\Base\Enumerations\Charset::UTF_7_IMAP, |
| 3880: | \MailSo\Base\Enumerations\Charset::UTF_8 |
| 3881: | ); |
| 3882: | }, $aFoldersOrderListNew); |
| 3883: | |
| 3884: | \usort($aFoldersOrderListUtf8, 'strnatcasecmp'); |
| 3885: | |
| 3886: | $iKey = \array_search($sFolderFullNameUtf8, $aFoldersOrderListUtf8, true); |
| 3887: | if (\is_int($iKey) && 0 < $iKey && isset($aFoldersOrderListUtf8[$iKey - 1])) { |
| 3888: | $sUpperName = $aFoldersOrderListUtf8[$iKey - 1]; |
| 3889: | |
| 3890: | $iUpperKey = \array_search(\MailSo\Base\Utils::ConvertEncoding( |
| 3891: | $sUpperName, |
| 3892: | \MailSo\Base\Enumerations\Charset::UTF_8, |
| 3893: | \MailSo\Base\Enumerations\Charset::UTF_7_IMAP |
| 3894: | ), $aFoldersOrderList, true); |
| 3895: | |
| 3896: | if (\is_int($iUpperKey) && isset($aFoldersOrderList[$iUpperKey])) { |
| 3897: | \Aurora\System\Api::Log('insert order index:' . $iUpperKey); |
| 3898: | \array_splice($aFoldersOrderList, $iUpperKey + 1, 0, $sFolderFullNameRaw); |
| 3899: | $this->getMailManager()->updateFoldersOrder($oAccount, $aFoldersOrderList); |
| 3900: | } |
| 3901: | } |
| 3902: | } |
| 3903: | |
| 3904: | return $bResult; |
| 3905: | } |
| 3906: | |
| 3907: | |
| 3908: | |
| 3909: | |
| 3910: | |
| 3911: | |
| 3912: | |
| 3913: | |
| 3914: | |
| 3915: | |
| 3916: | |
| 3917: | |
| 3918: | |
| 3919: | |
| 3920: | |
| 3921: | |
| 3922: | |
| 3923: | |
| 3924: | |
| 3925: | |
| 3926: | |
| 3927: | |
| 3928: | |
| 3929: | |
| 3930: | |
| 3931: | |
| 3932: | |
| 3933: | |
| 3934: | |
| 3935: | |
| 3936: | |
| 3937: | |
| 3938: | |
| 3939: | |
| 3940: | |
| 3941: | |
| 3942: | |
| 3943: | |
| 3944: | |
| 3945: | |
| 3946: | |
| 3947: | |
| 3948: | |
| 3949: | |
| 3950: | |
| 3951: | |
| 3952: | |
| 3953: | |
| 3954: | |
| 3955: | |
| 3956: | |
| 3957: | |
| 3958: | |
| 3959: | |
| 3960: | |
| 3961: | |
| 3962: | |
| 3963: | |
| 3964: | |
| 3965: | |
| 3966: | |
| 3967: | public function RenameFolder($AccountID, $PrevFolderFullNameRaw, $NewFolderNameInUtf8, $ChangeParent, $NewParentFolder) |
| 3968: | { |
| 3969: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 3970: | |
| 3971: | if (0 === \strlen($PrevFolderFullNameRaw) || 0 === \strlen($NewFolderNameInUtf8)) { |
| 3972: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::InvalidInputParameter); |
| 3973: | } |
| 3974: | |
| 3975: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 3976: | |
| 3977: | self::checkAccountAccess($oAccount); |
| 3978: | |
| 3979: | $mResult = $this->getMailManager()->renameFolder($oAccount, $PrevFolderFullNameRaw, $NewFolderNameInUtf8, $ChangeParent, $NewParentFolder); |
| 3980: | |
| 3981: | return (0 < \strlen($mResult) ? array( |
| 3982: | 'FullName' => $mResult, |
| 3983: | 'FullNameHash' => \md5($mResult) |
| 3984: | ) : false); |
| 3985: | } |
| 3986: | |
| 3987: | |
| 3988: | |
| 3989: | |
| 3990: | |
| 3991: | |
| 3992: | |
| 3993: | |
| 3994: | |
| 3995: | |
| 3996: | |
| 3997: | |
| 3998: | |
| 3999: | |
| 4000: | |
| 4001: | |
| 4002: | |
| 4003: | |
| 4004: | |
| 4005: | |
| 4006: | |
| 4007: | |
| 4008: | |
| 4009: | |
| 4010: | |
| 4011: | |
| 4012: | |
| 4013: | |
| 4014: | |
| 4015: | |
| 4016: | |
| 4017: | |
| 4018: | |
| 4019: | |
| 4020: | |
| 4021: | |
| 4022: | |
| 4023: | |
| 4024: | |
| 4025: | |
| 4026: | |
| 4027: | |
| 4028: | |
| 4029: | |
| 4030: | |
| 4031: | |
| 4032: | |
| 4033: | |
| 4034: | |
| 4035: | |
| 4036: | |
| 4037: | |
| 4038: | |
| 4039: | |
| 4040: | |
| 4041: | |
| 4042: | public function DeleteFolder($AccountID, $Folder) |
| 4043: | { |
| 4044: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 4045: | |
| 4046: | if (0 === \strlen(\trim($Folder))) { |
| 4047: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::InvalidInputParameter); |
| 4048: | } |
| 4049: | |
| 4050: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 4051: | |
| 4052: | self::checkAccountAccess($oAccount); |
| 4053: | |
| 4054: | $this->getMailManager()->deleteFolder($oAccount, $Folder); |
| 4055: | |
| 4056: | return true; |
| 4057: | } |
| 4058: | |
| 4059: | |
| 4060: | |
| 4061: | |
| 4062: | |
| 4063: | |
| 4064: | |
| 4065: | |
| 4066: | |
| 4067: | |
| 4068: | |
| 4069: | |
| 4070: | |
| 4071: | |
| 4072: | |
| 4073: | |
| 4074: | |
| 4075: | |
| 4076: | |
| 4077: | |
| 4078: | |
| 4079: | |
| 4080: | |
| 4081: | |
| 4082: | |
| 4083: | |
| 4084: | |
| 4085: | |
| 4086: | |
| 4087: | |
| 4088: | |
| 4089: | |
| 4090: | |
| 4091: | |
| 4092: | |
| 4093: | |
| 4094: | |
| 4095: | |
| 4096: | |
| 4097: | |
| 4098: | |
| 4099: | |
| 4100: | |
| 4101: | |
| 4102: | |
| 4103: | |
| 4104: | |
| 4105: | |
| 4106: | |
| 4107: | |
| 4108: | |
| 4109: | |
| 4110: | |
| 4111: | |
| 4112: | |
| 4113: | |
| 4114: | |
| 4115: | |
| 4116: | public function SubscribeFolder($AccountID, $Folder, $SetAction) |
| 4117: | { |
| 4118: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 4119: | |
| 4120: | if ($this->oModuleSettings->IgnoreImapSubscription) { |
| 4121: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::AccessDenied); |
| 4122: | } |
| 4123: | |
| 4124: | if (0 === \strlen(\trim($Folder))) { |
| 4125: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::InvalidInputParameter); |
| 4126: | } |
| 4127: | |
| 4128: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 4129: | |
| 4130: | self::checkAccountAccess($oAccount); |
| 4131: | |
| 4132: | $this->getMailManager()->subscribeFolder($oAccount, $Folder, $SetAction); |
| 4133: | |
| 4134: | return true; |
| 4135: | } |
| 4136: | |
| 4137: | |
| 4138: | |
| 4139: | |
| 4140: | |
| 4141: | |
| 4142: | |
| 4143: | |
| 4144: | |
| 4145: | |
| 4146: | |
| 4147: | |
| 4148: | |
| 4149: | |
| 4150: | |
| 4151: | |
| 4152: | |
| 4153: | |
| 4154: | |
| 4155: | |
| 4156: | |
| 4157: | |
| 4158: | |
| 4159: | |
| 4160: | |
| 4161: | |
| 4162: | |
| 4163: | |
| 4164: | |
| 4165: | |
| 4166: | |
| 4167: | |
| 4168: | |
| 4169: | |
| 4170: | |
| 4171: | |
| 4172: | |
| 4173: | |
| 4174: | |
| 4175: | |
| 4176: | |
| 4177: | |
| 4178: | |
| 4179: | |
| 4180: | |
| 4181: | |
| 4182: | |
| 4183: | |
| 4184: | |
| 4185: | |
| 4186: | |
| 4187: | |
| 4188: | |
| 4189: | |
| 4190: | |
| 4191: | |
| 4192: | public function UpdateFoldersOrder($AccountID, $FolderList) |
| 4193: | { |
| 4194: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 4195: | |
| 4196: | if (!\is_array($FolderList)) { |
| 4197: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::InvalidInputParameter); |
| 4198: | } |
| 4199: | |
| 4200: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 4201: | |
| 4202: | self::checkAccountAccess($oAccount); |
| 4203: | |
| 4204: | return $this->getMailManager()->updateFoldersOrder($oAccount, $FolderList); |
| 4205: | } |
| 4206: | |
| 4207: | |
| 4208: | |
| 4209: | |
| 4210: | |
| 4211: | |
| 4212: | |
| 4213: | |
| 4214: | |
| 4215: | |
| 4216: | |
| 4217: | |
| 4218: | |
| 4219: | |
| 4220: | |
| 4221: | |
| 4222: | |
| 4223: | |
| 4224: | |
| 4225: | |
| 4226: | |
| 4227: | |
| 4228: | |
| 4229: | |
| 4230: | |
| 4231: | |
| 4232: | |
| 4233: | |
| 4234: | |
| 4235: | |
| 4236: | |
| 4237: | |
| 4238: | |
| 4239: | |
| 4240: | |
| 4241: | |
| 4242: | |
| 4243: | |
| 4244: | |
| 4245: | |
| 4246: | |
| 4247: | |
| 4248: | |
| 4249: | |
| 4250: | |
| 4251: | |
| 4252: | |
| 4253: | |
| 4254: | |
| 4255: | |
| 4256: | |
| 4257: | |
| 4258: | |
| 4259: | |
| 4260: | |
| 4261: | public function ClearFolder($AccountID, $Folder) |
| 4262: | { |
| 4263: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 4264: | |
| 4265: | if (0 === \strlen(\trim($Folder))) { |
| 4266: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::InvalidInputParameter); |
| 4267: | } |
| 4268: | |
| 4269: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 4270: | |
| 4271: | self::checkAccountAccess($oAccount); |
| 4272: | |
| 4273: | $this->getMailManager()->clearFolder($oAccount, $Folder); |
| 4274: | |
| 4275: | return true; |
| 4276: | } |
| 4277: | |
| 4278: | |
| 4279: | |
| 4280: | |
| 4281: | |
| 4282: | |
| 4283: | |
| 4284: | |
| 4285: | |
| 4286: | |
| 4287: | |
| 4288: | |
| 4289: | |
| 4290: | |
| 4291: | |
| 4292: | |
| 4293: | |
| 4294: | |
| 4295: | |
| 4296: | |
| 4297: | |
| 4298: | |
| 4299: | |
| 4300: | |
| 4301: | |
| 4302: | |
| 4303: | |
| 4304: | |
| 4305: | |
| 4306: | |
| 4307: | |
| 4308: | |
| 4309: | |
| 4310: | |
| 4311: | |
| 4312: | |
| 4313: | |
| 4314: | |
| 4315: | |
| 4316: | |
| 4317: | |
| 4318: | |
| 4319: | |
| 4320: | |
| 4321: | |
| 4322: | |
| 4323: | |
| 4324: | |
| 4325: | |
| 4326: | |
| 4327: | |
| 4328: | |
| 4329: | |
| 4330: | |
| 4331: | |
| 4332: | |
| 4333: | |
| 4334: | |
| 4335: | |
| 4336: | |
| 4337: | |
| 4338: | |
| 4339: | |
| 4340: | |
| 4341: | |
| 4342: | |
| 4343: | |
| 4344: | |
| 4345: | |
| 4346: | |
| 4347: | |
| 4348: | |
| 4349: | |
| 4350: | |
| 4351: | |
| 4352: | |
| 4353: | |
| 4354: | |
| 4355: | |
| 4356: | |
| 4357: | |
| 4358: | |
| 4359: | |
| 4360: | |
| 4361: | |
| 4362: | |
| 4363: | |
| 4364: | |
| 4365: | |
| 4366: | |
| 4367: | |
| 4368: | |
| 4369: | |
| 4370: | |
| 4371: | |
| 4372: | |
| 4373: | |
| 4374: | |
| 4375: | |
| 4376: | |
| 4377: | |
| 4378: | |
| 4379: | |
| 4380: | |
| 4381: | |
| 4382: | |
| 4383: | |
| 4384: | |
| 4385: | |
| 4386: | |
| 4387: | |
| 4388: | |
| 4389: | |
| 4390: | |
| 4391: | |
| 4392: | |
| 4393: | public function GetMessagesByUids($AccountID, $Folder, $Uids) |
| 4394: | { |
| 4395: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 4396: | |
| 4397: | if (0 === \strlen(trim($Folder)) || !\is_array($Uids)) { |
| 4398: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::InvalidInputParameter); |
| 4399: | } |
| 4400: | |
| 4401: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 4402: | |
| 4403: | self::checkAccountAccess($oAccount); |
| 4404: | |
| 4405: | return $this->getMailManager()->getMessageListByUids($oAccount, $Folder, $Uids); |
| 4406: | } |
| 4407: | |
| 4408: | |
| 4409: | |
| 4410: | |
| 4411: | |
| 4412: | |
| 4413: | |
| 4414: | |
| 4415: | |
| 4416: | |
| 4417: | |
| 4418: | |
| 4419: | |
| 4420: | |
| 4421: | |
| 4422: | |
| 4423: | |
| 4424: | |
| 4425: | |
| 4426: | |
| 4427: | |
| 4428: | |
| 4429: | |
| 4430: | |
| 4431: | |
| 4432: | |
| 4433: | |
| 4434: | |
| 4435: | |
| 4436: | |
| 4437: | |
| 4438: | |
| 4439: | |
| 4440: | |
| 4441: | |
| 4442: | |
| 4443: | |
| 4444: | |
| 4445: | |
| 4446: | |
| 4447: | |
| 4448: | |
| 4449: | |
| 4450: | |
| 4451: | |
| 4452: | |
| 4453: | |
| 4454: | |
| 4455: | |
| 4456: | |
| 4457: | |
| 4458: | |
| 4459: | |
| 4460: | |
| 4461: | |
| 4462: | |
| 4463: | |
| 4464: | public function GetMessagesFlags($AccountID, $Folder, $Uids) |
| 4465: | { |
| 4466: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 4467: | |
| 4468: | if (0 === \strlen(\trim($Folder)) || !\is_array($Uids)) { |
| 4469: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::InvalidInputParameter); |
| 4470: | } |
| 4471: | |
| 4472: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 4473: | |
| 4474: | self::checkAccountAccess($oAccount); |
| 4475: | |
| 4476: | return $this->getMailManager()->getMessagesFlags($oAccount, $Folder, $Uids); |
| 4477: | } |
| 4478: | |
| 4479: | |
| 4480: | |
| 4481: | |
| 4482: | |
| 4483: | |
| 4484: | |
| 4485: | |
| 4486: | |
| 4487: | |
| 4488: | |
| 4489: | |
| 4490: | |
| 4491: | |
| 4492: | |
| 4493: | |
| 4494: | |
| 4495: | |
| 4496: | |
| 4497: | |
| 4498: | |
| 4499: | |
| 4500: | |
| 4501: | |
| 4502: | |
| 4503: | |
| 4504: | |
| 4505: | |
| 4506: | |
| 4507: | |
| 4508: | |
| 4509: | |
| 4510: | |
| 4511: | |
| 4512: | |
| 4513: | |
| 4514: | |
| 4515: | |
| 4516: | |
| 4517: | |
| 4518: | |
| 4519: | |
| 4520: | |
| 4521: | |
| 4522: | |
| 4523: | |
| 4524: | |
| 4525: | |
| 4526: | |
| 4527: | |
| 4528: | |
| 4529: | |
| 4530: | |
| 4531: | |
| 4532: | |
| 4533: | |
| 4534: | |
| 4535: | |
| 4536: | |
| 4537: | |
| 4538: | |
| 4539: | |
| 4540: | |
| 4541: | |
| 4542: | |
| 4543: | |
| 4544: | |
| 4545: | |
| 4546: | |
| 4547: | |
| 4548: | |
| 4549: | |
| 4550: | |
| 4551: | |
| 4552: | |
| 4553: | |
| 4554: | |
| 4555: | |
| 4556: | |
| 4557: | |
| 4558: | |
| 4559: | |
| 4560: | |
| 4561: | |
| 4562: | |
| 4563: | |
| 4564: | |
| 4565: | |
| 4566: | |
| 4567: | |
| 4568: | |
| 4569: | |
| 4570: | |
| 4571: | public function SaveMessage( |
| 4572: | $AccountID, |
| 4573: | $Fetcher = null, |
| 4574: | $Alias = null, |
| 4575: | $IdentityID = 0, |
| 4576: | $DraftInfo = [], |
| 4577: | $DraftUid = "", |
| 4578: | $To = "", |
| 4579: | $Cc = "", |
| 4580: | $Bcc = "", |
| 4581: | $Subject = "", |
| 4582: | $Text = "", |
| 4583: | $IsHtml = false, |
| 4584: | $Importance = \MailSo\Mime\Enumerations\MessagePriority::NORMAL, |
| 4585: | $SendReadingConfirmation = false, |
| 4586: | $Attachments = array(), |
| 4587: | $InReplyTo = "", |
| 4588: | $References = "", |
| 4589: | $Sensitivity = \MailSo\Mime\Enumerations\Sensitivity::NOTHING, |
| 4590: | $DraftFolder = "" |
| 4591: | ) { |
| 4592: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 4593: | |
| 4594: | $mResult = false; |
| 4595: | |
| 4596: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 4597: | |
| 4598: | self::checkAccountAccess($oAccount); |
| 4599: | |
| 4600: | if (0 === \strlen($DraftFolder)) { |
| 4601: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::InvalidInputParameter); |
| 4602: | } |
| 4603: | |
| 4604: | $oIdentity = $IdentityID !== 0 ? $this->getIdentitiesManager()->getIdentity($IdentityID, $AccountID) : null; |
| 4605: | |
| 4606: | $oMessage = self::Decorator()->BuildMessage( |
| 4607: | $oAccount, |
| 4608: | $To, |
| 4609: | $Cc, |
| 4610: | $Bcc, |
| 4611: | $Subject, |
| 4612: | $IsHtml, |
| 4613: | $Text, |
| 4614: | $Attachments, |
| 4615: | $DraftInfo, |
| 4616: | $InReplyTo, |
| 4617: | $References, |
| 4618: | $Importance, |
| 4619: | $Sensitivity, |
| 4620: | $SendReadingConfirmation, |
| 4621: | $Fetcher, |
| 4622: | $Alias, |
| 4623: | true, |
| 4624: | $oIdentity |
| 4625: | ); |
| 4626: | if ($oMessage) { |
| 4627: | try { |
| 4628: | $mResult = $this->getMailManager()->saveMessage($oAccount, $oMessage, $DraftFolder, $DraftUid); |
| 4629: | } catch (\Aurora\System\Exceptions\ManagerException $oException) { |
| 4630: | throw new \Aurora\Modules\Mail\Exceptions\Exception(Enums\ErrorCodes::CannotSaveMessage, $oException, $oException->getMessage()); |
| 4631: | } |
| 4632: | } |
| 4633: | |
| 4634: | return $mResult; |
| 4635: | } |
| 4636: | |
| 4637: | |
| 4638: | |
| 4639: | |
| 4640: | |
| 4641: | |
| 4642: | |
| 4643: | |
| 4644: | |
| 4645: | |
| 4646: | |
| 4647: | |
| 4648: | |
| 4649: | |
| 4650: | |
| 4651: | |
| 4652: | |
| 4653: | |
| 4654: | |
| 4655: | |
| 4656: | |
| 4657: | |
| 4658: | |
| 4659: | |
| 4660: | |
| 4661: | |
| 4662: | |
| 4663: | |
| 4664: | |
| 4665: | |
| 4666: | |
| 4667: | |
| 4668: | |
| 4669: | |
| 4670: | |
| 4671: | |
| 4672: | |
| 4673: | |
| 4674: | |
| 4675: | |
| 4676: | |
| 4677: | |
| 4678: | |
| 4679: | |
| 4680: | |
| 4681: | |
| 4682: | |
| 4683: | |
| 4684: | |
| 4685: | |
| 4686: | |
| 4687: | |
| 4688: | |
| 4689: | |
| 4690: | |
| 4691: | |
| 4692: | |
| 4693: | |
| 4694: | |
| 4695: | |
| 4696: | |
| 4697: | |
| 4698: | |
| 4699: | |
| 4700: | |
| 4701: | |
| 4702: | |
| 4703: | |
| 4704: | |
| 4705: | |
| 4706: | |
| 4707: | |
| 4708: | |
| 4709: | |
| 4710: | |
| 4711: | |
| 4712: | |
| 4713: | |
| 4714: | |
| 4715: | |
| 4716: | |
| 4717: | |
| 4718: | |
| 4719: | |
| 4720: | |
| 4721: | |
| 4722: | |
| 4723: | |
| 4724: | |
| 4725: | |
| 4726: | |
| 4727: | |
| 4728: | |
| 4729: | |
| 4730: | |
| 4731: | |
| 4732: | |
| 4733: | |
| 4734: | |
| 4735: | |
| 4736: | |
| 4737: | public function SendMessage( |
| 4738: | $AccountID, |
| 4739: | $Fetcher = null, |
| 4740: | $Alias = null, |
| 4741: | $IdentityID = 0, |
| 4742: | $DraftInfo = [], |
| 4743: | $DraftUid = "", |
| 4744: | $To = "", |
| 4745: | $Cc = "", |
| 4746: | $Bcc = "", |
| 4747: | $Recipients = array(), |
| 4748: | $Subject = "", |
| 4749: | $Text = "", |
| 4750: | $IsHtml = false, |
| 4751: | $Importance = \MailSo\Mime\Enumerations\MessagePriority::NORMAL, |
| 4752: | $SendReadingConfirmation = false, |
| 4753: | $Attachments = array(), |
| 4754: | $InReplyTo = "", |
| 4755: | $References = "", |
| 4756: | $Sensitivity = \MailSo\Mime\Enumerations\Sensitivity::NOTHING, |
| 4757: | $SentFolder = "", |
| 4758: | $DraftFolder = "", |
| 4759: | $ConfirmFolder = "", |
| 4760: | $ConfirmUid = "", |
| 4761: | $CustomHeaders = [] |
| 4762: | ) { |
| 4763: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 4764: | |
| 4765: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 4766: | |
| 4767: | self::checkAccountAccess($oAccount); |
| 4768: | |
| 4769: | $oIdentity = $IdentityID !== 0 ? $this->getIdentitiesManager()->getIdentity($IdentityID, $AccountID) : null; |
| 4770: | |
| 4771: | $oMessage = self::Decorator()->BuildMessage( |
| 4772: | $oAccount, |
| 4773: | $To, |
| 4774: | $Cc, |
| 4775: | $Bcc, |
| 4776: | $Subject, |
| 4777: | $IsHtml, |
| 4778: | $Text, |
| 4779: | $Attachments, |
| 4780: | $DraftInfo, |
| 4781: | $InReplyTo, |
| 4782: | $References, |
| 4783: | $Importance, |
| 4784: | $Sensitivity, |
| 4785: | $SendReadingConfirmation, |
| 4786: | $Fetcher, |
| 4787: | $Alias, |
| 4788: | false, |
| 4789: | $oIdentity, |
| 4790: | $CustomHeaders |
| 4791: | ); |
| 4792: | |
| 4793: | if ($oMessage) { |
| 4794: | $mResult = $this->getMailManager()->sendMessage($oAccount, $oMessage, $Fetcher, $oIdentity, $SentFolder, $DraftFolder, $DraftUid, $Recipients); |
| 4795: | |
| 4796: | if ($mResult) { |
| 4797: | $aCollection = $oMessage->GetRcpt(); |
| 4798: | |
| 4799: | $aEmails = array(); |
| 4800: | $aCollection->ForeachList(function ($oEmail) use (&$aEmails) { |
| 4801: | $aEmails[strtolower($oEmail->GetEmail(true))] = trim($oEmail->GetDisplayName()); |
| 4802: | }); |
| 4803: | |
| 4804: | if (\is_array($aEmails)) { |
| 4805: | $aArgs = ['IdUser' => $oAccount->IdUser, 'Emails' => $aEmails]; |
| 4806: | $this->broadcastEvent('AfterUseEmails', $aArgs); |
| 4807: | } |
| 4808: | } |
| 4809: | |
| 4810: | if (\is_array($DraftInfo) && 3 === \count($DraftInfo)) { |
| 4811: | $sDraftInfoType = $DraftInfo[0]; |
| 4812: | $sDraftInfoUid = $DraftInfo[1]; |
| 4813: | $sDraftInfoFolder = $DraftInfo[2]; |
| 4814: | |
| 4815: | try { |
| 4816: | switch (\strtolower($sDraftInfoType)) { |
| 4817: | case 'reply': |
| 4818: | case 'reply-all': |
| 4819: | $this->getMailManager()->setMessageFlag( |
| 4820: | $oAccount, |
| 4821: | $sDraftInfoFolder, |
| 4822: | array($sDraftInfoUid), |
| 4823: | \MailSo\Imap\Enumerations\MessageFlag::ANSWERED, |
| 4824: | \Aurora\Modules\Mail\Enums\MessageStoreAction::Add |
| 4825: | ); |
| 4826: | break; |
| 4827: | case 'forward': |
| 4828: | $this->getMailManager()->setMessageFlag( |
| 4829: | $oAccount, |
| 4830: | $sDraftInfoFolder, |
| 4831: | array($sDraftInfoUid), |
| 4832: | '$Forwarded', |
| 4833: | \Aurora\Modules\Mail\Enums\MessageStoreAction::Add |
| 4834: | ); |
| 4835: | break; |
| 4836: | } |
| 4837: | } catch (\Exception $oException) { |
| 4838: | } |
| 4839: | } |
| 4840: | |
| 4841: | if (0 < \strlen($ConfirmFolder) && 0 < \strlen($ConfirmUid)) { |
| 4842: | try { |
| 4843: | $mResult = $this->getMailManager()->setMessageFlag( |
| 4844: | $oAccount, |
| 4845: | $ConfirmFolder, |
| 4846: | array($ConfirmUid), |
| 4847: | '$ReadConfirm', |
| 4848: | \Aurora\Modules\Mail\Enums\MessageStoreAction::Add, |
| 4849: | false, |
| 4850: | true |
| 4851: | ); |
| 4852: | } catch (\Exception $oException) { |
| 4853: | } |
| 4854: | } |
| 4855: | } |
| 4856: | |
| 4857: | \Aurora\System\Api::LogEvent('message-send: ' . $oAccount->Email, self::GetName()); |
| 4858: | return $mResult; |
| 4859: | } |
| 4860: | |
| 4861: | |
| 4862: | |
| 4863: | |
| 4864: | |
| 4865: | |
| 4866: | |
| 4867: | |
| 4868: | |
| 4869: | |
| 4870: | |
| 4871: | |
| 4872: | |
| 4873: | |
| 4874: | |
| 4875: | |
| 4876: | |
| 4877: | |
| 4878: | |
| 4879: | |
| 4880: | |
| 4881: | |
| 4882: | |
| 4883: | |
| 4884: | |
| 4885: | |
| 4886: | |
| 4887: | |
| 4888: | |
| 4889: | |
| 4890: | |
| 4891: | |
| 4892: | |
| 4893: | |
| 4894: | |
| 4895: | |
| 4896: | |
| 4897: | |
| 4898: | |
| 4899: | |
| 4900: | |
| 4901: | |
| 4902: | |
| 4903: | |
| 4904: | |
| 4905: | |
| 4906: | |
| 4907: | |
| 4908: | |
| 4909: | |
| 4910: | |
| 4911: | |
| 4912: | |
| 4913: | |
| 4914: | |
| 4915: | |
| 4916: | |
| 4917: | |
| 4918: | |
| 4919: | |
| 4920: | |
| 4921: | public function SetupSystemFolders($AccountID, $Sent, $Drafts, $Trash, $Spam) |
| 4922: | { |
| 4923: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 4924: | |
| 4925: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 4926: | |
| 4927: | self::checkAccountAccess($oAccount); |
| 4928: | |
| 4929: | $aSystemNames = [ |
| 4930: | \Aurora\Modules\Mail\Enums\FolderType::Sent => \trim($Sent), |
| 4931: | \Aurora\Modules\Mail\Enums\FolderType::Drafts => \trim($Drafts), |
| 4932: | \Aurora\Modules\Mail\Enums\FolderType::Trash => \trim($Trash), |
| 4933: | \Aurora\Modules\Mail\Enums\FolderType::Spam => \trim($Spam) |
| 4934: | ]; |
| 4935: | |
| 4936: | return $this->getMailManager()->updateSystemFolderNames($oAccount, $aSystemNames); |
| 4937: | } |
| 4938: | |
| 4939: | |
| 4940: | |
| 4941: | |
| 4942: | |
| 4943: | |
| 4944: | |
| 4945: | public function SetAlwaysRefreshFolder($AccountID, $FolderFullName, $AlwaysRefresh) |
| 4946: | { |
| 4947: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 4948: | |
| 4949: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 4950: | |
| 4951: | self::checkAccountAccess($oAccount); |
| 4952: | |
| 4953: | return $this->getMailManager()->setAlwaysRefreshFolder($oAccount, $FolderFullName, $AlwaysRefresh); |
| 4954: | } |
| 4955: | |
| 4956: | |
| 4957: | |
| 4958: | |
| 4959: | |
| 4960: | |
| 4961: | |
| 4962: | |
| 4963: | public function SetTemplateFolderType($AccountID, $FolderFullName, $SetTemplate) |
| 4964: | { |
| 4965: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 4966: | |
| 4967: | if ($this->oModuleSettings->AllowTemplateFolders) { |
| 4968: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 4969: | |
| 4970: | self::checkAccountAccess($oAccount); |
| 4971: | |
| 4972: | return $this->getMailManager()->setSystemFolder($oAccount, $FolderFullName, \Aurora\Modules\Mail\Enums\FolderType::Template, $SetTemplate); |
| 4973: | } |
| 4974: | |
| 4975: | return false; |
| 4976: | } |
| 4977: | |
| 4978: | |
| 4979: | |
| 4980: | |
| 4981: | |
| 4982: | |
| 4983: | |
| 4984: | |
| 4985: | |
| 4986: | |
| 4987: | |
| 4988: | |
| 4989: | |
| 4990: | |
| 4991: | |
| 4992: | |
| 4993: | |
| 4994: | |
| 4995: | |
| 4996: | |
| 4997: | |
| 4998: | |
| 4999: | |
| 5000: | |
| 5001: | |
| 5002: | |
| 5003: | |
| 5004: | |
| 5005: | |
| 5006: | |
| 5007: | |
| 5008: | |
| 5009: | |
| 5010: | |
| 5011: | |
| 5012: | |
| 5013: | |
| 5014: | |
| 5015: | |
| 5016: | |
| 5017: | |
| 5018: | |
| 5019: | |
| 5020: | |
| 5021: | |
| 5022: | |
| 5023: | |
| 5024: | |
| 5025: | |
| 5026: | |
| 5027: | |
| 5028: | |
| 5029: | |
| 5030: | |
| 5031: | |
| 5032: | |
| 5033: | public function SetEmailSafety($AccountID, $Email) |
| 5034: | { |
| 5035: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 5036: | |
| 5037: | if (0 === \strlen(\trim($Email))) { |
| 5038: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::InvalidInputParameter); |
| 5039: | } |
| 5040: | |
| 5041: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 5042: | |
| 5043: | self::checkAccountAccess($oAccount); |
| 5044: | |
| 5045: | $this->getMailManager()->setSafetySender($oAccount->IdUser, $Email); |
| 5046: | |
| 5047: | return true; |
| 5048: | } |
| 5049: | |
| 5050: | |
| 5051: | |
| 5052: | |
| 5053: | |
| 5054: | |
| 5055: | |
| 5056: | |
| 5057: | |
| 5058: | |
| 5059: | |
| 5060: | |
| 5061: | |
| 5062: | |
| 5063: | |
| 5064: | |
| 5065: | |
| 5066: | |
| 5067: | |
| 5068: | |
| 5069: | |
| 5070: | |
| 5071: | |
| 5072: | |
| 5073: | |
| 5074: | |
| 5075: | |
| 5076: | |
| 5077: | |
| 5078: | |
| 5079: | |
| 5080: | |
| 5081: | |
| 5082: | |
| 5083: | |
| 5084: | |
| 5085: | |
| 5086: | |
| 5087: | |
| 5088: | |
| 5089: | |
| 5090: | |
| 5091: | |
| 5092: | |
| 5093: | |
| 5094: | |
| 5095: | |
| 5096: | |
| 5097: | |
| 5098: | |
| 5099: | |
| 5100: | |
| 5101: | |
| 5102: | |
| 5103: | |
| 5104: | |
| 5105: | |
| 5106: | |
| 5107: | |
| 5108: | public function CreateIdentity($UserId, $AccountID, $FriendlyName, $Email) |
| 5109: | { |
| 5110: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 5111: | |
| 5112: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 5113: | |
| 5114: | self::checkAccountAccess($oAccount); |
| 5115: | |
| 5116: | if ($this->oModuleSettings->OnlyUserEmailsInIdentities) { |
| 5117: | $Email = $oAccount->Email; |
| 5118: | } |
| 5119: | |
| 5120: | return $this->getIdentitiesManager()->createIdentity($UserId, $AccountID, $FriendlyName, $Email); |
| 5121: | } |
| 5122: | |
| 5123: | |
| 5124: | |
| 5125: | |
| 5126: | |
| 5127: | |
| 5128: | |
| 5129: | |
| 5130: | |
| 5131: | |
| 5132: | |
| 5133: | |
| 5134: | |
| 5135: | |
| 5136: | |
| 5137: | |
| 5138: | |
| 5139: | |
| 5140: | |
| 5141: | |
| 5142: | |
| 5143: | |
| 5144: | |
| 5145: | |
| 5146: | |
| 5147: | |
| 5148: | |
| 5149: | |
| 5150: | |
| 5151: | |
| 5152: | |
| 5153: | |
| 5154: | |
| 5155: | |
| 5156: | |
| 5157: | |
| 5158: | |
| 5159: | |
| 5160: | |
| 5161: | |
| 5162: | |
| 5163: | |
| 5164: | |
| 5165: | |
| 5166: | |
| 5167: | |
| 5168: | |
| 5169: | |
| 5170: | |
| 5171: | |
| 5172: | |
| 5173: | |
| 5174: | |
| 5175: | |
| 5176: | |
| 5177: | |
| 5178: | |
| 5179: | |
| 5180: | |
| 5181: | |
| 5182: | |
| 5183: | |
| 5184: | |
| 5185: | |
| 5186: | |
| 5187: | public function UpdateIdentity($UserId, $AccountID, $EntityId, $FriendlyName, $Email, $Default = false) |
| 5188: | { |
| 5189: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 5190: | |
| 5191: | if ($this->oModuleSettings->AllowIdentities) { |
| 5192: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 5193: | |
| 5194: | self::checkAccountAccess($oAccount); |
| 5195: | |
| 5196: | if ($Default) { |
| 5197: | $this->getIdentitiesManager()->resetDefaultIdentity($UserId, $AccountID); |
| 5198: | } |
| 5199: | |
| 5200: | if ($this->oModuleSettings->OnlyUserEmailsInIdentities) { |
| 5201: | $Email = $oAccount->Email; |
| 5202: | } |
| 5203: | |
| 5204: | if ($EntityId === null) { |
| 5205: | return !!$this->UpdateAccount($AccountID, null, $Email, $FriendlyName); |
| 5206: | } else { |
| 5207: | return $this->getIdentitiesManager()->updateIdentity($EntityId, $AccountID, $FriendlyName, $Email, $Default); |
| 5208: | } |
| 5209: | } else { |
| 5210: | return false; |
| 5211: | } |
| 5212: | } |
| 5213: | |
| 5214: | |
| 5215: | |
| 5216: | |
| 5217: | |
| 5218: | |
| 5219: | |
| 5220: | |
| 5221: | |
| 5222: | |
| 5223: | |
| 5224: | |
| 5225: | |
| 5226: | |
| 5227: | |
| 5228: | |
| 5229: | |
| 5230: | |
| 5231: | |
| 5232: | |
| 5233: | |
| 5234: | |
| 5235: | |
| 5236: | |
| 5237: | |
| 5238: | |
| 5239: | |
| 5240: | |
| 5241: | |
| 5242: | |
| 5243: | |
| 5244: | |
| 5245: | |
| 5246: | |
| 5247: | |
| 5248: | |
| 5249: | |
| 5250: | |
| 5251: | |
| 5252: | |
| 5253: | |
| 5254: | |
| 5255: | |
| 5256: | |
| 5257: | |
| 5258: | |
| 5259: | |
| 5260: | |
| 5261: | |
| 5262: | |
| 5263: | |
| 5264: | |
| 5265: | |
| 5266: | public function DeleteIdentity($AccountID, $EntityId) |
| 5267: | { |
| 5268: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 5269: | |
| 5270: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 5271: | |
| 5272: | self::checkAccountAccess($oAccount); |
| 5273: | |
| 5274: | return $this->getIdentitiesManager()->deleteIdentity($EntityId, $AccountID); |
| 5275: | } |
| 5276: | |
| 5277: | |
| 5278: | |
| 5279: | |
| 5280: | |
| 5281: | |
| 5282: | |
| 5283: | |
| 5284: | |
| 5285: | |
| 5286: | |
| 5287: | |
| 5288: | |
| 5289: | |
| 5290: | |
| 5291: | |
| 5292: | |
| 5293: | |
| 5294: | |
| 5295: | |
| 5296: | |
| 5297: | |
| 5298: | |
| 5299: | |
| 5300: | |
| 5301: | |
| 5302: | |
| 5303: | |
| 5304: | |
| 5305: | |
| 5306: | |
| 5307: | |
| 5308: | |
| 5309: | |
| 5310: | |
| 5311: | |
| 5312: | |
| 5313: | |
| 5314: | |
| 5315: | |
| 5316: | |
| 5317: | |
| 5318: | |
| 5319: | |
| 5320: | |
| 5321: | |
| 5322: | |
| 5323: | |
| 5324: | |
| 5325: | |
| 5326: | |
| 5327: | |
| 5328: | |
| 5329: | |
| 5330: | |
| 5331: | |
| 5332: | |
| 5333: | |
| 5334: | |
| 5335: | |
| 5336: | |
| 5337: | |
| 5338: | |
| 5339: | |
| 5340: | public function GetIdentities($UserId) |
| 5341: | { |
| 5342: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 5343: | |
| 5344: | \Aurora\System\Api::CheckAccess($UserId); |
| 5345: | |
| 5346: | return $this->getIdentitiesManager()->getIdentities($UserId)->all(); |
| 5347: | } |
| 5348: | |
| 5349: | |
| 5350: | |
| 5351: | |
| 5352: | |
| 5353: | |
| 5354: | |
| 5355: | |
| 5356: | |
| 5357: | |
| 5358: | |
| 5359: | |
| 5360: | |
| 5361: | |
| 5362: | |
| 5363: | |
| 5364: | |
| 5365: | |
| 5366: | |
| 5367: | |
| 5368: | |
| 5369: | |
| 5370: | |
| 5371: | |
| 5372: | |
| 5373: | |
| 5374: | |
| 5375: | |
| 5376: | |
| 5377: | |
| 5378: | |
| 5379: | |
| 5380: | |
| 5381: | |
| 5382: | |
| 5383: | |
| 5384: | |
| 5385: | |
| 5386: | |
| 5387: | |
| 5388: | |
| 5389: | |
| 5390: | |
| 5391: | |
| 5392: | |
| 5393: | |
| 5394: | |
| 5395: | |
| 5396: | |
| 5397: | |
| 5398: | |
| 5399: | |
| 5400: | |
| 5401: | |
| 5402: | |
| 5403: | |
| 5404: | |
| 5405: | |
| 5406: | |
| 5407: | |
| 5408: | public function UpdateSignature($AccountID, $UseSignature = null, $Signature = null, $IdentityId = null) |
| 5409: | { |
| 5410: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 5411: | |
| 5412: | if ($AccountID > 0) { |
| 5413: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 5414: | |
| 5415: | self::checkAccountAccess($oAccount); |
| 5416: | |
| 5417: | if ($Signature !== null) { |
| 5418: | $Signature = HtmlUtils::ClearHtml($Signature); |
| 5419: | } |
| 5420: | |
| 5421: | if ($this->oModuleSettings->AllowIdentities && $IdentityId !== null) { |
| 5422: | return $this->getIdentitiesManager()->updateIdentitySignature($IdentityId, $AccountID, $UseSignature, $Signature); |
| 5423: | } else { |
| 5424: | if ($oAccount) { |
| 5425: | if ($UseSignature !== null) { |
| 5426: | $oAccount->UseSignature = $UseSignature; |
| 5427: | } |
| 5428: | if ($Signature !== null) { |
| 5429: | $oAccount->Signature = $Signature; |
| 5430: | } |
| 5431: | |
| 5432: | return !!$this->getAccountsManager()->updateAccount($oAccount); |
| 5433: | } |
| 5434: | } |
| 5435: | } else { |
| 5436: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::InvalidInputParameter); |
| 5437: | } |
| 5438: | |
| 5439: | return false; |
| 5440: | } |
| 5441: | |
| 5442: | |
| 5443: | |
| 5444: | |
| 5445: | |
| 5446: | |
| 5447: | |
| 5448: | |
| 5449: | |
| 5450: | |
| 5451: | |
| 5452: | |
| 5453: | |
| 5454: | |
| 5455: | |
| 5456: | |
| 5457: | |
| 5458: | |
| 5459: | |
| 5460: | |
| 5461: | |
| 5462: | |
| 5463: | |
| 5464: | |
| 5465: | |
| 5466: | |
| 5467: | |
| 5468: | |
| 5469: | |
| 5470: | |
| 5471: | |
| 5472: | |
| 5473: | |
| 5474: | |
| 5475: | |
| 5476: | |
| 5477: | |
| 5478: | |
| 5479: | |
| 5480: | |
| 5481: | |
| 5482: | |
| 5483: | |
| 5484: | |
| 5485: | |
| 5486: | |
| 5487: | |
| 5488: | |
| 5489: | |
| 5490: | |
| 5491: | |
| 5492: | |
| 5493: | |
| 5494: | |
| 5495: | |
| 5496: | |
| 5497: | |
| 5498: | |
| 5499: | |
| 5500: | public function UploadAttachment($UserId, $AccountID, $UploadData) |
| 5501: | { |
| 5502: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 5503: | |
| 5504: | $sUUID = \Aurora\System\Api::getUserUUIDById($UserId); |
| 5505: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 5506: | |
| 5507: | self::checkAccountAccess($oAccount); |
| 5508: | |
| 5509: | $sError = ''; |
| 5510: | $aResponse = array(); |
| 5511: | |
| 5512: | if ($oAccount instanceof \Aurora\Modules\Mail\Models\MailAccount) { |
| 5513: | if (\is_array($UploadData)) { |
| 5514: | $sSavedName = 'upload-post-' . \md5($UploadData['name'] . $UploadData['tmp_name']); |
| 5515: | $rData = false; |
| 5516: | if (\is_resource($UploadData['tmp_name'])) { |
| 5517: | $rData = $UploadData['tmp_name']; |
| 5518: | } else { |
| 5519: | if ($this->getFilecacheManager()->moveUploadedFile($sUUID, $sSavedName, $UploadData['tmp_name'])) { |
| 5520: | $rData = $this->getFilecacheManager()->getFile($sUUID, $sSavedName); |
| 5521: | } |
| 5522: | } |
| 5523: | if ($rData) { |
| 5524: | $sUploadName = $UploadData['name']; |
| 5525: | $iSize = $UploadData['size']; |
| 5526: | $aResponse['Attachment'] = \Aurora\System\Utils::GetClientFileResponse( |
| 5527: | null, |
| 5528: | $UserId, |
| 5529: | $sUploadName, |
| 5530: | $sSavedName, |
| 5531: | $iSize |
| 5532: | ); |
| 5533: | } else { |
| 5534: | $sError = 'unknown'; |
| 5535: | } |
| 5536: | } else { |
| 5537: | $sError = 'unknown'; |
| 5538: | } |
| 5539: | } else { |
| 5540: | $sError = 'auth'; |
| 5541: | } |
| 5542: | |
| 5543: | if (0 < strlen($sError)) { |
| 5544: | $aResponse['Error'] = $sError; |
| 5545: | } |
| 5546: | |
| 5547: | return $aResponse; |
| 5548: | } |
| 5549: | |
| 5550: | |
| 5551: | |
| 5552: | |
| 5553: | |
| 5554: | |
| 5555: | |
| 5556: | |
| 5557: | |
| 5558: | |
| 5559: | |
| 5560: | |
| 5561: | |
| 5562: | |
| 5563: | |
| 5564: | |
| 5565: | |
| 5566: | |
| 5567: | |
| 5568: | |
| 5569: | |
| 5570: | |
| 5571: | |
| 5572: | |
| 5573: | |
| 5574: | |
| 5575: | |
| 5576: | |
| 5577: | |
| 5578: | |
| 5579: | |
| 5580: | |
| 5581: | |
| 5582: | |
| 5583: | |
| 5584: | |
| 5585: | |
| 5586: | |
| 5587: | |
| 5588: | |
| 5589: | |
| 5590: | |
| 5591: | |
| 5592: | |
| 5593: | |
| 5594: | |
| 5595: | |
| 5596: | |
| 5597: | |
| 5598: | |
| 5599: | |
| 5600: | |
| 5601: | |
| 5602: | |
| 5603: | |
| 5604: | |
| 5605: | public function SaveAttachmentsAsTempFiles($AccountID, $Attachments = array()) |
| 5606: | { |
| 5607: | $mResult = false; |
| 5608: | $self = $this; |
| 5609: | |
| 5610: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 5611: | |
| 5612: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 5613: | |
| 5614: | self::checkAccountAccess($oAccount); |
| 5615: | |
| 5616: | if ($oAccount instanceof \Aurora\Modules\Mail\Models\MailAccount) { |
| 5617: | $sUUID = \Aurora\System\Api::getUserUUIDById($oAccount->IdUser); |
| 5618: | try { |
| 5619: | if (is_array($Attachments) && 0 < count($Attachments)) { |
| 5620: | $mResult = array(); |
| 5621: | foreach ($Attachments as $sAttachment) { |
| 5622: | $aValues = \Aurora\System\Api::DecodeKeyValues($sAttachment); |
| 5623: | if (is_array($aValues) && isset($aValues['AccountID']) && $aValues['AccountID'] === $AccountID) { |
| 5624: | |
| 5625: | $sFolder = isset($aValues['Folder']) ? $aValues['Folder'] : ''; |
| 5626: | $iUid = (int) isset($aValues['Uid']) ? $aValues['Uid'] : 0; |
| 5627: | $sMimeIndex = (string) isset($aValues['MimeIndex']) ? $aValues['MimeIndex'] : ''; |
| 5628: | |
| 5629: | $sTempName = md5($sAttachment); |
| 5630: | if (!$this->getFilecacheManager()->isFileExists($sUUID, $sTempName)) { |
| 5631: | $this->getMailManager()->directMessageToStream( |
| 5632: | $oAccount, |
| 5633: | function ($rResource, $sContentType, $sFileName, $sMimeIndex = '') use ($sUUID, &$mResult, $sTempName, $sAttachment, $self) { |
| 5634: | if (is_resource($rResource)) { |
| 5635: | $sContentType = (empty($sFileName)) ? 'text/plain' : \MailSo\Base\Utils::MimeContentType($sFileName); |
| 5636: | $sFileName = \Aurora\System\Utils::clearFileName($sFileName, $sContentType, $sMimeIndex); |
| 5637: | |
| 5638: | if ($self->getFilecacheManager()->putFile($sUUID, $sTempName, $rResource)) { |
| 5639: | $mResult[$sTempName] = $sAttachment; |
| 5640: | } |
| 5641: | } |
| 5642: | }, |
| 5643: | $sFolder, |
| 5644: | $iUid, |
| 5645: | $sMimeIndex |
| 5646: | ); |
| 5647: | } else { |
| 5648: | $mResult[$sTempName] = $sAttachment; |
| 5649: | } |
| 5650: | } else { |
| 5651: | Api::Log('Error: can\'t read attachment data from hash.'); |
| 5652: | } |
| 5653: | } |
| 5654: | } |
| 5655: | } catch (\Exception $oException) { |
| 5656: | throw new \Aurora\Modules\Mail\Exceptions\Exception(Enums\ErrorCodes::CannotConnectToMailServer, $oException, $oException->getMessage()); |
| 5657: | } |
| 5658: | } |
| 5659: | |
| 5660: | return $mResult; |
| 5661: | } |
| 5662: | |
| 5663: | |
| 5664: | |
| 5665: | |
| 5666: | |
| 5667: | |
| 5668: | |
| 5669: | |
| 5670: | |
| 5671: | |
| 5672: | |
| 5673: | |
| 5674: | |
| 5675: | |
| 5676: | |
| 5677: | |
| 5678: | |
| 5679: | |
| 5680: | |
| 5681: | |
| 5682: | |
| 5683: | |
| 5684: | |
| 5685: | |
| 5686: | |
| 5687: | |
| 5688: | |
| 5689: | |
| 5690: | |
| 5691: | |
| 5692: | |
| 5693: | |
| 5694: | |
| 5695: | |
| 5696: | |
| 5697: | |
| 5698: | |
| 5699: | |
| 5700: | |
| 5701: | |
| 5702: | |
| 5703: | |
| 5704: | |
| 5705: | |
| 5706: | |
| 5707: | |
| 5708: | |
| 5709: | |
| 5710: | |
| 5711: | |
| 5712: | |
| 5713: | |
| 5714: | |
| 5715: | |
| 5716: | |
| 5717: | |
| 5718: | |
| 5719: | |
| 5720: | |
| 5721: | |
| 5722: | |
| 5723: | |
| 5724: | |
| 5725: | |
| 5726: | public function SaveMessageAsTempFile($AccountID, $MessageFolder, $MessageUid, $FileName) |
| 5727: | { |
| 5728: | $mResult = false; |
| 5729: | $self = $this; |
| 5730: | |
| 5731: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 5732: | |
| 5733: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 5734: | |
| 5735: | self::checkAccountAccess($oAccount); |
| 5736: | |
| 5737: | if ($oAccount instanceof \Aurora\Modules\Mail\Models\MailAccount) { |
| 5738: | $sUUID = \Aurora\System\Api::getUserUUIDById($oAccount->IdUser); |
| 5739: | try { |
| 5740: | $sMimeType = 'message/rfc822'; |
| 5741: | $sTempName = md5($MessageFolder . $MessageUid); |
| 5742: | if (!$this->getFilecacheManager()->isFileExists($sUUID, $sTempName)) { |
| 5743: | $this->getMailManager()->directMessageToStream( |
| 5744: | $oAccount, |
| 5745: | function ($rResource, $sContentType, $sFileName) use ($sUUID, $sTempName, &$sMimeType, $self) { |
| 5746: | if (is_resource($rResource)) { |
| 5747: | $sMimeType = $sContentType; |
| 5748: | $sFileName = \Aurora\System\Utils::clearFileName($sFileName, $sMimeType, ''); |
| 5749: | $self->getFilecacheManager()->putFile($sUUID, $sTempName, $rResource); |
| 5750: | } |
| 5751: | }, |
| 5752: | $MessageFolder, |
| 5753: | $MessageUid |
| 5754: | ); |
| 5755: | } |
| 5756: | |
| 5757: | if ($this->getFilecacheManager()->isFileExists($sUUID, $sTempName)) { |
| 5758: | $iSize = $this->getFilecacheManager()->fileSize($sUUID, $sTempName); |
| 5759: | $mResult = \Aurora\System\Utils::GetClientFileResponse( |
| 5760: | null, |
| 5761: | $oAccount->IdUser, |
| 5762: | $FileName, |
| 5763: | $sTempName, |
| 5764: | $iSize |
| 5765: | ); |
| 5766: | } |
| 5767: | } catch (\Exception $oException) { |
| 5768: | throw new \Aurora\Modules\Mail\Exceptions\Exception(Enums\ErrorCodes::CannotConnectToMailServer, $oException, $oException->getMessage()); |
| 5769: | } |
| 5770: | } |
| 5771: | |
| 5772: | return $mResult; |
| 5773: | } |
| 5774: | |
| 5775: | |
| 5776: | |
| 5777: | |
| 5778: | |
| 5779: | |
| 5780: | |
| 5781: | |
| 5782: | |
| 5783: | |
| 5784: | |
| 5785: | |
| 5786: | |
| 5787: | |
| 5788: | |
| 5789: | |
| 5790: | |
| 5791: | |
| 5792: | |
| 5793: | |
| 5794: | |
| 5795: | |
| 5796: | |
| 5797: | |
| 5798: | |
| 5799: | |
| 5800: | |
| 5801: | |
| 5802: | |
| 5803: | |
| 5804: | |
| 5805: | |
| 5806: | |
| 5807: | |
| 5808: | |
| 5809: | |
| 5810: | |
| 5811: | |
| 5812: | |
| 5813: | |
| 5814: | |
| 5815: | |
| 5816: | |
| 5817: | |
| 5818: | |
| 5819: | |
| 5820: | |
| 5821: | |
| 5822: | |
| 5823: | |
| 5824: | |
| 5825: | |
| 5826: | |
| 5827: | |
| 5828: | |
| 5829: | |
| 5830: | |
| 5831: | |
| 5832: | public function UploadMessage($AccountID, $Folder, $UploadData) |
| 5833: | { |
| 5834: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 5835: | |
| 5836: | $bResult = false; |
| 5837: | |
| 5838: | $oAccount = $this->getAccountsManager()->getAccountById((int)$AccountID); |
| 5839: | |
| 5840: | self::checkAccountAccess($oAccount); |
| 5841: | |
| 5842: | if ($oAccount) { |
| 5843: | $sUUID = \Aurora\System\Api::getUserUUIDById($oAccount->IdUser); |
| 5844: | if (is_array($UploadData)) { |
| 5845: | $sUploadName = $UploadData['name']; |
| 5846: | $bIsEmlExtension = strtolower(pathinfo($sUploadName, PATHINFO_EXTENSION)) === 'eml'; |
| 5847: | |
| 5848: | if ($bIsEmlExtension) { |
| 5849: | $sSavedName = 'upload-post-' . md5($UploadData['name'] . $UploadData['tmp_name']); |
| 5850: | if (is_resource($UploadData['tmp_name'])) { |
| 5851: | $this->getFilecacheManager()->putFile($sUUID, $sSavedName, $UploadData['tmp_name']); |
| 5852: | } else { |
| 5853: | $this->getFilecacheManager()->moveUploadedFile($sUUID, $sSavedName, $UploadData['tmp_name']); |
| 5854: | } |
| 5855: | if ($this->getFilecacheManager()->isFileExists($sUUID, $sSavedName)) { |
| 5856: | $sSavedFullName = $this->getFilecacheManager()->generateFullFilePath($sUUID, $sSavedName); |
| 5857: | try { |
| 5858: | $this->getMailManager()->appendMessageFromFile($oAccount, $sSavedFullName, $Folder); |
| 5859: | $bResult = true; |
| 5860: | } catch (\Exception $oException) { |
| 5861: | throw new \Aurora\Modules\Mail\Exceptions\Exception(Enums\ErrorCodes::CannotUploadMessage, $oException, $oException->getMessage()); |
| 5862: | } |
| 5863: | } else { |
| 5864: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::UnknownError); |
| 5865: | } |
| 5866: | } else { |
| 5867: | throw new \Aurora\Modules\Mail\Exceptions\Exception(Enums\ErrorCodes::CannotUploadMessageFileNotEml); |
| 5868: | } |
| 5869: | } |
| 5870: | } else { |
| 5871: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::InvalidInputParameter); |
| 5872: | } |
| 5873: | |
| 5874: | return $bResult; |
| 5875: | } |
| 5876: | |
| 5877: | |
| 5878: | |
| 5879: | |
| 5880: | |
| 5881: | |
| 5882: | |
| 5883: | |
| 5884: | |
| 5885: | |
| 5886: | |
| 5887: | |
| 5888: | |
| 5889: | |
| 5890: | |
| 5891: | |
| 5892: | |
| 5893: | |
| 5894: | |
| 5895: | |
| 5896: | |
| 5897: | |
| 5898: | |
| 5899: | |
| 5900: | |
| 5901: | |
| 5902: | |
| 5903: | |
| 5904: | |
| 5905: | |
| 5906: | |
| 5907: | |
| 5908: | |
| 5909: | |
| 5910: | |
| 5911: | |
| 5912: | |
| 5913: | |
| 5914: | |
| 5915: | |
| 5916: | |
| 5917: | |
| 5918: | |
| 5919: | |
| 5920: | |
| 5921: | |
| 5922: | |
| 5923: | |
| 5924: | |
| 5925: | |
| 5926: | |
| 5927: | |
| 5928: | |
| 5929: | |
| 5930: | |
| 5931: | |
| 5932: | |
| 5933: | public function ChangePassword($AccountId, $CurrentPassword, $NewPassword) |
| 5934: | { |
| 5935: | $mResult = false; |
| 5936: | $oAccount = null; |
| 5937: | |
| 5938: | if ($AccountId > 0) { |
| 5939: | $oAccount = $this->getAccountsManager()->getAccountById($AccountId); |
| 5940: | |
| 5941: | self::checkAccountAccess($oAccount); |
| 5942: | |
| 5943: | if ($oAccount instanceof Models\MailAccount) { |
| 5944: | $oUser = \Aurora\Modules\Core\Module::getInstance()->GetUser($oAccount->IdUser); |
| 5945: | if ($oAccount->getPassword() !== $CurrentPassword) { |
| 5946: | \Aurora\System\Api::LogEvent('password-change-failed: ' . $oAccount->Email, self::GetName()); |
| 5947: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::AccountOldPasswordNotCorrect); |
| 5948: | } |
| 5949: | |
| 5950: | $aArgs = [ |
| 5951: | 'Account' => $oAccount, |
| 5952: | 'CurrentPassword' => $CurrentPassword, |
| 5953: | 'NewPassword' => $NewPassword |
| 5954: | ]; |
| 5955: | $aResponse = [ |
| 5956: | 'AccountPasswordChanged' => false |
| 5957: | ]; |
| 5958: | |
| 5959: | $this->broadcastEvent( |
| 5960: | 'ChangeAccountPassword', |
| 5961: | $aArgs, |
| 5962: | $aResponse |
| 5963: | ); |
| 5964: | |
| 5965: | if ($aResponse['AccountPasswordChanged']) { |
| 5966: | $oAccount->setPassword($NewPassword); |
| 5967: | if ($this->getAccountsManager()->updateAccount($oAccount)) { |
| 5968: | $mResult = $oAccount; |
| 5969: | $mResult->RefreshToken = \Aurora\System\Api::UserSession()->UpdateTimestamp(\Aurora\System\Api::getAuthToken(), time()); |
| 5970: | \Aurora\System\Api::LogEvent('password-change-success: ' . $oAccount->Email, self::GetName()); |
| 5971: | \Aurora\System\Api::UserSession()->DeleteAllAccountSessions($oAccount); |
| 5972: | } |
| 5973: | } |
| 5974: | } |
| 5975: | } |
| 5976: | if (!$mResult) { |
| 5977: | \Aurora\System\Api::LogEvent('password-change-failed: ' . ($oAccount ? $oAccount->Email : 'Account ID ') . $AccountId, self::GetName()); |
| 5978: | } |
| 5979: | |
| 5980: | return $mResult; |
| 5981: | } |
| 5982: | |
| 5983: | |
| 5984: | |
| 5985: | |
| 5986: | |
| 5987: | |
| 5988: | |
| 5989: | |
| 5990: | |
| 5991: | |
| 5992: | |
| 5993: | |
| 5994: | |
| 5995: | |
| 5996: | |
| 5997: | |
| 5998: | |
| 5999: | |
| 6000: | |
| 6001: | |
| 6002: | |
| 6003: | |
| 6004: | |
| 6005: | |
| 6006: | |
| 6007: | |
| 6008: | |
| 6009: | |
| 6010: | |
| 6011: | |
| 6012: | |
| 6013: | |
| 6014: | |
| 6015: | |
| 6016: | |
| 6017: | |
| 6018: | |
| 6019: | |
| 6020: | |
| 6021: | |
| 6022: | |
| 6023: | |
| 6024: | |
| 6025: | |
| 6026: | |
| 6027: | |
| 6028: | |
| 6029: | |
| 6030: | |
| 6031: | |
| 6032: | |
| 6033: | |
| 6034: | |
| 6035: | public function GetFilters($AccountID) |
| 6036: | { |
| 6037: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 6038: | |
| 6039: | $mResult = false; |
| 6040: | |
| 6041: | $oAccount = $this->getAccountsManager()->getAccountById((int) $AccountID); |
| 6042: | |
| 6043: | self::checkAccountAccess($oAccount); |
| 6044: | |
| 6045: | if ($oAccount) { |
| 6046: | $mResult = $this->getSieveManager()->getSieveFilters($oAccount); |
| 6047: | } |
| 6048: | |
| 6049: | return $mResult; |
| 6050: | } |
| 6051: | |
| 6052: | |
| 6053: | |
| 6054: | |
| 6055: | |
| 6056: | |
| 6057: | |
| 6058: | |
| 6059: | |
| 6060: | |
| 6061: | |
| 6062: | |
| 6063: | |
| 6064: | |
| 6065: | |
| 6066: | |
| 6067: | |
| 6068: | |
| 6069: | |
| 6070: | |
| 6071: | |
| 6072: | |
| 6073: | |
| 6074: | |
| 6075: | |
| 6076: | |
| 6077: | |
| 6078: | |
| 6079: | |
| 6080: | |
| 6081: | |
| 6082: | |
| 6083: | |
| 6084: | |
| 6085: | |
| 6086: | |
| 6087: | |
| 6088: | |
| 6089: | |
| 6090: | |
| 6091: | |
| 6092: | |
| 6093: | |
| 6094: | |
| 6095: | |
| 6096: | |
| 6097: | |
| 6098: | |
| 6099: | |
| 6100: | |
| 6101: | |
| 6102: | |
| 6103: | |
| 6104: | |
| 6105: | |
| 6106: | |
| 6107: | public function UpdateFilters($AccountID, $Filters) |
| 6108: | { |
| 6109: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 6110: | |
| 6111: | $bResult = false; |
| 6112: | |
| 6113: | $oAccount = $this->getAccountsManager()->getAccountById((int) $AccountID); |
| 6114: | |
| 6115: | self::checkAccountAccess($oAccount); |
| 6116: | |
| 6117: | if ($oAccount) { |
| 6118: | $aFilters = array(); |
| 6119: | |
| 6120: | if (is_array($Filters)) { |
| 6121: | foreach ($Filters as $aFilterData) { |
| 6122: | $oFilter = $this->getSieveManager()->createFilterInstance($oAccount, $aFilterData); |
| 6123: | |
| 6124: | $aArgs = [ |
| 6125: | 'Account' => $oAccount, |
| 6126: | 'Filter' => &$oFilter, |
| 6127: | ]; |
| 6128: | $this->broadcastEvent('CreateFilterInstance', $aArgs); |
| 6129: | |
| 6130: | if ($oFilter) { |
| 6131: | $aFilters[] = $oFilter; |
| 6132: | } |
| 6133: | } |
| 6134: | } |
| 6135: | |
| 6136: | $bResult = $this->getSieveManager()->updateSieveFilters($oAccount, $aFilters); |
| 6137: | } |
| 6138: | |
| 6139: | return $bResult; |
| 6140: | } |
| 6141: | |
| 6142: | |
| 6143: | |
| 6144: | |
| 6145: | |
| 6146: | |
| 6147: | |
| 6148: | |
| 6149: | |
| 6150: | |
| 6151: | |
| 6152: | |
| 6153: | |
| 6154: | |
| 6155: | |
| 6156: | |
| 6157: | |
| 6158: | |
| 6159: | |
| 6160: | |
| 6161: | |
| 6162: | |
| 6163: | |
| 6164: | |
| 6165: | |
| 6166: | |
| 6167: | |
| 6168: | |
| 6169: | |
| 6170: | |
| 6171: | |
| 6172: | |
| 6173: | |
| 6174: | |
| 6175: | |
| 6176: | |
| 6177: | |
| 6178: | |
| 6179: | |
| 6180: | |
| 6181: | |
| 6182: | |
| 6183: | |
| 6184: | |
| 6185: | |
| 6186: | |
| 6187: | |
| 6188: | |
| 6189: | |
| 6190: | |
| 6191: | |
| 6192: | |
| 6193: | |
| 6194: | |
| 6195: | |
| 6196: | public function GetForward($AccountID) |
| 6197: | { |
| 6198: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 6199: | |
| 6200: | $mResult = false; |
| 6201: | |
| 6202: | $oAccount = $this->getAccountsManager()->getAccountById((int) $AccountID); |
| 6203: | |
| 6204: | self::checkAccountAccess($oAccount); |
| 6205: | |
| 6206: | if ($oAccount) { |
| 6207: | $mResult = $this->getSieveManager()->getForward($oAccount); |
| 6208: | } |
| 6209: | |
| 6210: | return $mResult; |
| 6211: | } |
| 6212: | |
| 6213: | |
| 6214: | |
| 6215: | |
| 6216: | |
| 6217: | |
| 6218: | |
| 6219: | |
| 6220: | |
| 6221: | |
| 6222: | |
| 6223: | |
| 6224: | |
| 6225: | |
| 6226: | |
| 6227: | |
| 6228: | |
| 6229: | |
| 6230: | |
| 6231: | |
| 6232: | |
| 6233: | |
| 6234: | |
| 6235: | |
| 6236: | |
| 6237: | |
| 6238: | |
| 6239: | |
| 6240: | |
| 6241: | |
| 6242: | |
| 6243: | |
| 6244: | |
| 6245: | |
| 6246: | |
| 6247: | |
| 6248: | |
| 6249: | |
| 6250: | |
| 6251: | |
| 6252: | |
| 6253: | |
| 6254: | |
| 6255: | |
| 6256: | |
| 6257: | |
| 6258: | |
| 6259: | |
| 6260: | |
| 6261: | |
| 6262: | |
| 6263: | |
| 6264: | |
| 6265: | |
| 6266: | |
| 6267: | |
| 6268: | |
| 6269: | |
| 6270: | public function UpdateForward($AccountID, $Enable = false, $Email = "", $KeepMessageCopy = true) |
| 6271: | { |
| 6272: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 6273: | |
| 6274: | $mResult = false; |
| 6275: | |
| 6276: | $oAccount = $this->getAccountsManager()->getAccountById((int) $AccountID); |
| 6277: | |
| 6278: | self::checkAccountAccess($oAccount); |
| 6279: | |
| 6280: | if ($oAccount) { |
| 6281: | $mResult = $this->getSieveManager()->setForward($oAccount, $Email, $Enable, $KeepMessageCopy); |
| 6282: | } |
| 6283: | |
| 6284: | return $mResult; |
| 6285: | } |
| 6286: | |
| 6287: | |
| 6288: | |
| 6289: | |
| 6290: | |
| 6291: | |
| 6292: | |
| 6293: | |
| 6294: | |
| 6295: | |
| 6296: | |
| 6297: | |
| 6298: | |
| 6299: | |
| 6300: | |
| 6301: | |
| 6302: | |
| 6303: | |
| 6304: | |
| 6305: | |
| 6306: | |
| 6307: | |
| 6308: | |
| 6309: | |
| 6310: | |
| 6311: | |
| 6312: | |
| 6313: | |
| 6314: | |
| 6315: | |
| 6316: | |
| 6317: | |
| 6318: | |
| 6319: | |
| 6320: | |
| 6321: | |
| 6322: | |
| 6323: | |
| 6324: | |
| 6325: | |
| 6326: | |
| 6327: | |
| 6328: | |
| 6329: | |
| 6330: | |
| 6331: | |
| 6332: | |
| 6333: | |
| 6334: | |
| 6335: | |
| 6336: | |
| 6337: | |
| 6338: | |
| 6339: | |
| 6340: | |
| 6341: | |
| 6342: | public function GetAutoresponder($AccountID) |
| 6343: | { |
| 6344: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 6345: | |
| 6346: | $mResult = false; |
| 6347: | |
| 6348: | $oAccount = $this->getAccountsManager()->getAccountById((int) $AccountID); |
| 6349: | |
| 6350: | self::checkAccountAccess($oAccount); |
| 6351: | |
| 6352: | if ($oAccount) { |
| 6353: | $mResult = $this->getSieveManager()->getAutoresponder($oAccount); |
| 6354: | if ($mResult) { |
| 6355: | if ($this->oModuleSettings->AllowScheduledAutoresponder) { |
| 6356: | $mResult['Scheduled'] = $oAccount->getExtendedProp(self::GetName() . '::' . 'AutoresponderScheduled', false); |
| 6357: | $mResult['Start'] = $oAccount->getExtendedProp(self::GetName() . '::' . 'AutoresponderStart'); |
| 6358: | $mResult['End'] = $oAccount->getExtendedProp(self::GetName() . '::' . 'AutoresponderEnd'); |
| 6359: | if ($mResult['Scheduled'] && !$mResult['Enable']) { |
| 6360: | $mResult['Enable'] = true; |
| 6361: | } |
| 6362: | } |
| 6363: | } |
| 6364: | } |
| 6365: | |
| 6366: | return $mResult; |
| 6367: | } |
| 6368: | |
| 6369: | |
| 6370: | |
| 6371: | |
| 6372: | |
| 6373: | |
| 6374: | |
| 6375: | |
| 6376: | |
| 6377: | |
| 6378: | |
| 6379: | |
| 6380: | |
| 6381: | |
| 6382: | |
| 6383: | |
| 6384: | |
| 6385: | |
| 6386: | |
| 6387: | |
| 6388: | |
| 6389: | |
| 6390: | |
| 6391: | |
| 6392: | |
| 6393: | |
| 6394: | |
| 6395: | |
| 6396: | |
| 6397: | |
| 6398: | |
| 6399: | |
| 6400: | |
| 6401: | |
| 6402: | |
| 6403: | |
| 6404: | |
| 6405: | |
| 6406: | |
| 6407: | |
| 6408: | |
| 6409: | |
| 6410: | |
| 6411: | |
| 6412: | |
| 6413: | |
| 6414: | |
| 6415: | |
| 6416: | |
| 6417: | |
| 6418: | |
| 6419: | |
| 6420: | |
| 6421: | |
| 6422: | |
| 6423: | |
| 6424: | |
| 6425: | |
| 6426: | |
| 6427: | public function UpdateAutoresponder($AccountID, $Enable = false, $Subject = "", $Message = "", $Scheduled = false, $Start = null, $End = null) |
| 6428: | { |
| 6429: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 6430: | |
| 6431: | $mResult = false; |
| 6432: | |
| 6433: | $oAccount = $this->getAccountsManager()->getAccountById((int) $AccountID); |
| 6434: | |
| 6435: | self::checkAccountAccess($oAccount); |
| 6436: | |
| 6437: | if ($Enable && \trim($Subject) === "" && \trim($Message) === "") { |
| 6438: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::InvalidInputParameter); |
| 6439: | } |
| 6440: | |
| 6441: | if ($oAccount) { |
| 6442: | $currentAutoresponderScheduled = $oAccount->getExtendedProp(self::GetName() . '::' . 'AutoresponderScheduled'); |
| 6443: | if ($this->oModuleSettings->AllowScheduledAutoresponder) { |
| 6444: | if ($Scheduled && $Start > time()) { |
| 6445: | $Enable = false; |
| 6446: | } |
| 6447: | |
| 6448: | $oAccount->setExtendedProp(self::GetName() . '::' . 'AutoresponderScheduled', $Scheduled); |
| 6449: | $oAccount->setExtendedProp(self::GetName() . '::' . 'AutoresponderStart', $Start); |
| 6450: | $oAccount->setExtendedProp(self::GetName() . '::' . 'AutoresponderEnd', $End); |
| 6451: | $oAccount->save(); |
| 6452: | } elseif ($currentAutoresponderScheduled === true) { |
| 6453: | $oAccount->setExtendedProp(self::GetName() . '::' . 'AutoresponderScheduled', false); |
| 6454: | $oAccount->save(); |
| 6455: | } |
| 6456: | |
| 6457: | $mResult = $this->getSieveManager()->setAutoresponder($oAccount, $Subject, $Message, $Enable); |
| 6458: | } |
| 6459: | |
| 6460: | return $mResult; |
| 6461: | } |
| 6462: | |
| 6463: | public function SetAccountSpamSettings($AccountID, $SpamScore, $AllowList, $BlockList) |
| 6464: | { |
| 6465: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 6466: | |
| 6467: | $mResult = false; |
| 6468: | |
| 6469: | $oAccount = $this->getAccountsManager()->getAccountById((int) $AccountID); |
| 6470: | |
| 6471: | self::checkAccountAccess($oAccount); |
| 6472: | |
| 6473: | if ($oAccount) { |
| 6474: | $mResult = $this->getSieveManager()->setAllowBlockLists($oAccount, $AllowList, $BlockList, $SpamScore); |
| 6475: | } |
| 6476: | |
| 6477: | return $mResult; |
| 6478: | } |
| 6479: | |
| 6480: | public function GetAccountSpamSettings($AccountID) |
| 6481: | { |
| 6482: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 6483: | |
| 6484: | $mResult = false; |
| 6485: | |
| 6486: | $oAccount = $this->getAccountsManager()->getAccountById((int) $AccountID); |
| 6487: | |
| 6488: | self::checkAccountAccess($oAccount); |
| 6489: | |
| 6490: | if ($oAccount) { |
| 6491: | $mResult = $this->getSieveManager()->getAllowBlockLists($oAccount); |
| 6492: | } |
| 6493: | |
| 6494: | return $mResult; |
| 6495: | } |
| 6496: | |
| 6497: | public function AddEmailToAllowList($AccountID, $Email) |
| 6498: | { |
| 6499: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 6500: | |
| 6501: | $mResult = false; |
| 6502: | |
| 6503: | $oAccount = $this->getAccountsManager()->getAccountById((int) $AccountID); |
| 6504: | |
| 6505: | self::checkAccountAccess($oAccount); |
| 6506: | |
| 6507: | if ($oAccount) { |
| 6508: | $mResult = $this->getSieveManager()->addRowToAllowList($oAccount, $Email); |
| 6509: | } |
| 6510: | |
| 6511: | return $mResult; |
| 6512: | } |
| 6513: | |
| 6514: | public function AddEmailToBlockList($AccountID, $Email) |
| 6515: | { |
| 6516: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 6517: | |
| 6518: | $mResult = false; |
| 6519: | |
| 6520: | $oAccount = $this->getAccountsManager()->getAccountById((int) $AccountID); |
| 6521: | |
| 6522: | self::checkAccountAccess($oAccount); |
| 6523: | |
| 6524: | if ($oAccount) { |
| 6525: | $mResult = $this->getSieveManager()->addRowToBlockList($oAccount, $Email); |
| 6526: | } |
| 6527: | |
| 6528: | return $mResult; |
| 6529: | } |
| 6530: | |
| 6531: | |
| 6532: | |
| 6533: | |
| 6534: | |
| 6535: | |
| 6536: | |
| 6537: | |
| 6538: | |
| 6539: | |
| 6540: | |
| 6541: | public function onBeforeDeleteUser($aArgs, &$mResult) |
| 6542: | { |
| 6543: | $mResult = $this->getAccountsManager()->getUserAccounts($aArgs["UserId"]); |
| 6544: | |
| 6545: | foreach ($mResult as $oItem) { |
| 6546: | self::Decorator()->DeleteAccount($oItem->Id); |
| 6547: | } |
| 6548: | } |
| 6549: | |
| 6550: | public function onAfterDeleteUser($aArgs, &$mResult) |
| 6551: | { |
| 6552: | if ($mResult) { |
| 6553: | Identity::where('IdUser', $aArgs["UserId"])->delete(); |
| 6554: | TrustedSender::where('IdUser', $aArgs["UserId"])->delete(); |
| 6555: | } |
| 6556: | } |
| 6557: | |
| 6558: | |
| 6559: | |
| 6560: | |
| 6561: | |
| 6562: | |
| 6563: | |
| 6564: | public function GetMailServerByDomain($Domain, $AllowWildcardDomain = false) |
| 6565: | { |
| 6566: | $aResult = []; |
| 6567: | $bFoundWithWildcard = false; |
| 6568: | |
| 6569: | $oServer = $this->getServersManager()->getServerByDomain($Domain); |
| 6570: | |
| 6571: | if (!($oServer instanceof \Aurora\Modules\Mail\Models\Server) && $AllowWildcardDomain) { |
| 6572: | $oServer = $this->getServersManager()->getServerByDomain('*'); |
| 6573: | $bFoundWithWildcard = true; |
| 6574: | } |
| 6575: | |
| 6576: | if (!($oServer instanceof \Aurora\Modules\Mail\Models\Server) && $AllowWildcardDomain) { |
| 6577: | $oServer = $this->getServersManager()->getServerByDomain(''); |
| 6578: | $bFoundWithWildcard = true; |
| 6579: | } |
| 6580: | |
| 6581: | if ($oServer instanceof \Aurora\Modules\Mail\Models\Server) { |
| 6582: | $aResult = [ |
| 6583: | 'Server' => $oServer, |
| 6584: | 'FoundWithWildcard' => $bFoundWithWildcard |
| 6585: | ]; |
| 6586: | } |
| 6587: | |
| 6588: | return $aResult; |
| 6589: | } |
| 6590: | |
| 6591: | |
| 6592: | |
| 6593: | |
| 6594: | |
| 6595: | |
| 6596: | |
| 6597: | |
| 6598: | |
| 6599: | public function onLogin($aArgs, &$mResult) |
| 6600: | { |
| 6601: | $bResult = false; |
| 6602: | $iUserId = 0; |
| 6603: | |
| 6604: | $sEmail = $sMailLogin = $aArgs['Login']; |
| 6605: | $sEmail = str_replace(" ", "", $sEmail); |
| 6606: | $oAccount = $this->getAccountsManager()->getAccountUsedToAuthorize($sEmail); |
| 6607: | |
| 6608: | $bNewAccount = false; |
| 6609: | $bAutocreateMailAccountOnNewUserFirstLogin = $this->oModuleSettings->AutocreateMailAccountOnNewUserFirstLogin; |
| 6610: | if (!$bAutocreateMailAccountOnNewUserFirstLogin && !$oAccount) { |
| 6611: | $oUser = \Aurora\Modules\Core\Module::Decorator()->GetUserByPublicId($sEmail); |
| 6612: | if ($oUser instanceof User) { |
| 6613: | $bAutocreateMailAccountOnNewUserFirstLogin = true; |
| 6614: | } |
| 6615: | } |
| 6616: | |
| 6617: | $oServer = null; |
| 6618: | if ($bAutocreateMailAccountOnNewUserFirstLogin && !$oAccount) { |
| 6619: | $sEmail = \strtolower($sEmail); |
| 6620: | $sDomain = \MailSo\Base\Utils::GetDomainFromEmail($sEmail); |
| 6621: | if (!empty(trim($sDomain))) { |
| 6622: | $aGetMailServerResult = self::Decorator()->GetMailServerByDomain($sDomain, true); |
| 6623: | if (!empty($aGetMailServerResult) && isset($aGetMailServerResult['Server']) && $aGetMailServerResult['Server'] instanceof \Aurora\Modules\Mail\Models\Server) { |
| 6624: | $oServer = $aGetMailServerResult['Server']; |
| 6625: | } |
| 6626: | |
| 6627: | $oTenant = \Aurora\System\Api::getTenantByWebDomain(); |
| 6628: | if ($oServer && (!$oTenant || $oServer->OwnerType === \Aurora\Modules\Mail\Enums\ServerOwnerType::SuperAdmin || $oServer->TenantId === $oTenant->Id)) { |
| 6629: | $sMailLogin = !$oServer->UseFullEmailAddressAsLogin && preg_match('/(.+)@.+$/', $sEmail, $matches) && $matches[1] ? $matches[1] : $sEmail; |
| 6630: | |
| 6631: | $oAccount = new \Aurora\Modules\Mail\Models\MailAccount(); |
| 6632: | $oAccount->Email = $sEmail; |
| 6633: | $oAccount->IncomingLogin = $sMailLogin; |
| 6634: | $oAccount->setPassword($aArgs['Password']); |
| 6635: | $oAccount->ServerId = $oServer->Id; |
| 6636: | $bNewAccount = true; |
| 6637: | } else { |
| 6638: | throw new \Aurora\System\Exceptions\ApiException( |
| 6639: | Enums\ErrorCodes::DomainIsNotAllowedForLoggingIn, |
| 6640: | null, |
| 6641: | '', |
| 6642: | [], |
| 6643: | $this |
| 6644: | ); |
| 6645: | } |
| 6646: | } |
| 6647: | } |
| 6648: | |
| 6649: | if ($oAccount instanceof \Aurora\Modules\Mail\Models\MailAccount) { |
| 6650: | try { |
| 6651: | $sOldPassword = $oAccount->getPassword(); |
| 6652: | $sNewPassword = $aArgs['Password']; |
| 6653: | |
| 6654: | $oAccount->setPassword($sNewPassword); |
| 6655: | $mValidResult = $this->getMailManager()->validateAccountConnection($oAccount, false); |
| 6656: | $bResult = !($mValidResult instanceof \Exception); |
| 6657: | |
| 6658: | if (!$bNewAccount && $bResult && $sNewPassword !== $sOldPassword) { |
| 6659: | |
| 6660: | $this->getAccountsManager()->updateAccount($oAccount); |
| 6661: | |
| 6662: | \Aurora\System\Api::UserSession()->DeleteAllAccountSessions($oAccount); |
| 6663: | } |
| 6664: | |
| 6665: | if ($bResult && $bAutocreateMailAccountOnNewUserFirstLogin && $bNewAccount) { |
| 6666: | $oUser = null; |
| 6667: | $aSubArgs = array( |
| 6668: | 'UserName' => $sEmail, |
| 6669: | 'Email' => $sEmail, |
| 6670: | 'UserId' => $iUserId, |
| 6671: | 'TenantId' => $oServer->TenantId |
| 6672: | ); |
| 6673: | $this->broadcastEvent( |
| 6674: | 'CreateAccount', |
| 6675: | $aSubArgs, |
| 6676: | $oUser |
| 6677: | ); |
| 6678: | |
| 6679: | if ($oUser instanceof User) { |
| 6680: | $iUserId = $oUser->Id; |
| 6681: | $bPrevState = \Aurora\System\Api::skipCheckUserRole(true); |
| 6682: | $oAccount = self::Decorator()->CreateAccount( |
| 6683: | $iUserId, |
| 6684: | '', |
| 6685: | $sEmail, |
| 6686: | $sMailLogin, |
| 6687: | $aArgs['Password'], |
| 6688: | array('ServerId' => $oServer->Id) |
| 6689: | ); |
| 6690: | \Aurora\System\Api::skipCheckUserRole($bPrevState); |
| 6691: | if ($oAccount) { |
| 6692: | $oAccount->UseToAuthorize = true; |
| 6693: | $oAccount->UseThreading = $oServer->EnableThreading; |
| 6694: | $bResult = $this->getAccountsManager()->updateAccount($oAccount); |
| 6695: | } else { |
| 6696: | $bResult = false; |
| 6697: | } |
| 6698: | } |
| 6699: | } |
| 6700: | |
| 6701: | if ($bResult) { |
| 6702: | $mResult = \Aurora\System\UserSession::getTokenData($oAccount, $aArgs['SignMe']); |
| 6703: | } |
| 6704: | } catch (\Aurora\System\Exceptions\ApiException $oException) { |
| 6705: | throw $oException; |
| 6706: | } catch (\Exception $oException) { |
| 6707: | } |
| 6708: | } |
| 6709: | |
| 6710: | return $bResult; |
| 6711: | } |
| 6712: | |
| 6713: | |
| 6714: | |
| 6715: | |
| 6716: | |
| 6717: | |
| 6718: | public function onGetAccounts($aArgs, &$aResult) |
| 6719: | { |
| 6720: | if (isset($aArgs['UserId'])) { |
| 6721: | $mResult = $this->GetAccounts($aArgs['UserId']); |
| 6722: | if (\is_array($mResult)) { |
| 6723: | foreach ($mResult as $oItem) { |
| 6724: | $aResult[] = [ |
| 6725: | 'Type' => $oItem->getName(), |
| 6726: | 'Module' => $this->GetName(), |
| 6727: | 'Id' => $oItem->Id, |
| 6728: | 'UUID' => $oItem->UUID, |
| 6729: | 'Login' => $oItem->IncomingLogin |
| 6730: | ]; |
| 6731: | } |
| 6732: | } |
| 6733: | } |
| 6734: | } |
| 6735: | |
| 6736: | |
| 6737: | |
| 6738: | |
| 6739: | |
| 6740: | |
| 6741: | |
| 6742: | |
| 6743: | |
| 6744: | |
| 6745: | |
| 6746: | private function setMessageFlag($AccountID, $sFolderFullNameRaw, $sUids, $bSetAction, $sFlagName) |
| 6747: | { |
| 6748: | $aUids = \Aurora\System\Utils::ExplodeIntUids((string) $sUids); |
| 6749: | |
| 6750: | if (0 === \strlen(\trim($sFolderFullNameRaw)) || !\is_array($aUids) || 0 === \count($aUids)) { |
| 6751: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::InvalidInputParameter); |
| 6752: | } |
| 6753: | |
| 6754: | $oAccount = $this->getAccountsManager()->getAccountById($AccountID); |
| 6755: | |
| 6756: | return $this->getMailManager()->setMessageFlag( |
| 6757: | $oAccount, |
| 6758: | $sFolderFullNameRaw, |
| 6759: | $aUids, |
| 6760: | $sFlagName, |
| 6761: | $bSetAction ? \Aurora\Modules\Mail\Enums\MessageStoreAction::Add : \Aurora\Modules\Mail\Enums\MessageStoreAction::Remove |
| 6762: | ); |
| 6763: | } |
| 6764: | |
| 6765: | |
| 6766: | |
| 6767: | |
| 6768: | |
| 6769: | |
| 6770: | |
| 6771: | |
| 6772: | |
| 6773: | private function fixBase64EncodeOmitsPaddingBytes($sRaw) |
| 6774: | { |
| 6775: | $rStream = \fopen('php://memory', 'r+'); |
| 6776: | \fwrite($rStream, '0'); |
| 6777: | \rewind($rStream); |
| 6778: | $rFilter = \stream_filter_append($rStream, 'convert.base64-encode'); |
| 6779: | |
| 6780: | if (0 === \strlen(\stream_get_contents($rStream))) { |
| 6781: | $iFileSize = \strlen($sRaw); |
| 6782: | $sRaw = \str_pad($sRaw, $iFileSize + ($iFileSize % 3)); |
| 6783: | } |
| 6784: | |
| 6785: | return $sRaw; |
| 6786: | } |
| 6787: | |
| 6788: | |
| 6789: | |
| 6790: | |
| 6791: | |
| 6792: | |
| 6793: | |
| 6794: | |
| 6795: | |
| 6796: | |
| 6797: | |
| 6798: | |
| 6799: | |
| 6800: | |
| 6801: | |
| 6802: | |
| 6803: | |
| 6804: | |
| 6805: | |
| 6806: | |
| 6807: | |
| 6808: | |
| 6809: | |
| 6810: | |
| 6811: | public function BuildMessage( |
| 6812: | $oAccount, |
| 6813: | $sTo = '', |
| 6814: | $sCc = '', |
| 6815: | $sBcc = '', |
| 6816: | $sSubject = '', |
| 6817: | $bTextIsHtml = false, |
| 6818: | $sText = '', |
| 6819: | $aAttachments = null, |
| 6820: | $aDraftInfo = null, |
| 6821: | $sInReplyTo = '', |
| 6822: | $sReferences = '', |
| 6823: | $iImportance = 0, |
| 6824: | $iSensitivity = 0, |
| 6825: | $bSendReadingConfirmation = false, |
| 6826: | $oFetcher = null, |
| 6827: | $oAlias = null, |
| 6828: | $bWithDraftInfo = true, |
| 6829: | $oIdentity = null, |
| 6830: | $aCustomHeaders = [] |
| 6831: | ) { |
| 6832: | self::checkAccountAccess($oAccount); |
| 6833: | |
| 6834: | $oMessage = \MailSo\Mime\Message::NewInstance(); |
| 6835: | $oMessage->RegenerateMessageId(); |
| 6836: | |
| 6837: | $sUUID = \Aurora\System\Api::getUserUUIDById($oAccount->IdUser); |
| 6838: | |
| 6839: | $sXMailer = $this->oModuleSettings->XMailerValue; |
| 6840: | if (0 < \strlen($sXMailer)) { |
| 6841: | $oMessage->SetXMailer($sXMailer); |
| 6842: | } |
| 6843: | |
| 6844: | $sXOriginatingIPHeaderName = $this->oModuleSettings->XOriginatingIPHeaderName; |
| 6845: | if (!empty($sXOriginatingIPHeaderName)) { |
| 6846: | $sIP = $this->oHttp->GetClientIp(); |
| 6847: | $oMessage->SetCustomHeader( |
| 6848: | $sXOriginatingIPHeaderName, |
| 6849: | $this->oHttp->IsLocalhost($sIP) ? '127.0.0.1' : $sIP |
| 6850: | ); |
| 6851: | } |
| 6852: | |
| 6853: | if ($oIdentity) { |
| 6854: | $oFrom = \MailSo\Mime\Email::NewInstance($oIdentity->Email, $oIdentity->FriendlyName); |
| 6855: | } elseif ($oAlias) { |
| 6856: | $oFrom = \MailSo\Mime\Email::NewInstance($oAlias->Email, $oAlias->FriendlyName); |
| 6857: | } else { |
| 6858: | $oFrom = $oFetcher |
| 6859: | ? \MailSo\Mime\Email::NewInstance($oFetcher->Email, $oFetcher->Name) |
| 6860: | : \MailSo\Mime\Email::NewInstance($oAccount->Email, $oAccount->FriendlyName); |
| 6861: | } |
| 6862: | |
| 6863: | $oMessage |
| 6864: | ->SetFrom($oFrom) |
| 6865: | ->SetSubject($sSubject) |
| 6866: | ; |
| 6867: | |
| 6868: | $oToEmails = \MailSo\Mime\EmailCollection::NewInstance($sTo); |
| 6869: | if ($oToEmails && $oToEmails->Count()) { |
| 6870: | $oMessage->SetTo($oToEmails); |
| 6871: | } |
| 6872: | |
| 6873: | $oCcEmails = \MailSo\Mime\EmailCollection::NewInstance($sCc); |
| 6874: | if ($oCcEmails && $oCcEmails->Count()) { |
| 6875: | $oMessage->SetCc($oCcEmails); |
| 6876: | } |
| 6877: | |
| 6878: | $oBccEmails = \MailSo\Mime\EmailCollection::NewInstance($sBcc); |
| 6879: | if ($oBccEmails && $oBccEmails->Count()) { |
| 6880: | $oMessage->SetBcc($oBccEmails); |
| 6881: | } |
| 6882: | |
| 6883: | if ($bWithDraftInfo && \is_array($aDraftInfo) && !empty($aDraftInfo[0]) && !empty($aDraftInfo[1]) && !empty($aDraftInfo[2])) { |
| 6884: | $oMessage->SetDraftInfo($aDraftInfo[0], $aDraftInfo[1], $aDraftInfo[2]); |
| 6885: | } |
| 6886: | |
| 6887: | if (0 < \strlen($sInReplyTo)) { |
| 6888: | $oMessage->SetInReplyTo($sInReplyTo); |
| 6889: | } |
| 6890: | |
| 6891: | if (0 < \strlen($sReferences)) { |
| 6892: | $oMessage->SetReferences($sReferences); |
| 6893: | } |
| 6894: | |
| 6895: | if (\in_array($iImportance, array( |
| 6896: | \MailSo\Mime\Enumerations\MessagePriority::HIGH, |
| 6897: | \MailSo\Mime\Enumerations\MessagePriority::NORMAL, |
| 6898: | \MailSo\Mime\Enumerations\MessagePriority::LOW |
| 6899: | ))) { |
| 6900: | $oMessage->SetPriority($iImportance); |
| 6901: | } |
| 6902: | |
| 6903: | if (\in_array($iSensitivity, array( |
| 6904: | \MailSo\Mime\Enumerations\Sensitivity::NOTHING, |
| 6905: | \MailSo\Mime\Enumerations\Sensitivity::CONFIDENTIAL, |
| 6906: | \MailSo\Mime\Enumerations\Sensitivity::PRIVATE_, |
| 6907: | \MailSo\Mime\Enumerations\Sensitivity::PERSONAL, |
| 6908: | ))) { |
| 6909: | $oMessage->SetSensitivity((int) $iSensitivity); |
| 6910: | } |
| 6911: | |
| 6912: | if (is_array($aCustomHeaders)) { |
| 6913: | foreach ($aCustomHeaders as $sHeaderName => $sHeaderValue) { |
| 6914: | $oMessage->SetCustomHeader($sHeaderName, $sHeaderValue); |
| 6915: | } |
| 6916: | } |
| 6917: | |
| 6918: | if ($bSendReadingConfirmation) { |
| 6919: | $oMessage->SetReadConfirmation($oFetcher ? $oFetcher->Email : $oAccount->Email); |
| 6920: | } |
| 6921: | |
| 6922: | $aFoundCids = array(); |
| 6923: | |
| 6924: | if ($bTextIsHtml) { |
| 6925: | $sTextConverted = \MailSo\Base\HtmlUtils::ConvertHtmlToPlain($sText); |
| 6926: | $oMessage->AddText($sTextConverted, false); |
| 6927: | } |
| 6928: | |
| 6929: | $mFoundDataURL = array(); |
| 6930: | $aFoundedContentLocationUrls = array(); |
| 6931: | |
| 6932: | $sTextConverted = $bTextIsHtml ? |
| 6933: | \MailSo\Base\HtmlUtils::BuildHtml($sText, $aFoundCids, $mFoundDataURL, $aFoundedContentLocationUrls) : $sText; |
| 6934: | |
| 6935: | $oMessage->AddText($sTextConverted, $bTextIsHtml); |
| 6936: | |
| 6937: | if (\is_array($aAttachments)) { |
| 6938: | foreach ($aAttachments as $sTempName => $aData) { |
| 6939: | if (\is_array($aData) && isset($aData[0], $aData[1], $aData[2], $aData[3])) { |
| 6940: | $sFileName = (string) $aData[0]; |
| 6941: | $sCID = (string) $aData[1]; |
| 6942: | $bIsInline = '1' === (string) $aData[2]; |
| 6943: | $bIsLinked = '1' === (string) $aData[3]; |
| 6944: | $sContentLocation = isset($aData[4]) ? (string) $aData[4] : ''; |
| 6945: | |
| 6946: | $rResource = $this->getFilecacheManager()->getFile($sUUID, $sTempName); |
| 6947: | if (\is_resource($rResource)) { |
| 6948: | $iFileSize = $this->getFilecacheManager()->fileSize($sUUID, $sTempName); |
| 6949: | |
| 6950: | $sCID = \trim(\trim($sCID), '<>'); |
| 6951: | $bIsFounded = 0 < \strlen($sCID) ? \in_array($sCID, $aFoundCids) : false; |
| 6952: | |
| 6953: | if (!$bIsLinked || $bIsFounded) { |
| 6954: | $oMessage->Attachments()->Add( |
| 6955: | \MailSo\Mime\Attachment::NewInstance( |
| 6956: | $rResource, |
| 6957: | $sFileName, |
| 6958: | $iFileSize, |
| 6959: | $bIsInline, |
| 6960: | $bIsLinked, |
| 6961: | $bIsLinked ? '<' . $sCID . '>' : '', |
| 6962: | array(), |
| 6963: | $sContentLocation |
| 6964: | ) |
| 6965: | ); |
| 6966: | } |
| 6967: | } else { |
| 6968: | \Aurora\System\Api::Log('Error: there is no temp file for attachment ' . $sFileName); |
| 6969: | } |
| 6970: | } |
| 6971: | } |
| 6972: | } |
| 6973: | |
| 6974: | if ($mFoundDataURL && \is_array($mFoundDataURL) && 0 < \count($mFoundDataURL)) { |
| 6975: | foreach ($mFoundDataURL as $sCidHash => $sDataUrlString) { |
| 6976: | $aMatch = array(); |
| 6977: | $sCID = '<' . $sCidHash . '>'; |
| 6978: | if (\preg_match('/^data:(image\/[a-zA-Z0-9]+\+?[a-zA-Z0-9]+);base64,(.+)$/i', $sDataUrlString, $aMatch) && |
| 6979: | !empty($aMatch[1]) && !empty($aMatch[2])) { |
| 6980: | $sRaw = \MailSo\Base\Utils::Base64Decode($aMatch[2]); |
| 6981: | $iFileSize = \strlen($sRaw); |
| 6982: | if (0 < $iFileSize) { |
| 6983: | $sFileName = \preg_replace('/[^a-z0-9]+/i', '.', \MailSo\Base\Utils::NormalizeContentType($aMatch[1])); |
| 6984: | |
| 6985: | |
| 6986: | $sRaw = $this->fixBase64EncodeOmitsPaddingBytes($sRaw); |
| 6987: | |
| 6988: | $rResource = \MailSo\Base\ResourceRegistry::CreateMemoryResourceFromString($sRaw); |
| 6989: | |
| 6990: | $sRaw = ''; |
| 6991: | unset($sRaw); |
| 6992: | unset($aMatch); |
| 6993: | |
| 6994: | $oMessage->Attachments()->Add( |
| 6995: | \MailSo\Mime\Attachment::NewInstance($rResource, $sFileName, $iFileSize, true, true, $sCID) |
| 6996: | ); |
| 6997: | } |
| 6998: | } |
| 6999: | } |
| 7000: | } |
| 7001: | |
| 7002: | return $oMessage; |
| 7003: | } |
| 7004: | |
| 7005: | public function onAfterDeleteTenant(&$aArgs, &$mResult) |
| 7006: | { |
| 7007: | $TenantId = $aArgs['TenantId']; |
| 7008: | $aServers = self::Decorator()->GetServers($TenantId); |
| 7009: | if (is_array($aServers) && $aServers['Count'] > 0) { |
| 7010: | foreach ($aServers['Items'] as $oServer) { |
| 7011: | if ($oServer['TenantId'] === $TenantId) { |
| 7012: | self::Decorator()->DeleteServer($oServer['Id'], $TenantId); |
| 7013: | } |
| 7014: | } |
| 7015: | } |
| 7016: | } |
| 7017: | |
| 7018: | public function onAfterGetAutodiscover(&$aArgs, &$mResult) |
| 7019: | { |
| 7020: | $sIncomingServer = \trim($this->oModuleSettings->ExternalHostNameOfLocalImap); |
| 7021: | $sOutgoingServer = \trim($this->oModuleSettings->ExternalHostNameOfLocalSmtp); |
| 7022: | $sEmail = $aArgs['Email']; |
| 7023: | |
| 7024: | if (0 < \strlen($sIncomingServer) && 0 < \strlen($sOutgoingServer)) { |
| 7025: | $iIncomingPort = 143; |
| 7026: | $iOutgoingPort = 25; |
| 7027: | |
| 7028: | $aMatch = array(); |
| 7029: | if (\preg_match('/:([\d]+)$/', $sIncomingServer, $aMatch) && !empty($aMatch[1]) && \is_numeric($aMatch[1])) { |
| 7030: | $sIncomingServer = \preg_replace('/:[\d]+$/', $sIncomingServer, ''); |
| 7031: | $iIncomingPort = (int) $aMatch[1]; |
| 7032: | } |
| 7033: | |
| 7034: | $aMatch = array(); |
| 7035: | if (\preg_match('/:([\d]+)$/', $sOutgoingServer, $aMatch) && !empty($aMatch[1]) && \is_numeric($aMatch[1])) { |
| 7036: | $sOutgoingServer = \preg_replace('/:[\d]+$/', $sOutgoingServer, ''); |
| 7037: | $iOutgoingPort = (int) $aMatch[1]; |
| 7038: | } |
| 7039: | |
| 7040: | $sResult = \implode("\n", array( |
| 7041: | ' <Account>', |
| 7042: | ' <AccountType>email</AccountType>', |
| 7043: | ' <Action>settings</Action>', |
| 7044: | ' <Protocol>', |
| 7045: | ' <Type>IMAP</Type>', |
| 7046: | ' <Server>' . $sIncomingServer . '</Server>', |
| 7047: | ' <LoginName>' . $sEmail . '</LoginName>', |
| 7048: | ' <Port>' . $iIncomingPort . '</Port>', |
| 7049: | ' <SSL>' . (993 === $iIncomingPort ? 'on' : 'off') . '</SSL>', |
| 7050: | ' <SPA>off</SPA>', |
| 7051: | ' <AuthRequired>on</AuthRequired>', |
| 7052: | ' </Protocol>', |
| 7053: | ' <Protocol>', |
| 7054: | ' <Type>SMTP</Type>', |
| 7055: | ' <Server>' . $sOutgoingServer . '</Server>', |
| 7056: | ' <LoginName>' . $sEmail . '</LoginName>', |
| 7057: | ' <Port>' . $iOutgoingPort . '</Port>', |
| 7058: | ' <SSL>' . (465 === $iOutgoingPort ? 'on' : 'off') . '</SSL>', |
| 7059: | ' <SPA>off</SPA>', |
| 7060: | ' <AuthRequired>on</AuthRequired>', |
| 7061: | ' </Protocol>', |
| 7062: | ' </Account>' |
| 7063: | )); |
| 7064: | $mResult = $mResult . $sResult; |
| 7065: | } |
| 7066: | } |
| 7067: | |
| 7068: | public function EntryMessageNewtab() |
| 7069: | { |
| 7070: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 7071: | |
| 7072: | $oApiIntegrator = \Aurora\System\Managers\Integrator::getInstance(); |
| 7073: | |
| 7074: | if ($oApiIntegrator) { |
| 7075: | \Aurora\Modules\CoreWebclient\Module::Decorator()->SetHtmlOutputHeaders(); |
| 7076: | $aConfig = array( |
| 7077: | 'new_tab' => true, |
| 7078: | 'modules_list' => $oApiIntegrator->GetModulesForEntry('MailWebclient') |
| 7079: | ); |
| 7080: | |
| 7081: | $oCoreWebclientModule = \Aurora\System\Api::GetModule('CoreWebclient'); |
| 7082: | if ($oCoreWebclientModule instanceof \Aurora\System\Module\AbstractModule) { |
| 7083: | $sResult = \file_get_contents($oCoreWebclientModule->GetPath() . '/templates/Index.html'); |
| 7084: | if (\is_string($sResult)) { |
| 7085: | return strtr($sResult, array( |
| 7086: | '{{AppVersion}}' => Application::GetVersion(), |
| 7087: | '{{IntegratorDir}}' => $oApiIntegrator->isRtl() ? 'rtl' : 'ltr', |
| 7088: | '{{IntegratorLinks}}' => $oApiIntegrator->buildHeadersLink(), |
| 7089: | '{{IntegratorBody}}' => $oApiIntegrator->buildBody($aConfig) |
| 7090: | )); |
| 7091: | } |
| 7092: | } |
| 7093: | } |
| 7094: | } |
| 7095: | |
| 7096: | public function EntryDownloadAttachment() |
| 7097: | { |
| 7098: | $sHash = (string) \Aurora\System\Router::getItemByIndex(1, ''); |
| 7099: | $aValues = \Aurora\System\Api::DecodeKeyValues($sHash); |
| 7100: | $sAuthToken = $aValues[\Aurora\System\Application::AUTH_TOKEN_KEY] ?? null; |
| 7101: | if (isset($sAuthToken)) { |
| 7102: | \Aurora\System\Api::setUserId( |
| 7103: | \Aurora\System\Api::getAuthenticatedUserId($sAuthToken) |
| 7104: | ); |
| 7105: | \Aurora\System\Api::setAuthToken($sAuthToken); |
| 7106: | } |
| 7107: | |
| 7108: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 7109: | |
| 7110: | if ($this->oModuleSettings->CleanupOutputBeforeDownload) { |
| 7111: | @ob_clean(); |
| 7112: | } |
| 7113: | |
| 7114: | $this->getRaw( |
| 7115: | $sHash, |
| 7116: | (string) \Aurora\System\Router::getItemByIndex(2, '') |
| 7117: | ); |
| 7118: | } |
| 7119: | |
| 7120: | public function onBeforeRunEntry(&$aArguments, &$aResult) |
| 7121: | { |
| 7122: | $sEntry = 'mail-attachment'; |
| 7123: | if ($aArguments['EntryName'] === $sEntry) { |
| 7124: | $sParam3 = \Aurora\System\Router::getItemByIndex(3, null); |
| 7125: | if (isset($sParam3) && $sParam3 === 'get-expired-link') { |
| 7126: | $sHash = (string) \Aurora\System\Router::getItemByIndex(1, ''); |
| 7127: | $sAction = (string) \Aurora\System\Router::getItemByIndex(2, ''); |
| 7128: | $iTime = $this->oModuleSettings->ExpiredLinkLifetimeMinutes ; |
| 7129: | |
| 7130: | $aValues = \Aurora\System\Api::DecodeKeyValues($sHash); |
| 7131: | |
| 7132: | if (!isset($aValues[\Aurora\System\Application::AUTH_TOKEN_KEY])) { |
| 7133: | $aValues[\Aurora\System\Application::AUTH_TOKEN_KEY] = \Aurora\System\Api::UserSession()->Set( |
| 7134: | array( |
| 7135: | 'token' => 'auth', |
| 7136: | 'id' => \Aurora\System\Api::getAuthenticatedUserId(), |
| 7137: | ), |
| 7138: | time(), |
| 7139: | time() + 60 * $iTime |
| 7140: | ); |
| 7141: | |
| 7142: | $sHash = \Aurora\System\Api::EncodeKeyValues($aValues); |
| 7143: | } |
| 7144: | |
| 7145: | \header('Location: ' . \MailSo\Base\Http::SingletonInstance()->GetFullUrl() . '?' . $sEntry . '/' . $sHash . '/' . $sAction); |
| 7146: | } |
| 7147: | } |
| 7148: | } |
| 7149: | |
| 7150: | public function EntryDownloadAttachmentCookieless() |
| 7151: | { |
| 7152: | $sAuthToken = $_GET['AuthToken']; |
| 7153: | |
| 7154: | $re = '/^[a-zA-Z0-9_-]+$/'; |
| 7155: | $bSafeToken = preg_match($re, $sAuthToken); |
| 7156: | |
| 7157: | if ($sAuthToken !== '' && !!$bSafeToken) { |
| 7158: | \Aurora\System\Api::authorise($sAuthToken); |
| 7159: | $this->EntryDownloadAttachment(); |
| 7160: | } |
| 7161: | } |
| 7162: | |
| 7163: | |
| 7164: | |
| 7165: | |
| 7166: | |
| 7167: | |
| 7168: | private function getRaw($sHash, $sAction = '') |
| 7169: | { |
| 7170: | $self = $this; |
| 7171: | $bDownload = true; |
| 7172: | $bThumbnail = false; |
| 7173: | |
| 7174: | switch ($sAction) { |
| 7175: | case 'view': |
| 7176: | $bDownload = false; |
| 7177: | $bThumbnail = false; |
| 7178: | break; |
| 7179: | case 'thumb': |
| 7180: | $bDownload = false; |
| 7181: | $bThumbnail = true; |
| 7182: | break; |
| 7183: | default: |
| 7184: | $bDownload = true; |
| 7185: | $bThumbnail = false; |
| 7186: | break; |
| 7187: | } |
| 7188: | |
| 7189: | $aValues = \Aurora\System\Api::DecodeKeyValues($sHash); |
| 7190: | |
| 7191: | $sFolder = ''; |
| 7192: | $iUid = 0; |
| 7193: | $sMimeIndex = ''; |
| 7194: | |
| 7195: | $oAccount = null; |
| 7196: | |
| 7197: | $iUserId = null; |
| 7198: | |
| 7199: | if (isset($aValues['AccountID'])) { |
| 7200: | $oAccount = $this->getAccountsManager()->getAccountById((int) $aValues['AccountID']); |
| 7201: | |
| 7202: | self::checkAccountAccess($oAccount); |
| 7203: | |
| 7204: | if (!$oAccount || \Aurora\System\Api::getAuthenticatedUserId() !== $oAccount->IdUser) { |
| 7205: | return false; |
| 7206: | } |
| 7207: | $iUserId = $oAccount->IdUser; |
| 7208: | } |
| 7209: | |
| 7210: | $sFolder = isset($aValues['Folder']) ? $aValues['Folder'] : ''; |
| 7211: | $iUid = (int) (isset($aValues['Uid']) ? $aValues['Uid'] : 0); |
| 7212: | $sMimeIndex = (string) (isset($aValues['MimeIndex']) ? $aValues['MimeIndex'] : ''); |
| 7213: | $sContentTypeIn = (string) (isset($aValues['MimeType']) ? $aValues['MimeType'] : ''); |
| 7214: | $sFileNameIn = (string) (isset($aValues['FileName']) ? $aValues['FileName'] : ''); |
| 7215: | |
| 7216: | |
| 7217: | if (!$bDownload && strtolower(pathinfo($sFileNameIn, PATHINFO_EXTENSION)) === 'svg') { |
| 7218: | $this->oHttp->StatusHeader(403); |
| 7219: | exit(); |
| 7220: | } |
| 7221: | |
| 7222: | $bCache = true; |
| 7223: | if ($bCache && 0 < \strlen($sFolder) && 0 < $iUid) { |
| 7224: | \Aurora\System\Managers\Response::verifyCacheByKey($sHash); |
| 7225: | } |
| 7226: | |
| 7227: | if ($bThumbnail) { |
| 7228: | $sThumbnail = \Aurora\System\Managers\Thumb::GetResourceCache($iUserId, $sFileNameIn); |
| 7229: | if ($sThumbnail) { |
| 7230: | $sContentType = \MailSo\Base\Utils::MimeContentType($sFileNameIn); |
| 7231: | \Aurora\System\Managers\Response::OutputHeaders($bDownload, $sContentType, $sFileNameIn); |
| 7232: | echo $sThumbnail; |
| 7233: | exit(); |
| 7234: | } |
| 7235: | } |
| 7236: | |
| 7237: | return $this->getMailManager()->directMessageToStream( |
| 7238: | $oAccount, |
| 7239: | function ($rResource, $sContentType, $sFileName, $sMimeIndex = '') use ($iUserId, $sHash, $bCache, $sContentTypeIn, $sFileNameIn, $bThumbnail, $bDownload) { |
| 7240: | if (\is_resource($rResource)) { |
| 7241: | $sContentTypeOut = $sContentTypeIn; |
| 7242: | if (empty($sContentTypeOut)) { |
| 7243: | $sContentTypeOut = $sContentType; |
| 7244: | if (empty($sContentTypeOut)) { |
| 7245: | $sContentTypeOut = (empty($sFileName)) ? 'text/plain' : \MailSo\Base\Utils::MimeContentType($sFileName); |
| 7246: | } |
| 7247: | } |
| 7248: | |
| 7249: | $sFileNameOut = $sFileNameIn; |
| 7250: | if (empty($sFileNameOut) || '.' === $sFileNameOut[0]) { |
| 7251: | $sFileNameOut = $sFileName; |
| 7252: | } |
| 7253: | |
| 7254: | $sFileNameOut = \Aurora\System\Utils::clearFileName($sFileNameOut, $sContentType, $sMimeIndex); |
| 7255: | |
| 7256: | if ($bCache) { |
| 7257: | \Aurora\System\Managers\Response::cacheByKey($sHash); |
| 7258: | } |
| 7259: | |
| 7260: | \Aurora\System\Utils::OutputFileResource($iUserId, $sContentType, $sFileName, $rResource, $bThumbnail, $bDownload); |
| 7261: | } |
| 7262: | }, |
| 7263: | $sFolder, |
| 7264: | $iUid, |
| 7265: | $sMimeIndex |
| 7266: | ); |
| 7267: | } |
| 7268: | |
| 7269: | public function onGetDigestHash($aArgs, &$mResult) |
| 7270: | { |
| 7271: | $oAccount = $this->getAccountsManager()->getAccountUsedToAuthorize($aArgs['Login']); |
| 7272: | if (is_a($oAccount, $aArgs['Type'])) { |
| 7273: | $mResult = \md5($aArgs['Login'] . ':' . $aArgs['Realm'] . ':' . $oAccount->GetPassword()); |
| 7274: | return true; |
| 7275: | } |
| 7276: | } |
| 7277: | |
| 7278: | public function onGetAccountUsedToAuthorize($aArgs, &$mResult) |
| 7279: | { |
| 7280: | $oAccount = $this->getAccountsManager()->getAccountUsedToAuthorize($aArgs['Login']); |
| 7281: | if ($oAccount) { |
| 7282: | $mResult = $oAccount; |
| 7283: | return true; |
| 7284: | } |
| 7285: | } |
| 7286: | |
| 7287: | public function onCastExtendedProp($aArgs, &$mValue) |
| 7288: | { |
| 7289: | if ($aArgs['Model'] instanceof User) { |
| 7290: | if ($aArgs['PropertyName'] === $this->GetName() . '::UserSpaceLimitMb') { |
| 7291: | $mValue = (int) $mValue; |
| 7292: | } |
| 7293: | if ($aArgs['PropertyName'] === $this->GetName() . '::AllowAutosaveInDrafts') { |
| 7294: | $mValue = (bool) $mValue; |
| 7295: | } |
| 7296: | } |
| 7297: | |
| 7298: | if ($aArgs['Model'] instanceof Tenant) { |
| 7299: | if ($aArgs['PropertyName'] === $this->GetName() . '::TenantSpaceLimitMb' || |
| 7300: | $aArgs['PropertyName'] === $this->GetName() . '::UserSpaceLimitMb' || |
| 7301: | $aArgs['PropertyName'] === $this->GetName() . '::AllocatedSpaceMb' |
| 7302: | ) { |
| 7303: | $mValue = (int) $mValue; |
| 7304: | } |
| 7305: | if ($aArgs['PropertyName'] === $this->GetName() . '::AllowChangeUserSpaceLimit') { |
| 7306: | $mValue = (bool) $mValue; |
| 7307: | } |
| 7308: | } |
| 7309: | } |
| 7310: | |
| 7311: | public function onAfterChangePassword($aArgs, &$mResult) |
| 7312: | { |
| 7313: | if ($mResult instanceof Models\MailAccount && $mResult->UseToAuthorize) { |
| 7314: | $oUser = \Aurora\System\Api::getAuthenticatedUser(); |
| 7315: | if ($oUser instanceof User && |
| 7316: | (($oUser->isNormalOrTenant() && $oUser->Id === $mResult->IdUser) || |
| 7317: | $oUser->Role === \Aurora\System\Enums\UserRole::SuperAdmin) |
| 7318: | ) { |
| 7319: | Api::UserSession()->DeleteAllAccountSessions($mResult); |
| 7320: | } |
| 7321: | } |
| 7322: | } |
| 7323: | |
| 7324: | public function GetServerDomains($ServerId, $TenantId) |
| 7325: | { |
| 7326: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
| 7327: | $aResult = []; |
| 7328: | |
| 7329: | $oServer = $this->getServersManager()->getServer($ServerId); |
| 7330: | if ($oServer instanceof Models\Server) { |
| 7331: | $aResult = explode("\n", $oServer->Domains); |
| 7332: | $iWildcard = array_search('*', $aResult); |
| 7333: | if ($iWildcard !== false) { |
| 7334: | unset($aResult[$iWildcard]); |
| 7335: | } |
| 7336: | } |
| 7337: | |
| 7338: | return $aResult; |
| 7339: | } |
| 7340: | |
| 7341: | public function IsEmailAllowedForCreation($Email) |
| 7342: | { |
| 7343: | |
| 7344: | $oAuthenticatedUser = \Aurora\System\Api::getAuthenticatedUser(); |
| 7345: | if ( |
| 7346: | $oAuthenticatedUser->Role === \Aurora\System\Enums\UserRole::SuperAdmin |
| 7347: | || $oAuthenticatedUser->Role === \Aurora\System\Enums\UserRole::TenantAdmin |
| 7348: | ) { |
| 7349: | $oUser = \Aurora\Modules\Core\Module::Decorator()->GetUserByPublicId($Email); |
| 7350: | if ($oUser instanceof User) { |
| 7351: | return false; |
| 7352: | } |
| 7353: | $aAccounts = $this->getAccountsManager()->getAccounts([ |
| 7354: | 'Email' => $Email, |
| 7355: | 'IsDisabled' => false |
| 7356: | ]); |
| 7357: | if (is_array($aAccounts) && count($aAccounts) > 0) { |
| 7358: | return false; |
| 7359: | } |
| 7360: | |
| 7361: | return true; |
| 7362: | } else { |
| 7363: | throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::AccessDenied); |
| 7364: | } |
| 7365: | } |
| 7366: | |
| 7367: | |
| 7368: | } |
| 7369: | |