use of com.zimbra.cs.index.MessageHit in project zm-mailbox by Zimbra.
the class ScheduleInbox method getAppointmentsByUids.
@Override
public java.util.Collection<DavResource> getAppointmentsByUids(DavContext ctxt, List<String> hrefs) throws ServiceException, DavException {
List<DavResource> result = new ArrayList<DavResource>();
if (!DavResource.isSchedulingEnabled()) {
return result;
}
Account target = null;
Provisioning prov = Provisioning.getInstance();
if (ctxt.getActingAsDelegateFor() != null) {
target = prov.getAccountByName(ctxt.getActingAsDelegateFor());
}
String query = "is:invite is:unread inid:" + getId() + " after:\"-1month\" ";
Mailbox mbox = getMailbox(ctxt);
ZimbraQueryResults zqr = null;
try {
zqr = mbox.index.search(ctxt.getOperationContext(), query, SEARCH_TYPES, SortBy.DATE_ASC, 100);
while (zqr.hasNext()) {
ZimbraHit hit = zqr.getNext();
if (hit instanceof MessageHit) {
Message msg = ((MessageHit) hit).getMessage();
if (target == null && msg.getCalendarIntendedFor() != null) {
continue;
}
if (!msg.isInvite() || !msg.hasCalendarItemInfos()) {
continue;
}
/* Bug 40567. hide replies to avoid them being deleted by CalDAV clients.
* TODO: An alternative approach would be to show them but when they are "deleted", flag them as
* absent from the scheduling inbox.
*/
if ("REPLY".equals(msg.getCalendarItemInfo(0).getInvite().getMethod())) {
continue;
}
if (target != null) {
if (msg.getCalendarIntendedFor() == null) {
continue;
}
Account apptRcpt = prov.getAccountByName(msg.getCalendarIntendedFor());
if (apptRcpt == null || !apptRcpt.getId().equals(target.getId())) {
continue;
}
}
DavResource rs = UrlNamespace.getResourceFromMailItem(ctxt, msg);
if (rs != null) {
String href = UrlNamespace.getRawResourceUrl(rs);
if (hrefs == null)
result.add(rs);
else {
boolean found = false;
for (String ref : hrefs) {
if (HttpUtil.urlUnescape(ref).equals(href)) {
result.add(rs);
found = true;
break;
}
}
if (!found)
result.add(new DavResource.InvalidResource(href, getOwner()));
}
}
}
}
} catch (Exception e) {
ZimbraLog.dav.error("can't search: uri=" + getUri(), e);
} finally {
Closeables.closeQuietly(zqr);
}
return result;
}
use of com.zimbra.cs.index.MessageHit in project zm-mailbox by Zimbra.
the class Search method putHits.
private void putHits(ZimbraSoapContext zsc, OperationContext octxt, Element el, ZimbraQueryResults results, SearchParams params) throws ServiceException {
if (params.getInlineRule() == ExpandResults.HITS || params.getInlineRule() == ExpandResults.FIRST_MSG || params.getInlineRule() == ExpandResults.HITS_OR_FIRST_MSG || params.getInlineRule() == ExpandResults.UNREAD || params.getInlineRule() == ExpandResults.UNREAD_FIRST || params.getInlineRule() == ExpandResults.U_OR_FIRST_MSG || params.getInlineRule() == ExpandResults.U1_OR_FIRST_MSG) {
// these are not valid values for Search (according to soap.txt)
params.setInlineRule(ExpandResults.NONE);
}
ResultsPager pager = ResultsPager.create(results, params);
if (params.getCursor() != null) {
if (params.getCursor().isIncludeOffset()) {
long offset = pager.getCursorOffset();
if (offset >= 0) {
el.addAttribute(MailConstants.A_QUERY_OFFSET, offset);
}
}
} else {
el.addAttribute(MailConstants.A_QUERY_OFFSET, params.getOffset());
}
SearchResponse resp = new SearchResponse(zsc, octxt, el, params);
resp.setIncludeMailbox(false);
resp.setSortOrder(pager.getSortOrder());
boolean expand;
ExpandResults expandValue = params.getInlineRule();
int hitNum = 0;
while (pager.hasNext() && resp.size() < params.getLimit()) {
hitNum++;
ZimbraHit hit = pager.getNextHit();
if (hit instanceof MessageHit) {
/*
* Determine whether or not to expand MessageHits.
* This logic used to be in SearchResponse.isInlineExpand, but was moved
* to the handler classes because in some cases
* the decision to expand any particular hit is dependent on
* other hits (see SearchConv)
*/
if (expandValue == ExpandResults.NONE) {
expand = false;
} else if (expandValue == ExpandResults.ALL) {
expand = true;
} else if (expandValue == ExpandResults.FIRST) {
expand = params.getOffset() > 0 ? false : hitNum == 1;
} else {
expand = expandValue.matches(hit.getParsedItemID());
}
resp.add(hit, expand);
} else {
resp.add(hit);
}
}
resp.addHasMore(pager.hasNext());
resp.add(results.getResultInfo());
}
Aggregations