Search in sources :

Example 26 with ZVCalendar

use of com.zimbra.common.calendar.ZCalendar.ZVCalendar in project zm-mailbox by Zimbra.

the class CalendarUtils method parseInviteForAddInvite.

static ParseMimeMessage.InviteParserResult parseInviteForAddInvite(Account account, MailItem.Type type, Element inviteElem, TimeZoneMap tzMap) throws ServiceException {
    if (tzMap == null)
        tzMap = new TimeZoneMap(Util.getAccountTimeZone(account));
    Invite inv = new Invite(ICalTok.PUBLISH.toString(), tzMap, false);
    CalendarUtils.parseInviteElementCommon(account, type, inviteElem, inv, true, true);
    String uid = inv.getUid();
    if (uid == null || uid.length() == 0)
        throw ServiceException.INVALID_REQUEST("Missing uid in an add invite", null);
    // DTSTAMP
    if (inv.getDTStamp() == 0) {
        //zdsync
        inv.setDtStamp(new Date().getTime());
    }
    ZVCalendar iCal = inv.newToICalendar(true);
    String summaryStr = inv.getName() != null ? inv.getName() : "";
    ParseMimeMessage.InviteParserResult toRet = new ParseMimeMessage.InviteParserResult();
    toRet.mCal = iCal;
    toRet.mUid = inv.getUid();
    toRet.mSummary = summaryStr;
    toRet.mInvite = inv;
    return toRet;
}
Also used : ZVCalendar(com.zimbra.common.calendar.ZCalendar.ZVCalendar) TimeZoneMap(com.zimbra.common.calendar.TimeZoneMap) Invite(com.zimbra.cs.mailbox.calendar.Invite) Date(java.util.Date)

Example 27 with ZVCalendar

use of com.zimbra.common.calendar.ZCalendar.ZVCalendar in project zm-mailbox by Zimbra.

the class CalendarUtils method parseInviteForCreate.

/**
     * Parse an <inv> element
     *
     * @param account
     * @param inviteElem
     * @param tzMap
     *            TimeZoneMap of invite we might want to refer to (eg we are an
     *            Exception to it)
     * @param uid
     * @param recurrenceIdAllowed
     * @return
     * @throws ServiceException
     */
static ParseMimeMessage.InviteParserResult parseInviteForCreate(Account account, MailItem.Type type, Element inviteElem, TimeZoneMap tzMap, String uid, boolean recurrenceIdAllowed, boolean recurAllowed) throws ServiceException {
    if (tzMap == null) {
        tzMap = new TimeZoneMap(Util.getAccountTimeZone(account));
    }
    Invite create = new Invite(ICalTok.PUBLISH.toString(), tzMap, false);
    create.setSentByMe(true);
    CalendarUtils.parseInviteElementCommon(account, type, inviteElem, create, recurrenceIdAllowed, recurAllowed);
    // DTSTAMP
    if (create.getDTStamp() == 0) {
        //zdsync
        create.setDtStamp(new Date().getTime());
    }
    // UID
    if (uid != null && uid.length() > 0) {
        create.setUid(uid);
    } else {
        String uidParsed = create.getUid();
        if (uidParsed == null || uidParsed.length() == 0)
            create.setUid(LdapUtil.generateUUID());
    }
    ZVCalendar iCal = create.newToICalendar(true);
    String summaryStr = create.getName() != null ? create.getName() : "";
    ParseMimeMessage.InviteParserResult toRet = new ParseMimeMessage.InviteParserResult();
    toRet.mCal = iCal;
    toRet.mUid = create.getUid();
    toRet.mSummary = summaryStr;
    toRet.mInvite = create;
    return toRet;
}
Also used : ZVCalendar(com.zimbra.common.calendar.ZCalendar.ZVCalendar) TimeZoneMap(com.zimbra.common.calendar.TimeZoneMap) Invite(com.zimbra.cs.mailbox.calendar.Invite) Date(java.util.Date)

Example 28 with ZVCalendar

use of com.zimbra.common.calendar.ZCalendar.ZVCalendar in project zm-mailbox by Zimbra.

the class CalendarUtils method parseInviteForModify.

/**
     * Parse an <inv> element in a Modify context -- existing UID, etc
     *
     * @param inviteElem
     * @param oldInv
     *            is the Default Invite of the appointment we are modifying
     * @return
     * @throws ServiceException
     */
static ParseMimeMessage.InviteParserResult parseInviteForModify(Account account, MailItem.Type type, Element inviteElem, Invite oldInv, Invite seriesInv, List<ZAttendee> attendeesAdded, List<ZAttendee> attendeesToCancel, boolean recurAllowed) throws ServiceException {
    Invite mod = new Invite(ICalTok.PUBLISH.toString(), oldInv.getTimeZoneMap(), false);
    mod.setSentByMe(true);
    CalendarUtils.parseInviteElementCommon(account, type, inviteElem, mod, oldInv.hasRecurId(), recurAllowed);
    // UID
    mod.setUid(oldInv.getUid());
    attendeesToCancel.addAll(getRemovedAttendees(oldInv.getAttendees(), mod.getAttendees(), true, account));
    // reverse of who's being canceled
    attendeesAdded.addAll(getRemovedAttendees(mod.getAttendees(), oldInv.getAttendees(), false, account));
    // SEQUENCE and DTSTAMP
    if (mod.isOrganizer()) {
        // Set sequence to the max of 1) what the modifying client specified (if any),
        // 2) current sequence + 1, and 3) current sequence of the series, if we're modifying
        // an exception instance.  This is to satisfy Outlook's requirement that an up-to-date
        // exception instance should have a sequence greater than or equal to the series sequence.
        // (bug 19111)
        int seriesSeq = seriesInv != null ? seriesInv.getSeqNo() : 0;
        int newSeq = Math.max(Math.max(mod.getSeqNo(), oldInv.getSeqNo() + 1), seriesSeq);
        // the update takes precedence over cancel in case someone receives both, regardless of delivery order. (bug 56642)
        if (!attendeesToCancel.isEmpty())
            ++newSeq;
        mod.setSeqNo(newSeq);
        mod.setDtStamp(new Date().getTime());
    } else {
        // If attendee is modifying his copy, preserve SEQUENCE and DTSTAMP.
        // If these were advanced, existing replies will get invalidated and
        // we don't want that.
        mod.setSeqNo(oldInv.getSeqNo());
        mod.setDtStamp(oldInv.getDTStamp());
    }
    if (oldInv.hasRecurId()) {
        mod.setRecurId(oldInv.getRecurId());
    }
    // change tracking
    String changes = parseInviteChanges(inviteElem);
    if (changes != null) {
        // Set the changes as x-prop in the serialized iCalendar object, but not to the parsed Invite object.
        mod.addXProp(new ZProperty(ICalTok.X_ZIMBRA_CHANGES, changes));
    }
    ZVCalendar iCal = mod.newToICalendar(true);
    // Don't set the changes x-prop in the parsed Invite.
    mod.removeXProp(ICalTok.X_ZIMBRA_CHANGES.toString());
    String summaryStr = "";
    if (mod.getName() != null) {
        summaryStr = mod.getName();
    }
    ParseMimeMessage.InviteParserResult toRet = new ParseMimeMessage.InviteParserResult();
    toRet.mCal = iCal;
    toRet.mUid = mod.getUid();
    toRet.mSummary = summaryStr;
    toRet.mInvite = mod;
    return toRet;
}
Also used : ZVCalendar(com.zimbra.common.calendar.ZCalendar.ZVCalendar) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) Invite(com.zimbra.cs.mailbox.calendar.Invite) Date(java.util.Date)

Example 29 with ZVCalendar

use of com.zimbra.common.calendar.ZCalendar.ZVCalendar in project zm-mailbox by Zimbra.

the class CancelCalendarItem method cancelInstance.

void cancelInstance(ZimbraSoapContext zsc, OperationContext octxt, Element msgElem, Account acct, Mailbox mbox, CalendarItem calItem, Invite inv, RecurId recurId, List<ZAttendee> toNotify, MailSendQueue sendQueue) throws ServiceException {
    boolean onBehalfOf = isOnBehalfOfRequest(zsc);
    Account authAcct = getAuthenticatedAccount(zsc);
    Locale locale = !onBehalfOf ? acct.getLocale() : authAcct.getLocale();
    String text = L10nUtil.getMessage(MsgKey.calendarCancelAppointmentInstance, locale);
    Invite cancelInvite = CalendarUtils.buildCancelInstanceCalendar(acct, authAcct, zsc.isUsingAdminPrivileges(), onBehalfOf, calItem, inv, text, recurId);
    CalSendData dat = new CalSendData();
    dat.mOrigId = new ItemId(mbox, inv.getMailItemId());
    dat.mReplyType = MailSender.MSGTYPE_REPLY;
    dat.mInvite = cancelInvite;
    ZVCalendar iCal = dat.mInvite.newToICalendar(true);
    // did they specify a custom <m> message?  If so, then we don't have to build one...
    if (msgElem != null) {
        String desc = ParseMimeMessage.getTextPlainContent(msgElem);
        String html = ParseMimeMessage.getTextHtmlContent(msgElem);
        iCal.addDescription(desc, html);
        MimeBodyPart[] mbps = new MimeBodyPart[1];
        mbps[0] = CalendarMailSender.makeICalIntoMimePart(iCal);
        // the <inv> element is *NOT* allowed -- we always build it manually
        // based on the params to the <CancelCalendarItem> and stick it in the
        // mbps (additionalParts) parameter...
        dat.mMm = ParseMimeMessage.parseMimeMsgSoap(zsc, octxt, mbox, msgElem, mbps, ParseMimeMessage.NO_INV_ALLOWED_PARSER, dat);
    } else {
        List<Address> rcpts = CalendarMailSender.toListFromAttendees(toNotify);
        dat.mMm = CalendarMailSender.createCancelMessage(acct, authAcct, zsc.isUsingAdminPrivileges(), onBehalfOf, rcpts, calItem, cancelInvite, text, iCal);
    }
    doRecipientsCheck(dat, inv.isOrganizer(), mbox);
    sendCalendarCancelMessage(zsc, octxt, calItem.getFolderId(), acct, mbox, dat, true, sendQueue);
}
Also used : Locale(java.util.Locale) Account(com.zimbra.cs.account.Account) ZVCalendar(com.zimbra.common.calendar.ZCalendar.ZVCalendar) Address(javax.mail.Address) MimeBodyPart(javax.mail.internet.MimeBodyPart) ItemId(com.zimbra.cs.service.util.ItemId) Invite(com.zimbra.cs.mailbox.calendar.Invite)

Example 30 with ZVCalendar

use of com.zimbra.common.calendar.ZCalendar.ZVCalendar in project zm-mailbox by Zimbra.

the class CancelCalendarItem method cancelInvite.

protected void cancelInvite(ZimbraSoapContext zsc, OperationContext octxt, Element msgElem, Account acct, Mailbox mbox, CalendarItem calItem, Invite inv, MailSendQueue sendQueue) throws ServiceException {
    boolean onBehalfOf = isOnBehalfOfRequest(zsc);
    Account authAcct = getAuthenticatedAccount(zsc);
    Locale locale = !onBehalfOf ? acct.getLocale() : authAcct.getLocale();
    String text = L10nUtil.getMessage(MsgKey.calendarCancelAppointment, locale);
    CalSendData csd = new CalSendData();
    csd.mOrigId = new ItemId(mbox, inv.getMailItemId());
    csd.mReplyType = MailSender.MSGTYPE_REPLY;
    csd.mInvite = CalendarUtils.buildCancelInviteCalendar(acct, authAcct, zsc.isUsingAdminPrivileges(), onBehalfOf, calItem, inv, text);
    ZVCalendar iCal = csd.mInvite.newToICalendar(true);
    // did they specify a custom <m> message?  If so, then we don't have to build one...
    if (msgElem != null) {
        String desc = ParseMimeMessage.getTextPlainContent(msgElem);
        String html = ParseMimeMessage.getTextHtmlContent(msgElem);
        iCal.addDescription(desc, html);
        MimeBodyPart[] mbps = new MimeBodyPart[1];
        mbps[0] = CalendarMailSender.makeICalIntoMimePart(iCal);
        // the <inv> element is *NOT* allowed -- we always build it manually
        // based on the params to the <CancelCalendarItem> and stick it in the
        // mbps (additionalParts) parameter...
        csd.mMm = ParseMimeMessage.parseMimeMsgSoap(zsc, octxt, mbox, msgElem, mbps, ParseMimeMessage.NO_INV_ALLOWED_PARSER, csd);
    } else {
        List<Address> rcpts;
        if (inv.isOrganizer())
            rcpts = CalendarMailSender.toListFromAttendees(inv.getAttendees());
        else
            rcpts = new ArrayList<Address>(0);
        csd.mMm = CalendarMailSender.createCancelMessage(acct, authAcct, zsc.isUsingAdminPrivileges(), onBehalfOf, rcpts, calItem, inv, text, iCal);
    }
    doRecipientsCheck(csd, inv.isOrganizer(), mbox);
    sendCalendarCancelMessage(zsc, octxt, calItem.getFolderId(), acct, mbox, csd, true, sendQueue);
}
Also used : Locale(java.util.Locale) Account(com.zimbra.cs.account.Account) ZVCalendar(com.zimbra.common.calendar.ZCalendar.ZVCalendar) Address(javax.mail.Address) ArrayList(java.util.ArrayList) MimeBodyPart(javax.mail.internet.MimeBodyPart) ItemId(com.zimbra.cs.service.util.ItemId)

Aggregations

ZVCalendar (com.zimbra.common.calendar.ZCalendar.ZVCalendar)47 Invite (com.zimbra.cs.mailbox.calendar.Invite)21 ZComponent (com.zimbra.common.calendar.ZCalendar.ZComponent)16 Account (com.zimbra.cs.account.Account)12 ICalTimeZone (com.zimbra.common.calendar.ICalTimeZone)10 ZProperty (com.zimbra.common.calendar.ZCalendar.ZProperty)10 IOException (java.io.IOException)10 MimeMessage (javax.mail.internet.MimeMessage)10 ParsedDateTime (com.zimbra.common.calendar.ParsedDateTime)9 ItemId (com.zimbra.cs.service.util.ItemId)9 TimeZoneMap (com.zimbra.common.calendar.TimeZoneMap)8 InputStream (java.io.InputStream)8 ArrayList (java.util.ArrayList)8 ServiceException (com.zimbra.common.service.ServiceException)7 Mailbox (com.zimbra.cs.mailbox.Mailbox)7 ByteArrayInputStream (java.io.ByteArrayInputStream)7 Locale (java.util.Locale)7 Test (org.junit.Test)7 Element (com.zimbra.common.soap.Element)6 Date (java.util.Date)6