Search in sources :

Example 11 with DataSourceItem

use of com.zimbra.cs.db.DbDataSource.DataSourceItem in project zm-mailbox by Zimbra.

the class ImapFolder method getNewMessageIds.

public List<Integer> getNewMessageIds() throws ServiceException {
    Collection<DataSourceItem> mappings = getMappingsAndFlags(ds, getItemId());
    Mailbox mbox = DataSourceManager.getInstance().getMailbox(ds);
    List<Integer> allIds = mbox.listItemIds(mbox.getOperationContext(), MailItem.Type.MESSAGE, getItemId());
    List<Integer> newIds = new ArrayList<Integer>();
    loop: for (Integer id : allIds) {
        for (DataSourceItem mapping : mappings) {
            if (mapping.itemId == id) {
                mappings.remove(mapping);
                continue loop;
            }
        }
        newIds.add(id);
    }
    return newIds;
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) ArrayList(java.util.ArrayList) DataSourceItem(com.zimbra.cs.db.DbDataSource.DataSourceItem)

Example 12 with DataSourceItem

use of com.zimbra.cs.db.DbDataSource.DataSourceItem in project zm-mailbox by Zimbra.

the class ImapFolder method getMessages.

public ImapMessageCollection getMessages() throws ServiceException {
    Collection<DataSourceItem> mappings = getMappingsAndFlags(ds, getItemId());
    ImapMessageCollection imc = new ImapMessageCollection();
    for (DataSourceItem mapping : mappings) imc.add(new ImapMessage(ds, mapping));
    return imc;
}
Also used : DbImapMessage(com.zimbra.cs.db.DbImapMessage) DataSourceItem(com.zimbra.cs.db.DbDataSource.DataSourceItem)

Example 13 with DataSourceItem

use of com.zimbra.cs.db.DbDataSource.DataSourceItem in project zm-mailbox by Zimbra.

the class ImapFolder method getFolders.

public static ImapFolderCollection getFolders(DataSource ds) throws ServiceException {
    Collection<DataSourceItem> mappings = getMappings(ds, ds.getFolderId());
    ImapFolderCollection ifc = new ImapFolderCollection();
    if (mappings.size() == 0) {
        Mailbox mbox = DataSourceManager.getInstance().getMailbox(ds);
        ZimbraLog.datasource.info("Upgrading IMAP data for %s", ds.getName());
        DbDataSource.deleteAllMappings(ds);
        try {
            for (ImapFolder folderTracker : DbImapFolder.getImapFolders(mbox, ds)) {
                folderTracker.add();
                for (ImapMessage msgTracker : DbImapMessage.getImapMessages(mbox, ds, folderTracker)) {
                    msgTracker.add();
                }
            }
        } catch (Exception e) {
            DbDataSource.deleteAllMappings(ds);
            throw ServiceException.FAILURE("IMAP data upgrade failed for " + ds.getName(), e);
        }
        mappings = getMappings(ds, ds.getFolderId());
        DbImapFolder.deleteImapData(mbox, ds.getId());
    }
    for (DataSourceItem mapping : mappings) ifc.add(new ImapFolder(ds, mapping));
    return ifc;
}
Also used : DbImapFolder(com.zimbra.cs.db.DbImapFolder) Mailbox(com.zimbra.cs.mailbox.Mailbox) DbImapMessage(com.zimbra.cs.db.DbImapMessage) DataSourceItem(com.zimbra.cs.db.DbDataSource.DataSourceItem) ServiceException(com.zimbra.common.service.ServiceException)

Aggregations

DataSourceItem (com.zimbra.cs.db.DbDataSource.DataSourceItem)13 DataSource (com.zimbra.cs.account.DataSource)6 DbDataSource (com.zimbra.cs.db.DbDataSource)6 ArrayList (java.util.ArrayList)5 ServiceException (com.zimbra.common.service.ServiceException)4 Metadata (com.zimbra.cs.mailbox.Metadata)4 OperationContext (com.zimbra.cs.mailbox.OperationContext)4 CalDavClient (com.zimbra.cs.dav.client.CalDavClient)3 Appointment (com.zimbra.cs.dav.client.CalDavClient.Appointment)3 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)3 Mailbox (com.zimbra.cs.mailbox.Mailbox)3 HashMap (java.util.HashMap)3 DbImapMessage (com.zimbra.cs.db.DbImapMessage)2 CalendarItem (com.zimbra.cs.mailbox.CalendarItem)2 NoSuchItemException (com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)2 HashSet (java.util.HashSet)2 GalMode (com.zimbra.common.account.ZAttrProvisioning.GalMode)1 Domain (com.zimbra.cs.account.Domain)1 SearchGalResult (com.zimbra.cs.account.Provisioning.SearchGalResult)1 DavException (com.zimbra.cs.dav.DavException)1