use of com.zimbra.cs.util.tnef.mapi.RecurrenceDefinition in project zm-mailbox by Zimbra.
the class TestMain method processMimeFile.
/**
* @param mimeFile Name of original test file - used for diagnostic reporting
* @param icalFile the file to write the ICALENDAR data to.
* @param tnefFile the file to write TNEF data to.
* @param recurInfoFile the file to write recurrence diagnostics data to.
* @return true if successfully written data.
*/
private static boolean processMimeFile(File mimeFile, File icalFile, File tnefFile, File recurInfoFile, boolean verbose) {
if (!mimeFile.exists()) {
sLog.warn("Can't find MIME file %s", mimeFile.getPath());
return false;
}
sLog.debug("Processing MIME file %s", mimeFile.getPath());
// Prepare the input and output.
InputStream fisMime = null;
ByteArrayOutputStream baos = new ByteArrayOutputStream(10240);
Writer baosOut = null;
boolean doneConversion = false;
try {
fisMime = new ZSharedFileInputStream(mimeFile);
baosOut = new OutputStreamWriter(baos, UTF8);
// Do the conversion.
MimeMessage mm = new ZMimeMessage(JMSession.getSession(), fisMime);
TnefToICalendar converter = getConverter();
doneConversion = doConversion(mm, baosOut, converter, tnefFile, verbose);
if (recurInfoFile != null) {
if (converter instanceof DefaultTnefToICalendar) {
DefaultTnefToICalendar tnef2ical = (DefaultTnefToICalendar) converter;
RecurrenceDefinition recurDef = tnef2ical.getRecurDef();
if (recurDef != null) {
FileWriter rsFileWriter = null;
try {
rsFileWriter = new FileWriter(recurInfoFile);
rsFileWriter.write(recurDef.toString());
} finally {
try {
if (rsFileWriter != null) {
rsFileWriter.close();
}
} catch (IOException e) {
sLog.error("Problem writing to recurInfo file %s", recurInfoFile, e);
}
}
}
}
}
} catch (UnsupportedTnefCalendaringMsgException ex) {
sLog.warn("Unable to map %s to ICALENDAR", mimeFile.getPath(), ex);
return false;
} catch (TNEFtoIcalendarServiceException ex) {
sLog.warn("Problem encountered mapping %s to ICALENDAR", mimeFile.getPath(), ex);
return false;
} catch (MessagingException ex) {
sLog.warn("Problem encountered mapping %s to ICALENDAR", mimeFile.getPath(), ex);
return false;
} catch (ServiceException ex) {
sLog.warn("Problem encountered mapping %s to ICALENDAR", mimeFile.getPath(), ex);
return false;
} catch (IOException ex) {
sLog.warn("IO Problem encountered mapping %s to ICALENDAR", mimeFile.getPath(), ex);
return false;
} finally {
try {
if (fisMime != null)
fisMime.close();
} catch (IOException e) {
sLog.error("Problem closing mime stream", e);
}
}
if (!doneConversion) {
return false;
}
if (!writeIcalendarData(mimeFile, baos, icalFile)) {
return false;
}
if (!validateIcalendarData(mimeFile, baos)) {
return false;
}
return true;
}
use of com.zimbra.cs.util.tnef.mapi.RecurrenceDefinition in project zm-mailbox by Zimbra.
the class SchedulingViewOfTnef method getRecurrenceDefinition.
public RecurrenceDefinition getRecurrenceDefinition(TimeZoneDefinition tzDef) throws IOException, TNEFtoIcalendarServiceException {
RawInputStream tzRis;
if (this.getIcalType() == ICALENDAR_TYPE.VTODO) {
tzRis = MapiPropertyId.PidLidTaskRecurrence.getRawInputStreamValue(this);
} else {
tzRis = MapiPropertyId.PidLidAppointmentRecur.getRawInputStreamValue(this);
}
if (tzRis == null) {
return null;
}
String oemCodePage = super.getOEMCodePage();
RecurrenceDefinition recurDef = new RecurrenceDefinition(tzRis, tzDef, oemCodePage);
return recurDef;
}
Aggregations