use of com.zimbra.cs.datasource.imap.ImapMessage in project zm-mailbox by Zimbra.
the class DbImapMessage method getMovedMessages.
public static List<ImapMessage> getMovedMessages(Mailbox mbox, DataSource ds, int folderId) throws ServiceException {
List<ImapMessage> msgs = new ArrayList<ImapMessage>();
DbConnection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
conn = DbPool.getConnection();
stmt = conn.prepareStatement(String.format("SELECT imap.uid, imap.item_id, imap.flags as tflags, mi.unread, mi.flags " + " FROM %s imap JOIN %s mi " + " ON imap.mailbox_id = mi.mailbox_id AND imap.item_id = mi.id " + " WHERE imap.mailbox_id = %d AND imap.imap_folder_id = %d AND mi.folder_id != %d", getTableName(mbox), DbMailItem.getMailItemTableName(mbox), mbox.getId(), folderId, folderId));
rs = stmt.executeQuery();
while (rs.next()) {
long uid = rs.getLong("uid");
int itemId = rs.getInt("item_id");
int flags = rs.getInt("flags");
int unread = rs.getInt("unread");
int tflags = rs.getInt("tflags");
flags = unread > 0 ? (flags | Flag.BITMASK_UNREAD) : (flags & ~Flag.BITMASK_UNREAD);
msgs.add(new ImapMessage(ds, -1, itemId, tflags, uid, flags));
}
rs.close();
stmt.close();
} catch (SQLException e) {
throw ServiceException.FAILURE("Unable to get IMAP message data", e);
} finally {
DbPool.closeResults(rs);
DbPool.closeStatement(stmt);
DbPool.quietClose(conn);
}
return msgs;
}
use of com.zimbra.cs.datasource.imap.ImapMessage in project zm-mailbox by Zimbra.
the class DbImapMessage method getImapMessage.
public static Pair<ImapMessage, Integer> getImapMessage(Mailbox mbox, DataSource ds, int itemId) throws ServiceException {
DbConnection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
conn = DbPool.getConnection();
String MBOX_JOIN = DebugConfig.disableMailboxGroups ? "" : "imap.mailbox_id = mi.mailbox_id AND";
String IN_IMAP_MAILBOX_AND = DebugConfig.disableMailboxGroups ? "" : "imap.mailbox_id = ? AND";
stmt = conn.prepareStatement("SELECT imap.uid, imap.flags as tflags, imap.imap_folder_id, mi.unread, mi.flags " + "FROM " + getTableName(mbox) + " imap " + " LEFT OUTER JOIN " + DbMailItem.getMailItemTableName(mbox) + " mi " + " ON " + MBOX_JOIN + " imap.item_id = mi.id " + "WHERE " + IN_IMAP_MAILBOX_AND + " imap.item_id = ?");
int pos = 1;
pos = DbMailItem.setMailboxId(stmt, mbox, pos);
stmt.setInt(pos++, itemId);
rs = stmt.executeQuery();
if (rs.next()) {
long uid = rs.getLong("uid");
int flags = rs.getInt("flags");
int unread = rs.getInt("unread");
int tflags = rs.getInt("tflags");
int folderId = rs.getInt("imap_folder_id");
flags = unread > 0 ? (flags | Flag.BITMASK_UNREAD) : (flags & ~Flag.BITMASK_UNREAD);
return new Pair<ImapMessage, Integer>(new ImapMessage(ds, -1, itemId, tflags, uid, flags), folderId);
}
return null;
} catch (SQLException e) {
throw ServiceException.FAILURE("Unable to get IMAP message data", e);
} finally {
DbPool.closeResults(rs);
DbPool.closeStatement(stmt);
DbPool.quietClose(conn);
}
}
use of com.zimbra.cs.datasource.imap.ImapMessage in project zm-mailbox by Zimbra.
the class DbImapMessage method getImapMessages.
/**
* Returns a collection of tracked IMAP messages for the given data source.
*/
public static ImapMessageCollection getImapMessages(Mailbox mbox, DataSource ds, ImapFolder imapFolder) throws ServiceException {
ImapMessageCollection imapMessages = new ImapMessageCollection();
DbConnection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
String MBOX_JOIN = DebugConfig.disableMailboxGroups ? "" : "imap.mailbox_id = mi.mailbox_id AND";
String IN_IMAP_MAILBOX_AND = DebugConfig.disableMailboxGroups ? "" : "imap.mailbox_id = ? AND";
conn = DbPool.getConnection(mbox);
stmt = conn.prepareStatement("SELECT imap.uid, imap.item_id, imap.flags as tflags, mi.unread, mi.flags " + "FROM " + getTableName(mbox) + " imap " + " LEFT OUTER JOIN " + DbMailItem.getMailItemTableName(mbox) + " mi " + " ON " + MBOX_JOIN + " imap.item_id = mi.id " + "WHERE " + IN_IMAP_MAILBOX_AND + " imap.imap_folder_id = ?");
int pos = 1;
pos = DbMailItem.setMailboxId(stmt, mbox, pos);
stmt.setInt(pos++, imapFolder.getItemId());
rs = stmt.executeQuery();
while (rs.next()) {
long uid = rs.getLong("uid");
int itemId = rs.getInt("item_id");
int flags = rs.getInt("flags");
int unread = rs.getInt("unread");
int tflags = rs.getInt("tflags");
flags = unread > 0 ? (flags | Flag.BITMASK_UNREAD) : (flags & ~Flag.BITMASK_UNREAD);
imapMessages.add(new ImapMessage(ds, imapFolder.getItemId(), itemId, tflags, uid, flags));
}
} catch (SQLException e) {
throw ServiceException.FAILURE("Unable to get IMAP message data", e);
} finally {
DbPool.closeResults(rs);
DbPool.closeStatement(stmt);
DbPool.quietClose(conn);
}
ZimbraLog.datasource.debug("Found %d tracked IMAP messages for %s", imapMessages.size(), imapFolder.getRemoteId());
return imapMessages;
}
Aggregations