use of com.zimbra.cs.mailbox.util.TypedIdList in project zm-mailbox by Zimbra.
the class DbMailItem method listByFolder.
public static TypedIdList listByFolder(Folder folder, boolean descending) throws ServiceException {
Mailbox mbox = folder.getMailbox();
TypedIdList result = new TypedIdList();
DbConnection conn = mbox.getOperationConnection();
PreparedStatement stmt = null;
ResultSet rs = null;
try {
stmt = conn.prepareStatement("SELECT id, type, uuid FROM " + getMailItemTableName(folder) + " WHERE " + IN_THIS_MAILBOX_AND + "folder_id = ?" + " ORDER BY date" + (descending ? " DESC" : ""));
int pos = 1;
pos = setMailboxId(stmt, mbox, pos);
stmt.setInt(pos++, folder.getId());
rs = stmt.executeQuery();
while (rs.next()) {
result.add(MailItem.Type.of(rs.getByte(2)), rs.getInt(1), rs.getString(3));
}
return result;
} catch (SQLException e) {
throw ServiceException.FAILURE("fetching item list for folder " + folder.getId(), e);
} finally {
DbPool.closeResults(rs);
DbPool.closeStatement(stmt);
}
}
use of com.zimbra.cs.mailbox.util.TypedIdList in project zm-mailbox by Zimbra.
the class Mailbox method getTombstones.
public TypedIdList getTombstones(int lastSync, boolean equalModSeq) throws ServiceException {
lock.lock(false);
try {
if (!isTrackingSync()) {
throw ServiceException.FAILURE("not tracking sync", null);
} else if (lastSync < getSyncCutoff()) {
throw MailServiceException.TOMBSTONES_EXPIRED();
}
boolean success = false;
try {
beginReadTransaction("getTombstones", null);
TypedIdList tombstones = DbMailItem.readTombstones(this, lastSync, equalModSeq);
success = true;
return tombstones;
} finally {
endTransaction(success);
}
} finally {
lock.release();
}
}
use of com.zimbra.cs.mailbox.util.TypedIdList in project zm-mailbox by Zimbra.
the class Mailbox method listItemsForSync.
public TypedIdList listItemsForSync(OperationContext octxt, int folderId, MailItem.Type type, long messageSyncStart) throws ServiceException {
if (folderId == ID_AUTO_INCREMENT) {
return new TypedIdList();
}
boolean success = false;
try {
beginTransaction("listMessageItemsforgivenDate", octxt);
// if they specified a folder, make sure it actually exists
Folder folder = getFolderById(folderId);
TypedIdList ids = DbMailItem.listItems(folder, messageSyncStart, type, true, false);
success = true;
return ids;
} finally {
endTransaction(success);
}
}
use of com.zimbra.cs.mailbox.util.TypedIdList in project zm-mailbox by Zimbra.
the class Mailbox method listConvItemsForSync.
public TypedIdList listConvItemsForSync(OperationContext octxt, int folderId, MailItem.Type type, long messageSyncStart) throws ServiceException {
if (folderId == ID_AUTO_INCREMENT) {
return new TypedIdList();
}
boolean success = false;
try {
beginTransaction("listMessageItemsforgivenDate", octxt);
// if they specified a folder, make sure it actually exists
Folder folder = getFolderById(folderId);
TypedIdList ids = DbMailItem.listConvItems(folder, messageSyncStart, type, true, false);
success = true;
return ids;
} finally {
endTransaction(success);
}
}
use of com.zimbra.cs.mailbox.util.TypedIdList in project zm-mailbox by Zimbra.
the class CalendarUtils method migrateAppointmentsAndTasks.
/**
* Move appointments from TASKS type folders to Calendar folder.
* Also, move tasks from APPOINTMENT type folders to Tasks folder.
* @param mbox
* @throws ServiceException
*/
public static void migrateAppointmentsAndTasks(Mailbox mbox) throws ServiceException {
// get the list of folders.
List<Folder> folderList = mbox.getFolderList(null, SortBy.NONE);
for (Folder folder : folderList) {
int targetId;
TypedIdList idlist;
MailItem.Type type;
if (folder.getDefaultView() == MailItem.Type.APPOINTMENT) {
// get tasks from this folder and move them to TASKS folder.
idlist = mbox.listCalendarItemsForRange(null, MailItem.Type.TASK, -1, -1, folder.getId());
targetId = Mailbox.ID_FOLDER_TASKS;
type = MailItem.Type.TASK;
} else if (folder.getDefaultView() == MailItem.Type.TASK) {
// get appointments from this folder and move them to Calendar folder.
idlist = mbox.listCalendarItemsForRange(null, MailItem.Type.APPOINTMENT, -1, -1, folder.getId());
targetId = Mailbox.ID_FOLDER_CALENDAR;
type = MailItem.Type.APPOINTMENT;
} else {
continue;
}
if (!idlist.isEmpty()) {
if (type == MailItem.Type.APPOINTMENT)
ZimbraLog.calendar.info("Migrating " + idlist.size() + " Appointment(s) from '" + folder.getName() + "' to 'Calendar' folder for mailbox " + mbox.getId());
else
ZimbraLog.calendar.info("Migrating " + idlist.size() + " Task(s) from '" + folder.getName() + "' to 'Tasks' folder for mailbox " + mbox.getId());
int[] items = new int[idlist.size()];
int i = 0;
for (Integer id : idlist.getAllIds()) {
items[i] = id.intValue();
i++;
}
mbox.move(null, items, type, targetId, null);
}
}
}
Aggregations