Search in sources :

Example 1 with MailboxManager

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");
}
Also used : MailboxData(com.zimbra.cs.mailbox.Mailbox.MailboxData) MailSender(com.zimbra.cs.mailbox.MailSender) IOException(java.io.IOException) Provisioning(com.zimbra.cs.account.Provisioning) MessagingException(javax.mail.MessagingException) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException) MailboxManager(com.zimbra.cs.mailbox.MailboxManager) Mailbox(com.zimbra.cs.mailbox.Mailbox) MimeMessage(javax.mail.internet.MimeMessage) Collection(java.util.Collection) BeforeClass(org.junit.BeforeClass)

Example 2 with MailboxManager

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();
                            }
                        }
                    };
                }
            };
        }
    });
}
Also used : MailboxData(com.zimbra.cs.mailbox.Mailbox.MailboxData) MailSender(com.zimbra.cs.mailbox.MailSender) Provisioning(com.zimbra.cs.account.Provisioning) MailboxManager(com.zimbra.cs.mailbox.MailboxManager) Mailbox(com.zimbra.cs.mailbox.Mailbox) MimeMessage(javax.mail.internet.MimeMessage) Collection(java.util.Collection) Before(org.junit.Before)

Example 3 with MailboxManager

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();
                            }
                        }
                    };
                }
            };
        }
    });
}
Also used : MailboxData(com.zimbra.cs.mailbox.Mailbox.MailboxData) MailSender(com.zimbra.cs.mailbox.MailSender) ZAttrProvisioning(com.zimbra.common.account.ZAttrProvisioning) Provisioning(com.zimbra.cs.account.Provisioning) MailboxManager(com.zimbra.cs.mailbox.MailboxManager) Mailbox(com.zimbra.cs.mailbox.Mailbox) MimeMessage(javax.mail.internet.MimeMessage) Collection(java.util.Collection) Before(org.junit.Before)

Example 4 with MailboxManager

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);
        }
    }
}
Also used : Account(com.zimbra.cs.account.Account) Server(com.zimbra.cs.account.Server) ItemIdFormatter(com.zimbra.cs.service.util.ItemIdFormatter) ArrayList(java.util.ArrayList) CalendarDataResult(com.zimbra.cs.mailbox.calendar.cache.CalSummaryCache.CalendarDataResult) ItemId(com.zimbra.cs.service.util.ItemId) Provisioning(com.zimbra.cs.account.Provisioning) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ArrayList(java.util.ArrayList) List(java.util.List) MailItem(com.zimbra.cs.mailbox.MailItem) MailboxManager(com.zimbra.cs.mailbox.MailboxManager) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) HashMap(java.util.HashMap) Map(java.util.Map) ContactMemberOfMap(com.zimbra.cs.mailbox.ContactMemberOfMap) CalSummaryCache(com.zimbra.cs.mailbox.calendar.cache.CalSummaryCache)

Example 5 with MailboxManager

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;
}
Also used : MailboxManager(com.zimbra.cs.mailbox.MailboxManager) Mailbox(com.zimbra.cs.mailbox.Mailbox) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) FetchMode(com.zimbra.cs.mailbox.MailboxManager.FetchMode) ArrayList(java.util.ArrayList)

Aggregations

MailboxManager (com.zimbra.cs.mailbox.MailboxManager)10 Mailbox (com.zimbra.cs.mailbox.Mailbox)9 ServiceException (com.zimbra.common.service.ServiceException)7 Provisioning (com.zimbra.cs.account.Provisioning)6 MailSender (com.zimbra.cs.mailbox.MailSender)4 MailboxData (com.zimbra.cs.mailbox.Mailbox.MailboxData)4 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)4 MimeMessage (javax.mail.internet.MimeMessage)4 Account (com.zimbra.cs.account.Account)3 AccountServiceException (com.zimbra.cs.account.AccountServiceException)3 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)3 ZMailbox (com.zimbra.client.ZMailbox)2 Server (com.zimbra.cs.account.Server)2 FetchMode (com.zimbra.cs.mailbox.MailboxManager.FetchMode)2 CalSummaryCache (com.zimbra.cs.mailbox.calendar.cache.CalSummaryCache)2 CalendarDataResult (com.zimbra.cs.mailbox.calendar.cache.CalSummaryCache.CalendarDataResult)2 ItemId (com.zimbra.cs.service.util.ItemId)2 ItemIdFormatter (com.zimbra.cs.service.util.ItemIdFormatter)2 IOException (java.io.IOException)2