public static MailAccount GetMailAccount(int itemId) { // load meta item MailAccount item = (MailAccount)PackageController.GetPackageItem(itemId); // load service item MailServer mail = new MailServer(); ServiceProviderProxy.Init(mail, item.ServiceId); MailAccount account = mail.GetAccount(item.Name); // add common properties account.Id = item.Id; account.PackageId = item.PackageId; account.ServiceId = item.ServiceId; return account; }
public static int UpdateMailAccount(MailAccount item) { // check account int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive); if (accountCheck < 0) return accountCheck; // load original meta item MailAccount origItem = (MailAccount)PackageController.GetPackageItem(item.Id); if (origItem == null) return BusinessErrorCodes.ERROR_MAIL_ACCOUNTS_PACKAGE_ITEM_NOT_FOUND; // check package int packageCheck = SecurityContext.CheckPackage(origItem.PackageId, DemandPackage.IsActive); if (packageCheck < 0) return packageCheck; // place log record TaskManager.StartTask("MAIL_ACCOUNT", "UPDATE", origItem.Name); TaskManager.ItemId = item.Id; try { // restore original props if (item.Password == "") item.Password = CryptoUtils.Decrypt(origItem.Password); // get service MailServer mail = new MailServer(); ServiceProviderProxy.Init(mail, origItem.ServiceId); item.Name = origItem.Name; item.Enabled = true; item.MaxMailboxSize = GetMaxMailBoxSize(origItem.PackageId, item); if (String.IsNullOrEmpty(item.Password)) { // get password from the service MailAccount origBox = mail.GetAccount(item.Name); item.Password = origBox.Password; } // update service item mail.UpdateAccount(item); // update meta item item.Password = CryptoUtils.Encrypt(item.Password); PackageController.UpdatePackageItem(item); return 0; } catch (Exception ex) { throw TaskManager.WriteError(ex); } finally { TaskManager.CompleteTask(); } }
public static int UpdateMailAccount(MailAccount item) { // check account int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive); if (accountCheck < 0) return accountCheck; // load original meta item MailAccount origItem = (MailAccount)PackageController.GetPackageItem(item.Id); if (origItem == null) return BusinessErrorCodes.ERROR_MAIL_ACCOUNTS_PACKAGE_ITEM_NOT_FOUND; // check package int packageCheck = SecurityContext.CheckPackage(origItem.PackageId, DemandPackage.IsActive); if (packageCheck < 0) return packageCheck; // check mailbox account size limit if (item.MaxMailboxSize < -1) return BusinessErrorCodes.ERROR_MAIL_ACCOUNT_MAX_MAILBOX_SIZE_LIMIT; // place log record TaskManager.StartTask("MAIL_ACCOUNT", "UPDATE", origItem.Name, item.Id); try { // restore original props if (item.Password == "") item.Password = CryptoUtils.Decrypt(origItem.Password); // get service MailServer mail = new MailServer(); ServiceProviderProxy.Init(mail, origItem.ServiceId); item.Name = origItem.Name; item.MaxMailboxSize = GetMaxMailBoxSize(origItem.PackageId, item); if (String.IsNullOrEmpty(item.Password)) { // get password from the service MailAccount origBox = mail.GetAccount(item.Name); item.Password = origBox.Password; } // update service item mail.UpdateAccount(item); // update meta item item.Password = CryptoUtils.Encrypt(item.Password); PackageController.UpdatePackageItem(item); return 0; } catch (Exception ex) { if (ex.Message.Contains("Password doesn't meet complexity") || ex.Message.Contains("IceWarp password policy denies use of this account") || ex.Message.Contains("Invalid characters in password")) { return BusinessErrorCodes.ERROR_MAIL_ACCOUNT_PASSWORD_NOT_COMPLEXITY; } throw TaskManager.WriteError(ex); } finally { TaskManager.CompleteTask(); } }