Search in sources :

Example 6 with ZVCalendar

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

the class CalendarRequest method notifyRemovedAttendees.

protected static void notifyRemovedAttendees(ZimbraSoapContext zsc, OperationContext octxt, Account acct, Mailbox mbox, CalendarItem calItem, Invite invToCancel, List<ZAttendee> removedAttendees, MailSendQueue sendQueue) throws ServiceException {
    boolean onBehalfOf = isOnBehalfOfRequest(zsc);
    Account authAcct = getAuthenticatedAccount(zsc);
    Locale locale = !onBehalfOf ? acct.getLocale() : authAcct.getLocale();
    CalSendData dat = new CalSendData();
    dat.mOrigId = new ItemId(mbox, invToCancel.getMailItemId());
    dat.mReplyType = MailSender.MSGTYPE_REPLY;
    String text = L10nUtil.getMessage(MsgKey.calendarCancelRemovedFromAttendeeList, locale);
    if (ZimbraLog.calendar.isDebugEnabled()) {
        StringBuilder sb = new StringBuilder("Sending cancellation message for \"");
        sb.append(invToCancel.getName()).append("\" to ");
        sb.append(getAttendeesAddressList(removedAttendees));
        ZimbraLog.calendar.debug(sb.toString());
    }
    List<Address> rcpts = CalendarMailSender.toListFromAttendees(removedAttendees);
    try {
        dat.mInvite = CalendarUtils.buildCancelInviteCalendar(acct, authAcct, zsc.isUsingAdminPrivileges(), onBehalfOf, calItem, invToCancel, text, removedAttendees);
        ZVCalendar cal = dat.mInvite.newToICalendar(true);
        dat.mMm = CalendarMailSender.createCancelMessage(acct, authAcct, zsc.isUsingAdminPrivileges(), onBehalfOf, rcpts, calItem, invToCancel, text, cal);
        // If we are sending this cancellation to other people, then we MUST be the organizer!
        if (!dat.mInvite.isOrganizer() && rcpts != null && !rcpts.isEmpty())
            throw MailServiceException.MUST_BE_ORGANIZER("updateRemovedInvitees");
        sendCalendarCancelMessage(zsc, octxt, calItem.getFolderId(), acct, mbox, dat, false, sendQueue);
    } catch (ServiceException ex) {
        String to = getAttendeesAddressList(removedAttendees);
        ZimbraLog.calendar.debug("Could not inform attendees (" + to + ") that they were removed from meeting " + invToCancel.toString() + " b/c of exception: " + ex.toString());
    }
}
Also used : Locale(java.util.Locale) Account(com.zimbra.cs.account.Account) ZVCalendar(com.zimbra.common.calendar.ZCalendar.ZVCalendar) Address(javax.mail.Address) InternetAddress(javax.mail.internet.InternetAddress) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) ItemId(com.zimbra.cs.service.util.ItemId)

Example 7 with ZVCalendar

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

the class CalendarUtils method parseInviteForDeclineCounter.

static ParseMimeMessage.InviteParserResult parseInviteForDeclineCounter(Account account, MailItem.Type type, Element inviteElem) throws ServiceException {
    TimeZoneMap tzMap = new TimeZoneMap(Util.getAccountTimeZone(account));
    Invite inv = new Invite(ICalTok.DECLINECOUNTER.toString(), tzMap, false);
    CalendarUtils.parseInviteElementCommon(account, type, inviteElem, inv, true, true);
    // UID
    String uid = inv.getUid();
    if (uid == null || uid.length() == 0)
        throw ServiceException.INVALID_REQUEST("Missing uid in a decline counter invite", null);
    // ORGANIZER
    if (!inv.hasOrganizer())
        throw ServiceException.INVALID_REQUEST("Missing organizer in a decline counter invite", null);
    // DTSTAMP
    if (inv.getDTStamp() == 0) {
        //zdsync
        inv.setDtStamp(new Date().getTime());
    }
    inv.setLocalOnly(false);
    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 8 with ZVCalendar

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

the class CalendarUtils method parseInviteForCounter.

static ParseMimeMessage.InviteParserResult parseInviteForCounter(Account account, Invite oldInvite, MailItem.Type type, Element inviteElem) throws ServiceException {
    TimeZoneMap tzMap = new TimeZoneMap(Util.getAccountTimeZone(account));
    Invite inv = new Invite(ICalTok.COUNTER.toString(), tzMap, false);
    CalendarUtils.parseInviteElementCommon(account, type, inviteElem, inv, true, true);
    // Get the existing invite to populate X-MS-OLK-ORIGINALSTART and X-MS-OLK-ORIGINALEND
    if (oldInvite == null) {
        Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
        CalendarItem calItem = mbox.getCalendarItemByUid(null, inv.getUid());
        if (calItem != null)
            oldInvite = calItem.getInvite(inv.getRecurId());
    }
    if (oldInvite != null) {
        // Add TZIDs from oldInvite to inv
        inv.getTimeZoneMap().add(oldInvite.getTimeZoneMap());
        // Add ORIGINALSTART x-prop
        ParsedDateTime dt = oldInvite.getStartTime();
        if (dt != null) {
            ZCalendar.ZProperty prop = new ZCalendar.ZProperty("X-MS-OLK-ORIGINALSTART");
            prop.setValue(dt.getDateTimePartString());
            if (dt.getTZName() != null)
                prop.addParameter(new ZParameter(ICalTok.TZID, dt.getTZName()));
            inv.addXProp(prop);
        }
        // Add ORIGINALEND x-prop
        dt = oldInvite.getEffectiveEndTime();
        if (dt != null) {
            ZCalendar.ZProperty prop = new ZCalendar.ZProperty("X-MS-OLK-ORIGINALEND");
            prop.setValue(dt.getDateTimePartString());
            if (dt.getTZName() != null)
                prop.addParameter(new ZParameter(ICalTok.TZID, dt.getTZName()));
            inv.addXProp(prop);
        }
        // Add LOCATION if not already exist.
        if (inv.getLocation() == null || inv.getLocation().isEmpty())
            inv.setLocation(oldInvite.getLocation());
    }
    // UID
    String uid = inv.getUid();
    if (uid == null || uid.length() == 0)
        throw ServiceException.INVALID_REQUEST("Missing uid in a counter invite", null);
    // ORGANIZER
    if (!inv.hasOrganizer())
        throw ServiceException.INVALID_REQUEST("Missing organizer in a counter invite", null);
    // DTSTAMP
    if (inv.getDTStamp() == 0) {
        //zdsync
        inv.setDtStamp(new Date().getTime());
    }
    // DTSTART
    if (inv.getStartTime() == null)
        throw ServiceException.INVALID_REQUEST("Missing dtstart in a counter invite", null);
    // iCalendar object doesn't have an ATTENDEE property.  RFC2446 doesn't require one.
    if (!inv.hasOtherAttendees()) {
        ZAttendee at = new ZAttendee(account.getMail());
        at.setPartStat(IcalXmlStrMap.PARTSTAT_TENTATIVE);
        inv.addAttendee(at);
    }
    inv.setLocalOnly(false);
    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 : ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) ZParameter(com.zimbra.common.calendar.ZCalendar.ZParameter) Date(java.util.Date) CalendarItem(com.zimbra.cs.mailbox.CalendarItem) ZCalendar(com.zimbra.common.calendar.ZCalendar) ZVCalendar(com.zimbra.common.calendar.ZCalendar.ZVCalendar) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZAttendee(com.zimbra.cs.mailbox.calendar.ZAttendee) TimeZoneMap(com.zimbra.common.calendar.TimeZoneMap) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime) Invite(com.zimbra.cs.mailbox.calendar.Invite)

Example 9 with ZVCalendar

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

the class CalendarUtils method parseInviteForCancel.

static ParseMimeMessage.InviteParserResult parseInviteForCancel(Account account, Folder folder, MailItem.Type type, Element inviteElem, TimeZoneMap tzMap, boolean recurrenceIdAllowed, boolean recurAllowed) throws ServiceException {
    if (tzMap == null) {
        tzMap = new TimeZoneMap(Util.getAccountTimeZone(account));
    }
    Invite cancel = new Invite(ICalTok.CANCEL.toString(), tzMap, false);
    cancel.setSentByMe(true);
    CalendarUtils.parseInviteElementCommon(account, type, inviteElem, cancel, recurrenceIdAllowed, recurAllowed);
    String uid = cancel.getUid();
    if (uid == null || uid.length() == 0)
        throw ServiceException.INVALID_REQUEST("Missing uid in a cancel invite", null);
    Invite sanitized = cancelInvite(account, null, false, false, folder, cancel, null, cancel.getAttendees(), cancel.getRecurId(), false);
    //zdsync
    sanitized.setInviteId(cancel.getMailItemId());
    //zdsync
    sanitized.setDtStamp(cancel.getDTStamp());
    ZVCalendar iCal = sanitized.newToICalendar(true);
    String summaryStr = sanitized.getName() != null ? sanitized.getName() : "";
    ParseMimeMessage.InviteParserResult toRet = new ParseMimeMessage.InviteParserResult();
    toRet.mCal = iCal;
    toRet.mUid = sanitized.getUid();
    toRet.mSummary = summaryStr;
    toRet.mInvite = sanitized;
    return toRet;
}
Also used : ZVCalendar(com.zimbra.common.calendar.ZCalendar.ZVCalendar) TimeZoneMap(com.zimbra.common.calendar.TimeZoneMap) Invite(com.zimbra.cs.mailbox.calendar.Invite)

Example 10 with ZVCalendar

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

the class CalendarUtils method parseInviteForCreateException.

static ParseMimeMessage.InviteParserResult parseInviteForCreateException(Account account, MailItem.Type type, Element inviteElem, TimeZoneMap tzMap, String uid, Invite defaultInv) 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, true, false);
    // DTSTAMP
    if (create.getDTStamp() == 0) {
        //zdsync
        create.setDtStamp(new Date().getTime());
    }
    // UID
    if (uid != null && uid.length() > 0)
        create.setUid(uid);
    // SEQUENCE - Make sure it's greater than the series sequence.  (bugs 19111 and 35036)
    create.setSeqNo(Math.max(create.getSeqNo(), defaultInv.getSeqNo() + 1));
    // Don't allow changing organizer in an exception instance.
    create.setOrganizer(defaultInv.hasOrganizer() ? new ZOrganizer(defaultInv.getOrganizer()) : null);
    create.setIsOrganizer(account);
    // 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.
        create.addXProp(new ZProperty(ICalTok.X_ZIMBRA_CHANGES, changes));
    }
    ZVCalendar iCal = create.newToICalendar(true);
    // Don't set the changes x-prop in the parsed Invite.
    create.removeXProp(ICalTok.X_ZIMBRA_CHANGES.toString());
    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) ZOrganizer(com.zimbra.cs.mailbox.calendar.ZOrganizer) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) Invite(com.zimbra.cs.mailbox.calendar.Invite) Date(java.util.Date)

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