use of com.zimbra.cs.mailbox.calendar.FriendlyCalendaringDescription in project zm-mailbox by Zimbra.
the class ScheduleOutbox method handleEventRequest.
private void handleEventRequest(DavContext ctxt, ZCalendar.ZVCalendar cal, ZComponent req, DelegationInfo delegationInfo, String rcpt, Element resp) throws ServiceException, DavException {
if (!DavResource.isSchedulingEnabled()) {
resp.addElement(DavElements.E_RECIPIENT).addElement(DavElements.E_HREF).setText(rcpt);
resp.addElement(DavElements.E_REQUEST_STATUS).setText("5.3;No scheduling for the user");
return;
}
ArrayList<Address> recipients = new java.util.ArrayList<Address>();
InternetAddress from, sender, to;
Account target = null;
try {
sender = new JavaMailInternetAddress(delegationInfo.getOriginatorEmail());
Provisioning prov = Provisioning.getInstance();
if (ctxt.getActingAsDelegateFor() != null) {
target = prov.getAccountByName(ctxt.getActingAsDelegateFor());
}
if (target != null) {
from = AccountUtil.getFriendlyEmailAddress(target);
} else {
if (delegationInfo.getOwnerEmail() != null) {
from = new JavaMailInternetAddress(delegationInfo.getOwnerEmail());
} else {
target = getMailbox(ctxt).getAccount();
if (AccountUtil.addressMatchesAccount(target, delegationInfo.getOriginatorEmail())) {
// Make sure we don't use two different aliases for From and Sender.
// This is a concern with Apple iCal, which picks a random alias as originator.
from = sender;
} else {
from = AccountUtil.getFriendlyEmailAddress(target);
}
}
}
if (sender.getAddress() != null && sender.getAddress().equalsIgnoreCase(from.getAddress())) {
sender = null;
}
to = new JavaMailInternetAddress(CalDavUtils.stripMailto(rcpt));
recipients.add(to);
} catch (AddressException e) {
resp.addElement(DavElements.E_RECIPIENT).addElement(DavElements.E_HREF).setText(rcpt);
resp.addElement(DavElements.E_REQUEST_STATUS).setText("3.7;" + rcpt);
return;
}
String status = req.getPropVal(ICalTok.STATUS, "");
String method = cal.getPropVal(ICalTok.METHOD, "REQUEST");
String subject = "";
if (method.equals("REQUEST")) {
ZProperty organizerProp = req.getProperty(ICalTok.ORGANIZER);
if (organizerProp != null) {
String organizerStr = this.getAddressFromPrincipalURL(new ZOrganizer(organizerProp).getAddress());
if (!AccountUtil.addressMatchesAccount(getMailbox(ctxt).getAccount(), organizerStr)) {
ZimbraLog.dav.debug("scheduling appointment on behalf of %s", organizerStr);
}
}
} else if (method.equals("REPLY")) {
ZProperty attendeeProp = req.getProperty(ICalTok.ATTENDEE);
if (attendeeProp == null)
throw new DavException("missing property ATTENDEE", HttpServletResponse.SC_BAD_REQUEST);
ZAttendee attendee = new ZAttendee(attendeeProp);
String partStat = attendee.getPartStat();
if (partStat.equals(IcalXmlStrMap.PARTSTAT_ACCEPTED)) {
subject = "Accept: ";
} else if (partStat.equals(IcalXmlStrMap.PARTSTAT_TENTATIVE)) {
subject = "Tentative: ";
} else if (partStat.equals(IcalXmlStrMap.PARTSTAT_DECLINED)) {
subject = "Decline: ";
}
}
if (status.equals("CANCELLED"))
subject = "Cancelled: ";
subject += req.getPropVal(ICalTok.SUMMARY, "");
String uid = req.getPropVal(ICalTok.UID, null);
if (uid == null) {
resp.addElement(DavElements.E_RECIPIENT).addElement(DavElements.E_HREF).setText(rcpt);
resp.addElement(DavElements.E_REQUEST_STATUS).setText("3.1;UID");
return;
}
try {
List<Invite> components = Invite.createFromCalendar(ctxt.getAuthAccount(), null, cal, false);
FriendlyCalendaringDescription friendlyDesc = new FriendlyCalendaringDescription(components, ctxt.getAuthAccount());
String desc = friendlyDesc.getAsPlainText();
String descHtml = req.getDescriptionHtml();
if ((descHtml == null) || (descHtml.length() == 0))
descHtml = friendlyDesc.getAsHtml();
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(ctxt.getAuthAccount());
MimeMessage mm = CalendarMailSender.createCalendarMessage(target, from, sender, recipients, subject, desc, descHtml, uid, cal);
mbox.getMailSender().setSendPartial(true).sendMimeMessage(ctxt.getOperationContext(), mbox, true, mm, null, null, null, null, false);
} catch (ServiceException e) {
resp.addElement(DavElements.E_RECIPIENT).addElement(DavElements.E_HREF).setText(rcpt);
resp.addElement(DavElements.E_REQUEST_STATUS).setText("5.1");
return;
}
resp.addElement(DavElements.E_RECIPIENT).addElement(DavElements.E_HREF).setText(rcpt);
resp.addElement(DavElements.E_REQUEST_STATUS).setText("2.0;Success");
}
Aggregations