use of com.zimbra.cs.mailbox.MailItem 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.mailbox.MailItem in project zm-mailbox by Zimbra.
the class ZimbraHit method getModifiedSequence.
public int getModifiedSequence() throws ServiceException {
if (cachedModseq < 0) {
MailItem item = getMailItem();
cachedModseq = item != null ? item.getModifiedSequence() : 0;
}
return cachedModseq;
}
use of com.zimbra.cs.mailbox.MailItem 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.mailbox.MailItem in project zm-mailbox by Zimbra.
the class ExportAndDeleteItems method handle.
@Override
public Element handle(Element requst, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
checkRight(zsc, context, null, AdminRight.PR_SYSTEM_ADMIN_ONLY);
// Parse request.
ExportAndDeleteItemsRequest req = JaxbUtil.elementToJaxb(requst);
ExportAndDeleteMailboxSpec mailbox = req.getMailbox();
if (mailbox == null) {
throw ServiceException.INVALID_REQUEST("empty mbox id", null);
}
Mailbox mbox = MailboxManager.getInstance().getMailboxById(mailbox.getId());
Multimap<Integer, Integer> idRevs = HashMultimap.create();
for (ExportAndDeleteItemSpec item : mailbox.getItems()) {
idRevs.put(item.getId(), item.getVersion());
}
String dirPath = req.getExportDir();
String prefix = req.getExportFilenamePrefix();
// Lock the mailbox, to make sure that another thread doesn't modify the items we're exporting/deleting.
mbox.lock.lock();
try {
DbConnection conn = null;
try {
conn = DbPool.getConnection();
if (dirPath != null) {
File exportDir = new File(dirPath);
if (!exportDir.isDirectory()) {
DbPool.quietClose(conn);
throw ServiceException.INVALID_REQUEST(dirPath + " is not a directory", null);
}
String filePath = makePath(dirPath, DbMailItem.TABLE_MAIL_ITEM, prefix);
export(conn, mbox, DbMailItem.TABLE_MAIL_ITEM, "id", idRevs, filePath);
filePath = makePath(dirPath, DbMailItem.TABLE_MAIL_ITEM_DUMPSTER, prefix);
export(conn, mbox, DbMailItem.TABLE_MAIL_ITEM_DUMPSTER, "id", idRevs, filePath);
filePath = makePath(dirPath, DbMailItem.TABLE_REVISION, prefix);
export(conn, mbox, DbMailItem.TABLE_REVISION, "item_id", idRevs, filePath);
filePath = makePath(dirPath, DbMailItem.TABLE_REVISION_DUMPSTER, prefix);
export(conn, mbox, DbMailItem.TABLE_REVISION_DUMPSTER, "item_id", idRevs, filePath);
filePath = makePath(dirPath, DbMailItem.TABLE_APPOINTMENT, prefix);
export(conn, mbox, DbMailItem.TABLE_APPOINTMENT, "item_id", idRevs, filePath);
filePath = makePath(dirPath, DbMailItem.TABLE_APPOINTMENT_DUMPSTER, prefix);
export(conn, mbox, DbMailItem.TABLE_APPOINTMENT_DUMPSTER, "item_id", idRevs, filePath);
}
// delete item from mail_item and revision table
for (Integer itemId : idRevs.keySet()) {
Collection<Integer> revs = idRevs.get(itemId);
for (int rev : revs) {
if (rev == 0) {
// delete all revisions to make sure we delete all blobs
List<MailItem> list = null;
try {
list = mbox.getAllRevisions(null, itemId, MailItem.Type.UNKNOWN);
} catch (NoSuchItemException ex) {
// exception happens when we try to delete a mail_item which is already in mail_item_dumpster
continue;
}
for (MailItem item : list) {
if (item.getType() == MailItem.Type.DOCUMENT) {
mbox.purgeRevision(null, itemId, item.getVersion(), false);
}
}
mbox.delete(null, itemId, MailItem.Type.UNKNOWN, null);
break;
} else if (!revs.contains(0)) {
try {
mbox.purgeRevision(null, itemId, rev, false);
} catch (NoSuchItemException ex) {
// exception happens when we try to delete a revision which is already in revision_dumpster
continue;
}
}
}
}
// Delete items from mail_item_dumpster & revision_dumpster tables just
// incase moved to dumpster tables
DbBlobConsistency.delete(conn, mbox, idRevs);
} finally {
conn.commit();
DbPool.quietClose(conn);
}
} finally {
mbox.lock.release();
}
return zsc.createElement(AdminConstants.EXPORT_AND_DELETE_ITEMS_RESPONSE);
}
use of com.zimbra.cs.mailbox.MailItem in project zm-mailbox by Zimbra.
the class GetMsg method getMsgs.
public static List<Message> getMsgs(OperationContext octxt, Mailbox mbox, List<Integer> iids, boolean read) throws ServiceException {
int i = 0;
int[] msgIdArray = new int[iids.size()];
for (int id : iids) {
msgIdArray[i++] = id;
}
List<Message> toRet = new ArrayList<Message>(msgIdArray.length);
for (MailItem item : mbox.getItemById(octxt, msgIdArray, MailItem.Type.MESSAGE)) {
toRet.add((Message) item);
if (read && item.isUnread() && !RedoLogProvider.getInstance().isSlave()) {
mbox.alterTag(octxt, item.getId(), MailItem.Type.MESSAGE, Flag.FlagInfo.UNREAD, false, null);
}
}
return toRet;
}
Aggregations