use of com.zimbra.common.calendar.ZCalendar.ZComponent in project zm-mailbox by Zimbra.
the class RemoteFreeBusyProvider method getResults.
@Override
public List<FreeBusy> getResults() {
ArrayList<FreeBusy> fbList = new ArrayList<FreeBusy>();
for (Request req : mRequestList) {
HttpMethod method = null;
Account acct = (Account) req.data;
try {
StringBuilder targetUrl = new StringBuilder();
targetUrl.append(UserServlet.getRestUrl(acct));
targetUrl.append("/Calendar?fmt=ifb");
targetUrl.append("&start=").append(mStart);
targetUrl.append("&end=").append(mEnd);
if (req.folder != FreeBusyQuery.CALENDAR_FOLDER_ALL)
targetUrl.append("&").append(UserServlet.QP_FREEBUSY_CALENDAR).append("=").append(req.folder);
try {
if (mExApptUid != null)
targetUrl.append("&").append(UserServlet.QP_EXUID).append("=").append(URLEncoder.encode(mExApptUid, "UTF-8"));
} catch (UnsupportedEncodingException e) {
}
String authToken = null;
try {
if (mSoapCtxt != null)
authToken = mSoapCtxt.getAuthToken().getEncoded();
} catch (AuthTokenException e) {
}
if (authToken != null) {
targetUrl.append("&").append(ZimbraServlet.QP_ZAUTHTOKEN).append("=");
try {
targetUrl.append(URLEncoder.encode(authToken, "UTF-8"));
} catch (UnsupportedEncodingException e) {
}
}
HttpClient client = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient();
HttpProxyUtil.configureProxy(client);
method = new GetMethod(targetUrl.toString());
String fbMsg;
try {
HttpClientUtil.executeMethod(client, method);
byte[] buf = ByteUtil.getContent(method.getResponseBodyAsStream(), 0);
fbMsg = new String(buf, "UTF-8");
} catch (IOException ex) {
// ignore this recipient and go on
fbMsg = null;
}
if (fbMsg != null) {
ZVCalendar cal = ZCalendarBuilder.build(fbMsg);
for (Iterator<ZComponent> compIter = cal.getComponentIterator(); compIter.hasNext(); ) {
ZComponent comp = compIter.next();
if (ICalTok.VFREEBUSY.equals(comp.getTok())) {
FreeBusy fb = FreeBusy.parse(comp);
fbList.add(fb);
}
}
}
} catch (ServiceException e) {
ZimbraLog.fb.warn("can't get free/busy information for " + req.email, e);
} finally {
if (method != null)
method.releaseConnection();
}
}
return fbList;
}
use of com.zimbra.common.calendar.ZCalendar.ZComponent in project zm-mailbox by Zimbra.
the class CalendarMailSender method createResourceAutoReply.
public static MimeMessage createResourceAutoReply(OperationContext octxt, String fromIdentityId, String authIdentityId, Mailbox mbox, Verb verb, boolean partialAccept, String additionalMsgBody, CalendarItem calItem, Invite inv, Invite[] replies, MimeMessage mmInv, boolean addSignature) throws ServiceException {
boolean onBehalfOf = false;
Account acct = mbox.getAccount();
Account authAcct = acct;
if (octxt != null) {
Account authuser = octxt.getAuthenticatedUser();
if (authuser != null) {
onBehalfOf = !acct.getId().equalsIgnoreCase(authuser.getId());
if (onBehalfOf)
authAcct = authuser;
}
}
Locale lc;
Account organizer = inv.getOrganizerAccount();
if (organizer != null)
lc = organizer.getLocale();
else
lc = authAcct.getLocale();
boolean asAdmin = octxt != null ? octxt.isUsingAdminPrivileges() : false;
boolean allowPrivateAccess = calItem.allowPrivateAccess(authAcct, asAdmin);
boolean hidePrivate = !inv.isPublic() && !allowPrivateAccess;
String subject;
if (hidePrivate)
subject = L10nUtil.getMessage(MsgKey.calendarSubjectWithheld, lc);
else
subject = inv.getName();
String replySubject = getReplySubject(verb, subject, lc);
// Put all REPLY VEVENTs into a single VCALENDAR object.
ZVCalendar iCal = null;
for (Invite replyInv : replies) {
if (iCal == null) {
iCal = replyInv.newToICalendar(!hidePrivate);
} else {
ZComponent cancelComp = replyInv.newToVComponent(true, !hidePrivate);
iCal.addComponent(cancelComp);
}
}
return createDefaultReply(acct, fromIdentityId, authAcct, authIdentityId, asAdmin, onBehalfOf, calItem, inv, mmInv, replySubject, verb, partialAccept, additionalMsgBody, iCal, addSignature);
}
use of com.zimbra.common.calendar.ZCalendar.ZComponent in project zm-mailbox by Zimbra.
the class CalendarMailSender method createForwardedPrivateInviteMessage.
public static MimeMessage createForwardedPrivateInviteMessage(Account account, Locale lc, String method, List<Invite> invites, String origSenderEmail, String forwarderEmail, String[] forwardTo) throws ServiceException {
if (invites == null || invites.isEmpty())
return null;
List<Address> rcpts = new ArrayList<Address>();
for (String to : forwardTo) {
try {
rcpts.add(new JavaMailInternetAddress(to));
} catch (AddressException e) {
ZimbraLog.calendar.warn("Ignoring invalid address \"" + to + "\" during invite forward");
}
}
if (rcpts.isEmpty())
return null;
String subject = L10nUtil.getMessage(MsgKey.calendarSubjectWithheld, lc);
// Create filtered version of invites.
List<Invite> filteredInvs = new ArrayList<Invite>();
for (Invite inv : invites) {
Invite filtered = inv.newCopy();
filtered.clearAlarms();
filtered.clearPrivateInfo();
filtered.setName(subject);
// Add ATTENDEE for forwarder.
List<ZAttendee> atts = inv.getAttendees();
if (atts != null && forwarderEmail != null) {
for (ZAttendee att : atts) {
if (forwarderEmail.equalsIgnoreCase(att.getAddress())) {
filtered.addAttendee(att);
}
}
}
filteredInvs.add(filtered);
}
MimeMessage mm = null;
try {
mm = new Mime.FixedMimeMessage(JMSession.getSmtpSession(account));
mm.setFrom(new JavaMailInternetAddress(origSenderEmail));
mm.addRecipients(RecipientType.TO, rcpts.toArray(new Address[0]));
// Set special header to indicate the forwarding attendee.
mm.setHeader(CalendarMailSender.X_ZIMBRA_CALENDAR_INTENDED_FOR, forwarderEmail);
mm.setSubject(subject);
StringWriter writer = new StringWriter();
try {
writer.write("BEGIN:VCALENDAR\r\n");
ZProperty prop;
prop = new ZProperty(ICalTok.PRODID, ZCalendar.sZimbraProdID);
prop.toICalendar(writer);
prop = new ZProperty(ICalTok.VERSION, ZCalendar.sIcalVersion);
prop.toICalendar(writer);
prop = new ZProperty(ICalTok.METHOD, method);
prop.toICalendar(writer);
// timezones
Invite firstInv = filteredInvs.get(0);
TimeZoneMap tzmap = new TimeZoneMap(firstInv.getTimeZoneMap().getLocalTimeZone());
for (Invite inv : filteredInvs) {
tzmap.add(inv.getTimeZoneMap());
}
for (Iterator<ICalTimeZone> iter = tzmap.tzIterator(); iter.hasNext(); ) {
ICalTimeZone tz = iter.next();
tz.newToVTimeZone().toICalendar(writer);
}
// VEVENTs/VTODOs
for (Invite inv : filteredInvs) {
ZComponent comp = inv.newToVComponent(false, true);
comp.toICalendar(writer);
}
writer.write("END:VCALENDAR\r\n");
} catch (IOException e) {
throw ServiceException.FAILURE("Error writing iCalendar", e);
} finally {
Closeables.closeQuietly(writer);
}
mm.setText(writer.toString());
ContentType ct = new ContentType(MimeConstants.CT_TEXT_CALENDAR);
ct.setParameter(MimeConstants.P_CHARSET, MimeConstants.P_CHARSET_UTF8);
ct.setParameter("method", method);
mm.setHeader("Content-Type", ct.toString());
} catch (MessagingException e) {
ZimbraLog.calendar.warn("Unable to compose email for invite forwarding", e);
}
return mm;
}
use of com.zimbra.common.calendar.ZCalendar.ZComponent 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.ZComponent 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);
}
}
}
}
Aggregations