Search in sources :

Example 26 with CalendarItem

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);
    }
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) ItemIdFormatter(com.zimbra.cs.service.util.ItemIdFormatter) Element(com.zimbra.common.soap.Element) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ItemId(com.zimbra.cs.service.util.ItemId) CalendarItem(com.zimbra.cs.mailbox.CalendarItem) ZVCalendar(com.zimbra.common.calendar.ZCalendar.ZVCalendar) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) OutputStreamWriter(java.io.OutputStreamWriter) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) Invite(com.zimbra.cs.mailbox.calendar.Invite) Browser(com.zimbra.common.util.HttpUtil.Browser)

Example 27 with CalendarItem

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;
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) Element(com.zimbra.common.soap.Element) RecurId(com.zimbra.cs.mailbox.calendar.RecurId) ItemId(com.zimbra.cs.service.util.ItemId) CalendarItem(com.zimbra.cs.mailbox.CalendarItem) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) TimeZoneMap(com.zimbra.common.calendar.TimeZoneMap) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ICalTimeZone(com.zimbra.common.calendar.ICalTimeZone)

Example 28 with CalendarItem

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;
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) CalendarItem(com.zimbra.cs.mailbox.CalendarItem) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) ItemId(com.zimbra.cs.service.util.ItemId)

Example 29 with CalendarItem

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;
}
Also used : CalendarItem(com.zimbra.cs.mailbox.CalendarItem) DataSourceItem(com.zimbra.cs.db.DbDataSource.DataSourceItem)

Example 30 with CalendarItem

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;
    }
}
Also used : CalendarItem(com.zimbra.cs.mailbox.CalendarItem) Appointment(com.zimbra.cs.dav.client.CalDavClient.Appointment) Metadata(com.zimbra.cs.mailbox.Metadata) DataSourceItem(com.zimbra.cs.db.DbDataSource.DataSourceItem) DbDataSource(com.zimbra.cs.db.DbDataSource) DataSource(com.zimbra.cs.account.DataSource)

Aggregations

CalendarItem (com.zimbra.cs.mailbox.CalendarItem)56 Mailbox (com.zimbra.cs.mailbox.Mailbox)36 Element (com.zimbra.common.soap.Element)27 OperationContext (com.zimbra.cs.mailbox.OperationContext)24 Invite (com.zimbra.cs.mailbox.calendar.Invite)23 ItemId (com.zimbra.cs.service.util.ItemId)22 Account (com.zimbra.cs.account.Account)19 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)17 ServiceException (com.zimbra.common.service.ServiceException)15 MailItem (com.zimbra.cs.mailbox.MailItem)14 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)13 Message (com.zimbra.cs.mailbox.Message)12 ItemIdFormatter (com.zimbra.cs.service.util.ItemIdFormatter)11 Folder (com.zimbra.cs.mailbox.Folder)9 RecurId (com.zimbra.cs.mailbox.calendar.RecurId)9 Appointment (com.zimbra.cs.mailbox.Appointment)8 ArrayList (java.util.ArrayList)8 MimeMessage (javax.mail.internet.MimeMessage)8 ParsedDateTime (com.zimbra.common.calendar.ParsedDateTime)7 TimeZoneMap (com.zimbra.common.calendar.TimeZoneMap)5