Search in sources :

Example 16 with MailItem

use of com.zimbra.cs.mailbox.MailItem in project zm-mailbox by Zimbra.

the class ImapFolder method handleItemUpdate.

@Override
public void handleItemUpdate(int changeId, Change chg, ImapSession.AddedItems added) {
    MailItem item = (MailItem) chg.what;
    boolean inFolder = isVirtual() || item.getFolderId() == folderId;
    ImapMessage i4msg = getById(item.getId());
    if (i4msg == null) {
        if (inFolder && !isVirtual()) {
            added.add(item);
            ZimbraLog.imap.debug("  ** moved (ntfn) {id: %d UID: %d}", item.getId(), item.getImapUid());
        }
    } else if (!inFolder && !isVirtual()) {
        markMessageExpunged(i4msg);
    } else if ((chg.why & Change.IMAP_UID) != 0) {
        // if the IMAP uid changed, need to bump it to the back of the sequence!
        if (item.getImapUid() > 0 && i4msg.imapUid > item.getImapUid()) {
            //this update was the result of renumber which occurred in other session
            //we need to ignore it or we end up expunging the newest copy of the message (with current UID) and replacing it with an older UID
            ZimbraLog.imap.debug("IMAP UID changed (ntfn) {id: %d UID: %d} but sequence already contains higher UID %s", item.getId(), item.getImapUid(), i4msg);
            return;
        }
        markMessageExpunged(i4msg);
        if (!isVirtual()) {
            added.add(item);
        }
        ZimbraLog.imap.debug("  ** imap uid changed (ntfn) {id: %d UID: %d}", item.getId(), item.getImapUid());
    } else if ((chg.why & (Change.TAGS | Change.FLAGS | Change.UNREAD)) != 0) {
        i4msg.setPermanentFlags(item.getFlagBitmask(), item.getTags(), changeId, this);
    }
}
Also used : MailItem(com.zimbra.cs.mailbox.MailItem)

Example 17 with MailItem

use of com.zimbra.cs.mailbox.MailItem in project zm-mailbox by Zimbra.

the class AclPushTask method doWork.

public static synchronized void doWork() {
    if (!supported)
        return;
    ZimbraLog.misc.debug("Starting pending ACL push");
    Multimap<Integer, List<Integer>> currentItemIdsProcessed = ArrayListMultimap.create();
    try {
        Date now = new Date();
        Multimap<Integer, Integer> mboxIdToItemIds = DbPendingAclPush.getEntries(now);
        for (int mboxId : mboxIdToItemIds.keySet()) {
            Mailbox mbox;
            List<Integer> itemsProcessed = new ArrayList<Integer>();
            try {
                mbox = MailboxManager.getInstance().getMailboxById(mboxId);
            } catch (ServiceException e) {
                ZimbraLog.misc.info("Exception occurred while getting mailbox for id %s during ACL push", mboxId, e);
                continue;
            }
            Collection<Integer> itemIds = mboxIdToItemIds.get(mboxId);
            MailItem[] items = null;
            try {
                items = mbox.getItemById(null, itemIds, MailItem.Type.UNKNOWN);
            } catch (MailServiceException.NoSuchItemException e) {
                // one or more folders no longer exist
                if (itemIds.size() > 1) {
                    List<MailItem> itemList = new ArrayList<MailItem>();
                    for (int itemId : itemIds) {
                        try {
                            itemList.add(mbox.getItemById(null, itemId, MailItem.Type.UNKNOWN));
                        } catch (MailServiceException.NoSuchItemException ignored) {
                        }
                    }
                    items = itemList.toArray(new MailItem[itemList.size()]);
                }
            }
            Account account = mbox.getAccount();
            String[] existingSharedItems = account.getSharedItem();
            Set<String> updatedSharedItems = new HashSet<String>();
            for (String sharedItem : existingSharedItems) {
                ShareInfoData shareData = AclPushSerializer.deserialize(sharedItem);
                if (!itemIds.contains(shareData.getItemId())) {
                    updatedSharedItems.add(sharedItem);
                }
            }
            if (items != null) {
                for (MailItem item : items) {
                    if (item == null) {
                        continue;
                    }
                    // for now push the Folder grants to LDAP
                    if (!(item instanceof Folder)) {
                        continue;
                    }
                    ACL acl = item.getACL();
                    if (acl == null) {
                        continue;
                    }
                    for (ACL.Grant grant : acl.getGrants()) {
                        updatedSharedItems.add(AclPushSerializer.serialize(item, grant));
                    }
                    itemsProcessed.add(item.getId());
                    currentItemIdsProcessed.put(mboxId, itemsProcessed);
                }
            }
            account.setSharedItem(updatedSharedItems.toArray(new String[updatedSharedItems.size()]));
        }
        // for
        DbPendingAclPush.deleteEntries(now);
    } catch (ServiceException e) {
        ZimbraLog.misc.warn("Error during ACL push task", e);
    } catch (Throwable t) {
        //don't let exceptions kill the timer
        try {
            // We ran into runtime exception, so we want to delete records from ACL 
            // table for processed records.
            deleteDbAclEntryForProcessedItems(currentItemIdsProcessed);
        } catch (ServiceException e) {
            ZimbraLog.misc.warn("Error during ACL push task and deleting ACL push entry.");
        }
        ZimbraLog.misc.warn("Error during ACL push task", t);
    }
    ZimbraLog.misc.debug("Finished pending ACL push");
}
Also used : Account(com.zimbra.cs.account.Account) ArrayList(java.util.ArrayList) Folder(com.zimbra.cs.mailbox.Folder) Mailbox(com.zimbra.cs.mailbox.Mailbox) ArrayList(java.util.ArrayList) List(java.util.List) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) HashSet(java.util.HashSet) ShareInfoData(com.zimbra.cs.account.ShareInfoData) ACL(com.zimbra.cs.mailbox.ACL) Date(java.util.Date) MailItem(com.zimbra.cs.mailbox.MailItem) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException)

Example 18 with MailItem

use of com.zimbra.cs.mailbox.MailItem in project zm-mailbox by Zimbra.

the class IndexItem method redo.

@Override
public void redo() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxById(getMailboxId());
    MailItem item;
    try {
        item = mbox.getItemById(null, mId, type);
    } catch (MailServiceException.NoSuchItemException e) {
        // problem.  So just ignore the NoSuchItemException.
        return;
    }
    try {
        List<IndexDocument> docList = item.generateIndexData();
        mbox.index.redoIndexItem(item, mId, docList);
    } catch (Exception e) {
        // TODO - update the item and set the item's "unindexed" flag
        ZimbraLog.index.info("Caught exception attempting to replay IndexItem for ID " + mId + " item will not be indexed", e);
    }
}
Also used : IndexDocument(com.zimbra.cs.index.IndexDocument) MailItem(com.zimbra.cs.mailbox.MailItem) Mailbox(com.zimbra.cs.mailbox.Mailbox) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) IOException(java.io.IOException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException)

Example 19 with MailItem

use of com.zimbra.cs.mailbox.MailItem in project zm-mailbox by Zimbra.

the class ImapSession method handleModify.

private void handleModify(int changeId, Change chg, AddedItems added) {
    if (chg.what instanceof Tag && (chg.why & Change.NAME) != 0) {
        mFolder.handleTagRename(changeId, (Tag) chg.what, chg);
    } else if (chg.what instanceof Folder && ((Folder) chg.what).getId() == mFolderId) {
        Folder folder = (Folder) chg.what;
        if ((chg.why & Change.FLAGS) != 0 && (folder.getFlagBitmask() & Flag.BITMASK_DELETED) != 0) {
            //                mailbox accessed by sending a untagged BYE response."
            if (handler != null) {
                handler.close();
            }
        } else if ((chg.why & (Change.FOLDER | Change.NAME)) != 0) {
            mFolder.handleFolderRename(changeId, folder, chg);
        }
    } else if (chg.what instanceof Message || chg.what instanceof Contact) {
        MailItem item = (MailItem) chg.what;
        boolean inFolder = mIsVirtual || item.getFolderId() == mFolderId;
        if (!inFolder && (chg.why & Change.FOLDER) == 0) {
            return;
        }
        mFolder.handleItemUpdate(changeId, chg, added);
    }
}
Also used : MailItem(com.zimbra.cs.mailbox.MailItem) Message(com.zimbra.cs.mailbox.Message) DirtyMessage(com.zimbra.cs.imap.ImapFolder.DirtyMessage) Tag(com.zimbra.cs.mailbox.Tag) Folder(com.zimbra.cs.mailbox.Folder) Contact(com.zimbra.cs.mailbox.Contact)

Example 20 with MailItem

use of com.zimbra.cs.mailbox.MailItem in project zm-mailbox by Zimbra.

the class CalSummaryCache method notifyCommittedChanges.

void notifyCommittedChanges(PendingModifications mods, int changeId) {
    if (mods.created != null) {
        for (Map.Entry<ModificationKey, MailItem> entry : mods.created.entrySet()) {
            MailItem item = entry.getValue();
            if (item instanceof CalendarItem) {
                int folderId = item.getFolderId();
                invalidateItem(item.getMailbox(), folderId, item.getId());
            }
        }
    }
    if (mods.modified != null) {
        for (Map.Entry<ModificationKey, Change> entry : mods.modified.entrySet()) {
            Change change = entry.getValue();
            Object whatChanged = change.what;
            if (whatChanged instanceof CalendarItem) {
                CalendarItem item = (CalendarItem) whatChanged;
                Mailbox mbox = item.getMailbox();
                int folderId = item.getFolderId();
                int itemId = item.getId();
                invalidateItem(mbox, folderId, itemId);
                // If this is a folder move, invalidate the item from the old folder too.
                if ((change.why & Change.FOLDER) != 0) {
                    String accountId = mbox.getAccountId();
                    int prevFolderId;
                    synchronized (mSummaryCache) {
                        prevFolderId = mSummaryCache.getFolderForItem(accountId, itemId);
                    }
                    if (prevFolderId != folderId && prevFolderId != SummaryLRU.FOLDER_NOT_FOUND) {
                        invalidateItem(mbox, prevFolderId, itemId);
                    }
                }
            }
        }
    }
    if (mods.deleted != null) {
        String lastAcctId = null;
        Mailbox lastMbox = null;
        for (Map.Entry<ModificationKey, Change> entry : mods.deleted.entrySet()) {
            MailItem.Type type = (MailItem.Type) entry.getValue().what;
            if (type == MailItem.Type.APPOINTMENT || type == MailItem.Type.TASK) {
                // We only have item id.  Look up the folder id of the item in the cache.
                Mailbox mbox = null;
                String acctId = entry.getKey().getAccountId();
                // just to be safe
                if (acctId == null)
                    continue;
                if (acctId.equals(lastAcctId)) {
                    // Deletion by id list usually happens because of a folder getting emptied.
                    // It's highly likely the items all belong to the same mailbox, let alone folder.
                    mbox = lastMbox;
                } else {
                    try {
                        mbox = MailboxManager.getInstance().getMailboxByAccountId(acctId, FetchMode.DO_NOT_AUTOCREATE);
                    } catch (ServiceException e) {
                        ZimbraLog.calendar.error("Error looking up the mailbox of account in delete notification: account=" + acctId, e);
                        continue;
                    }
                }
                if (mbox != null) {
                    lastAcctId = acctId;
                    lastMbox = mbox;
                    int itemId = entry.getKey().getItemId();
                    String accountId = mbox.getAccountId();
                    int folderId;
                    synchronized (mSummaryCache) {
                        folderId = mSummaryCache.getFolderForItem(accountId, itemId);
                    }
                    if (folderId != SummaryLRU.FOLDER_NOT_FOUND) {
                        invalidateItem(mbox, folderId, itemId);
                    }
                }
            }
        }
    }
    if (MemcachedConnector.isConnected()) {
        mMemcachedCache.notifyCommittedChanges(mods, changeId);
    }
}
Also used : ModificationKey(com.zimbra.cs.session.PendingModifications.ModificationKey) Change(com.zimbra.cs.session.PendingModifications.Change) CalendarItem(com.zimbra.cs.mailbox.CalendarItem) MailItem(com.zimbra.cs.mailbox.MailItem) Mailbox(com.zimbra.cs.mailbox.Mailbox) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

MailItem (com.zimbra.cs.mailbox.MailItem)74 Mailbox (com.zimbra.cs.mailbox.Mailbox)36 ServiceException (com.zimbra.common.service.ServiceException)30 Folder (com.zimbra.cs.mailbox.Folder)23 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)23 Message (com.zimbra.cs.mailbox.Message)19 Mountpoint (com.zimbra.cs.mailbox.Mountpoint)17 ArrayList (java.util.ArrayList)17 IOException (java.io.IOException)16 OperationContext (com.zimbra.cs.mailbox.OperationContext)15 NoSuchItemException (com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)14 Element (com.zimbra.common.soap.Element)13 CalendarItem (com.zimbra.cs.mailbox.CalendarItem)13 Account (com.zimbra.cs.account.Account)12 Document (com.zimbra.cs.mailbox.Document)12 ItemId (com.zimbra.cs.service.util.ItemId)11 HashMap (java.util.HashMap)11 ZMailbox (com.zimbra.client.ZMailbox)9 Contact (com.zimbra.cs.mailbox.Contact)9 HashSet (java.util.HashSet)9