Search in sources :

Example 1 with SharedFileInputStream

use of javax.mail.util.SharedFileInputStream in project zm-mailbox by Zimbra.

the class TestMain method main.

public static void main(String[] args) throws Exception {
    ZimbraLog.toolSetupLog4jConsole("INFO", true, false);
    boolean verbose = false;
    boolean inputWasIcs = false;
    File mimeFile = null;
    File icalFile = null;
    File tnefFile = null;
    File recurInfoFile = null;
    String outDirName = null;
    int firstTestFileArgIndex = 0;
    // Thread.sleep(30000);
    for (int i = 0; i < args.length; ++i) {
        String arg = args[i];
        if (arg != null) {
            if (arg.equalsIgnoreCase("-v")) {
                verbose = true;
            } else if (arg.equalsIgnoreCase("-debug")) {
                sLog.setLevel(Level.debug);
            } else if (arg.equalsIgnoreCase("-d")) {
                if (i >= args.length - 2)
                    usage();
                outDirName = args[i + 1];
                firstTestFileArgIndex = i + 2;
                ;
                break;
            } else if (arg.equalsIgnoreCase("-i")) {
                if (i >= args.length - 1)
                    usage();
                String fname = args[i + 1];
                mimeFile = new File(fname);
                inputWasIcs = fname.endsWith(".ics");
                ++i;
            } else if (arg.equalsIgnoreCase("-o")) {
                if (i >= args.length - 1)
                    usage();
                icalFile = new File(args[i + 1]);
                ++i;
            } else if (arg.equalsIgnoreCase("-t")) {
                if (i >= args.length - 1) {
                    usage();
                }
                tnefFile = new File(args[i + 1]);
                ++i;
            } else if (arg.equalsIgnoreCase("-r")) {
                if (i >= args.length - 1) {
                    usage();
                }
                recurInfoFile = new File(args[i + 1]);
                ++i;
            } else {
                usage();
            }
        }
    }
    if (inputWasIcs) {
        SharedFileInputStream sfisMime = null;
        ByteArrayOutputStream baos = new ByteArrayOutputStream(10240);
        ByteUtil.copy(sfisMime, false, baos, true);
        writeIcalendarData(mimeFile, baos, icalFile);
        validateIcalendarData(mimeFile, baos);
        return;
    }
    if (outDirName != null) {
        File outDir = new File(outDirName);
        if (!outDir.exists()) {
            sLog.error("Output directory %s does not exist.", outDirName);
            return;
        }
        for (int i = firstTestFileArgIndex; i < args.length; ++i) {
            mimeFile = new File(args[i]);
            String prefix = mimeFile.getName().replace(".eml", "");
            icalFile = new File(outDir, prefix + ".ics");
            tnefFile = new File(outDir, prefix + ".tnef");
            recurInfoFile = new File(outDir, prefix + ".recurState");
            processMimeFile(mimeFile, icalFile, tnefFile, recurInfoFile, verbose);
        }
        return;
    }
    // Thread.sleep(30000);
    if (mimeFile == null)
        usage();
    processMimeFile(mimeFile, icalFile, tnefFile, recurInfoFile, verbose);
// List<ZVCalendar> icals = ZCalendarBuilder.buildMulti(bais, UTF8);
// Account dummyAcct = new Account();
// List<Invite> invites = Invite.createFromCalendar(dummyAcct, null, icals, false);
// boolean allGood = true;
// for (Invite inv : invites) {
// try {
// // This doesn't check much...
// inv.sanitize(true);
// } catch (ServiceException e) {
// ZimbraLog.tnef.error(e.getMessage());
// allGood = false;
// }
// }
// if (!allGood)
// System.exit(1);
}
Also used : SharedFileInputStream(javax.mail.util.SharedFileInputStream) ZSharedFileInputStream(com.zimbra.common.zmime.ZSharedFileInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File)

Example 2 with SharedFileInputStream

use of javax.mail.util.SharedFileInputStream in project zm-mailbox by Zimbra.

the class Mime method main.

public static void main(String[] args) throws MessagingException, IOException {
    String s = URLDecoder.decode("Zimbra%20&#26085;&#26412;&#35486;&#21270;&#12398;&#32771;&#24942;&#28857;.txt", "utf-8");
    System.out.println(s);
    System.out.println(expandNumericCharacterReferences("Zimbra%20&#26085;&#26412;&#35486;&#21270;&#12398;&#32771;&#24942;&#28857;.txt&#x40;&;&#;&#x;&#&#3876;&#55"));
    MimeMessage mm = new FixedMimeMessage(JMSession.getSession(), new SharedFileInputStream("C:\\Temp\\mail\\24245"));
    InputStream is = new RawContentMultipartDataSource(mm, new ContentType(mm.getContentType())).getInputStream();
    int num;
    byte[] buf = new byte[1024];
    while ((num = is.read(buf)) != -1) {
        System.out.write(buf, 0, num);
    }
}
Also used : ContentType(com.zimbra.common.mime.ContentType) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) SharedFileInputStream(javax.mail.util.SharedFileInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) PipedInputStream(java.io.PipedInputStream) SharedFileInputStream(javax.mail.util.SharedFileInputStream) FilterInputStream(java.io.FilterInputStream) InputStream(java.io.InputStream)

Aggregations

SharedFileInputStream (javax.mail.util.SharedFileInputStream)2 ContentType (com.zimbra.common.mime.ContentType)1 ZMimeMessage (com.zimbra.common.zmime.ZMimeMessage)1 ZSharedFileInputStream (com.zimbra.common.zmime.ZSharedFileInputStream)1 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FilterInputStream (java.io.FilterInputStream)1 InputStream (java.io.InputStream)1 PipedInputStream (java.io.PipedInputStream)1 MimeMessage (javax.mail.internet.MimeMessage)1