use of com.zimbra.common.calendar.ZCalendar.ZProperty 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.ZProperty 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.ZProperty in project zm-mailbox by Zimbra.
the class ICalTimeZone method newToVTimeZone.
public ZComponent newToVTimeZone() {
ZComponent vtz = new ZComponent(ICalTok.VTIMEZONE);
vtz.addProperty(new ZProperty(ICalTok.TZID, getID()));
if (mDayToStdDtStart != null) {
ZComponent standard = new ZComponent(ICalTok.STANDARD);
vtz.addComponent(standard);
standard.addProperty(new ZProperty(ICalTok.DTSTART, mDayToStdDtStart));
standard.addProperty(new ZProperty(ICalTok.TZOFFSETTO, timeToTzOffsetString(mStandardOffset)));
standard.addProperty(new ZProperty(ICalTok.TZOFFSETFROM, timeToTzOffsetString(mDaylightOffset)));
if (mDayToStdRule != null)
standard.addProperty(new ZProperty(ICalTok.RRULE, mDayToStdRule));
if (mStandardTzname != null)
standard.addProperty(new ZProperty(ICalTok.TZNAME, mStandardTzname));
}
if (mStdToDayDtStart != null && (mStandardOffset != mDaylightOffset || mDayToStdDtStart == null)) {
ZComponent daylight = new ZComponent(ICalTok.DAYLIGHT);
vtz.addComponent(daylight);
daylight.addProperty(new ZProperty(ICalTok.DTSTART, mStdToDayDtStart));
daylight.addProperty(new ZProperty(ICalTok.TZOFFSETTO, timeToTzOffsetString(mDaylightOffset)));
daylight.addProperty(new ZProperty(ICalTok.TZOFFSETFROM, timeToTzOffsetString(mStandardOffset)));
if (mStdToDayRule != null)
daylight.addProperty(new ZProperty(ICalTok.RRULE, mStdToDayRule));
if (mDaylightTzname != null)
daylight.addProperty(new ZProperty(ICalTok.TZNAME, mDaylightTzname));
}
return vtz;
}
use of com.zimbra.common.calendar.ZCalendar.ZProperty in project zm-mailbox by Zimbra.
the class Geo method toZProperty.
public ZProperty toZProperty() {
ZProperty prop = new ZProperty(ICalTok.GEO);
prop.setValue(mLatitude + ";" + mLongitude);
return prop;
}
use of com.zimbra.common.calendar.ZCalendar.ZProperty in project zm-mailbox by Zimbra.
the class Message method getInfoForAssociatedCalendarItem.
/**
* Update {@code status.calItem} and {@code calendarItemInfos}
*/
private void getInfoForAssociatedCalendarItem(Account acct, Invite cur, String method, ParsedMessage pm, boolean applyToCalendar, ProcessInvitesStatus status) throws ServiceException {
boolean calItemIsNew = false;
boolean modifiedCalItem = false;
boolean success = false;
try {
InviteChanges invChanges = null;
// Look for organizer-provided change list.
ZProperty changesProp = cur.getXProperty(ICalTok.X_ZIMBRA_CHANGES.toString());
if (changesProp != null) {
invChanges = new InviteChanges(changesProp.getValue());
// Don't let the x-prop propagate further. This x-prop is used during transport only. Presence
// of this x-prop in the appointment object can confuse clients.
cur.removeXProp(ICalTok.X_ZIMBRA_CHANGES.toString());
}
if (!(status.intendedForMe || status.intendedForCalendarIManage)) {
// Not intended for me. Just save the invite detail in metadata.
CalendarItemInfo info = new CalendarItemInfo(CalendarItemInfo.CALITEM_ID_NONE, cur.getComponentNum(), cur, invChanges);
calendarItemInfos.add(info);
status.updatedMetadata = true;
success = true;
return;
}
OperationContext octxt = getMailbox().getOperationContext();
ICalTok methodTok = Invite.lookupMethod(method);
AccountAddressMatcher acctMatcher = status.getAcctMatcher();
cur.sanitize(true);
if (status.intendedForCalendarIManage) {
Provisioning prov = Provisioning.getInstance();
Account ownerAcct = prov.get(AccountBy.name, calendarIntendedFor);
com.zimbra.soap.mail.type.CalendarItemInfo cii = getMailbox().getRemoteCalItemByUID(ownerAcct, cur.getUid(), false, false);
CalendarItemInfo info;
if (cii == null) {
info = new CalendarItemInfo(CalendarItemInfo.CALITEM_ID_NONE, cur.getComponentNum(), cur, invChanges);
calendarItemInfos.add(info);
} else {
int calItemId;
String owner;
try {
ItemId iid = new ItemId(cii.getId(), (String) null);
calItemId = iid.getId();
owner = iid.getAccountId();
} catch (Exception e) {
calItemId = CalendarItemInfo.CALITEM_ID_NONE;
owner = null;
}
info = new CalendarItemInfo(calItemId, owner, cur.getComponentNum(), cur, invChanges);
calendarItemInfos.add(info);
}
status.updatedMetadata = true;
success = true;
return;
}
status.calItem = mMailbox.getCalendarItemByUid(octxt, cur.getUid());
if (applyToCalendar && // replies are handled elsewhere (in Mailbox.addMessage())
!ICalTok.REPLY.equals(methodTok) && !ICalTok.COUNTER.equals(methodTok) && !ICalTok.DECLINECOUNTER.equals(methodTok)) {
if (status.calItem == null) {
// Allow PUBLISH method as well depending on the preference.
if (ICalTok.REQUEST.equals(methodTok) || (ICalTok.PUBLISH.equals(methodTok) && getAccount().getBooleanAttr(Provisioning.A_zimbraPrefCalendarAllowPublishMethodInvite, false))) {
if (status.autoAddNew) {
if (mMailbox.getAccount().sameAccount(cur.getOrganizerAccount())) {
// Bug 100456 ZCO sends out invites before adding a calendar entry. If server adds
// Calendar entry and ZCO sees that before creating its entry, ZCO gets confused.
LOG.info("Mailbox %d Msg %d Don't create ORGANIZER calendar item for Invite %s", getMailboxId(), getId(), method);
} else {
int flags = 0;
// int flags = Flag.BITMASK_INDEXING_DEFERRED;
// mMailbox.incrementIndexDeferredCount(1);
int defaultFolder = cur.isTodo() ? Mailbox.ID_FOLDER_TASKS : Mailbox.ID_FOLDER_CALENDAR;
status.calItem = mMailbox.createCalendarItem(defaultFolder, flags, null, cur.getUid(), pm, cur, null);
calItemIsNew = true;
status.calItemFolderId = status.calItem.getFolderId();
}
}
} else {
LOG.info("Mailbox %d Message %d SKIPPING Invite %s b/c no CalendarItem could be found", getMailboxId(), getId(), method);
}
} else {
// bug 27887: Ignore when calendar request email somehow made a loop back to the
// organizer address. Necessary conditions are:
//
// 1) This mailbox is currently organizer.
// 2) ORGANIZER in the request is this mailbox.
// 3) User/COS preference doesn't explicitly allow it. (bug 29777)
//
// If ORGANIZER in the request is a different user this is an organizer change request,
// which should be allowed to happen.
boolean ignore = false;
Invite defInv = status.calItem.getDefaultInviteOrNull();
if (defInv != null && defInv.isOrganizer()) {
ZOrganizer org = cur.getOrganizer();
String orgAddress = org != null ? org.getAddress() : null;
if (acctMatcher.matches(orgAddress))
ignore = !acct.getBooleanAttr(Provisioning.A_zimbraPrefCalendarAllowCancelEmailToSelf, false);
}
if (ignore) {
ZimbraLog.calendar.info("Ignoring calendar request emailed from organizer to self, " + "possibly in a mail loop involving mailing lists and/or forwards; " + "calItemId=" + status.calItem.getId() + ", msgId=" + getId());
} else {
// the calendar item in the folder it's currently in.
if (status.addRevision)
status.calItem.snapshotRevision(false);
// If updating (but not canceling) an appointment in trash folder,
// use default calendar folder and discard all existing invites.
boolean discardExistingInvites = false;
int calFolderId = status.calItem.getFolderId();
if (!cur.isCancel() && status.calItem.inTrash()) {
discardExistingInvites = true;
if (status.calItem.getType() == MailItem.Type.TASK) {
calFolderId = Mailbox.ID_FOLDER_TASKS;
} else {
calFolderId = Mailbox.ID_FOLDER_CALENDAR;
}
}
// against the current appointment data.
if (invChanges == null && !cur.isCancel()) {
Invite prev = status.calItem.getInvite(cur.getRecurId());
if (prev == null) {
// If incoming invite is a brand-new exception instance, we have to compare
// against the series data, but adjusted to the RECURRENCE-ID of the instance.
Invite series = status.calItem.getInvite(null);
if (series != null)
prev = series.makeInstanceInvite(cur.getRecurId().getDt());
}
if (prev != null)
invChanges = new InviteChanges(prev, cur);
}
modifiedCalItem = status.calItem.processNewInvite(pm, cur, calFolderId, discardExistingInvites);
status.calItemFolderId = calFolderId;
status.calItem.getFolder().updateHighestMODSEQ();
}
}
}
int calItemId = status.calItem != null ? status.calItem.getId() : CalendarItemInfo.CALITEM_ID_NONE;
CalendarItemInfo info = new CalendarItemInfo(calItemId, cur.getComponentNum(), cur, invChanges);
calendarItemInfos.add(info);
status.updatedMetadata = true;
if (status.calItem != null && (calItemIsNew || modifiedCalItem)) {
mMailbox.index.add(status.calItem);
}
success = true;
} finally {
if (!success && status.calItem != null) {
// Error occurred and the calItem in memory may be out of sync with the database.
// Uncache it here, because the error will be ignored by this method's caller.
getMailbox().uncache(status.calItem);
}
}
}
Aggregations