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;
}
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;
}
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);
}
}
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);
}
}
Aggregations