use of com.zimbra.cs.mailbox.calendar.ZOrganizer 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");
}
use of com.zimbra.cs.mailbox.calendar.ZOrganizer in project zm-mailbox by Zimbra.
the class ForwardCalendarItem method makeFwdMsg.
private static Pair<MimeMessage, MimeMessage> makeFwdMsg(Account senderAcct, Invite inv, MimeMessage mmInv, ZVCalendar cal, MimeMessage mmFwdWrapper, MimeBodyPart plainDesc, MimeBodyPart htmlDesc, boolean useFwdText) throws ServiceException, MessagingException, IOException {
// Set SENT-BY to sender's email address. Required by Outlook.
// Also, set ATTENDEEs to the forwardees. For consistency with Outlook.
setSentByAndAttendees(cal, AccountUtil.getFriendlyEmailAddress(senderAcct).getAddress(), mmFwdWrapper.getAllRecipients());
// From: and Sender: headers
Address from = null;
Address sender = null;
sender = AccountUtil.getFriendlyEmailAddress(senderAcct);
ZOrganizer org = inv.getOrganizer();
if (org != null) {
if (org.hasCn())
from = new JavaMailInternetAddress(org.getAddress(), org.getCn(), MimeConstants.P_CHARSET_UTF8);
else
from = new JavaMailInternetAddress(org.getAddress());
} else {
from = sender;
}
MimeMessage mm;
if (useFwdText) {
String plainDescStr = null;
String htmlDescStr = null;
if (plainDesc != null)
plainDescStr = (String) plainDesc.getContent();
if (htmlDesc != null)
htmlDescStr = (String) htmlDesc.getContent();
setDescProps(cal, plainDescStr, htmlDescStr);
mm = createMergedMessage(senderAcct, from, sender, mmInv, inv, cal, plainDesc, htmlDesc);
} else {
mm = CalendarMailSender.createCalendarMessage(senderAcct, from, sender, null, mmInv, inv, cal, false);
}
// Copy recipient headers from forward wrapper msg.
RecipientType[] rcptTypes = { RecipientType.TO, RecipientType.CC, RecipientType.BCC };
for (RecipientType rcptType : rcptTypes) {
Address[] rcpts = mmFwdWrapper.getRecipients(rcptType);
mm.setRecipients(rcptType, rcpts);
}
mm.setSubject(mmFwdWrapper.getSubject());
mm.saveChanges();
// Create a Forward Notification message if the invitation is originally from ZCS user.
MimeMessage notifyMimeMsg = null;
if (org != null) {
String orgAddress = org.getAddress();
Account orgAccount = Provisioning.getInstance().getAccountByName(orgAddress);
if (orgAccount != null && !orgAccount.getId().equals(senderAcct.getId())) {
notifyMimeMsg = CalendarMailSender.createForwardNotifyMessage(senderAcct, orgAccount, orgAddress, mmFwdWrapper.getAllRecipients(), inv);
}
}
return new Pair<MimeMessage, MimeMessage>(mm, notifyMimeMsg);
}
use of com.zimbra.cs.mailbox.calendar.ZOrganizer in project zm-mailbox by Zimbra.
the class ToXML method encodeInviteComponent.
public static Element encodeInviteComponent(Element parent, ItemIdFormatter ifmt, OperationContext octxt, CalendarItem calItem, /* may be null */
ItemId calId, /* may be null */
Invite invite, int fields, boolean neuter) throws ServiceException {
boolean allFields = true;
if (fields != NOTIFY_FIELDS) {
allFields = false;
if (!needToOutput(fields, Change.INVITE)) {
return parent;
}
}
Element e = parent.addElement(MailConstants.E_INVITE_COMPONENT);
e.addAttribute(MailConstants.A_CAL_METHOD, invite.getMethod());
e.addAttribute(MailConstants.A_CAL_COMPONENT_NUM, invite.getComponentNum());
e.addAttribute(MailConstants.A_CAL_RSVP, invite.getRsvp());
boolean allowPrivateAccess = calItem != null ? allowPrivateAccess(octxt, calItem) : true;
if (allFields) {
if (invite.isPublic() || allowPrivateAccess) {
String priority = invite.getPriority();
if (priority != null) {
e.addAttribute(MailConstants.A_CAL_PRIORITY, priority);
}
e.addAttribute(MailConstants.A_NAME, invite.getName());
e.addAttribute(MailConstants.A_CAL_LOCATION, invite.getLocation());
List<String> categories = invite.getCategories();
if (categories != null) {
for (String cat : categories) {
e.addElement(MailConstants.E_CAL_CATEGORY).setText(cat);
}
}
List<String> comments = invite.getComments();
if (comments != null) {
for (String cmt : comments) {
e.addElement(MailConstants.E_CAL_COMMENT).setText(cmt);
}
}
List<String> contacts = invite.getContacts();
if (contacts != null) {
for (String contact : contacts) {
e.addElement(MailConstants.E_CAL_CONTACT).setText(contact);
}
}
Geo geo = invite.getGeo();
if (geo != null) {
geo.toXml(e);
}
// Percent Complete (VTODO)
if (invite.isTodo()) {
String pct = invite.getPercentComplete();
if (pct != null)
e.addAttribute(MailConstants.A_TASK_PERCENT_COMPLETE, pct);
long completed = invite.getCompleted();
if (completed != 0) {
ParsedDateTime c = ParsedDateTime.fromUTCTime(completed);
e.addAttribute(MailConstants.A_TASK_COMPLETED, c.getDateTimePartString());
}
}
// Attendee(s)
List<ZAttendee> attendees = invite.getAttendees();
for (ZAttendee at : attendees) {
at.toXml(e);
}
// Alarms
Iterator<Alarm> alarmsIter = invite.alarmsIterator();
while (alarmsIter.hasNext()) {
Alarm alarm = alarmsIter.next();
alarm.toXml(e);
}
// x-prop
encodeXProps(e, invite.xpropsIterator());
// fragment
String fragment = invite.getFragment();
if (!Strings.isNullOrEmpty(fragment)) {
e.addAttribute(MailConstants.E_FRAG, fragment, Element.Disposition.CONTENT);
}
if (!invite.hasBlobPart()) {
e.addAttribute(MailConstants.A_CAL_NO_BLOB, true);
}
// Description (plain and html)
String desc = invite.getDescription();
if (desc != null) {
Element descElem = e.addElement(MailConstants.E_CAL_DESCRIPTION);
descElem.setText(desc);
}
String descHtml = invite.getDescriptionHtml();
BrowserDefang defanger = DefangFactory.getDefanger(MimeConstants.CT_TEXT_HTML);
if (descHtml != null) {
try {
descHtml = StringUtil.stripControlCharacters(descHtml);
descHtml = defanger.defang(descHtml, neuter);
Element descHtmlElem = e.addElement(MailConstants.E_CAL_DESC_HTML);
descHtmlElem.setText(descHtml);
} catch (IOException ex) {
ZimbraLog.calendar.warn("Unable to defang HTML for SetAppointmentRequest", ex);
}
}
if (invite.isEvent()) {
if (calItem != null && calItem instanceof Appointment) {
Instance inst = Instance.fromInvite(calItem.getId(), invite);
Appointment appt = (Appointment) calItem;
e.addAttribute(MailConstants.A_APPT_FREEBUSY_ACTUAL, appt.getEffectiveFreeBusyActual(invite, inst));
}
e.addAttribute(MailConstants.A_APPT_FREEBUSY, invite.getFreeBusy());
e.addAttribute(MailConstants.A_APPT_TRANSPARENCY, invite.getTransparency());
}
// Organizer
if (invite.hasOrganizer()) {
ZOrganizer org = invite.getOrganizer();
org.toXml(e);
}
e.addAttribute(MailConstants.A_CAL_URL, invite.getUrl());
}
if (invite.isOrganizer()) {
e.addAttribute(MailConstants.A_CAL_ISORG, true);
}
boolean isRecurring = false;
e.addAttribute("x_uid", invite.getUid());
e.addAttribute(MailConstants.A_UID, invite.getUid());
e.addAttribute(MailConstants.A_CAL_SEQUENCE, invite.getSeqNo());
//zdsync
e.addAttribute(MailConstants.A_CAL_DATETIME, invite.getDTStamp());
String itemId = null;
if (calId != null) {
itemId = calId.toString(ifmt);
} else if (calItem != null) {
itemId = ifmt.formatItemId(calItem);
}
if ((itemId != null) && !("0".equals(itemId))) {
e.addAttribute(MailConstants.A_CAL_ID, /* calItemId */
itemId);
if (invite.isEvent()) {
// for backward compat
e.addAttribute(MailConstants.A_APPT_ID_DEPRECATE_ME, /* apptId */
itemId);
}
if (calItem != null) {
ItemId ciFolderId = new ItemId(calItem.getMailbox(), calItem.getFolderId());
e.addAttribute(MailConstants.A_CAL_ITEM_FOLDER, /* ciFolder */
ifmt.formatItemId(ciFolderId));
}
}
Recurrence.IRecurrence recur = invite.getRecurrence();
if (recur != null) {
isRecurring = true;
Element recurElt = e.addElement(MailConstants.E_CAL_RECUR);
recur.toXml(recurElt);
}
e.addAttribute(MailConstants.A_CAL_STATUS, invite.getStatus());
e.addAttribute(MailConstants.A_CAL_CLASS, invite.getClassProp());
boolean allDay = invite.isAllDayEvent();
boolean isException = invite.hasRecurId();
if (isException) {
e.addAttribute(MailConstants.A_CAL_IS_EXCEPTION, true);
RecurId rid = invite.getRecurId();
e.addAttribute(MailConstants.A_CAL_RECURRENCE_ID_Z, rid.getDtZ());
encodeRecurId(e, rid, allDay);
}
boolean forceUTC = DebugConfig.calendarForceUTC && !isRecurring && !isException && !allDay;
ParsedDateTime dtStart = invite.getStartTime();
if (dtStart != null) {
encodeDtStart(e, dtStart, allDay, forceUTC);
}
ParsedDateTime dtEnd = invite.getEndTime();
if (dtEnd != null) {
encodeDtEnd(e, dtEnd, allDay, invite.isTodo(), forceUTC);
}
ParsedDuration dur = invite.getDuration();
if (dur != null) {
dur.toXml(e);
}
if (allDay) {
e.addAttribute(MailConstants.A_CAL_ALLDAY, true);
}
if (invite.isDraft()) {
e.addAttribute(MailConstants.A_CAL_DRAFT, true);
}
if (invite.isNeverSent()) {
e.addAttribute(MailConstants.A_CAL_NEVER_SENT, true);
}
}
return e;
}
use of com.zimbra.cs.mailbox.calendar.ZOrganizer in project zm-mailbox by Zimbra.
the class Appointment method getBusyTimesString.
private static String getBusyTimesString(OperationContext octxt, Mailbox mbox, List<Conflict> list, TimeZone tz, Locale lc, boolean hasMoreConflicts) throws ServiceException {
StringBuilder sb = new StringBuilder();
int conflictCount = 0;
for (Conflict avail : list) {
if (!avail.isBusy())
continue;
// List conflicting appointments and their organizers.
FreeBusy fb = avail.getFreeBusy();
List<FBInstance> instances = new ArrayList<FBInstance>();
for (Iterator<Interval> iter = fb.iterator(); iter.hasNext(); ) {
Interval interval = iter.next();
// busy intervals only
if (Conflict.isBusy(interval.getStatus())) {
// busy appointments only
for (FBInstance fbinst : interval.getInstances()) {
if (Conflict.isBusy(fbinst.getFreeBusy()))
instances.add(fbinst);
}
}
}
for (FBInstance instance : instances) {
Date startDate = new Date(instance.getStartTime());
Date endDate = new Date(instance.getEndTime());
String start = CalendarMailSender.formatDateTime(startDate, tz, lc);
sb.append(" * ").append(start);
String end;
if (DateTimeUtil.sameDay(startDate, endDate, tz)) {
end = CalendarMailSender.formatTime(endDate, tz, lc);
sb.append(" - ").append(end);
} else {
end = CalendarMailSender.formatDateTime(endDate, tz, lc);
sb.append("\r\n - ").append(end);
}
int apptId = instance.getApptId();
long recurIdDt = instance.getRecurIdDt();
CalendarItem appt = mbox.getCalendarItemById(octxt, apptId);
Invite inv = appt.getInviteForRecurId(recurIdDt);
if (inv != null && inv.hasOrganizer()) {
ZOrganizer organizer = inv.getOrganizer();
String orgDispName;
if (organizer.hasCn())
orgDispName = organizer.getCn() + " <" + organizer.getAddress() + ">";
else
orgDispName = organizer.getAddress();
sb.append(L10nUtil.getMessage(MsgKey.calendarResourceConflictScheduledBy, lc, orgDispName));
}
sb.append("\r\n");
conflictCount++;
}
}
if (hasMoreConflicts)
sb.append(" * ...\r\n");
return sb.toString();
}
use of com.zimbra.cs.mailbox.calendar.ZOrganizer in project zm-mailbox by Zimbra.
the class CalItemEmailReminderTask method getBody.
private String getBody(CalendarItem calItem, Invite invite, boolean html, Locale locale, TimeZone tz) throws ServiceException {
DateFormat dateTimeFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale);
dateTimeFormat.setTimeZone(tz);
DateFormat onlyDateFormat = DateFormat.getDateInstance(DateFormat.SHORT, locale);
onlyDateFormat.setTimeZone(tz);
DateFormat onlyTimeFormat = DateFormat.getTimeInstance(DateFormat.SHORT, locale);
onlyTimeFormat.setTimeZone(tz);
String formattedStart;
String formattedEnd;
if (calItem.getType() == MailItem.Type.APPOINTMENT) {
Date start = new Date(new Long(getProperty(NEXT_INST_START_PROP_NAME)));
formattedStart = dateTimeFormat.format(start);
Date end = invite.getEffectiveDuration().addToDate(start);
formattedEnd = onlyDateFormat.format(start).equals(onlyDateFormat.format(end)) ? onlyTimeFormat.format(end) : dateTimeFormat.format(end);
} else {
// start date and due date is optional for tasks
formattedStart = invite.getStartTime() == null ? "" : onlyDateFormat.format(invite.getStartTime().getDate());
formattedEnd = invite.getEndTime() == null ? "" : onlyDateFormat.format(invite.getEndTime().getDate());
}
String location = invite.getLocation();
String organizer = null;
ZOrganizer zOrganizer = invite.getOrganizer();
if (zOrganizer != null) {
organizer = zOrganizer.hasCn() ? zOrganizer.getCn() : zOrganizer.getAddress();
}
if (organizer == null) {
organizer = "";
}
String folder = calItem.getMailbox().getFolderById(null, calItem.getFolderId()).getName();
String description = html ? invite.getDescriptionHtml() : invite.getDescription();
if (description == null)
description = "";
return html ? L10nUtil.getMessage(calItem.getType() == MailItem.Type.APPOINTMENT ? L10nUtil.MsgKey.apptReminderEmailBodyHtml : L10nUtil.MsgKey.taskReminderEmailBodyHtml, locale, formattedStart, formattedEnd, location, organizer, folder, description) : L10nUtil.getMessage(calItem.getType() == MailItem.Type.APPOINTMENT ? L10nUtil.MsgKey.apptReminderEmailBody : L10nUtil.MsgKey.taskReminderEmailBody, locale, formattedStart, formattedEnd, location, organizer, folder, description);
}
Aggregations