Search in sources :

Example 1 with ImapMessage

use of com.zimbra.cs.imap.ImapMessage 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 2 with ImapMessage

use of com.zimbra.cs.imap.ImapMessage 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 3 with ImapMessage

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

the class Mailbox method openImapFolder.

public List<ImapMessage> openImapFolder(OperationContext octxt, int folderId) throws ServiceException {
    boolean success = false;
    try {
        beginTransaction("openImapFolder", octxt);
        Folder folder = getFolderById(folderId);
        List<ImapMessage> i4list = DbMailItem.loadImapFolder(folder);
        success = true;
        return i4list;
    } finally {
        endTransaction(success);
    }
}
Also used : ImapMessage(com.zimbra.cs.imap.ImapMessage) CreateFolder(com.zimbra.cs.redolog.op.CreateFolder) ZFolder(com.zimbra.client.ZFolder)

Example 4 with ImapMessage

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

the class DbMailItem method loadImapFolder.

public static List<ImapMessage> loadImapFolder(Folder folder) throws ServiceException {
    Mailbox mbox = folder.getMailbox();
    List<ImapMessage> result = new ArrayList<ImapMessage>();
    DbConnection conn = mbox.getOperationConnection();
    PreparedStatement stmt = null;
    ResultSet rs = null;
    try {
        stmt = conn.prepareStatement("SELECT " + IMAP_FIELDS + " FROM " + getMailItemTableName(folder.getMailbox(), " mi") + " WHERE " + IN_THIS_MAILBOX_AND + "folder_id = ? AND type IN " + IMAP_TYPES);
        if (folder.getSize() > RESULTS_STREAMING_MIN_ROWS) {
            Db.getInstance().enableStreaming(stmt);
        }
        int pos = 1;
        pos = setMailboxId(stmt, mbox, pos);
        stmt.setInt(pos++, folder.getId());
        rs = stmt.executeQuery();
        while (rs.next()) {
            int flags = rs.getBoolean(4) ? Flag.BITMASK_UNREAD | rs.getInt(5) : rs.getInt(5);
            result.add(new ImapMessage(rs.getInt(1), MailItem.Type.of(rs.getByte(2)), rs.getInt(3), flags, DbTag.deserializeTags(rs.getString(6))));
        }
        return result;
    } catch (SQLException e) {
        throw ServiceException.FAILURE("loading IMAP folder data: " + folder.getPath(), e);
    } finally {
        DbPool.closeResults(rs);
        DbPool.closeStatement(stmt);
    }
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) ImapMessage(com.zimbra.cs.imap.ImapMessage) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DbConnection(com.zimbra.cs.db.DbPool.DbConnection)

Aggregations

ImapMessage (com.zimbra.cs.imap.ImapMessage)4 MailItem (com.zimbra.cs.mailbox.MailItem)2 ZFolder (com.zimbra.client.ZFolder)1 DbConnection (com.zimbra.cs.db.DbPool.DbConnection)1 CalendarItem (com.zimbra.cs.mailbox.CalendarItem)1 Contact (com.zimbra.cs.mailbox.Contact)1 Mailbox (com.zimbra.cs.mailbox.Mailbox)1 Message (com.zimbra.cs.mailbox.Message)1 Note (com.zimbra.cs.mailbox.Note)1 Task (com.zimbra.cs.mailbox.Task)1 CreateFolder (com.zimbra.cs.redolog.op.CreateFolder)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Document (org.apache.lucene.document.Document)1