use of com.zimbra.common.calendar.ZCalendar.ZParameter in project zm-mailbox by Zimbra.
the class ForwardCalendarItem method setDescProps.
private static void setDescProps(ZVCalendar cal, String descPlain, String descHtml) {
for (Iterator<ZComponent> compIter = cal.getComponentIterator(); compIter.hasNext(); ) {
ZComponent comp = compIter.next();
ICalTok compName = ICalTok.lookup(comp.getName());
if (ICalTok.VEVENT.equals(compName) || ICalTok.VTODO.equals(compName)) {
// Remove existing DESCRIPTION and X-ALT-DESC properties.
for (Iterator<ZProperty> propIter = comp.getPropertyIterator(); propIter.hasNext(); ) {
ZProperty prop = propIter.next();
ICalTok tok = prop.getToken();
if (ICalTok.DESCRIPTION.equals(tok) || ICalTok.X_ALT_DESC.equals(tok))
propIter.remove();
}
if (descPlain != null && descPlain.length() > 0) {
comp.addProperty(new ZProperty(ICalTok.DESCRIPTION, descPlain));
}
if (descHtml != null && descHtml.length() > 0) {
ZProperty prop = new ZProperty(ICalTok.X_ALT_DESC, descHtml);
prop.addParameter(new ZParameter(ICalTok.FMTTYPE, MimeConstants.CT_TEXT_HTML));
comp.addProperty(prop);
}
// only update the first component (comps are ordered correctly)
break;
}
}
}
use of com.zimbra.common.calendar.ZCalendar.ZParameter in project zm-mailbox by Zimbra.
the class ForwardCalendarItem method setSentByAndAttendees.
private static void setSentByAndAttendees(ZVCalendar cal, String sentBy, Address[] rcpts) throws ServiceException {
// Set SENT-BY to sender's email address in ORGANIZER property of all VEVENT/VTODO components.
// Required by Outlook.
// Also, remove existing ATTENDEEs and add ATTENDEE lines for forwardees.
String sentByAddr = "mailto:" + sentBy;
for (Iterator<ZComponent> compIter = cal.getComponentIterator(); compIter.hasNext(); ) {
ZComponent comp = compIter.next();
ICalTok compName = ICalTok.lookup(comp.getName());
if (ICalTok.VEVENT.equals(compName) || ICalTok.VTODO.equals(compName)) {
// Remove existing ATTENDEEs and X-MS-OLK-SENDER.
for (Iterator<ZProperty> propIter = comp.getPropertyIterator(); propIter.hasNext(); ) {
ZProperty prop = propIter.next();
if (ICalTok.ATTENDEE.equals(prop.getToken()) || "X-MS-OLK-SENDER".equalsIgnoreCase(prop.getName()))
propIter.remove();
}
// SENT-BY
ZProperty orgProp = comp.getProperty(ICalTok.ORGANIZER);
if (orgProp != null) {
ZParameter sentByParam = orgProp.getParameter(ICalTok.SENT_BY);
if (sentByParam != null) {
sentByParam.setValue(sentByAddr);
} else {
sentByParam = new ZParameter(ICalTok.SENT_BY, sentByAddr);
orgProp.addParameter(sentByParam);
}
// Set X-MS-OLK-SENDER, another Outlook special.
ZProperty xMsOlkSender = new ZProperty("X-MS-OLK-SENDER");
xMsOlkSender.setValue(sentByAddr);
comp.addProperty(xMsOlkSender);
}
// ATTENDEEs
if (rcpts == null)
throw ServiceException.INVALID_REQUEST("Missing forwardees", null);
for (Address r : rcpts) {
InternetAddress rcpt = (InternetAddress) r;
String email = "mailto:" + rcpt.getAddress();
ZProperty att = new ZProperty(ICalTok.ATTENDEE, email);
String name = rcpt.getPersonal();
if (name != null && name.length() > 0)
att.addParameter(new ZParameter(ICalTok.CN, name));
att.addParameter(new ZParameter(ICalTok.PARTSTAT, ICalTok.NEEDS_ACTION.toString()));
att.addParameter(new ZParameter(ICalTok.RSVP, "TRUE"));
comp.addProperty(att);
}
}
}
}
use of com.zimbra.common.calendar.ZCalendar.ZParameter 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;
}
use of com.zimbra.common.calendar.ZCalendar.ZParameter in project zm-mailbox by Zimbra.
the class CalendarUtils method parseXProps.
public static List<ZProperty> parseXProps(Element element) throws ServiceException {
List<ZProperty> props = new ArrayList<ZProperty>();
for (Iterator<Element> propIter = element.elementIterator(MailConstants.E_CAL_XPROP); propIter.hasNext(); ) {
Element propElem = propIter.next();
String propName = propElem.getAttribute(MailConstants.A_NAME);
String propValue = propElem.getAttribute(MailConstants.A_VALUE, null);
ZProperty xprop = new ZProperty(propName);
xprop.setValue(propValue);
List<ZParameter> xparams = CalendarUtil.parseXParams(propElem);
for (ZParameter xparam : xparams) {
xprop.addParameter(xparam);
}
props.add(xprop);
}
return props;
}
use of com.zimbra.common.calendar.ZCalendar.ZParameter in project zm-mailbox by Zimbra.
the class Alarm method toZComponent.
public ZComponent toZComponent() throws ServiceException {
ZComponent comp = new ZComponent(ICalTok.VALARM);
ZProperty action = new ZProperty(ICalTok.ACTION, mAction.toString());
comp.addProperty(action);
ZProperty trigger = new ZProperty(ICalTok.TRIGGER);
if (TriggerType.ABSOLUTE.equals(mTriggerType)) {
ZParameter vt = new ZParameter(ICalTok.VALUE, ICalTok.DATE_TIME.toString());
trigger.addParameter(vt);
trigger.setValue(mTriggerAbsolute.getDateTimePartString(false));
} else {
if (mTriggerRelated != null) {
ZParameter related = new ZParameter(ICalTok.RELATED, mTriggerRelated.toString());
trigger.addParameter(related);
}
trigger.setValue(mTriggerRelative.toString());
}
comp.addProperty(trigger);
if (mRepeatDuration != null) {
ZProperty duration = new ZProperty(ICalTok.DURATION, mRepeatDuration.toString());
comp.addProperty(duration);
ZProperty repeat = new ZProperty(ICalTok.REPEAT, mRepeatCount);
comp.addProperty(repeat);
}
if (!Action.AUDIO.equals(mAction)) {
String d = mDescription;
// DESCRIPTION is required in DISPLAY and EMAIL alarms.
if (d == null && !Action.PROCEDURE.equals(mAction))
d = "Reminder";
ZProperty desc = new ZProperty(ICalTok.DESCRIPTION, d);
comp.addProperty(desc);
}
if (mAttach != null)
comp.addProperty(mAttach.toZProperty());
if (Action.EMAIL.equals(mAction) || Action.X_YAHOO_CALENDAR_ACTION_IM.equals(mAction) || Action.X_YAHOO_CALENDAR_ACTION_MOBILE.equals(mAction)) {
String s = mSummary;
if (s == null)
s = "Reminder";
ZProperty summary = new ZProperty(ICalTok.SUMMARY, s);
comp.addProperty(summary);
// if somehow the object didn't have any attendee.
if (mAttendees != null) {
for (ZAttendee attendee : mAttendees) {
comp.addProperty(attendee.toProperty());
}
}
}
// x-prop
for (ZProperty xprop : xProps) {
comp.addProperty(xprop);
}
return comp;
}
Aggregations