Search in sources :

Example 21 with ZProperty

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

the class RdateExdate method addAsSeparateProperties.

// bug 59333: Hack for Apple iCal.  It doesn't like comma-separate values in a single EXDATE property.
// Output each value as its own EXDATE property.
void addAsSeparateProperties(ZComponent comp) {
    if (isRDATE() && !DebugConfig.enableRdate) {
        return;
    }
    ZParameter tzid = mTimeZone != null ? new ZParameter(ICalTok.TZID, mTimeZone.getID()) : null;
    ZParameter valType = !ICalTok.DATE_TIME.equals(mValueType) ? new ZParameter(ICalTok.VALUE, mValueType.toString()) : null;
    for (Object value : mValues) {
        ZProperty prop = new ZProperty(mPropertyName);
        if (tzid != null) {
            prop.addParameter(tzid);
        }
        if (valType != null) {
            prop.addParameter(valType);
        }
        if (value instanceof ParsedDateTime) {
            ParsedDateTime t = (ParsedDateTime) value;
            prop.setValue(t.getDateTimePartString(false));
        } else if (value instanceof Period) {
            prop.setValue(value.toString());
        }
        comp.addProperty(prop);
    }
}
Also used : ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime) ZParameter(com.zimbra.common.calendar.ZCalendar.ZParameter)

Example 22 with ZProperty

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

the class Alarm method parse.

/**
     * Create an Alarm from ZComponent.  Return value may be null.
     * @param comp
     * @return
     * @throws ServiceException
     */
public static Alarm parse(ZComponent comp) throws ServiceException {
    Action action = Action.DISPLAY;
    TriggerType triggerType = TriggerType.RELATIVE;
    TriggerRelated triggerRelated = null;
    ParsedDuration triggerRelative = null;
    ParsedDateTime triggerAbsolute = null;
    ParsedDuration repeatDuration = null;
    int repeatCount = 0;
    String description = null;
    String summary = null;
    Attach attach = null;
    List<ZAttendee> attendees = null;
    List<ZProperty> xprops = new ArrayList<ZProperty>();
    Iterator<ZProperty> propIter = comp.getPropertyIterator();
    while (propIter.hasNext()) {
        ZProperty prop = propIter.next();
        ICalTok tok = prop.getToken();
        String val = prop.getValue();
        if (tok == null) {
            String name = prop.getName();
            if (name.startsWith("X-") || name.startsWith("x-")) {
                xprops.add(prop);
            }
            continue;
        }
        switch(tok) {
            case ACTION:
                if (val != null) {
                    action = Action.lookup(val);
                    if (action == null)
                        throw ServiceException.INVALID_REQUEST("Invalid ACTION value " + val, null);
                    if (!actionAllowed(action))
                        return null;
                }
                break;
            case TRIGGER:
                ZParameter valueType = prop.getParameter(ICalTok.VALUE);
                if (valueType != null) {
                    String vt = valueType.getValue();
                    if (ICalTok.DATE_TIME.toString().equals(vt))
                        triggerType = TriggerType.ABSOLUTE;
                }
                if (TriggerType.RELATIVE.equals(triggerType)) {
                    ZParameter related = prop.getParameter(ICalTok.RELATED);
                    if (related != null) {
                        String rel = related.getValue();
                        if (rel != null) {
                            triggerRelated = TriggerRelated.lookup(rel);
                            if (triggerRelated == null)
                                throw ServiceException.INVALID_REQUEST("Invalid RELATED value " + rel, null);
                        }
                    }
                    triggerRelative = ParsedDuration.parse(val);
                } else {
                    try {
                        if (val != null)
                            triggerAbsolute = ParsedDateTime.parseUtcOnly(val);
                    } catch (ParseException e) {
                        throw ServiceException.INVALID_REQUEST("Invalid TRIGGER value " + val, e);
                    }
                }
                break;
            case DURATION:
                if (val != null)
                    repeatDuration = ParsedDuration.parse(val);
                break;
            case REPEAT:
                if (val != null) {
                    try {
                        repeatCount = Integer.parseInt(val);
                    } catch (NumberFormatException e) {
                        throw ServiceException.INVALID_REQUEST("Invalid REPEAT value " + val, e);
                    }
                }
                break;
            case DESCRIPTION:
                description = val;
                break;
            case SUMMARY:
                summary = val;
                break;
            case ATTACH:
                attach = Attach.parse(prop);
                break;
            case ATTENDEE:
                ZAttendee attendee = new ZAttendee(prop);
                if (attendees == null)
                    attendees = new ArrayList<ZAttendee>();
                attendees.add(attendee);
                break;
        }
    }
    Alarm alarm = new Alarm(action, triggerType, triggerRelated, triggerRelative, triggerAbsolute, repeatDuration, repeatCount, description, summary, attach, attendees, xprops);
    return alarm;
}
Also used : ParsedDuration(com.zimbra.common.calendar.ParsedDuration) Attach(com.zimbra.common.calendar.Attach) CalendarAttach(com.zimbra.soap.mail.type.CalendarAttach) ArrayList(java.util.ArrayList) ZParameter(com.zimbra.common.calendar.ZCalendar.ZParameter) ICalTok(com.zimbra.common.calendar.ZCalendar.ICalTok) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime) ParseException(java.text.ParseException)

Example 23 with ZProperty

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

the class Alarm method toString.

@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("action=").append(mAction.toString());
    sb.append(", triggerType=").append(mTriggerType.toString());
    if (TriggerType.ABSOLUTE.equals(mTriggerType)) {
        sb.append(", triggerAbsolute=").append(mTriggerAbsolute != null ? mTriggerAbsolute.toString() : "<none>");
    } else {
        sb.append(", triggerRelated").append(mTriggerRelated != null ? mTriggerRelated.toString() : "<default>");
        sb.append(", triggerRelative=").append(mTriggerRelative != null ? mTriggerRelative.toString() : "<none>");
    }
    if (mRepeatDuration != null) {
        sb.append(", repeatDuration=").append(mRepeatDuration != null ? mRepeatDuration.toString() : "<none>");
        sb.append(", repeatCount=").append(mRepeatCount);
    } else {
        sb.append(", repeat=<none>");
    }
    sb.append(", summary=\"").append(mSummary).append("\"");
    sb.append(", desc=\"").append(mDescription).append("\"");
    if (mAttach != null)
        sb.append(", attach=").append(mAttach.toString());
    if (mAttendees != null) {
        sb.append(", attendees=[");
        boolean first = true;
        for (ZAttendee attendee : mAttendees) {
            if (!first)
                sb.append(", ");
            else
                first = false;
            sb.append("[").append(attendee.toString()).append("]");
        }
        sb.append("]");
    }
    for (ZProperty xprop : xProps) {
        sb.append(", ").append(xprop.toString());
    }
    return sb.toString();
}
Also used : ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty)

Example 24 with ZProperty

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

the class CalendarMailSender method createForwardedPrivateInviteMessage.

public static MimeMessage createForwardedPrivateInviteMessage(Account account, Locale lc, String method, List<Invite> invites, String origSenderEmail, String forwarderEmail, String[] forwardTo) throws ServiceException {
    if (invites == null || invites.isEmpty())
        return null;
    List<Address> rcpts = new ArrayList<Address>();
    for (String to : forwardTo) {
        try {
            rcpts.add(new JavaMailInternetAddress(to));
        } catch (AddressException e) {
            ZimbraLog.calendar.warn("Ignoring invalid address \"" + to + "\" during invite forward");
        }
    }
    if (rcpts.isEmpty())
        return null;
    String subject = L10nUtil.getMessage(MsgKey.calendarSubjectWithheld, lc);
    // Create filtered version of invites.
    List<Invite> filteredInvs = new ArrayList<Invite>();
    for (Invite inv : invites) {
        Invite filtered = inv.newCopy();
        filtered.clearAlarms();
        filtered.clearPrivateInfo();
        filtered.setName(subject);
        // Add ATTENDEE for forwarder.
        List<ZAttendee> atts = inv.getAttendees();
        if (atts != null && forwarderEmail != null) {
            for (ZAttendee att : atts) {
                if (forwarderEmail.equalsIgnoreCase(att.getAddress())) {
                    filtered.addAttendee(att);
                }
            }
        }
        filteredInvs.add(filtered);
    }
    MimeMessage mm = null;
    try {
        mm = new Mime.FixedMimeMessage(JMSession.getSmtpSession(account));
        mm.setFrom(new JavaMailInternetAddress(origSenderEmail));
        mm.addRecipients(RecipientType.TO, rcpts.toArray(new Address[0]));
        // Set special header to indicate the forwarding attendee.
        mm.setHeader(CalendarMailSender.X_ZIMBRA_CALENDAR_INTENDED_FOR, forwarderEmail);
        mm.setSubject(subject);
        StringWriter writer = new StringWriter();
        try {
            writer.write("BEGIN:VCALENDAR\r\n");
            ZProperty prop;
            prop = new ZProperty(ICalTok.PRODID, ZCalendar.sZimbraProdID);
            prop.toICalendar(writer);
            prop = new ZProperty(ICalTok.VERSION, ZCalendar.sIcalVersion);
            prop.toICalendar(writer);
            prop = new ZProperty(ICalTok.METHOD, method);
            prop.toICalendar(writer);
            // timezones
            Invite firstInv = filteredInvs.get(0);
            TimeZoneMap tzmap = new TimeZoneMap(firstInv.getTimeZoneMap().getLocalTimeZone());
            for (Invite inv : filteredInvs) {
                tzmap.add(inv.getTimeZoneMap());
            }
            for (Iterator<ICalTimeZone> iter = tzmap.tzIterator(); iter.hasNext(); ) {
                ICalTimeZone tz = iter.next();
                tz.newToVTimeZone().toICalendar(writer);
            }
            // VEVENTs/VTODOs
            for (Invite inv : filteredInvs) {
                ZComponent comp = inv.newToVComponent(false, true);
                comp.toICalendar(writer);
            }
            writer.write("END:VCALENDAR\r\n");
        } catch (IOException e) {
            throw ServiceException.FAILURE("Error writing iCalendar", e);
        } finally {
            Closeables.closeQuietly(writer);
        }
        mm.setText(writer.toString());
        ContentType ct = new ContentType(MimeConstants.CT_TEXT_CALENDAR);
        ct.setParameter(MimeConstants.P_CHARSET, MimeConstants.P_CHARSET_UTF8);
        ct.setParameter("method", method);
        mm.setHeader("Content-Type", ct.toString());
    } catch (MessagingException e) {
        ZimbraLog.calendar.warn("Unable to compose email for invite forwarding", e);
    }
    return mm;
}
Also used : Address(javax.mail.Address) InternetAddress(javax.mail.internet.InternetAddress) JavaMailInternetAddress(com.zimbra.common.mime.shim.JavaMailInternetAddress) ContentType(javax.mail.internet.ContentType) MessagingException(javax.mail.MessagingException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Mime(com.zimbra.cs.mime.Mime) ZComponent(com.zimbra.common.calendar.ZCalendar.ZComponent) StringWriter(java.io.StringWriter) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) AddressException(javax.mail.internet.AddressException) JavaMailInternetAddress(com.zimbra.common.mime.shim.JavaMailInternetAddress) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty) TimeZoneMap(com.zimbra.common.calendar.TimeZoneMap) ICalTimeZone(com.zimbra.common.calendar.ICalTimeZone)

Example 25 with ZProperty

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

the class ToXML method jaxbXProps.

public static List<XProp> jaxbXProps(Iterator<ZProperty> xpropsIterator) {
    List<XProp> xprops = Lists.newArrayList();
    while (xpropsIterator.hasNext()) {
        ZProperty xprop = xpropsIterator.next();
        String paramName = xprop.getName();
        if (paramName == null) {
            continue;
        }
        XProp xp = new XProp(paramName, xprop.getValue());
        xp.setXParams(jaxbXParams(xprop.parameterIterator()));
        xprops.add(xp);
    }
    return Collections.unmodifiableList(xprops);
}
Also used : XProp(com.zimbra.soap.mail.type.XProp) ZProperty(com.zimbra.common.calendar.ZCalendar.ZProperty)

Aggregations

ZProperty (com.zimbra.common.calendar.ZCalendar.ZProperty)49 ZParameter (com.zimbra.common.calendar.ZCalendar.ZParameter)19 ZComponent (com.zimbra.common.calendar.ZCalendar.ZComponent)18 ParsedDateTime (com.zimbra.common.calendar.ParsedDateTime)13 ArrayList (java.util.ArrayList)12 Account (com.zimbra.cs.account.Account)10 ICalTok (com.zimbra.common.calendar.ZCalendar.ICalTok)9 ZVCalendar (com.zimbra.common.calendar.ZCalendar.ZVCalendar)9 ICalTimeZone (com.zimbra.common.calendar.ICalTimeZone)8 Invite (com.zimbra.cs.mailbox.calendar.Invite)8 ParsedDuration (com.zimbra.common.calendar.ParsedDuration)7 ZOrganizer (com.zimbra.cs.mailbox.calendar.ZOrganizer)7 TimeZoneMap (com.zimbra.common.calendar.TimeZoneMap)6 ServiceException (com.zimbra.common.service.ServiceException)6 ParseException (java.text.ParseException)6 IRecurrence (com.zimbra.cs.mailbox.calendar.Recurrence.IRecurrence)5 AccountAddressMatcher (com.zimbra.cs.util.AccountUtil.AccountAddressMatcher)5 Element (com.zimbra.common.soap.Element)4 IOException (java.io.IOException)4 Geo (com.zimbra.common.calendar.Geo)3