use of com.zimbra.cs.mailbox.MailboxManager in project zm-mailbox by Zimbra.
the class SendShareNotificationTest 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);
attrs = Maps.newHashMap();
attrs.put(Provisioning.A_zimbraId, UUID.randomUUID().toString());
prov.createAccount("test2@zimbra.com", "secret", attrs);
attrs = Maps.newHashMap();
attrs.put(Provisioning.A_zimbraId, UUID.randomUUID().toString());
prov.createAccount("test3@zimbra.com", "secret", attrs);
// this MailboxManager does everything except actually send mail
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 GetMsgTest method setUp.
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
MailboxTestUtil.initServer();
MailboxTestUtil.clearData();
Provisioning prov = Provisioning.getInstance();
Map<String, Object> attrs = Maps.newHashMap();
prov.createDomain("zimbra.com", attrs);
attrs = Maps.newHashMap();
attrs.put(Provisioning.A_zimbraId, UUID.randomUUID().toString());
prov.createAccount("test@zimbra.com", "secret", attrs);
attrs = Maps.newHashMap();
attrs.put(Provisioning.A_zimbraId, UUID.randomUUID().toString());
prov.createAccount("test2@zimbra.com", "secret", attrs);
// this MailboxManager does everything except actually send mail
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) {
try {
return Arrays.asList(getRecipients(mm));
} catch (Exception e) {
return Collections.emptyList();
}
}
};
}
};
}
});
}
use of com.zimbra.cs.mailbox.MailboxManager in project zm-mailbox by Zimbra.
the class ModifyProfileImageTest method setUp.
@Before
public void setUp() throws Exception {
System.out.println(testName.getMethodName());
MailboxTestUtil.initServer();
Provisioning prov = Provisioning.getInstance();
Map<String, Object> attrs = Maps.newHashMap();
prov.createDomain("zimbra.com", attrs);
attrs = Maps.newHashMap();
attrs.put(Provisioning.A_zimbraId, UUID.randomUUID().toString());
prov.createAccount("testZCS3545@zimbra.com", "secret", attrs);
attrs = Maps.newHashMap();
attrs.put(Provisioning.A_zimbraId, UUID.randomUUID().toString());
prov.createAccount("testZCS3871@zimbra.com", "secret", attrs);
// this MailboxManager does everything except actually send mail
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) {
try {
return Arrays.asList(getRecipients(mm));
} catch (Exception e) {
return Collections.emptyList();
}
}
};
}
};
}
});
}
use of com.zimbra.cs.mailbox.MailboxManager in project zm-mailbox by Zimbra.
the class Search method runSimpleAppointmentQuery.
private static void runSimpleAppointmentQuery(Element parent, SearchParams params, OperationContext octxt, ZimbraSoapContext zsc, Account authAcct, Mailbox mbox, List<String> folderIdStrs) throws ServiceException {
Set<MailItem.Type> types = params.getTypes();
MailItem.Type type = types.size() == 1 ? Iterables.getOnlyElement(types) : MailItem.Type.APPOINTMENT;
if (params.getSortBy() != null) {
parent.addAttribute(MailConstants.A_SORTBY, params.getSortBy().toString());
}
parent.addAttribute(MailConstants.A_QUERY_OFFSET, params.getOffset());
parent.addAttribute(MailConstants.A_QUERY_MORE, false);
List<ItemId> folderIids = new ArrayList<ItemId>(folderIdStrs.size());
for (String folderIdStr : folderIdStrs) {
folderIids.add(new ItemId(folderIdStr, zsc));
}
Provisioning prov = Provisioning.getInstance();
MailboxManager mboxMgr = MailboxManager.getInstance();
Server localServer = prov.getLocalServer();
Map<Server, Map<String, List<Integer>>> /* folder ids */
groupedByServer = groupByServer(ItemId.groupFoldersByAccount(octxt, mbox, folderIids));
// Look up in calendar cache first.
if (LC.calendar_cache_enabled.booleanValue()) {
CalSummaryCache calCache = CalendarCacheManager.getInstance().getSummaryCache();
long rangeStart = params.getCalItemExpandStart();
long rangeEnd = params.getCalItemExpandEnd();
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();
// Setup ItemIdFormatter appropriate for this folder which might not be in the authed account
// but also take note of presense of <noqualify/> in SOAP context
ItemIdFormatter ifmt = new ItemIdFormatter(authAcct.getId(), acctId, zsc.wantsUnqualifiedIds());
// for each folder
for (Iterator<Integer> iterFolderId = folderIds.iterator(); iterFolderId.hasNext(); ) {
int folderId = iterFolderId.next();
try {
CalendarDataResult result = calCache.getCalendarSummary(octxt, acctId, folderId, type, rangeStart, rangeEnd, true);
if (result != null) {
// Found data in cache.
iterFolderId.remove();
addCalendarDataToResponse(parent, zsc, ifmt, result.data, result.allowPrivateAccess);
}
} catch (ServiceException e) {
String ecode = e.getCode();
if (ecode.equals(ServiceException.PERM_DENIED)) {
// share permission was revoked
ZimbraLog.calendar.warn("Ignoring permission error during calendar search of folder %s", ifmt.formatItemId(folderId), e);
} else if (ecode.equals(MailServiceException.NO_SUCH_FOLDER)) {
// shared calendar folder was deleted by the owner
ZimbraLog.calendar.warn("Ignoring deleted calendar folder %s", ifmt.formatItemId(folderId));
} else {
throw e;
}
iterFolderId.remove();
}
}
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();
if (folderIds.isEmpty())
continue;
Account targetAcct = prov.get(AccountBy.id, acctId);
if (targetAcct == null) {
ZimbraLog.calendar.warn("Skipping unknown account " + acctId + " during calendar search");
continue;
}
Mailbox targetMbox = mboxMgr.getMailboxByAccount(targetAcct);
searchLocalAccountCalendars(parent, params, octxt, zsc, authAcct, targetMbox, folderIds, type);
}
} else {
// remote server
searchRemoteAccountCalendars(parent, params, zsc, authAcct, accountFolders);
}
}
}
use of com.zimbra.cs.mailbox.MailboxManager in project zm-mailbox by Zimbra.
the class SomeAccountsWaitSet method addAccountErrors.
protected synchronized List<WaitSetError> addAccountErrors(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;
}
Aggregations