use of com.zimbra.cs.account.Provisioning in project zm-mailbox by Zimbra.
the class BrowseWrapper method browseByType.
private List<DavResource> browseByType(DavContext ctxt) throws IOException, ServiceException {
ArrayList<DavResource> res = new ArrayList<DavResource>();
String user = ctxt.getUser();
Provisioning prov = Provisioning.getInstance();
Account account = prov.get(AccountBy.name, user);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
List<BrowseTerm> terms = mbox.browse(ctxt.getOperationContext(), Mailbox.BrowseBy.attachments, "", 0);
for (BrowseTerm term : terms) {
String ctype = term.getText();
int index = ctype.indexOf('/');
if (index != -1 || ctype.equals("message") || ctype.equals("none")) {
continue;
// the client still gets confused about having a slash in the
// path even after encoding
//ctype = ctype.substring(0,index) + "%2F" + ctype.substring(index+1);
}
res.add(new BrowseWrapper(generateUri(ctype), getOwner()));
}
res.add(new BrowseWrapper(generateUri("word"), getOwner()));
res.add(new BrowseWrapper(generateUri("excel"), getOwner()));
res.add(new BrowseWrapper(generateUri("ppt"), getOwner()));
res.add(new BrowseWrapper(generateUri("pdf"), getOwner()));
return res;
}
use of com.zimbra.cs.account.Provisioning in project zm-mailbox by Zimbra.
the class CalendarCollection method handlePost.
@Override
public void handlePost(DavContext ctxt) throws DavException, IOException, ServiceException {
Provisioning prov = Provisioning.getInstance();
DavResource rs = null;
try {
String user = ctxt.getUser();
Account account = prov.get(AccountBy.name, user);
if (account == null) {
// Anti-account name harvesting.
ZimbraLog.dav.info("Failing POST to Calendar - no such account '%s'", user);
throw new DavException("Request denied", HttpServletResponse.SC_NOT_FOUND, null);
}
List<Invite> invites = uploadToInvites(ctxt, account);
String uid = findEventUid(invites);
rs = createItemFromInvites(ctxt, account, uid + ".ics", invites, false);
if (rs.isNewlyCreated()) {
ctxt.getResponse().setHeader("Location", rs.getHref());
ctxt.setStatus(HttpServletResponse.SC_CREATED);
} else {
ctxt.setStatus(HttpServletResponse.SC_NO_CONTENT);
}
if (rs.hasEtag()) {
ctxt.getResponse().setHeader(DavProtocol.HEADER_ETAG, rs.getEtag());
ctxt.getResponse().setHeader(ETagHeaderFilter.ZIMBRA_ETAG_HEADER, rs.getEtag());
}
} catch (ServiceException e) {
if (e.getCode().equals(ServiceException.FORBIDDEN)) {
throw new DavException(e.getMessage(), HttpServletResponse.SC_FORBIDDEN, e);
} else {
throw new DavException("cannot create icalendar item", HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e);
}
}
}
use of com.zimbra.cs.account.Provisioning in project zm-mailbox by Zimbra.
the class DavResource method getTextContent.
protected String getTextContent(DavContext ctxt) throws IOException {
StringBuilder buf = new StringBuilder();
buf.append("Request\n\n");
buf.append("\tAuthenticated user:\t").append(ctxt.getAuthAccount().getName()).append("\n");
buf.append("\tCurrent date:\t\t").append(new Date(System.currentTimeMillis())).append("\n");
buf.append("\nResource\n\n");
buf.append("\tName:\t\t\t").append(getName()).append("\n");
buf.append("\tPath:\t\t\t").append(getUri()).append("\n");
buf.append("\tDate:\t\t\t").append(getLastModifiedDate()).append("\n");
try {
Provisioning prov = Provisioning.getInstance();
Account account = prov.get(Key.AccountBy.name, getOwner());
buf.append("\tOwner account name:\t").append(account.getName()).append("\n");
} catch (ServiceException se) {
}
buf.append("\nProperties\n\n");
buf.append(getPropertiesAsText(ctxt));
return buf.toString();
}
use of com.zimbra.cs.account.Provisioning in project zm-mailbox by Zimbra.
the class AclReports method getAclPrincipals.
private ArrayList<DavResource> getAclPrincipals(DavContext ctxt) throws DavException, ServiceException {
ArrayList<DavResource> ret = new ArrayList<DavResource>();
DavResource res = ctxt.getRequestedResource();
if (!(res instanceof MailItemResource))
return ret;
List<Ace> aces = ((MailItemResource) res).getAce(ctxt);
Provisioning prov = Provisioning.getInstance();
for (Ace ace : aces) {
if (ace.hasHref()) {
Account acct = prov.get(Key.AccountBy.id, ace.getZimbraId());
if (acct != null)
ret.add(UrlNamespace.getPrincipal(ctxt, acct));
}
}
return ret;
}
use of com.zimbra.cs.account.Provisioning in project zm-mailbox by Zimbra.
the class SearchWrapper method getChildren.
@Override
public Collection<DavResource> getChildren(DavContext ctxt) {
ArrayList<DavResource> children = new ArrayList<DavResource>();
String user = ctxt.getUser();
Provisioning prov = Provisioning.getInstance();
ZimbraQueryResults zqr = null;
try {
Account account = prov.get(AccountBy.name, user);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
SearchParams params = new SearchParams();
params.setQueryString(mQuery.toString());
params.setTypes(SEARCH_TYPES);
params.setSortBy(SortBy.NAME_ASC);
params.setFetchMode(SearchParams.Fetch.NORMAL);
params.setPrefetch(true);
params.setChunkSize(SEARCH_LIMIT);
zqr = mbox.index.search(SoapProtocol.Soap12, ctxt.getOperationContext(), params);
while (zqr.hasNext()) {
ZimbraHit hit = zqr.getNext();
if (hit instanceof MessageHit)
addAttachmentResources((MessageHit) hit, children);
}
} catch (Exception e) {
ZimbraLog.dav.error("can't search: uri=" + getUri(), e);
} finally {
Closeables.closeQuietly(zqr);
}
return children;
}
Aggregations