use of com.zimbra.common.calendar.ZCalendar.ZVCalendar in project zm-mailbox by Zimbra.
the class TestCalDav method testFuzzyTimeZoneMatchGMT_06.
@Test
public void testFuzzyTimeZoneMatchGMT_06() throws Exception {
try (ByteArrayInputStream bais = new ByteArrayInputStream(VtimeZoneGMT_0600_0500.getBytes())) {
ZVCalendar tzcal = ZCalendar.ZCalendarBuilder.build(bais, MimeConstants.P_CHARSET_UTF8);
assertNotNull("tzcal", tzcal);
ZComponent tzcomp = tzcal.getComponent(ICalTok.VTIMEZONE);
assertNotNull("tzcomp", tzcomp);
ICalTimeZone tz = ICalTimeZone.fromVTimeZone(tzcomp, false, /* skipLookup */
ICalTimeZone.TZID_NAME_ASSIGNMENT_BEHAVIOR.ALWAYS_KEEP);
ICalTimeZone matchtz = ICalTimeZone.lookupMatchingWellKnownTZ(tz);
assertEquals("ID of Timezone which fuzzy matches GMT=06.00/-05.00", "America/Chicago", matchtz.getID());
}
}
use of com.zimbra.common.calendar.ZCalendar.ZVCalendar 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) {
HttpRequestBase 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) {
}
}
HttpClientBuilder clientBuilder = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient();
HttpProxyUtil.configureProxy(clientBuilder);
method = new HttpGet(targetUrl.toString());
String fbMsg;
try {
HttpResponse response = HttpClientUtil.executeMethod(clientBuilder.build(), method);
byte[] buf = ByteUtil.getContent(response.getEntity().getContent(), 0);
fbMsg = new String(buf, "UTF-8");
} catch (IOException | HttpException 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.ZVCalendar in project zm-mailbox by Zimbra.
the class Ical4JTest method doParse.
public static List<ZVCalendar> doParse(String ical) throws IOException, ParserException, ServiceException {
ByteArrayInputStream bais = new ByteArrayInputStream(ical.getBytes(Charsets.UTF_8));
List<ZVCalendar> zvcals = ZCalendar.ZCalendarBuilder.buildMulti(bais, Charsets.UTF_8.name());
return zvcals;
}
use of com.zimbra.common.calendar.ZCalendar.ZVCalendar in project zm-mailbox by Zimbra.
the class ParsedMessage method analyzePart.
/**
* @return Extracted toplevel text (any text that should go into the toplevel indexed document)
*/
private String analyzePart(boolean isMainBody, MPartInfo mpi) throws MessagingException, ServiceException {
boolean ignoreCalendar;
if (calendarPartInfo == null) {
ignoreCalendar = isBouncedCalendar(mpi);
} else {
ignoreCalendar = true;
}
String methodParam = (new ContentType(mpi.getMimePart().getContentType())).getParameter("method");
if (methodParam == null && !LC.calendar_allow_invite_without_method.booleanValue()) {
ignoreCalendar = true;
}
String toRet = "";
try {
// ignore multipart "container" parts
if (mpi.isMultipart()) {
return toRet;
}
String ctype = mpi.getContentType();
MimeHandler handler = MimeHandlerManager.getMimeHandler(ctype, mpi.getFilename());
assert (handler != null);
handler.setDefaultCharset(defaultCharset);
Mime.repairTransferEncoding(mpi.getMimePart());
if (handler.isIndexingEnabled()) {
handler.init(mpi.getMimePart().getDataHandler().getDataSource());
handler.setPartName(mpi.getPartName());
handler.setFilename(mpi.getFilename());
handler.setSize(mpi.getSize());
// remember the first iCalendar attachment
if (!ignoreCalendar && calendarPartInfo == null) {
ZVCalendar cal = handler.getICalendar();
if (cal != null) {
setCalendarPartInfo(mpi, cal);
}
}
// - IndexAttachments was set and !disableIndexingAttachmentsTogether
if ((isMainBody && (!handler.runsExternally() || indexAttachments)) || (indexAttachments && !DebugConfig.disableIndexingAttachmentsTogether)) {
toRet = handler.getContent();
}
if (indexAttachments && !DebugConfig.disableIndexingAttachmentsSeparately) {
// Each non-text MIME part is also indexed as a separate
// Lucene document. This is necessary so that we can tell the
// client what parts match if a search matched a particular
// part.
IndexDocument doc = new IndexDocument(handler.getDocument());
String filename = handler.getFilename();
if (!Strings.isNullOrEmpty(filename)) {
filenames.add(filename);
}
doc.addSortSize(mpi.getMimePart().getSize());
luceneDocuments.add(setLuceneHeadersFromContainer(doc));
}
}
// make sure we've got the text/calendar handler installed
if (!ignoreCalendar && calendarPartInfo == null && ctype.equals(MimeConstants.CT_TEXT_CALENDAR)) {
if (handler.isIndexingEnabled()) {
ZimbraLog.index.warn("TextCalendarHandler not correctly installed");
}
InputStream is = null;
try {
String charset = mpi.getContentTypeParameter(MimeConstants.P_CHARSET);
if (charset == null || charset.trim().isEmpty()) {
charset = MimeConstants.P_CHARSET_DEFAULT;
}
is = mpi.getMimePart().getInputStream();
ZVCalendar cal = ZCalendarBuilder.build(is, charset);
if (cal != null) {
setCalendarPartInfo(mpi, cal);
}
} catch (IOException ioe) {
ZimbraLog.index.warn("error reading text/calendar mime part", ioe);
} finally {
ByteUtil.closeStream(is);
}
}
} catch (MimeHandlerException e) {
handleParseError(mpi, e);
} catch (ObjectHandlerException e) {
handleParseError(mpi, e);
}
return toRet;
}
use of com.zimbra.common.calendar.ZCalendar.ZVCalendar in project zm-mailbox by Zimbra.
the class Invite method getDescription.
/**
* Returns the meeting notes. Meeting notes is the text/plain part in an
* invite. It typically includes CUA-generated meeting summary as well as
* text entered by the user.
*
* @return null if notes is not found
* @throws ServiceException
*/
public static String getDescription(Part mmInv, String mimeType) throws ServiceException {
if (mmInv == null)
return null;
try {
// If top-level is text/calendar, parse the iCalendar object and return
// the DESCRIPTION of the first VEVENT/VTODO encountered.
String mmCtStr = mmInv.getContentType();
if (mmCtStr != null) {
ContentType mmCt = new ContentType(mmCtStr);
if (mmCt.match(MimeConstants.CT_TEXT_CALENDAR)) {
boolean wantHtml = MimeConstants.CT_TEXT_HTML.equalsIgnoreCase(mimeType);
Object mmInvContent = mmInv.getContent();
InputStream is = null;
try {
String charset = MimeConstants.P_CHARSET_UTF8;
if (mmInvContent instanceof InputStream) {
charset = mmCt.getParameter(MimeConstants.P_CHARSET);
if (charset == null)
charset = MimeConstants.P_CHARSET_UTF8;
is = (InputStream) mmInvContent;
} else if (mmInvContent instanceof String) {
String str = (String) mmInvContent;
charset = MimeConstants.P_CHARSET_UTF8;
is = new ByteArrayInputStream(str.getBytes(charset));
}
if (is != null) {
ZVCalendar iCal = ZCalendarBuilder.build(is, charset);
for (Iterator<ZComponent> compIter = iCal.getComponentIterator(); compIter.hasNext(); ) {
ZComponent component = compIter.next();
ICalTok compTypeTok = component.getTok();
if (compTypeTok == ICalTok.VEVENT || compTypeTok == ICalTok.VTODO) {
if (!wantHtml)
return component.getPropVal(ICalTok.DESCRIPTION, null);
else
return component.getDescriptionHtml();
}
}
}
} finally {
ByteUtil.closeStream(is);
}
}
}
Object mmInvContent = mmInv.getContent();
if (!(mmInvContent instanceof MimeMultipart)) {
if (mmInvContent instanceof InputStream) {
ByteUtil.closeStream((InputStream) mmInvContent);
}
return null;
}
MimeMultipart mm = (MimeMultipart) mmInvContent;
// If top-level is multipart, get description from text/* part.
int numParts = mm.getCount();
String charset = null;
for (int i = 0; i < numParts; i++) {
BodyPart part = mm.getBodyPart(i);
String ctStr = part.getContentType();
try {
ContentType ct = new ContentType(ctStr);
if (ct.match(mimeType)) {
charset = ct.getParameter(MimeConstants.P_CHARSET);
if (charset == null)
charset = MimeConstants.P_CHARSET_DEFAULT;
byte[] descBytes = ByteUtil.getContent(part.getInputStream(), part.getSize());
return new String(descBytes, charset);
}
// If part is a multipart, recurse.
if (ct.getBaseType().matches(MimeConstants.CT_MULTIPART_WILD)) {
String str = getDescription(part, mimeType);
if (str != null) {
return str;
}
}
} catch (javax.mail.internet.ParseException e) {
ZimbraLog.calendar.warn("Invalid Content-Type found: \"" + ctStr + "\"; skipping part", e);
}
}
} catch (IOException e) {
throw ServiceException.FAILURE("Unable to get calendar item notes MIME part", e);
} catch (MessagingException e) {
throw ServiceException.FAILURE("Unable to get calendar item notes MIME part", e);
}
return null;
}
Aggregations