use of com.zimbra.cs.mailbox.calendar.Invite in project zm-mailbox by Zimbra.
the class ContentServlet method getCommand.
private void getCommand(HttpServletRequest req, HttpServletResponse resp, AuthToken token) throws ServletException, IOException {
ItemId iid = null;
try {
iid = new ItemId(req.getParameter(PARAM_MSGID), (String) null);
} catch (ServiceException e) {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, L10nUtil.getMessage(MsgKey.errInvalidId, req));
return;
}
String part = req.getParameter(PARAM_PART);
String fmt = req.getParameter(PARAM_FORMAT);
String dumpsterParam = req.getParameter(PARAM_DUMPSTER);
boolean fromDumpster = dumpsterParam != null && !dumpsterParam.equals("0") && !dumpsterParam.equalsIgnoreCase("false");
try {
// need to proxy the fetch if the mailbox lives on another server
if (!iid.isLocal()) {
// wrong server; proxy to the right one...
proxyServletRequest(req, resp, iid.getAccountId());
return;
}
String authId = token.getAccountId();
String accountId = iid.getAccountId() != null ? iid.getAccountId() : authId;
AccountUtil.addAccountToLogContext(Provisioning.getInstance(), accountId, ZimbraLog.C_NAME, ZimbraLog.C_ID, token);
if (!accountId.equalsIgnoreCase(authId))
ZimbraLog.addToContext(ZimbraLog.C_AID, authId);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(accountId);
if (mbox == null) {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, L10nUtil.getMessage(MsgKey.errMailboxNotFound, req));
return;
}
ZimbraLog.addMboxToContext(mbox.getId());
MailItem item = mbox.getItemById(new OperationContext(token), iid.getId(), MailItem.Type.UNKNOWN, fromDumpster);
if (item == null) {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, L10nUtil.getMessage(MsgKey.errMessageNotFound, req));
return;
}
try {
if (part == null) {
// they want the entire message...
boolean sync = "1".equals(req.getParameter(PARAM_SYNC));
StringBuffer hdr = new StringBuffer();
if (sync) {
// for sync, return metadata as headers to avoid extra SOAP round-trips
resp.addHeader("X-Zimbra-Tags", TagUtil.getTagIdString(item));
resp.addHeader("X-Zimbra-Tag-Names", TagUtil.encodeTags(item.getTags()));
resp.addHeader("X-Zimbra-Flags", item.getFlagString());
resp.addHeader("X-Zimbra-Received", Long.toString(item.getDate()));
resp.addHeader("X-Zimbra-Modified", Long.toString(item.getChangeDate()));
// also return metadata inline in the message content for now
hdr.append("X-Zimbra-Tags: ").append(TagUtil.getTagIdString(item)).append("\n");
hdr.append("X-Zimbra-Tag-Names: ").append(TagUtil.encodeTags(item.getTags()));
hdr.append("X-Zimbra-Flags: ").append(item.getFlagString()).append("\n");
hdr.append("X-Zimbra-Received: ").append(item.getDate()).append("\n");
hdr.append("X-Zimbra-Modified: ").append(item.getChangeDate()).append("\n");
}
if (item instanceof Message) {
Message msg = (Message) item;
if (sync) {
resp.addHeader("X-Zimbra-Conv", Integer.toString(msg.getConversationId()));
hdr.append("X-Zimbra-Conv: ").append(msg.getConversationId()).append("\n");
resp.getOutputStream().write(hdr.toString().getBytes());
}
resp.setContentType(MimeConstants.CT_TEXT_PLAIN);
InputStream is = msg.getContentStream();
ByteUtil.copy(is, true, resp.getOutputStream(), false);
} else if (item instanceof CalendarItem) {
CalendarItem calItem = (CalendarItem) item;
if (sync) {
resp.getOutputStream().write(hdr.toString().getBytes());
}
resp.setContentType(MimeConstants.CT_TEXT_PLAIN);
if (iid.hasSubpart()) {
int invId = iid.getSubpartId();
MimeMessage mm = calItem.getSubpartMessage(invId);
if (mm == null) {
// Backward compatibility for pre-5.0.16 ZDesktop: Build a MIME message on the fly.
Invite[] invs = calItem.getInvites(invId);
if (invs != null && invs.length > 0) {
Invite invite = invs[0];
mm = CalendarMailSender.createCalendarMessage(invite);
}
}
if (mm != null)
mm.writeTo(resp.getOutputStream());
} else {
InputStream is = calItem.getRawMessage();
if (is != null)
ByteUtil.copy(is, true, resp.getOutputStream(), false);
}
}
return;
} else {
MimePart mp = null;
if (item instanceof Message) {
mp = getMimePart((Message) item, part);
} else {
CalendarItem calItem = (CalendarItem) item;
if (iid.hasSubpart()) {
MimeMessage mbp = calItem.getSubpartMessage(iid.getSubpartId());
if (mbp != null)
mp = Mime.getMimePart(mbp, part);
} else {
mp = getMimePart(calItem, part);
}
}
if (mp != null) {
String contentType = mp.getContentType();
if (contentType == null) {
contentType = MimeConstants.CT_APPLICATION_OCTET_STREAM;
}
if (contentType.toLowerCase().startsWith(MimeConstants.CT_TEXT_HTML) && (FORMAT_DEFANGED_HTML.equals(fmt) || FORMAT_DEFANGED_HTML_NOT_IMAGES.equals(fmt))) {
sendbackDefangedHtml(mp, contentType, resp, fmt);
} else {
if (!isTrue(Provisioning.A_zimbraAttachmentsViewInHtmlOnly, mbox.getAccountId())) {
sendbackOriginalDoc(mp, contentType, req, resp);
} else {
req.setAttribute(ATTR_MIMEPART, mp);
req.setAttribute(ATTR_MSGDIGEST, item.getDigest());
req.setAttribute(ATTR_CONTENTURL, req.getRequestURL().toString());
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(CONVERSION_PATH);
dispatcher.forward(req, resp);
}
}
return;
}
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, L10nUtil.getMessage(MsgKey.errPartNotFound, req));
}
} catch (MessagingException e) {
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
}
} catch (NoSuchItemException e) {
resp.sendError(HttpServletResponse.SC_NOT_FOUND, L10nUtil.getMessage(MsgKey.errNoSuchItem, req));
} catch (ServiceException e) {
returnError(resp, e);
} finally {
ZimbraLog.clearContext();
}
/*
out.println("hello world "+req.getParameter("id"));
out.println("path info: "+req.getPathInfo());
out.println("pathtrans: "+req.getPathTranslated());
*/
}
use of com.zimbra.cs.mailbox.calendar.Invite in project zm-mailbox by Zimbra.
the class CalendarUtils method parseInviteForAddInvite.
static ParseMimeMessage.InviteParserResult parseInviteForAddInvite(Account account, MailItem.Type type, Element inviteElem, TimeZoneMap tzMap) throws ServiceException {
if (tzMap == null)
tzMap = new TimeZoneMap(Util.getAccountTimeZone(account));
Invite inv = new Invite(ICalTok.PUBLISH.toString(), tzMap, false);
CalendarUtils.parseInviteElementCommon(account, type, inviteElem, inv, true, true);
String uid = inv.getUid();
if (uid == null || uid.length() == 0)
throw ServiceException.INVALID_REQUEST("Missing uid in an add invite", null);
// DTSTAMP
if (inv.getDTStamp() == 0) {
//zdsync
inv.setDtStamp(new Date().getTime());
}
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.cs.mailbox.calendar.Invite in project zm-mailbox by Zimbra.
the class CalendarUtils method parseInviteForCreate.
/**
* Parse an <inv> element
*
* @param account
* @param inviteElem
* @param tzMap
* TimeZoneMap of invite we might want to refer to (eg we are an
* Exception to it)
* @param uid
* @param recurrenceIdAllowed
* @return
* @throws ServiceException
*/
static ParseMimeMessage.InviteParserResult parseInviteForCreate(Account account, MailItem.Type type, Element inviteElem, TimeZoneMap tzMap, String uid, boolean recurrenceIdAllowed, boolean recurAllowed) throws ServiceException {
if (tzMap == null) {
tzMap = new TimeZoneMap(Util.getAccountTimeZone(account));
}
Invite create = new Invite(ICalTok.PUBLISH.toString(), tzMap, false);
create.setSentByMe(true);
CalendarUtils.parseInviteElementCommon(account, type, inviteElem, create, recurrenceIdAllowed, recurAllowed);
// DTSTAMP
if (create.getDTStamp() == 0) {
//zdsync
create.setDtStamp(new Date().getTime());
}
// UID
if (uid != null && uid.length() > 0) {
create.setUid(uid);
} else {
String uidParsed = create.getUid();
if (uidParsed == null || uidParsed.length() == 0)
create.setUid(LdapUtil.generateUUID());
}
ZVCalendar iCal = create.newToICalendar(true);
String summaryStr = create.getName() != null ? create.getName() : "";
ParseMimeMessage.InviteParserResult toRet = new ParseMimeMessage.InviteParserResult();
toRet.mCal = iCal;
toRet.mUid = create.getUid();
toRet.mSummary = summaryStr;
toRet.mInvite = create;
return toRet;
}
use of com.zimbra.cs.mailbox.calendar.Invite in project zm-mailbox by Zimbra.
the class CalendarUtils method parseInviteForModify.
/**
* Parse an <inv> element in a Modify context -- existing UID, etc
*
* @param inviteElem
* @param oldInv
* is the Default Invite of the appointment we are modifying
* @return
* @throws ServiceException
*/
static ParseMimeMessage.InviteParserResult parseInviteForModify(Account account, MailItem.Type type, Element inviteElem, Invite oldInv, Invite seriesInv, List<ZAttendee> attendeesAdded, List<ZAttendee> attendeesToCancel, boolean recurAllowed) throws ServiceException {
Invite mod = new Invite(ICalTok.PUBLISH.toString(), oldInv.getTimeZoneMap(), false);
mod.setSentByMe(true);
CalendarUtils.parseInviteElementCommon(account, type, inviteElem, mod, oldInv.hasRecurId(), recurAllowed);
// UID
mod.setUid(oldInv.getUid());
attendeesToCancel.addAll(getRemovedAttendees(oldInv.getAttendees(), mod.getAttendees(), true, account));
// reverse of who's being canceled
attendeesAdded.addAll(getRemovedAttendees(mod.getAttendees(), oldInv.getAttendees(), false, account));
// SEQUENCE and DTSTAMP
if (mod.isOrganizer()) {
// Set sequence to the max of 1) what the modifying client specified (if any),
// 2) current sequence + 1, and 3) current sequence of the series, if we're modifying
// an exception instance. This is to satisfy Outlook's requirement that an up-to-date
// exception instance should have a sequence greater than or equal to the series sequence.
// (bug 19111)
int seriesSeq = seriesInv != null ? seriesInv.getSeqNo() : 0;
int newSeq = Math.max(Math.max(mod.getSeqNo(), oldInv.getSeqNo() + 1), seriesSeq);
// the update takes precedence over cancel in case someone receives both, regardless of delivery order. (bug 56642)
if (!attendeesToCancel.isEmpty())
++newSeq;
mod.setSeqNo(newSeq);
mod.setDtStamp(new Date().getTime());
} else {
// If attendee is modifying his copy, preserve SEQUENCE and DTSTAMP.
// If these were advanced, existing replies will get invalidated and
// we don't want that.
mod.setSeqNo(oldInv.getSeqNo());
mod.setDtStamp(oldInv.getDTStamp());
}
if (oldInv.hasRecurId()) {
mod.setRecurId(oldInv.getRecurId());
}
// change tracking
String changes = parseInviteChanges(inviteElem);
if (changes != null) {
// Set the changes as x-prop in the serialized iCalendar object, but not to the parsed Invite object.
mod.addXProp(new ZProperty(ICalTok.X_ZIMBRA_CHANGES, changes));
}
ZVCalendar iCal = mod.newToICalendar(true);
// Don't set the changes x-prop in the parsed Invite.
mod.removeXProp(ICalTok.X_ZIMBRA_CHANGES.toString());
String summaryStr = "";
if (mod.getName() != null) {
summaryStr = mod.getName();
}
ParseMimeMessage.InviteParserResult toRet = new ParseMimeMessage.InviteParserResult();
toRet.mCal = iCal;
toRet.mUid = mod.getUid();
toRet.mSummary = summaryStr;
toRet.mInvite = mod;
return toRet;
}
use of com.zimbra.cs.mailbox.calendar.Invite in project zm-mailbox by Zimbra.
the class CalendarRequest method echoAddedInvite.
protected static Element echoAddedInvite(Element parent, ItemIdFormatter ifmt, OperationContext octxt, Mailbox mbox, AddInviteData aid, int maxSize, boolean wantHtml, boolean neuter) throws ServiceException {
CalendarItem calItem = mbox.getCalendarItemById(octxt, aid.calItemId);
Invite inv = calItem.getInvite(aid.invId, aid.compNum);
String recurIdZ = null;
if (inv != null && inv.getRecurId() != null)
recurIdZ = inv.getRecurId().getDtZ();
ItemId iid = new ItemId(calItem, aid.invId);
Element echoElem = parent.addElement(MailConstants.E_CAL_ECHO);
ToXML.encodeInviteAsMP(echoElem, ifmt, octxt, calItem, recurIdZ, iid, null, maxSize, wantHtml, neuter, null, false, false);
return echoElem;
}
Aggregations