use of com.zimbra.cs.mailbox.calendar.Invite in project zm-mailbox by Zimbra.
the class ToXML method encodeAlarmData.
public static Element encodeAlarmData(Element parent, CalendarItem calItem, AlarmData alarmData) {
Element alarmElem = parent.addElement(MailConstants.E_CAL_ALARM_DATA);
encodeAlarmTimes(alarmElem, calItem);
// Start time of the meeting instance we're reminding about.
long alarmInstStart = alarmData.getNextInstanceStart();
if (alarmInstStart != 0) {
alarmElem.addAttribute(MailConstants.A_CAL_ALARM_INSTANCE_START, alarmInstStart);
}
int alarmInvId = alarmData.getInvId();
int alarmCompNum = alarmData.getCompNum();
Invite alarmInv = calItem.getInvite(alarmInvId, alarmCompNum);
if (alarmInv != null) {
// Some info on the meeting instance the reminder is for.
// These allow the UI to display tooltip and issue a Get
// call on the correct meeting instance.
alarmElem.addAttribute(MailConstants.A_NAME, alarmInv.getName());
alarmElem.addAttribute(MailConstants.A_CAL_LOCATION, alarmInv.getLocation());
alarmElem.addAttribute(MailConstants.A_CAL_INV_ID, alarmInvId);
alarmElem.addAttribute(MailConstants.A_CAL_COMPONENT_NUM, alarmCompNum);
}
Alarm alarmObj = alarmData.getAlarm();
if (alarmObj != null) {
alarmObj.toXml(alarmElem);
}
return alarmElem;
}
use of com.zimbra.cs.mailbox.calendar.Invite in project zm-mailbox by Zimbra.
the class ToXML method encodeInvitesForMessage.
private static Element encodeInvitesForMessage(Element parent, ItemIdFormatter ifmt, OperationContext octxt, Message msg, int fields, boolean neuter) throws ServiceException {
if (fields != NOTIFY_FIELDS && !needToOutput(fields, Change.INVITE)) {
return parent;
}
Element ie = parent.addNonUniqueElement(MailConstants.E_INVITE);
Mailbox mbox = msg.getMailbox();
for (Iterator<Message.CalendarItemInfo> iter = msg.getCalendarItemInfoIterator(); iter.hasNext(); ) {
Message.CalendarItemInfo info = iter.next();
CalendarItem calItem = null;
ICalTok method = ICalTok.REQUEST;
Invite invCi = info.getInvite();
if (invCi != null) {
method = Invite.lookupMethod(invCi.getMethod());
}
Invite invite = invCi;
ItemId calendarItemId = info.getCalendarItemId();
if (info.calItemCreated()) {
try {
calItem = mbox.getCalendarItemById(octxt, calendarItemId);
} catch (MailServiceException.NoSuchItemException e) {
// Calendar item has been deleted. Bug 84877 - don't include stale references to it in SOAP response
calendarItemId = null;
} catch (ServiceException e) {
// eat PERM_DENIED
if (e.getCode() != ServiceException.PERM_DENIED) {
throw e;
}
// If we can't access it. Don't include a reference to it.
calendarItemId = null;
}
// Do staleness check for invitation messages.
if (ICalTok.REQUEST.equals(method) || ICalTok.PUBLISH.equals(method)) {
if (calItem != null && calItem.getFolderId() != Mailbox.ID_FOLDER_TRASH) {
if (invCi != null) {
// See if the messsage's invite is outdated.
Invite invCurr = calItem.getInvite(invCi.getRecurId());
if (invCurr != null) {
if (invCi.getSeqNo() >= invCurr.getSeqNo()) {
// Invite is new or same as what's in the appointment. Show it.
invite = invCi;
} else {
// Outdated. Don't show it.
invite = null;
}
} else {
// New invite. Show it.
invite = invCi;
}
} else {
// legacy case
invite = calItem.getInvite(msg.getId(), info.getComponentNo());
// invite == null if the invite was outdated by a newer update
}
}
}
} else {
// We have an invite that wasn't auto-added.
if (invCi != null) {
if (!Invite.isOrganizerMethod(invCi.getMethod()) || ICalTok.DECLINECOUNTER.equals(method)) {
invite = invCi;
} else {
try {
calItem = mbox.getCalendarItemByUid(octxt, invCi.getUid());
} catch (MailServiceException.NoSuchItemException e) {
// ignore
} catch (ServiceException e) {
// eat PERM_DENIED
if (e.getCode() != ServiceException.PERM_DENIED) {
throw e;
}
}
if (calItem != null) {
// See if the messsage's invite is outdated.
Invite invCurr = calItem.getInvite(invCi.getRecurId());
if (invCurr != null) {
if (invCi.getSeqNo() >= invCurr.getSeqNo()) {
// Invite is new or same as what's in the appointment. Show it.
invite = invCi;
} else {
// Outdated. Don't show it.
invite = null;
}
} else {
// New invite. Show it.
invite = invCi;
}
} else {
// Appointment doesn't exist. The invite in the message should be displayed and the
// user can manually add the appointment.
invite = invCi;
}
}
}
}
if (invite != null) {
setCalendarItemType(ie, invite.getItemType());
encodeTimeZoneMap(ie, invite.getTimeZoneMap());
com.zimbra.soap.mail.type.CalendarItemInfo remoteCalendarItem = null;
if (calItem == null) {
remoteCalendarItem = msg.getRemoteCalendarItem(invite);
if (remoteCalendarItem != null) {
calendarItemId = new ItemId(remoteCalendarItem.getId(), (String) null);
}
}
encodeInviteComponent(ie, ifmt, octxt, calItem, calendarItemId, invite, fields, neuter);
ICalTok invMethod = Invite.lookupMethod(invite.getMethod());
if (ICalTok.REQUEST.equals(invMethod) || ICalTok.PUBLISH.equals(invMethod)) {
InviteChanges invChanges = info.getInviteChanges();
if (invChanges != null && !invChanges.noChange()) {
Element comp = ie.getOptionalElement(MailConstants.E_INVITE_COMPONENT);
if (comp != null) {
comp.addAttribute(MailConstants.A_CAL_CHANGES, invChanges.toString());
}
}
if (calItem != null) {
boolean showAll = invite.isPublic() || allowPrivateAccess(octxt, calItem);
if (showAll) {
RecurId rid = invite.getRecurId();
encodeCalendarReplies(ie, calItem, invite, rid != null ? rid.getDtZ() : null);
}
} else if (null != remoteCalendarItem) {
CalendarReply.encodeCalendarReplyList(ie, remoteCalendarItem.getCalendarReplies());
}
}
}
}
return ie;
}
use of com.zimbra.cs.mailbox.calendar.Invite in project zm-mailbox by Zimbra.
the class ToXML method setCalendarItemFields.
/**
* Encodes the basic search / sync fields onto an existing calendar item element
*/
public static void setCalendarItemFields(Element calItemElem, ItemIdFormatter ifmt, OperationContext octxt, CalendarItem calItem, int fields, boolean encodeInvites, boolean includeContent, boolean neuter) throws ServiceException {
recordItemTags(calItemElem, calItem, octxt, fields);
calItemElem.addAttribute(MailConstants.A_UID, calItem.getUid());
calItemElem.addAttribute(MailConstants.A_ID, ifmt.formatItemId(calItem));
calItemElem.addAttribute(MailConstants.A_FOLDER, ifmt.formatItemId(new ItemId(calItem.getMailbox().getAccountId(), calItem.getFolderId())));
if (needToOutput(fields, Change.CONTENT) && calItem.getSavedSequence() != 0) {
calItemElem.addAttribute(MailConstants.A_REVISION, calItem.getSavedSequence());
}
if (needToOutput(fields, Change.SIZE)) {
calItemElem.addAttribute(MailConstants.A_SIZE, calItem.getSize());
}
if (needToOutput(fields, Change.DATE)) {
calItemElem.addAttribute(MailConstants.A_DATE, calItem.getDate());
}
if (needToOutput(fields, Change.CONFLICT)) {
calItemElem.addAttribute(MailConstants.A_CHANGE_DATE, calItem.getChangeDate() / 1000);
calItemElem.addAttribute(MailConstants.A_MODIFIED_SEQUENCE, calItem.getModifiedSequence());
}
boolean doDetails = needToOutput(fields, Change.CONTENT) && encodeInvites;
boolean isPublic = true;
boolean hasSeries = false;
boolean hasExceptions = false;
Invite[] invites = calItem.getInvites();
for (Invite inv : invites) {
if (inv.isRecurrence()) {
hasSeries = true;
} else if (inv.hasRecurId()) {
hasExceptions = true;
}
if (!inv.isPublic()) {
isPublic = false;
}
if (doDetails) {
encodeInvite(calItemElem, ifmt, octxt, calItem, inv, includeContent, neuter);
}
}
if (doDetails) {
if (isPublic || allowPrivateAccess(octxt, calItem)) {
encodeCalendarReplies(calItemElem, calItem);
}
encodeAlarmTimes(calItemElem, calItem);
}
if (hasExceptions && !hasSeries) {
calItemElem.addAttribute(MailConstants.A_CAL_ORPHAN, true);
}
}
use of com.zimbra.cs.mailbox.calendar.Invite in project zm-mailbox by Zimbra.
the class ForwardCalendarItem method forwardCalItem.
public static Pair<List<MimeMessage>, List<MimeMessage>> forwardCalItem(Mailbox mbox, OperationContext octxt, CalendarItem calItem, RecurId rid, MimeMessage mm, Account senderAcct) throws ServiceException {
List<MimeMessage> fwdMsgs = new ArrayList<MimeMessage>();
List<MimeMessage> notifyMsgs = new ArrayList<MimeMessage>();
Pair<List<MimeMessage>, List<MimeMessage>> pair = new Pair<List<MimeMessage>, List<MimeMessage>>(fwdMsgs, notifyMsgs);
mbox.lock.lock();
try {
if (rid == null) {
// Forwarding entire appointment
pair = getSeriesFwdMsgs(octxt, senderAcct, calItem, mm);
} else {
// Forwarding an instance
Invite inv = calItem.getInvite(rid);
MimeMessage mmInv = null;
if (inv != null) {
mmInv = calItem.getSubpartMessage(inv.getMailItemId());
} else {
assert (rid != null);
// No invite found matching the RECURRENCE-ID. It must be a non-exception instance.
// Create an invite based on the series invite.
Invite seriesInv = calItem.getDefaultInviteOrNull();
if (seriesInv == null)
throw ServiceException.INVALID_REQUEST("Instance specified but no recurrence series found", null);
Invite exceptInv = seriesInv.newCopy();
exceptInv.clearAlarms();
exceptInv.setRecurrence(null);
exceptInv.setRecurId(rid);
long now = octxt != null ? octxt.getTimestamp() : System.currentTimeMillis();
exceptInv.setDtStamp(now);
ParsedDateTime dtStart = rid.getDt();
ParsedDateTime dtEnd = dtStart.add(exceptInv.getEffectiveDuration());
exceptInv.setDtStart(dtStart);
exceptInv.setDtEnd(dtEnd);
inv = exceptInv;
// Carry over the MimeMessage/ParsedMessage to preserve any attachments.
mmInv = calItem.getSubpartMessage(seriesInv.getMailItemId());
}
ZVCalendar cal = inv.newToICalendar(true);
Pair<MimeMessage, MimeMessage> instancePair = getInstanceFwdMsg(senderAcct, inv, cal, mmInv, mm);
if (instancePair.getFirst() != null) {
fwdMsgs.add(instancePair.getFirst());
}
if (instancePair.getSecond() != null) {
notifyMsgs.add(instancePair.getSecond());
}
}
} finally {
mbox.lock.release();
}
return pair;
}
use of com.zimbra.cs.mailbox.calendar.Invite in project zm-mailbox by Zimbra.
the class ForwardAppointmentInvite method getMessagePair.
public static Pair<MimeMessage, MimeMessage> getMessagePair(Mailbox mbox, Account senderAcct, Message msg, MimeMessage mmFwdWrapper) throws ServiceException {
Pair<MimeMessage, MimeMessage> msgPair;
mbox.lock.lock();
try {
MimeMessage mmInv = msg.getMimeMessage();
List<Invite> invs = new ArrayList<Invite>();
for (Iterator<CalendarItemInfo> iter = msg.getCalendarItemInfoIterator(); iter.hasNext(); ) {
CalendarItemInfo cii = iter.next();
Invite inv = cii.getInvite();
if (inv != null) {
invs.add(inv);
}
}
ZVCalendar cal = null;
Invite firstInv = null;
if (!invs.isEmpty()) {
// Recreate the VCALENDAR from Invites.
boolean first = true;
for (Invite inv : invs) {
if (first) {
first = false;
firstInv = inv;
cal = inv.newToICalendar(true);
} else {
ZComponent comp = inv.newToVComponent(true, true);
cal.addComponent(comp);
}
}
} else {
// If no invites found in metadata, parse from text/calendar MIME part.
try {
CalPartDetectVisitor visitor = new CalPartDetectVisitor();
visitor.accept(mmInv);
MimeBodyPart calPart = visitor.getCalendarPart();
if (calPart != null) {
String ctHdr = calPart.getContentType();
ContentType ct = new ContentType(ctHdr);
String charset = ct.getParameter(MimeConstants.P_CHARSET);
if (charset == null || charset.length() == 0)
charset = MimeConstants.P_CHARSET_UTF8;
InputStream is = calPart.getInputStream();
try {
cal = ZCalendarBuilder.build(is, charset);
} finally {
ByteUtil.closeStream(is);
}
List<Invite> invList = Invite.createFromCalendar(senderAcct, msg.getFragment(), cal, false);
if (invList != null && !invList.isEmpty())
firstInv = invList.get(0);
if (firstInv == null)
throw ServiceException.FAILURE("Error building Invite for calendar part in message " + msg.getId(), null);
}
} catch (MessagingException e) {
throw ServiceException.FAILURE("Error getting calendar part in message " + msg.getId(), null);
} catch (IOException e) {
throw ServiceException.FAILURE("Error getting calendar part in message " + msg.getId(), null);
}
}
msgPair = getInstanceFwdMsg(senderAcct, firstInv, cal, mmInv, mmFwdWrapper);
} finally {
mbox.lock.release();
}
return msgPair;
}
Aggregations