use of com.zimbra.common.calendar.ZCalendar.ZParameter in project zm-mailbox by Zimbra.
the class Attach method parse.
public static Attach parse(ZProperty prop) {
String value = prop.getValue();
String ct = null;
ZParameter fmttype = prop.getParameter(ICalTok.FMTTYPE);
if (fmttype != null) {
ct = fmttype.getValue();
}
ZParameter valueType = prop.getParameter(ICalTok.VALUE);
Attach attach = null;
if ((valueType != null) && (valueType.getValue().equals("BINARY"))) {
attach = Attach.fromEncodedAndContentType(value, ct);
ZParameter fn = prop.getParameter(ICalTok.X_FILENAME);
if (fn == null) {
fn = prop.getParameter(ICalTok.X_APPLE_FILENAME);
}
if (fn != null) {
attach.setFileName(fn.getValue());
}
} else {
// URI
attach = Attach.fromUriAndContentType(value, ct);
}
return attach;
}
use of com.zimbra.common.calendar.ZCalendar.ZParameter in project zm-mailbox by Zimbra.
the class Attach method toZProperty.
public ZProperty toZProperty() {
ZProperty prop;
if (mUri != null) {
prop = new ZProperty(ICalTok.ATTACH, mUri);
} else {
prop = new ZProperty(ICalTok.ATTACH, mBinaryB64Data);
prop.addParameter(new ZParameter(ICalTok.VALUE, "BINARY"));
prop.addParameter(new ZParameter(ICalTok.ENCODING, "BASE64"));
}
if (mContentType != null) {
prop.addParameter(new ZParameter(ICalTok.FMTTYPE, mContentType));
}
if (fileName != null) {
/* We recognise X-FILENAME incoming as well from Microsoft documentation but CalDAV clients are more
* likely to use X-APPLE-FILENAME
*/
prop.addParameter(new ZParameter(ICalTok.X_APPLE_FILENAME, fileName));
}
return prop;
}
use of com.zimbra.common.calendar.ZCalendar.ZParameter in project zm-mailbox by Zimbra.
the class ParsedDateTime method toProperty.
public ZProperty toProperty(ICalTok tok, boolean useOutlookCompatMode) {
ZProperty toRet = new ZProperty(tok, getDateTimePartString(useOutlookCompatMode));
String tzName = getTZName();
if (!useOutlookCompatMode && !hasTime()) {
toRet.addParameter(new ZParameter(ICalTok.VALUE, ICalTok.DATE.toString()));
} else {
if (tzName != null) {
toRet.addParameter(new ZParameter(ICalTok.TZID, tzName));
}
}
return toRet;
}
use of com.zimbra.common.calendar.ZCalendar.ZParameter in project zm-mailbox by Zimbra.
the class ScheduleOutbox method adjustOrganizer.
/**
* For Vanilla CalDAV access where Apple style delegation has not been enabled, attempts by the delegate
* to use a shared calendar acting as themselves are translated to appear as if acting as a delegate,
* otherwise the experience can be very poor.
* @throws ServiceException
*/
private void adjustOrganizer(DavContext ctxt, ZCalendar.ZVCalendar cal, ZComponent req, DelegationInfo delegationInfo) throws ServiceException {
// BusyCal 2.5.3 seems to post with the wrong organizer even if ical delegation is switched on - even though
// it uses the right ORGANIZER in the calendar entry.
// if (ctxt.useIcalDelegation()) { return; }
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(ctxt.getAuthAccount());
String uid = req.getPropVal(ICalTok.UID, null);
CalendarItem matchingCalendarEntry = mbox.getCalendarItemByUid(ctxt.getOperationContext(), uid);
if (matchingCalendarEntry == null) {
List<com.zimbra.cs.mailbox.Mountpoint> sharedCalendars = mbox.getCalendarMountpoints(ctxt.getOperationContext(), SortBy.NONE);
if (sharedCalendars == null) {
// Can't work out anything useful
return;
}
Set<Account> accts = Sets.newHashSet();
for (com.zimbra.cs.mailbox.Mountpoint sharedCalendar : sharedCalendars) {
accts.add(Provisioning.getInstance().get(AccountBy.id, sharedCalendar.getOwnerId()));
}
for (Account acct : accts) {
Mailbox sbox = MailboxManager.getInstance().getMailboxByAccount(acct);
matchingCalendarEntry = sbox.getCalendarItemByUid(ctxt.getOperationContext(), uid);
if (matchingCalendarEntry != null) {
break;
}
}
}
if (matchingCalendarEntry == null) {
return;
}
Invite[] invites = matchingCalendarEntry.getInvites();
if (invites == null) {
return;
}
for (Invite inv : invites) {
ZOrganizer org = inv.getOrganizer();
if (org != null) {
delegationInfo.setOwner(org.getAddress());
if (Strings.isNullOrEmpty(org.getCn())) {
Account ownerAcct = Provisioning.getInstance().get(AccountBy.name, org.getAddress());
if (!Strings.isNullOrEmpty(ownerAcct.getDisplayName())) {
delegationInfo.setOwnerCn(ownerAcct.getDisplayName());
}
} else {
delegationInfo.setOwnerCn(org.getCn());
}
break;
}
}
if (delegationInfo.getOwner() == null) {
return;
}
AccountAddressMatcher acctMatcher = new AccountAddressMatcher(ctxt.getAuthAccount());
boolean originatorIsCalEntryOrganizer = acctMatcher.matches(delegationInfo.getOwnerEmail());
if (originatorIsCalEntryOrganizer) {
return;
}
for (ZComponent component : cal.getComponents()) {
ZProperty organizerProp = component.getProperty(ICalTok.ORGANIZER);
if (organizerProp != null) {
organizerProp.setValue(delegationInfo.getOwner());
ZParameter cn = organizerProp.getParameter(ICalTok.CN);
if (cn == null) {
organizerProp.addParameter(new ZParameter(ICalTok.CN, delegationInfo.getOwnerCn()));
} else {
cn.setValue(delegationInfo.getOwnerCn());
}
ZParameter sentBy = organizerProp.getParameter(ICalTok.SENT_BY);
if (sentBy == null) {
organizerProp.addParameter(new ZParameter(ICalTok.SENT_BY, delegationInfo.getOriginator()));
} else {
sentBy.setValue(delegationInfo.getOriginator());
}
}
}
}
use of com.zimbra.common.calendar.ZCalendar.ZParameter in project zm-mailbox by Zimbra.
the class FreeBusy method parse.
/**
* Create a FreeBusy object from VFREEBUSY ZComponent.
* @param comp
* @return
* @throws ServiceException
*/
public static FreeBusy parse(ZComponent comp) throws ServiceException {
String name = null;
ParsedDateTime dtStart = null;
ParsedDateTime dtEnd = null;
List<Interval> intervals = new ArrayList<Interval>();
TimeZoneMap tzmap = new TimeZoneMap(ICalTimeZone.getUTC());
Iterator<ZProperty> propIter = comp.getPropertyIterator();
while (propIter.hasNext()) {
ZProperty prop = propIter.next();
ICalTok tok = prop.getToken();
if (tok == null)
continue;
switch(tok) {
case DTSTART:
try {
dtStart = ParsedDateTime.parse(prop, tzmap);
} catch (ParseException e) {
throw ServiceException.INVALID_REQUEST("bad DTSTART: " + prop.toString(), e);
}
break;
case DTEND:
try {
dtEnd = ParsedDateTime.parse(prop, tzmap);
} catch (ParseException e) {
throw ServiceException.INVALID_REQUEST("bad DTEND: " + prop.toString(), e);
}
break;
case ORGANIZER:
ZOrganizer att = new ZOrganizer(prop);
name = att.getAddress();
break;
case FREEBUSY:
String fbStatus = IcalXmlStrMap.FBTYPE_FREE;
ZParameter fbType = prop.getParameter(ICalTok.FBTYPE);
if (fbType != null)
fbStatus = IcalXmlStrMap.sFreeBusyMap.toXml(fbType.getValue());
List<String> vals = prop.getValueList();
for (String fbVal : vals) {
Period period;
try {
period = Period.parse(fbVal, ICalTimeZone.getUTC(), tzmap);
} catch (ParseException e) {
throw ServiceException.INVALID_REQUEST("bad period value: " + fbVal, e);
}
intervals.add(new Interval(period.getStart().getUtcTime(), period.getEnd().getUtcTime(), fbStatus));
}
break;
}
}
if (name == null)
throw ServiceException.INVALID_REQUEST("VFREEBUSY missing ORGANIZER", null);
if (dtStart == null || dtEnd == null)
throw ServiceException.INVALID_REQUEST("VFREEBUSY missing DTSTART/DTEND", null);
IntervalList ivalList = new IntervalList(dtStart.getUtcTime(), dtEnd.getUtcTime());
for (Interval ival : intervals) {
ivalList.addInterval(ival);
}
return new FreeBusy(name, ivalList, dtStart.getUtcTime(), dtEnd.getUtcTime());
}
Aggregations