use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.
the class FileBlobStoreConsistencyCheckTest method deleteAllBlobs.
@Override
protected void deleteAllBlobs() throws ServiceException, IOException {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
Volume vol = VolumeManager.getInstance().getCurrentMessageVolume();
String dir = vol.getMailboxDir(mbox.getId(), Volume.TYPE_MESSAGE);
log.info("mailbox dir is %s", dir);
File blobDir = new File(dir);
FileUtil.deleteDirContents(blobDir);
}
use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.
the class HttpStoreManagerTest method fail.
@Test
public void fail() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
int count = countMailItems(mbox);
MockHttpStore.setFail();
try {
mbox.addMessage(null, MailboxTestUtil.generateMessage("test"), MailboxTest.STANDARD_DELIVERY_OPTIONS, null).getId();
Assert.fail("expected exception not thrown");
} catch (ServiceException expected) {
}
Assert.assertEquals(count, countMailItems(mbox));
}
use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.
the class ExternalAccountManagerTask method run.
@Override
public void run() {
ZimbraLog.misc.info("Starting external virtual account status manager task");
Provisioning prov = Provisioning.getInstance();
SearchAccountsOptions searchOpts = new SearchAccountsOptions();
try {
searchOpts.setFilter(ZLdapFilterFactory.getInstance().externalAccountsHomedOnServer(prov.getLocalServer().getServiceHostname()));
List<NamedEntry> accounts = prov.searchDirectory(searchOpts);
for (NamedEntry ne : accounts) {
Account account = (Account) ne;
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
if (mbox == null) {
ZimbraLog.misc.error("Mailbox for external virtual account %s is unexpectedly null", account.getId());
continue;
}
List<Folder> folders = mbox.getFolderList(null, SortBy.NONE);
List<Mountpoint> mountpoints = new LinkedList<Mountpoint>();
for (Folder folder : folders) {
if (folder instanceof Mountpoint) {
mountpoints.add((Mountpoint) folder);
}
}
if (mountpoints.isEmpty()) {
disableOrDeleteAccount(prov, account, mbox);
continue;
}
// Get all shares granted to the external user
ShareInfoVisitor shareInfoVisitor = new ShareInfoVisitor(mountpoints);
ShareInfo.Published.get(prov, account, ACL.GRANTEE_GUEST, null, shareInfoVisitor);
boolean hasValidMountpoint = shareInfoVisitor.getResult();
if (!hasValidMountpoint) {
disableOrDeleteAccount(prov, account, mbox);
} else if (account.getAccountStatus() == AccountStatus.closed) {
// re-enable account
account.setAccountStatus(AccountStatus.active);
}
}
} catch (Throwable e) {
ZimbraLog.misc.warn("Error during external virtual account status manager task run", e);
}
ZimbraLog.misc.info("Finished external virtual account status manager task");
}
use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.
the class LdapProvisioning method autoProvZMGProxyAccount.
@Override
public Pair<Account, Boolean> autoProvZMGProxyAccount(String emailAddr, String password) throws ServiceException {
Account acct = getAccountByForeignPrincipal(ZMG_PROXY_ACCT_FOREIGN_PRINCIPAL_PREFIX + emailAddr);
if (acct != null) {
return new Pair<>(acct, false);
}
String domainId = getConfig().getMobileGatewayDefaultProxyAccountDomainId();
if (domainId == null) {
return new Pair<>(null, false);
}
Domain domain = getDomainById(domainId);
if (domain == null) {
ZimbraLog.account.error("Domain corresponding to" + A_zimbraMobileGatewayDefaultProxyAccountDomainId + "not found ");
throw ServiceException.FAILURE("Missing server configuration", null);
}
String testDsId = "TestId";
Map<String, Object> testAttrs = getZMGProxyDataSourceAttrs(emailAddr, password, true, testDsId);
DataSource dsToTest = new DataSource(null, DataSourceType.imap, "Test", testDsId, testAttrs, this);
try {
DataSourceManager.test(dsToTest);
} catch (ServiceException e) {
ZimbraLog.account.debug("ZMG Proxy account auto provisioning failed", e);
throw AuthFailedServiceException.AUTH_FAILED(emailAddr, SystemUtil.getInnermostException(e).getMessage(), e);
}
Map<String, Object> acctAttrs = new HashMap<String, Object>();
acctAttrs.put(Provisioning.A_zimbraIsMobileGatewayProxyAccount, ProvisioningConstants.TRUE);
acctAttrs.put(Provisioning.A_zimbraForeignPrincipal, ZMG_PROXY_ACCT_FOREIGN_PRINCIPAL_PREFIX + emailAddr);
acctAttrs.put(Provisioning.A_zimbraHideInGal, ProvisioningConstants.TRUE);
acctAttrs.put(Provisioning.A_zimbraMailStatus, Provisioning.MailStatus.disabled.toString());
acctAttrs.put(Provisioning.A_zimbraMailHost, getLocalServer().getServiceHostname());
acct = createDummyAccount(acctAttrs, password, domain);
DataSource ds;
try {
Map<String, Object> dsAttrs = getZMGProxyDataSourceAttrs(emailAddr, password, false, null);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
dsAttrs.put(Provisioning.A_zimbraDataSourceFolderId, Integer.toString(mbox.createFolder(null, "/" + emailAddr, new Folder.FolderOptions()).getId()));
ds = createDataSource(acct, DataSourceType.imap, emailAddr, dsAttrs);
} catch (ServiceException e) {
try {
deleteAccount(acct.getId());
} catch (ServiceException e1) {
if (!AccountServiceException.NO_SUCH_ACCOUNT.equals(e1.getCode())) {
throw e1;
}
}
throw e;
}
DataSourceManager.asyncImportData(ds);
return new Pair<>(acct, true);
}
use of com.zimbra.cs.mailbox.Mailbox in project zm-mailbox by Zimbra.
the class DataSourceTask method call.
@Override
public Void call() {
ZimbraLog.clearContext();
ZimbraLog.addMboxToContext(getMailboxId());
ZimbraLog.datasource.debug("Running scheduled import for DataSource %s", getDataSourceId());
Mailbox mbox = null;
try {
// Look up mailbox, account and data source
mbox = MailboxManager.getInstance().getMailboxById(getMailboxId());
Account account = mbox.getAccount();
ZimbraLog.addAccountNameToContext(account.getName());
Provisioning prov = Provisioning.getInstance();
DataSource ds = prov.get(account, Key.DataSourceBy.id, getDataSourceId());
if (ds != null) {
ZimbraLog.addDataSourceNameToContext(ds.getName());
if (!ds.isEnabled()) {
ZimbraLog.datasource.info("DataSource is disabled. Cancelling future tasks.");
DataSourceManager.cancelTask(mbox, getDataSourceId());
return null;
}
// Do the work
DataSourceManager.importData(ds);
} else {
ZimbraLog.datasource.info("DataSource %s was deleted. Cancelling future tasks.", getDataSourceId());
DataSourceManager.cancelTask(mbox, getDataSourceId());
}
} catch (ServiceException e) {
ZimbraLog.datasource.warn("Scheduled DataSource import failed.", e);
return null;
}
ZimbraLog.clearContext();
return null;
}
Aggregations