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);
}
}
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;
}
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();
}
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;
}
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);
}
Aggregations