Search in sources :

Example 1 with RecurrenceDefinition

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;
}
Also used : ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) MessagingException(javax.mail.MessagingException) ByteArrayInputStream(java.io.ByteArrayInputStream) SharedFileInputStream(javax.mail.util.SharedFileInputStream) ZSharedFileInputStream(com.zimbra.common.zmime.ZSharedFileInputStream) InputStream(java.io.InputStream) FileWriter(java.io.FileWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ZSharedFileInputStream(com.zimbra.common.zmime.ZSharedFileInputStream) ServiceException(com.zimbra.common.service.ServiceException) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) OutputStreamWriter(java.io.OutputStreamWriter) UnsupportedTnefCalendaringMsgException(com.zimbra.cs.util.tnef.TNEFtoIcalendarServiceException.UnsupportedTnefCalendaringMsgException) OutputStreamWriter(java.io.OutputStreamWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer) RecurrenceDefinition(com.zimbra.cs.util.tnef.mapi.RecurrenceDefinition)

Example 2 with RecurrenceDefinition

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;
}
Also used : RawInputStream(net.freeutils.tnef.RawInputStream) RecurrenceDefinition(com.zimbra.cs.util.tnef.mapi.RecurrenceDefinition)

Aggregations

RecurrenceDefinition (com.zimbra.cs.util.tnef.mapi.RecurrenceDefinition)2 ServiceException (com.zimbra.common.service.ServiceException)1 ZMimeMessage (com.zimbra.common.zmime.ZMimeMessage)1 ZSharedFileInputStream (com.zimbra.common.zmime.ZSharedFileInputStream)1 UnsupportedTnefCalendaringMsgException (com.zimbra.cs.util.tnef.TNEFtoIcalendarServiceException.UnsupportedTnefCalendaringMsgException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 MessagingException (javax.mail.MessagingException)1 MimeMessage (javax.mail.internet.MimeMessage)1 SharedFileInputStream (javax.mail.util.SharedFileInputStream)1 RawInputStream (net.freeutils.tnef.RawInputStream)1