use of com.zimbra.cs.mailbox.CalendarItem in project zm-mailbox by Zimbra.
the class GetICal method handle.
/* (non-Javadoc)
* @see com.zimbra.soap.DocumentHandler#handle(org.dom4j.Element, java.util.Map)
*/
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Account authAccount = getAuthenticatedAccount(zsc);
Mailbox mbx = getRequestedMailbox(zsc);
OperationContext octxt = getOperationContext(zsc, context);
String iidStr = request.getAttribute(MailConstants.A_ID, null);
long rangeStart = request.getAttributeLong(MailConstants.A_CAL_START_TIME, -1);
long rangeEnd = request.getAttributeLong(MailConstants.A_CAL_END_TIME, -1);
// int compNum = (int)request.getAttributeLong(MailService.A_CAL_COMPONENT_NUM);
int compNum = 0;
Browser browser = HttpUtil.guessBrowser(zsc.getUserAgent());
boolean useOutlookCompatMode = Browser.IE.equals(browser);
try {
try {
ByteArrayOutputStream buf = new ByteArrayOutputStream();
OutputStreamWriter wout = new OutputStreamWriter(buf);
ZVCalendar cal = null;
ItemId iid = iidStr != null ? new ItemId(iidStr, zsc) : null;
if (iid != null) {
CalendarItem calItem = mbx.getCalendarItemById(octxt, iid.getId());
if (calItem == null) {
throw MailServiceException.NO_SUCH_CALITEM(iid.toString(), "Could not find calendar item");
}
Invite inv = calItem.getInvite(iid.getSubpartId(), compNum);
if (inv == null) {
throw MailServiceException.INVITE_OUT_OF_DATE(iid.toString());
}
boolean allowPrivateAccess = calItem.allowPrivateAccess(authAccount, zsc.isUsingAdminPrivileges());
cal = inv.newToICalendar(useOutlookCompatMode, allowPrivateAccess);
cal.toICalendar(wout);
} else {
mbx.writeICalendarForRange(wout, octxt, rangeStart, rangeEnd, Mailbox.ID_FOLDER_CALENDAR, useOutlookCompatMode, false, false);
}
wout.flush();
Element response = getResponseElement(zsc);
Element icalElt = response.addElement(MailConstants.E_CAL_ICAL);
if (iid != null)
icalElt.addAttribute(MailConstants.A_ID, new ItemIdFormatter(zsc).formatItemId(iid));
icalElt.addText(buf.toString());
return response;
} catch (MailServiceException.NoSuchItemException e) {
throw ServiceException.FAILURE("Error could get default invite for Invite: " + iidStr + "-" + compNum, e);
} catch (IOException e) {
throw ServiceException.FAILURE("IO Exception while outputing Calendar for Invite: " + iidStr + "-" + compNum, e);
}
} catch (MailServiceException.NoSuchItemException e) {
throw ServiceException.FAILURE("No Such Invite Message: " + iidStr, e);
}
}
use of com.zimbra.cs.mailbox.CalendarItem in project zm-mailbox by Zimbra.
the class ForwardCalendarItem method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Account senderAcct = getZDesktopSafeAuthenticatedAccount(zsc);
Mailbox mbox = getRequestedMailbox(zsc);
OperationContext octxt = getOperationContext(zsc, context);
// proxy handling
ItemId iid = new ItemId(request.getAttribute(MailConstants.A_ID), zsc);
if (!iid.belongsTo(getRequestedAccount(zsc))) {
// Proxy it.
return proxyRequest(request, context, iid.getAccountId());
}
Element msgElem = request.getElement(MailConstants.E_MSG);
ParseMimeMessage.MimeMessageData parsedMessageData = new ParseMimeMessage.MimeMessageData();
MimeMessage mm = ParseMimeMessage.parseMimeMsgSoap(zsc, octxt, mbox, msgElem, null, ParseMimeMessage.NO_INV_ALLOWED_PARSER, parsedMessageData);
Element exc = request.getOptionalElement(MailConstants.E_CAL_EXCEPTION_ID);
Element tzElem = request.getOptionalElement(MailConstants.E_CAL_TZ);
CalendarItem calItem = mbox.getCalendarItemById(octxt, iid.getId());
if (calItem == null) {
throw MailServiceException.NO_SUCH_CALITEM(iid.toString(), "Could not find calendar item");
}
RecurId rid = null;
if (exc != null) {
TimeZoneMap tzmap = calItem.getTimeZoneMap();
ICalTimeZone tz = null;
if (tzElem != null) {
tz = CalendarUtils.parseTzElement(tzElem);
tzmap.add(tz);
}
ParsedDateTime exceptDt = CalendarUtils.parseDateTime(exc, tzmap);
rid = new RecurId(exceptDt, RecurId.RANGE_NONE);
}
Pair<List<MimeMessage>, List<MimeMessage>> mimePair = forwardCalItem(mbox, octxt, calItem, rid, mm, senderAcct);
sendForwardMessages(mbox, octxt, mimePair);
Element response = getResponseElement(zsc);
return response;
}
use of com.zimbra.cs.mailbox.CalendarItem in project zm-mailbox by Zimbra.
the class GetRecur method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Mailbox mbox = getRequestedMailbox(zsc);
OperationContext octxt = getOperationContext(zsc, context);
ItemId iid = new ItemId(request.getAttribute(MailConstants.A_ID), zsc);
Element response = getResponseElement(zsc);
CalendarItem calItem = mbox.getCalendarItemById(octxt, iid.getId());
ToXML.encodeCalendarItemRecur(response, calItem);
return response;
}
use of com.zimbra.cs.mailbox.CalendarItem in project zm-mailbox by Zimbra.
the class CalDavDataImport method createTargetUrl.
private String createTargetUrl(MailItem mitem) throws ServiceException {
DataSourceItem folder = DbDataSource.getMapping(getDataSource(), mitem.getFolderId());
String url = folder.remoteId;
switch(mitem.getType()) {
case APPOINTMENT:
url += ((CalendarItem) mitem).getUid() + ".ics";
break;
default:
String name = mitem.getName();
if (name != null)
url += name;
else
url += mitem.getSubject();
break;
}
return url;
}
use of com.zimbra.cs.mailbox.CalendarItem in project zm-mailbox by Zimbra.
the class CalDavDataImport method pushModify.
private void pushModify(MailItem mitem) throws ServiceException, IOException, DavException, HttpException {
int itemId = mitem.getId();
DataSource ds = getDataSource();
DataSourceItem item = DbDataSource.getMapping(ds, itemId);
boolean isCreate = false;
if (item.remoteId == null) {
// new item
item.md = new Metadata();
item.md.put(METADATA_KEY_TYPE, METADATA_TYPE_APPOINTMENT);
item.remoteId = createTargetUrl(mitem);
item.folderId = mitem.getFolderId();
isCreate = true;
}
String type = item.md.get(METADATA_KEY_TYPE);
if (METADATA_TYPE_FOLDER.equals(type)) {
if (mitem.getType() != MailItem.Type.FOLDER) {
ZimbraLog.datasource.warn("pushModify: item type doesn't match in metadata for item %d", itemId);
return;
}
// detect and push rename
} else if (METADATA_TYPE_APPOINTMENT.equals(type)) {
if (mitem.getType() != MailItem.Type.APPOINTMENT) {
ZimbraLog.datasource.warn("pushModify: item type doesn't match in metadata for item %d", itemId);
return;
}
// push modified appt
ZimbraLog.datasource.debug("pushModify: sending appointment %s", item.remoteId);
String etag = putAppointment((CalendarItem) mitem, item);
if (etag == null) {
Appointment appt = mClient.getEtag(item.remoteId);
etag = appt.etag;
}
item.md.put(METADATA_KEY_ETAG, etag);
if (isCreate) {
DbDataSource.addMapping(ds, item);
} else {
DbDataSource.updateMapping(ds, item);
}
} else {
ZimbraLog.datasource.warn("pushModify: unrecognized item type for %d: %s", itemId, type);
return;
}
}
Aggregations