use of com.zimbra.cs.mailbox.MailboxManager in project zm-mailbox by Zimbra.
the class ModifyPrefsTest method init.
@BeforeClass
public static void init() throws Exception {
MailboxTestUtil.initServer();
Provisioning prov = Provisioning.getInstance();
Map<String, Object> attrs = Maps.newHashMap();
prov.createDomain("zimbra.com", attrs);
attrs = Maps.newHashMap();
prov.createAccount("test@zimbra.com", "secret", attrs);
MailboxManager.setInstance(new MailboxManager() {
@Override
protected Mailbox instantiateMailbox(MailboxData data) {
return new Mailbox(data) {
@Override
public MailSender getMailSender() {
return new MailSender() {
@Override
protected Collection<Address> sendMessage(Mailbox mbox, MimeMessage mm, Collection<RollbackData> rollbacks) throws SafeMessagingException, IOException {
try {
return Arrays.asList(getRecipients(mm));
} catch (Exception e) {
return Collections.emptyList();
}
}
};
}
};
}
});
L10nUtil.setMsgClassLoader("../store-conf/conf/msgs");
}
use of com.zimbra.cs.mailbox.MailboxManager in project zm-mailbox by Zimbra.
the class CreateDataSource method doZMGAppProvisioningIfReq.
private static synchronized boolean doZMGAppProvisioningIfReq(ZimbraSoapContext zsc, Provisioning prov, Element eDataSource, DataSourceType type) throws ServiceException {
String acctId = zsc.getAuthtokenAccountId();
AuthToken authToken = zsc.getAuthToken();
if (authToken.isZMGAppBootstrap() && prov.getAccountById(acctId) == null) {
// test the data source to make sure it is a valid one
TestDataSource.testDataSourceConnection(prov, eDataSource, type, null);
Account acct = prov.autoProvZMGAppAccount(acctId, authToken.getDigest());
MailboxManager mailboxManager = MailboxManager.getInstance();
if (mailboxManager.getMailboxByAccountId(acctId, false) == null) {
try {
mailboxManager.createMailbox(null, acct);
} catch (ServiceException e) {
// Rollback account creation
prov.deleteAccount(acctId);
throw e;
}
}
return true;
}
return false;
}
use of com.zimbra.cs.mailbox.MailboxManager in project zm-mailbox by Zimbra.
the class SomeAccountsWaitSet method addAccounts.
synchronized List<WaitSetError> addAccounts(List<WaitSetAccount> wsas) {
List<WaitSetError> errors = new ArrayList<WaitSetError>();
for (WaitSetAccount wsa : wsas) {
if (!mSessions.containsKey(wsa.getAccountId())) {
// add the account to our session list
mSessions.put(wsa.getAccountId(), wsa);
// create the Session, if necessary, to listen to the requested mailbox
try {
// if there is a sync token, then we need to check to see if the
// token is up-to-date...which means we have to fetch the mailbox. Otherwise,
// we don't have to fetch the mailbox.
MailboxManager.FetchMode fetchMode = MailboxManager.FetchMode.AUTOCREATE;
if (wsa.getLastKnownSyncToken() == null)
fetchMode = MailboxManager.FetchMode.ONLY_IF_CACHED;
//
// THIS CALL MIGHT REGISTER THE SESSION (via the MailboxManager notification --> mailboxLoaded() callback!
//
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(wsa.getAccountId(), fetchMode);
if (mbox != null) {
WaitSetError error = initializeWaitSetSession(wsa, mbox);
if (error != null) {
errors.add(error);
}
}
} catch (ServiceException e) {
if (e.getCode() == AccountServiceException.NO_SUCH_ACCOUNT) {
errors.add(new WaitSetError(wsa.getAccountId(), WaitSetError.Type.NO_SUCH_ACCOUNT));
} else if (e.getCode() == ServiceException.WRONG_HOST) {
errors.add(new WaitSetError(wsa.getAccountId(), WaitSetError.Type.WRONG_HOST_FOR_ACCOUNT));
} else {
errors.add(new WaitSetError(wsa.getAccountId(), WaitSetError.Type.ERROR_LOADING_MAILBOX));
}
mSessions.remove(wsa);
}
} else {
errors.add(new WaitSetError(wsa.getAccountId(), WaitSetError.Type.ALREADY_IN_SET_DURING_ADD));
}
}
return errors;
}
use of com.zimbra.cs.mailbox.MailboxManager in project zm-mailbox by Zimbra.
the class GetMiniCal method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Mailbox mbox = getRequestedMailbox(zsc);
Account authAcct = getAuthenticatedAccount(zsc);
OperationContext octxt = getOperationContext(zsc, context);
Element response = getResponseElement(zsc);
long rangeStart = request.getAttributeLong(MailConstants.A_CAL_START_TIME);
long rangeEnd = request.getAttributeLong(MailConstants.A_CAL_END_TIME);
List<ItemId> folderIids = new ArrayList<ItemId>();
for (Iterator<Element> foldersIter = request.elementIterator(MailConstants.E_FOLDER); foldersIter.hasNext(); ) {
Element fElem = foldersIter.next();
ItemId iidFolder = new ItemId(fElem.getAttribute(MailConstants.A_ID), zsc);
folderIids.add(iidFolder);
}
ICalTimeZone tz = parseTimeZone(request);
if (tz == null)
// requestor's time zone, not mailbox owner's
tz = Util.getAccountTimeZone(authAcct);
TreeSet<String> busyDates = new TreeSet<String>();
Provisioning prov = Provisioning.getInstance();
MailboxManager mboxMgr = MailboxManager.getInstance();
Server localServer = prov.getLocalServer();
ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
Map<ItemId, Resolved> resolved = resolveMountpoints(octxt, mbox, folderIids);
Map<ItemId, ItemId> /* requested iid */
reverseMap = new HashMap<ItemId, ItemId>();
for (Map.Entry<ItemId, Resolved> entry : resolved.entrySet()) {
ItemId requestedIid = entry.getKey();
Resolved res = entry.getValue();
if (res.error == null) {
reverseMap.put(res.iid, requestedIid);
} else {
addError(response, ifmt.formatItemId(requestedIid), res.error.getCode(), res.error.getMessage());
}
}
Map<Server, Map<String, List<Integer>>> /* folder ids */
groupedByServer = Search.groupByServer(groupFoldersByAccount(resolved));
// Look up in calendar cache first.
if (LC.calendar_cache_enabled.booleanValue()) {
CalSummaryCache calCache = CalendarCacheManager.getInstance().getSummaryCache();
Calendar cal = new GregorianCalendar(tz);
for (Iterator<Map.Entry<Server, Map<String, List<Integer>>>> serverIter = groupedByServer.entrySet().iterator(); serverIter.hasNext(); ) {
Map.Entry<Server, Map<String, List<Integer>>> serverMapEntry = serverIter.next();
Map<String, List<Integer>> accountFolders = serverMapEntry.getValue();
// for each account
for (Iterator<Map.Entry<String, List<Integer>>> acctIter = accountFolders.entrySet().iterator(); acctIter.hasNext(); ) {
Map.Entry<String, List<Integer>> acctEntry = acctIter.next();
String acctId = acctEntry.getKey();
List<Integer> folderIds = acctEntry.getValue();
// for each folder
for (Iterator<Integer> iterFolderId = folderIds.iterator(); iterFolderId.hasNext(); ) {
int folderId = iterFolderId.next();
try {
CalendarDataResult result = calCache.getCalendarSummary(octxt, acctId, folderId, MailItem.Type.APPOINTMENT, rangeStart, rangeEnd, true);
if (result != null) {
// Found data in cache.
iterFolderId.remove();
addBusyDates(cal, result.data, rangeStart, rangeEnd, busyDates);
}
} catch (ServiceException e) {
iterFolderId.remove();
ItemId iid = new ItemId(acctId, folderId);
// Error must mention folder id requested by client.
ItemId reqIid = reverseMap.get(iid);
if (reqIid != null) {
ZimbraLog.calendar.warn("Error accessing calendar folder " + ifmt.formatItemId(reqIid), e);
addError(response, ifmt.formatItemId(reqIid), e.getCode(), e.getMessage());
} else {
ZimbraLog.calendar.warn("Error accessing calendar folder; resolved id=" + ifmt.formatItemId(iid) + " (missing reverse mapping)", e);
addError(response, ifmt.formatItemId(iid), e.getCode(), e.getMessage());
}
}
}
if (folderIds.isEmpty())
acctIter.remove();
}
if (accountFolders.isEmpty())
serverIter.remove();
}
}
// For any remaining calendars, we have to get the data the hard way.
for (Map.Entry<Server, Map<String, List<Integer>>> serverMapEntry : groupedByServer.entrySet()) {
Server server = serverMapEntry.getKey();
Map<String, List<Integer>> accountFolders = serverMapEntry.getValue();
if (server.equals(localServer)) {
// local server
for (Map.Entry<String, List<Integer>> entry : accountFolders.entrySet()) {
String acctId = entry.getKey();
List<Integer> folderIds = entry.getValue();
Account targetAcct = prov.get(AccountBy.id, acctId);
if (targetAcct == null) {
ZimbraLog.calendar.warn("Skipping unknown account " + acctId + " during minical search");
continue;
}
Mailbox targetMbox = mboxMgr.getMailboxByAccount(targetAcct);
for (int folderId : folderIds) {
try {
doLocalFolder(octxt, tz, targetMbox, folderId, rangeStart, rangeEnd, busyDates);
} catch (ServiceException e) {
ItemId iid = new ItemId(acctId, folderId);
// Error must mention folder id requested by client.
ItemId reqIid = reverseMap.get(iid);
if (reqIid != null) {
ZimbraLog.calendar.warn("Error accessing calendar folder " + ifmt.formatItemId(reqIid), e);
addError(response, ifmt.formatItemId(reqIid), e.getCode(), e.getMessage());
} else {
ZimbraLog.calendar.warn("Error accessing calendar folder; resolved id=" + ifmt.formatItemId(iid) + " (missing reverse mapping)", e);
addError(response, ifmt.formatItemId(iid), e.getCode(), e.getMessage());
}
}
}
}
} else {
// remote server
// mail service soap requests want to see a target account
String nominalTargetAcctId = null;
List<String> folderList = new ArrayList<String>();
for (Map.Entry<String, List<Integer>> entry : accountFolders.entrySet()) {
String acctId = entry.getKey();
if (nominalTargetAcctId == null)
nominalTargetAcctId = acctId;
ItemIdFormatter ifmtRemote = new ItemIdFormatter(authAcct.getId(), acctId, false);
List<Integer> folderIds = entry.getValue();
for (int folderId : folderIds) {
folderList.add(ifmtRemote.formatItemId(folderId));
}
}
doRemoteFolders(zsc, nominalTargetAcctId, folderList, rangeStart, rangeEnd, busyDates, response, reverseMap, ifmt);
}
}
for (String datestamp : busyDates) {
Element dateElem = response.addElement(MailConstants.E_CAL_MINICAL_DATE);
dateElem.setText(datestamp);
}
return response;
}
use of com.zimbra.cs.mailbox.MailboxManager in project zm-mailbox by Zimbra.
the class IndexEditor method reIndexAll.
public void reIndexAll() {
MailboxManager mmgr;
try {
mmgr = MailboxManager.getInstance();
} catch (ServiceException e) {
ZimbraLog.index.error("could not retrieve mailbox manager; aborting reindex", e);
return;
}
int[] ids = mmgr.getMailboxIds();
for (int i = 0; i < ids.length; i++) {
mLog.info("Mailbox " + ids[i] + "\n");
try {
Mailbox mbx = mmgr.getMailboxById(ids[i]);
mbx.index.startReIndex();
} catch (ServiceException e) {
mLog.info("Exception ReIndexing " + ids[i], e);
}
}
}
Aggregations