use of com.zimbra.cs.datasource.imap.ImapFolderCollection in project zm-mailbox by Zimbra.
the class DbImapFolder method getImapFolders.
/**
* Returns a <tt>List</tt> of <tt>ImapFolders</tt> for the given <tt>DataSource</tt>.
*/
public static ImapFolderCollection getImapFolders(Mailbox mbox, DataSource ds) throws ServiceException {
ImapFolderCollection imapFolders = new ImapFolderCollection();
DbConnection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
conn = DbPool.getConnection(mbox);
stmt = conn.prepareStatement("SELECT item_id, local_path, remote_path, uid_validity" + " FROM " + getTableName(mbox) + " WHERE " + DbMailItem.IN_THIS_MAILBOX_AND + "data_source_id = ?");
int pos = 1;
pos = DbMailItem.setMailboxId(stmt, mbox, pos);
stmt.setString(pos++, ds.getId());
rs = stmt.executeQuery();
while (rs.next()) {
int itemId = rs.getInt("item_id");
String localPath = rs.getString("local_path");
String remotePath = rs.getString("remote_path");
Long uidValidity = rs.getLong("uid_validity");
if (rs.wasNull())
uidValidity = null;
ImapFolder imapFolder = new ImapFolder(ds, itemId, remotePath, localPath, uidValidity);
imapFolders.add(imapFolder);
}
} catch (SQLException e) {
throw ServiceException.FAILURE("Unable to get IMAP folder data", e);
} finally {
DbPool.closeResults(rs);
DbPool.closeStatement(stmt);
DbPool.quietClose(conn);
}
ZimbraLog.datasource.debug("Found %d folders for %s", imapFolders.size(), ds);
return imapFolders;
}
Aggregations