Search in sources :

Example 31 with MailItem

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

the class ZimbraQueryResultsImpl method getZimbraHit.

/**
     * We've got a {@link Mailbox}, a {@link DbSearch.Result} and (optionally) a Lucene Doc...
     * that's everything we need to build a real ZimbraHit.
     *
     * @param doc - Optional, only set if this search had a Lucene part
     */
ZimbraHit getZimbraHit(Mailbox mbox, DbSearch.Result sr, Document doc, DbSearch.FetchMode fetch) {
    MailItem item = null;
    ImapMessage i4msg = null;
    int modseq = -1, parentId = 0;
    switch(fetch) {
        case MAIL_ITEM:
            item = sr.getItem();
            break;
        case IMAP_MSG:
            i4msg = sr.getImapMessage();
            break;
        case MODSEQ:
            modseq = sr.getModSeq();
            break;
        case PARENT:
            parentId = sr.getParentId();
            break;
    }
    ZimbraHit result = null;
    switch(sr.getType()) {
        case CHAT:
        case MESSAGE:
            if (doc != null) {
                result = getMessagePartHit(mbox, sr.getId(), (Message) item, doc, sr.getSortValue());
            } else {
                result = getMessageHit(mbox, sr.getId(), (Message) item, null, sr.getSortValue());
            }
            break;
        case CONTACT:
            result = getContactHit(mbox, sr.getId(), (Contact) item, sr.getSortValue());
            break;
        case NOTE:
            result = getNoteHit(mbox, sr.getId(), (Note) item, sr.getSortValue());
            break;
        case APPOINTMENT:
            result = getAppointmentHit(mbox, sr.getId(), (CalendarItem) item, sr.getSortValue());
            break;
        case TASK:
            result = getTaskHit(mbox, sr.getId(), (Task) item, sr.getSortValue());
            break;
        case DOCUMENT:
        case WIKI:
            result = getDocumentHit(mbox, sr.getId(), (com.zimbra.cs.mailbox.Document) item, doc, sr.getSortValue());
            break;
        default:
            assert (false);
    }
    if (i4msg != null) {
        result.cacheImapMessage(i4msg);
    }
    if (modseq > 0) {
        result.cacheModifiedSequence(modseq);
    }
    if (parentId != 0) {
        result.cacheParentId(parentId);
    }
    return result;
}
Also used : CalendarItem(com.zimbra.cs.mailbox.CalendarItem) MailItem(com.zimbra.cs.mailbox.MailItem) Task(com.zimbra.cs.mailbox.Task) ImapMessage(com.zimbra.cs.imap.ImapMessage) Message(com.zimbra.cs.mailbox.Message) ImapMessage(com.zimbra.cs.imap.ImapMessage) Note(com.zimbra.cs.mailbox.Note) Document(org.apache.lucene.document.Document) Contact(com.zimbra.cs.mailbox.Contact)

Example 32 with MailItem

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

the class ZimbraHit method getModifiedSequence.

public int getModifiedSequence() throws ServiceException {
    if (cachedModseq < 0) {
        MailItem item = getMailItem();
        cachedModseq = item != null ? item.getModifiedSequence() : 0;
    }
    return cachedModseq;
}
Also used : MailItem(com.zimbra.cs.mailbox.MailItem)

Example 33 with MailItem

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

the class ZimbraHit method getImapMessage.

public ImapMessage getImapMessage() throws ServiceException {
    if (cachedImapMessage == null) {
        MailItem item = getMailItem();
        if (item == null) {
            return null;
        }
        cachedImapMessage = new ImapMessage(item);
    }
    return cachedImapMessage;
}
Also used : MailItem(com.zimbra.cs.mailbox.MailItem) ImapMessage(com.zimbra.cs.imap.ImapMessage)

Example 34 with MailItem

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

the class ExportAndDeleteItems method handle.

@Override
public Element handle(Element requst, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    checkRight(zsc, context, null, AdminRight.PR_SYSTEM_ADMIN_ONLY);
    // Parse request.
    ExportAndDeleteItemsRequest req = JaxbUtil.elementToJaxb(requst);
    ExportAndDeleteMailboxSpec mailbox = req.getMailbox();
    if (mailbox == null) {
        throw ServiceException.INVALID_REQUEST("empty mbox id", null);
    }
    Mailbox mbox = MailboxManager.getInstance().getMailboxById(mailbox.getId());
    Multimap<Integer, Integer> idRevs = HashMultimap.create();
    for (ExportAndDeleteItemSpec item : mailbox.getItems()) {
        idRevs.put(item.getId(), item.getVersion());
    }
    String dirPath = req.getExportDir();
    String prefix = req.getExportFilenamePrefix();
    // Lock the mailbox, to make sure that another thread doesn't modify the items we're exporting/deleting.
    mbox.lock.lock();
    try {
        DbConnection conn = null;
        try {
            conn = DbPool.getConnection();
            if (dirPath != null) {
                File exportDir = new File(dirPath);
                if (!exportDir.isDirectory()) {
                    DbPool.quietClose(conn);
                    throw ServiceException.INVALID_REQUEST(dirPath + " is not a directory", null);
                }
                String filePath = makePath(dirPath, DbMailItem.TABLE_MAIL_ITEM, prefix);
                export(conn, mbox, DbMailItem.TABLE_MAIL_ITEM, "id", idRevs, filePath);
                filePath = makePath(dirPath, DbMailItem.TABLE_MAIL_ITEM_DUMPSTER, prefix);
                export(conn, mbox, DbMailItem.TABLE_MAIL_ITEM_DUMPSTER, "id", idRevs, filePath);
                filePath = makePath(dirPath, DbMailItem.TABLE_REVISION, prefix);
                export(conn, mbox, DbMailItem.TABLE_REVISION, "item_id", idRevs, filePath);
                filePath = makePath(dirPath, DbMailItem.TABLE_REVISION_DUMPSTER, prefix);
                export(conn, mbox, DbMailItem.TABLE_REVISION_DUMPSTER, "item_id", idRevs, filePath);
                filePath = makePath(dirPath, DbMailItem.TABLE_APPOINTMENT, prefix);
                export(conn, mbox, DbMailItem.TABLE_APPOINTMENT, "item_id", idRevs, filePath);
                filePath = makePath(dirPath, DbMailItem.TABLE_APPOINTMENT_DUMPSTER, prefix);
                export(conn, mbox, DbMailItem.TABLE_APPOINTMENT_DUMPSTER, "item_id", idRevs, filePath);
            }
            // delete item from mail_item and revision table
            for (Integer itemId : idRevs.keySet()) {
                Collection<Integer> revs = idRevs.get(itemId);
                for (int rev : revs) {
                    if (rev == 0) {
                        // delete all revisions to make sure we delete all blobs
                        List<MailItem> list = null;
                        try {
                            list = mbox.getAllRevisions(null, itemId, MailItem.Type.UNKNOWN);
                        } catch (NoSuchItemException ex) {
                            // exception happens when we try to delete a mail_item which is already in mail_item_dumpster
                            continue;
                        }
                        for (MailItem item : list) {
                            if (item.getType() == MailItem.Type.DOCUMENT) {
                                mbox.purgeRevision(null, itemId, item.getVersion(), false);
                            }
                        }
                        mbox.delete(null, itemId, MailItem.Type.UNKNOWN, null);
                        break;
                    } else if (!revs.contains(0)) {
                        try {
                            mbox.purgeRevision(null, itemId, rev, false);
                        } catch (NoSuchItemException ex) {
                            // exception happens when we try to delete a revision which is already in revision_dumpster
                            continue;
                        }
                    }
                }
            }
            // Delete items from mail_item_dumpster & revision_dumpster tables just
            // incase moved to dumpster tables
            DbBlobConsistency.delete(conn, mbox, idRevs);
        } finally {
            conn.commit();
            DbPool.quietClose(conn);
        }
    } finally {
        mbox.lock.release();
    }
    return zsc.createElement(AdminConstants.EXPORT_AND_DELETE_ITEMS_RESPONSE);
}
Also used : ExportAndDeleteItemSpec(com.zimbra.soap.admin.type.ExportAndDeleteItemSpec) NoSuchItemException(com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException) DbConnection(com.zimbra.cs.db.DbPool.DbConnection) MailItem(com.zimbra.cs.mailbox.MailItem) DbMailItem(com.zimbra.cs.db.DbMailItem) ExportAndDeleteItemsRequest(com.zimbra.soap.admin.message.ExportAndDeleteItemsRequest) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) ExportAndDeleteMailboxSpec(com.zimbra.soap.admin.type.ExportAndDeleteMailboxSpec) File(java.io.File)

Example 35 with MailItem

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

the class GetMsg method getMsgs.

public static List<Message> getMsgs(OperationContext octxt, Mailbox mbox, List<Integer> iids, boolean read) throws ServiceException {
    int i = 0;
    int[] msgIdArray = new int[iids.size()];
    for (int id : iids) {
        msgIdArray[i++] = id;
    }
    List<Message> toRet = new ArrayList<Message>(msgIdArray.length);
    for (MailItem item : mbox.getItemById(octxt, msgIdArray, MailItem.Type.MESSAGE)) {
        toRet.add((Message) item);
        if (read && item.isUnread() && !RedoLogProvider.getInstance().isSlave()) {
            mbox.alterTag(octxt, item.getId(), MailItem.Type.MESSAGE, Flag.FlagInfo.UNREAD, false, null);
        }
    }
    return toRet;
}
Also used : MailItem(com.zimbra.cs.mailbox.MailItem) Message(com.zimbra.cs.mailbox.Message) ArrayList(java.util.ArrayList)

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